|
|
1.1 root 1: #ifndef WHIRLPOOL_H
2: #define WHIRLPOOL_H 1
3:
1.1.1.3 ! root 4: #if defined(__cplusplus)
! 5: extern "C"
! 6: {
! 7: #endif
! 8:
1.1 root 9: #ifndef PORTABLE_C__
10: #define PORTABLE_C__
11:
12: #include <limits.h>
13:
14: /* Definition of minimum-width integer types
15: *
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
19: *
20: * s8, s16, s32 -> signed counterparts of u8, u16, u32
21: *
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.
24: */
25:
26: typedef signed char s8;
27: typedef unsigned char u8;
28:
29: #if UINT_MAX >= 4294967295UL
30:
31: typedef signed short s16;
32: typedef signed int s32;
33: typedef unsigned short u16;
34: typedef unsigned int u32;
35:
36: #define ONE32 0xffffffffU
37:
38: #else
39:
40: typedef signed int s16;
41: typedef signed long s32;
42: typedef unsigned int u16;
43: typedef unsigned __int32 u32;
44:
45: #define ONE32 0xffffffffUL
46:
47: #endif
48:
49: #define ONE8 0xffU
50: #define ONE16 0xffffU
51:
52: #define T8(x) ((x) & ONE8)
53: #define T16(x) ((x) & ONE16)
54: #define T32(x) ((x) & ONE32)
55:
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))))
69: /*
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).
74: *
75: * On non-64-bit architectures, "long long" is used.
76: */
77:
78: /*
79: * U8TO32_BIG(c) returns the 32-bit value stored in big-endian convention
80: * in the unsigned char array pointed to by c.
81: */
82: #define U8TO32_BIG(c) (((u32)T8(*(c)) << 24) | ((u32)T8(*((c) + 1)) << 16) | ((u32)T8(*((c) + 2)) << 8) | ((u32)T8(*((c) + 3))))
83:
84: /*
85: * U8TO32_LITTLE(c) returns the 32-bit value stored in little-endian convention
86: * in the unsigned char array pointed to by c.
87: */
88: #define U8TO32_LITTLE(c) (((u32)T8(*(c))) | ((u32)T8(*((c) + 1)) << 8) | (u32)T8(*((c) + 2)) << 16) | ((u32)T8(*((c) + 3)) << 24))
89:
90: /*
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.
93: */
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)
95:
96: /*
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.
99: */
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)
101:
102: /*
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.
106: *
107: * It evaluates v and n twice.
108: *
109: * The compiler might emit a warning if n is the constant 0. The result
110: * is undefined if n is greater than 31.
111: */
112: #define ROTL32(v, n) (T32((v) << (n)) | ((v) >> (32 - (n))))
113:
114: /*
115: * Whirlpool-specific definitions.
116: */
117:
118: #define DIGESTBYTES 64
119: #define DIGESTBITS (8*DIGESTBYTES) /* 512 */
120:
121: #define WBLOCKBYTES 64
122: #define WBLOCKBITS (8*WBLOCKBYTES) /* 512 */
123:
124: #define LENGTHBYTES 32
125: #define LENGTHBITS (8*LENGTHBYTES) /* 256 */
126:
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;
134:
135: #endif /* PORTABLE_C__ */
136:
137: // -------------
138:
139: typedef NESSIEstruct WHIRLPOOL_CTX;
140:
1.1.1.2 root 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);
1.1 root 144:
1.1.1.3 ! root 145: #if defined(__cplusplus)
! 146: }
! 147: #endif
! 148:
1.1 root 149: #endif /* WHIRLPOOL_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.