2 * Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include "cipher_camellia.h"
11 #include <openssl/camellia.h>
13 static int cipher_hw_camellia_initkey(PROV_CIPHER_CTX *dat,
14 const unsigned char *key, size_t keylen)
16 int ret, mode = dat->mode;
17 PROV_CAMELLIA_CTX *adat = (PROV_CAMELLIA_CTX *)dat;
18 CAMELLIA_KEY *ks = &adat->ks.ks;
21 ret = Camellia_set_key(key, keylen * 8, ks);
23 ERR_raise(ERR_LIB_PROV, EVP_R_ARIA_KEY_SETUP_FAILED);
26 if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE)) {
27 dat->block = (block128_f) Camellia_encrypt;
28 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
29 (cbc128_f) Camellia_cbc_encrypt : NULL;
31 dat->block = (block128_f) Camellia_decrypt;
32 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
33 (cbc128_f) Camellia_cbc_encrypt : NULL;
38 # if defined(SPARC_CMLL_CAPABLE)
39 # include "cipher_camellia_hw_t4.inc"
41 /* The generic case */
42 # define PROV_CIPHER_HW_declare(mode)
43 # define PROV_CIPHER_HW_select(mode)
44 # endif /* SPARC_CMLL_CAPABLE */
46 #define PROV_CIPHER_HW_camellia_mode(mode) \
47 static const PROV_CIPHER_HW camellia_##mode = { \
48 cipher_hw_camellia_initkey, \
49 cipher_hw_generic_##mode \
51 PROV_CIPHER_HW_declare(mode) \
52 const PROV_CIPHER_HW *PROV_CIPHER_HW_camellia_##mode(size_t keybits) \
54 PROV_CIPHER_HW_select(mode) \
55 return &camellia_##mode; \
58 PROV_CIPHER_HW_camellia_mode(cbc)
59 PROV_CIPHER_HW_camellia_mode(ecb)
60 PROV_CIPHER_HW_camellia_mode(ofb128)
61 PROV_CIPHER_HW_camellia_mode(cfb128)
62 PROV_CIPHER_HW_camellia_mode(cfb1)
63 PROV_CIPHER_HW_camellia_mode(cfb8)
64 PROV_CIPHER_HW_camellia_mode(ctr)