Fix migration guide mappings for i2o/o2i_ECPublicKey
[openssl.git] / providers / implementations / ciphers / cipher_camellia_hw.c
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 /*
11  * Camellia low level APIs are deprecated for public use, but still ok for
12  * internal use.
13  */
14 #include "internal/deprecated.h"
15
16 #include "cipher_camellia.h"
17 #include <openssl/camellia.h>
18
19 static int cipher_hw_camellia_initkey(PROV_CIPHER_CTX *dat,
20                                       const unsigned char *key, size_t keylen)
21 {
22     int ret, mode = dat->mode;
23     PROV_CAMELLIA_CTX *adat = (PROV_CAMELLIA_CTX *)dat;
24     CAMELLIA_KEY *ks = &adat->ks.ks;
25
26     dat->ks = ks;
27     ret = Camellia_set_key(key, keylen * 8, ks);
28     if (ret < 0) {
29         ERR_raise(ERR_LIB_PROV, EVP_R_ARIA_KEY_SETUP_FAILED);
30         return 0;
31     }
32     if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE)) {
33         dat->block = (block128_f) Camellia_encrypt;
34         dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
35             (cbc128_f) Camellia_cbc_encrypt : NULL;
36     } else {
37         dat->block = (block128_f) Camellia_decrypt;
38         dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
39             (cbc128_f) Camellia_cbc_encrypt : NULL;
40     }
41     return 1;
42 }
43
44 IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_camellia_copyctx, PROV_CAMELLIA_CTX)
45
46 # if defined(SPARC_CMLL_CAPABLE)
47 #  include "cipher_camellia_hw_t4.inc"
48 # else
49 /* The generic case */
50 #  define PROV_CIPHER_HW_declare(mode)
51 #  define PROV_CIPHER_HW_select(mode)
52 # endif /* SPARC_CMLL_CAPABLE */
53
54 #define PROV_CIPHER_HW_camellia_mode(mode)                                     \
55 static const PROV_CIPHER_HW camellia_##mode = {                                \
56     cipher_hw_camellia_initkey,                                                \
57     cipher_hw_generic_##mode,                                                  \
58     cipher_hw_camellia_copyctx                                                 \
59 };                                                                             \
60 PROV_CIPHER_HW_declare(mode)                                                   \
61 const PROV_CIPHER_HW *PROV_CIPHER_HW_camellia_##mode(size_t keybits)           \
62 {                                                                              \
63     PROV_CIPHER_HW_select(mode)                                                \
64     return &camellia_##mode;                                                   \
65 }
66
67 PROV_CIPHER_HW_camellia_mode(cbc)
68 PROV_CIPHER_HW_camellia_mode(ecb)
69 PROV_CIPHER_HW_camellia_mode(ofb128)
70 PROV_CIPHER_HW_camellia_mode(cfb128)
71 PROV_CIPHER_HW_camellia_mode(cfb1)
72 PROV_CIPHER_HW_camellia_mode(cfb8)
73 PROV_CIPHER_HW_camellia_mode(ctr)