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