1 /*
2 * Copyright 2001-2021 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 #include <openssl/proverr.h>
11 #include "cipher_aria.h"
12
cipher_hw_aria_initkey(PROV_CIPHER_CTX * dat,const unsigned char * key,size_t keylen)13 static int cipher_hw_aria_initkey(PROV_CIPHER_CTX *dat,
14 const unsigned char *key, size_t keylen)
15 {
16 int ret, mode = dat->mode;
17 PROV_ARIA_CTX *adat = (PROV_ARIA_CTX *)dat;
18 ARIA_KEY *ks = &adat->ks.ks;
19
20 if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE))
21 ret = ossl_aria_set_encrypt_key(key, keylen * 8, ks);
22 else
23 ret = ossl_aria_set_decrypt_key(key, keylen * 8, ks);
24 if (ret < 0) {
25 ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED);
26 return 0;
27 }
28 dat->ks = ks;
29 dat->block = (block128_f)ossl_aria_encrypt;
30 return 1;
31 }
32
33 IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_aria_copyctx, PROV_ARIA_CTX)
34
35 # define PROV_CIPHER_HW_aria_mode(mode) \
36 static const PROV_CIPHER_HW aria_##mode = { \
37 cipher_hw_aria_initkey, \
38 ossl_cipher_hw_chunked_##mode, \
39 cipher_hw_aria_copyctx \
40 }; \
41 const PROV_CIPHER_HW *ossl_prov_cipher_hw_aria_##mode(size_t keybits) \
42 { \
43 return &aria_##mode; \
44 }
45
46 PROV_CIPHER_HW_aria_mode(cbc)
47 PROV_CIPHER_HW_aria_mode(ecb)
48 PROV_CIPHER_HW_aria_mode(ofb128)
49 PROV_CIPHER_HW_aria_mode(cfb128)
50 PROV_CIPHER_HW_aria_mode(cfb1)
51 PROV_CIPHER_HW_aria_mode(cfb8)
52 PROV_CIPHER_HW_aria_mode(ctr)
53