-From 37a5c14aad5051201e4bd18faf1a4b25a824cc30 Mon Sep 17 00:00:00 2001
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Eneas U de Queiroz <cote2004-github@yahoo.com>
Date: Tue, 6 Nov 2018 10:57:03 -0200
-Subject: [PATCH 4/4] e_devcrypto: make the /dev/crypto engine dynamic
+Subject: e_devcrypto: make the /dev/crypto engine dynamic
Engine has been moved from crypto/engine/eng_devcrypto.c to
engines/e_devcrypto.c.
-ENDIF
--- a/crypto/init.c
+++ b/crypto/init.c
-@@ -330,18 +330,6 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_engine_
+@@ -328,18 +328,6 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_engine_
engine_load_openssl_int();
return 1;
}
# ifndef OPENSSL_NO_RDRAND
static CRYPTO_ONCE engine_rdrand = CRYPTO_ONCE_STATIC_INIT;
-@@ -366,6 +354,18 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_engine_
+@@ -364,6 +352,18 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_engine_
return 1;
}
# ifndef OPENSSL_NO_STATIC_ENGINE
# if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
static CRYPTO_ONCE engine_padlock = CRYPTO_ONCE_STATIC_INIT;
DEFINE_RUN_ONCE_STATIC(ossl_init_engine_padlock)
-@@ -714,11 +714,6 @@ int OPENSSL_init_crypto(uint64_t opts, c
+@@ -704,11 +704,6 @@ int OPENSSL_init_crypto(uint64_t opts, c
if ((opts & OPENSSL_INIT_ENGINE_OPENSSL)
&& !RUN_ONCE(&engine_openssl, ossl_init_engine_openssl))
return 0;
# ifndef OPENSSL_NO_RDRAND
if ((opts & OPENSSL_INIT_ENGINE_RDRAND)
&& !RUN_ONCE(&engine_rdrand, ossl_init_engine_rdrand))
-@@ -728,6 +723,11 @@ int OPENSSL_init_crypto(uint64_t opts, c
+@@ -718,6 +713,11 @@ int OPENSSL_init_crypto(uint64_t opts, c
&& !RUN_ONCE(&engine_dynamic, ossl_init_engine_dynamic))
return 0;
# ifndef OPENSSL_NO_STATIC_ENGINE
&& !RUN_ONCE(&engine_padlock, ossl_init_engine_padlock))
--- a/engines/build.info
+++ b/engines/build.info
-@@ -10,6 +10,9 @@ IF[{- !$disabled{"engine"} -}]
+@@ -11,6 +11,9 @@ IF[{- !$disabled{"engine"} -}]
IF[{- !$disabled{afalgeng} -}]
SOURCE[../libcrypto]=e_afalg.c
ENDIF
+ SOURCE[../libcrypto]=e_devcrypto.c
+ ENDIF
ELSE
- ENGINES=padlock
- SOURCE[padlock]=e_padlock.c {- $target{padlock_asm_src} -}
-@@ -27,6 +30,12 @@ IF[{- !$disabled{"engine"} -}]
+ IF[{- !$disabled{hw} && !$disabled{'hw-padlock'} -}]
+ ENGINES=padlock
+@@ -30,6 +33,12 @@ IF[{- !$disabled{"engine"} -}]
DEPEND[afalg]=../libcrypto
INCLUDE[afalg]= ../include
ENDIF
SOURCE[dasync]=e_dasync.c
--- a/crypto/engine/eng_devcrypto.c
+++ /dev/null
-@@ -1,1264 +0,0 @@
+@@ -1,1277 +0,0 @@
-/*
-- * Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
+- * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
- *
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
-#include <openssl/objects.h>
-#include <crypto/cryptodev.h>
-
--#include "internal/engine.h"
+-#include "crypto/engine.h"
-
-/* #define ENGINE_DEVCRYPTO_DEBUG */
-
--#ifdef CRYPTO_ALGORITHM_MIN
+-#if CRYPTO_ALGORITHM_MIN < CRYPTO_ALGORITHM_MAX
-# define CHECK_BSD_STYLE_MACROS
-#endif
-
-void engine_load_devcrypto_int()
-{
- ENGINE *e = NULL;
+- int fd;
-
-- if ((cfd = open("/dev/crypto", O_RDWR, 0)) < 0) {
+- if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
-#ifndef ENGINE_DEVCRYPTO_DEBUG
- if (errno != ENOENT)
-#endif
- return;
- }
-
+-#ifdef CRIOGET
+- if (ioctl(fd, CRIOGET, &cfd) < 0) {
+- fprintf(stderr, "Could not create crypto fd: %s\n", strerror(errno));
+- close(fd);
+- cfd = -1;
+- return;
+- }
+- close(fd);
+-#else
+- cfd = fd;
+-#endif
+-
- if ((e = ENGINE_new()) == NULL
- || !ENGINE_set_destroy_function(e, devcrypto_unload)) {
- ENGINE_free(e);
-}
--- /dev/null
+++ b/engines/e_devcrypto.c
-@@ -0,0 +1,1315 @@
+@@ -0,0 +1,1327 @@
+/*
-+ * Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
++ * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+#include <openssl/objects.h>
+#include <crypto/cryptodev.h>
+
++#include "crypto/engine.h"
++
+/* #define ENGINE_DEVCRYPTO_DEBUG */
+
-+#ifdef CRYPTO_ALGORITHM_MIN
++#if CRYPTO_ALGORITHM_MIN < CRYPTO_ALGORITHM_MAX
+# define CHECK_BSD_STYLE_MACROS
+#endif
+
+ char *driver_name;
+};
+
-+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
-+void engine_load_devcrypto_int(void);
-+#endif
-+
+static int clean_devcrypto_session(struct session_op *sess) {
+ if (ioctl(cfd, CIOCFSESSION, &sess->ses) < 0) {
+ SYSerr(SYS_F_IOCTL, errno);
+ struct cipher_ctx *to_cipher_ctx;
+
+ switch (type) {
-+
+ case EVP_CTRL_COPY:
+ if (cipher_ctx == NULL)
+ return 1;
+ SYSerr(SYS_F_IOCTL, errno);
+ return 0;
+ }
++
+ return 1;
+}
+
+ */
+static int open_devcrypto(void)
+{
++ int fd;
++
+ if (cfd >= 0)
+ return 1;
+
-+ if ((cfd = open("/dev/crypto", O_RDWR, 0)) < 0) {
++ if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
+#ifndef ENGINE_DEVCRYPTO_DEBUG
+ if (errno != ENOENT)
+#endif
+ return 0;
+ }
+
++#ifdef CRIOGET
++ if (ioctl(fd, CRIOGET, &cfd) < 0) {
++ fprintf(stderr, "Could not create crypto fd: %s\n", strerror(errno));
++ close(fd);
++ cfd = -1;
++ return 0;
++ }
++ close(fd);
++#else
++ cfd = fd;
++#endif
++
+ return 1;
+}
+