summaryrefslogtreecommitdiff
path: root/lib/libcrypto/sha/sha256_amd64.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2024-11-16 15:31:37 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2024-11-16 15:31:37 +0000
commitbbab9dc78c82fe8745bf14259991978e1b6237dc (patch)
treecea9e5c892fde550461786d717f1ecbab26ba96a /lib/libcrypto/sha/sha256_amd64.c
parent49a5f51943c3561a0a5176f1e4c9b98fd1a65fca (diff)
Provide a SHA-256 assembly implementation for amd64 using SHA-NI.
This provides a SHA-256 assembly implementation for amd64, which uses the Intel SHA Extensions (aka SHA New Instructions or SHA-NI). This provides a 3-5x performance gain on some Intel CPUs and many AMD CPUs. ok tb@
Diffstat (limited to 'lib/libcrypto/sha/sha256_amd64.c')
-rw-r--r--lib/libcrypto/sha/sha256_amd64.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/libcrypto/sha/sha256_amd64.c b/lib/libcrypto/sha/sha256_amd64.c
index f7531b340f3..6c5d3e897f1 100644
--- a/lib/libcrypto/sha/sha256_amd64.c
+++ b/lib/libcrypto/sha/sha256_amd64.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sha256_amd64.c,v 1.1 2024/11/08 15:09:48 jsing Exp $ */
+/* $OpenBSD: sha256_amd64.c,v 1.2 2024/11/16 15:31:36 jsing Exp $ */
/*
* Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
*
@@ -17,10 +17,18 @@
#include <openssl/sha.h>
+#include "crypto_arch.h"
+
void sha256_block_generic(SHA256_CTX *ctx, const void *in, size_t num);
+void sha256_block_shani(SHA256_CTX *ctx, const void *in, size_t num);
void
sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num)
{
+ if ((crypto_cpu_caps_amd64 & CRYPTO_CPU_CAPS_AMD64_SHA) != 0) {
+ sha256_block_shani(ctx, in, num);
+ return;
+ }
+
sha256_block_generic(ctx, in, num);
}