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