aboutsummaryrefslogtreecommitdiff
path: root/libbb/hash_md5_sha.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/hash_md5_sha.c')
-rw-r--r--libbb/hash_md5_sha.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
index ee19c1cb7..4c6904b48 100644
--- a/libbb/hash_md5_sha.c
+++ b/libbb/hash_md5_sha.c
@@ -699,7 +699,7 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx UNUSED_PARAM)
699 699
700/* in hash_md5_sha_x86-64.S */ 700/* in hash_md5_sha_x86-64.S */
701struct ASM_expects_80 { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; }; 701struct ASM_expects_80 { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; };
702void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx UNUSED_PARAM); 702void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx);
703 703
704# else 704# else
705/* Fast, fully-unrolled SHA1. +3800 bytes of code on x86. 705/* Fast, fully-unrolled SHA1. +3800 bytes of code on x86.
@@ -1142,6 +1142,28 @@ static void FAST_FUNC sha512_process_block128(sha512_ctx_t *ctx)
1142} 1142}
1143#endif /* NEED_SHA512 */ 1143#endif /* NEED_SHA512 */
1144 1144
1145#if ENABLE_SHA1_HWACCEL
1146# if defined(__GNUC__) && defined(__x86_64__)
1147static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
1148{
1149 asm (
1150 "cpuid\n"
1151 : "=a"(*eax), /* Output */
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 );
1161}
1162struct ASM_expects_80_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; };
1163void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx);
1164# endif
1165#endif
1166
1145void FAST_FUNC sha1_begin(sha1_ctx_t *ctx) 1167void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
1146{ 1168{
1147 ctx->hash[0] = 0x67452301; 1169 ctx->hash[0] = 0x67452301;
@@ -1151,6 +1173,20 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
1151 ctx->hash[4] = 0xc3d2e1f0; 1173 ctx->hash[4] = 0xc3d2e1f0;
1152 ctx->total64 = 0; 1174 ctx->total64 = 0;
1153 ctx->process_block = sha1_process_block64; 1175 ctx->process_block = sha1_process_block64;
1176#if ENABLE_SHA1_HWACCEL
1177# if defined(__GNUC__) && defined(__x86_64__)
1178 {
1179 static smallint shaNI;
1180 if (!shaNI) {
1181 unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx;
1182 cpuid(&eax, &ebx, &ecx, &edx);
1183 shaNI = ((ebx >> 28) & 2) - 1;
1184 }
1185 if (shaNI > 0)
1186 ctx->process_block = sha1_process_block64_shaNI;
1187 }
1188# endif
1189#endif
1154} 1190}
1155 1191
1156static const uint32_t init256[] ALIGN4 = { 1192static const uint32_t init256[] ALIGN4 = {