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