diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2019-09-18 18:55:11 +1000 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2019-09-18 18:55:11 +1000 |
commit | 18b0042731c739855cddf1f296b0b5a536ef88a3 (patch) | |
tree | 0829b995cbcf2b1b339bb86feba5be10ee5d332a /providers | |
parent | fddb1847b1d53ead95678cbe21004c03c88d506d (diff) |
Add cast5 ciphers to default provider
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9929)
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_cast.h | 24 | ||||
-rw-r--r-- | providers/default/ciphers/cipher_cast5.c | 46 | ||||
-rw-r--r-- | providers/default/ciphers/cipher_cast5_hw.c | 36 | ||||
-rw-r--r-- | providers/default/defltprov.c | 6 |
6 files changed, 123 insertions, 0 deletions
diff --git a/providers/common/include/internal/provider_algs.h b/providers/common/include/internal/provider_algs.h index 9e0a96e9ad..560a967562 100644 --- a/providers/common/include/internal/provider_algs.h +++ b/providers/common/include/internal/provider_algs.h @@ -128,6 +128,12 @@ extern const OSSL_DISPATCH idea128cbc_functions[]; extern const OSSL_DISPATCH idea128ofb64_functions[]; extern const OSSL_DISPATCH idea128cfb64_functions[]; #endif /* OPENSSL_NO_IDEA */ +#ifndef OPENSSL_NO_CAST +extern const OSSL_DISPATCH cast5128ecb_functions[]; +extern const OSSL_DISPATCH cast5128cbc_functions[]; +extern const OSSL_DISPATCH cast564ofb64_functions[]; +extern const OSSL_DISPATCH cast564cfb64_functions[]; +#endif /* OPENSSL_NO_CAST */ 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 3722215daf..05e45553f9 100644 --- a/providers/default/ciphers/build.info +++ b/providers/default/ciphers/build.info @@ -29,4 +29,9 @@ IF[{- !$disabled{idea} -}] cipher_idea.c cipher_idea_hw.c ENDIF +IF[{- !$disabled{cast} -}] + SOURCE[../../../libcrypto]=\ + cipher_cast5.c cipher_cast5_hw.c +ENDIF + INCLUDE[../../../libcrypto]=. ../../../crypto diff --git a/providers/default/ciphers/cipher_cast.h b/providers/default/ciphers/cipher_cast.h new file mode 100644 index 0000000000..279f92216f --- /dev/null +++ b/providers/default/ciphers/cipher_cast.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/cast.h> +#include "internal/ciphers/ciphercommon.h" + +typedef struct prov_cast_ctx_st { + PROV_CIPHER_CTX base; /* Must be first */ + union { + OSSL_UNION_ALIGN; + CAST_KEY ks; + } ks; +} PROV_CAST_CTX; + +const PROV_CIPHER_HW *PROV_CIPHER_HW_cast5_cbc(size_t keybits); +const PROV_CIPHER_HW *PROV_CIPHER_HW_cast5_ecb(size_t keybits); +const PROV_CIPHER_HW *PROV_CIPHER_HW_cast5_ofb64(size_t keybits); +const PROV_CIPHER_HW *PROV_CIPHER_HW_cast5_cfb64(size_t keybits); diff --git a/providers/default/ciphers/cipher_cast5.c b/providers/default/ciphers/cipher_cast5.c new file mode 100644 index 0000000000..13d48ea091 --- /dev/null +++ b/providers/default/ciphers/cipher_cast5.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 cast cipher modes ecb, cbc, ofb, cfb */ + +#include "cipher_cast.h" +#include "internal/provider_algs.h" + +static OSSL_OP_cipher_freectx_fn cast5_freectx; +static OSSL_OP_cipher_dupctx_fn cast5_dupctx; + +static void cast5_freectx(void *vctx) +{ + PROV_CAST_CTX *ctx = (PROV_CAST_CTX *)vctx; + + OPENSSL_clear_free(ctx, sizeof(*ctx)); +} + +static void *cast5_dupctx(void *ctx) +{ + PROV_CAST_CTX *in = (PROV_CAST_CTX *)ctx; + PROV_CAST_CTX *ret = OPENSSL_malloc(sizeof(*ret)); + + if (ret == NULL) { + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); + return NULL; + } + *ret = *in; + + return ret; +} + +/* cast5128ecb_functions */ +IMPLEMENT_generic_cipher(cast5, CAST, ecb, ECB, EVP_CIPH_VARIABLE_LENGTH, 128, 64, 0, block) +/* cast5128cbc_functions */ +IMPLEMENT_generic_cipher(cast5, CAST, cbc, CBC, EVP_CIPH_VARIABLE_LENGTH, 128, 64, 64, block) +/* cast564ofb64_functions */ +IMPLEMENT_generic_cipher(cast5, CAST, ofb64, OFB, EVP_CIPH_VARIABLE_LENGTH, 64, 8, 64, stream) +/* cast564cfb64_functions */ +IMPLEMENT_generic_cipher(cast5, CAST, cfb64, CFB, EVP_CIPH_VARIABLE_LENGTH, 64, 8, 64, stream) diff --git a/providers/default/ciphers/cipher_cast5_hw.c b/providers/default/ciphers/cipher_cast5_hw.c new file mode 100644 index 0000000000..227e90d7a7 --- /dev/null +++ b/providers/default/ciphers/cipher_cast5_hw.c @@ -0,0 +1,36 @@ +/* + * 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_cast.h" + +static int cipher_hw_cast5_initkey(PROV_CIPHER_CTX *ctx, + const unsigned char *key, size_t keylen) +{ + PROV_CAST_CTX *bctx = (PROV_CAST_CTX *)ctx; + + CAST_set_key(&(bctx->ks.ks), keylen, key); + return 1; +} + +# define PROV_CIPHER_HW_cast_mode(mode, UCMODE) \ +IMPLEMENT_CIPHER_HW_##UCMODE(mode, cast5, PROV_CAST_CTX, CAST_KEY, \ + CAST_##mode) \ +static const PROV_CIPHER_HW cast5_##mode = { \ + cipher_hw_cast5_initkey, \ + cipher_hw_cast5_##mode##_cipher \ +}; \ +const PROV_CIPHER_HW *PROV_CIPHER_HW_cast5_##mode(size_t keybits) \ +{ \ + return &cast5_##mode; \ +} + +PROV_CIPHER_HW_cast_mode(cbc, CBC) +PROV_CIPHER_HW_cast_mode(ecb, ECB) +PROV_CIPHER_HW_cast_mode(ofb64, OFB) +PROV_CIPHER_HW_cast_mode(cfb64, CFB) diff --git a/providers/default/defltprov.c b/providers/default/defltprov.c index cd91ba7ba1..a6a6c9f470 100644 --- a/providers/default/defltprov.c +++ b/providers/default/defltprov.c @@ -201,6 +201,12 @@ static const OSSL_ALGORITHM deflt_ciphers[] = { { "IDEA-OFB", "default=yes", idea128ofb64_functions }, { "IDEA-CFB", "default=yes", idea128cfb64_functions }, #endif /* OPENSSL_NO_IDEA */ +#ifndef OPENSSL_NO_CAST + { "CAST5-ECB", "default=yes", cast5128ecb_functions }, + { "CAST5-CBC", "default=yes", cast5128cbc_functions }, + { "CAST5-OFB", "default=yes", cast564ofb64_functions }, + { "CAST5-CFB", "default=yes", cast564cfb64_functions }, +#endif /* OPENSSL_NO_CAST */ { NULL, NULL, NULL } }; |