diff --git a/libxcrypt-4.4.33-SHA512_Maj_optimization.patch b/libxcrypt-4.4.33-SHA512_Maj_optimization.patch new file mode 100644 index 0000000..3ecff47 --- /dev/null +++ b/libxcrypt-4.4.33-SHA512_Maj_optimization.patch @@ -0,0 +1,54 @@ +From 59823543d095ad0fe4a063d819c52953249c9ba0 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Wed, 7 Dec 2022 07:04:51 +0100 +Subject: [PATCH] alg-sha512.c: SHA-2 Maj() optimization proposed by Wei Dai. + +This patch has already been applied to 'lib/alg-sha256.c' +in commit bb1721800932268a537c804a4b7655af8c62d5e8. +--- + lib/alg-sha512.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/lib/alg-sha512.c b/lib/alg-sha512.c +index c30f8a0..4e9965d 100644 +--- a/lib/alg-sha512.c ++++ b/lib/alg-sha512.c +@@ -1,6 +1,7 @@ + /*- + * Copyright 2005 Colin Percival + * Copyright (c) 2015 Allan Jude ++ * Copyright 2021, 2022 Alexander Peslyak + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without +@@ -78,7 +79,11 @@ static const uint64_t K[80] = { + + /* Elementary functions used by SHA512 */ + #define Ch(x, y, z) ((x & (y ^ z)) ^ z) +-#define Maj(x, y, z) ((x & (y | z)) | (y & z)) ++#if 1 /* Explicit caching/reuse of common subexpression between rounds */ ++#define Maj(x, y, z) (y ^ ((x_xor_y = x ^ y) & y_xor_z)) ++#else /* Let the compiler cache/reuse or not */ ++#define Maj(x, y, z) (y ^ ((x ^ y) & (y ^ z))) ++#endif + #define SHR(x, n) (x >> n) + #define ROTR(x, n) ((x >> n) | (x << (64 - n))) + #define S0(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39)) +@@ -90,7 +95,8 @@ static const uint64_t K[80] = { + #define RND(a, b, c, d, e, f, g, h, k) \ + h += S1(e) + Ch(e, f, g) + k; \ + d += h; \ +- h += S0(a) + Maj(a, b, c); ++ h += S0(a) + Maj(a, b, c); \ ++ y_xor_z = x_xor_y; + + /* Adjusted round function for rotating state */ + #define RNDr(S, W, i, ii) \ +@@ -123,6 +129,7 @@ SHA512_Transform(uint64_t * state, const unsigned char block[SHA512_BLOCK_LENGTH + + /* 3. Mix. */ + for (i = 0; i < 80; i += 16) { ++ uint64_t x_xor_y, y_xor_z = S[(65 - i) % 8] ^ S[(66 - i) % 8]; + RNDr(S, W, 0, i); + RNDr(S, W, 1, i); + RNDr(S, W, 2, i); diff --git a/libxcrypt.spec b/libxcrypt.spec index 5abee57..1089182 100644 --- a/libxcrypt.spec +++ b/libxcrypt.spec @@ -162,7 +162,7 @@ fi \ Name: libxcrypt Version: 4.4.33 -Release: 3%{?dist} +Release: 4%{?dist} Summary: Extended crypt library for descrypt, md5crypt, bcrypt, and others # For explicit license breakdown, see the @@ -176,6 +176,7 @@ Source3: %{url}/releases/download/v%{version}/%{name}-%{version}.tar.xz.s # Patch 0000 - 2999: Backported patches from upstream. Patch0000: %{url}/commit/9d5e7b7307f2.patch#/%{name}-4.4.33-yescrypt_platform_cast_performance.patch +Patch0001: %{url}/commit/59823543d095.patch#/%{name}-4.4.33-SHA512_Maj_optimization.patch # Patch 3000 - 5999: Backported patches from pull requests. @@ -576,6 +577,9 @@ done %changelog +* Tue Dec 13 2022 Björn Esser - 4.4.33-4 +- Add upstream patch to improve performance on SHA512 computation + * Mon Nov 28 2022 Björn Esser - 4.4.33-3 - Convert License to SPDX expression - Add upstream patch to improve performance on some type-cast operations