xref: /netbsd-src/crypto/external/bsd/openssl/dist/providers/implementations/ciphers/cipher_aes.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1*b0d17251Schristos /*
2*b0d17251Schristos  * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3*b0d17251Schristos  *
4*b0d17251Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*b0d17251Schristos  * this file except in compliance with the License.  You can obtain a copy
6*b0d17251Schristos  * in the file LICENSE in the source distribution or at
7*b0d17251Schristos  * https://www.openssl.org/source/license.html
8*b0d17251Schristos  */
9*b0d17251Schristos 
10*b0d17251Schristos /*
11*b0d17251Schristos  * AES low level APIs are deprecated for public use, but still ok for internal
12*b0d17251Schristos  * use where we're using them to implement the higher level EVP interface, as is
13*b0d17251Schristos  * the case here.
14*b0d17251Schristos  */
15*b0d17251Schristos #include "internal/deprecated.h"
16*b0d17251Schristos 
17*b0d17251Schristos /* Dispatch functions for AES cipher modes ecb, cbc, ofb, cfb, ctr */
18*b0d17251Schristos 
19*b0d17251Schristos #include "cipher_aes.h"
20*b0d17251Schristos #include "prov/implementations.h"
21*b0d17251Schristos #include "prov/providercommon.h"
22*b0d17251Schristos 
23*b0d17251Schristos static OSSL_FUNC_cipher_freectx_fn aes_freectx;
24*b0d17251Schristos static OSSL_FUNC_cipher_dupctx_fn aes_dupctx;
25*b0d17251Schristos 
aes_freectx(void * vctx)26*b0d17251Schristos static void aes_freectx(void *vctx)
27*b0d17251Schristos {
28*b0d17251Schristos     PROV_AES_CTX *ctx = (PROV_AES_CTX *)vctx;
29*b0d17251Schristos 
30*b0d17251Schristos     ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
31*b0d17251Schristos     OPENSSL_clear_free(ctx,  sizeof(*ctx));
32*b0d17251Schristos }
33*b0d17251Schristos 
aes_dupctx(void * ctx)34*b0d17251Schristos static void *aes_dupctx(void *ctx)
35*b0d17251Schristos {
36*b0d17251Schristos     PROV_AES_CTX *in = (PROV_AES_CTX *)ctx;
37*b0d17251Schristos     PROV_AES_CTX *ret;
38*b0d17251Schristos 
39*b0d17251Schristos     if (!ossl_prov_is_running())
40*b0d17251Schristos         return NULL;
41*b0d17251Schristos 
42*b0d17251Schristos     ret = OPENSSL_malloc(sizeof(*ret));
43*b0d17251Schristos     if (ret == NULL) {
44*b0d17251Schristos         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
45*b0d17251Schristos         return NULL;
46*b0d17251Schristos     }
47*b0d17251Schristos     in->base.hw->copyctx(&ret->base, &in->base);
48*b0d17251Schristos 
49*b0d17251Schristos     return ret;
50*b0d17251Schristos }
51*b0d17251Schristos 
52*b0d17251Schristos /* ossl_aes256ecb_functions */
53*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 256, 128, 0, block)
54*b0d17251Schristos /* ossl_aes192ecb_functions */
55*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 192, 128, 0, block)
56*b0d17251Schristos /* ossl_aes128ecb_functions */
57*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 128, 128, 0, block)
58*b0d17251Schristos /* ossl_aes256cbc_functions */
59*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 256, 128, 128, block)
60*b0d17251Schristos /* ossl_aes192cbc_functions */
61*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 192, 128, 128, block)
62*b0d17251Schristos /* ossl_aes128cbc_functions */
63*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 128, 128, 128, block)
64*b0d17251Schristos /* ossl_aes256ofb_functions */
65*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 256, 8, 128, stream)
66*b0d17251Schristos /* ossl_aes192ofb_functions */
67*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 192, 8, 128, stream)
68*b0d17251Schristos /* ossl_aes128ofb_functions */
69*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 128, 8, 128, stream)
70*b0d17251Schristos /* ossl_aes256cfb_functions */
71*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb,  CFB, 0, 256, 8, 128, stream)
72*b0d17251Schristos /* ossl_aes192cfb_functions */
73*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb,  CFB, 0, 192, 8, 128, stream)
74*b0d17251Schristos /* ossl_aes128cfb_functions */
75*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb,  CFB, 0, 128, 8, 128, stream)
76*b0d17251Schristos /* ossl_aes256cfb1_functions */
77*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 256, 8, 128, stream)
78*b0d17251Schristos /* ossl_aes192cfb1_functions */
79*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 192, 8, 128, stream)
80*b0d17251Schristos /* ossl_aes128cfb1_functions */
81*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 128, 8, 128, stream)
82*b0d17251Schristos /* ossl_aes256cfb8_functions */
83*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 256, 8, 128, stream)
84*b0d17251Schristos /* ossl_aes192cfb8_functions */
85*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 192, 8, 128, stream)
86*b0d17251Schristos /* ossl_aes128cfb8_functions */
87*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 128, 8, 128, stream)
88*b0d17251Schristos /* ossl_aes256ctr_functions */
89*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 256, 8, 128, stream)
90*b0d17251Schristos /* ossl_aes192ctr_functions */
91*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 192, 8, 128, stream)
92*b0d17251Schristos /* ossl_aes128ctr_functions */
93*b0d17251Schristos IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 128, 8, 128, stream)
94*b0d17251Schristos 
95*b0d17251Schristos #include "cipher_aes_cts.inc"
96