Git Patch to Generate Known Answer Tests ( KATs ) from Dilithium Reference Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ref/hex_print.h b/ref/hex_print.h | |
new file mode 100644 | |
index 0000000..7afd872 | |
--- /dev/null | |
+++ b/ref/hex_print.h | |
@@ -0,0 +1,9 @@ | |
+#include <stdio.h> | |
+#include <stdint.h> | |
+ | |
+inline void to_hex(const uint8_t *const bytes, const size_t blen) { | |
+ for(size_t i = 0; i < blen; i++) { | |
+ printf("%.2x", bytes[i]); | |
+ } | |
+ printf("\n"); | |
+} | |
diff --git a/ref/sign.c b/ref/sign.c | |
index 5d0455c..e92aa9d 100644 | |
--- a/ref/sign.c | |
+++ b/ref/sign.c | |
@@ -7,6 +7,7 @@ | |
#include "randombytes.h" | |
#include "symmetric.h" | |
#include "fips202.h" | |
+#include "hex_print.h" | |
/************************************************* | |
* Name: crypto_sign_keypair | |
@@ -30,6 +31,9 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk) { | |
/* Get randomness for rho, rhoprime and key */ | |
randombytes(seedbuf, SEEDBYTES); | |
+ printf("seed = "); | |
+ to_hex(seedbuf, SEEDBYTES); | |
+ | |
shake256(seedbuf, 2*SEEDBYTES + CRHBYTES, seedbuf, SEEDBYTES); | |
rho = seedbuf; | |
rhoprime = rho + SEEDBYTES; | |
@@ -61,6 +65,11 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk) { | |
shake256(tr, SEEDBYTES, pk, CRYPTO_PUBLICKEYBYTES); | |
pack_sk(sk, rho, tr, key, &t0, &s1, &s2); | |
+ printf("pkey = "); | |
+ to_hex(pk, CRYPTO_PUBLICKEYBYTES); | |
+ printf("skey = "); | |
+ to_hex(sk, CRYPTO_SECRETKEYBYTES); | |
+ | |
return 0; | |
} | |
@@ -83,6 +92,10 @@ int crypto_sign_signature(uint8_t *sig, | |
size_t mlen, | |
const uint8_t *sk) | |
{ | |
+ printf("mlen = %zu\n", mlen); | |
+ printf("msg = "); | |
+ to_hex(m, mlen); | |
+ | |
unsigned int n; | |
uint8_t seedbuf[3*SEEDBYTES + 2*CRHBYTES]; | |
uint8_t *rho, *tr, *key, *mu, *rhoprime; | |
@@ -174,6 +187,11 @@ rej: | |
/* Write signature */ | |
pack_sig(sig, sig, &z, &h); | |
*siglen = CRYPTO_BYTES; | |
+ | |
+ printf("sig = "); | |
+ to_hex(sig, *siglen); | |
+ printf("\n"); | |
+ | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to follow for generating Dilithium{2, 3, 5} Known Answer Tests
cd dilithium git apply dilithium_kat_generation.patch