initial version of SQIsign
Co-authored-by: Jorge Chavez-Saab <jorgechavezsaab@gmail.com> Co-authored-by: Maria Corte-Real Santos <36373796+mariascrs@users.noreply.github.com> Co-authored-by: Luca De Feo <github@defeo.lu> Co-authored-by: Jonathan Komada Eriksen <jonathan.eriksen97@gmail.com> Co-authored-by: Basil Hess <bhe@zurich.ibm.com> Co-authored-by: Antonin Leroux <18654258+tonioecto@users.noreply.github.com> Co-authored-by: Patrick Longa <plonga@microsoft.com> Co-authored-by: Lorenz Panny <lorenz@yx7.cc> Co-authored-by: Francisco Rodríguez-Henríquez <francisco.rodriguez@tii.ae> Co-authored-by: Sina Schaeffler <108983332+syndrakon@users.noreply.github.com> Co-authored-by: Benjamin Wesolowski <19474926+Calodeon@users.noreply.github.com>
This commit is contained in:
110
test/test_sqisign.c
Normal file
110
test/test_sqisign.c
Normal file
@@ -0,0 +1,110 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <rng.h>
|
||||
#include <sig.h>
|
||||
#include <api.h>
|
||||
|
||||
#ifdef ENABLE_CT_TESTING
|
||||
#include <valgrind/memcheck.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CT_TESTING
|
||||
static void print_hex(const unsigned char *hex, int len) {
|
||||
unsigned char *copy = calloc(len, 1);
|
||||
memcpy(copy, hex, len); // make a copy that we can tell valgrind is okay to leak
|
||||
VALGRIND_MAKE_MEM_DEFINED(copy, len);
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
printf("%02x", copy[i]);
|
||||
}
|
||||
printf("\n");
|
||||
free(copy);
|
||||
}
|
||||
#else
|
||||
static void print_hex(const unsigned char *hex, int len) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
printf("%02x", hex[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int test_sqisign() {
|
||||
unsigned char *pk = calloc(CRYPTO_PUBLICKEYBYTES, 1);
|
||||
unsigned char *sk = calloc(CRYPTO_SECRETKEYBYTES, 1);
|
||||
unsigned char *sig = calloc(CRYPTO_BYTES + 32, 1);
|
||||
|
||||
unsigned char seed[48] = { 0 };
|
||||
unsigned char msg[32] = { 0 };
|
||||
unsigned long long msglen = 32;
|
||||
|
||||
randombytes_init(seed, NULL, 256);
|
||||
|
||||
printf("Testing Keygen, Sign, Open: %s\n", CRYPTO_ALGNAME);
|
||||
|
||||
int res = sqisign_keypair(pk, sk);
|
||||
if (res != 0) {
|
||||
res = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CT_TESTING
|
||||
VALGRIND_MAKE_MEM_DEFINED(pk, CRYPTO_PUBLICKEYBYTES);
|
||||
#endif
|
||||
|
||||
unsigned long long smlen = CRYPTO_BYTES + 32;
|
||||
|
||||
res = sqisign_sign(sig, &smlen, msg, 32, sk);
|
||||
if (res != 0) {
|
||||
res = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
printf("pk: ");
|
||||
print_hex(pk, CRYPTO_PUBLICKEYBYTES);
|
||||
printf("sk: ");
|
||||
print_hex(sk, CRYPTO_SECRETKEYBYTES);
|
||||
printf("sm: ");
|
||||
print_hex(sig, smlen);
|
||||
|
||||
#ifdef ENABLE_CT_TESTING
|
||||
VALGRIND_MAKE_MEM_DEFINED(sig, smlen);
|
||||
#endif
|
||||
|
||||
res = sqisign_open(msg, &msglen, sig, smlen, pk);
|
||||
if (res != 0) {
|
||||
res = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
sig[0] = ~sig[0];
|
||||
res = sqisign_open(msg, &msglen, sig, smlen, pk);
|
||||
if (res != 1) {
|
||||
res = -1;
|
||||
goto err;
|
||||
} else {
|
||||
res = 0;
|
||||
}
|
||||
|
||||
err:
|
||||
free(pk);
|
||||
free(sk);
|
||||
free(sig);
|
||||
return res;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int rc = 0;
|
||||
|
||||
rc = test_sqisign();
|
||||
|
||||
if (rc != 0) {
|
||||
printf("test failed for %s\n", argv[1]);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
Reference in New Issue
Block a user