Skip to content

Commit f17403e

Browse files
committed
Clean-up SHA256-based.
* 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 fddbae2 commit f17403e

7 files changed

Lines changed: 28 additions & 34 deletions

File tree

src/hashes/sha2/sha224_desc.c

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

src/hashes/sha2/sha224_x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "tomcrypt_private.h"
99

10-
#if defined(LTC_SHA224) && defined(LTC_SHA256)
10+
#if defined(LTC_SHA224) && defined(LTC_SHA256) && defined(LTC_SHA224_X86)
1111

1212
const struct ltc_hash_descriptor sha224_x86_desc =
1313
{

src/hashes/sha2/sha256_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_sha256_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/hashes/sha2/sha256_x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
SHA256 by Marek Knapek
88
*/
99

10-
#ifdef LTC_SHA1_X86
10+
#if defined(LTC_SHA256) && defined(LTC_SHA256_X86)
1111

1212
#if defined __GNUC__
1313
#pragma GCC diagnostic push

src/headers/tomcrypt_cfg.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ typedef unsigned long ltc_mp_digit;
314314
#if !defined(LTC_NO_SHA1_X86)
315315
#define LTC_SHA1_X86
316316
#endif
317+
#if !defined(LTC_NO_SHA224_X86)
318+
#define LTC_SHA224_X86
319+
#endif
320+
#if !defined(LTC_NO_SHA256_X86)
321+
#define LTC_SHA256_X86
322+
#endif
317323
#endif
318324

319325
#if defined(__GNUC__)

src/headers/tomcrypt_custom.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,7 @@
9595
#define LTC_SHA512_224
9696
#define LTC_SHA384
9797
#define LTC_SHA256
98-
#if defined LTC_ARCH_X86 || defined LTC_ARCH_X64
99-
#define LTC_SHA256_X86
100-
#endif
10198
#define LTC_SHA224
102-
#if defined LTC_ARCH_X86 || defined LTC_ARCH_X64
103-
#define LTC_SHA224_X86
104-
#endif
10599
#define LTC_HASH_HELPERS
106100

107101
#define LTC_NO_MACS
@@ -274,13 +268,7 @@
274268
#define LTC_SHA512_224
275269
#define LTC_SHA384
276270
#define LTC_SHA256
277-
#if defined LTC_ARCH_X86 || defined LTC_ARCH_X64
278-
#define LTC_SHA256_X86
279-
#endif
280271
#define LTC_SHA224
281-
#if defined LTC_ARCH_X86 || defined LTC_ARCH_X64
282-
#define LTC_SHA224_X86
283-
#endif
284272
#define LTC_TIGER
285273
#define LTC_SHA1
286274
#define LTC_MD5

src/headers/tomcrypt_hash.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ int sha512_256_init(hash_state * md);
362362
int sha512_256_done(hash_state * md, unsigned char *out);
363363
int sha512_256_test(void);
364364
extern const struct ltc_hash_descriptor sha512_256_desc;
365-
#endif
365+
#endif /* LTC_SHA512_256 */
366366

367367
#ifdef LTC_SHA512_224
368368
#ifndef LTC_SHA512
@@ -373,9 +373,15 @@ int sha512_224_init(hash_state * md);
373373
int sha512_224_done(hash_state * md, unsigned char *out);
374374
int sha512_224_test(void);
375375
extern const struct ltc_hash_descriptor sha512_224_desc;
376-
#endif
376+
#endif /* LTC_SHA512_224 */
377377

378378
#ifdef LTC_SHA256
379+
int sha256_init(hash_state * md);
380+
int sha256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
381+
int sha256_done(hash_state * md, unsigned char *out);
382+
int sha256_test(void);
383+
extern const struct ltc_hash_descriptor sha256_desc;
384+
379385
int sha256_c_init(hash_state * md);
380386
int sha256_c_process(hash_state * md, const unsigned char *in, unsigned long inlen);
381387
int sha256_c_done(hash_state * md, unsigned char *out);
@@ -388,18 +394,19 @@ int sha256_x86_process(hash_state * md, const unsigned char *in, unsigned long i
388394
int sha256_x86_done(hash_state * md, unsigned char *out);
389395
int sha256_x86_test(void);
390396
extern const struct ltc_hash_descriptor sha256_x86_desc;
391-
#endif
392-
393-
int sha256_init(hash_state * md);
394-
int sha256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
395-
int sha256_done(hash_state * md, unsigned char *out);
396-
int sha256_test(void);
397-
extern const struct ltc_hash_descriptor sha256_desc;
397+
#endif /* LTC_SHA256_X86 */
398+
#endif /* LTC_SHA256 */
398399

399400
#ifdef LTC_SHA224
400401
#ifndef LTC_SHA256
401402
#error LTC_SHA256 is required for LTC_SHA224
402403
#endif
404+
int sha224_init(hash_state * md);
405+
#define sha224_process sha256_process
406+
int sha224_done(hash_state * md, unsigned char *out);
407+
int sha224_test(void);
408+
extern const struct ltc_hash_descriptor sha224_desc;
409+
403410
int sha224_c_init(hash_state * md);
404411
#define sha224_c_process sha256_c_process
405412
int sha224_c_done(hash_state * md, unsigned char *out);
@@ -412,15 +419,8 @@ int sha224_x86_init(hash_state * md);
412419
int sha224_x86_done(hash_state * md, unsigned char *out);
413420
int sha224_x86_test(void);
414421
extern const struct ltc_hash_descriptor sha224_x86_desc;
415-
#endif
416-
417-
int sha224_init(hash_state * md);
418-
#define sha224_process sha256_process
419-
int sha224_done(hash_state * md, unsigned char *out);
420-
int sha224_test(void);
421-
extern const struct ltc_hash_descriptor sha224_desc;
422-
#endif
423-
#endif
422+
#endif /* LTC_SHA224_X86 */
423+
#endif /* LTC_SHA224 */
424424

425425
#ifdef LTC_SHA1
426426
int sha1_init(hash_state * md);

0 commit comments

Comments
 (0)