aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/hash_md5_sha.c42
1 files changed, 10 insertions, 32 deletions
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
index 0b3af723a..a23db5152 100644
--- a/libbb/hash_md5_sha.c
+++ b/libbb/hash_md5_sha.c
@@ -1143,43 +1143,21 @@ static void FAST_FUNC sha512_process_block128(sha512_ctx_t *ctx)
1143#endif /* NEED_SHA512 */ 1143#endif /* NEED_SHA512 */
1144 1144
1145#if ENABLE_SHA1_HWACCEL 1145#if ENABLE_SHA1_HWACCEL
1146# if defined(__GNUC__) && defined(__i386__) 1146# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1147static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) 1147static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
1148{ 1148{
1149 asm ( 1149 asm ("cpuid"
1150 " cpuid\n" 1150 : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
1151 : "=a"(*eax), /* Output */ 1151 : "0"(*eax), "1"(*ebx), "2"(*ecx), "3"(*edx)
1152 "=b"(*ebx),
1153 "=c"(*ecx),
1154 "=d"(*edx)
1155 : "0"(*eax), /* Input */
1156 "1"(*ebx),
1157 "2"(*ecx),
1158 "3"(*edx)
1159 /* No clobbered registers */
1160 ); 1152 );
1161} 1153}
1162struct ASM_expects_76_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 76)]; };
1163void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx); 1154void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx);
1164# endif 1155# if defined(__i386__)
1165# if defined(__GNUC__) && defined(__x86_64__) 1156struct ASM_expects_76_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 76)]; };
1166static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) 1157# endif
1167{ 1158# if defined(__x86_64__)
1168 asm (
1169 "cpuid\n"
1170 : "=a"(*eax), /* Output */
1171 "=b"(*ebx),
1172 "=c"(*ecx),
1173 "=d"(*edx)
1174 : "0"(*eax), /* Input */
1175 "1"(*ebx),
1176 "2"(*ecx),
1177 "3"(*edx)
1178 /* No clobbered registers */
1179 );
1180}
1181struct ASM_expects_80_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; }; 1159struct ASM_expects_80_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; };
1182void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx); 1160# endif
1183# endif 1161# endif
1184#endif 1162#endif
1185 1163
@@ -1199,7 +1177,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
1199 if (!shaNI) { 1177 if (!shaNI) {
1200 unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx; 1178 unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx;
1201 cpuid(&eax, &ebx, &ecx, &edx); 1179 cpuid(&eax, &ebx, &ecx, &edx);
1202 shaNI = ((ebx >> 28) & 2) - 1; 1180 shaNI = ((ebx >> 29) << 1) - 1;
1203 } 1181 }
1204 if (shaNI > 0) 1182 if (shaNI > 0)
1205 ctx->process_block = sha1_process_block64_shaNI; 1183 ctx->process_block = sha1_process_block64_shaNI;