You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

342 lines
7.4 KiB

  1. #include <stdint.h>
  2. #include "params_runtime.h"
  3. unsigned int XMSS_FUNC;
  4. unsigned int XMSS_N;
  5. unsigned int XMSS_WOTS_W;
  6. unsigned int XMSS_WOTS_LOG_W;
  7. unsigned int XMSS_WOTS_LEN1;
  8. unsigned int XMSS_WOTS_LEN2;
  9. unsigned int XMSS_WOTS_LEN;
  10. unsigned int XMSS_WOTS_KEYSIZE;
  11. unsigned int XMSS_FULLHEIGHT;
  12. unsigned int XMSS_TREEHEIGHT;
  13. unsigned int XMSS_D;
  14. unsigned int XMSS_INDEX_LEN;
  15. unsigned int XMSS_BYTES;
  16. unsigned int XMSS_PUBLICKEY_BYTES;
  17. unsigned int XMSS_PRIVATEKEY_BYTES;
  18. unsigned int XMSS_OID_LEN;
  19. unsigned int XMSS_BDS_K;
  20. int xmss_parse_oid(uint32_t oid)
  21. {
  22. switch (oid) {
  23. case 0x01000001:
  24. case 0x02000002:
  25. case 0x03000003:
  26. case 0x04000004:
  27. case 0x05000005:
  28. case 0x06000006:
  29. XMSS_FUNC = XMSS_SHA2;
  30. break;
  31. case 0x07000007:
  32. case 0x08000008:
  33. case 0x09000009:
  34. case 0x0a00000a:
  35. case 0x0b00000b:
  36. case 0x0c00000c:
  37. XMSS_FUNC = XMSS_SHAKE;
  38. break;
  39. default:
  40. return 1;
  41. }
  42. switch (oid) {
  43. case 0x01000001:
  44. case 0x02000002:
  45. case 0x03000003:
  46. case 0x07000007:
  47. case 0x08000008:
  48. case 0x09000009:
  49. XMSS_N = 32;
  50. break;
  51. case 0x04000004:
  52. case 0x05000005:
  53. case 0x06000006:
  54. case 0x0a00000a:
  55. case 0x0b00000b:
  56. case 0x0c00000c:
  57. XMSS_N = 64;
  58. break;
  59. default:
  60. return 1;
  61. }
  62. switch (oid) {
  63. case 0x01000001:
  64. case 0x04000004:
  65. case 0x07000007:
  66. case 0x0a00000a:
  67. XMSS_FULLHEIGHT = 10;
  68. break;
  69. case 0x02000002:
  70. case 0x05000005:
  71. case 0x08000008:
  72. case 0x0b00000b:
  73. XMSS_FULLHEIGHT = 16;
  74. break;
  75. case 0x03000003:
  76. case 0x06000006:
  77. case 0x09000009:
  78. case 0x0c00000c:
  79. XMSS_FULLHEIGHT = 20;
  80. break;
  81. default:
  82. return 1;
  83. }
  84. XMSS_D = 1;
  85. XMSS_TREEHEIGHT = XMSS_FULLHEIGHT / XMSS_D;
  86. XMSS_WOTS_W = 16;
  87. XMSS_WOTS_LOG_W = 4;
  88. if (XMSS_N == 32) {
  89. XMSS_WOTS_LEN1 = 64;
  90. }
  91. else {
  92. XMSS_WOTS_LEN1 = 128;
  93. }
  94. XMSS_WOTS_LEN2 = 3;
  95. XMSS_WOTS_LEN = XMSS_WOTS_LEN1 + XMSS_WOTS_LEN2;
  96. XMSS_WOTS_KEYSIZE = XMSS_WOTS_LEN * XMSS_N;
  97. XMSS_INDEX_LEN = 4;
  98. XMSS_BYTES = (XMSS_INDEX_LEN + XMSS_N + XMSS_D*XMSS_WOTS_KEYSIZE
  99. + XMSS_FULLHEIGHT*XMSS_N);
  100. XMSS_PUBLICKEY_BYTES = 2*XMSS_N;
  101. XMSS_PRIVATEKEY_BYTES = 4*XMSS_N + XMSS_INDEX_LEN;
  102. XMSS_OID_LEN = 4;
  103. // TODO figure out sensible and legal values for this based on the above
  104. XMSS_BDS_K = 0;
  105. return 0;
  106. }
  107. int xmssmt_parse_oid(uint32_t oid)
  108. {
  109. switch (oid) {
  110. case 0x01000001:
  111. case 0x02000002:
  112. case 0x03000003:
  113. case 0x04000004:
  114. case 0x05000005:
  115. case 0x06000006:
  116. case 0x07000007:
  117. case 0x08000008:
  118. case 0x09000009:
  119. case 0x0a00000a:
  120. case 0x0b00000b:
  121. case 0x0c00000c:
  122. case 0x0d00000d:
  123. case 0x0e00000e:
  124. case 0x0f00000f:
  125. case 0x01010101:
  126. XMSS_FUNC = XMSS_SHA2;
  127. break;
  128. case 0x02010102:
  129. case 0x03010103:
  130. case 0x04010104:
  131. case 0x05010105:
  132. case 0x06010106:
  133. case 0x07010107:
  134. case 0x08010108:
  135. case 0x09010109:
  136. case 0x0a01010a:
  137. case 0x0b01010b:
  138. case 0x0c01010c:
  139. case 0x0d01010d:
  140. case 0x0e01010e:
  141. case 0x0f01010f:
  142. case 0x01020201:
  143. case 0x02020202:
  144. XMSS_FUNC = XMSS_SHAKE;
  145. break;
  146. default:
  147. return 1;
  148. }
  149. switch (oid) {
  150. case 0x01000001:
  151. case 0x02000002:
  152. case 0x03000003:
  153. case 0x04000004:
  154. case 0x05000005:
  155. case 0x06000006:
  156. case 0x07000007:
  157. case 0x08000008:
  158. case 0x02010102:
  159. case 0x03010103:
  160. case 0x04010104:
  161. case 0x05010105:
  162. case 0x06010106:
  163. case 0x07010107:
  164. case 0x08010108:
  165. case 0x09010109:
  166. XMSS_N = 32;
  167. break;
  168. case 0x09000009:
  169. case 0x0a00000a:
  170. case 0x0b00000b:
  171. case 0x0c00000c:
  172. case 0x0d00000d:
  173. case 0x0e00000e:
  174. case 0x0f00000f:
  175. case 0x01010101:
  176. case 0x0a01010a:
  177. case 0x0b01010b:
  178. case 0x0c01010c:
  179. case 0x0d01010d:
  180. case 0x0e01010e:
  181. case 0x0f01010f:
  182. case 0x01020201:
  183. case 0x02020202:
  184. XMSS_N = 64;
  185. break;
  186. default:
  187. return 1;
  188. }
  189. switch (oid) {
  190. case 0x01000001:
  191. case 0x02000002:
  192. case 0x09000009:
  193. case 0x0a00000a:
  194. case 0x02010102:
  195. case 0x03010103:
  196. case 0x0a01010a:
  197. case 0x0b01010b:
  198. XMSS_FULLHEIGHT = 20;
  199. break;
  200. case 0x03000003:
  201. case 0x04000004:
  202. case 0x05000005:
  203. case 0x0b00000b:
  204. case 0x0c00000c:
  205. case 0x0d00000d:
  206. case 0x04010104:
  207. case 0x05010105:
  208. case 0x06010106:
  209. case 0x0c01010c:
  210. case 0x0d01010d:
  211. case 0x0e01010e:
  212. XMSS_FULLHEIGHT = 40;
  213. break;
  214. case 0x06000006:
  215. case 0x07000007:
  216. case 0x08000008:
  217. case 0x0e00000e:
  218. case 0x0f00000f:
  219. case 0x01010101:
  220. case 0x07010107:
  221. case 0x08010108:
  222. case 0x09010109:
  223. case 0x0f01010f:
  224. case 0x01020201:
  225. case 0x02020202:
  226. XMSS_FULLHEIGHT = 60;
  227. break;
  228. default:
  229. return 1;
  230. }
  231. switch (oid) {
  232. case 0x01000001:
  233. case 0x03000003:
  234. case 0x09000009:
  235. case 0x0b00000b:
  236. case 0x02010102:
  237. case 0x04010104:
  238. case 0x0a01010a:
  239. case 0x0c01010c:
  240. XMSS_D = 2;
  241. break;
  242. case 0x02000002:
  243. case 0x04000004:
  244. case 0x0a00000a:
  245. case 0x0c00000c:
  246. case 0x03010103:
  247. case 0x05010105:
  248. case 0x0b01010b:
  249. case 0x0d01010d:
  250. XMSS_D = 4;
  251. break;
  252. case 0x05000005:
  253. case 0x0d00000d:
  254. case 0x06010106:
  255. case 0x0e01010e:
  256. XMSS_D = 8;
  257. break;
  258. case 0x06000006:
  259. case 0x0e00000e:
  260. case 0x07010107:
  261. case 0x0f01010f:
  262. XMSS_D = 3;
  263. break;
  264. case 0x07000007:
  265. case 0x0f00000f:
  266. case 0x08010108:
  267. case 0x01020201:
  268. XMSS_D = 6;
  269. break;
  270. case 0x08000008:
  271. case 0x01010101:
  272. case 0x09010109:
  273. case 0x02020202:
  274. XMSS_D = 12;
  275. break;
  276. default:
  277. return 1;
  278. }
  279. XMSS_TREEHEIGHT = XMSS_FULLHEIGHT / XMSS_D;
  280. XMSS_WOTS_W = 16;
  281. XMSS_WOTS_LOG_W = 4;
  282. if (XMSS_N == 32) {
  283. XMSS_WOTS_LEN1 = 64;
  284. }
  285. else {
  286. XMSS_WOTS_LEN1 = 128;
  287. }
  288. XMSS_WOTS_LEN2 = 3;
  289. XMSS_WOTS_LEN = XMSS_WOTS_LEN1 + XMSS_WOTS_LEN2;
  290. XMSS_WOTS_KEYSIZE = XMSS_WOTS_LEN * XMSS_N;
  291. XMSS_INDEX_LEN = 4;
  292. XMSS_BYTES = (XMSS_INDEX_LEN + XMSS_N + XMSS_D*XMSS_WOTS_KEYSIZE
  293. + XMSS_FULLHEIGHT*XMSS_N);
  294. XMSS_PUBLICKEY_BYTES = 2*XMSS_N;
  295. XMSS_PRIVATEKEY_BYTES = 4*XMSS_N + XMSS_INDEX_LEN;
  296. XMSS_OID_LEN = 4;
  297. // TODO figure out sensible and legal values for this based on the above
  298. XMSS_BDS_K = 0;
  299. return 0;
  300. }