#include <stdio.h>
#include <errno.h>
#include <assert.h>
+#include <machine/endian.h>
#include "cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/bio.h>
}
static void longswap(void *_ptr, size_t len)
-{ const union { long one; char little; } is_endian = {1};
-
- if (is_endian.little) {
+{
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
size_t i;
unsigned char *p=_ptr,c;
}
#if !defined(OPENSSL_SMALL_FOOTPRINT)
-static void ctr128_inc_aligned(unsigned char *counter) {
+static void
+ctr128_inc_aligned(unsigned char *counter)
+{
size_t *data,c,n;
- const union { long one; char little; } is_endian = {1};
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
ctr128_inc(counter);
return;
}
u128 Z = { 0, 0};
const u8 *xi = (const u8 *)Xi+15;
size_t rem, n = *xi;
- const union { long one; char little; } is_endian = {1};
static const size_t rem_8bit[256] = {
PACK(0x0000), PACK(0x01C2), PACK(0x0384), PACK(0x0246),
PACK(0x0708), PACK(0x06CA), PACK(0x048C), PACK(0x054E),
Z.hi ^= (u64)rem_8bit[rem]<<32;
}
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
*/
{
int j;
- const union { long one; char little; } is_endian = {1};
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
for (j=0;j<16;++j) {
V = Htable[j];
Htable[j].hi = V.lo;
u128 Z;
int cnt = 15;
size_t rem, nlo, nhi;
- const union { long one; char little; } is_endian = {1};
nlo = ((const u8 *)Xi)[15];
nhi = nlo>>4;
Z.lo ^= Htable[nlo].lo;
}
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
u128 Z;
int cnt;
size_t rem, nlo, nhi;
- const union { long one; char little; } is_endian = {1};
#if 1
do {
Z.hi ^= ((u64)rem_8bit[rem<<4])<<48;
#endif
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
long X;
int i,j;
const long *xi = (const long *)Xi;
- const union { long one; char little; } is_endian = {1};
V.hi = H[0]; /* H is in host byte order, no byte swapping */
V.lo = H[1];
for (j=0; j<16/sizeof(long); ++j) {
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
if (sizeof(long)==8) {
#ifdef BSWAP8
X = (long)(BSWAP8(xi[j]));
}
}
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block)
{
- const union { long one; char little; } is_endian = {1};
-
memset(ctx,0,sizeof(*ctx));
ctx->block = block;
ctx->key = key;
(*block)(ctx->H.c,ctx->H.c,key);
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
/* H is stored in host byte order */
#ifdef BSWAP8
ctx->H.u[0] = BSWAP8(ctx->H.u[0]);
void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx,const unsigned char *iv,size_t len)
{
- const union { long one; char little; } is_endian = {1};
unsigned int ctr;
#ifdef GCM_FUNCREF_4BIT
void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult;
GCM_MUL(ctx,Yi);
}
len0 <<= 3;
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
ctx->Yi.u[1] ^= BSWAP8(len0);
#else
GCM_MUL(ctx,Yi);
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
(*ctx->block)(ctx->Yi.c,ctx->EK0.c,ctx->key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (n==0) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (n==0) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len, ctr128_f stream)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
while (len>=GHASH_CHUNK) {
(*stream)(in,out,GHASH_CHUNK/16,key,ctx->Yi.c);
ctr += GHASH_CHUNK/16;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*stream)(in,out,j,key,ctx->Yi.c);
ctr += (unsigned int)j;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*ctx->block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len,ctr128_f stream)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
GHASH(ctx,in,GHASH_CHUNK);
(*stream)(in,out,GHASH_CHUNK/16,key,ctx->Yi.c);
ctr += GHASH_CHUNK/16;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
#endif
(*stream)(in,out,j,key,ctx->Yi.c);
ctr += (unsigned int)j;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*ctx->block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx,const unsigned char *tag,
size_t len)
{
- const union { long one; char little; } is_endian = {1};
u64 alen = ctx->len.u[0]<<3;
u64 clen = ctx->len.u[1]<<3;
#ifdef GCM_FUNCREF_4BIT
if (ctx->mres || ctx->ares)
GCM_MUL(ctx,Xi);
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
alen = BSWAP8(alen);
clen = BSWAP8(clen);
*/
#include <openssl/modes.h>
+#include <machine/endian.h>
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
const unsigned char *inp, unsigned char *out,
size_t len, int enc)
{
- const union { long one; char little; } is_endian = {1};
union { u64 u[2]; u32 d[4]; u8 c[16]; } tweak, scratch;
unsigned int i;
if (len==0) return 0;
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
unsigned int carry,res;
res = 0x87&(((int)tweak.d[3])>>31);
else {
union { u64 u[2]; u8 c[16]; } tweak1;
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
unsigned int carry,res;
res = 0x87&(((int)tweak.d[3])>>31);
* [including the GNU Public Licence.]
*/
+#include <machine/endian.h>
#include <openssl/rc4.h>
#include "rc4_locl.h"
((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
{
RC4_CHUNK ichunk,otp;
- const union { long one; char little; } is_endian = {1};
/*
* I reckon we can afford to implement both endian
* because the machine code appears to be very compact
* and redundant 1-2KB is perfectly tolerable (i.e.
* in case the compiler fails to eliminate it:-). By
- * suggestion from Terrel Larson <terr@terralogic.net>
- * who also stands for the is_endian union:-)
+ * suggestion from Terrel Larson <terr@terralogic.net>.
*
* Special notes.
*
- * - is_endian is declared automatic as doing otherwise
- * (declaring static) prevents gcc from eliminating
- * the redundant code;
* - compilers (those I've tried) don't seem to have
* problems eliminating either the operators guarded
* by "if (sizeof(RC4_CHUNK)==8)" or the condition
*
* <appro@fy.chalmers.se>
*/
- if (!is_endian.little)
+ if (_BYTE_ORDER != _LITTLE_ENDIAN)
{ /* BIG-ENDIAN CASE */
# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
#include <stdlib.h>
#include <string.h>
+#include <machine/endian.h>
#include <openssl/crypto.h>
#include <openssl/sha.h>
SHA_LONG X[16];
int i;
const unsigned char *data=in;
- const union { long one; char little; } is_endian = {1};
while (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];
- if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)in%4)==0)
+ if (_BYTE_ORDER != _LITTLE_ENDIAN &&
+ sizeof(SHA_LONG)==4 && ((size_t)in%4)==0)
{
const SHA_LONG *W=(const SHA_LONG *)data;
#endif
#if !defined(SHA_1) || !defined(SHA1_ASM)
+#include <machine/endian.h>
static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
{
const unsigned char *data=p;
for (;;)
{
- const union { long one; char little; } is_endian = {1};
- if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)p%4)==0)
+ if (_BYTE_ORDER != _LITTLE_ENDIAN &&
+ sizeof(SHA_LONG)==4 && ((size_t)p%4)==0)
{
const SHA_LONG *W=(const SHA_LONG *)data;
#include <stdio.h>
#include <errno.h>
+#include <machine/endian.h>
#include "ssl_locl.h"
#include <openssl/evp.h>
#include <openssl/buffer.h>
if (sizeof(long) == 8)
do {
- const union {
- long one;
- char little;
- } is_endian = {1};
long l;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
break;
/* not reached on little-endians */
/* following test is redundant, because input is
#include <stdio.h>
#include <errno.h>
#include <assert.h>
+#include <machine/endian.h>
#include "cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/bio.h>
}
static void longswap(void *_ptr, size_t len)
-{ const union { long one; char little; } is_endian = {1};
-
- if (is_endian.little) {
+{
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
size_t i;
unsigned char *p=_ptr,c;
}
#if !defined(OPENSSL_SMALL_FOOTPRINT)
-static void ctr128_inc_aligned(unsigned char *counter) {
+static void
+ctr128_inc_aligned(unsigned char *counter)
+{
size_t *data,c,n;
- const union { long one; char little; } is_endian = {1};
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
ctr128_inc(counter);
return;
}
u128 Z = { 0, 0};
const u8 *xi = (const u8 *)Xi+15;
size_t rem, n = *xi;
- const union { long one; char little; } is_endian = {1};
static const size_t rem_8bit[256] = {
PACK(0x0000), PACK(0x01C2), PACK(0x0384), PACK(0x0246),
PACK(0x0708), PACK(0x06CA), PACK(0x048C), PACK(0x054E),
Z.hi ^= (u64)rem_8bit[rem]<<32;
}
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
*/
{
int j;
- const union { long one; char little; } is_endian = {1};
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
for (j=0;j<16;++j) {
V = Htable[j];
Htable[j].hi = V.lo;
u128 Z;
int cnt = 15;
size_t rem, nlo, nhi;
- const union { long one; char little; } is_endian = {1};
nlo = ((const u8 *)Xi)[15];
nhi = nlo>>4;
Z.lo ^= Htable[nlo].lo;
}
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
u128 Z;
int cnt;
size_t rem, nlo, nhi;
- const union { long one; char little; } is_endian = {1};
#if 1
do {
Z.hi ^= ((u64)rem_8bit[rem<<4])<<48;
#endif
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
long X;
int i,j;
const long *xi = (const long *)Xi;
- const union { long one; char little; } is_endian = {1};
V.hi = H[0]; /* H is in host byte order, no byte swapping */
V.lo = H[1];
for (j=0; j<16/sizeof(long); ++j) {
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
if (sizeof(long)==8) {
#ifdef BSWAP8
X = (long)(BSWAP8(xi[j]));
}
}
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
Xi[0] = BSWAP8(Z.hi);
Xi[1] = BSWAP8(Z.lo);
void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block)
{
- const union { long one; char little; } is_endian = {1};
-
memset(ctx,0,sizeof(*ctx));
ctx->block = block;
ctx->key = key;
(*block)(ctx->H.c,ctx->H.c,key);
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
/* H is stored in host byte order */
#ifdef BSWAP8
ctx->H.u[0] = BSWAP8(ctx->H.u[0]);
void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx,const unsigned char *iv,size_t len)
{
- const union { long one; char little; } is_endian = {1};
unsigned int ctr;
#ifdef GCM_FUNCREF_4BIT
void (*gcm_gmult_p)(u64 Xi[2],const u128 Htable[16]) = ctx->gmult;
GCM_MUL(ctx,Yi);
}
len0 <<= 3;
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
ctx->Yi.u[1] ^= BSWAP8(len0);
#else
GCM_MUL(ctx,Yi);
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
(*ctx->block)(ctx->Yi.c,ctx->EK0.c,ctx->key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (n==0) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (n==0) {
(*block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len, ctr128_f stream)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
while (len>=GHASH_CHUNK) {
(*stream)(in,out,GHASH_CHUNK/16,key,ctx->Yi.c);
ctr += GHASH_CHUNK/16;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
(*stream)(in,out,j,key,ctx->Yi.c);
ctr += (unsigned int)j;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*ctx->block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
const unsigned char *in, unsigned char *out,
size_t len,ctr128_f stream)
{
- const union { long one; char little; } is_endian = {1};
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
ctx->ares = 0;
}
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
#else
GHASH(ctx,in,GHASH_CHUNK);
(*stream)(in,out,GHASH_CHUNK/16,key,ctx->Yi.c);
ctr += GHASH_CHUNK/16;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
#endif
(*stream)(in,out,j,key,ctx->Yi.c);
ctr += (unsigned int)j;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
if (len) {
(*ctx->block)(ctx->Yi.c,ctx->EKi.c,key);
++ctr;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
#ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
#else
int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx,const unsigned char *tag,
size_t len)
{
- const union { long one; char little; } is_endian = {1};
u64 alen = ctx->len.u[0]<<3;
u64 clen = ctx->len.u[1]<<3;
#ifdef GCM_FUNCREF_4BIT
if (ctx->mres || ctx->ares)
GCM_MUL(ctx,Xi);
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
#ifdef BSWAP8
alen = BSWAP8(alen);
clen = BSWAP8(clen);
*/
#include <openssl/modes.h>
+#include <machine/endian.h>
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
const unsigned char *inp, unsigned char *out,
size_t len, int enc)
{
- const union { long one; char little; } is_endian = {1};
union { u64 u[2]; u32 d[4]; u8 c[16]; } tweak, scratch;
unsigned int i;
if (len==0) return 0;
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
unsigned int carry,res;
res = 0x87&(((int)tweak.d[3])>>31);
else {
union { u64 u[2]; u8 c[16]; } tweak1;
- if (is_endian.little) {
+ if (_BYTE_ORDER == _LITTLE_ENDIAN) {
unsigned int carry,res;
res = 0x87&(((int)tweak.d[3])>>31);
* [including the GNU Public Licence.]
*/
+#include <machine/endian.h>
#include <openssl/rc4.h>
#include "rc4_locl.h"
((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
{
RC4_CHUNK ichunk,otp;
- const union { long one; char little; } is_endian = {1};
/*
* I reckon we can afford to implement both endian
* because the machine code appears to be very compact
* and redundant 1-2KB is perfectly tolerable (i.e.
* in case the compiler fails to eliminate it:-). By
- * suggestion from Terrel Larson <terr@terralogic.net>
- * who also stands for the is_endian union:-)
+ * suggestion from Terrel Larson <terr@terralogic.net>.
*
* Special notes.
*
- * - is_endian is declared automatic as doing otherwise
- * (declaring static) prevents gcc from eliminating
- * the redundant code;
* - compilers (those I've tried) don't seem to have
* problems eliminating either the operators guarded
* by "if (sizeof(RC4_CHUNK)==8)" or the condition
*
* <appro@fy.chalmers.se>
*/
- if (!is_endian.little)
+ if (_BYTE_ORDER != _LITTLE_ENDIAN)
{ /* BIG-ENDIAN CASE */
# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
#include <stdlib.h>
#include <string.h>
+#include <machine/endian.h>
#include <openssl/crypto.h>
#include <openssl/sha.h>
SHA_LONG X[16];
int i;
const unsigned char *data=in;
- const union { long one; char little; } is_endian = {1};
while (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];
- if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)in%4)==0)
+ if (_BYTE_ORDER != _LITTLE_ENDIAN &&
+ sizeof(SHA_LONG)==4 && ((size_t)in%4)==0)
{
const SHA_LONG *W=(const SHA_LONG *)data;
#endif
#if !defined(SHA_1) || !defined(SHA1_ASM)
+#include <machine/endian.h>
static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
{
const unsigned char *data=p;
for (;;)
{
- const union { long one; char little; } is_endian = {1};
- if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)p%4)==0)
+ if (_BYTE_ORDER != _LITTLE_ENDIAN &&
+ sizeof(SHA_LONG)==4 && ((size_t)p%4)==0)
{
const SHA_LONG *W=(const SHA_LONG *)data;
#include <stdio.h>
#include <errno.h>
+#include <machine/endian.h>
#include "ssl_locl.h"
#include <openssl/evp.h>
#include <openssl/buffer.h>
if (sizeof(long) == 8)
do {
- const union {
- long one;
- char little;
- } is_endian = {1};
long l;
- if (is_endian.little)
+ if (_BYTE_ORDER == _LITTLE_ENDIAN)
break;
/* not reached on little-endians */
/* following test is redundant, because input is