| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#ifndef _SKEIN_PORT_H_ |
| 30 |
#define _SKEIN_PORT_H_ |
| 31 |
|
| 32 |
#include <limits.h> |
| 33 |
#include <stdint.h> |
| 34 |
|
| 35 |
#ifndef RETURN_VALUES |
| 36 |
# define RETURN_VALUES |
| 37 |
# if defined( DLL_EXPORT ) |
| 38 |
# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) |
| 39 |
# define VOID_RETURN __declspec( dllexport ) void __stdcall |
| 40 |
# define INT_RETURN __declspec( dllexport ) int __stdcall |
| 41 |
# elif defined( __GNUC__ ) |
| 42 |
# define VOID_RETURN __declspec( __dllexport__ ) void |
| 43 |
# define INT_RETURN __declspec( __dllexport__ ) int |
| 44 |
# else |
| 45 |
# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers |
| 46 |
# endif |
| 47 |
# elif defined( DLL_IMPORT ) |
| 48 |
# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) |
| 49 |
# define VOID_RETURN __declspec( dllimport ) void __stdcall |
| 50 |
# define INT_RETURN __declspec( dllimport ) int __stdcall |
| 51 |
# elif defined( __GNUC__ ) |
| 52 |
# define VOID_RETURN __declspec( __dllimport__ ) void |
| 53 |
# define INT_RETURN __declspec( __dllimport__ ) int |
| 54 |
# else |
| 55 |
# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers |
| 56 |
# endif |
| 57 |
# elif defined( __WATCOMC__ ) |
| 58 |
# define VOID_RETURN void __cdecl |
| 59 |
# define INT_RETURN int __cdecl |
| 60 |
# else |
| 61 |
# define VOID_RETURN void |
| 62 |
# define INT_RETURN int |
| 63 |
# endif |
| 64 |
#endif |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
#define ui_type(size) uint##size##_t |
| 83 |
#define dec_unit_type(size,x) typedef ui_type(size) x |
| 84 |
#define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)] |
| 85 |
#define ptr_cast(x,size) ((ui_type(size)*)(x)) |
| 86 |
|
| 87 |
typedef unsigned int uint_t; |
| 88 |
typedef uint8_t u08b_t; |
| 89 |
typedef uint64_t u64b_t; |
| 90 |
|
| 91 |
#ifndef RotL_64 |
| 92 |
#define RotL_64(x,N) (((x) << (N)) | ((x) >> (64-(N)))) |
| 93 |
#endif |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
#ifndef SKEIN_NEED_SWAP |
| 115 |
|
| 116 |
|
| 117 |
#include "int-util.h" |
| 118 |
|
| 119 |
#define IS_BIG_ENDIAN 4321 |
| 120 |
#define IS_LITTLE_ENDIAN 1234 |
| 121 |
|
| 122 |
#if BYTE_ORDER == LITTLE_ENDIAN |
| 123 |
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 124 |
#endif |
| 125 |
|
| 126 |
#if BYTE_ORDER == BIG_ENDIAN |
| 127 |
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 128 |
#endif |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
#if defined(__ia64) || defined(__ia64__) || defined(_M_IA64) |
| 133 |
# define PLATFORM_MUST_ALIGN (1) |
| 134 |
#ifndef PLATFORM_BYTE_ORDER |
| 135 |
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 136 |
#endif |
| 137 |
#endif |
| 138 |
|
| 139 |
#ifndef PLATFORM_MUST_ALIGN |
| 140 |
# define PLATFORM_MUST_ALIGN (0) |
| 141 |
#endif |
| 142 |
|
| 143 |
|
| 144 |
#if PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN |
| 145 |
|
| 146 |
#define SKEIN_NEED_SWAP (1) |
| 147 |
#elif PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN |
| 148 |
|
| 149 |
#define SKEIN_NEED_SWAP (0) |
| 150 |
#if PLATFORM_MUST_ALIGN == 0 |
| 151 |
#define Skein_Put64_LSB_First(dst08,src64,bCnt) memcpy(dst08,src64,bCnt) |
| 152 |
#define Skein_Get64_LSB_First(dst64,src08,wCnt) memcpy(dst64,src08,8*(wCnt)) |
| 153 |
#endif |
| 154 |
#else |
| 155 |
#error "Skein needs endianness setting!" |
| 156 |
#endif |
| 157 |
|
| 158 |
#endif |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
#ifndef Skein_Swap64 |
| 166 |
#if SKEIN_NEED_SWAP |
| 167 |
#define Skein_Swap64(w64) \ |
| 168 |
( (( ((u64b_t)(w64)) & 0xFF) << 56) | \ |
| 169 |
(((((u64b_t)(w64)) >> 8) & 0xFF) << 48) | \ |
| 170 |
(((((u64b_t)(w64)) >>16) & 0xFF) << 40) | \ |
| 171 |
(((((u64b_t)(w64)) >>24) & 0xFF) << 32) | \ |
| 172 |
(((((u64b_t)(w64)) >>32) & 0xFF) << 24) | \ |
| 173 |
(((((u64b_t)(w64)) >>40) & 0xFF) << 16) | \ |
| 174 |
(((((u64b_t)(w64)) >>48) & 0xFF) << 8) | \ |
| 175 |
(((((u64b_t)(w64)) >>56) & 0xFF) ) ) |
| 176 |
#else |
| 177 |
#define Skein_Swap64(w64) (w64) |
| 178 |
#endif |
| 179 |
#endif |
| 180 |
|
| 181 |
|
| 182 |
#ifndef Skein_Put64_LSB_First |
| 183 |
void Skein_Put64_LSB_First(u08b_t *dst,const u64b_t *src,size_t bCnt) |
| 184 |
#ifdef SKEIN_PORT_CODE |
| 185 |
{ |
| 186 |
size_t n; |
| 187 |
|
| 188 |
for (n=0;n<bCnt;n++) |
| 189 |
dst[n] = (u08b_t) (src[n>>3] >> (8*(n&7))); |
| 190 |
} |
| 191 |
#else |
| 192 |
; |
| 193 |
#endif |
| 194 |
#endif |
| 195 |
|
| 196 |
|
| 197 |
#ifndef Skein_Get64_LSB_First |
| 198 |
void Skein_Get64_LSB_First(u64b_t *dst,const u08b_t *src,size_t wCnt) |
| 199 |
#ifdef SKEIN_PORT_CODE |
| 200 |
{ |
| 201 |
size_t n; |
| 202 |
|
| 203 |
for (n=0;n<8*wCnt;n+=8) |
| 204 |
dst[n/8] = (((u64b_t) src[n ]) ) + |
| 205 |
(((u64b_t) src[n+1]) << 8) + |
| 206 |
(((u64b_t) src[n+2]) << 16) + |
| 207 |
(((u64b_t) src[n+3]) << 24) + |
| 208 |
(((u64b_t) src[n+4]) << 32) + |
| 209 |
(((u64b_t) src[n+5]) << 40) + |
| 210 |
(((u64b_t) src[n+6]) << 48) + |
| 211 |
(((u64b_t) src[n+7]) << 56) ; |
| 212 |
} |
| 213 |
#else |
| 214 |
; |
| 215 |
#endif |
| 216 |
#endif |
| 217 |
|
| 218 |
#endif |