Skip to content

Commit

Permalink
Fix i386 build
Browse files Browse the repository at this point in the history
Disable SSE hashing in 32-bit environments because it uses registers only available on x86-64
  • Loading branch information
tbuktu committed Apr 3, 2015
1 parent ac175b3 commit 34aa764
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ SRCDIR=src
TESTDIR=tests
LIB_OBJS=bitstring.o encparams.o hash.o idxgen.o key.o mgf.o ntru.o poly.o rand.o arith.o sha1.o sha2.o
ifeq ($(SSE), yes)
LIB_OBJS+=sha1-mb-x86_64.o sha256-mb-x86_64.o
ifeq ($(MACHINE), x86_64)
LIB_OBJS+=sha1-mb-x86_64.o sha256-mb-x86_64.o
endif
endif
TEST_OBJS=test_bitstring.o test_hash.o test_idxgen.o test_key.o test_ntru.o test.o test_poly.o test_util.o
VERSION=0.3
Expand Down
20 changes: 10 additions & 10 deletions src/hash.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <string.h>
#include <stdint.h>
#ifdef __SSSE3__
#if defined __SSSE3__ && _LP64
#include <tmmintrin.h>
#endif
#ifdef WIN32
Expand All @@ -12,7 +12,7 @@
#include "sph_sha2.h"
#include "hash.h"

#ifdef __SSSE3__
#if defined __SSSE3__ && _LP64
typedef struct {
uint32_t A[8], B[8], C[8], D[8], E[8];
uint32_t Nl,Nh;
Expand All @@ -36,7 +36,7 @@ typedef struct {
uint8_t *ptr;
uint32_t blocks;
} HASH_DESC;
#endif /* __SSSE3__ */
#endif /* __SSSE3__ && _LP64 */

void ntru_sha1(uint8_t *input, uint16_t input_len, uint8_t *digest) {
sph_sha1_context context;
Expand All @@ -45,7 +45,7 @@ void ntru_sha1(uint8_t *input, uint16_t input_len, uint8_t *digest) {
sph_sha1_close(&context, digest);
}

#ifdef __SSSE3__
#if defined __SSSE3__ && _LP64
uint64_t OPENSSL_ia32cap_P = 0; /* don’t detect SHA extensions for now */

extern void sha1_multi_block(SHA1_MB_CTX *, HASH_DESC *, int num);
Expand Down Expand Up @@ -157,10 +157,10 @@ void SHA1_MB_Final(uint8_t *digest[4], SHA1_MB_CTX *ctx) {
*d32 = ntohl(ctx->E[i]);
}
}
#endif /* __SSSE3__ */
#endif /* __SSSE3__ && _LP64 */

void ntru_sha1_4way(uint8_t *input[4], uint16_t input_len, uint8_t *digest[4]) {
#ifdef __SSSE3__
#if defined __SSSE3__ && _LP64
SHA1_MB_CTX ctx;
SHA1_MB_Init(&ctx);
SHA1_MB_Update(&ctx, input, input_len);
Expand All @@ -169,7 +169,7 @@ void ntru_sha1_4way(uint8_t *input[4], uint16_t input_len, uint8_t *digest[4]) {
uint8_t i;
for (i=0; i<4; i++)
ntru_sha1(input[i], input_len, digest[i]);
#endif /* __SSSE3__ */
#endif /* __SSSE3__ && _LP64 */
}

void ntru_sha256(uint8_t *input, uint16_t input_len, uint8_t *digest) {
Expand All @@ -179,7 +179,7 @@ void ntru_sha256(uint8_t *input, uint16_t input_len, uint8_t *digest) {
sph_sha256_close(&context, digest);
}

#ifdef __SSSE3__
#if defined __SSSE3__ && _LP64
void SHA256_MB_Init(SHA256_MB_CTX *ctx) {
memset(ctx, 0, sizeof(*ctx));
__m128i a = _mm_set1_epi32(0x6a09e667);
Expand Down Expand Up @@ -294,10 +294,10 @@ void SHA256_MB_Final(uint8_t *digest[4], SHA256_MB_CTX *ctx) {
*d32 = ntohl(ctx->H[i]);
}
}
#endif /* __SSSE3__ */
#endif /* __SSSE3__ && _LP64 */

void ntru_sha256_4way(uint8_t *input[4], uint16_t input_len, uint8_t *digest[4]) {
#ifdef __SSSE3__
#if defined __SSSE3__ && _LP64
SHA256_MB_CTX ctx;
SHA256_MB_Init(&ctx);
SHA256_MB_Update(&ctx, input, input_len);
Expand Down

0 comments on commit 34aa764

Please sign in to comment.