xref: /netbsd-src/crypto/external/bsd/openssl/dist/providers/implementations/ciphers/cipher_cast5.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  * CAST 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 cast cipher modes ecb, cbc, ofb, cfb */
17*b0d17251Schristos 
18*b0d17251Schristos #include <openssl/proverr.h>
19*b0d17251Schristos #include "cipher_cast.h"
20*b0d17251Schristos #include "prov/implementations.h"
21*b0d17251Schristos #include "prov/providercommon.h"
22*b0d17251Schristos 
23*b0d17251Schristos #define CAST5_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH
24*b0d17251Schristos 
25*b0d17251Schristos static OSSL_FUNC_cipher_freectx_fn cast5_freectx;
26*b0d17251Schristos static OSSL_FUNC_cipher_dupctx_fn cast5_dupctx;
27*b0d17251Schristos 
cast5_freectx(void * vctx)28*b0d17251Schristos static void cast5_freectx(void *vctx)
29*b0d17251Schristos {
30*b0d17251Schristos     PROV_CAST_CTX *ctx = (PROV_CAST_CTX *)vctx;
31*b0d17251Schristos 
32*b0d17251Schristos     ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
33*b0d17251Schristos     OPENSSL_clear_free(ctx,  sizeof(*ctx));
34*b0d17251Schristos }
35*b0d17251Schristos 
cast5_dupctx(void * ctx)36*b0d17251Schristos static void *cast5_dupctx(void *ctx)
37*b0d17251Schristos {
38*b0d17251Schristos     PROV_CAST_CTX *in = (PROV_CAST_CTX *)ctx;
39*b0d17251Schristos     PROV_CAST_CTX *ret;
40*b0d17251Schristos 
41*b0d17251Schristos     if (!ossl_prov_is_running())
42*b0d17251Schristos         return NULL;
43*b0d17251Schristos 
44*b0d17251Schristos     ret = OPENSSL_malloc(sizeof(*ret));
45*b0d17251Schristos     if (ret == NULL) {
46*b0d17251Schristos         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
47*b0d17251Schristos         return NULL;
48*b0d17251Schristos     }
49*b0d17251Schristos     *ret = *in;
50*b0d17251Schristos 
51*b0d17251Schristos     return ret;
52*b0d17251Schristos }
53*b0d17251Schristos 
54*b0d17251Schristos /* ossl_cast5128ecb_functions */
55*b0d17251Schristos IMPLEMENT_var_keylen_cipher(cast5, CAST, ecb, ECB, CAST5_FLAGS, 128, 64, 0, block)
56*b0d17251Schristos /* ossl_cast5128cbc_functions */
57*b0d17251Schristos IMPLEMENT_var_keylen_cipher(cast5, CAST, cbc, CBC, CAST5_FLAGS, 128, 64, 64, block)
58*b0d17251Schristos /* ossl_cast5128ofb64_functions */
59*b0d17251Schristos IMPLEMENT_var_keylen_cipher(cast5, CAST, ofb64, OFB, CAST5_FLAGS, 128, 8, 64, stream)
60*b0d17251Schristos /* ossl_cast5128cfb64_functions */
61*b0d17251Schristos IMPLEMENT_var_keylen_cipher(cast5, CAST, cfb64,  CFB, CAST5_FLAGS, 128, 8, 64, stream)
62