xref: /netbsd-src/crypto/external/bsd/openssl/dist/providers/implementations/ciphers/cipher_idea.c (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1*b0d17251Schristos /*
2*b0d17251Schristos  * Copyright 2019-2020 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  * IDEA low level APIs are deprecated for public use, but still ok for internal
12*b0d17251Schristos  * use where we're using them to implement the higher level EVP interface, as is
13*b0d17251Schristos  * the case here.
14*b0d17251Schristos  */
15*b0d17251Schristos #include "internal/deprecated.h"
16*b0d17251Schristos 
17*b0d17251Schristos /* Dispatch functions for Idea cipher modes ecb, cbc, ofb, cfb */
18*b0d17251Schristos 
19*b0d17251Schristos #include "cipher_idea.h"
20*b0d17251Schristos #include "prov/implementations.h"
21*b0d17251Schristos #include "prov/providercommon.h"
22*b0d17251Schristos 
23*b0d17251Schristos static OSSL_FUNC_cipher_freectx_fn idea_freectx;
24*b0d17251Schristos static OSSL_FUNC_cipher_dupctx_fn idea_dupctx;
25*b0d17251Schristos 
idea_freectx(void * vctx)26*b0d17251Schristos static void idea_freectx(void *vctx)
27*b0d17251Schristos {
28*b0d17251Schristos     PROV_IDEA_CTX *ctx = (PROV_IDEA_CTX *)vctx;
29*b0d17251Schristos 
30*b0d17251Schristos     ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
31*b0d17251Schristos     OPENSSL_clear_free(ctx,  sizeof(*ctx));
32*b0d17251Schristos }
33*b0d17251Schristos 
idea_dupctx(void * ctx)34*b0d17251Schristos static void *idea_dupctx(void *ctx)
35*b0d17251Schristos {
36*b0d17251Schristos     PROV_IDEA_CTX *in = (PROV_IDEA_CTX *)ctx;
37*b0d17251Schristos     PROV_IDEA_CTX *ret;
38*b0d17251Schristos 
39*b0d17251Schristos     if (!ossl_prov_is_running())
40*b0d17251Schristos         return NULL;
41*b0d17251Schristos 
42*b0d17251Schristos     ret = OPENSSL_malloc(sizeof(*ret));
43*b0d17251Schristos     if (ret == NULL) {
44*b0d17251Schristos         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
45*b0d17251Schristos         return NULL;
46*b0d17251Schristos     }
47*b0d17251Schristos     *ret = *in;
48*b0d17251Schristos 
49*b0d17251Schristos     return ret;
50*b0d17251Schristos }
51*b0d17251Schristos 
52*b0d17251Schristos /* ossl_idea128ecb_functions */
53*b0d17251Schristos IMPLEMENT_generic_cipher(idea, IDEA, ecb, ECB, 0, 128, 64, 0, block)
54*b0d17251Schristos /* ossl_idea128cbc_functions */
55*b0d17251Schristos IMPLEMENT_generic_cipher(idea, IDEA, cbc, CBC, 0, 128, 64, 64, block)
56*b0d17251Schristos /* ossl_idea128ofb64_functions */
57*b0d17251Schristos IMPLEMENT_generic_cipher(idea, IDEA, ofb64, OFB, 0, 128, 8, 64, stream)
58*b0d17251Schristos /* ossl_idea128cfb64_functions */
59*b0d17251Schristos IMPLEMENT_generic_cipher(idea, IDEA, cfb64,  CFB, 0, 128, 8, 64, stream)
60