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.

111 lines
3.5 KiB

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