mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Add supports_sha_ni(void) function
It executes CPUID instruction to check whether SHA extensions are supported by hosting CPU.
This commit is contained in:
parent
59e2334029
commit
f51a5c9235
2
ssh.h
2
ssh.h
@ -258,6 +258,8 @@ void hmacmd5_key(void *handle, void const *key, int len);
|
||||
void hmacmd5_do_hmac(void *handle, unsigned char const *blk, int len,
|
||||
unsigned char *hmac);
|
||||
|
||||
int supports_sha_ni(void);
|
||||
|
||||
typedef struct SHA_State {
|
||||
uint32 h[5];
|
||||
unsigned char block[64];
|
||||
|
49
sshsha.c
49
sshsha.c
@ -461,3 +461,52 @@ const struct ssh_mac ssh_hmac_sha1_96_buggy = {
|
||||
12, 16,
|
||||
"bug-compatible HMAC-SHA1-96"
|
||||
};
|
||||
|
||||
#ifdef COMPILER_SUPPORTS_SHA_NI
|
||||
|
||||
/*
|
||||
* Set target architecture for Clang and GCC
|
||||
*/
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
# pragma GCC target("sha")
|
||||
# pragma GCC target("sse4.1")
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5))
|
||||
# define FUNC_ISA __attribute__ ((target("sse4.1,sha")))
|
||||
#else
|
||||
# define FUNC_ISA
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Determinators of CPU type
|
||||
*/
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
|
||||
#include <cpuid.h>
|
||||
int supports_sha_ni(void)
|
||||
{
|
||||
unsigned int CPUInfo[4];
|
||||
__cpuid_count(7, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
|
||||
return CPUInfo[1] & (1 << 29); /* SHA */
|
||||
}
|
||||
|
||||
#else /* defined(__clang__) || defined(__GNUC__) */
|
||||
|
||||
int supports_sha_ni(void)
|
||||
{
|
||||
unsigned int CPUInfo[4];
|
||||
__cpuidex(CPUInfo, 7, 0);
|
||||
return CPUInfo[1] & (1 << 29); /* Check SHA */
|
||||
}
|
||||
|
||||
#endif /* defined(__clang__) || defined(__GNUC__) */
|
||||
|
||||
#else /* COMPILER_SUPPORTS_AES_NI */
|
||||
|
||||
int supports_sha_ni(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* COMPILER_SUPPORTS_AES_NI */
|
||||
|
Loading…
Reference in New Issue
Block a user