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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <stdint.h>
  2. #include "params.h"
  3. #include "xmss_core.h"
  4. /* This file provides wrapper functions that take keys that include OIDs to
  5. identify the parameter set to be used. After setting the parameters accordingly
  6. it falls back to the regular XMSS core functions. */
  7. int xmss_keypair(unsigned char *pk, unsigned char *sk, const uint32_t oid)
  8. {
  9. xmss_params params;
  10. unsigned int i;
  11. if (xmss_parse_oid(&params, oid)) {
  12. return 1;
  13. }
  14. for (i = 0; i < XMSS_OID_LEN; i++) {
  15. pk[i] = (oid >> (8 * i)) & 0xFF;
  16. /* For an implementation that uses runtime parameters, it is crucial
  17. that the OID is part of the secret key as well;
  18. i.e. not just for interoperability, but also for internal use. */
  19. sk[i] = (oid >> (8 * i)) & 0xFF;
  20. }
  21. return xmss_core_keypair(&params, pk + XMSS_OID_LEN, sk + XMSS_OID_LEN);
  22. }
  23. int xmss_sign(unsigned char *sk,
  24. unsigned char *sm, unsigned long long *smlen,
  25. const unsigned char *m, unsigned long long mlen)
  26. {
  27. xmss_params params;
  28. uint32_t oid = 0;
  29. unsigned int i;
  30. for (i = 0; i < XMSS_OID_LEN; i++) {
  31. oid |= sk[i] << (i * 8);
  32. }
  33. if (xmss_parse_oid(&params, oid)) {
  34. return 1;
  35. }
  36. return xmss_core_sign(&params, sk + XMSS_OID_LEN, sm, smlen, m, mlen);
  37. }
  38. int xmss_sign_open(unsigned char *m, unsigned long long *mlen,
  39. const unsigned char *sm, unsigned long long smlen,
  40. const unsigned char *pk)
  41. {
  42. xmss_params params;
  43. uint32_t oid = 0;
  44. unsigned int i;
  45. for (i = 0; i < XMSS_OID_LEN; i++) {
  46. oid |= pk[i] << (i * 8);
  47. }
  48. if (xmss_parse_oid(&params, oid)) {
  49. return 1;
  50. }
  51. return xmss_core_sign_open(&params, m, mlen, sm, smlen, pk + XMSS_OID_LEN);
  52. }
  53. int xmssmt_keypair(unsigned char *pk, unsigned char *sk, const uint32_t oid)
  54. {
  55. xmss_params params;
  56. unsigned int i;
  57. if (xmssmt_parse_oid(&params, oid)) {
  58. return 1;
  59. }
  60. for (i = 0; i < XMSS_OID_LEN; i++) {
  61. pk[i] = (oid >> (8 * i)) & 0xFF;
  62. sk[i] = (oid >> (8 * i)) & 0xFF;
  63. }
  64. return xmssmt_core_keypair(&params, pk + XMSS_OID_LEN, sk + XMSS_OID_LEN);
  65. }
  66. int xmssmt_sign(unsigned char *sk,
  67. unsigned char *sm, unsigned long long *smlen,
  68. const unsigned char *m, unsigned long long mlen)
  69. {
  70. xmss_params params;
  71. uint32_t oid = 0;
  72. unsigned int i;
  73. for (i = 0; i < XMSS_OID_LEN; i++) {
  74. oid |= sk[i] << (i * 8);
  75. }
  76. if (xmssmt_parse_oid(&params, oid)) {
  77. return 1;
  78. }
  79. return xmssmt_core_sign(&params, sk + XMSS_OID_LEN, sm, smlen, m, mlen);
  80. }
  81. int xmssmt_sign_open(unsigned char *m, unsigned long long *mlen,
  82. const unsigned char *sm, unsigned long long smlen,
  83. const unsigned char *pk)
  84. {
  85. xmss_params params;
  86. uint32_t oid = 0;
  87. unsigned int i;
  88. for (i = 0; i < XMSS_OID_LEN; i++) {
  89. oid |= pk[i] << (i * 8);
  90. }
  91. if (xmssmt_parse_oid(&params, oid)) {
  92. return 1;
  93. }
  94. return xmssmt_core_sign_open(&params, m, mlen, sm, smlen, pk + XMSS_OID_LEN);
  95. }