Skip to content

Commit fddbae2

Browse files
committed
Clean-up SHA1.
* we try to keep ifdef's at one place * the last real x86 was launched in 2007, while the SHA instructions were only introduced in 2013, so IMO we can safely assume that there's no need to handle non-x86-64 instruction sets. * some minor fixes Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 902be86 commit fddbae2

4 files changed

Lines changed: 16 additions & 28 deletions

File tree

src/hashes/sha1_desc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static LTC_INLINE int s_sha1_x86_is_supported(void)
6767
if(regs[0] >= 7) {
6868
s_x86_cpuid(regs, 1);
6969
sse2 = ((((unsigned int)(regs[3])) >> 26) & 1u) != 0; /* SSE2, leaf 1, edx, bit 26 */
70-
ssse3 = ((((unsigned int)(regs[2])) >> 9) & 1u) != 0; /* SSES3, leaf 1, ecx, bit 9 */
70+
ssse3 = ((((unsigned int)(regs[2])) >> 9) & 1u) != 0; /* SSSE3, leaf 1, ecx, bit 9 */
7171
sse41 = ((((unsigned int)(regs[2])) >> 19) & 1u) != 0; /* SSE4.1, leaf 1, ecx, bit 19 */
7272
s_x86_cpuid(regs, 7);
7373
sha = ((((unsigned int)(regs[1])) >> 29) & 1u) != 0; /* SHA, leaf 7, ebx, bit 29 */

src/headers/tomcrypt_cfg.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,13 @@ typedef unsigned long ltc_mp_digit;
307307
#define LTC_HAVE_CTZL_BUILTIN
308308
#endif
309309

310-
#if !defined(LTC_NO_AES_NI) && (defined(__x86_64__) || defined(_M_X64))
311-
#define LTC_AES_NI
310+
#if (defined(__x86_64__) || defined(_M_X64))
311+
#if !defined(LTC_NO_AES_NI)
312+
#define LTC_AES_NI
313+
#endif
314+
#if !defined(LTC_NO_SHA1_X86)
315+
#define LTC_SHA1_X86
316+
#endif
312317
#endif
313318

314319
#if defined(__GNUC__)

src/headers/tomcrypt_custom.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@
6161
#define LTC_NO_PROTOTYPES
6262
#endif
6363

64-
#if \
65-
(defined _MSC_VER && defined _M_X64 && defined _M_AMD64) || \
66-
(defined __amd64__)
67-
#define LTC_ARCH_X64
68-
#endif
69-
#if \
70-
(defined _MSC_VER && defined _M_IX86 && !defined _M_I86 && !defined M_I86) || \
71-
(defined __i386__)
72-
#define LTC_ARCH_X86
73-
#endif
74-
7564
/* shortcut to disable automatic inclusion */
7665
#if defined LTC_NOTHING && !defined LTC_EASY
7766
#define LTC_NO_CIPHERS
@@ -100,9 +89,6 @@
10089

10190
#define LTC_NO_HASHES
10291
#define LTC_SHA1
103-
#if defined LTC_ARCH_X86 || defined LTC_ARCH_X64
104-
#define LTC_SHA1_X86
105-
#endif
10692
#define LTC_SHA3
10793
#define LTC_SHA512
10894
#define LTC_SHA512_256
@@ -297,9 +283,6 @@
297283
#endif
298284
#define LTC_TIGER
299285
#define LTC_SHA1
300-
#if defined LTC_ARCH_X86 || defined LTC_ARCH_X64
301-
#define LTC_SHA1_X86
302-
#endif
303286
#define LTC_MD5
304287
#define LTC_MD4
305288
#define LTC_MD2

src/headers/tomcrypt_hash.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,26 +423,26 @@ extern const struct ltc_hash_descriptor sha224_desc;
423423
#endif
424424

425425
#ifdef LTC_SHA1
426-
int sha1_c_init(hash_state * md);
427-
int sha1_c_process(hash_state * md, const unsigned char *in, unsigned long inlen);
428-
int sha1_c_done(hash_state * md, unsigned char *out);
429-
int sha1_c_test(void);
430-
extern const struct ltc_hash_descriptor sha1_portable_desc;
431-
432426
int sha1_init(hash_state * md);
433427
int sha1_process(hash_state * md, const unsigned char *in, unsigned long inlen);
434428
int sha1_done(hash_state * md, unsigned char *out);
435429
int sha1_test(void);
436430
extern const struct ltc_hash_descriptor sha1_desc;
437-
#endif
431+
432+
int sha1_c_init(hash_state * md);
433+
int sha1_c_process(hash_state * md, const unsigned char *in, unsigned long inlen);
434+
int sha1_c_done(hash_state * md, unsigned char *out);
435+
int sha1_c_test(void);
436+
extern const struct ltc_hash_descriptor sha1_portable_desc;
438437

439438
#ifdef LTC_SHA1_X86
440439
int sha1_x86_init(hash_state * md);
441440
int sha1_x86_process(hash_state * md, const unsigned char *in, unsigned long inlen);
442441
int sha1_x86_done(hash_state * md, unsigned char *out);
443442
int sha1_x86_test(void);
444443
extern const struct ltc_hash_descriptor sha1_x86_desc;
445-
#endif
444+
#endif /* LTC_SHA1_X86 */
445+
#endif /* LTC_SHA1 */
446446

447447
#ifdef LTC_BLAKE2S
448448
extern const struct ltc_hash_descriptor blake2s_256_desc;

0 commit comments

Comments
 (0)