2017-08-01 14:31:42 +01:00
|
|
|
#include <stdint.h>
|
2017-10-17 16:11:18 +01:00
|
|
|
#include <string.h>
|
2017-10-26 15:54:06 +01:00
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
#include "params.h"
|
2017-10-26 15:54:06 +01:00
|
|
|
#include "xmss_core.h"
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2017-10-17 16:11:18 +01:00
|
|
|
int xmss_str_to_oid(uint32_t *oid, const char *s)
|
|
|
|
{
|
|
|
|
if (!strcmp(s, "XMSS-SHA2_10_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000001;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHA2_16_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000002;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHA2_20_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000003;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHA2_10_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000004;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHA2_16_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000005;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHA2_20_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000006;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE_10_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000007;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE_16_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000008;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE_20_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000009;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE_10_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000a;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE_16_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000b;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE_20_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000c;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
2020-04-28 14:30:15 +01:00
|
|
|
else if (!strcmp(s, "XMSS-SHA2_10_192")) {
|
|
|
|
*oid = 0x0000000d;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHA2_16_192")) {
|
|
|
|
*oid = 0x0000000e;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHA2_20_192")) {
|
|
|
|
*oid = 0x0000000f;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE256_10_256")) {
|
|
|
|
*oid = 0x00000010;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE256_16_256")) {
|
|
|
|
*oid = 0x00000011;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE256_20_256")) {
|
|
|
|
*oid = 0x00000012;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE256_10_192")) {
|
|
|
|
*oid = 0x00000013;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE256_16_192")) {
|
|
|
|
*oid = 0x00000014;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSS-SHAKE256_20_192")) {
|
|
|
|
*oid = 0x00000015;
|
|
|
|
}
|
2017-10-17 16:11:18 +01:00
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xmssmt_str_to_oid(uint32_t *oid, const char *s)
|
|
|
|
{
|
|
|
|
if (!strcmp(s, "XMSSMT-SHA2_20/2_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000001;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_20/4_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000002;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/2_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000003;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/4_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000004;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/8_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000005;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/3_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000006;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/6_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000007;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/12_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000008;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_20/2_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000009;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_20/4_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000a;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/2_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000b;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/4_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000c;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/8_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000d;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/3_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000e;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/6_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000000f;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/12_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000010;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_20/2_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000011;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_20/4_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000012;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_40/2_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000013;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_40/4_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000014;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_40/8_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000015;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_60/3_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000016;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_60/6_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000017;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_60/12_256")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000018;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_20/2_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000019;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_20/4_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000001a;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_40/2_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000001b;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_40/4_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000001c;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_40/8_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000001d;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_60/3_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000001e;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_60/6_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x0000001f;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE_60/12_512")) {
|
2018-01-10 22:00:31 +00:00
|
|
|
*oid = 0x00000020;
|
2017-10-17 16:11:18 +01:00
|
|
|
}
|
2020-04-28 14:30:15 +01:00
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_20/2_192")) {
|
|
|
|
*oid = 0x00000021;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_20/4_192")) {
|
|
|
|
*oid = 0x00000022;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/2_192")) {
|
|
|
|
*oid = 0x00000023;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/4_192")) {
|
|
|
|
*oid = 0x00000024;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_40/8_192")) {
|
|
|
|
*oid = 0x00000025;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/3_192")) {
|
|
|
|
*oid = 0x00000026;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/6_192")) {
|
|
|
|
*oid = 0x00000027;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHA2_60/12_192")) {
|
|
|
|
*oid = 0x00000028;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_20/2_256")) {
|
|
|
|
*oid = 0x00000029;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_20/4_256")) {
|
|
|
|
*oid = 0x0000002a;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_40/2_256")) {
|
|
|
|
*oid = 0x0000002b;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_40/4_256")) {
|
|
|
|
*oid = 0x0000002c;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_40/8_256")) {
|
|
|
|
*oid = 0x0000002d;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_60/3_256")) {
|
|
|
|
*oid = 0x0000002e;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_60/6_256")) {
|
|
|
|
*oid = 0x0000002f;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_60/12_256")) {
|
|
|
|
*oid = 0x00000030;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_20/2_192")) {
|
|
|
|
*oid = 0x00000031;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_20/4_192")) {
|
|
|
|
*oid = 0x00000032;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_40/2_192")) {
|
|
|
|
*oid = 0x00000033;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_40/4_192")) {
|
|
|
|
*oid = 0x00000034;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_40/8_192")) {
|
|
|
|
*oid = 0x00000035;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_60/3_192")) {
|
|
|
|
*oid = 0x00000036;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_60/6_192")) {
|
|
|
|
*oid = 0x00000037;
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "XMSSMT-SHAKE256_60/12_192")) {
|
|
|
|
*oid = 0x00000038;
|
|
|
|
}
|
2017-10-17 16:11:18 +01:00
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
int xmss_parse_oid(xmss_params *params, const uint32_t oid)
|
2017-08-01 14:31:42 +01:00
|
|
|
{
|
|
|
|
switch (oid) {
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000001:
|
|
|
|
case 0x00000002:
|
|
|
|
case 0x00000003:
|
|
|
|
case 0x00000004:
|
|
|
|
case 0x00000005:
|
|
|
|
case 0x00000006:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x0000000d:
|
|
|
|
case 0x0000000e:
|
|
|
|
case 0x0000000f:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->func = XMSS_SHA2;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000007:
|
|
|
|
case 0x00000008:
|
|
|
|
case 0x00000009:
|
2020-04-28 14:30:15 +01:00
|
|
|
params->func = XMSS_SHAKE128;
|
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x0000000a:
|
|
|
|
case 0x0000000b:
|
|
|
|
case 0x0000000c:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000010:
|
|
|
|
case 0x00000011:
|
|
|
|
case 0x00000012:
|
|
|
|
case 0x00000013:
|
|
|
|
case 0x00000014:
|
|
|
|
case 0x00000015:
|
|
|
|
params->func = XMSS_SHAKE256;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-01 13:33:07 +00:00
|
|
|
return -1;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
switch (oid) {
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x0000000d:
|
|
|
|
case 0x0000000e:
|
|
|
|
case 0x0000000f:
|
|
|
|
|
|
|
|
case 0x00000013:
|
|
|
|
case 0x00000014:
|
|
|
|
case 0x00000015:
|
|
|
|
params->n = 24;
|
|
|
|
params->padding_len = 4;
|
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000001:
|
|
|
|
case 0x00000002:
|
|
|
|
case 0x00000003:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000007:
|
|
|
|
case 0x00000008:
|
|
|
|
case 0x00000009:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000010:
|
|
|
|
case 0x00000011:
|
|
|
|
case 0x00000012:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 32;
|
2020-04-14 20:18:01 +01:00
|
|
|
params->padding_len = 32;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000004:
|
|
|
|
case 0x00000005:
|
|
|
|
case 0x00000006:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x0000000a:
|
|
|
|
case 0x0000000b:
|
|
|
|
case 0x0000000c:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 64;
|
2020-04-14 20:18:01 +01:00
|
|
|
params->padding_len = 64;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-01 13:33:07 +00:00
|
|
|
return -1;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
switch (oid) {
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000001:
|
|
|
|
case 0x00000004:
|
|
|
|
case 0x00000007:
|
|
|
|
case 0x0000000a:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x0000000d:
|
|
|
|
case 0x00000010:
|
|
|
|
case 0x00000013:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 10;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000002:
|
|
|
|
case 0x00000005:
|
|
|
|
case 0x00000008:
|
|
|
|
case 0x0000000b:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x0000000e:
|
|
|
|
case 0x00000011:
|
|
|
|
case 0x00000014:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 16;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000003:
|
|
|
|
case 0x00000006:
|
|
|
|
case 0x00000009:
|
|
|
|
case 0x0000000c:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x0000000f:
|
|
|
|
case 0x00000012:
|
|
|
|
case 0x00000015:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 20;
|
2017-08-01 14:31:42 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
2017-11-01 13:33:07 +00:00
|
|
|
return -1;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
2018-09-03 08:49:44 +01:00
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 1;
|
|
|
|
params->wots_w = 16;
|
2017-08-01 14:31:42 +01:00
|
|
|
|
|
|
|
// TODO figure out sensible and legal values for this based on the above
|
2017-10-16 10:58:45 +01:00
|
|
|
params->bds_k = 0;
|
2017-10-30 12:11:22 +00:00
|
|
|
|
2018-09-03 08:49:44 +01:00
|
|
|
return xmss_xmssmt_initialize_params(params);
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
int xmssmt_parse_oid(xmss_params *params, const uint32_t oid)
|
2017-08-01 14:31:42 +01:00
|
|
|
{
|
|
|
|
switch (oid) {
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000001:
|
|
|
|
case 0x00000002:
|
|
|
|
case 0x00000003:
|
|
|
|
case 0x00000004:
|
|
|
|
case 0x00000005:
|
|
|
|
case 0x00000006:
|
|
|
|
case 0x00000007:
|
|
|
|
case 0x00000008:
|
|
|
|
case 0x00000009:
|
|
|
|
case 0x0000000a:
|
|
|
|
case 0x0000000b:
|
|
|
|
case 0x0000000c:
|
|
|
|
case 0x0000000d:
|
|
|
|
case 0x0000000e:
|
|
|
|
case 0x0000000f:
|
|
|
|
case 0x00000010:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000021:
|
|
|
|
case 0x00000022:
|
|
|
|
case 0x00000023:
|
|
|
|
case 0x00000024:
|
|
|
|
case 0x00000025:
|
|
|
|
case 0x00000026:
|
|
|
|
case 0x00000027:
|
|
|
|
case 0x00000028:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->func = XMSS_SHA2;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000011:
|
|
|
|
case 0x00000012:
|
|
|
|
case 0x00000013:
|
|
|
|
case 0x00000014:
|
|
|
|
case 0x00000015:
|
|
|
|
case 0x00000016:
|
|
|
|
case 0x00000017:
|
|
|
|
case 0x00000018:
|
2020-04-28 14:30:15 +01:00
|
|
|
params->func = XMSS_SHAKE128;
|
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000019:
|
|
|
|
case 0x0000001a:
|
|
|
|
case 0x0000001b:
|
|
|
|
case 0x0000001c:
|
|
|
|
case 0x0000001e:
|
|
|
|
case 0x0000001d:
|
|
|
|
case 0x0000001f:
|
|
|
|
case 0x00000020:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000029:
|
|
|
|
case 0x0000002a:
|
|
|
|
case 0x0000002b:
|
|
|
|
case 0x0000002c:
|
|
|
|
case 0x0000002d:
|
|
|
|
case 0x0000002e:
|
|
|
|
case 0x0000002f:
|
|
|
|
case 0x00000030:
|
|
|
|
case 0x00000031:
|
|
|
|
case 0x00000032:
|
|
|
|
case 0x00000033:
|
|
|
|
case 0x00000034:
|
|
|
|
case 0x00000035:
|
|
|
|
case 0x00000036:
|
|
|
|
case 0x00000037:
|
|
|
|
case 0x00000038:
|
|
|
|
params->func = XMSS_SHAKE256;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-01 13:33:07 +00:00
|
|
|
return -1;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
switch (oid) {
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x00000021:
|
|
|
|
case 0x00000022:
|
|
|
|
case 0x00000023:
|
|
|
|
case 0x00000024:
|
|
|
|
case 0x00000025:
|
|
|
|
case 0x00000026:
|
|
|
|
case 0x00000027:
|
|
|
|
case 0x00000028:
|
|
|
|
|
|
|
|
case 0x00000031:
|
|
|
|
case 0x00000032:
|
|
|
|
case 0x00000033:
|
|
|
|
case 0x00000034:
|
|
|
|
case 0x00000035:
|
|
|
|
case 0x00000036:
|
|
|
|
case 0x00000037:
|
|
|
|
case 0x00000038:
|
|
|
|
params->n = 24;
|
|
|
|
params->padding_len = 4;
|
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000001:
|
|
|
|
case 0x00000002:
|
|
|
|
case 0x00000003:
|
|
|
|
case 0x00000004:
|
|
|
|
case 0x00000005:
|
|
|
|
case 0x00000006:
|
|
|
|
case 0x00000007:
|
|
|
|
case 0x00000008:
|
|
|
|
|
|
|
|
case 0x00000011:
|
|
|
|
case 0x00000012:
|
|
|
|
case 0x00000013:
|
|
|
|
case 0x00000014:
|
|
|
|
case 0x00000015:
|
|
|
|
case 0x00000016:
|
|
|
|
case 0x00000017:
|
|
|
|
case 0x00000018:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000029:
|
|
|
|
case 0x0000002a:
|
|
|
|
case 0x0000002b:
|
|
|
|
case 0x0000002c:
|
|
|
|
case 0x0000002d:
|
|
|
|
case 0x0000002e:
|
|
|
|
case 0x0000002f:
|
|
|
|
case 0x00000030:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 32;
|
2020-04-14 20:18:01 +01:00
|
|
|
params->padding_len = 32;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000009:
|
|
|
|
case 0x0000000a:
|
|
|
|
case 0x0000000b:
|
|
|
|
case 0x0000000c:
|
|
|
|
case 0x0000000d:
|
|
|
|
case 0x0000000e:
|
|
|
|
case 0x0000000f:
|
|
|
|
case 0x00000010:
|
|
|
|
|
|
|
|
case 0x00000019:
|
|
|
|
case 0x0000001a:
|
|
|
|
case 0x0000001b:
|
|
|
|
case 0x0000001c:
|
|
|
|
case 0x0000001d:
|
|
|
|
case 0x0000001e:
|
|
|
|
case 0x0000001f:
|
|
|
|
case 0x00000020:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 64;
|
2020-04-14 20:18:01 +01:00
|
|
|
params->padding_len = 64;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-01 13:33:07 +00:00
|
|
|
return -1;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
switch (oid) {
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000001:
|
|
|
|
case 0x00000002:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000009:
|
|
|
|
case 0x0000000a:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000011:
|
|
|
|
case 0x00000012:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000019:
|
|
|
|
case 0x0000001a:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000021:
|
|
|
|
case 0x00000022:
|
|
|
|
|
|
|
|
case 0x00000029:
|
|
|
|
case 0x0000002a:
|
|
|
|
|
|
|
|
case 0x00000031:
|
|
|
|
case 0x00000032:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 20;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000003:
|
|
|
|
case 0x00000004:
|
|
|
|
case 0x00000005:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x0000000b:
|
|
|
|
case 0x0000000c:
|
|
|
|
case 0x0000000d:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000013:
|
|
|
|
case 0x00000014:
|
|
|
|
case 0x00000015:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x0000001b:
|
|
|
|
case 0x0000001c:
|
|
|
|
case 0x0000001d:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000023:
|
|
|
|
case 0x00000024:
|
|
|
|
case 0x00000025:
|
|
|
|
|
|
|
|
case 0x0000002b:
|
|
|
|
case 0x0000002c:
|
|
|
|
case 0x0000002d:
|
|
|
|
|
|
|
|
case 0x00000033:
|
|
|
|
case 0x00000034:
|
|
|
|
case 0x00000035:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 40;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000006:
|
|
|
|
case 0x00000007:
|
|
|
|
case 0x00000008:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x0000000e:
|
|
|
|
case 0x0000000f:
|
|
|
|
case 0x00000010:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000016:
|
|
|
|
case 0x00000017:
|
|
|
|
case 0x00000018:
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x0000001e:
|
|
|
|
case 0x0000001f:
|
|
|
|
case 0x00000020:
|
2020-04-28 14:30:15 +01:00
|
|
|
|
|
|
|
case 0x00000026:
|
|
|
|
case 0x00000027:
|
|
|
|
case 0x00000028:
|
|
|
|
|
|
|
|
case 0x0000002e:
|
|
|
|
case 0x0000002f:
|
|
|
|
case 0x00000030:
|
|
|
|
|
|
|
|
case 0x00000036:
|
|
|
|
case 0x00000037:
|
|
|
|
case 0x00000038:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 60;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-01 13:33:07 +00:00
|
|
|
return -1;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
switch (oid) {
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000001:
|
|
|
|
case 0x00000003:
|
|
|
|
case 0x00000009:
|
|
|
|
case 0x0000000b:
|
|
|
|
case 0x00000011:
|
|
|
|
case 0x00000013:
|
|
|
|
case 0x00000019:
|
|
|
|
case 0x0000001b:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x00000021:
|
|
|
|
case 0x00000023:
|
|
|
|
case 0x00000029:
|
|
|
|
case 0x0000002b:
|
|
|
|
case 0x00000031:
|
|
|
|
case 0x00000033:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 2;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000002:
|
|
|
|
case 0x00000004:
|
|
|
|
case 0x0000000a:
|
|
|
|
case 0x0000000c:
|
|
|
|
case 0x00000012:
|
|
|
|
case 0x00000014:
|
|
|
|
case 0x0000001a:
|
|
|
|
case 0x0000001c:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x00000022:
|
|
|
|
case 0x00000024:
|
|
|
|
case 0x0000002a:
|
|
|
|
case 0x0000002c:
|
|
|
|
case 0x00000032:
|
|
|
|
case 0x00000034:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 4;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000005:
|
|
|
|
case 0x0000000d:
|
|
|
|
case 0x00000015:
|
|
|
|
case 0x0000001d:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x00000025:
|
|
|
|
case 0x0000002d:
|
|
|
|
case 0x00000035:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 8;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000006:
|
|
|
|
case 0x0000000e:
|
|
|
|
case 0x00000016:
|
|
|
|
case 0x0000001e:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x00000026:
|
|
|
|
case 0x0000002e:
|
|
|
|
case 0x00000036:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 3;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000007:
|
|
|
|
case 0x0000000f:
|
|
|
|
case 0x00000017:
|
|
|
|
case 0x0000001f:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x00000027:
|
|
|
|
case 0x0000002f:
|
|
|
|
case 0x00000037:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 6;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
2018-01-10 22:00:31 +00:00
|
|
|
case 0x00000008:
|
|
|
|
case 0x00000010:
|
|
|
|
case 0x00000018:
|
|
|
|
case 0x00000020:
|
2020-04-28 14:30:15 +01:00
|
|
|
case 0x00000028:
|
|
|
|
case 0x00000030:
|
|
|
|
case 0x00000038:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 12;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-01 13:33:07 +00:00
|
|
|
return -1;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
params->wots_w = 16;
|
2018-09-03 08:49:44 +01:00
|
|
|
|
|
|
|
// TODO figure out sensible and legal values for this based on the above
|
|
|
|
params->bds_k = 0;
|
|
|
|
|
|
|
|
return xmss_xmssmt_initialize_params(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a params struct where the following properties have been initialized;
|
|
|
|
* - full_height; the height of the complete (hyper)tree
|
|
|
|
* - n; the number of bytes of hash function output
|
|
|
|
* - d; the number of layers (d > 1 implies XMSSMT)
|
2020-04-28 14:30:15 +01:00
|
|
|
* - func; one of {XMSS_SHA2, XMSS_SHAKE128, XMSS_SHAKE256}
|
2018-09-03 08:49:44 +01:00
|
|
|
* - wots_w; the Winternitz parameter
|
|
|
|
* - optionally, bds_k; the BDS traversal trade-off parameter,
|
|
|
|
* this function initializes the remainder of the params structure.
|
|
|
|
*/
|
|
|
|
int xmss_xmssmt_initialize_params(xmss_params *params)
|
|
|
|
{
|
|
|
|
params->tree_height = params->full_height / params->d;
|
|
|
|
if (params->wots_w == 4) {
|
|
|
|
params->wots_log_w = 2;
|
|
|
|
params->wots_len1 = 8 * params->n / params->wots_log_w;
|
|
|
|
/* len_2 = floor(log(len_1 * (w - 1)) / log(w)) + 1 */
|
|
|
|
params->wots_len2 = 5;
|
|
|
|
}
|
|
|
|
else if (params->wots_w == 16) {
|
|
|
|
params->wots_log_w = 4;
|
|
|
|
params->wots_len1 = 8 * params->n / params->wots_log_w;
|
|
|
|
/* len_2 = floor(log(len_1 * (w - 1)) / log(w)) + 1 */
|
|
|
|
params->wots_len2 = 3;
|
|
|
|
}
|
|
|
|
else if (params->wots_w == 256) {
|
|
|
|
params->wots_log_w = 8;
|
|
|
|
params->wots_len1 = 8 * params->n / params->wots_log_w;
|
|
|
|
/* len_2 = floor(log(len_1 * (w - 1)) / log(w)) + 1 */
|
|
|
|
params->wots_len2 = 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-10-16 10:58:45 +01:00
|
|
|
params->wots_len = params->wots_len1 + params->wots_len2;
|
2017-10-24 16:51:56 +01:00
|
|
|
params->wots_sig_bytes = params->wots_len * params->n;
|
2018-09-03 08:49:44 +01:00
|
|
|
|
|
|
|
if (params->d == 1) { // Assume this is XMSS, not XMSS^MT
|
|
|
|
/* In XMSS, always use fixed 4 bytes for index_bytes */
|
|
|
|
params->index_bytes = 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* In XMSS^MT, round index_bytes up to nearest byte. */
|
|
|
|
params->index_bytes = (params->full_height + 7) / 8;
|
|
|
|
}
|
2017-10-24 16:51:56 +01:00
|
|
|
params->sig_bytes = (params->index_bytes + params->n
|
|
|
|
+ params->d * params->wots_sig_bytes
|
|
|
|
+ params->full_height * params->n);
|
2017-08-01 14:31:42 +01:00
|
|
|
|
2017-10-30 12:11:22 +00:00
|
|
|
params->pk_bytes = 2 * params->n;
|
2018-09-03 08:49:44 +01:00
|
|
|
params->sk_bytes = xmss_xmssmt_core_sk_bytes(params);
|
|
|
|
|
2017-08-01 14:31:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|