2 Commits

1 changed files with 49 additions and 32 deletions
Split View
  1. +49
    -32
      test/acvpkat.c

+ 49
- 32
test/acvpkat.c View File

@@ -22,6 +22,7 @@

struct param_t {
uint8_t oid;
const char *name;
const char *hash;
unsigned height;
unsigned n_samples;
@@ -41,34 +42,44 @@ void vectors_keygen(uint32_t oid, json_object *jreq, json_object *jres, uint32_t
xmss_parse_oid(&params, oid);

unsigned char seed[params.n * 3];
unsigned char pk[params.pk_bytes];
unsigned char sk[params.sk_bytes];
unsigned char pk[params.pk_bytes + XMSS_OID_LEN];
unsigned char sk[params.sk_bytes + XMSS_OID_LEN];
char *sbuf;
unsigned i;

tcs_req = json_object_new_array();
tcs_res = json_object_new_array();

for (i = 0; i < XMSS_OID_LEN; i++) {
pk[XMSS_OID_LEN - i - 1] = (oid >> (8 * i)) & 0xFF;
sk[XMSS_OID_LEN - i - 1] = (oid >> (8 * i)) & 0xFF;
}

for (size_t i=0; i<n_samples; i++) {
tc_req = json_object_new_object();
tc_res = json_object_new_object();

getentropy(seed, 3*params.n);
xmssmt_core_seed_keypair(&params, pk, sk, seed);
xmssmt_core_seed_keypair(&params, &pk[XMSS_OID_LEN], &sk[XMSS_OID_LEN], seed);

json_object_object_add(tc_req, "tcId", json_object_new_int(i+1));
sbuf = malloc(2*3*params.n + 1);
sprint_hex(sbuf, seed, 3*params.n);
json_object_object_add(tc_req, "seed", json_object_new_string(sbuf));
sbuf = malloc(2*params.n + 1);
sprint_hex(sbuf, seed, params.n);
json_object_object_add(tc_req, "S_XMSS", json_object_new_string(sbuf));
sprint_hex(sbuf, &seed[params.n], params.n);
json_object_object_add(tc_req, "SK_PRF", json_object_new_string(sbuf));
sprint_hex(sbuf, &seed[2*params.n], params.n);
json_object_object_add(tc_req, "I", json_object_new_string(sbuf));
free(sbuf);

json_object_object_add(tc_res, "tcId", json_object_new_int(i+1));
sbuf = malloc(2*params.pk_bytes + 1);
sprint_hex(sbuf, pk, params.pk_bytes);
sprint_hex(sbuf, pk, params.pk_bytes + XMSS_OID_LEN);
json_object_object_add(tc_res, "publicKey", json_object_new_string(sbuf));
free(sbuf);

sbuf = malloc(2*params.sk_bytes + 1);
sprint_hex(sbuf, sk, params.sk_bytes);
sprint_hex(sbuf, sk, params.sk_bytes + XMSS_OID_LEN);
json_object_object_add(tc_res, "secretKey", json_object_new_string(sbuf));
free(sbuf);

@@ -107,6 +118,7 @@ void keygen_KAT(const struct param_t *h) {
json_object_object_add(tg_req, "tgId", json_object_new_int(1));
json_object_object_add(tg_req, "testType", json_object_new_string("AFT"));
json_object_object_add(tg_req, "OID", json_object_new_int(h->oid));
json_object_object_add(tg_req, "param", json_object_new_string(h->name));

// Response file
json_object_object_add(tg_res, "tgId", json_object_new_int(1));
@@ -194,8 +206,8 @@ void siggen_KAT(const struct param_t *h) {

char buf[256], *sbuf;
unsigned char seed[params.n * 3];
unsigned char pk[params.pk_bytes];
unsigned char sk[params.sk_bytes];
unsigned char pk[params.pk_bytes + XMSS_OID_LEN];
unsigned char sk[params.sk_bytes + XMSS_OID_LEN];

jreq = json_object_new_object();
jres = json_object_new_object();
@@ -213,25 +225,30 @@ void siggen_KAT(const struct param_t *h) {
json_object_object_add(tg_req, "tgId", json_object_new_int(1));
json_object_object_add(tg_req, "testType", json_object_new_string("AFT"));
json_object_object_add(tg_req, "OID", json_object_new_int(h->oid));
json_object_object_add(tg_req, "param", json_object_new_string(h->name));

// Response file
json_object_object_add(tg_res, "tgId", json_object_new_int(1));
json_object_object_add(tg_req, "OID", json_object_new_int(h->oid));
json_object_object_add(tg_res, "OID", json_object_new_int(h->oid));
getentropy(seed, 3*params.n);
xmssmt_core_seed_keypair(&params, pk, sk, seed);

sbuf = malloc(2*3*params.n + 1);
sprint_hex(sbuf, seed, 3*params.n);
json_object_object_add(tg_req, "seed", json_object_new_string(sbuf));
xmssmt_core_seed_keypair(&params, pk + XMSS_OID_LEN, sk + XMSS_OID_LEN, seed);

sbuf = malloc(2*params.n + 1);
sprint_hex(sbuf, seed, params.n);
json_object_object_add(tg_req, "S_XMSS", json_object_new_string(sbuf));
sprint_hex(sbuf, &seed[params.n], params.n);
json_object_object_add(tg_req, "SK_PRF", json_object_new_string(sbuf));
sprint_hex(sbuf, &seed[2*params.n], params.n);
json_object_object_add(tg_req, "I", json_object_new_string(sbuf));
free(sbuf);

sbuf = malloc(2*params.pk_bytes + 1);
sprint_hex(sbuf, pk, params.pk_bytes);
sprint_hex(sbuf, pk, params.pk_bytes + XMSS_OID_LEN);
json_object_object_add(tg_res, "publicKey", json_object_new_string(sbuf));
free(sbuf);

vectors_siggen(h->oid, sk, tg_req, tg_res, h->n_samples);
vectors_siggen(h->oid, sk + XMSS_OID_LEN, tg_req, tg_res, h->n_samples);

json_object_array_add(tgs_req, tg_req);
json_object_array_add(tgs_res, tg_res);
@@ -252,20 +269,20 @@ void siggen_KAT(const struct param_t *h) {

int main() {
const struct param_t OIDs[] = {
{0x01, "SHA256-N32", 10, 10}, // H10
{0x0D, "SHA256-N24", 10, 10}, // H10
{0x10, "SHAKE256-N32", 10, 10}, // H10
{0x13, "SHAKE256-N24", 10, 10}, // H10
{0x02, "SHA256-N32", 16, 5}, // H16
{0x0E, "SHA256-N24", 16, 5}, // H16
{0x11, "SHAKE256-N32", 16, 5}, // H16
{0x14, "SHAKE256-N24", 16, 5}, // H16
{0x03, "SHA256-N32", 20, 3}, // H20
{0x0F, "SHA256-N24", 20, 3}, // H20
{0x12, "SHAKE256-N32", 20, 3}, // H20
{0x15, "SHAKE256-N24", 20, 3} // H20
{0x01, "XMSS-SHA2_10_256", "SHA256-N32", 10, 10}, // H10
{0x0D, "XMSS-SHA2_10_192", "SHA256-N24", 10, 10}, // H10
{0x10, "XMSS-SHAKE256_10_256", "SHAKE256-N32", 10, 10}, // H10
{0x13, "XMSS-SHAKE256_10_192", "SHA2KE56-N24", 10, 10}, // H10
{0x02, "XMSS-SHA2_16_256", "SHA256-N32", 16, 5}, // H16
{0x0E, "XMSS-SHA2_16_192", "SHA256-N24", 16, 5}, // H16
{0x11, "XMSS-SHAKE256_16_256", "SHAKE256-N32", 16, 5}, // H16
{0x14, "XMSS-SHAKE256_16_192", "SHAKE256-N24", 16, 5}, // H16
{0x03, "XMSS-SHA2_20_256", "SHA256-N32", 20, 3}, // H20
{0x0F, "XMSS-SHA2_20_192", "SHA256-N24", 20, 3}, // H20
{0x12, "XMSS-SHAKE256_20_256", "SHAKE256-N32", 20, 3}, // H20
{0x15, "XMSS-SHAKE256_20_192", "SHAKE256-N24", 20, 3} // H20
};
for (size_t i=0; i<12; i++) {


Loading…
Cancel
Save