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