mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Add CPUID leaf checks prior to SHA checks
Some old CPUs do not support CPUID to be called with eax=7 To prevent failures, call CPUID with eax=0 to get the highest possible eax value (leaf) and compare it to 7. GCC does this check internally with __get_cpuid_count function Thanks to Jeffrey Walton for noticing.
This commit is contained in:
parent
a27f55e819
commit
1ec8a84cf6
8
sshsha.c
8
sshsha.c
@ -501,6 +501,10 @@ const struct ssh_mac ssh_hmac_sha1_96_buggy = {
|
||||
int supports_sha_ni(void)
|
||||
{
|
||||
unsigned int CPUInfo[4];
|
||||
__cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
|
||||
if (CPUInfo[0] < 7)
|
||||
return 0;
|
||||
|
||||
__cpuid_count(7, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
|
||||
return CPUInfo[1] & (1 << 29); /* SHA */
|
||||
}
|
||||
@ -510,6 +514,10 @@ int supports_sha_ni(void)
|
||||
int supports_sha_ni(void)
|
||||
{
|
||||
unsigned int CPUInfo[4];
|
||||
__cpuid(CPUInfo, 0);
|
||||
if (CPUInfo[0] < 7)
|
||||
return 0;
|
||||
|
||||
__cpuidex(CPUInfo, 7, 0);
|
||||
return CPUInfo[1] & (1 << 29); /* Check SHA */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user