| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <openssl/evp.h> |
| 19 |
|
| 20 |
#include "crypto/s2n_hash.h" |
| 21 |
#include "stuffer/s2n_stuffer.h" |
| 22 |
#include "tls/s2n_kex_data.h" |
| 23 |
#include "tls/s2n_tls_parameters.h" |
| 24 |
#include "utils/s2n_safety.h" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#define SECP256R1_SHARE_SIZE ((32 * 2) + 1) |
| 29 |
#define SECP384R1_SHARE_SIZE ((48 * 2) + 1) |
| 30 |
#define SECP521R1_SHARE_SIZE ((66 * 2) + 1) |
| 31 |
#define X25519_SHARE_SIZE (32) |
| 32 |
|
| 33 |
struct s2n_ecc_named_curve { |
| 34 |
|
| 35 |
uint16_t iana_id; |
| 36 |
|
| 37 |
int libcrypto_nid; |
| 38 |
const char *name; |
| 39 |
const uint8_t share_size; |
| 40 |
int (*generate_key)(const struct s2n_ecc_named_curve *named_curve, EVP_PKEY **evp_pkey); |
| 41 |
}; |
| 42 |
|
| 43 |
extern const struct s2n_ecc_named_curve s2n_ecc_curve_secp256r1; |
| 44 |
extern const struct s2n_ecc_named_curve s2n_ecc_curve_secp384r1; |
| 45 |
extern const struct s2n_ecc_named_curve s2n_ecc_curve_secp521r1; |
| 46 |
extern const struct s2n_ecc_named_curve s2n_ecc_curve_x25519; |
| 47 |
extern const struct s2n_ecc_named_curve s2n_ecc_curve_none; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
#if S2N_OPENSSL_VERSION_AT_LEAST(1, 1, 0) && !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_IS_BORINGSSL) |
| 53 |
#define EVP_APIS_SUPPORTED 1 |
| 54 |
#define S2N_ECC_EVP_SUPPORTED_CURVES_COUNT 4 |
| 55 |
#else |
| 56 |
#define EVP_APIS_SUPPORTED 0 |
| 57 |
#define S2N_ECC_EVP_SUPPORTED_CURVES_COUNT 3 |
| 58 |
#endif |
| 59 |
|
| 60 |
extern const struct s2n_ecc_named_curve *const s2n_all_supported_curves_list[]; |
| 61 |
extern const size_t s2n_all_supported_curves_list_len; |
| 62 |
|
| 63 |
struct s2n_ecc_evp_params { |
| 64 |
const struct s2n_ecc_named_curve *negotiated_curve; |
| 65 |
EVP_PKEY *evp_pkey; |
| 66 |
}; |
| 67 |
|
| 68 |
int s2n_ecc_evp_generate_ephemeral_key(struct s2n_ecc_evp_params *ecc_evp_params); |
| 69 |
int s2n_ecc_evp_compute_shared_secret_from_params(struct s2n_ecc_evp_params *private_ecc_evp_params, |
| 70 |
struct s2n_ecc_evp_params *public_ecc_evp_params, |
| 71 |
struct s2n_blob *shared_key); |
| 72 |
int s2n_ecc_evp_write_params_point(struct s2n_ecc_evp_params *ecc_evp_params, struct s2n_stuffer *out); |
| 73 |
int s2n_ecc_evp_read_params_point(struct s2n_stuffer *in, int point_size, struct s2n_blob *point_blob); |
| 74 |
int s2n_ecc_evp_compute_shared_secret_as_server(struct s2n_ecc_evp_params *server_ecc_evp_params, |
| 75 |
struct s2n_stuffer *Yc_in, struct s2n_blob *shared_key); |
| 76 |
int s2n_ecc_evp_compute_shared_secret_as_client(struct s2n_ecc_evp_params *server_ecc_evp_params, |
| 77 |
struct s2n_stuffer *Yc_out, struct s2n_blob *shared_key); |
| 78 |
int s2n_ecc_evp_parse_params_point(struct s2n_blob *point_blob, struct s2n_ecc_evp_params *ecc_evp_params); |
| 79 |
int s2n_ecc_evp_write_params(struct s2n_ecc_evp_params *ecc_evp_params, struct s2n_stuffer *out, |
| 80 |
struct s2n_blob *written); |
| 81 |
int s2n_ecc_evp_read_params(struct s2n_stuffer *in, struct s2n_blob *data_to_verify, |
| 82 |
struct s2n_ecdhe_raw_server_params *raw_server_ecc_params); |
| 83 |
int s2n_ecc_evp_parse_params(struct s2n_connection *conn, |
| 84 |
struct s2n_ecdhe_raw_server_params *raw_server_ecc_params, |
| 85 |
struct s2n_ecc_evp_params *ecc_evp_params); |
| 86 |
int s2n_ecc_evp_find_supported_curve(struct s2n_connection *conn, struct s2n_blob *iana_ids, const struct s2n_ecc_named_curve **found); |
| 87 |
int s2n_ecc_evp_params_free(struct s2n_ecc_evp_params *ecc_evp_params); |
| 88 |
int s2n_is_evp_apis_supported(); |
| 89 |
bool s2n_ecc_evp_supports_fips_check(); |
| 90 |
int s2n_find_ecc_curve_from_iana_id(uint16_t iana_id, const struct s2n_ecc_named_curve **out, bool *found); |