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.
 
 
 
 
 

172 lines
4.4 KiB

  1. /**
  2. * @file decaf_crypto.h
  3. * @copyright
  4. * Copyright (c) 2015 Cryptography Research, Inc. \n
  5. * Released under the MIT License. See LICENSE.txt for license information.
  6. * @author Mike Hamburg
  7. * @brief Decaf cyrpto routines.
  8. * @warning Experimental! The names, parameter orders etc are likely to change.
  9. */
  10. #ifndef __DECAF_CRYPTO_H__
  11. #define __DECAF_CRYPTO_H__ 1
  12. #include "decaf.h"
  13. #include "shake.h"
  14. #define DECAF_448_SYMMETRIC_KEY_BYTES 32
  15. /** @cond internal */
  16. #define API_VIS __attribute__((visibility("default")))
  17. #define WARN_UNUSED __attribute__((warn_unused_result))
  18. #define NONNULL1 __attribute__((nonnull(1)))
  19. #define NONNULL2 __attribute__((nonnull(1,2)))
  20. #define NONNULL3 __attribute__((nonnull(1,2,3)))
  21. #define NONNULL134 __attribute__((nonnull(1,3,4)))
  22. #define NONNULL5 __attribute__((nonnull(1,2,3,4,5)))
  23. /** @endcond */
  24. /** A symmetric key, the compressed point of a private key. */
  25. typedef unsigned char decaf_448_symmetric_key_t[DECAF_448_SYMMETRIC_KEY_BYTES];
  26. /** An encoded public key. */
  27. typedef unsigned char decaf_448_public_key_t[DECAF_448_SER_BYTES];
  28. /** A signature. */
  29. typedef unsigned char decaf_448_signature_t[DECAF_448_SER_BYTES + DECAF_448_SCALAR_BYTES];
  30. /** A private key. */
  31. typedef struct {
  32. decaf_448_symmetric_key_t sym;
  33. decaf_448_scalar_t secret_scalar;
  34. decaf_448_public_key_t pub;
  35. } decaf_448_private_key_t[1];
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /**
  40. * @brief Derive a key from its compressed form.
  41. * @param [out] privkey The derived private key.
  42. * @param [in] proto The compressed or proto-key, which must be 32 random bytes.
  43. */
  44. void decaf_448_derive_private_key (
  45. decaf_448_private_key_t priv,
  46. const decaf_448_symmetric_key_t proto
  47. ) NONNULL2 API_VIS;
  48. /**
  49. * @brief Destroy a private key.
  50. */
  51. void decaf_448_destroy_private_key (
  52. decaf_448_private_key_t priv
  53. ) NONNULL1 API_VIS;
  54. /**
  55. * @brief Convert a private key to a public one.
  56. * @param [out] pub The extracted private key.
  57. * @param [in] priv The private key.
  58. */
  59. void decaf_448_private_to_public (
  60. decaf_448_public_key_t pub,
  61. const decaf_448_private_key_t priv
  62. ) NONNULL2 API_VIS;
  63. /**
  64. * @brief Compute a Diffie-Hellman shared secret.
  65. *
  66. * This is an example routine; real protocols would use something
  67. * protocol-specific.
  68. *
  69. * @param [out] shared A buffer to store the shared secret.
  70. * @param [in] shared_bytes The size of the buffer.
  71. * @param [in] my_privkey My private key.
  72. * @param [in] your_pubkey Your public key.
  73. *
  74. * @retval DECAF_SUCCESS Key exchange was successful.
  75. * @retval DECAF_FAILURE Key exchange failed.
  76. */
  77. decaf_bool_t
  78. decaf_448_shared_secret (
  79. uint8_t *shared,
  80. size_t shared_bytes,
  81. const decaf_448_private_key_t my_privkey,
  82. const decaf_448_public_key_t your_pubkey
  83. ) NONNULL134 WARN_UNUSED API_VIS;
  84. /**
  85. * @brief Sign a message from its SHAKE context.
  86. *
  87. * @param [out] sig The signature.
  88. * @param [in] priv Your private key.
  89. * @param [in] shake A SHAKE256 context with the message.
  90. */
  91. void
  92. decaf_448_sign_shake (
  93. decaf_448_signature_t sig,
  94. const decaf_448_private_key_t priv,
  95. const keccak_sponge_t shake
  96. ) NONNULL3 API_VIS;
  97. /**
  98. * @brief Sign a message from its SHAKE context.
  99. *
  100. * @param [out] sig The signature.
  101. * @param [in] priv Your private key.
  102. * @param [in] message The message.
  103. * @param [in] message_len The message's length.
  104. */
  105. void
  106. decaf_448_sign (
  107. decaf_448_signature_t sig,
  108. const decaf_448_private_key_t priv,
  109. const unsigned char *message,
  110. size_t message_len
  111. ) NONNULL3 API_VIS;
  112. /**
  113. * @brief Verify a signed message from its SHAKE context.
  114. *
  115. * @param [in] sig The signature.
  116. * @param [in] pub The public key.
  117. * @param [in] shake A SHAKE256 context with the message.
  118. */
  119. decaf_bool_t
  120. decaf_448_verify_shake (
  121. const decaf_448_signature_t sig,
  122. const decaf_448_public_key_t pub,
  123. const keccak_sponge_t shake
  124. ) NONNULL3 API_VIS WARN_UNUSED;
  125. /**
  126. * @brief Verify a signed message.
  127. *
  128. * @param [in] sig The signature.
  129. * @param [in] pub The public key.
  130. * @param [in] message The message.
  131. * @param [in] message_len The message's length.
  132. */
  133. decaf_bool_t
  134. decaf_448_verify (
  135. const decaf_448_signature_t sig,
  136. const decaf_448_public_key_t pub,
  137. const unsigned char *message,
  138. size_t message_len
  139. ) NONNULL3 API_VIS WARN_UNUSED;
  140. #undef API_VIS
  141. #undef WARN_UNUSED
  142. #undef NONNULL1
  143. #undef NONNULL2
  144. #undef NONNULL3
  145. #undef NONNULL134
  146. #undef NONNULL5
  147. #ifdef __cplusplus
  148. }; /* extern "C" */
  149. #endif
  150. #endif /* __DECAF_CRYPTO_H__ */