Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include "params.h"
  4. #include "xmss_core.h"
  5. int xmss_str_to_oid(uint32_t *oid, const char *s)
  6. {
  7. if (!strcmp(s, "XMSS-SHA2_10_256")) {
  8. *oid = 0x00000001;
  9. }
  10. else if (!strcmp(s, "XMSS-SHA2_16_256")) {
  11. *oid = 0x00000002;
  12. }
  13. else if (!strcmp(s, "XMSS-SHA2_20_256")) {
  14. *oid = 0x00000003;
  15. }
  16. else if (!strcmp(s, "XMSS-SHA2_10_512")) {
  17. *oid = 0x00000004;
  18. }
  19. else if (!strcmp(s, "XMSS-SHA2_16_512")) {
  20. *oid = 0x00000005;
  21. }
  22. else if (!strcmp(s, "XMSS-SHA2_20_512")) {
  23. *oid = 0x00000006;
  24. }
  25. else if (!strcmp(s, "XMSS-SHAKE_10_256")) {
  26. *oid = 0x00000007;
  27. }
  28. else if (!strcmp(s, "XMSS-SHAKE_16_256")) {
  29. *oid = 0x00000008;
  30. }
  31. else if (!strcmp(s, "XMSS-SHAKE_20_256")) {
  32. *oid = 0x00000009;
  33. }
  34. else if (!strcmp(s, "XMSS-SHAKE_10_512")) {
  35. *oid = 0x0000000a;
  36. }
  37. else if (!strcmp(s, "XMSS-SHAKE_16_512")) {
  38. *oid = 0x0000000b;
  39. }
  40. else if (!strcmp(s, "XMSS-SHAKE_20_512")) {
  41. *oid = 0x0000000c;
  42. }
  43. else if (!strcmp(s, "XMSS-SHA2_10_192")) {
  44. *oid = 0x0000000d;
  45. }
  46. else if (!strcmp(s, "XMSS-SHA2_16_192")) {
  47. *oid = 0x0000000e;
  48. }
  49. else if (!strcmp(s, "XMSS-SHA2_20_192")) {
  50. *oid = 0x0000000f;
  51. }
  52. else if (!strcmp(s, "XMSS-SHAKE256_10_256")) {
  53. *oid = 0x00000010;
  54. }
  55. else if (!strcmp(s, "XMSS-SHAKE256_16_256")) {
  56. *oid = 0x00000011;
  57. }
  58. else if (!strcmp(s, "XMSS-SHAKE256_20_256")) {
  59. *oid = 0x00000012;
  60. }
  61. else if (!strcmp(s, "XMSS-SHAKE256_10_192")) {
  62. *oid = 0x00000013;
  63. }
  64. else if (!strcmp(s, "XMSS-SHAKE256_16_192")) {
  65. *oid = 0x00000014;
  66. }
  67. else if (!strcmp(s, "XMSS-SHAKE256_20_192")) {
  68. *oid = 0x00000015;
  69. }
  70. else {
  71. return -1;
  72. }
  73. return 0;
  74. }
  75. int xmssmt_str_to_oid(uint32_t *oid, const char *s)
  76. {
  77. if (!strcmp(s, "XMSSMT-SHA2_20/2_256")) {
  78. *oid = 0x00000001;
  79. }
  80. else if (!strcmp(s, "XMSSMT-SHA2_20/4_256")) {
  81. *oid = 0x00000002;
  82. }
  83. else if (!strcmp(s, "XMSSMT-SHA2_40/2_256")) {
  84. *oid = 0x00000003;
  85. }
  86. else if (!strcmp(s, "XMSSMT-SHA2_40/4_256")) {
  87. *oid = 0x00000004;
  88. }
  89. else if (!strcmp(s, "XMSSMT-SHA2_40/8_256")) {
  90. *oid = 0x00000005;
  91. }
  92. else if (!strcmp(s, "XMSSMT-SHA2_60/3_256")) {
  93. *oid = 0x00000006;
  94. }
  95. else if (!strcmp(s, "XMSSMT-SHA2_60/6_256")) {
  96. *oid = 0x00000007;
  97. }
  98. else if (!strcmp(s, "XMSSMT-SHA2_60/12_256")) {
  99. *oid = 0x00000008;
  100. }
  101. else if (!strcmp(s, "XMSSMT-SHA2_20/2_512")) {
  102. *oid = 0x00000009;
  103. }
  104. else if (!strcmp(s, "XMSSMT-SHA2_20/4_512")) {
  105. *oid = 0x0000000a;
  106. }
  107. else if (!strcmp(s, "XMSSMT-SHA2_40/2_512")) {
  108. *oid = 0x0000000b;
  109. }
  110. else if (!strcmp(s, "XMSSMT-SHA2_40/4_512")) {
  111. *oid = 0x0000000c;
  112. }
  113. else if (!strcmp(s, "XMSSMT-SHA2_40/8_512")) {
  114. *oid = 0x0000000d;
  115. }
  116. else if (!strcmp(s, "XMSSMT-SHA2_60/3_512")) {
  117. *oid = 0x0000000e;
  118. }
  119. else if (!strcmp(s, "XMSSMT-SHA2_60/6_512")) {
  120. *oid = 0x0000000f;
  121. }
  122. else if (!strcmp(s, "XMSSMT-SHA2_60/12_512")) {
  123. *oid = 0x00000010;
  124. }
  125. else if (!strcmp(s, "XMSSMT-SHAKE_20/2_256")) {
  126. *oid = 0x00000011;
  127. }
  128. else if (!strcmp(s, "XMSSMT-SHAKE_20/4_256")) {
  129. *oid = 0x00000012;
  130. }
  131. else if (!strcmp(s, "XMSSMT-SHAKE_40/2_256")) {
  132. *oid = 0x00000013;
  133. }
  134. else if (!strcmp(s, "XMSSMT-SHAKE_40/4_256")) {
  135. *oid = 0x00000014;
  136. }
  137. else if (!strcmp(s, "XMSSMT-SHAKE_40/8_256")) {
  138. *oid = 0x00000015;
  139. }
  140. else if (!strcmp(s, "XMSSMT-SHAKE_60/3_256")) {
  141. *oid = 0x00000016;
  142. }
  143. else if (!strcmp(s, "XMSSMT-SHAKE_60/6_256")) {
  144. *oid = 0x00000017;
  145. }
  146. else if (!strcmp(s, "XMSSMT-SHAKE_60/12_256")) {
  147. *oid = 0x00000018;
  148. }
  149. else if (!strcmp(s, "XMSSMT-SHAKE_20/2_512")) {
  150. *oid = 0x00000019;
  151. }
  152. else if (!strcmp(s, "XMSSMT-SHAKE_20/4_512")) {
  153. *oid = 0x0000001a;
  154. }
  155. else if (!strcmp(s, "XMSSMT-SHAKE_40/2_512")) {
  156. *oid = 0x0000001b;
  157. }
  158. else if (!strcmp(s, "XMSSMT-SHAKE_40/4_512")) {
  159. *oid = 0x0000001c;
  160. }
  161. else if (!strcmp(s, "XMSSMT-SHAKE_40/8_512")) {
  162. *oid = 0x0000001d;
  163. }
  164. else if (!strcmp(s, "XMSSMT-SHAKE_60/3_512")) {
  165. *oid = 0x0000001e;
  166. }
  167. else if (!strcmp(s, "XMSSMT-SHAKE_60/6_512")) {
  168. *oid = 0x0000001f;
  169. }
  170. else if (!strcmp(s, "XMSSMT-SHAKE_60/12_512")) {
  171. *oid = 0x00000020;
  172. }
  173. else if (!strcmp(s, "XMSSMT-SHA2_20/2_192")) {
  174. *oid = 0x00000021;
  175. }
  176. else if (!strcmp(s, "XMSSMT-SHA2_20/4_192")) {
  177. *oid = 0x00000022;
  178. }
  179. else if (!strcmp(s, "XMSSMT-SHA2_40/2_192")) {
  180. *oid = 0x00000023;
  181. }
  182. else if (!strcmp(s, "XMSSMT-SHA2_40/4_192")) {
  183. *oid = 0x00000024;
  184. }
  185. else if (!strcmp(s, "XMSSMT-SHA2_40/8_192")) {
  186. *oid = 0x00000025;
  187. }
  188. else if (!strcmp(s, "XMSSMT-SHA2_60/3_192")) {
  189. *oid = 0x00000026;
  190. }
  191. else if (!strcmp(s, "XMSSMT-SHA2_60/6_192")) {
  192. *oid = 0x00000027;
  193. }
  194. else if (!strcmp(s, "XMSSMT-SHA2_60/12_192")) {
  195. *oid = 0x00000028;
  196. }
  197. else if (!strcmp(s, "XMSSMT-SHAKE256_20/2_256")) {
  198. *oid = 0x00000029;
  199. }
  200. else if (!strcmp(s, "XMSSMT-SHAKE256_20/4_256")) {
  201. *oid = 0x0000002a;
  202. }
  203. else if (!strcmp(s, "XMSSMT-SHAKE256_40/2_256")) {
  204. *oid = 0x0000002b;
  205. }
  206. else if (!strcmp(s, "XMSSMT-SHAKE256_40/4_256")) {
  207. *oid = 0x0000002c;
  208. }
  209. else if (!strcmp(s, "XMSSMT-SHAKE256_40/8_256")) {
  210. *oid = 0x0000002d;
  211. }
  212. else if (!strcmp(s, "XMSSMT-SHAKE256_60/3_256")) {
  213. *oid = 0x0000002e;
  214. }
  215. else if (!strcmp(s, "XMSSMT-SHAKE256_60/6_256")) {
  216. *oid = 0x0000002f;
  217. }
  218. else if (!strcmp(s, "XMSSMT-SHAKE256_60/12_256")) {
  219. *oid = 0x00000030;
  220. }
  221. else if (!strcmp(s, "XMSSMT-SHAKE256_20/2_192")) {
  222. *oid = 0x00000031;
  223. }
  224. else if (!strcmp(s, "XMSSMT-SHAKE256_20/4_192")) {
  225. *oid = 0x00000032;
  226. }
  227. else if (!strcmp(s, "XMSSMT-SHAKE256_40/2_192")) {
  228. *oid = 0x00000033;
  229. }
  230. else if (!strcmp(s, "XMSSMT-SHAKE256_40/4_192")) {
  231. *oid = 0x00000034;
  232. }
  233. else if (!strcmp(s, "XMSSMT-SHAKE256_40/8_192")) {
  234. *oid = 0x00000035;
  235. }
  236. else if (!strcmp(s, "XMSSMT-SHAKE256_60/3_192")) {
  237. *oid = 0x00000036;
  238. }
  239. else if (!strcmp(s, "XMSSMT-SHAKE256_60/6_192")) {
  240. *oid = 0x00000037;
  241. }
  242. else if (!strcmp(s, "XMSSMT-SHAKE256_60/12_192")) {
  243. *oid = 0x00000038;
  244. }
  245. else {
  246. return -1;
  247. }
  248. return 0;
  249. }
  250. int xmss_parse_oid(xmss_params *params, const uint32_t oid)
  251. {
  252. switch (oid) {
  253. case 0x00000001:
  254. case 0x00000002:
  255. case 0x00000003:
  256. case 0x00000004:
  257. case 0x00000005:
  258. case 0x00000006:
  259. case 0x0000000d:
  260. case 0x0000000e:
  261. case 0x0000000f:
  262. params->func = XMSS_SHA2;
  263. break;
  264. case 0x00000007:
  265. case 0x00000008:
  266. case 0x00000009:
  267. params->func = XMSS_SHAKE128;
  268. break;
  269. case 0x0000000a:
  270. case 0x0000000b:
  271. case 0x0000000c:
  272. case 0x00000010:
  273. case 0x00000011:
  274. case 0x00000012:
  275. case 0x00000013:
  276. case 0x00000014:
  277. case 0x00000015:
  278. params->func = XMSS_SHAKE256;
  279. break;
  280. default:
  281. return -1;
  282. }
  283. switch (oid) {
  284. case 0x0000000d:
  285. case 0x0000000e:
  286. case 0x0000000f:
  287. case 0x00000013:
  288. case 0x00000014:
  289. case 0x00000015:
  290. params->n = 24;
  291. params->padding_len = 4;
  292. break;
  293. case 0x00000001:
  294. case 0x00000002:
  295. case 0x00000003:
  296. case 0x00000007:
  297. case 0x00000008:
  298. case 0x00000009:
  299. case 0x00000010:
  300. case 0x00000011:
  301. case 0x00000012:
  302. params->n = 32;
  303. params->padding_len = 32;
  304. break;
  305. case 0x00000004:
  306. case 0x00000005:
  307. case 0x00000006:
  308. case 0x0000000a:
  309. case 0x0000000b:
  310. case 0x0000000c:
  311. params->n = 64;
  312. params->padding_len = 64;
  313. break;
  314. default:
  315. return -1;
  316. }
  317. switch (oid) {
  318. case 0x00000001:
  319. case 0x00000004:
  320. case 0x00000007:
  321. case 0x0000000a:
  322. case 0x0000000d:
  323. case 0x00000010:
  324. case 0x00000013:
  325. params->full_height = 10;
  326. break;
  327. case 0x00000002:
  328. case 0x00000005:
  329. case 0x00000008:
  330. case 0x0000000b:
  331. case 0x0000000e:
  332. case 0x00000011:
  333. case 0x00000014:
  334. params->full_height = 16;
  335. break;
  336. case 0x00000003:
  337. case 0x00000006:
  338. case 0x00000009:
  339. case 0x0000000c:
  340. case 0x0000000f:
  341. case 0x00000012:
  342. case 0x00000015:
  343. params->full_height = 20;
  344. break;
  345. default:
  346. return -1;
  347. }
  348. params->d = 1;
  349. params->wots_w = 16;
  350. // TODO figure out sensible and legal values for this based on the above
  351. params->bds_k = 0;
  352. return xmss_xmssmt_initialize_params(params);
  353. }
  354. int xmssmt_parse_oid(xmss_params *params, const uint32_t oid)
  355. {
  356. switch (oid) {
  357. case 0x00000001:
  358. case 0x00000002:
  359. case 0x00000003:
  360. case 0x00000004:
  361. case 0x00000005:
  362. case 0x00000006:
  363. case 0x00000007:
  364. case 0x00000008:
  365. case 0x00000009:
  366. case 0x0000000a:
  367. case 0x0000000b:
  368. case 0x0000000c:
  369. case 0x0000000d:
  370. case 0x0000000e:
  371. case 0x0000000f:
  372. case 0x00000010:
  373. case 0x00000021:
  374. case 0x00000022:
  375. case 0x00000023:
  376. case 0x00000024:
  377. case 0x00000025:
  378. case 0x00000026:
  379. case 0x00000027:
  380. case 0x00000028:
  381. params->func = XMSS_SHA2;
  382. break;
  383. case 0x00000011:
  384. case 0x00000012:
  385. case 0x00000013:
  386. case 0x00000014:
  387. case 0x00000015:
  388. case 0x00000016:
  389. case 0x00000017:
  390. case 0x00000018:
  391. params->func = XMSS_SHAKE128;
  392. break;
  393. case 0x00000019:
  394. case 0x0000001a:
  395. case 0x0000001b:
  396. case 0x0000001c:
  397. case 0x0000001e:
  398. case 0x0000001d:
  399. case 0x0000001f:
  400. case 0x00000020:
  401. case 0x00000029:
  402. case 0x0000002a:
  403. case 0x0000002b:
  404. case 0x0000002c:
  405. case 0x0000002d:
  406. case 0x0000002e:
  407. case 0x0000002f:
  408. case 0x00000030:
  409. case 0x00000031:
  410. case 0x00000032:
  411. case 0x00000033:
  412. case 0x00000034:
  413. case 0x00000035:
  414. case 0x00000036:
  415. case 0x00000037:
  416. case 0x00000038:
  417. params->func = XMSS_SHAKE256;
  418. break;
  419. default:
  420. return -1;
  421. }
  422. switch (oid) {
  423. case 0x00000021:
  424. case 0x00000022:
  425. case 0x00000023:
  426. case 0x00000024:
  427. case 0x00000025:
  428. case 0x00000026:
  429. case 0x00000027:
  430. case 0x00000028:
  431. case 0x00000031:
  432. case 0x00000032:
  433. case 0x00000033:
  434. case 0x00000034:
  435. case 0x00000035:
  436. case 0x00000036:
  437. case 0x00000037:
  438. case 0x00000038:
  439. params->n = 24;
  440. params->padding_len = 4;
  441. break;
  442. case 0x00000001:
  443. case 0x00000002:
  444. case 0x00000003:
  445. case 0x00000004:
  446. case 0x00000005:
  447. case 0x00000006:
  448. case 0x00000007:
  449. case 0x00000008:
  450. case 0x00000011:
  451. case 0x00000012:
  452. case 0x00000013:
  453. case 0x00000014:
  454. case 0x00000015:
  455. case 0x00000016:
  456. case 0x00000017:
  457. case 0x00000018:
  458. case 0x00000029:
  459. case 0x0000002a:
  460. case 0x0000002b:
  461. case 0x0000002c:
  462. case 0x0000002d:
  463. case 0x0000002e:
  464. case 0x0000002f:
  465. case 0x00000030:
  466. params->n = 32;
  467. params->padding_len = 32;
  468. break;
  469. case 0x00000009:
  470. case 0x0000000a:
  471. case 0x0000000b:
  472. case 0x0000000c:
  473. case 0x0000000d:
  474. case 0x0000000e:
  475. case 0x0000000f:
  476. case 0x00000010:
  477. case 0x00000019:
  478. case 0x0000001a:
  479. case 0x0000001b:
  480. case 0x0000001c:
  481. case 0x0000001d:
  482. case 0x0000001e:
  483. case 0x0000001f:
  484. case 0x00000020:
  485. params->n = 64;
  486. params->padding_len = 64;
  487. break;
  488. default:
  489. return -1;
  490. }
  491. switch (oid) {
  492. case 0x00000001:
  493. case 0x00000002:
  494. case 0x00000009:
  495. case 0x0000000a:
  496. case 0x00000011:
  497. case 0x00000012:
  498. case 0x00000019:
  499. case 0x0000001a:
  500. case 0x00000021:
  501. case 0x00000022:
  502. case 0x00000029:
  503. case 0x0000002a:
  504. case 0x00000031:
  505. case 0x00000032:
  506. params->full_height = 20;
  507. break;
  508. case 0x00000003:
  509. case 0x00000004:
  510. case 0x00000005:
  511. case 0x0000000b:
  512. case 0x0000000c:
  513. case 0x0000000d:
  514. case 0x00000013:
  515. case 0x00000014:
  516. case 0x00000015:
  517. case 0x0000001b:
  518. case 0x0000001c:
  519. case 0x0000001d:
  520. case 0x00000023:
  521. case 0x00000024:
  522. case 0x00000025:
  523. case 0x0000002b:
  524. case 0x0000002c:
  525. case 0x0000002d:
  526. case 0x00000033:
  527. case 0x00000034:
  528. case 0x00000035:
  529. params->full_height = 40;
  530. break;
  531. case 0x00000006:
  532. case 0x00000007:
  533. case 0x00000008:
  534. case 0x0000000e:
  535. case 0x0000000f:
  536. case 0x00000010:
  537. case 0x00000016:
  538. case 0x00000017:
  539. case 0x00000018:
  540. case 0x0000001e:
  541. case 0x0000001f:
  542. case 0x00000020:
  543. case 0x00000026:
  544. case 0x00000027:
  545. case 0x00000028:
  546. case 0x0000002e:
  547. case 0x0000002f:
  548. case 0x00000030:
  549. case 0x00000036:
  550. case 0x00000037:
  551. case 0x00000038:
  552. params->full_height = 60;
  553. break;
  554. default:
  555. return -1;
  556. }
  557. switch (oid) {
  558. case 0x00000001:
  559. case 0x00000003:
  560. case 0x00000009:
  561. case 0x0000000b:
  562. case 0x00000011:
  563. case 0x00000013:
  564. case 0x00000019:
  565. case 0x0000001b:
  566. case 0x00000021:
  567. case 0x00000023:
  568. case 0x00000029:
  569. case 0x0000002b:
  570. case 0x00000031:
  571. case 0x00000033:
  572. params->d = 2;
  573. break;
  574. case 0x00000002:
  575. case 0x00000004:
  576. case 0x0000000a:
  577. case 0x0000000c:
  578. case 0x00000012:
  579. case 0x00000014:
  580. case 0x0000001a:
  581. case 0x0000001c:
  582. case 0x00000022:
  583. case 0x00000024:
  584. case 0x0000002a:
  585. case 0x0000002c:
  586. case 0x00000032:
  587. case 0x00000034:
  588. params->d = 4;
  589. break;
  590. case 0x00000005:
  591. case 0x0000000d:
  592. case 0x00000015:
  593. case 0x0000001d:
  594. case 0x00000025:
  595. case 0x0000002d:
  596. case 0x00000035:
  597. params->d = 8;
  598. break;
  599. case 0x00000006:
  600. case 0x0000000e:
  601. case 0x00000016:
  602. case 0x0000001e:
  603. case 0x00000026:
  604. case 0x0000002e:
  605. case 0x00000036:
  606. params->d = 3;
  607. break;
  608. case 0x00000007:
  609. case 0x0000000f:
  610. case 0x00000017:
  611. case 0x0000001f:
  612. case 0x00000027:
  613. case 0x0000002f:
  614. case 0x00000037:
  615. params->d = 6;
  616. break;
  617. case 0x00000008:
  618. case 0x00000010:
  619. case 0x00000018:
  620. case 0x00000020:
  621. case 0x00000028:
  622. case 0x00000030:
  623. case 0x00000038:
  624. params->d = 12;
  625. break;
  626. default:
  627. return -1;
  628. }
  629. params->wots_w = 16;
  630. // TODO figure out sensible and legal values for this based on the above
  631. params->bds_k = 0;
  632. return xmss_xmssmt_initialize_params(params);
  633. }
  634. /**
  635. * Given a params struct where the following properties have been initialized;
  636. * - full_height; the height of the complete (hyper)tree
  637. * - n; the number of bytes of hash function output
  638. * - d; the number of layers (d > 1 implies XMSSMT)
  639. * - func; one of {XMSS_SHA2, XMSS_SHAKE128, XMSS_SHAKE256}
  640. * - wots_w; the Winternitz parameter
  641. * - optionally, bds_k; the BDS traversal trade-off parameter,
  642. * this function initializes the remainder of the params structure.
  643. */
  644. int xmss_xmssmt_initialize_params(xmss_params *params)
  645. {
  646. params->tree_height = params->full_height / params->d;
  647. if (params->wots_w == 4) {
  648. params->wots_log_w = 2;
  649. params->wots_len1 = 8 * params->n / params->wots_log_w;
  650. /* len_2 = floor(log(len_1 * (w - 1)) / log(w)) + 1 */
  651. params->wots_len2 = 5;
  652. }
  653. else if (params->wots_w == 16) {
  654. params->wots_log_w = 4;
  655. params->wots_len1 = 8 * params->n / params->wots_log_w;
  656. /* len_2 = floor(log(len_1 * (w - 1)) / log(w)) + 1 */
  657. params->wots_len2 = 3;
  658. }
  659. else if (params->wots_w == 256) {
  660. params->wots_log_w = 8;
  661. params->wots_len1 = 8 * params->n / params->wots_log_w;
  662. /* len_2 = floor(log(len_1 * (w - 1)) / log(w)) + 1 */
  663. params->wots_len2 = 2;
  664. }
  665. else {
  666. return -1;
  667. }
  668. params->wots_len = params->wots_len1 + params->wots_len2;
  669. params->wots_sig_bytes = params->wots_len * params->n;
  670. if (params->d == 1) { // Assume this is XMSS, not XMSS^MT
  671. /* In XMSS, always use fixed 4 bytes for index_bytes */
  672. params->index_bytes = 4;
  673. }
  674. else {
  675. /* In XMSS^MT, round index_bytes up to nearest byte. */
  676. params->index_bytes = (params->full_height + 7) / 8;
  677. }
  678. params->sig_bytes = (params->index_bytes + params->n
  679. + params->d * params->wots_sig_bytes
  680. + params->full_height * params->n);
  681. params->pk_bytes = 2 * params->n;
  682. params->sk_bytes = xmss_xmssmt_core_sk_bytes(params);
  683. return 0;
  684. }