xref: /netbsd-src/crypto/external/bsd/openssl/dist/providers/implementations/ciphers/cipher_camellia.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1*b0d17251Schristos /*
2*b0d17251Schristos  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3*b0d17251Schristos  *
4*b0d17251Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*b0d17251Schristos  * this file except in compliance with the License.  You can obtain a copy
6*b0d17251Schristos  * in the file LICENSE in the source distribution or at
7*b0d17251Schristos  * https://www.openssl.org/source/license.html
8*b0d17251Schristos  */
9*b0d17251Schristos 
10*b0d17251Schristos /*
11*b0d17251Schristos  * Camellia low level APIs are deprecated for public use, but still ok for
12*b0d17251Schristos  * internal use.
13*b0d17251Schristos  */
14*b0d17251Schristos #include "internal/deprecated.h"
15*b0d17251Schristos 
16*b0d17251Schristos /* Dispatch functions for CAMELLIA cipher modes ecb, cbc, ofb, cfb, ctr */
17*b0d17251Schristos 
18*b0d17251Schristos #include "cipher_camellia.h"
19*b0d17251Schristos #include "prov/implementations.h"
20*b0d17251Schristos #include "prov/providercommon.h"
21*b0d17251Schristos 
22*b0d17251Schristos static OSSL_FUNC_cipher_freectx_fn camellia_freectx;
23*b0d17251Schristos static OSSL_FUNC_cipher_dupctx_fn camellia_dupctx;
24*b0d17251Schristos 
camellia_freectx(void * vctx)25*b0d17251Schristos static void camellia_freectx(void *vctx)
26*b0d17251Schristos {
27*b0d17251Schristos     PROV_CAMELLIA_CTX *ctx = (PROV_CAMELLIA_CTX *)vctx;
28*b0d17251Schristos 
29*b0d17251Schristos     ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
30*b0d17251Schristos     OPENSSL_clear_free(ctx,  sizeof(*ctx));
31*b0d17251Schristos }
32*b0d17251Schristos 
camellia_dupctx(void * ctx)33*b0d17251Schristos static void *camellia_dupctx(void *ctx)
34*b0d17251Schristos {
35*b0d17251Schristos     PROV_CAMELLIA_CTX *in = (PROV_CAMELLIA_CTX *)ctx;
36*b0d17251Schristos     PROV_CAMELLIA_CTX *ret;
37*b0d17251Schristos 
38*b0d17251Schristos     if (!ossl_prov_is_running())
39*b0d17251Schristos         return NULL;
40*b0d17251Schristos 
41*b0d17251Schristos     ret = OPENSSL_malloc(sizeof(*ret));
42*b0d17251Schristos     if (ret == NULL) {
43*b0d17251Schristos         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
44*b0d17251Schristos         return NULL;
45*b0d17251Schristos     }
46*b0d17251Schristos     in->base.hw->copyctx(&ret->base, &in->base);
47*b0d17251Schristos 
48*b0d17251Schristos     return ret;
49*b0d17251Schristos }
50*b0d17251Schristos 
51*b0d17251Schristos /* ossl_camellia256ecb_functions */
52*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ecb, ECB, 0, 256, 128, 0, block)
53*b0d17251Schristos /* ossl_camellia192ecb_functions */
54*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ecb, ECB, 0, 192, 128, 0, block)
55*b0d17251Schristos /* ossl_camellia128ecb_functions */
56*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ecb, ECB, 0, 128, 128, 0, block)
57*b0d17251Schristos /* ossl_camellia256cbc_functions */
58*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cbc, CBC, 0, 256, 128, 128, block)
59*b0d17251Schristos /* ossl_camellia192cbc_functions */
60*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cbc, CBC, 0, 192, 128, 128, block)
61*b0d17251Schristos /* ossl_camellia128cbc_functions */
62*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cbc, CBC, 0, 128, 128, 128, block)
63*b0d17251Schristos /* ossl_camellia256ofb_functions */
64*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ofb, OFB, 0, 256, 8, 128, stream)
65*b0d17251Schristos /* ossl_camellia192ofb_functions */
66*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ofb, OFB, 0, 192, 8, 128, stream)
67*b0d17251Schristos /* ossl_camellia128ofb_functions */
68*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ofb, OFB, 0, 128, 8, 128, stream)
69*b0d17251Schristos /* ossl_camellia256cfb_functions */
70*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb,  CFB, 0, 256, 8, 128, stream)
71*b0d17251Schristos /* ossl_camellia192cfb_functions */
72*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb,  CFB, 0, 192, 8, 128, stream)
73*b0d17251Schristos /* ossl_camellia128cfb_functions */
74*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb,  CFB, 0, 128, 8, 128, stream)
75*b0d17251Schristos /* ossl_camellia256cfb1_functions */
76*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb1, CFB, 0, 256, 8, 128, stream)
77*b0d17251Schristos /* ossl_camellia192cfb1_functions */
78*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb1, CFB, 0, 192, 8, 128, stream)
79*b0d17251Schristos /* ossl_camellia128cfb1_functions */
80*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb1, CFB, 0, 128, 8, 128, stream)
81*b0d17251Schristos /* ossl_camellia256cfb8_functions */
82*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb8, CFB, 0, 256, 8, 128, stream)
83*b0d17251Schristos /* ossl_camellia192cfb8_functions */
84*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb8, CFB, 0, 192, 8, 128, stream)
85*b0d17251Schristos /* ossl_camellia128cfb8_functions */
86*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb8, CFB, 0, 128, 8, 128, stream)
87*b0d17251Schristos /* ossl_camellia256ctr_functions */
88*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ctr, CTR, 0, 256, 8, 128, stream)
89*b0d17251Schristos /* ossl_camellia192ctr_functions */
90*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ctr, CTR, 0, 192, 8, 128, stream)
91*b0d17251Schristos /* ossl_camellia128ctr_functions */
92*b0d17251Schristos IMPLEMENT_generic_cipher(camellia, CAMELLIA, ctr, CTR, 0, 128, 8, 128, stream)
93*b0d17251Schristos 
94*b0d17251Schristos #include "cipher_camellia_cts.inc"
95