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.
 
 
 
 
 

102 lines
2.5 KiB

  1. /* Copyright (c) 2015 Cryptography Research, Inc.
  2. * Released under the MIT License. See LICENSE.txt for license information.
  3. */
  4. /**
  5. * @file decaf.h
  6. * @author Mike Hamburg
  7. * @brief A group of prime order p.
  8. *
  9. * The Decaf library implements cryptographic operations on a an elliptic curve
  10. * group of prime order p. It accomplishes this by using a twisted Edwards
  11. * curve (isogenous to Ed448-Goldilocks) and wiping out the cofactor.
  12. *
  13. * The formulas are all complete and have no special cases, except that
  14. * decaf_decode can fail because not every sequence of bytes is a valid group
  15. * element.
  16. *
  17. * The formulas contain no data-dependent branches, timing or memory accesses.
  18. */
  19. #ifndef __DECAF_H__
  20. #define __DECAF_H__ 1
  21. #include <stdint.h>
  22. typedef uint64_t decaf_word_t, decaf_bool_t;
  23. #define DECAF_LIMBS (512/8/sizeof(decaf_word_t))
  24. #define DECAF_SER_BYTES 56
  25. typedef struct decaf_point_s {
  26. decaf_word_t x[DECAF_LIMBS],y[DECAF_LIMBS],z[DECAF_LIMBS],t[DECAF_LIMBS];
  27. } decaf_point_t[1];
  28. static const decaf_bool_t DECAF_SUCCESS = -(decaf_bool_t)1, DECAF_FAILURE = 0;
  29. const decaf_point_t decaf_identity;
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #define API_VIS __attribute__((visibility("default")))
  34. #define WARN_UNUSED __attribute__((warn_unused_result))
  35. #define NONNULL2 __attribute__((nonnull(1,2)))
  36. #define NONNULL3 __attribute__((nonnull(1,2,3)))
  37. void decaf_encode (
  38. uint8_t ser[DECAF_SER_BYTES],
  39. const decaf_point_t pt
  40. ) API_VIS NONNULL2;
  41. decaf_bool_t decaf_decode (
  42. decaf_point_t pt,
  43. const uint8_t ser[DECAF_SER_BYTES],
  44. decaf_bool_t allow_identity
  45. ) API_VIS WARN_UNUSED NONNULL2;
  46. void decaf_add (
  47. decaf_point_t a,
  48. const decaf_point_t b,
  49. const decaf_point_t c
  50. ) API_VIS NONNULL3;
  51. void decaf_copy (
  52. decaf_point_t a,
  53. const decaf_point_t b
  54. ) API_VIS NONNULL2;
  55. decaf_bool_t decaf_eq (
  56. const decaf_point_t a,
  57. const decaf_point_t b
  58. ) API_VIS WARN_UNUSED NONNULL2;
  59. void decaf_sub (
  60. decaf_point_t a,
  61. const decaf_point_t b,
  62. const decaf_point_t c
  63. ) API_VIS NONNULL3;
  64. void decaf_add_sub (
  65. decaf_point_t a,
  66. const decaf_point_t b,
  67. const decaf_point_t c,
  68. decaf_bool_t do_sub
  69. ) API_VIS NONNULL3;
  70. void decaf_scalarmul (
  71. decaf_point_t a,
  72. const decaf_point_t b,
  73. const decaf_word_t *scalar,
  74. unsigned int scalar_words
  75. ) API_VIS NONNULL3;
  76. #undef API_VIS
  77. #undef WARN_UNUSED
  78. #undef NONNULL2
  79. #undef NONNULL3
  80. #ifdef __cplusplus
  81. }; /* extern "C" */
  82. #endif
  83. #endif /* __DECAF_H__ */