summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2014-04-18 19:41:24 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2014-04-18 19:41:24 +0000
commita16c6b3aa4c4195221da44cb52f7d5613881a8ec (patch)
tree9a63fb00c5f7709010702eddd276e907b2ef359d
parentc59fbe52bc01bfb340776cb9ddf938b9c96c3078 (diff)
Do not ask the user to pass either -DB_ENDIAN or -DL_ENDIAN to the compiler,
but rather figure out the endianness from <machine/endian.h> automagically; help from guenther@ ok jca@ guenther@ beck@ and the rest of the `Buena SSL rampage club'
-rw-r--r--lib/libcrypto/crypto/Makefile12
-rw-r--r--lib/libssl/src/crypto/bn/bn_nist.c4
-rw-r--r--lib/libssl/src/crypto/des/cfb_enc.c11
-rw-r--r--lib/libssl/src/crypto/sha/sha512.c7
-rw-r--r--lib/libssl/src/crypto/whrlpool/wp_block.c9
5 files changed, 19 insertions, 24 deletions
diff --git a/lib/libcrypto/crypto/Makefile b/lib/libcrypto/crypto/Makefile
index 31cab709d97..f46702b7ebc 100644
--- a/lib/libcrypto/crypto/Makefile
+++ b/lib/libcrypto/crypto/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.25 2014/04/18 17:32:31 miod Exp $
+# $OpenBSD: Makefile,v 1.26 2014/04/18 19:41:21 miod Exp $
LIB= crypto
@@ -7,16 +7,6 @@ LCRYPTO_SRC= ${SSL_SRC}/crypto
CFLAGS+= -Wall
-# arm and sh default to little endian, mips defaults to big endian
-.if ${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH} == "amd64" || \
- ${MACHINE_ARCH} == "arm" || ${MACHINE_ARCH} == "i386" || \
- ${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "sh" || \
- ${MACHINE_ARCH} == "vax"
-CFLAGS+= -DL_ENDIAN
-.else
-CFLAGS+= -DB_ENDIAN
-.endif
-
.include <bsd.own.mk> # for 'NOPIC' definition
.if !defined(NOPIC)
CFLAGS+= -DDSO_DLFCN -DHAVE_DLFCN_H
diff --git a/lib/libssl/src/crypto/bn/bn_nist.c b/lib/libssl/src/crypto/bn/bn_nist.c
index 1e4cf833dc9..4d4a7b86df4 100644
--- a/lib/libssl/src/crypto/bn/bn_nist.c
+++ b/lib/libssl/src/crypto/bn/bn_nist.c
@@ -59,6 +59,8 @@
#include "bn_lcl.h"
#include "cryptlib.h"
+#include <machine/endian.h>
+
#define BN_NIST_192_TOP (192+BN_BITS2-1)/BN_BITS2
#define BN_NIST_224_TOP (224+BN_BITS2-1)/BN_BITS2
@@ -318,7 +320,7 @@ static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top)
:(to[(n)/2] =((m)&1)?(from[(m)/2]>>32):(from[(m)/2]&BN_MASK2l)))
#define bn_32_set_0(to, n) (((n)&1)?(to[(n)/2]&=BN_MASK2l):(to[(n)/2]=0));
#define bn_cp_32(to,n,from,m) ((m)>=0)?bn_cp_32_naked(to,n,from,m):bn_32_set_0(to,n)
-# if defined(L_ENDIAN)
+# if _BYTE_ORDER == _LITTLE_ENDIAN
# if defined(__arch64__)
# define NIST_INT64 long
# else
diff --git a/lib/libssl/src/crypto/des/cfb_enc.c b/lib/libssl/src/crypto/des/cfb_enc.c
index dd5237a86de..9bf6466bd28 100644
--- a/lib/libssl/src/crypto/des/cfb_enc.c
+++ b/lib/libssl/src/crypto/des/cfb_enc.c
@@ -58,6 +58,7 @@
#include "des_locl.h"
#include <assert.h>
+#include <machine/endian.h>
/* The input and output are loaded in multiples of 8 bits.
* What this means is that if you hame numbits=12 and length=2
@@ -76,7 +77,7 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
register int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8;
DES_LONG ti[2];
unsigned char *iv;
-#ifndef L_ENDIAN
+#if _BYTE_ORDER != _LITTLE_ENDIAN
unsigned char ovec[16];
#else
unsigned int sh[4];
@@ -114,7 +115,7 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
{ v0=d0; v1=d1; }
else
{
-#ifndef L_ENDIAN
+#if _BYTE_ORDER != _LITTLE_ENDIAN
iv=&ovec[0];
l2c(v0,iv);
l2c(v1,iv);
@@ -129,7 +130,7 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
for(i=0 ; i < 8 ; ++i)
ovec[i]=ovec[i+num]<<rem |
ovec[i+num+1]>>(8-rem);
-#ifdef L_ENDIAN
+#if _BYTE_ORDER == _LITTLE_ENDIAN
v0=sh[0], v1=sh[1];
#else
iv=&ovec[0];
@@ -157,7 +158,7 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
{ v0=d0; v1=d1; }
else
{
-#ifndef L_ENDIAN
+#if _BYTE_ORDER != _LITTLE_ENDIAN
iv=&ovec[0];
l2c(v0,iv);
l2c(v1,iv);
@@ -172,7 +173,7 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
for(i=0 ; i < 8 ; ++i)
ovec[i]=ovec[i+num]<<rem |
ovec[i+num+1]>>(8-rem);
-#ifdef L_ENDIAN
+#if _BYTE_ORDER == _LITTLE_ENDIAN
v0=sh[0], v1=sh[1];
#else
iv=&ovec[0];
diff --git a/lib/libssl/src/crypto/sha/sha512.c b/lib/libssl/src/crypto/sha/sha512.c
index c92f18e418c..49afaa05c25 100644
--- a/lib/libssl/src/crypto/sha/sha512.c
+++ b/lib/libssl/src/crypto/sha/sha512.c
@@ -43,6 +43,7 @@
*/
#include <stdlib.h>
#include <string.h>
+#include <machine/endian.h>
#include <openssl/crypto.h>
#include <openssl/sha.h>
@@ -108,7 +109,7 @@ int SHA512_Final (unsigned char *md, SHA512_CTX *c)
sha512_block_data_order (c,p,1);
memset (p+n,0,sizeof(c->u)-16-n);
-#ifdef B_ENDIAN
+#if _BYTE_ORDER == _BIG_ENDIAN
c->u.d[SHA_LBLOCK-2] = c->Nh;
c->u.d[SHA_LBLOCK-1] = c->Nl;
#else
@@ -437,7 +438,7 @@ static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num
for (i=0;i<16;i++)
{
-#ifdef B_ENDIAN
+#if _BYTE_ORDER == _BIG_ENDIAN
T1 = X[i] = W[i];
#else
T1 = X[i] = PULL64(W[i]);
@@ -492,7 +493,7 @@ static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num
a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3];
e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7];
-#ifdef B_ENDIAN
+#if _BYTE_ORDER == _BIG_ENDIAN
T1 = X[0] = W[0]; ROUND_00_15(0,a,b,c,d,e,f,g,h);
T1 = X[1] = W[1]; ROUND_00_15(1,h,a,b,c,d,e,f,g);
T1 = X[2] = W[2]; ROUND_00_15(2,g,h,a,b,c,d,e,f);
diff --git a/lib/libssl/src/crypto/whrlpool/wp_block.c b/lib/libssl/src/crypto/whrlpool/wp_block.c
index fadad01401d..11164e50f56 100644
--- a/lib/libssl/src/crypto/whrlpool/wp_block.c
+++ b/lib/libssl/src/crypto/whrlpool/wp_block.c
@@ -37,6 +37,7 @@
#include "wp_locl.h"
#include <string.h>
+#include <machine/endian.h>
typedef unsigned char u8;
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32)
@@ -82,10 +83,10 @@ typedef unsigned long long u64;
# define ROTATE(a,n) ({ u64 ret; asm ("rolq %1,%0" \
: "=r"(ret) : "J"(n),"0"(a) : "cc"); ret; })
# elif defined(__ia64) || defined(__ia64__)
-# if defined(L_ENDIAN)
+# if _BYTE_ORDER == _LITTLE_ENDIAN
# define ROTATE(a,n) ({ u64 ret; asm ("shrp %0=%1,%1,%2" \
: "=r"(ret) : "r"(a),"M"(64-(n))); ret; })
-# elif defined(B_ENDIAN)
+# else
# define ROTATE(a,n) ({ u64 ret; asm ("shrp %0=%1,%1,%2" \
: "=r"(ret) : "r"(a),"M"(n)); ret; })
# endif
@@ -94,9 +95,9 @@ typedef unsigned long long u64;
#if defined(OPENSSL_SMALL_FOOTPRINT)
# if !defined(ROTATE)
-# if defined(L_ENDIAN) /* little-endians have to rotate left */
+# if _BYTE_ORDER == _LITTLE_ENDIAN /* little-endians have to rotate left */
# define ROTATE(i,n) ((i)<<(n) ^ (i)>>(64-n))
-# elif defined(B_ENDIAN) /* big-endians have to rotate right */
+# else /* big-endians have to rotate right */
# define ROTATE(i,n) ((i)>>(n) ^ (i)<<(64-n))
# endif
# endif