Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1654142 - Add CPU feature detection for Intel SHA extension. r=kj…
…acobs

Differential Revision: https://phabricator.services.mozilla.com/D84286

--HG--
extra : moz-landing-system : lando
  • Loading branch information
makotokato committed Jul 31, 2020
1 parent 4ba0631 commit 80417a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/freebl/blapii.h
Expand Up @@ -85,6 +85,7 @@ SECStatus generate_prime(mp_int *prime, int primeLen);
/* Freebl state. */
PRBool aesni_support();
PRBool clmul_support();
PRBool sha_support();
PRBool avx_support();
PRBool avx2_support();
PRBool ssse3_support();
Expand Down
9 changes: 9 additions & 0 deletions lib/freebl/blinit.c
Expand Up @@ -30,6 +30,7 @@ static PRCallOnceType coFreeblInit;
/* State variables. */
static PRBool aesni_support_ = PR_FALSE;
static PRBool clmul_support_ = PR_FALSE;
static PRBool sha_support_ = PR_FALSE;
static PRBool avx_support_ = PR_FALSE;
static PRBool avx2_support_ = PR_FALSE;
static PRBool ssse3_support_ = PR_FALSE;
Expand Down Expand Up @@ -83,6 +84,7 @@ check_xcr0_ymm()
#define EBX_AVX2 (1 << 5)
#define EBX_BMI1 (1 << 3)
#define EBX_BMI2 (1 << 8)
#define EBX_SHA (1 << 29)
#define ECX_FMA (1 << 12)
#define ECX_MOVBE (1 << 22)
#define ECX_SSSE3 (1 << 9)
Expand All @@ -99,6 +101,7 @@ CheckX86CPUSupport()
unsigned long eax7, ebx7, ecx7, edx7;
char *disable_hw_aes = PR_GetEnvSecure("NSS_DISABLE_HW_AES");
char *disable_pclmul = PR_GetEnvSecure("NSS_DISABLE_PCLMUL");
char *disable_hw_sha = PR_GetEnvSecure("NSS_DISABLE_HW_SHA");
char *disable_avx = PR_GetEnvSecure("NSS_DISABLE_AVX");
char *disable_avx2 = PR_GetEnvSecure("NSS_DISABLE_AVX2");
char *disable_ssse3 = PR_GetEnvSecure("NSS_DISABLE_SSSE3");
Expand All @@ -108,6 +111,7 @@ CheckX86CPUSupport()
freebl_cpuid(7, &eax7, &ebx7, &ecx7, &edx7);
aesni_support_ = (PRBool)((ecx & ECX_AESNI) != 0 && disable_hw_aes == NULL);
clmul_support_ = (PRBool)((ecx & ECX_CLMUL) != 0 && disable_pclmul == NULL);
sha_support_ = (PRBool)((ebx7 & EBX_SHA) != 0 && disable_hw_sha == NULL);
/* For AVX we check AVX, OSXSAVE, and XSAVE
* as well as XMM and YMM state. */
avx_support_ = (PRBool)((ecx & AVX_BITS) == AVX_BITS) && check_xcr0_ymm() &&
Expand Down Expand Up @@ -403,6 +407,11 @@ clmul_support()
return clmul_support_;
}
PRBool
sha_support()
{
return sha_support_;
}
PRBool
avx_support()
{
return avx_support_;
Expand Down
1 change: 1 addition & 0 deletions nss-tool/hw-support.c
Expand Up @@ -22,6 +22,7 @@ int main(int argc, char const *argv[]) {
#if defined(NSS_X86_OR_X64)
printf("\tAES-NI \t%s supported\n", aesni_support() ? "" : "not");
printf("\tPCLMUL \t%s supported\n", clmul_support() ? "" : "not");
printf("\tSHA \t%s supported\n", sha_support() ? "" : "not");
printf("\tAVX \t%s supported\n", avx_support() ? "" : "not");
printf("\tAVX2 \t%s supported\n", avx2_support() ? "" : "not");
printf("\tSSSE3 \t%s supported\n", ssse3_support() ? "" : "not");
Expand Down

0 comments on commit 80417a9

Please sign in to comment.