]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/implementations/ciphers/cipher_camellia_hw.c
Update copyright year
[thirdparty/openssl.git] / providers / implementations / ciphers / cipher_camellia_hw.c
CommitLineData
e1178600 1/*
a28d06f3 2 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
e1178600
SL
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
291850b4
MC
10/*
11 * Camellia low level APIs are deprecated for public use, but still ok for
12 * internal use.
13 */
14#include "internal/deprecated.h"
15
f5f29796
TM
16#include <openssl/camellia.h>
17#include <openssl/proverr.h>
4a42e264 18#include "cipher_camellia.h"
e1178600 19
e1178600
SL
20static int cipher_hw_camellia_initkey(PROV_CIPHER_CTX *dat,
21 const unsigned char *key, size_t keylen)
22{
23 int ret, mode = dat->mode;
24 PROV_CAMELLIA_CTX *adat = (PROV_CAMELLIA_CTX *)dat;
25 CAMELLIA_KEY *ks = &adat->ks.ks;
26
27 dat->ks = ks;
28 ret = Camellia_set_key(key, keylen * 8, ks);
29 if (ret < 0) {
f5f29796 30 ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED);
e1178600
SL
31 return 0;
32 }
33 if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE)) {
34 dat->block = (block128_f) Camellia_encrypt;
35 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
36 (cbc128_f) Camellia_cbc_encrypt : NULL;
37 } else {
38 dat->block = (block128_f) Camellia_decrypt;
39 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
40 (cbc128_f) Camellia_cbc_encrypt : NULL;
41 }
42 return 1;
43}
44
f75abcc0
SL
45IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_camellia_copyctx, PROV_CAMELLIA_CTX)
46
e1178600
SL
47# if defined(SPARC_CMLL_CAPABLE)
48# include "cipher_camellia_hw_t4.inc"
49# else
50/* The generic case */
51# define PROV_CIPHER_HW_declare(mode)
52# define PROV_CIPHER_HW_select(mode)
53# endif /* SPARC_CMLL_CAPABLE */
54
55#define PROV_CIPHER_HW_camellia_mode(mode) \
56static const PROV_CIPHER_HW camellia_##mode = { \
57 cipher_hw_camellia_initkey, \
592dcfd3 58 ossl_cipher_hw_generic_##mode, \
f75abcc0 59 cipher_hw_camellia_copyctx \
e1178600
SL
60}; \
61PROV_CIPHER_HW_declare(mode) \
7d6766cb 62const PROV_CIPHER_HW *ossl_prov_cipher_hw_camellia_##mode(size_t keybits) \
e1178600
SL
63{ \
64 PROV_CIPHER_HW_select(mode) \
65 return &camellia_##mode; \
66}
67
68PROV_CIPHER_HW_camellia_mode(cbc)
69PROV_CIPHER_HW_camellia_mode(ecb)
70PROV_CIPHER_HW_camellia_mode(ofb128)
71PROV_CIPHER_HW_camellia_mode(cfb128)
72PROV_CIPHER_HW_camellia_mode(cfb1)
73PROV_CIPHER_HW_camellia_mode(cfb8)
74PROV_CIPHER_HW_camellia_mode(ctr)