25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

110 satır
3.1 KiB

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