second-round version of SQIsign
Co-authored-by: Marius A. Aardal <marius.andre.aardal@gmail.com> Co-authored-by: Gora Adj <gora.adj@tii.ae> Co-authored-by: Diego F. Aranha <dfaranha@cs.au.dk> Co-authored-by: Andrea Basso <sqisign@andreabasso.com> Co-authored-by: Isaac Andrés Canales Martínez <icanalesm0500@gmail.com> Co-authored-by: Jorge Chávez-Saab <jorgechavezsaab@gmail.com> Co-authored-by: Maria Corte-Real Santos <mariascrsantos98@gmail.com> Co-authored-by: Luca De Feo <github@defeo.lu> Co-authored-by: Max Duparc <max.duparc@epfl.ch> Co-authored-by: Jonathan Komada Eriksen <jonathan.eriksen97@gmail.com> Co-authored-by: Décio Luiz Gazzoni Filho <decio@decpp.net> Co-authored-by: Basil Hess <bhe@zurich.ibm.com> Co-authored-by: Antonin Leroux <antonin.leroux@polytechnique.org> Co-authored-by: Patrick Longa <plonga@microsoft.com> Co-authored-by: Luciano Maino <mainoluciano.96@gmail.com> Co-authored-by: Michael Meyer <michael@random-oracles.org> Co-authored-by: Hiroshi Onuki <onuki@mist.i.u-tokyo.ac.jp> Co-authored-by: Lorenz Panny <lorenz@yx7.cc> Co-authored-by: Giacomo Pope <giacomopope@gmail.com> Co-authored-by: Krijn Reijnders <reijnderskrijn@gmail.com> Co-authored-by: Damien Robert <damien.robert@inria.fr> Co-authored-by: Francisco Rodríguez-Henriquez <francisco.rodriguez@tii.ae> Co-authored-by: Sina Schaeffler <sschaeffle@student.ethz.ch> Co-authored-by: Benjamin Wesolowski <benjamin.wesolowski@ens-lyon.fr>
This commit is contained in:
committed by
Lorenz Panny
parent
ff34a8cd18
commit
91e9e464fe
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -7,6 +8,10 @@
|
||||
#include <rng.h>
|
||||
#include <sig.h>
|
||||
#include <api.h>
|
||||
#include <bench_test_arguments.h>
|
||||
#ifdef TARGET_BIG_ENDIAN
|
||||
#include <tutil.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CT_TESTING
|
||||
#include <valgrind/memcheck.h>
|
||||
@@ -33,17 +38,18 @@ static void print_hex(const unsigned char *hex, int len) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int test_sqisign() {
|
||||
static int test_sqisign(unsigned long long in_msglen) {
|
||||
unsigned char *pk = calloc(CRYPTO_PUBLICKEYBYTES, 1);
|
||||
unsigned char *sk = calloc(CRYPTO_SECRETKEYBYTES, 1);
|
||||
unsigned char *sig = calloc(CRYPTO_BYTES + 32, 1);
|
||||
unsigned char *sig = calloc(CRYPTO_BYTES + in_msglen, 1);
|
||||
|
||||
unsigned char seed[48] = { 0 };
|
||||
unsigned char msg[32] = { 0 };
|
||||
unsigned long long msglen = 32;
|
||||
unsigned char *msg = malloc(in_msglen);
|
||||
unsigned char *msg_open = malloc(in_msglen);
|
||||
|
||||
randombytes_init(seed, NULL, 256);
|
||||
unsigned long long msglen = in_msglen;
|
||||
|
||||
randombytes(msg, in_msglen);
|
||||
randombytes(msg_open, in_msglen);
|
||||
|
||||
printf("Testing Keygen, Sign, Open: %s\n", CRYPTO_ALGNAME);
|
||||
|
||||
@@ -57,9 +63,9 @@ static int test_sqisign() {
|
||||
VALGRIND_MAKE_MEM_DEFINED(pk, CRYPTO_PUBLICKEYBYTES);
|
||||
#endif
|
||||
|
||||
unsigned long long smlen = CRYPTO_BYTES + 32;
|
||||
unsigned long long smlen = CRYPTO_BYTES + in_msglen;
|
||||
|
||||
res = sqisign_sign(sig, &smlen, msg, 32, sk);
|
||||
res = sqisign_sign(sig, &smlen, msg, in_msglen, sk);
|
||||
if (res != 0) {
|
||||
res = -1;
|
||||
goto err;
|
||||
@@ -76,14 +82,16 @@ static int test_sqisign() {
|
||||
VALGRIND_MAKE_MEM_DEFINED(sig, smlen);
|
||||
#endif
|
||||
|
||||
res = sqisign_open(msg, &msglen, sig, smlen, pk);
|
||||
if (res != 0) {
|
||||
res = sqisign_open(msg_open, &msglen, sig, smlen, pk);
|
||||
if (res != 0 || msglen != in_msglen || memcmp(msg_open, msg, msglen)) {
|
||||
res = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
randombytes(msg_open, in_msglen);
|
||||
|
||||
sig[0] = ~sig[0];
|
||||
res = sqisign_open(msg, &msglen, sig, smlen, pk);
|
||||
res = sqisign_open(msg_open, &msglen, sig, smlen, pk);
|
||||
if (res != 1) {
|
||||
res = -1;
|
||||
goto err;
|
||||
@@ -91,20 +99,87 @@ static int test_sqisign() {
|
||||
res = 0;
|
||||
}
|
||||
|
||||
// Test with `sm` and `m` as the same buffer
|
||||
msglen = in_msglen;
|
||||
randombytes(msg, in_msglen);
|
||||
memcpy(sig, msg, msglen);
|
||||
|
||||
res = sqisign_sign(sig, &smlen, sig, in_msglen, sk);
|
||||
if (res != 0) {
|
||||
res = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
randombytes(msg_open, in_msglen);
|
||||
|
||||
res = sqisign_open(msg_open, &msglen, sig, smlen, pk);
|
||||
if (res != 0 || msglen != in_msglen || memcmp(msg_open, msg, msglen)) {
|
||||
res = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
err:
|
||||
free(pk);
|
||||
free(sk);
|
||||
free(sig);
|
||||
free(msg);
|
||||
free(msg_open);
|
||||
return res;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int rc = 0;
|
||||
uint32_t seed[12] = { 0 };
|
||||
int help = 0;
|
||||
int seed_set = 0;
|
||||
int msglen_set = 0;
|
||||
int res = 0;
|
||||
unsigned long long msglen = 32;
|
||||
|
||||
rc = test_sqisign();
|
||||
for (int i = 1; i < argc; i++) {
|
||||
unsigned int _msglen;
|
||||
|
||||
if (rc != 0) {
|
||||
if (!help && strcmp(argv[i], "--help") == 0) {
|
||||
help = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!seed_set && !parse_seed(argv[i], seed)) {
|
||||
seed_set = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!msglen_set && sscanf(argv[i], "--msglen=%u", &_msglen) == 1) {
|
||||
msglen = (unsigned long long) _msglen;
|
||||
msglen_set = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (help) {
|
||||
printf("Usage: %s [--seed=<seed>]\n", argv[0]);
|
||||
printf("Where <seed> is the random seed to be used; if not present, a random seed is "
|
||||
"generated\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!seed_set) {
|
||||
randombytes_select((unsigned char *)seed, sizeof(seed));
|
||||
}
|
||||
|
||||
print_seed(seed);
|
||||
|
||||
#if defined(TARGET_BIG_ENDIAN)
|
||||
for (int i = 0; i < 12; i++) {
|
||||
seed[i] = BSWAP32(seed[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
randombytes_init((unsigned char *)seed, NULL, 256);
|
||||
|
||||
res = test_sqisign(msglen);
|
||||
|
||||
if (res != 0) {
|
||||
printf("test failed for %s\n", argv[1]);
|
||||
}
|
||||
return rc;
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user