2015-08-12 14:38:25 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-08-01 14:20:30 +01:00
|
|
|
#include "../xmss_core.h"
|
2017-06-02 13:10:24 +01:00
|
|
|
#include "../params.h"
|
|
|
|
#include "../randombytes.h"
|
2015-08-12 14:38:25 +01:00
|
|
|
|
|
|
|
#define MLEN 3491
|
2017-06-02 13:10:24 +01:00
|
|
|
#define SIGNATURES 5
|
2015-08-12 14:38:25 +01:00
|
|
|
|
|
|
|
unsigned char mi[MLEN];
|
|
|
|
unsigned long long smlen;
|
|
|
|
unsigned long long mlen;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2017-10-16 10:58:45 +01:00
|
|
|
xmss_params params;
|
|
|
|
// TODO test more different OIDs
|
|
|
|
uint32_t oid = 0x01000001;
|
|
|
|
xmssmt_parse_oid(¶ms, oid);
|
|
|
|
|
2015-08-12 14:38:25 +01:00
|
|
|
int r;
|
|
|
|
unsigned long long i,j;
|
2016-02-02 13:06:43 +00:00
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
unsigned char sk[(params.index_len+4*params.n)];
|
|
|
|
unsigned char pk[2*params.n];
|
2016-02-02 13:06:43 +00:00
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
unsigned long long signature_length = params.index_len + params.n + (params.d*params.wots_keysize) + params.full_height*params.n;
|
2015-08-12 14:38:25 +01:00
|
|
|
unsigned char mo[MLEN+signature_length];
|
|
|
|
unsigned char sm[MLEN+signature_length];
|
|
|
|
|
|
|
|
printf("keypair\n");
|
2017-10-16 10:58:45 +01:00
|
|
|
xmssmt_core_keypair(¶ms, pk, sk);
|
2015-08-12 14:38:25 +01:00
|
|
|
// check pub_seed in SK
|
2017-10-16 10:58:45 +01:00
|
|
|
for (i = 0; i < params.n; i++) {
|
|
|
|
if (pk[params.n+i] != sk[params.index_len+2*params.n+i]) printf("pk.pub_seed != sk.pub_seed %llu",i);
|
|
|
|
if (pk[i] != sk[params.index_len+3*params.n+i]) printf("pk.root != sk.root %llu",i);
|
2015-08-12 14:38:25 +01:00
|
|
|
}
|
|
|
|
printf("pk checked\n");
|
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
unsigned int idx_len = params.index_len;
|
2015-08-12 14:38:25 +01:00
|
|
|
// check index
|
|
|
|
unsigned long long idx = 0;
|
2016-02-02 13:06:43 +00:00
|
|
|
for (i = 0; i < idx_len; i++) {
|
2015-08-12 14:38:25 +01:00
|
|
|
idx |= ((unsigned long long)sk[i]) << 8*(idx_len - 1 - i);
|
|
|
|
}
|
|
|
|
|
2016-02-02 13:06:43 +00:00
|
|
|
if (idx) printf("\nidx != 0: %llu\n",idx);
|
|
|
|
|
|
|
|
for (i = 0; i < SIGNATURES; i++) {
|
2017-06-02 13:10:24 +01:00
|
|
|
randombytes(mi, MLEN);
|
|
|
|
|
2015-08-12 14:38:25 +01:00
|
|
|
printf("sign\n");
|
2017-10-16 10:58:45 +01:00
|
|
|
xmssmt_core_sign(¶ms, sk, sm, &smlen, mi, MLEN);
|
2015-08-12 14:38:25 +01:00
|
|
|
idx = 0;
|
2016-02-02 13:06:43 +00:00
|
|
|
for (j = 0; j < idx_len; j++) {
|
2015-08-12 17:04:16 +01:00
|
|
|
idx += ((unsigned long long)sm[j]) << 8*(idx_len - 1 - j);
|
2015-08-12 14:38:25 +01:00
|
|
|
}
|
2015-08-12 17:04:16 +01:00
|
|
|
printf("\nidx = %llu\n",idx);
|
2015-08-12 14:38:25 +01:00
|
|
|
r = memcmp(mi, sm+signature_length,MLEN);
|
|
|
|
printf("%d\n", r);
|
2016-02-02 13:06:43 +00:00
|
|
|
|
2017-06-02 13:10:24 +01:00
|
|
|
for (j = 0; j < smlen; j++) {
|
|
|
|
printf("%02X", sm[j]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2015-08-12 14:38:25 +01:00
|
|
|
/* Test valid signature */
|
|
|
|
printf("verify\n");
|
2017-10-16 10:58:45 +01:00
|
|
|
r = xmssmt_core_sign_open(¶ms, mo, &mlen, sm, smlen, pk);
|
2015-08-12 14:38:25 +01:00
|
|
|
printf("%d\n", r);
|
|
|
|
r = memcmp(mi,mo,MLEN);
|
|
|
|
printf("%d\n", r);
|
|
|
|
printf("%llu\n", MLEN-mlen);
|
|
|
|
|
|
|
|
/* Test with modified message */
|
|
|
|
sm[52] ^= 1;
|
2017-10-16 10:58:45 +01:00
|
|
|
r = xmssmt_core_sign_open(¶ms, mo, &mlen, sm, smlen, pk);
|
2015-08-12 14:38:25 +01:00
|
|
|
printf("%d\n", r+1);
|
|
|
|
r = memcmp(mi,mo,MLEN);
|
|
|
|
printf("%d\n", (r!=0) - 1);
|
|
|
|
printf("%llu\n", mlen+1);
|
|
|
|
|
|
|
|
/* Test with modified signature */
|
|
|
|
sm[260] ^= 1;
|
|
|
|
sm[52] ^= 1;
|
|
|
|
sm[2] ^= 1;
|
2017-10-16 10:58:45 +01:00
|
|
|
r = xmssmt_core_sign_open(¶ms, mo, &mlen, sm, smlen, pk);
|
2015-08-12 14:38:25 +01:00
|
|
|
printf("%d\n", r+1);
|
|
|
|
r = memcmp(mi,mo,MLEN);
|
|
|
|
printf("%d\n", (r!=0) - 1);
|
|
|
|
printf("%llu\n", mlen+1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|