|
|
1.1 root 1: #ifndef WHIRLPOOL_H
2: #define WHIRLPOOL_H 1
3:
4: #ifndef PORTABLE_C__
5: #define PORTABLE_C__
6:
7: #include <limits.h>
8:
9: /* Definition of minimum-width integer types
10: *
11: * u8 -> unsigned integer type, at least 8 bits, equivalent to unsigned char
12: * u16 -> unsigned integer type, at least 16 bits
13: * u32 -> unsigned integer type, at least 32 bits
14: *
15: * s8, s16, s32 -> signed counterparts of u8, u16, u32
16: *
17: * Always use macro's T8(), T16() or T32() to obtain exact-width results,
18: * i.e., to specify the size of the result of each expression.
19: */
20:
21: typedef signed char s8;
22: typedef unsigned char u8;
23:
24: #if UINT_MAX >= 4294967295UL
25:
26: typedef signed short s16;
27: typedef signed int s32;
28: typedef unsigned short u16;
29: typedef unsigned int u32;
30:
31: #define ONE32 0xffffffffU
32:
33: #else
34:
35: typedef signed int s16;
36: typedef signed long s32;
37: typedef unsigned int u16;
38: typedef unsigned __int32 u32;
39:
40: #define ONE32 0xffffffffUL
41:
42: #endif
43:
44: #define ONE8 0xffU
45: #define ONE16 0xffffU
46:
47: #define T8(x) ((x) & ONE8)
48: #define T16(x) ((x) & ONE16)
49: #define T32(x) ((x) & ONE32)
50:
51: #ifdef _MSC_VER
52: typedef unsigned __int64 u64;
53: typedef signed __int64 s64;
54: #define LL(v) (v##i64)
55: #define ONE64 LL(0xffffffffffffffff)
56: #else /* !_MSC_VER */
57: typedef unsigned long long u64;
58: typedef signed long long s64;
59: #define LL(v) (v##ULL)
60: #define ONE64 LL(0xffffffffffffffff)
61: #endif /* ?_MSC_VER */
62: #define T64(x) ((x) & ONE64)
63: #define ROTR64(v, n) (((v) >> (n)) | T64((v) << (64 - (n))))
64: /*
65: * Note: the test is used to detect native 64-bit architectures;
66: * if the unsigned long is strictly greater than 32-bit, it is
67: * assumed to be at least 64-bit. This will not work correctly
68: * on (old) 36-bit architectures (PDP-11 for instance).
69: *
70: * On non-64-bit architectures, "long long" is used.
71: */
72:
73: /*
74: * U8TO32_BIG(c) returns the 32-bit value stored in big-endian convention
75: * in the unsigned char array pointed to by c.
76: */
77: #define U8TO32_BIG(c) (((u32)T8(*(c)) << 24) | ((u32)T8(*((c) + 1)) << 16) | ((u32)T8(*((c) + 2)) << 8) | ((u32)T8(*((c) + 3))))
78:
79: /*
80: * U8TO32_LITTLE(c) returns the 32-bit value stored in little-endian convention
81: * in the unsigned char array pointed to by c.
82: */
83: #define U8TO32_LITTLE(c) (((u32)T8(*(c))) | ((u32)T8(*((c) + 1)) << 8) | (u32)T8(*((c) + 2)) << 16) | ((u32)T8(*((c) + 3)) << 24))
84:
85: /*
86: * U8TO32_BIG(c, v) stores the 32-bit-value v in big-endian convention
87: * into the unsigned char array pointed to by c.
88: */
89: #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)
90:
91: /*
92: * U8TO32_LITTLE(c, v) stores the 32-bit-value v in little-endian convention
93: * into the unsigned char array pointed to by c.
94: */
95: #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)
96:
97: /*
98: * ROTL32(v, n) returns the value of the 32-bit unsigned value v after
99: * a rotation of n bits to the left. It might be replaced by the appropriate
100: * architecture-specific macro.
101: *
102: * It evaluates v and n twice.
103: *
104: * The compiler might emit a warning if n is the constant 0. The result
105: * is undefined if n is greater than 31.
106: */
107: #define ROTL32(v, n) (T32((v) << (n)) | ((v) >> (32 - (n))))
108:
109: /*
110: * Whirlpool-specific definitions.
111: */
112:
113: #define DIGESTBYTES 64
114: #define DIGESTBITS (8*DIGESTBYTES) /* 512 */
115:
116: #define WBLOCKBYTES 64
117: #define WBLOCKBITS (8*WBLOCKBYTES) /* 512 */
118:
119: #define LENGTHBYTES 32
120: #define LENGTHBITS (8*LENGTHBYTES) /* 256 */
121:
122: typedef struct NESSIEstruct {
123: u8 bitLength[LENGTHBYTES]; /* global number of hashed bits (256-bit counter) */
124: u8 buffer[WBLOCKBYTES]; /* buffer of data to hash */
125: int bufferBits; /* current number of bits on the buffer */
126: int bufferPos; /* current (possibly incomplete) byte slot on the buffer */
127: u64 hash[DIGESTBYTES/8]; /* the hashing state */
128: } NESSIEstruct;
129:
130: #endif /* PORTABLE_C__ */
131:
132: // -------------
133:
134: typedef NESSIEstruct WHIRLPOOL_CTX;
135:
136: void _cdecl WHIRLPOOL_add(const unsigned char * const source, unsigned __int32 sourceBits, struct NESSIEstruct * const structpointer);
137: void _cdecl WHIRLPOOL_finalize(struct NESSIEstruct * const structpointer, unsigned char * const result);
138: void _cdecl WHIRLPOOL_init(struct NESSIEstruct * const structpointer);
139:
140: #endif /* WHIRLPOOL_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.