diff options
| author | Ron Yorston <rmy@pobox.com> | 2024-07-13 08:29:09 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2024-07-13 08:29:09 +0100 |
| commit | b18891bba511d4fc4fcd0a6ff5cd2df31a086f1b (patch) | |
| tree | ef78f9ecc339d6ab95eed03f787f058f270b8772 /libbb | |
| parent | 684dabdb8452b3d33d5d6265f3d7ef32c10f5307 (diff) | |
| parent | 23da5c4b716b92524240c6f81c2e2474c1825cfc (diff) | |
| download | busybox-w32-b18891bba511d4fc4fcd0a6ff5cd2df31a086f1b.tar.gz busybox-w32-b18891bba511d4fc4fcd0a6ff5cd2df31a086f1b.tar.bz2 busybox-w32-b18891bba511d4fc4fcd0a6ff5cd2df31a086f1b.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
| -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; |
