]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/default/ciphers/cipher_camellia_hw.c
Reorganize private crypto header files
[thirdparty/openssl.git] / providers / default / ciphers / cipher_camellia_hw.c
CommitLineData
e1178600
SL
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
4a42e264
SL
10#include "cipher_camellia.h"
11#include <openssl/camellia.h>
e1178600 12
e1178600
SL
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
38# if defined(SPARC_CMLL_CAPABLE)
39# include "cipher_camellia_hw_t4.inc"
40# else
41/* The generic case */
42# define PROV_CIPHER_HW_declare(mode)
43# define PROV_CIPHER_HW_select(mode)
44# endif /* SPARC_CMLL_CAPABLE */
45
46#define PROV_CIPHER_HW_camellia_mode(mode) \
47static const PROV_CIPHER_HW camellia_##mode = { \
48 cipher_hw_camellia_initkey, \
49 cipher_hw_generic_##mode \
50}; \
51PROV_CIPHER_HW_declare(mode) \
52const PROV_CIPHER_HW *PROV_CIPHER_HW_camellia_##mode(size_t keybits) \
53{ \
54 PROV_CIPHER_HW_select(mode) \
55 return &camellia_##mode; \
56}
57
58PROV_CIPHER_HW_camellia_mode(cbc)
59PROV_CIPHER_HW_camellia_mode(ecb)
60PROV_CIPHER_HW_camellia_mode(ofb128)
61PROV_CIPHER_HW_camellia_mode(cfb128)
62PROV_CIPHER_HW_camellia_mode(cfb1)
63PROV_CIPHER_HW_camellia_mode(cfb8)
64PROV_CIPHER_HW_camellia_mode(ctr)