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 IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_camellia_copyctx, PROV_CAMELLIA_CTX)
40 # if defined(SPARC_CMLL_CAPABLE)
41 # include "cipher_camellia_hw_t4.inc"
43 /* The generic case */
44 # define PROV_CIPHER_HW_declare(mode)
45 # define PROV_CIPHER_HW_select(mode)
46 # endif /* SPARC_CMLL_CAPABLE */
48 #define PROV_CIPHER_HW_camellia_mode(mode) \
49 static const PROV_CIPHER_HW camellia_##mode = { \
50 cipher_hw_camellia_initkey, \
51 cipher_hw_generic_##mode, \
52 cipher_hw_camellia_copyctx \
54 PROV_CIPHER_HW_declare(mode) \
55 const PROV_CIPHER_HW *PROV_CIPHER_HW_camellia_##mode(size_t keybits) \
57 PROV_CIPHER_HW_select(mode) \
58 return &camellia_##mode; \
61 PROV_CIPHER_HW_camellia_mode(cbc)
62 PROV_CIPHER_HW_camellia_mode(ecb)
63 PROV_CIPHER_HW_camellia_mode(ofb128)
64 PROV_CIPHER_HW_camellia_mode(cfb128)
65 PROV_CIPHER_HW_camellia_mode(cfb1)
66 PROV_CIPHER_HW_camellia_mode(cfb8)
67 PROV_CIPHER_HW_camellia_mode(ctr)