4 /*******************************************************************
6 ** Platform-specific definitions for Skein hash function.
8 ** Source code author: Doug Whiting, 2008.
10 ** This algorithm and source code is released to the public domain.
12 ** Many thanks to Brian Gladman for his portable header files.
14 ** To port Skein to an "unsupported" platform, change the definitions
15 ** in this file appropriately.
17 ********************************************************************/
19 #include <sys/endian.h>
20 #include <sys/types.h>
22 #ifndef _OPENSOLARIS_SYS_TYPES_H_ /* Avoid redefining this typedef */
23 typedef unsigned int uint_t; /* native unsigned integer */
25 typedef u_int8_t u08b_t; /* 8-bit unsigned integer */
26 typedef u_int32_t uint_32t; /* 32-bit unsigned integer */
27 typedef u_int64_t u64b_t; /* 64-bit unsigned integer */
30 #define RotL_64(x,N) (((x) << (N)) | ((x) >> (64-(N))))
36 * Skein is "natively" little-endian (unlike SHA-xxx), for optimal
37 * performance on x86 CPUs. The Skein code requires the following
38 * definitions for dealing with endianness:
40 * SKEIN_NEED_SWAP: 0 for little-endian, 1 for big-endian
41 * Skein_Put64_LSB_First
42 * Skein_Get64_LSB_First
45 * If SKEIN_NEED_SWAP is defined at compile time, it is used here
46 * along with the portable versions of Put64/Get64/Swap64, which
47 * are slow in general.
49 * Otherwise, an "auto-detect" of endianness is attempted below.
50 * If the default handling doesn't work well, the user may insert
51 * platform-specific code instead (e.g., for big-endian CPUs).
54 #ifndef SKEIN_NEED_SWAP /* compile-time "override" for endianness? */
56 #if BYTE_ORDER == BIG_ENDIAN
57 /* here for big-endian CPUs */
58 #define SKEIN_NEED_SWAP (1)
59 #ifdef SKEIN_PORT_CODE
60 void Skein_Put64_LSB_First(u08b_t *dst,const u64b_t *src,size_t bCnt);
61 void Skein_Get64_LSB_First(u64b_t *dst,const u08b_t *src,size_t wCnt);
62 #endif /* ifdef SKEIN_PORT_CODE */
63 #elif BYTE_ORDER == LITTLE_ENDIAN
64 /* here for x86 and x86-64 CPUs (and other detected little-endian CPUs) */
65 #define SKEIN_NEED_SWAP (0)
66 #define Skein_Put64_LSB_First(dst08,src64,bCnt) memcpy(dst08,src64,bCnt)
67 #define Skein_Get64_LSB_First(dst64,src08,wCnt) memcpy(dst64,src08,8*(wCnt))
69 #error "Skein needs endianness setting!"
72 #endif /* ifndef SKEIN_NEED_SWAP */
75 ******************************************************************
76 * Provide any definitions still needed.
77 ******************************************************************
79 #ifndef Skein_Swap64 /* swap for big-endian, nop for little-endian */
81 #define Skein_Swap64(w64) bswap64(w64)
83 #define Skein_Swap64(w64) (w64)
85 #endif /* ifndef Skein_Swap64 */
88 #ifndef Skein_Put64_LSB_First
89 void Skein_Put64_LSB_First(u08b_t *dst,const u64b_t *src,size_t bCnt)
90 #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */
94 for (n = 0; n < bCnt / 8; n++)
95 le64enc(dst + n * 8, src[n]);
98 ; /* output only the function prototype */
100 #endif /* ifndef Skein_Put64_LSB_First */
103 #ifndef Skein_Get64_LSB_First
104 void Skein_Get64_LSB_First(u64b_t *dst,const u08b_t *src,size_t wCnt)
105 #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */
109 for (n = 0; n < wCnt; n++)
110 dst[n] = le64dec(src + n * 8);
113 ; /* output only the function prototype */
115 #endif /* ifndef Skein_Get64_LSB_First */
117 /* Start FreeBSD libmd shims */
119 /* Ensure libmd symbols do not clash with libcrypto */
120 #ifndef SKEIN256_Init
121 #define SKEIN256_Init _libmd_SKEIN256_Init
122 #define SKEIN512_Init _libmd_SKEIN512_Init
123 #define SKEIN1024_Init _libmd_SKEIN1024_Init
125 #ifndef SKEIN256_Update
126 #define SKEIN256_Update _libmd_SKEIN256_Update
127 #define SKEIN512_Update _libmd_SKEIN512_Update
128 #define SKEIN1024_Update _libmd_SKEIN1024_Update
130 #ifndef SKEIN256_Final
131 #define SKEIN256_Final _libmd_SKEIN256_Final
132 #define SKEIN512_Final _libmd_SKEIN512_Final
133 #define SKEIN1024_Final _libmd_SKEIN1024_Final
136 #define SKEIN256_End _libmd_SKEIN256_End
137 #define SKEIN512_End _libmd_SKEIN512_End
138 #define SKEIN1024_End _libmd_SKEIN1024_End
141 #define SKEIN256_Fd _libmd_SKEIN256_Fd
142 #define SKEIN512_Fd _libmd_SKEIN512_Fd
143 #define SKEIN1024_Fd _libmd_SKEIN1024_Fd
145 #ifndef SKEIN256_FdChunk
146 #define SKEIN256_FdChunk _libmd_SKEIN256_FdChunk
147 #define SKEIN512_FdChunk _libmd_SKEIN512_FdChunk
148 #define SKEIN1024_FdChunk _libmd_SKEIN1024_FdChunk
150 #ifndef SKEIN256_File
151 #define SKEIN256_File _libmd_SKEIN256_File
152 #define SKEIN512_File _libmd_SKEIN512_File
153 #define SKEIN1024_File _libmd_SKEIN1024_File
155 #ifndef SKEIN256_FileChunk
156 #define SKEIN256_FileChunk _libmd_SKEIN256_FileChunk
157 #define SKEIN512_FileChunk _libmd_SKEIN512_FileChunk
158 #define SKEIN1024_FileChunk _libmd_SKEIN1024_FileChunk
160 #ifndef SKEIN256_Data
161 #define SKEIN256_Data _libmd_SKEIN256_Data
162 #define SKEIN512_Data _libmd_SKEIN512_Data
163 #define SKEIN1024_Data _libmd_SKEIN1024_Data
168 #endif /* ifndef _SKEIN_PORT_H_ */