1*b077aed3SPierre Pronchery /*
2*b077aed3SPierre Pronchery * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
3*b077aed3SPierre Pronchery *
4*b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use
5*b077aed3SPierre Pronchery * this file except in compliance with the License. You can obtain a copy
6*b077aed3SPierre Pronchery * in the file LICENSE in the source distribution or at
7*b077aed3SPierre Pronchery * https://www.openssl.org/source/license.html
8*b077aed3SPierre Pronchery */
9*b077aed3SPierre Pronchery
10*b077aed3SPierre Pronchery /* Dispatch functions for Blowfish cipher modes ecb, cbc, ofb, cfb */
11*b077aed3SPierre Pronchery
12*b077aed3SPierre Pronchery /*
13*b077aed3SPierre Pronchery * BF low level APIs are deprecated for public use, but still ok for internal
14*b077aed3SPierre Pronchery * use.
15*b077aed3SPierre Pronchery */
16*b077aed3SPierre Pronchery #include "internal/deprecated.h"
17*b077aed3SPierre Pronchery
18*b077aed3SPierre Pronchery #include "cipher_blowfish.h"
19*b077aed3SPierre Pronchery #include "prov/implementations.h"
20*b077aed3SPierre Pronchery #include "prov/providercommon.h"
21*b077aed3SPierre Pronchery
22*b077aed3SPierre Pronchery #define BF_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH
23*b077aed3SPierre Pronchery
24*b077aed3SPierre Pronchery static OSSL_FUNC_cipher_freectx_fn blowfish_freectx;
25*b077aed3SPierre Pronchery static OSSL_FUNC_cipher_dupctx_fn blowfish_dupctx;
26*b077aed3SPierre Pronchery
blowfish_freectx(void * vctx)27*b077aed3SPierre Pronchery static void blowfish_freectx(void *vctx)
28*b077aed3SPierre Pronchery {
29*b077aed3SPierre Pronchery PROV_BLOWFISH_CTX *ctx = (PROV_BLOWFISH_CTX *)vctx;
30*b077aed3SPierre Pronchery
31*b077aed3SPierre Pronchery ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
32*b077aed3SPierre Pronchery OPENSSL_clear_free(ctx, sizeof(*ctx));
33*b077aed3SPierre Pronchery }
34*b077aed3SPierre Pronchery
blowfish_dupctx(void * ctx)35*b077aed3SPierre Pronchery static void *blowfish_dupctx(void *ctx)
36*b077aed3SPierre Pronchery {
37*b077aed3SPierre Pronchery PROV_BLOWFISH_CTX *in = (PROV_BLOWFISH_CTX *)ctx;
38*b077aed3SPierre Pronchery PROV_BLOWFISH_CTX *ret;
39*b077aed3SPierre Pronchery
40*b077aed3SPierre Pronchery if (!ossl_prov_is_running())
41*b077aed3SPierre Pronchery return NULL;
42*b077aed3SPierre Pronchery
43*b077aed3SPierre Pronchery ret = OPENSSL_malloc(sizeof(*ret));
44*b077aed3SPierre Pronchery if (ret == NULL) {
45*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
46*b077aed3SPierre Pronchery return NULL;
47*b077aed3SPierre Pronchery }
48*b077aed3SPierre Pronchery *ret = *in;
49*b077aed3SPierre Pronchery
50*b077aed3SPierre Pronchery return ret;
51*b077aed3SPierre Pronchery }
52*b077aed3SPierre Pronchery
53*b077aed3SPierre Pronchery /* bf_ecb_functions */
54*b077aed3SPierre Pronchery IMPLEMENT_var_keylen_cipher(blowfish, BLOWFISH, ecb, ECB, BF_FLAGS, 128, 64, 0, block)
55*b077aed3SPierre Pronchery /* bf_cbc_functions */
56*b077aed3SPierre Pronchery IMPLEMENT_var_keylen_cipher(blowfish, BLOWFISH, cbc, CBC, BF_FLAGS, 128, 64, 64, block)
57*b077aed3SPierre Pronchery /* bf_ofb_functions */
58*b077aed3SPierre Pronchery IMPLEMENT_var_keylen_cipher(blowfish, BLOWFISH, ofb64, OFB, BF_FLAGS, 128, 8, 64, stream)
59*b077aed3SPierre Pronchery /* bf_cfb_functions */
60*b077aed3SPierre Pronchery IMPLEMENT_var_keylen_cipher(blowfish, BLOWFISH, cfb64, CFB, BF_FLAGS, 128, 8, 64, stream)
61