summaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2020-01-15 10:48:01 +1000
committerShane Lontis <shane.lontis@oracle.com>2020-01-15 10:48:01 +1000
commit36fc5fc6bd5ca53fb30aabc38e3fefbab0005b2c (patch)
tree16e416a148ab7e40d416977ab971e315f7b034f1 /crypto
parent76123661a1db136b9ef368dc296a628818e7a4cc (diff)
downloadopenssl-new-36fc5fc6bd5ca53fb30aabc38e3fefbab0005b2c.tar.gz
Add FIPS Self test kats for digests
Added an API to optionally set a self test callback. The callback has the following 2 purposes (1) Output information about the KAT tests. (2) Allow the ability to corrupt one of the KAT's The fipsinstall program uses the API. Some KATS are not included in this PR since the required functionality did not yet exist in the provider. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/10374)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/build.info2
-rw-r--r--crypto/provider_core.c5
-rw-r--r--crypto/self_test_core.c62
3 files changed, 67 insertions, 2 deletions
diff --git a/crypto/build.info b/crypto/build.info
index ab10a1cfe6..daa26b8ed4 100644
--- a/crypto/build.info
+++ b/crypto/build.info
@@ -62,7 +62,7 @@ ENDIF
$CORE_COMMON=provider_core.c provider_predefined.c \
core_fetch.c core_algorithm.c core_namemap.c
-SOURCE[../libcrypto]=$CORE_COMMON provider_conf.c
+SOURCE[../libcrypto]=$CORE_COMMON provider_conf.c self_test_core.c
SOURCE[../providers/libfips.a]=$CORE_COMMON
# Central utilities
diff --git a/crypto/provider_core.c b/crypto/provider_core.c
index c95615f882..2f2d69a0c3 100644
--- a/crypto/provider_core.c
+++ b/crypto/provider_core.c
@@ -18,6 +18,9 @@
#include "internal/provider.h"
#include "internal/refcount.h"
#include "provider_local.h"
+#ifndef FIPS_MODE
+# include <openssl/self_test.h>
+#endif
static OSSL_PROVIDER *provider_new(const char *name,
OSSL_provider_init_fn *init_function);
@@ -874,8 +877,8 @@ static const OSSL_DISPATCH core_dispatch_[] = {
{ OSSL_FUNC_BIO_READ_EX, (void (*)(void))BIO_read_ex },
{ OSSL_FUNC_BIO_FREE, (void (*)(void))BIO_free },
{ OSSL_FUNC_BIO_VPRINTF, (void (*)(void))BIO_vprintf },
+ { OSSL_FUNC_SELF_TEST_CB, (void (*)(void))OSSL_SELF_TEST_get_callback },
#endif
-
{ OSSL_FUNC_CRYPTO_MALLOC, (void (*)(void))CRYPTO_malloc },
{ OSSL_FUNC_CRYPTO_ZALLOC, (void (*)(void))CRYPTO_zalloc },
{ OSSL_FUNC_CRYPTO_FREE, (void (*)(void))CRYPTO_free },
diff --git a/crypto/self_test_core.c b/crypto/self_test_core.c
new file mode 100644
index 0000000000..77864a230b
--- /dev/null
+++ b/crypto/self_test_core.c
@@ -0,0 +1,62 @@
+/*
+ * 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/self_test.h>
+#include "internal/cryptlib.h"
+
+typedef struct self_test_cb_st
+{
+ OSSL_CALLBACK *cb;
+ void *cbarg;
+} SELF_TEST_CB;
+
+static void *self_test_set_callback_new(OPENSSL_CTX *ctx)
+{
+ SELF_TEST_CB *stcb;
+
+ stcb = OPENSSL_zalloc(sizeof(*stcb));
+ return stcb;
+}
+
+static void self_test_set_callback_free(void *stcb)
+{
+ OPENSSL_free(stcb);
+}
+
+static const OPENSSL_CTX_METHOD self_test_set_callback_method = {
+ self_test_set_callback_new,
+ self_test_set_callback_free,
+};
+
+static SELF_TEST_CB *get_self_test_callback(OPENSSL_CTX *libctx)
+{
+ return openssl_ctx_get_data(libctx, OPENSSL_CTX_SELF_TEST_CB_INDEX,
+ &self_test_set_callback_method);
+}
+
+void OSSL_SELF_TEST_set_callback(OPENSSL_CTX *libctx, OSSL_CALLBACK *cb,
+ void *cbarg)
+{
+ SELF_TEST_CB *stcb = get_self_test_callback(libctx);
+
+ if (stcb != NULL) {
+ stcb->cb = cb;
+ stcb->cbarg = cbarg;
+ }
+}
+void OSSL_SELF_TEST_get_callback(OPENSSL_CTX *libctx, OSSL_CALLBACK **cb,
+ void **cbarg)
+{
+ SELF_TEST_CB *stcb = get_self_test_callback(libctx);
+
+ if (cb != NULL)
+ *cb = (stcb != NULL ? stcb->cb : NULL);
+ if (cbarg != NULL)
+ *cbarg = (stcb != NULL ? stcb->cbarg : NULL);
+}