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.
 
 
 
 
 

179 lines
4.8 KiB

  1. /**
  2. * @file decaf/crypto_448.h
  3. * @author Mike Hamburg
  4. *
  5. * @copyright
  6. * Copyright (c) 2015-2016 Cryptography Research, Inc. \n
  7. * Released under the MIT License. See LICENSE.txt for license information.
  8. *
  9. * Example Decaf crypto routines.
  10. * @warning These are merely examples, though they ought to be secure. But real
  11. * protocols will decide differently on magic numbers, formats, which items to
  12. * hash, etc.
  13. * @warning Experimental! The names, parameter orders etc are likely to change.
  14. *
  15. * @warning This file was automatically generated in Python.
  16. * Please do not edit it.
  17. */
  18. #ifndef __DECAF_CRYPTO_448_H__
  19. #define __DECAF_CRYPTO_448_H__ 1
  20. #include <decaf/decaf_448.h>
  21. #include <decaf/strobe.h>
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /** Number of bytes for a symmetric key (expanded to full key) */
  26. #define DECAF_448_SYMMETRIC_KEY_BYTES 32
  27. /** A symmetric key, the compressed point of a private key. */
  28. typedef unsigned char decaf_448_symmetric_key_t[DECAF_448_SYMMETRIC_KEY_BYTES];
  29. /** An encoded public key. */
  30. typedef unsigned char decaf_448_public_key_t[DECAF_448_SER_BYTES];
  31. /** A signature. */
  32. typedef unsigned char decaf_448_signature_t[DECAF_448_SER_BYTES + DECAF_448_SCALAR_BYTES];
  33. typedef struct {
  34. /** @cond internal */
  35. /** The symmetric key from which everything is expanded */
  36. decaf_448_symmetric_key_t sym;
  37. /** The scalar x */
  38. decaf_448_scalar_t secret_scalar;
  39. /** x*Base */
  40. decaf_448_public_key_t pub;
  41. /** @endcond */
  42. } /** Private key structure for pointers. */
  43. decaf_448_private_key_s,
  44. /** A private key (gmp array[1] style). */
  45. decaf_448_private_key_t[1];
  46. /**
  47. * Derive a key from its compressed form.
  48. * @param [out] priv The derived private key.
  49. * @param [in] proto The compressed or proto-key, which must be 32 random bytes.
  50. */
  51. void decaf_448_derive_private_key (
  52. decaf_448_private_key_t priv,
  53. const decaf_448_symmetric_key_t proto
  54. ) NONNULL API_VIS;
  55. /**
  56. * Destroy a private key.
  57. */
  58. void decaf_448_destroy_private_key (
  59. decaf_448_private_key_t priv
  60. ) NONNULL API_VIS;
  61. /**
  62. * Convert a private key to a public one.
  63. * @param [out] pub The extracted private key.
  64. * @param [in] priv The private key.
  65. */
  66. void decaf_448_private_to_public (
  67. decaf_448_public_key_t pub,
  68. const decaf_448_private_key_t priv
  69. ) NONNULL API_VIS;
  70. /**
  71. * Compute a Diffie-Hellman shared secret.
  72. *
  73. * This is an example routine; real protocols would use something
  74. * protocol-specific.
  75. *
  76. * @param [out] shared A buffer to store the shared secret.
  77. * @param [in] shared_bytes The size of the buffer.
  78. * @param [in] my_privkey My private key.
  79. * @param [in] your_pubkey Your public key.
  80. * @param [in] me_first Direction flag to break symmetry.
  81. *
  82. * @retval DECAF_SUCCESS Key exchange was successful.
  83. * @retval DECAF_FAILURE Key exchange failed.
  84. */
  85. decaf_error_t
  86. decaf_448_shared_secret (
  87. uint8_t *shared,
  88. size_t shared_bytes,
  89. const decaf_448_private_key_t my_privkey,
  90. const decaf_448_public_key_t your_pubkey,
  91. int me_first
  92. ) NONNULL WARN_UNUSED API_VIS;
  93. /**
  94. * Sign a message from a STROBE context.
  95. *
  96. * @param [out] sig The signature.
  97. * @param [in] priv Your private key.
  98. * @param [in] strobe A STROBE context with the message.
  99. */
  100. void
  101. decaf_448_sign_strobe (
  102. keccak_strobe_t strobe,
  103. decaf_448_signature_t sig,
  104. const decaf_448_private_key_t priv
  105. ) NONNULL API_VIS;
  106. /**
  107. * Sign a message.
  108. *
  109. * @param [out] sig The signature.
  110. * @param [in] priv Your private key.
  111. * @param [in] message The message.
  112. * @param [in] message_len The message's length.
  113. */
  114. void
  115. decaf_448_sign (
  116. decaf_448_signature_t sig,
  117. const decaf_448_private_key_t priv,
  118. const unsigned char *message,
  119. size_t message_len
  120. ) NONNULL API_VIS;
  121. /**
  122. * Verify a signed message from its STROBE context.
  123. *
  124. * @param [in] sig The signature.
  125. * @param [in] pub The public key.
  126. * @param [in] strobe A STROBE context with the message.
  127. *
  128. * @return DECAF_SUCCESS The signature verified successfully.
  129. * @return DECAF_FAILURE The signature did not verify successfully.
  130. */
  131. decaf_error_t
  132. decaf_448_verify_strobe (
  133. keccak_strobe_t strobe,
  134. const decaf_448_signature_t sig,
  135. const decaf_448_public_key_t pub
  136. ) NONNULL API_VIS WARN_UNUSED;
  137. /**
  138. * Verify a signed message.
  139. *
  140. * @param [in] sig The signature.
  141. * @param [in] pub The public key.
  142. * @param [in] message The message.
  143. * @param [in] message_len The message's length.
  144. *
  145. * @return DECAF_SUCCESS The signature verified successfully.
  146. * @return DECAF_FAILURE The signature did not verify successfully.
  147. */
  148. decaf_error_t
  149. decaf_448_verify (
  150. const decaf_448_signature_t sig,
  151. const decaf_448_public_key_t pub,
  152. const unsigned char *message,
  153. size_t message_len
  154. ) NONNULL API_VIS WARN_UNUSED;
  155. #ifdef __cplusplus
  156. } /* extern "C" */
  157. #endif
  158. #endif /* __DECAF_CRYPTO_448_H__ */