109 lines
2.8 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 private key. */
  29. typedef struct {
  30. decaf_448_symmetric_key_t sym;
  31. decaf_448_scalar_t secret_scalar;
  32. decaf_448_public_key_t pub;
  33. } decaf_448_private_key_t[1];
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. * @brief Derive a key from its compressed form.
  39. * @param [out] privkey The derived private key.
  40. * @param [in] proto The compressed or proto-key, which must be 32 random bytes.
  41. */
  42. void decaf_448_derive_private_key (
  43. decaf_448_private_key_t priv,
  44. const decaf_448_symmetric_key_t proto
  45. ) NONNULL2 API_VIS;
  46. /**
  47. * @brief Destroy a private key.
  48. */
  49. void decaf_448_destroy_private_key (
  50. decaf_448_private_key_t priv
  51. ) NONNULL1 API_VIS;
  52. /**
  53. * @brief Convert a private key to a public one.
  54. * @param [out] pub The extracted private key.
  55. * @param [in] priv The private key.
  56. */
  57. void decaf_448_private_to_public (
  58. decaf_448_public_key_t pub,
  59. const decaf_448_private_key_t priv
  60. ) NONNULL2 API_VIS;
  61. /**
  62. * @brief Compute a Diffie-Hellman shared secret.
  63. *
  64. * This is an example routine; real protocols would use something
  65. * protocol-specific.
  66. *
  67. * @param [out] shared A buffer to store the shared secret.
  68. * @param [in] shared_bytes The size of the buffer.
  69. * @param [in] my_privkey My private key.
  70. * @param [in] your_pubkey Your public key.
  71. *
  72. * @retval DECAF_SUCCESS Key exchange was successful.
  73. * @retval DECAF_FAILURE Key exchange failed.
  74. */
  75. decaf_bool_t
  76. decaf_448_shared_secret (
  77. uint8_t *shared,
  78. size_t shared_bytes,
  79. const decaf_448_private_key_t my_privkey,
  80. const decaf_448_public_key_t your_pubkey
  81. ) NONNULL134 WARN_UNUSED API_VIS;
  82. #undef API_VIS
  83. #undef WARN_UNUSED
  84. #undef NONNULL1
  85. #undef NONNULL2
  86. #undef NONNULL3
  87. #undef NONNULL134
  88. #undef NONNULL5
  89. #ifdef __cplusplus
  90. }; /* extern "C" */
  91. #endif
  92. #endif /* __DECAF_CRYPTO_H__ */