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ů.

110 řádky
3.5 KiB

  1. /*
  2. xmss_fast.h version 20160722
  3. Andreas Hülsing
  4. Joost Rijneveld
  5. Public domain.
  6. */
  7. #include "wots.h"
  8. #ifndef XMSS_H
  9. #define XMSS_H
  10. typedef struct{
  11. unsigned int level;
  12. unsigned long long subtree;
  13. unsigned int subleaf;
  14. } leafaddr;
  15. typedef struct{
  16. wots_params wots_par;
  17. unsigned int n;
  18. unsigned int h;
  19. unsigned int k;
  20. } xmss_params;
  21. typedef struct{
  22. xmss_params xmss_par;
  23. unsigned int n;
  24. unsigned int h;
  25. unsigned int d;
  26. unsigned int index_len;
  27. } xmssmt_params;
  28. typedef struct{
  29. unsigned int h;
  30. unsigned int next_idx;
  31. unsigned int stackusage;
  32. unsigned char completed;
  33. unsigned char *node;
  34. } treehash_inst;
  35. typedef struct {
  36. unsigned char *stack;
  37. unsigned int stackoffset;
  38. unsigned char *stacklevels;
  39. unsigned char *auth;
  40. unsigned char *keep;
  41. treehash_inst *treehash;
  42. unsigned char *retain;
  43. unsigned int next_leaf;
  44. } bds_state;
  45. /**
  46. * Initialize BDS state struct
  47. * parameter names are the same as used in the description of the BDS traversal
  48. */
  49. void xmss_set_bds_state(bds_state *state, unsigned char *stack, int stackoffset, unsigned char *stacklevels, unsigned char *auth, unsigned char *keep, treehash_inst *treehash, unsigned char *retain, int next_leaf);
  50. /**
  51. * Initializes parameter set.
  52. * Needed, for any of the other methods.
  53. */
  54. int xmss_set_params(xmss_params *params, int n, int h, int w, int k);
  55. /**
  56. * Initialize xmssmt_params struct
  57. * parameter names are the same as in the draft
  58. *
  59. * Especially h is the total tree height, i.e. the XMSS trees have height h/d
  60. */
  61. int xmssmt_set_params(xmssmt_params *params, int n, int h, int d, int w, int k);
  62. /**
  63. * Generates a XMSS key pair for a given parameter set.
  64. * Format sk: [(32bit) idx || SK_SEED || SK_PRF || PUB_SEED || root]
  65. * Format pk: [root || PUB_SEED] omitting algo oid.
  66. */
  67. int xmss_keypair(unsigned char *pk, unsigned char *sk, bds_state *state, xmss_params *params);
  68. /**
  69. * Signs a message.
  70. * Returns
  71. * 1. an array containing the signature followed by the message AND
  72. * 2. an updated secret key!
  73. *
  74. */
  75. int xmss_sign(unsigned char *sk, bds_state *state, unsigned char *sig_msg, unsigned long long *sig_msg_len, const unsigned char *msg,unsigned long long msglen, const xmss_params *params);
  76. /**
  77. * Verifies a given message signature pair under a given public key.
  78. *
  79. * Note: msg and msglen are pure outputs which carry the message in case verification succeeds. The (input) message is assumed to be within sig_msg which has the form (sig||msg).
  80. */
  81. int xmss_sign_open(unsigned char *msg,unsigned long long *msglen, const unsigned char *sig_msg,unsigned long long sig_msg_len, const unsigned char *pk, const xmss_params *params);
  82. /*
  83. * Generates a XMSSMT key pair for a given parameter set.
  84. * Format sk: [(ceil(h/8) bit) idx || SK_SEED || SK_PRF || PUB_SEED || root]
  85. * Format pk: [root || PUB_SEED] omitting algo oid.
  86. */
  87. int xmssmt_keypair(unsigned char *pk, unsigned char *sk, bds_state *states, unsigned char *wots_sigs, xmssmt_params *params);
  88. /**
  89. * Signs a message.
  90. * Returns
  91. * 1. an array containing the signature followed by the message AND
  92. * 2. an updated secret key!
  93. *
  94. */
  95. int xmssmt_sign(unsigned char *sk, bds_state *state, unsigned char *wots_sigs, unsigned char *sig_msg, unsigned long long *sig_msg_len, const unsigned char *msg, unsigned long long msglen, const xmssmt_params *params);
  96. /**
  97. * Verifies a given message signature pair under a given public key.
  98. */
  99. int xmssmt_sign_open(unsigned char *msg, unsigned long long *msglen, const unsigned char *sig_msg, unsigned long long sig_msg_len, const unsigned char *pk, const xmssmt_params *params);
  100. #endif