Skip to content

Commit bd46b2e

Browse files
committed
sha512ni_is_supported
1 parent d5d0b23 commit bd46b2e

4 files changed

Lines changed: 50 additions & 23 deletions

File tree

src/hashes/sha2/sha512_desc.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,7 @@
77
SHA512 by Tom St Denis
88
*/
99

10-
#ifdef LTC_SHA512
11-
12-
const struct ltc_hash_descriptor sha512_desc =
13-
{
14-
"sha512",
15-
5,
16-
64,
17-
128,
18-
19-
/* OID */
20-
{ 2, 16, 840, 1, 101, 3, 4, 2, 3, },
21-
9,
22-
23-
&sha512_init,
24-
&sha512_process,
25-
&sha512_done,
26-
&sha512_test,
27-
NULL
28-
};
29-
30-
#if defined LTC_SHA512_X86
10+
#if defined LTC_ARCH_X86
3111

3212
#if !defined (LTC_S_X86_CPUID)
3313
#define LTC_S_X86_CPUID
@@ -54,6 +34,7 @@ static LTC_INLINE void s_x86_cpuid(int* regs, int leaf)
5434
#endif
5535
}
5636
#endif /* LTC_S_X86_CPUID */
37+
5738
#if !defined (LTC_S_X86_CPUIDEX)
5839
#define LTC_S_X86_CPUIDEX
5940
#if defined _MSC_VER
@@ -109,7 +90,37 @@ static LTC_INLINE int s_sha512_x86_is_supported(void)
10990
}
11091
return is_supported;
11192
}
112-
#endif /* LTC_SHA512_X86 */
93+
94+
#endif /* LTC_ARCH_X86 */
95+
96+
int sha512ni_is_supported(void)
97+
{
98+
#ifdef LTC_ARCH_X86
99+
return s_sha512_x86_is_supported();
100+
#else
101+
return 0;
102+
#endif
103+
}
104+
105+
#ifdef LTC_SHA512
106+
107+
const struct ltc_hash_descriptor sha512_desc =
108+
{
109+
"sha512",
110+
5,
111+
64,
112+
128,
113+
114+
/* OID */
115+
{ 2, 16, 840, 1, 101, 3, 4, 2, 3, },
116+
9,
117+
118+
&sha512_init,
119+
&sha512_process,
120+
&sha512_done,
121+
&sha512_test,
122+
NULL
123+
};
113124

114125
/**
115126
Initialize the hash state

src/headers/tomcrypt_hash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ extern const struct ltc_hash_descriptor sha512_224_x86_desc;
433433
#endif /* LTC_SHA512_224 */
434434

435435
int shani_is_supported(void);
436+
int sha512ni_is_supported(void);
436437

437438
#ifdef LTC_SHA256
438439
int sha256_init(hash_state * md);

tests/cipher_hash_test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ int cipher_hash_test(void)
6060
}
6161

6262
/* explicit SHA-NI + portable implementations tests */
63+
if (sha512ni_is_supported()) {
64+
#if defined(LTC_SHA512) && defined(LTC_SHA512_X86)
65+
DO(sha512_x86_test());
66+
#endif
67+
#if defined(LTC_SHA384) && defined(LTC_SHA384_X86)
68+
DO(sha384_x86_test());
69+
#endif
70+
#if defined(LTC_SHA512_256) && defined(LTC_SHA512_256_X86)
71+
DO(sha512_256_x86_test());
72+
#endif
73+
#if defined(LTC_SHA512_224) && defined(LTC_SHA512_224_X86)
74+
DO(sha512_224_x86_test());
75+
#endif
76+
}
6377
if (shani_is_supported()) {
6478
#if defined(LTC_SHA256) && defined(LTC_SHA256_X86)
6579
DO(sha256_x86_test());

tests/test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ int main(int argc, char **argv)
366366
printf("LTC_VERSION = %s\n%s\n\n", GIT_VERSION, crypt_build_settings);
367367

368368
printf("AES-NI CPU support = %d\n", aesni_is_supported());
369-
printf("SHA-NI CPU support = %d\n\n", shani_is_supported());
369+
printf("SHA-NI CPU support = %d\n", shani_is_supported());
370+
printf("SHA-512-NI CPU support = %d\n\n", sha512ni_is_supported());
370371

371372
#ifdef USE_LTM
372373
mpi_provider = "ltm";

0 commit comments

Comments
 (0)