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_camellia.h"
11#include <openssl/camellia.h>
12
13static int cipher_hw_camellia_initkey(PROV_CIPHER_CTX *dat,
14 const unsigned char *key, size_t keylen)
15{
16 int ret, mode = dat->mode;
17 PROV_CAMELLIA_CTX *adat = (PROV_CAMELLIA_CTX *)dat;
18 CAMELLIA_KEY *ks = &adat->ks.ks;
19
20 dat->ks = ks;
21 ret = Camellia_set_key(key, keylen * 8, ks);
22 if (ret < 0) {
23 ERR_raise(ERR_LIB_PROV, EVP_R_ARIA_KEY_SETUP_FAILED);
24 return 0;
25 }
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;
30 } else {
31 dat->block = (block128_f) Camellia_decrypt;
32 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
33 (cbc128_f) Camellia_cbc_encrypt : NULL;
34 }
35 return 1;
36}
37
38IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_camellia_copyctx, PROV_CAMELLIA_CTX)
39
40# if defined(SPARC_CMLL_CAPABLE)
41# include "cipher_camellia_hw_t4.inc"
42# else
43/* The generic case */
44# define PROV_CIPHER_HW_declare(mode)
45# define PROV_CIPHER_HW_select(mode)
46# endif /* SPARC_CMLL_CAPABLE */
47
48#define PROV_CIPHER_HW_camellia_mode(mode) \
49static const PROV_CIPHER_HW camellia_##mode = { \
50 cipher_hw_camellia_initkey, \
51 cipher_hw_generic_##mode, \
52 cipher_hw_camellia_copyctx \
53}; \
54PROV_CIPHER_HW_declare(mode) \
55const PROV_CIPHER_HW *PROV_CIPHER_HW_camellia_##mode(size_t keybits) \
56{ \
57 PROV_CIPHER_HW_select(mode) \
58 return &camellia_##mode; \
59}
60
61PROV_CIPHER_HW_camellia_mode(cbc)
62PROV_CIPHER_HW_camellia_mode(ecb)
63PROV_CIPHER_HW_camellia_mode(ofb128)
64PROV_CIPHER_HW_camellia_mode(cfb128)
65PROV_CIPHER_HW_camellia_mode(cfb1)
66PROV_CIPHER_HW_camellia_mode(cfb8)
67PROV_CIPHER_HW_camellia_mode(ctr)
68