diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2019-09-18 15:57:08 +1000 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2019-09-18 15:57:08 +1000 |
commit | f22431f2cd9e96cf75fd020c6e5019ff58f710cf (patch) | |
tree | c699b366e86c6a4754b3fc38a04ef91bf1373e91 /providers | |
parent | ecae0575103918868b29cc11aa35e3b91fe7dcc8 (diff) |
Add IDEA ciphers to default provider
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9917)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/common/include/internal/provider_algs.h | 6 | ||||
-rw-r--r-- | providers/default/ciphers/build.info | 5 | ||||
-rw-r--r-- | providers/default/ciphers/cipher_idea.c | 46 | ||||
-rw-r--r-- | providers/default/ciphers/cipher_idea.h | 24 | ||||
-rw-r--r-- | providers/default/ciphers/cipher_idea_hw.c | 56 | ||||
-rw-r--r-- | providers/default/defltprov.c | 6 |
6 files changed, 143 insertions, 0 deletions
diff --git a/providers/common/include/internal/provider_algs.h b/providers/common/include/internal/provider_algs.h index 5f54612b0a..9e0a96e9ad 100644 --- a/providers/common/include/internal/provider_algs.h +++ b/providers/common/include/internal/provider_algs.h @@ -122,6 +122,12 @@ extern const OSSL_DISPATCH blowfish128cbc_functions[]; extern const OSSL_DISPATCH blowfish64ofb64_functions[]; extern const OSSL_DISPATCH blowfish64cfb64_functions[]; #endif /* OPENSSL_NO_BF */ +#ifndef OPENSSL_NO_IDEA +extern const OSSL_DISPATCH idea128ecb_functions[]; +extern const OSSL_DISPATCH idea128cbc_functions[]; +extern const OSSL_DISPATCH idea128ofb64_functions[]; +extern const OSSL_DISPATCH idea128cfb64_functions[]; +#endif /* OPENSSL_NO_IDEA */ extern const OSSL_DISPATCH tdes_ede3_ecb_functions[]; extern const OSSL_DISPATCH tdes_ede3_cbc_functions[]; diff --git a/providers/default/ciphers/build.info b/providers/default/ciphers/build.info index a4ca5cc6c8..3722215daf 100644 --- a/providers/default/ciphers/build.info +++ b/providers/default/ciphers/build.info @@ -24,4 +24,9 @@ IF[{- !$disabled{bf} -}] cipher_blowfish.c cipher_blowfish_hw.c ENDIF +IF[{- !$disabled{idea} -}] + SOURCE[../../../libcrypto]=\ + cipher_idea.c cipher_idea_hw.c +ENDIF + INCLUDE[../../../libcrypto]=. ../../../crypto diff --git a/providers/default/ciphers/cipher_idea.c b/providers/default/ciphers/cipher_idea.c new file mode 100644 index 0000000000..6bb5419b6d --- /dev/null +++ b/providers/default/ciphers/cipher_idea.c @@ -0,0 +1,46 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* Dispatch functions for Idea cipher modes ecb, cbc, ofb, cfb */ + +#include "cipher_idea.h" +#include "internal/provider_algs.h" + +static OSSL_OP_cipher_freectx_fn idea_freectx; +static OSSL_OP_cipher_dupctx_fn idea_dupctx; + +static void idea_freectx(void *vctx) +{ + PROV_IDEA_CTX *ctx = (PROV_IDEA_CTX *)vctx; + + OPENSSL_clear_free(ctx, sizeof(*ctx)); +} + +static void *idea_dupctx(void *ctx) +{ + PROV_IDEA_CTX *in = (PROV_IDEA_CTX *)ctx; + PROV_IDEA_CTX *ret = OPENSSL_malloc(sizeof(*ret)); + + if (ret == NULL) { + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); + return NULL; + } + *ret = *in; + + return ret; +} + +/* idea128ecb_functions */ +IMPLEMENT_generic_cipher(idea, IDEA, ecb, ECB, 0, 128, 64, 0, block) +/* idea128cbc_functions */ +IMPLEMENT_generic_cipher(idea, IDEA, cbc, CBC, 0, 128, 64, 64, block) +/* idea128ofb64_functions */ +IMPLEMENT_generic_cipher(idea, IDEA, ofb64, OFB, 0, 128, 8, 64, stream) +/* idea128cfb64_functions */ +IMPLEMENT_generic_cipher(idea, IDEA, cfb64, CFB, 0, 128, 8, 64, stream) diff --git a/providers/default/ciphers/cipher_idea.h b/providers/default/ciphers/cipher_idea.h new file mode 100644 index 0000000000..8e096bfe9f --- /dev/null +++ b/providers/default/ciphers/cipher_idea.h @@ -0,0 +1,24 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <openssl/idea.h> +#include "internal/ciphers/ciphercommon.h" + +typedef struct prov_idea_ctx_st { + PROV_CIPHER_CTX base; /* Must be first */ + union { + OSSL_UNION_ALIGN; + IDEA_KEY_SCHEDULE ks; + } ks; +} PROV_IDEA_CTX; + +const PROV_CIPHER_HW *PROV_CIPHER_HW_idea_cbc(size_t keybits); +const PROV_CIPHER_HW *PROV_CIPHER_HW_idea_ecb(size_t keybits); +const PROV_CIPHER_HW *PROV_CIPHER_HW_idea_ofb64(size_t keybits); +const PROV_CIPHER_HW *PROV_CIPHER_HW_idea_cfb64(size_t keybits); diff --git a/providers/default/ciphers/cipher_idea_hw.c b/providers/default/ciphers/cipher_idea_hw.c new file mode 100644 index 0000000000..d722cc7a27 --- /dev/null +++ b/providers/default/ciphers/cipher_idea_hw.c @@ -0,0 +1,56 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "cipher_idea.h" + +static int cipher_hw_idea_initkey(PROV_CIPHER_CTX *ctx, + const unsigned char *key, size_t keylen) +{ + PROV_IDEA_CTX *ictx = (PROV_IDEA_CTX *)ctx; + IDEA_KEY_SCHEDULE *ks = &(ictx->ks.ks); + + if (ctx->enc + || ctx->mode == EVP_CIPH_OFB_MODE + || ctx->mode == EVP_CIPH_CFB_MODE) { + IDEA_set_encrypt_key(key, ks); + } else { + IDEA_KEY_SCHEDULE tmp; + + IDEA_set_encrypt_key(key, &tmp); + IDEA_set_decrypt_key(&tmp, ks); + OPENSSL_cleanse((unsigned char *)&tmp, sizeof(IDEA_KEY_SCHEDULE)); + } + return 1; +} + +# define PROV_CIPHER_HW_idea_mode_ex(mode, UCMODE, fname) \ +IMPLEMENT_CIPHER_HW_##UCMODE(mode, idea, PROV_IDEA_CTX, IDEA_KEY_SCHEDULE, \ + fname) \ +static const PROV_CIPHER_HW idea_##mode = { \ + cipher_hw_idea_initkey, \ + cipher_hw_idea_##mode##_cipher \ +}; \ +const PROV_CIPHER_HW *PROV_CIPHER_HW_idea_##mode(size_t keybits) \ +{ \ + return &idea_##mode; \ +} + +# define PROV_CIPHER_HW_idea_mode(mode, UCMODE) \ + PROV_CIPHER_HW_idea_mode_ex(mode, UCMODE, IDEA_##mode) + +PROV_CIPHER_HW_idea_mode(cbc, CBC) +PROV_CIPHER_HW_idea_mode(ofb64, OFB) +PROV_CIPHER_HW_idea_mode(cfb64, CFB) +/* + * IDEA_ecb_encrypt() does not have a enc parameter - so we create a macro + * that ignores this parameter when IMPLEMENT_CIPHER_HW_ecb() is called. + */ +#define IDEA2_ecb_encrypt(in, out, ks, enc) IDEA_ecb_encrypt(in, out, ks) + +PROV_CIPHER_HW_idea_mode_ex(ecb, ECB, IDEA2_ecb) diff --git a/providers/default/defltprov.c b/providers/default/defltprov.c index 59a7b60e83..cd91ba7ba1 100644 --- a/providers/default/defltprov.c +++ b/providers/default/defltprov.c @@ -195,6 +195,12 @@ static const OSSL_ALGORITHM deflt_ciphers[] = { { "BF-OFB", "default=yes", blowfish64ofb64_functions }, { "BF-CFB", "default=yes", blowfish64cfb64_functions }, #endif /* OPENSSL_NO_BF */ +#ifndef OPENSSL_NO_IDEA + { "IDEA-ECB", "default=yes", idea128ecb_functions }, + { "IDEA-CBC", "default=yes", idea128cbc_functions }, + { "IDEA-OFB", "default=yes", idea128ofb64_functions }, + { "IDEA-CFB", "default=yes", idea128cfb64_functions }, +#endif /* OPENSSL_NO_IDEA */ { NULL, NULL, NULL } }; |