Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

320 Zeilen
7.2 KiB

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