| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <openssl/evp.h> |
| 17 |
#if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) |
| 18 |
#include <openssl/mem.h> |
| 19 |
#endif |
| 20 |
|
| 21 |
#include "crypto/s2n_cipher.h" |
| 22 |
#include "utils/s2n_safety.h" |
| 23 |
|
| 24 |
int s2n_session_key_alloc(struct s2n_session_key *key) |
| 25 |
{ |
| 26 |
POSIX_ENSURE_EQ(key->evp_cipher_ctx, NULL); |
| 27 |
POSIX_ENSURE_REF(key->evp_cipher_ctx = EVP_CIPHER_CTX_new()); |
| 28 |
#if defined(S2N_CIPHER_AEAD_API_AVAILABLE) |
| 29 |
POSIX_ENSURE_EQ(key->evp_aead_ctx, NULL); |
| 30 |
key->evp_aead_ctx = OPENSSL_malloc(sizeof(EVP_AEAD_CTX)); |
| 31 |
if (key->evp_aead_ctx == NULL) { |
| 32 |
EVP_CIPHER_CTX_free(key->evp_cipher_ctx); |
| 33 |
S2N_ERROR_PRESERVE_ERRNO(); |
| 34 |
} |
| 35 |
EVP_AEAD_CTX_zero(key->evp_aead_ctx); |
| 36 |
#endif |
| 37 |
|
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
int s2n_session_key_free(struct s2n_session_key *key) |
| 42 |
{ |
| 43 |
if (key->evp_cipher_ctx != NULL) { |
| 44 |
EVP_CIPHER_CTX_free(key->evp_cipher_ctx); |
| 45 |
key->evp_cipher_ctx = NULL; |
| 46 |
} |
| 47 |
#if defined(S2N_CIPHER_AEAD_API_AVAILABLE) |
| 48 |
if (key->evp_aead_ctx != NULL) { |
| 49 |
EVP_AEAD_CTX_free(key->evp_aead_ctx); |
| 50 |
key->evp_aead_ctx = NULL; |
| 51 |
} |
| 52 |
#endif |
| 53 |
|
| 54 |
return 0; |
| 55 |
} |