xmss_fast.h 3.6 KB

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