2017-10-23 13:52:33 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../params.h"
|
|
|
|
#include "../xmss.h"
|
|
|
|
#include "../randombytes.h"
|
|
|
|
|
|
|
|
#define MLEN 32
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
xmss_params params;
|
|
|
|
char *oidstr = "XMSS-SHA2_10_256";
|
|
|
|
uint32_t oid = 0x01000001;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
fprintf(stderr, "Testing if XMSS-SHA2_10_256 signing is deterministic.. ");
|
|
|
|
|
|
|
|
xmss_str_to_oid(&oid, oidstr);
|
|
|
|
xmss_parse_oid(¶ms, oid);
|
|
|
|
|
2017-10-24 16:51:56 +01:00
|
|
|
unsigned char pk[XMSS_OID_LEN + params.pk_bytes];
|
|
|
|
unsigned char sk[XMSS_OID_LEN + params.sk_bytes];
|
|
|
|
unsigned char sk2[XMSS_OID_LEN + params.sk_bytes];
|
2017-10-23 13:52:33 +01:00
|
|
|
|
|
|
|
unsigned char m[MLEN];
|
2017-10-24 16:51:56 +01:00
|
|
|
unsigned char sm[params.sig_bytes + MLEN];
|
|
|
|
unsigned char sm2[params.sig_bytes + MLEN];
|
2017-10-23 13:52:33 +01:00
|
|
|
unsigned long long smlen;
|
|
|
|
|
|
|
|
xmss_keypair(pk, sk, oid);
|
|
|
|
|
|
|
|
/* Duplicate the key, because the original will be modified. */
|
2017-10-24 16:51:56 +01:00
|
|
|
memcpy(sk2, sk, XMSS_OID_LEN + params.sk_bytes);
|
2017-10-23 13:52:33 +01:00
|
|
|
|
|
|
|
/* Sign a random message (but twice the same one). */
|
|
|
|
randombytes(m, MLEN);
|
|
|
|
|
|
|
|
xmss_sign(sk, sm, &smlen, m, MLEN);
|
|
|
|
xmss_sign(sk2, sm2, &smlen, m, MLEN);
|
|
|
|
|
|
|
|
/* Compare signature, and, if applicable, print the differences. */
|
2017-10-24 16:51:56 +01:00
|
|
|
if (memcmp(sm, sm2, params.sig_bytes + MLEN)) {
|
2017-10-23 13:52:33 +01:00
|
|
|
fprintf(stderr, "signatures differ!\n");
|
2017-10-24 16:51:56 +01:00
|
|
|
for (i = 0; i < params.sig_bytes + MLEN; i++) {
|
2017-10-23 13:52:33 +01:00
|
|
|
fprintf(stderr, (sm[i] != sm2[i] ? "x" : "."));
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "signatures are identical.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|