summaryrefslogtreecommitdiffstats
path: root/providers/default/ciphers
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2019-09-18 22:13:59 +1000
committerShane Lontis <shane.lontis@oracle.com>2019-09-18 22:13:59 +1000
commit70adc64632dde9359c8c1c23d01ef7f68d51382e (patch)
tree4a2773f14dde1e47f4920f0d3fb094e3cfba1415 /providers/default/ciphers
parent9a92bf1bffad15ede5ac97d1f1705c3e2c249a98 (diff)
Add SEED ciphers to default provider
Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9932)
Diffstat (limited to 'providers/default/ciphers')
-rw-r--r--providers/default/ciphers/build.info5
-rw-r--r--providers/default/ciphers/cipher_seed.c49
-rw-r--r--providers/default/ciphers/cipher_seed.h24
-rw-r--r--providers/default/ciphers/cipher_seed_hw.c36
4 files changed, 114 insertions, 0 deletions
diff --git a/providers/default/ciphers/build.info b/providers/default/ciphers/build.info
index 05e45553f9..66ef9df68a 100644
--- a/providers/default/ciphers/build.info
+++ b/providers/default/ciphers/build.info
@@ -34,4 +34,9 @@ IF[{- !$disabled{cast} -}]
cipher_cast5.c cipher_cast5_hw.c
ENDIF
+IF[{- !$disabled{seed} -}]
+ SOURCE[../../../libcrypto]=\
+ cipher_seed.c cipher_seed_hw.c
+ENDIF
+
INCLUDE[../../../libcrypto]=. ../../../crypto
diff --git a/providers/default/ciphers/cipher_seed.c b/providers/default/ciphers/cipher_seed.c
new file mode 100644
index 0000000000..5dfa648c96
--- /dev/null
+++ b/providers/default/ciphers/cipher_seed.c
@@ -0,0 +1,49 @@
+/*
+ * 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 Seed cipher modes ecb, cbc, ofb, cfb */
+
+#include "cipher_seed.h"
+#include "internal/provider_algs.h"
+
+/* TODO (3.0) Figure out what flags are required */
+#define SEED_FLAGS EVP_CIPH_FLAG_DEFAULT_ASN1
+
+static OSSL_OP_cipher_freectx_fn seed_freectx;
+static OSSL_OP_cipher_dupctx_fn seed_dupctx;
+
+static void seed_freectx(void *vctx)
+{
+ PROV_SEED_CTX *ctx = (PROV_SEED_CTX *)vctx;
+
+ OPENSSL_clear_free(ctx, sizeof(*ctx));
+}
+
+static void *seed_dupctx(void *ctx)
+{
+ PROV_SEED_CTX *in = (PROV_SEED_CTX *)ctx;
+ PROV_SEED_CTX *ret = OPENSSL_malloc(sizeof(*ret));
+
+ if (ret == NULL) {
+ ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+ *ret = *in;
+
+ return ret;
+}
+
+/* seed128ecb_functions */
+IMPLEMENT_generic_cipher(seed, SEED, ecb, ECB, SEED_FLAGS, 128, 128, 0, block)
+/* seed128cbc_functions */
+IMPLEMENT_generic_cipher(seed, SEED, cbc, CBC, SEED_FLAGS, 128, 128, 128, block)
+/* seed128ofb128_functions */
+IMPLEMENT_generic_cipher(seed, SEED, ofb128, OFB, SEED_FLAGS, 128, 8, 128, stream)
+/* seed128cfb128_functions */
+IMPLEMENT_generic_cipher(seed, SEED, cfb128, CFB, SEED_FLAGS, 128, 8, 128, stream)
diff --git a/providers/default/ciphers/cipher_seed.h b/providers/default/ciphers/cipher_seed.h
new file mode 100644
index 0000000000..093cd3bb5d
--- /dev/null
+++ b/providers/default/ciphers/cipher_seed.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/seed.h>
+#include "internal/ciphers/ciphercommon.h"
+
+typedef struct prov_seed_ctx_st {
+ PROV_CIPHER_CTX base; /* Must be first */
+ union {
+ OSSL_UNION_ALIGN;
+ SEED_KEY_SCHEDULE ks;
+ } ks;
+} PROV_SEED_CTX;
+
+const PROV_CIPHER_HW *PROV_CIPHER_HW_seed_cbc(size_t keybits);
+const PROV_CIPHER_HW *PROV_CIPHER_HW_seed_ecb(size_t keybits);
+const PROV_CIPHER_HW *PROV_CIPHER_HW_seed_ofb128(size_t keybits);
+const PROV_CIPHER_HW *PROV_CIPHER_HW_seed_cfb128(size_t keybits);
diff --git a/providers/default/ciphers/cipher_seed_hw.c b/providers/default/ciphers/cipher_seed_hw.c
new file mode 100644
index 0000000000..3bd3323dc0
--- /dev/null
+++ b/providers/default/ciphers/cipher_seed_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_seed.h"
+
+static int cipher_hw_seed_initkey(PROV_CIPHER_CTX *ctx,
+ const unsigned char *key, size_t keylen)
+{
+ PROV_SEED_CTX *sctx = (PROV_SEED_CTX *)ctx;
+
+ SEED_set_key(key, &(sctx->ks.ks));
+ return 1;
+}
+
+# define PROV_CIPHER_HW_seed_mode(mode, UCMODE) \
+IMPLEMENT_CIPHER_HW_##UCMODE(mode, seed, PROV_SEED_CTX, SEED_KEY_SCHEDULE, \
+ SEED_##mode) \
+static const PROV_CIPHER_HW seed_##mode = { \
+ cipher_hw_seed_initkey, \
+ cipher_hw_seed_##mode##_cipher \
+}; \
+const PROV_CIPHER_HW *PROV_CIPHER_HW_seed_##mode(size_t keybits) \
+{ \
+ return &seed_##mode; \
+}
+
+PROV_CIPHER_HW_seed_mode(cbc, CBC)
+PROV_CIPHER_HW_seed_mode(ecb, ECB)
+PROV_CIPHER_HW_seed_mode(ofb128, OFB)
+PROV_CIPHER_HW_seed_mode(cfb128, CFB)