Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

126 linhas
2.8 KiB

  1. /*
  2. * Generate intermediate test vectors useful to test implementations.
  3. */
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include <string.h>
  7. #include "../wots.h"
  8. #include "../randombytes.h"
  9. #include "../params.h"
  10. #include "../fips202.h"
  11. #include "../utils.h"
  12. #include "../xmss_commons.h"
  13. #include "../xmss_core.h"
  14. void print_hex(unsigned char *buf, int len) {
  15. for (int i = 0; i < len; i++) {
  16. printf("%x%x", buf[i] / 16, buf[i] & 15);
  17. }
  18. }
  19. void print_hash(unsigned char *buf, int len) {
  20. unsigned char tmp[10];
  21. shake128(tmp, 10, buf, len);
  22. print_hex(tmp, 10);
  23. }
  24. void vectors_xmss(uint32_t oid, int mt) {
  25. xmss_params params;
  26. if (mt) {
  27. xmssmt_parse_oid(&params, oid);
  28. } else {
  29. xmss_parse_oid(&params, oid);
  30. }
  31. unsigned char seed[params.n * 3];
  32. unsigned char pk[params.pk_bytes];
  33. unsigned char sk[params.sk_bytes];
  34. unsigned char msg[1] = {37};
  35. unsigned char sm[params.sig_bytes + 1];
  36. unsigned long long smlen = 0;
  37. for (unsigned int i = 0; i < 3*params.n; i++) {
  38. seed[i] = i;
  39. }
  40. xmssmt_core_seed_keypair(&params, pk, sk, seed);
  41. ull_to_bytes(sk, params.index_bytes, 1 << (params.full_height - 1));
  42. if (mt) {
  43. xmssmt_core_sign(&params, sk, sm, &smlen, msg, 1);
  44. } else {
  45. xmss_core_sign(&params, sk, sm, &smlen, msg, 1);
  46. }
  47. if (mt) {
  48. printf("XMSSMT ");
  49. } else {
  50. printf("XMSS ");
  51. }
  52. printf("%d ", oid);
  53. print_hash(pk, params.pk_bytes);
  54. printf(" ");
  55. print_hash(sm, params.sig_bytes);
  56. printf("\n");
  57. }
  58. void vectors_wots(uint32_t oid) {
  59. xmss_params params;
  60. xmss_parse_oid(&params, oid);
  61. unsigned char sk_seed[params.n];
  62. unsigned char pub_seed[params.n];
  63. unsigned char pk[params.wots_sig_bytes];
  64. unsigned char leaf[params.n];
  65. unsigned char sig[params.wots_sig_bytes];
  66. unsigned char m[params.n];
  67. uint32_t addr[8] = {0};
  68. uint32_t addr2[8] = {0};
  69. for (unsigned int i = 0; i < 8; i++) {
  70. addr[i] = 500000000*i;
  71. addr2[i] = 400000000*i;
  72. }
  73. for (unsigned int i = 0; i < params.n; i++) {
  74. m[i] = 3*i;
  75. pub_seed[i] = 2*i;
  76. sk_seed[i] = i;
  77. }
  78. wots_pkgen(&params, pk, sk_seed, pub_seed, addr);
  79. wots_sign(&params, sig, m, sk_seed, pub_seed, addr);
  80. printf("WOTS+ %d ", oid);
  81. print_hash(pk, params.wots_sig_bytes);
  82. printf(" ");
  83. print_hash(sig, params.wots_sig_bytes);
  84. printf(" ");
  85. // Note that this garbles pk
  86. gen_leaf_wots(&params, leaf, sk_seed, pub_seed, addr, addr2);
  87. print_hash(leaf, params.n);
  88. printf("\n");
  89. }
  90. int main() {
  91. for (uint32_t oid = 1; oid <= 0x15; oid += 3) {
  92. vectors_wots(oid);
  93. }
  94. for (uint32_t oid = 2; oid <= 56; oid += 8) {
  95. vectors_xmss(oid, 1);
  96. }
  97. for (uint32_t oid = 1; oid <= 0x15; oid += 3) {
  98. vectors_xmss(oid, 0);
  99. }
  100. }