2017-08-01 14:31:42 +01:00
|
|
|
#include <stdint.h>
|
2017-10-16 10:58:45 +01:00
|
|
|
#include "params.h"
|
2017-08-01 14:31:42 +01:00
|
|
|
|
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) {
|
|
|
|
case 0x01000001:
|
|
|
|
case 0x02000002:
|
|
|
|
case 0x03000003:
|
|
|
|
case 0x04000004:
|
|
|
|
case 0x05000005:
|
|
|
|
case 0x06000006:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->func = XMSS_SHA2;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x07000007:
|
|
|
|
case 0x08000008:
|
|
|
|
case 0x09000009:
|
|
|
|
case 0x0a00000a:
|
|
|
|
case 0x0b00000b:
|
|
|
|
case 0x0c00000c:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->func = XMSS_SHAKE;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (oid) {
|
|
|
|
case 0x01000001:
|
|
|
|
case 0x02000002:
|
|
|
|
case 0x03000003:
|
|
|
|
|
|
|
|
case 0x07000007:
|
|
|
|
case 0x08000008:
|
|
|
|
case 0x09000009:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 32;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x04000004:
|
|
|
|
case 0x05000005:
|
|
|
|
case 0x06000006:
|
|
|
|
|
|
|
|
case 0x0a00000a:
|
|
|
|
case 0x0b00000b:
|
|
|
|
case 0x0c00000c:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 64;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (oid) {
|
|
|
|
case 0x01000001:
|
|
|
|
case 0x04000004:
|
|
|
|
case 0x07000007:
|
|
|
|
case 0x0a00000a:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 10;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02000002:
|
|
|
|
case 0x05000005:
|
|
|
|
case 0x08000008:
|
|
|
|
case 0x0b00000b:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 16;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03000003:
|
|
|
|
case 0x06000006:
|
|
|
|
case 0x09000009:
|
|
|
|
case 0x0c00000c:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 20;
|
2017-08-01 14:31:42 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 1;
|
|
|
|
params->tree_height = params->full_height / params->d;
|
|
|
|
params->wots_w = 16;
|
|
|
|
params->wots_log_w = 4;
|
|
|
|
if (params->n == 32) {
|
|
|
|
params->wots_len1 = 64;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-10-16 10:58:45 +01:00
|
|
|
params->wots_len1 = 128;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
2017-10-16 10:58:45 +01:00
|
|
|
params->wots_len2 = 3;
|
|
|
|
params->wots_len = params->wots_len1 + params->wots_len2;
|
|
|
|
params->wots_keysize = params->wots_len * params->n;
|
|
|
|
params->index_len = 4;
|
|
|
|
params->bytes = (params->index_len + params->n + params->d*params->wots_keysize
|
|
|
|
+ params->full_height *params->n);
|
|
|
|
params->publickey_bytes = 2*params->n;
|
|
|
|
params->privatekey_bytes = 4*params->n + params->index_len;
|
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-08-01 14:31:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
case 0x01000001:
|
|
|
|
case 0x02000002:
|
|
|
|
case 0x03000003:
|
|
|
|
case 0x04000004:
|
|
|
|
case 0x05000005:
|
|
|
|
case 0x06000006:
|
|
|
|
case 0x07000007:
|
|
|
|
case 0x08000008:
|
|
|
|
case 0x09000009:
|
|
|
|
case 0x0a00000a:
|
|
|
|
case 0x0b00000b:
|
|
|
|
case 0x0c00000c:
|
|
|
|
case 0x0d00000d:
|
|
|
|
case 0x0e00000e:
|
|
|
|
case 0x0f00000f:
|
|
|
|
case 0x01010101:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->func = XMSS_SHA2;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02010102:
|
|
|
|
case 0x03010103:
|
|
|
|
case 0x04010104:
|
|
|
|
case 0x05010105:
|
|
|
|
case 0x06010106:
|
|
|
|
case 0x07010107:
|
|
|
|
case 0x08010108:
|
|
|
|
case 0x09010109:
|
|
|
|
case 0x0a01010a:
|
|
|
|
case 0x0b01010b:
|
|
|
|
case 0x0c01010c:
|
|
|
|
case 0x0d01010d:
|
|
|
|
case 0x0e01010e:
|
|
|
|
case 0x0f01010f:
|
|
|
|
case 0x01020201:
|
|
|
|
case 0x02020202:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->func = XMSS_SHAKE;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (oid) {
|
|
|
|
case 0x01000001:
|
|
|
|
case 0x02000002:
|
|
|
|
case 0x03000003:
|
|
|
|
case 0x04000004:
|
|
|
|
case 0x05000005:
|
|
|
|
case 0x06000006:
|
|
|
|
case 0x07000007:
|
|
|
|
case 0x08000008:
|
|
|
|
|
|
|
|
case 0x02010102:
|
|
|
|
case 0x03010103:
|
|
|
|
case 0x04010104:
|
|
|
|
case 0x05010105:
|
|
|
|
case 0x06010106:
|
|
|
|
case 0x07010107:
|
|
|
|
case 0x08010108:
|
|
|
|
case 0x09010109:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 32;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x09000009:
|
|
|
|
case 0x0a00000a:
|
|
|
|
case 0x0b00000b:
|
|
|
|
case 0x0c00000c:
|
|
|
|
case 0x0d00000d:
|
|
|
|
case 0x0e00000e:
|
|
|
|
case 0x0f00000f:
|
|
|
|
case 0x01010101:
|
|
|
|
|
|
|
|
case 0x0a01010a:
|
|
|
|
case 0x0b01010b:
|
|
|
|
case 0x0c01010c:
|
|
|
|
case 0x0d01010d:
|
|
|
|
case 0x0e01010e:
|
|
|
|
case 0x0f01010f:
|
|
|
|
case 0x01020201:
|
|
|
|
case 0x02020202:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->n = 64;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (oid) {
|
|
|
|
case 0x01000001:
|
|
|
|
case 0x02000002:
|
|
|
|
|
|
|
|
case 0x09000009:
|
|
|
|
case 0x0a00000a:
|
|
|
|
|
|
|
|
case 0x02010102:
|
|
|
|
case 0x03010103:
|
|
|
|
|
|
|
|
case 0x0a01010a:
|
|
|
|
case 0x0b01010b:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 20;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03000003:
|
|
|
|
case 0x04000004:
|
|
|
|
case 0x05000005:
|
|
|
|
|
|
|
|
case 0x0b00000b:
|
|
|
|
case 0x0c00000c:
|
|
|
|
case 0x0d00000d:
|
|
|
|
|
|
|
|
case 0x04010104:
|
|
|
|
case 0x05010105:
|
|
|
|
case 0x06010106:
|
|
|
|
|
|
|
|
case 0x0c01010c:
|
|
|
|
case 0x0d01010d:
|
|
|
|
case 0x0e01010e:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 40;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x06000006:
|
|
|
|
case 0x07000007:
|
|
|
|
case 0x08000008:
|
|
|
|
|
|
|
|
case 0x0e00000e:
|
|
|
|
case 0x0f00000f:
|
|
|
|
case 0x01010101:
|
|
|
|
|
|
|
|
case 0x07010107:
|
|
|
|
case 0x08010108:
|
|
|
|
case 0x09010109:
|
|
|
|
|
|
|
|
case 0x0f01010f:
|
|
|
|
case 0x01020201:
|
|
|
|
case 0x02020202:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->full_height = 60;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (oid) {
|
|
|
|
case 0x01000001:
|
|
|
|
case 0x03000003:
|
|
|
|
case 0x09000009:
|
|
|
|
case 0x0b00000b:
|
|
|
|
case 0x02010102:
|
|
|
|
case 0x04010104:
|
|
|
|
case 0x0a01010a:
|
|
|
|
case 0x0c01010c:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 2;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02000002:
|
|
|
|
case 0x04000004:
|
|
|
|
case 0x0a00000a:
|
|
|
|
case 0x0c00000c:
|
|
|
|
case 0x03010103:
|
|
|
|
case 0x05010105:
|
|
|
|
case 0x0b01010b:
|
|
|
|
case 0x0d01010d:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 4;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x05000005:
|
|
|
|
case 0x0d00000d:
|
|
|
|
case 0x06010106:
|
|
|
|
case 0x0e01010e:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 8;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x06000006:
|
|
|
|
case 0x0e00000e:
|
|
|
|
case 0x07010107:
|
|
|
|
case 0x0f01010f:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 3;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x07000007:
|
|
|
|
case 0x0f00000f:
|
|
|
|
case 0x08010108:
|
|
|
|
case 0x01020201:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 6;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08000008:
|
|
|
|
case 0x01010101:
|
|
|
|
case 0x09010109:
|
|
|
|
case 0x02020202:
|
2017-10-16 10:58:45 +01:00
|
|
|
params->d = 12;
|
2017-08-01 14:31:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-16 10:58:45 +01:00
|
|
|
params->tree_height = params->full_height / params->d;
|
|
|
|
params->wots_w = 16;
|
|
|
|
params->wots_log_w = 4;
|
|
|
|
if (params->n == 32) {
|
|
|
|
params->wots_len1 = 64;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-10-16 10:58:45 +01:00
|
|
|
params->wots_len1 = 128;
|
2017-08-01 14:31:42 +01:00
|
|
|
}
|
2017-10-16 10:58:45 +01:00
|
|
|
params->wots_len2 = 3;
|
|
|
|
params->wots_len = params->wots_len1 + params->wots_len2;
|
|
|
|
params->wots_keysize = params->wots_len * params->n;
|
|
|
|
params->index_len = 4;
|
|
|
|
params->bytes = (params->index_len + params->n + params->d*params->wots_keysize
|
|
|
|
+ params->full_height *params->n);
|
|
|
|
params->publickey_bytes = 2*params->n;
|
|
|
|
params->privatekey_bytes = 4*params->n + params->index_len;
|
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-08-01 14:31:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|