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 5from __future__ import absolute_import, division, print_function 6 7INCLUDES = """ 8#include <openssl/ec.h> 9#include <openssl/obj_mac.h> 10""" 11 12TYPES = """ 13static const int Cryptography_HAS_EC; 14static const int Cryptography_HAS_EC2M; 15static const int Cryptography_HAS_EC_1_0_2; 16 17static const int OPENSSL_EC_NAMED_CURVE; 18 19typedef ... EC_KEY; 20typedef ... EC_GROUP; 21typedef ... EC_POINT; 22typedef ... EC_METHOD; 23typedef struct { 24 int nid; 25 const char *comment; 26} EC_builtin_curve; 27typedef enum { 28 POINT_CONVERSION_COMPRESSED, 29 POINT_CONVERSION_UNCOMPRESSED, 30 ... 31} point_conversion_form_t; 32""" 33 34FUNCTIONS = """ 35void EC_GROUP_free(EC_GROUP *); 36 37EC_GROUP *EC_GROUP_new_by_curve_name(int); 38 39int EC_GROUP_get_degree(const EC_GROUP *); 40 41const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *); 42const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *); 43int EC_GROUP_get_curve_name(const EC_GROUP *); 44 45size_t EC_get_builtin_curves(EC_builtin_curve *, size_t); 46 47EC_KEY *EC_KEY_new(void); 48void EC_KEY_free(EC_KEY *); 49 50EC_KEY *EC_KEY_new_by_curve_name(int); 51const EC_GROUP *EC_KEY_get0_group(const EC_KEY *); 52int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *, BN_CTX *); 53int EC_KEY_set_group(EC_KEY *, const EC_GROUP *); 54const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *); 55int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *); 56const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *); 57int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *); 58void EC_KEY_set_asn1_flag(EC_KEY *, int); 59int EC_KEY_generate_key(EC_KEY *); 60int EC_KEY_set_public_key_affine_coordinates(EC_KEY *, BIGNUM *, BIGNUM *); 61 62EC_POINT *EC_POINT_new(const EC_GROUP *); 63void EC_POINT_free(EC_POINT *); 64void EC_POINT_clear_free(EC_POINT *); 65EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *); 66 67int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *, 68 const BIGNUM *, const BIGNUM *, BN_CTX *); 69 70int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, 71 const EC_POINT *, BIGNUM *, BIGNUM *, BN_CTX *); 72 73int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *, 74 const BIGNUM *, int, BN_CTX *); 75 76int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *, 77 const BIGNUM *, const BIGNUM *, BN_CTX *); 78 79int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, 80 const EC_POINT *, BIGNUM *, BIGNUM *, BN_CTX *); 81 82int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *, 83 const BIGNUM *, int, BN_CTX *); 84 85size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, 86 point_conversion_form_t, 87 unsigned char *, size_t, BN_CTX *); 88 89int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *, 90 const unsigned char *, size_t, BN_CTX *); 91 92int EC_POINT_add(const EC_GROUP *, EC_POINT *, const EC_POINT *, 93 const EC_POINT *, BN_CTX *); 94 95int EC_POINT_dbl(const EC_GROUP *, EC_POINT *, const EC_POINT *, BN_CTX *); 96int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 97int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *); 98int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); 99 100int EC_POINT_cmp( 101 const EC_GROUP *, const EC_POINT *, const EC_POINT *, BN_CTX *); 102 103int EC_POINT_mul(const EC_GROUP *, EC_POINT *, const BIGNUM *, 104 const EC_POINT *, const BIGNUM *, BN_CTX *); 105 106int EC_METHOD_get_field_type(const EC_METHOD *); 107 108const char *EC_curve_nid2nist(int); 109""" 110 111CUSTOMIZATIONS = """ 112static const long Cryptography_HAS_EC = 1; 113 114#if defined(OPENSSL_NO_EC2M) 115static const long Cryptography_HAS_EC2M = 0; 116 117int (*EC_POINT_set_affine_coordinates_GF2m)(const EC_GROUP *, EC_POINT *, 118 const BIGNUM *, const BIGNUM *, BN_CTX *) = NULL; 119 120int (*EC_POINT_get_affine_coordinates_GF2m)(const EC_GROUP *, 121 const EC_POINT *, BIGNUM *, BIGNUM *, BN_CTX *) = NULL; 122 123int (*EC_POINT_set_compressed_coordinates_GF2m)(const EC_GROUP *, EC_POINT *, 124 const BIGNUM *, int, BN_CTX *) = NULL; 125#else 126static const long Cryptography_HAS_EC2M = 1; 127#endif 128 129#if (!CRYPTOGRAPHY_IS_LIBRESSL && CRYPTOGRAPHY_OPENSSL_LESS_THAN_102) 130static const long Cryptography_HAS_EC_1_0_2 = 0; 131const char *(*EC_curve_nid2nist)(int) = NULL; 132#else 133static const long Cryptography_HAS_EC_1_0_2 = 1; 134#endif 135""" 136