diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-07-12 19:30:14 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-07-12 19:30:14 +0200 |
commit | 1ad2f5cd9fe5de0f19212924e100c6d87229c950 (patch) | |
tree | 569108f2797fed51977b116455236351df09a87f | |
parent | 999e290ef64cbd49a9e0a0f6d3cfaf26414c1c3e (diff) | |
download | busybox-w32-1ad2f5cd9fe5de0f19212924e100c6d87229c950.tar.gz busybox-w32-1ad2f5cd9fe5de0f19212924e100c6d87229c950.tar.bz2 busybox-w32-1ad2f5cd9fe5de0f19212924e100c6d87229c950.zip |
tls: fix CONFIG_FEATURE_TLS_SHA1=y + CONFIG_SHA1_HWACCEL=y
The check for result hash size was buggy for CONFIG_SHA1_HWACCEL=y.
While at it, document CPUID use a bit better.
function old new delta
get_shaNI - 28 +28
sha1_end 66 79 +13
sha256_begin 83 60 -23
sha1_begin 111 88 -23
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 41/-46) Total: -5 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/hash_md5_sha.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 88baf51dc..57a801459 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c | |||
@@ -15,18 +15,28 @@ | |||
15 | 15 | ||
16 | #if ENABLE_SHA1_HWACCEL || ENABLE_SHA256_HWACCEL | 16 | #if ENABLE_SHA1_HWACCEL || ENABLE_SHA256_HWACCEL |
17 | # if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | 17 | # if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) |
18 | static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) | 18 | static void cpuid_eax_ebx_ecx(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) |
19 | { | 19 | { |
20 | asm ("cpuid" | 20 | asm ("cpuid" |
21 | : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) | 21 | : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) |
22 | : "0"(*eax), "1"(*ebx), "2"(*ecx), "3"(*edx) | 22 | : "0" (*eax), "1" (*ebx), "2" (*ecx) |
23 | ); | 23 | ); |
24 | } | 24 | } |
25 | static smallint shaNI; | 25 | static smallint shaNI; |
26 | static int get_shaNI(void) | 26 | static NOINLINE int get_shaNI(void) |
27 | { | 27 | { |
28 | unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx; | 28 | /* Get leaf 7 subleaf 0. Exists on all CPUs since Merom (2006). |
29 | cpuid(&eax, &ebx, &ecx, &edx); | 29 | * "If a value entered for CPUID.EAX is higher than the maximum |
30 | * input value for basic or extended function for that processor | ||
31 | * then the data for the highest basic information leaf is returned". | ||
32 | * This means that Pentiums 4 would return leaf 5 or 6 instead of 7, | ||
33 | * which happen to have zero in EBX bit 29. Thus they should work too. | ||
34 | */ | ||
35 | unsigned eax = 7; | ||
36 | unsigned ecx = 0; | ||
37 | unsigned ebx = 0; /* should not be needed, paranoia */ | ||
38 | unsigned edx; | ||
39 | cpuid_eax_ebx_ecx(&eax, &ebx, &ecx, &edx); | ||
30 | ebx = ((ebx >> 28) & 2) - 1; /* bit 29 -> 1 or -1 */ | 40 | ebx = ((ebx >> 28) & 2) - 1; /* bit 29 -> 1 or -1 */ |
31 | shaNI = (int)ebx; | 41 | shaNI = (int)ebx; |
32 | return (int)ebx; | 42 | return (int)ebx; |
@@ -1300,7 +1310,14 @@ unsigned FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) | |||
1300 | /* SHA stores total in BE, need to swap on LE arches: */ | 1310 | /* SHA stores total in BE, need to swap on LE arches: */ |
1301 | common64_end(ctx, /*swap_needed:*/ BB_LITTLE_ENDIAN); | 1311 | common64_end(ctx, /*swap_needed:*/ BB_LITTLE_ENDIAN); |
1302 | 1312 | ||
1303 | hash_size = (ctx->process_block == sha1_process_block64) ? 5 : 8; | 1313 | hash_size = 8; |
1314 | if (ctx->process_block == sha1_process_block64 | ||
1315 | #if ENABLE_SHA1_HWACCEL | ||
1316 | || ctx->process_block == sha1_process_block64_shaNI | ||
1317 | #endif | ||
1318 | ) { | ||
1319 | hash_size = 5; | ||
1320 | } | ||
1304 | /* This way we do not impose alignment constraints on resbuf: */ | 1321 | /* This way we do not impose alignment constraints on resbuf: */ |
1305 | if (BB_LITTLE_ENDIAN) { | 1322 | if (BB_LITTLE_ENDIAN) { |
1306 | unsigned i; | 1323 | unsigned i; |