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.

keypair_private.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef KEYPAIR_PRIVATE_H_
  17. #define KEYPAIR_PRIVATE_H_
  18. #include "config.h"
  19. #include "ref.h"
  20. #include "cryptobox.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25. * KEX cached data
  26. */
  27. struct rspamd_cryptobox_nm {
  28. guchar nm[rspamd_cryptobox_MAX_NMBYTES];
  29. uint64_t sk_id; /* Used to store secret key id */
  30. ref_entry_t ref;
  31. };
  32. /*
  33. * Generic keypair
  34. */
  35. struct rspamd_cryptobox_keypair {
  36. guchar id[rspamd_cryptobox_HASHBYTES];
  37. enum rspamd_cryptobox_keypair_type type;
  38. enum rspamd_cryptobox_mode alg;
  39. ucl_object_t *extensions;
  40. ref_entry_t ref;
  41. };
  42. /*
  43. * NIST p256 ecdh keypair
  44. */
  45. #define RSPAMD_CRYPTOBOX_KEYPAIR_NIST(x) ((struct rspamd_cryptobox_keypair_nist *) (x))
  46. struct rspamd_cryptobox_keypair_nist {
  47. struct rspamd_cryptobox_keypair parent;
  48. guchar sk[32];
  49. guchar pk[65];
  50. };
  51. /*
  52. * Curve25519 ecdh keypair
  53. */
  54. #define RSPAMD_CRYPTOBOX_KEYPAIR_25519(x) ((struct rspamd_cryptobox_keypair_25519 *) (x))
  55. struct rspamd_cryptobox_keypair_25519 {
  56. struct rspamd_cryptobox_keypair parent;
  57. guchar sk[32];
  58. guchar pk[32];
  59. };
  60. /*
  61. * NIST p256 ecdsa keypair
  62. */
  63. #define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_NIST(x) ((struct rspamd_cryptobox_keypair_sig_nist *) (x))
  64. struct rspamd_cryptobox_keypair_sig_nist {
  65. struct rspamd_cryptobox_keypair parent;
  66. guchar sk[32];
  67. guchar pk[65];
  68. };
  69. /*
  70. * Ed25519 keypair
  71. */
  72. #define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_25519(x) ((struct rspamd_cryptobox_keypair_sig_25519 *) (x))
  73. struct rspamd_cryptobox_keypair_sig_25519 {
  74. struct rspamd_cryptobox_keypair parent;
  75. guchar sk[64];
  76. guchar pk[32];
  77. };
  78. /*
  79. * Public component of the keypair
  80. */
  81. struct rspamd_cryptobox_pubkey {
  82. guchar id[rspamd_cryptobox_HASHBYTES];
  83. struct rspamd_cryptobox_nm *nm;
  84. enum rspamd_cryptobox_keypair_type type;
  85. enum rspamd_cryptobox_mode alg;
  86. ref_entry_t ref;
  87. };
  88. /*
  89. * Public p256 ecdh
  90. */
  91. #define RSPAMD_CRYPTOBOX_PUBKEY_NIST(x) ((struct rspamd_cryptobox_pubkey_nist *) (x))
  92. struct rspamd_cryptobox_pubkey_nist {
  93. struct rspamd_cryptobox_pubkey parent;
  94. guchar pk[65];
  95. };
  96. /*
  97. * Public curve25519 ecdh
  98. */
  99. #define RSPAMD_CRYPTOBOX_PUBKEY_25519(x) ((struct rspamd_cryptobox_pubkey_25519 *) (x))
  100. struct rspamd_cryptobox_pubkey_25519 {
  101. struct rspamd_cryptobox_pubkey parent;
  102. guchar pk[32];
  103. };
  104. /*
  105. * Public p256 ecdsa
  106. */
  107. #define RSPAMD_CRYPTOBOX_PUBKEY_SIG_NIST(x) ((struct rspamd_cryptobox_pubkey_sig_nist *) (x))
  108. struct rspamd_cryptobox_pubkey_sig_nist {
  109. struct rspamd_cryptobox_pubkey parent;
  110. guchar pk[65];
  111. };
  112. /*
  113. * Public ed25519
  114. */
  115. #define RSPAMD_CRYPTOBOX_PUBKEY_SIG_25519(x) ((struct rspamd_cryptobox_pubkey_sig_25519 *) (x))
  116. struct rspamd_cryptobox_pubkey_sig_25519 {
  117. struct rspamd_cryptobox_pubkey parent;
  118. guchar pk[32];
  119. };
  120. void rspamd_cryptobox_nm_dtor(struct rspamd_cryptobox_nm *nm);
  121. void rspamd_cryptobox_keypair_dtor(struct rspamd_cryptobox_keypair *kp);
  122. void rspamd_cryptobox_pubkey_dtor(struct rspamd_cryptobox_pubkey *p);
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif /* KEYPAIR_PRIVATE_H_ */