| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <openssl/aes.h> |
| 19 |
#include <openssl/des.h> |
| 20 |
#include <openssl/dh.h> |
| 21 |
#include <openssl/evp.h> |
| 22 |
#include <openssl/rc4.h> |
| 23 |
#include <openssl/rsa.h> |
| 24 |
|
| 25 |
#include "crypto/s2n_crypto.h" |
| 26 |
#include "crypto/s2n_ktls_crypto.h" |
| 27 |
#include "utils/s2n_blob.h" |
| 28 |
|
| 29 |
#if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) |
| 30 |
#define S2N_CIPHER_AEAD_API_AVAILABLE |
| 31 |
#endif |
| 32 |
|
| 33 |
struct s2n_session_key { |
| 34 |
EVP_CIPHER_CTX *evp_cipher_ctx; |
| 35 |
#if defined(S2N_CIPHER_AEAD_API_AVAILABLE) |
| 36 |
EVP_AEAD_CTX *evp_aead_ctx; |
| 37 |
#endif |
| 38 |
}; |
| 39 |
|
| 40 |
struct s2n_stream_cipher { |
| 41 |
int (*decrypt)(struct s2n_session_key *key, struct s2n_blob *in, struct s2n_blob *out); |
| 42 |
int (*encrypt)(struct s2n_session_key *key, struct s2n_blob *in, struct s2n_blob *out); |
| 43 |
}; |
| 44 |
|
| 45 |
struct s2n_cbc_cipher { |
| 46 |
uint8_t block_size; |
| 47 |
uint8_t record_iv_size; |
| 48 |
int (*decrypt)(struct s2n_session_key *key, struct s2n_blob *iv, struct s2n_blob *in, struct s2n_blob *out); |
| 49 |
int (*encrypt)(struct s2n_session_key *key, struct s2n_blob *iv, struct s2n_blob *in, struct s2n_blob *out); |
| 50 |
}; |
| 51 |
|
| 52 |
struct s2n_aead_cipher { |
| 53 |
uint8_t fixed_iv_size; |
| 54 |
uint8_t record_iv_size; |
| 55 |
uint8_t tag_size; |
| 56 |
int (*decrypt)(struct s2n_session_key *key, struct s2n_blob *iv, struct s2n_blob *add, struct s2n_blob *in, struct s2n_blob *out); |
| 57 |
int (*encrypt)(struct s2n_session_key *key, struct s2n_blob *iv, struct s2n_blob *add, struct s2n_blob *in, struct s2n_blob *out); |
| 58 |
}; |
| 59 |
|
| 60 |
struct s2n_composite_cipher { |
| 61 |
uint8_t block_size; |
| 62 |
uint8_t record_iv_size; |
| 63 |
uint8_t mac_key_size; |
| 64 |
int (*decrypt)(struct s2n_session_key *key, struct s2n_blob *iv, struct s2n_blob *in, struct s2n_blob *out); |
| 65 |
int (*encrypt)(struct s2n_session_key *key, struct s2n_blob *iv, struct s2n_blob *in, struct s2n_blob *out); |
| 66 |
int (*set_mac_write_key)(struct s2n_session_key *key, uint8_t *mac_key, uint32_t mac_size); |
| 67 |
int (*initial_hmac)(struct s2n_session_key *key, uint8_t *sequence_number, uint8_t content_type, uint16_t protocol_version, |
| 68 |
uint16_t payload_and_eiv_len, int *extra); |
| 69 |
}; |
| 70 |
|
| 71 |
struct s2n_cipher { |
| 72 |
enum { |
| 73 |
S2N_STREAM, |
| 74 |
S2N_CBC, |
| 75 |
S2N_AEAD, |
| 76 |
S2N_COMPOSITE |
| 77 |
} type; |
| 78 |
union { |
| 79 |
struct s2n_stream_cipher stream; |
| 80 |
struct s2n_aead_cipher aead; |
| 81 |
struct s2n_cbc_cipher cbc; |
| 82 |
struct s2n_composite_cipher comp; |
| 83 |
} io; |
| 84 |
uint8_t key_material_size; |
| 85 |
bool (*is_available)(void); |
| 86 |
S2N_RESULT (*init)(struct s2n_session_key *key); |
| 87 |
S2N_RESULT (*set_decryption_key)(struct s2n_session_key *key, struct s2n_blob *in); |
| 88 |
S2N_RESULT (*set_encryption_key)(struct s2n_session_key *key, struct s2n_blob *in); |
| 89 |
S2N_RESULT (*destroy_key)(struct s2n_session_key *key); |
| 90 |
S2N_RESULT (*set_ktls_info)(struct s2n_ktls_crypto_info_inputs *inputs, |
| 91 |
struct s2n_ktls_crypto_info *crypto_info); |
| 92 |
}; |
| 93 |
|
| 94 |
int s2n_session_key_alloc(struct s2n_session_key *key); |
| 95 |
int s2n_session_key_free(struct s2n_session_key *key); |
| 96 |
|
| 97 |
extern const struct s2n_cipher s2n_null_cipher; |
| 98 |
extern const struct s2n_cipher s2n_rc4; |
| 99 |
extern const struct s2n_cipher s2n_aes128; |
| 100 |
extern const struct s2n_cipher s2n_aes256; |
| 101 |
extern const struct s2n_cipher s2n_3des; |
| 102 |
extern const struct s2n_cipher s2n_aes128_gcm; |
| 103 |
extern const struct s2n_cipher s2n_aes256_gcm; |
| 104 |
extern const struct s2n_cipher s2n_aes128_sha; |
| 105 |
extern const struct s2n_cipher s2n_aes256_sha; |
| 106 |
extern const struct s2n_cipher s2n_aes128_sha256; |
| 107 |
extern const struct s2n_cipher s2n_aes256_sha256; |
| 108 |
extern const struct s2n_cipher s2n_chacha20_poly1305; |
| 109 |
|
| 110 |
extern const struct s2n_cipher s2n_tls13_aes128_gcm; |
| 111 |
extern const struct s2n_cipher s2n_tls13_aes256_gcm; |
| 112 |
|
| 113 |
S2N_RESULT s2n_rc4_init(); |
| 114 |
S2N_RESULT s2n_rc4_cleanup(); |