Add phnxdeco with debian patch set (version 0.33-3).
[delutions.git] / tc / crypto / Whirlpool.h
blobe12266b59930bf6348a8440852f87034d21f6100
1 #ifndef WHIRLPOOL_H
2 #define WHIRLPOOL_H 1
4 #if defined(__cplusplus)
5 extern "C"
7 #endif
9 #ifndef PORTABLE_C__
10 #define PORTABLE_C__
12 #include <limits.h>
14 /* Definition of minimum-width integer types
16 * u8 -> unsigned integer type, at least 8 bits, equivalent to unsigned char
17 * u16 -> unsigned integer type, at least 16 bits
18 * u32 -> unsigned integer type, at least 32 bits
20 * s8, s16, s32 -> signed counterparts of u8, u16, u32
22 * Always use macro's T8(), T16() or T32() to obtain exact-width results,
23 * i.e., to specify the size of the result of each expression.
26 typedef signed char s8;
27 typedef unsigned char u8;
29 #if UINT_MAX >= 4294967295UL
31 typedef signed short s16;
32 typedef signed int s32;
33 typedef unsigned short u16;
34 typedef unsigned int u32;
36 #define ONE32 0xffffffffU
38 #else
40 typedef signed int s16;
41 typedef signed long s32;
42 typedef unsigned int u16;
43 typedef unsigned __int32 u32;
45 #define ONE32 0xffffffffUL
47 #endif
49 #define ONE8 0xffU
50 #define ONE16 0xffffU
52 #define T8(x) ((x) & ONE8)
53 #define T16(x) ((x) & ONE16)
54 #define T32(x) ((x) & ONE32)
56 #ifdef _MSC_VER
57 typedef unsigned __int64 u64;
58 typedef signed __int64 s64;
59 #define LL(v) (v##i64)
60 #define ONE64 LL(0xffffffffffffffff)
61 #else /* !_MSC_VER */
62 typedef unsigned long long u64;
63 typedef signed long long s64;
64 #define LL(v) (v##ULL)
65 #define ONE64 LL(0xffffffffffffffff)
66 #endif /* ?_MSC_VER */
67 #define T64(x) ((x) & ONE64)
68 #define ROTR64(v, n) (((v) >> (n)) | T64((v) << (64 - (n))))
70 * Note: the test is used to detect native 64-bit architectures;
71 * if the unsigned long is strictly greater than 32-bit, it is
72 * assumed to be at least 64-bit. This will not work correctly
73 * on (old) 36-bit architectures (PDP-11 for instance).
75 * On non-64-bit architectures, "long long" is used.
79 * U8TO32_BIG(c) returns the 32-bit value stored in big-endian convention
80 * in the unsigned char array pointed to by c.
82 #define U8TO32_BIG(c) (((u32)T8(*(c)) << 24) | ((u32)T8(*((c) + 1)) << 16) | ((u32)T8(*((c) + 2)) << 8) | ((u32)T8(*((c) + 3))))
85 * U8TO32_LITTLE(c) returns the 32-bit value stored in little-endian convention
86 * in the unsigned char array pointed to by c.
88 #define U8TO32_LITTLE(c) (((u32)T8(*(c))) | ((u32)T8(*((c) + 1)) << 8) | (u32)T8(*((c) + 2)) << 16) | ((u32)T8(*((c) + 3)) << 24))
91 * U8TO32_BIG(c, v) stores the 32-bit-value v in big-endian convention
92 * into the unsigned char array pointed to by c.
94 #define U32TO8_BIG(c, v) do { u32 x = (v); u8 *d = (c); d[0] = T8(x >> 24); d[1] = T8(x >> 16); d[2] = T8(x >> 8); d[3] = T8(x); } while (0)
97 * U8TO32_LITTLE(c, v) stores the 32-bit-value v in little-endian convention
98 * into the unsigned char array pointed to by c.
100 #define U32TO8_LITTLE(c, v) do { u32 x = (v); u8 *d = (c); d[0] = T8(x); d[1] = T8(x >> 8); d[2] = T8(x >> 16); d[3] = T8(x >> 24); } while (0)
103 * ROTL32(v, n) returns the value of the 32-bit unsigned value v after
104 * a rotation of n bits to the left. It might be replaced by the appropriate
105 * architecture-specific macro.
107 * It evaluates v and n twice.
109 * The compiler might emit a warning if n is the constant 0. The result
110 * is undefined if n is greater than 31.
112 #define ROTL32(v, n) (T32((v) << (n)) | ((v) >> (32 - (n))))
115 * Whirlpool-specific definitions.
118 #define DIGESTBYTES 64
119 #define DIGESTBITS (8*DIGESTBYTES) /* 512 */
121 #define WBLOCKBYTES 64
122 #define WBLOCKBITS (8*WBLOCKBYTES) /* 512 */
124 #define LENGTHBYTES 32
125 #define LENGTHBITS (8*LENGTHBYTES) /* 256 */
127 typedef struct NESSIEstruct {
128 u8 bitLength[LENGTHBYTES]; /* global number of hashed bits (256-bit counter) */
129 u8 buffer[WBLOCKBYTES]; /* buffer of data to hash */
130 int bufferBits; /* current number of bits on the buffer */
131 int bufferPos; /* current (possibly incomplete) byte slot on the buffer */
132 u64 hash[DIGESTBYTES/8]; /* the hashing state */
133 } NESSIEstruct;
135 #endif /* PORTABLE_C__ */
137 // -------------
139 typedef NESSIEstruct WHIRLPOOL_CTX;
141 void WHIRLPOOL_add(const unsigned char * const source, unsigned __int32 sourceBits, struct NESSIEstruct * const structpointer);
142 void WHIRLPOOL_finalize(struct NESSIEstruct * const structpointer, unsigned char * const result);
143 void WHIRLPOOL_init(struct NESSIEstruct * const structpointer);
145 #if defined(__cplusplus)
147 #endif
149 #endif /* WHIRLPOOL_H */