summaryrefslogtreecommitdiffstats
path: root/providers/default/ciphers
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2019-09-18 18:55:11 +1000
committerShane Lontis <shane.lontis@oracle.com>2019-09-18 18:55:11 +1000
commit18b0042731c739855cddf1f296b0b5a536ef88a3 (patch)
tree0829b995cbcf2b1b339bb86feba5be10ee5d332a /providers/default/ciphers
parentfddb1847b1d53ead95678cbe21004c03c88d506d (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/default/ciphers')
-rw-r--r--providers/default/ciphers/build.info5
-rw-r--r--providers/default/ciphers/cipher_cast.h24
-rw-r--r--providers/default/ciphers/cipher_cast5.c46
-rw-r--r--providers/default/ciphers/cipher_cast5_hw.c36
4 files changed, 111 insertions, 0 deletions
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)