Skip to content

Commit f9bf96d

Browse files
authored
Merge pull request #7187 from SparkiDev/sha256_intel_instrs
SHA-256: Implementation using Intel instructions
2 parents 1fda249 + 492490f commit f9bf96d

4 files changed

Lines changed: 839 additions & 0 deletions

File tree

wolfcrypt/src/cpuid.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
if (cpuid_flag(7, 0, EBX, 19)) { cpuid_flags |= CPUID_ADX ; }
9797
if (cpuid_flag(1, 0, ECX, 22)) { cpuid_flags |= CPUID_MOVBE ; }
9898
if (cpuid_flag(7, 0, EBX, 3)) { cpuid_flags |= CPUID_BMI1 ; }
99+
if (cpuid_flag(7, 0, EBX, 29)) { cpuid_flags |= CPUID_SHA ; }
99100

100101
cpuid_check = 1;
101102
}

wolfcrypt/src/sha256.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,15 @@ static int InitSha256(wc_Sha256* sha256)
302302
extern "C" {
303303
#endif
304304

305+
extern int Transform_Sha256_SSE2_Sha(wc_Sha256 *sha256,
306+
const byte* data);
307+
extern int Transform_Sha256_SSE2_Sha_Len(wc_Sha256* sha256,
308+
const byte* data, word32 len);
305309
#if defined(HAVE_INTEL_AVX1)
310+
extern int Transform_Sha256_AVX1_Sha(wc_Sha256 *sha256,
311+
const byte* data);
312+
extern int Transform_Sha256_AVX1_Sha_Len(wc_Sha256* sha256,
313+
const byte* data, word32 len);
306314
extern int Transform_Sha256_AVX1(wc_Sha256 *sha256, const byte* data);
307315
extern int Transform_Sha256_AVX1_Len(wc_Sha256* sha256,
308316
const byte* data, word32 len);
@@ -356,6 +364,22 @@ static int InitSha256(wc_Sha256* sha256)
356364

357365
intel_flags = cpuid_get_flags();
358366

367+
if (IS_INTEL_SHA(intel_flags)) {
368+
#ifdef HAVE_INTEL_AVX1
369+
if (IS_INTEL_AVX1(intel_flags)) {
370+
Transform_Sha256_p = Transform_Sha256_AVX1_Sha;
371+
Transform_Sha256_Len_p = Transform_Sha256_AVX1_Sha_Len;
372+
Transform_Sha256_is_vectorized = 1;
373+
}
374+
else
375+
#endif
376+
{
377+
Transform_Sha256_p = Transform_Sha256_SSE2_Sha;
378+
Transform_Sha256_Len_p = Transform_Sha256_SSE2_Sha_Len;
379+
Transform_Sha256_is_vectorized = 1;
380+
}
381+
}
382+
else
359383
#ifdef HAVE_INTEL_AVX2
360384
if (IS_INTEL_AVX2(intel_flags)) {
361385
#ifdef HAVE_INTEL_RORX

0 commit comments

Comments
 (0)