Raise an error on syscall failure in tls_retry_write_records
[openssl.git] / providers / implementations / ciphers / cipher_aes_gcm.c
1 /*
2  * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /*
11  * AES low level APIs are deprecated for public use, but still ok for internal
12  * use where we're using them to implement the higher level EVP interface, as is
13  * the case here.
14  */
15 #include "internal/deprecated.h"
16
17 /* Dispatch functions for AES GCM mode */
18
19 #include "cipher_aes_gcm.h"
20 #include "prov/implementations.h"
21 #include "prov/providercommon.h"
22
23 #define AES_GCM_IV_MIN_SIZE     (64 / 8) /* size in bytes */
24 /* Note: GCM_IV_MAX_SIZE is listed in ciphercommon_gcm.h */
25
26 static void *aes_gcm_newctx(void *provctx, size_t keybits)
27 {
28     PROV_AES_GCM_CTX *ctx;
29
30     if (!ossl_prov_is_running())
31         return NULL;
32
33     ctx = OPENSSL_zalloc(sizeof(*ctx));
34     if (ctx != NULL)
35         gcm_initctx(provctx, &ctx->base, keybits, ossl_prov_aes_hw_gcm(keybits),
36                     AES_GCM_IV_MIN_SIZE);
37     return ctx;
38 }
39
40 static OSSL_FUNC_cipher_freectx_fn aes_gcm_freectx;
41 static void aes_gcm_freectx(void *vctx)
42 {
43     PROV_AES_GCM_CTX *ctx = (PROV_AES_GCM_CTX *)vctx;
44
45     OPENSSL_clear_free(ctx,  sizeof(*ctx));
46 }
47
48 /* ossl_aes128gcm_functions */
49 IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 128, 8, 96);
50 /* ossl_aes192gcm_functions */
51 IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 192, 8, 96);
52 /* ossl_aes256gcm_functions */
53 IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 256, 8, 96);