From 487da616d8ed3fd6ad6c30584c6405c6979ede11 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Fri, 8 Nov 2024 15:09:48 +0000 Subject: Provide a replacement assembly implementation for SHA-256 on amd64. Replace the perlasm generated SHA-256 assembly implementation with one that is actually readable. Call the assembly implementation from a C wrapper that can, in the future, dispatch to alternate implementations. Performance is similar (or even better) on modern CPUs, while somewhat slower on older CPUs (this is in part due to the wrapper, the impact of which is more noticable with small block sizes). Thanks to gkoehler@ and tb@ for testing. ok tb@ --- src/lib/libcrypto/sha/sha256_amd64.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/lib/libcrypto/sha/sha256_amd64.c (limited to 'src/lib/libcrypto/sha/sha256_amd64.c') diff --git a/src/lib/libcrypto/sha/sha256_amd64.c b/src/lib/libcrypto/sha/sha256_amd64.c new file mode 100644 index 0000000000..f7531b340f --- /dev/null +++ b/src/lib/libcrypto/sha/sha256_amd64.c @@ -0,0 +1,26 @@ +/* $OpenBSD: sha256_amd64.c,v 1.1 2024/11/08 15:09:48 jsing Exp $ */ +/* + * Copyright (c) 2024 Joel Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +void sha256_block_generic(SHA256_CTX *ctx, const void *in, size_t num); + +void +sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num) +{ + sha256_block_generic(ctx, in, num); +} -- cgit v1.2.3-55-g6feb