代码拉取完成,页面将自动刷新
同步操作将从 OpenCloudOS Stream/openssl 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 6f4a91a665e123fa037a2d61b314e16033b5bdbf Mon Sep 17 00:00:00 2001
From: zoedong <zoedong@tencent.com>
Date: Tue, 13 Aug 2024 15:47:23 +0800
Subject: [PATCH] turbo: optimized sha256 call chain for improved efficiency
Optimized the SHA256 execution by skipping the EVP framework, leading to
performance improvements.
Performance testing on Intel(R) Xeon(R) Gold 6133 CPU @ 2.50GHz showed
the following improvements.
Test command used: openssl speed -multi 80 -seconds 30 sha256
| Block Size(Bytes) | Before(kB/s) | After(kB/s) | Improvement(%) |
|-------------------|---------------|---------------|----------------|
| 16 | 1,626,936.53 | 2,604,869.21 | 60.12% |
| 64 | 4,281,664.80 | 5,779,046.85 | 34.97% |
| 256 | 9,609,261.08 | 10,987,963.69 | 14.35% |
| 1024 | 13,396,612.57 | 13,995,488.49 | 4.47% |
| 8192 | 15,183,924.43 | 15,275,545.94 | 0.60% |
| 16384 | 15,342,331.43 | 15,391,760.93 | 0.32% |
Signed-off-by: zoedong <zoedong@tencent.com>
---
crypto/evp/build.info | 2 +-
crypto/evp/digest.c | 5 +++++
crypto/evp/digest_fast_path.c | 33 ++++++++++++++++++++++++++++++
include/openssl/digest_fast_path.h | 8 ++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
create mode 100644 crypto/evp/digest_fast_path.c
create mode 100644 include/openssl/digest_fast_path.h
diff --git a/crypto/evp/build.info b/crypto/evp/build.info
index 95fea31..e14f3d0 100644
--- a/crypto/evp/build.info
+++ b/crypto/evp/build.info
@@ -2,7 +2,7 @@ LIBS=../../libcrypto
$COMMON=digest.c evp_enc.c evp_lib.c evp_fetch.c evp_utils.c \
mac_lib.c mac_meth.c keymgmt_meth.c keymgmt_lib.c kdf_lib.c kdf_meth.c \
m_sigver.c pmeth_lib.c signature.c p_lib.c pmeth_gn.c exchange.c \
- evp_rand.c asymcipher.c kem.c dh_support.c ec_support.c pmeth_check.c
+ evp_rand.c asymcipher.c kem.c dh_support.c ec_support.c pmeth_check.c digest_fast_path.c
SOURCE[../../libcrypto]=$COMMON\
encode.c evp_key.c evp_cnf.c \
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index eefed52..cf24f05 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -24,6 +24,7 @@
#include "internal/core.h"
#include "crypto/evp.h"
#include "evp_local.h"
+#include "openssl/digest_fast_path.h"
static void cleanup_old_md_data(EVP_MD_CTX *ctx, int force)
{
@@ -647,6 +648,10 @@ int EVP_Digest(const void *data, size_t count,
unsigned char *md, unsigned int *size, const EVP_MD *type,
ENGINE *impl)
{
+ if (digest_fast_path(data, count, md, size, type)) {
+ return 1;
+ }
+
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
int ret;
diff --git a/crypto/evp/digest_fast_path.c b/crypto/evp/digest_fast_path.c
new file mode 100644
index 0000000..7e744c9
--- /dev/null
+++ b/crypto/evp/digest_fast_path.c
@@ -0,0 +1,33 @@
+#include <openssl/evp.h>
+#include <openssl/sha.h>
+
+int sha256_digest_fast_path(const void *data, size_t count,
+ unsigned char *md, unsigned int *size)
+{
+ static unsigned char m[SHA256_DIGEST_LENGTH];
+ SHA256_CTX ctx;
+
+ if (md == NULL)
+ md = m;
+ SHA256_Init(&ctx);
+ SHA256_Update(&ctx, data, count);
+ SHA256_Final(md, &ctx);
+ OPENSSL_cleanse(&ctx, sizeof(ctx));
+
+ // stores the length of the message digest actually generated
+ if (size != NULL) {
+ *size = SHA256_DIGEST_LENGTH;
+ }
+
+ return 1;
+}
+
+int digest_fast_path(const void *data, size_t count,
+ unsigned char *md, unsigned int *size, const EVP_MD *type)
+{
+ if (EVP_MD_get_type(type) == NID_sha256) {
+ return sha256_digest_fast_path(data, count, md, size);
+ }
+
+ return 0;
+}
diff --git a/include/openssl/digest_fast_path.h b/include/openssl/digest_fast_path.h
new file mode 100644
index 0000000..18d25fc
--- /dev/null
+++ b/include/openssl/digest_fast_path.h
@@ -0,0 +1,8 @@
+#ifndef DIGEST_FAST_PATH_H
+#define DIGEST_FAST_PATH_H
+
+#include <openssl/evp.h>
+
+int digest_fast_path(const void *data, size_t count, unsigned char *md, unsigned int *size, const EVP_MD *type);
+
+#endif // DIGEST_FAST_PATH_H
\ No newline at end of file
--
2.41.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。