ec.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import absolute_import, division, print_function
  5. INCLUDES = """
  6. #include <openssl/ec.h>
  7. #include <openssl/obj_mac.h>
  8. """
  9. TYPES = """
  10. static const int Cryptography_HAS_EC2M;
  11. static const int OPENSSL_EC_NAMED_CURVE;
  12. typedef ... EC_KEY;
  13. typedef ... EC_GROUP;
  14. typedef ... EC_POINT;
  15. typedef ... EC_METHOD;
  16. typedef struct {
  17. int nid;
  18. const char *comment;
  19. } EC_builtin_curve;
  20. typedef enum {
  21. POINT_CONVERSION_COMPRESSED,
  22. POINT_CONVERSION_UNCOMPRESSED,
  23. ...
  24. } point_conversion_form_t;
  25. """
  26. FUNCTIONS = """
  27. void EC_GROUP_free(EC_GROUP *);
  28. EC_GROUP *EC_GROUP_new_by_curve_name(int);
  29. int EC_GROUP_get_degree(const EC_GROUP *);
  30. const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
  31. const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
  32. int EC_GROUP_get_curve_name(const EC_GROUP *);
  33. size_t EC_get_builtin_curves(EC_builtin_curve *, size_t);
  34. EC_KEY *EC_KEY_new(void);
  35. void EC_KEY_free(EC_KEY *);
  36. EC_KEY *EC_KEY_new_by_curve_name(int);
  37. const EC_GROUP *EC_KEY_get0_group(const EC_KEY *);
  38. int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *, BN_CTX *);
  39. int EC_KEY_set_group(EC_KEY *, const EC_GROUP *);
  40. const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);
  41. int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);
  42. const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);
  43. int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);
  44. void EC_KEY_set_asn1_flag(EC_KEY *, int);
  45. int EC_KEY_generate_key(EC_KEY *);
  46. int EC_KEY_set_public_key_affine_coordinates(EC_KEY *, BIGNUM *, BIGNUM *);
  47. EC_POINT *EC_POINT_new(const EC_GROUP *);
  48. void EC_POINT_free(EC_POINT *);
  49. void EC_POINT_clear_free(EC_POINT *);
  50. EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);
  51. int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
  52. const BIGNUM *, const BIGNUM *, BN_CTX *);
  53. int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *,
  54. const EC_POINT *, BIGNUM *, BIGNUM *, BN_CTX *);
  55. int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
  56. const BIGNUM *, int, BN_CTX *);
  57. int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
  58. const BIGNUM *, const BIGNUM *, BN_CTX *);
  59. int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *,
  60. const EC_POINT *, BIGNUM *, BIGNUM *, BN_CTX *);
  61. int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
  62. const BIGNUM *, int, BN_CTX *);
  63. size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *,
  64. point_conversion_form_t,
  65. unsigned char *, size_t, BN_CTX *);
  66. int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
  67. const unsigned char *, size_t, BN_CTX *);
  68. int EC_POINT_add(const EC_GROUP *, EC_POINT *, const EC_POINT *,
  69. const EC_POINT *, BN_CTX *);
  70. int EC_POINT_dbl(const EC_GROUP *, EC_POINT *, const EC_POINT *, BN_CTX *);
  71. int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
  72. int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
  73. int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
  74. int EC_POINT_cmp(
  75. const EC_GROUP *, const EC_POINT *, const EC_POINT *, BN_CTX *);
  76. int EC_POINT_mul(const EC_GROUP *, EC_POINT *, const BIGNUM *,
  77. const EC_POINT *, const BIGNUM *, BN_CTX *);
  78. int EC_METHOD_get_field_type(const EC_METHOD *);
  79. const char *EC_curve_nid2nist(int);
  80. int EC_GROUP_get_asn1_flag(const EC_GROUP *);
  81. """
  82. CUSTOMIZATIONS = """
  83. #if defined(OPENSSL_NO_EC2M)
  84. static const long Cryptography_HAS_EC2M = 0;
  85. int (*EC_POINT_set_affine_coordinates_GF2m)(const EC_GROUP *, EC_POINT *,
  86. const BIGNUM *, const BIGNUM *, BN_CTX *) = NULL;
  87. int (*EC_POINT_get_affine_coordinates_GF2m)(const EC_GROUP *,
  88. const EC_POINT *, BIGNUM *, BIGNUM *, BN_CTX *) = NULL;
  89. int (*EC_POINT_set_compressed_coordinates_GF2m)(const EC_GROUP *, EC_POINT *,
  90. const BIGNUM *, int, BN_CTX *) = NULL;
  91. #else
  92. static const long Cryptography_HAS_EC2M = 1;
  93. #endif
  94. """