Embedded SDK
Embedded SDK
lib_cxng
src
cx_Groestl-ref.h
Go to the documentation of this file.
1
#ifdef HAVE_GROESTL
2
3
#ifndef __groestl_ref_h
4
#define __groestl_ref_h
5
6
// #include <stdio.h>
7
// #include <stdlib.h>
8
#define NEED_UINT_64T
9
10
/* ****
11
#include "brg_types.h"
12
//Inline the file here:
13
*/
14
15
/*
16
---------------------------------------------------------------------------
17
Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
18
19
(a few lines added by Soeren S. Thomsen, October 2008)
20
21
LICENSE TERMS
22
23
The redistribution and use of this software (with or without changes)
24
is allowed without the payment of fees or royalties provided that:
25
26
1. source code distributions include the above copyright notice, this
27
list of conditions and the following disclaimer;
28
29
2. binary distributions include the above copyright notice, this list
30
of conditions and the following disclaimer in their documentation;
31
32
3. the name of the copyright holder is not used to endorse products
33
built using this software without specific written permission.
34
35
DISCLAIMER
36
37
This software is provided 'as is' with no explicit or implied warranties
38
in respect of its properties, including, but not limited to, correctness
39
and/or fitness for purpose.
40
---------------------------------------------------------------------------
41
Issue Date: 20/12/2007
42
43
The unsigned integer types defined here are of the form uint_<nn>t where
44
<nn> is the length of the type; for example, the unsigned 32-bit type is
45
'uint_32t'. These are NOT the same as the 'C99 integer types' that are
46
defined in the inttypes.h and stdint.h headers since attempts to use these
47
types have shown that support for them is still highly variable. However,
48
since the latter are of the form uint<nn>_t, a regular expression search
49
and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t')
50
can be used to convert the types used here to the C99 standard types.
51
*/
52
53
#ifndef _BRG_TYPES_H
54
#define _BRG_TYPES_H
55
56
#include <limits.h>
57
58
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
59
#include <stddef.h>
60
#define ptrint_t intptr_t
61
#elif defined(__GNUC__) && (__GNUC__ >= 3)
62
#include <stdint.h>
63
#define ptrint_t intptr_t
64
#else
65
#define ptrint_t int
66
#endif
67
68
#ifndef BRG_UI8
69
#define BRG_UI8
70
#if UCHAR_MAX == 255u
71
typedef
unsigned
char
uint_8t;
72
#else
73
#error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h
74
#endif
75
#endif
76
77
#ifndef BRG_UI16
78
#define BRG_UI16
79
#if USHRT_MAX == 65535u
80
typedef
unsigned
short
uint_16t;
81
#else
82
#error Please define uint_16t as a 16-bit unsigned short type in brg_types.h
83
#endif
84
#endif
85
86
#ifndef BRG_UI32
87
#define BRG_UI32
88
#if UINT_MAX == 4294967295u
89
#define li_32(h) 0x##h##u
90
typedef
unsigned
int
uint_32t;
91
#elif ULONG_MAX == 4294967295u
92
#define li_32(h) 0x##h##ul
93
typedef
unsigned
long
uint_32t;
94
#elif defined(_CRAY)
95
#error This code needs 32-bit data types, which Cray machines do not provide
96
#else
97
#error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h
98
#endif
99
#endif
100
101
#ifndef BRG_UI64
102
#if defined(__BORLANDC__) && !defined(__MSDOS__)
103
#define BRG_UI64
104
#define li_64(h) 0x##h##ui64
105
typedef
unsigned
__int64 uint_64t;
106
#elif defined(_MSC_VER) && (_MSC_VER < 1300)
/* 1300 == VC++ 7.0 */
107
#define BRG_UI64
108
#define li_64(h) 0x##h##ui64
109
typedef
unsigned
__int64 uint_64t;
110
#elif defined(__sun) && defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful
111
#define BRG_UI64
112
#define li_64(h) 0x##h##ull
113
typedef
unsigned
long
long
uint_64t;
114
#elif defined(__MVS__)
115
#define BRG_UI64
116
#define li_64(h) 0x##h##ull
117
typedef
unsigned
int
long
long
uint_64t;
118
#elif defined(UINT_MAX) && UINT_MAX > 4294967295u
119
#if UINT_MAX == 18446744073709551615u
120
#define BRG_UI64
121
#define li_64(h) 0x##h##u
122
typedef
unsigned
int
uint_64t;
123
#endif
124
#elif defined(ULONG_MAX) && ULONG_MAX > 4294967295u
125
#if ULONG_MAX == 18446744073709551615ul
126
#define BRG_UI64
127
#define li_64(h) 0x##h##ul
128
typedef
unsigned
long
uint_64t;
129
#endif
130
#elif defined(ULLONG_MAX) && ULLONG_MAX > 4294967295u
131
#if ULLONG_MAX == 18446744073709551615ull
132
#define BRG_UI64
133
#define li_64(h) 0x##h##ull
134
typedef
unsigned
long
long
uint_64t;
135
#endif
136
#elif defined(ULONG_LONG_MAX) && ULONG_LONG_MAX > 4294967295u
137
#if ULONG_LONG_MAX == 18446744073709551615ull
138
#define BRG_UI64
139
#define li_64(h) 0x##h##ull
140
typedef
unsigned
long
long
uint_64t;
141
#endif
142
#endif
143
#endif
144
145
#if !defined(BRG_UI64)
146
#if defined(NEED_UINT_64T)
147
#error Please define uint_64t as an unsigned 64 bit type in brg_types.h
148
#endif
149
#endif
150
151
#ifndef RETURN_VALUES
152
#define RETURN_VALUES
153
#if defined(DLL_EXPORT)
154
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
155
#define VOID_RETURN __declspec(dllexport) void __stdcall
156
#define INT_RETURN __declspec(dllexport) int __stdcall
157
#elif defined(__GNUC__)
158
#define VOID_RETURN __declspec(__dllexport__) void
159
#define INT_RETURN __declspec(__dllexport__) int
160
#else
161
#error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
162
#endif
163
#elif defined(DLL_IMPORT)
164
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
165
#define VOID_RETURN __declspec(dllimport) void __stdcall
166
#define INT_RETURN __declspec(dllimport) int __stdcall
167
#elif defined(__GNUC__)
168
#define VOID_RETURN __declspec(__dllimport__) void
169
#define INT_RETURN __declspec(__dllimport__) int
170
#else
171
#error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
172
#endif
173
#elif defined(__WATCOMC__)
174
#define VOID_RETURN void __cdecl
175
#define INT_RETURN int __cdecl
176
#else
177
#define VOID_RETURN void
178
#define INT_RETURN int
179
#endif
180
#endif
181
182
/* These defines are used to detect and set the memory alignment of pointers.
183
Note that offsets are in bytes.
184
185
ALIGN_OFFSET(x,n) return the positive or zero offset of
186
the memory addressed by the pointer 'x'
187
from an address that is aligned on an
188
'n' byte boundary ('n' is a power of 2)
189
190
ALIGN_FLOOR(x,n) return a pointer that points to memory
191
that is aligned on an 'n' byte boundary
192
and is not higher than the memory address
193
pointed to by 'x' ('n' is a power of 2)
194
195
ALIGN_CEIL(x,n) return a pointer that points to memory
196
that is aligned on an 'n' byte boundary
197
and is not lower than the memory address
198
pointed to by 'x' ('n' is a power of 2)
199
*/
200
201
#define ALIGN_OFFSET(x, n) (((ptrint_t) (x)) & ((n) -1))
202
#define ALIGN_FLOOR(x, n) ((uint_8t *) (x) - (((ptrint_t) (x)) & ((n) -1)))
203
#define ALIGN_CEIL(x, n) ((uint_8t *) (x) + (-((ptrint_t) (x)) & ((n) -1)))
204
205
/* These defines are used to declare buffers in a way that allows
206
faster operations on longer variables to be used. In all these
207
defines 'size' must be a power of 2 and >= 8. NOTE that the
208
buffer size is in bytes but the type length is in bits
209
210
UNIT_TYPEDEF(x,size) declares a variable 'x' of length
211
'size' bits
212
213
BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize'
214
bytes defined as an array of variables
215
each of 'size' bits (bsize must be a
216
multiple of size / 8)
217
218
UNIT_CAST(x,size) casts a variable to a type of
219
length 'size' bits
220
221
UPTR_CAST(x,size) casts a pointer to a pointer to a
222
variable of length 'size' bits
223
*/
224
225
#define UI_TYPE(size) uint_##size##t
226
#define UNIT_TYPEDEF(x, size) typedef UI_TYPE(size) x
227
#define BUFR_TYPEDEF(x, size, bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)]
228
#define UNIT_CAST(x, size) ((UI_TYPE(size))(x))
229
#define UPTR_CAST(x, size) ((UI_TYPE(size) *) (x))
230
231
/* Added by Soeren S. Thomsen (begin) */
232
#define u8 uint_8t
233
#define u32 uint_32t
234
#define u64 uint_64t
235
/* (end) */
236
237
#endif
238
239
/*
240
//End of inline
241
**** */
242
243
#define ROWS 8
244
#define LENGTHFIELDLEN ROWS
245
#define COLS512 8
246
#define COLS1024 16
247
#define SIZE512 (ROWS * COLS512)
248
// #define SIZE1024 (ROWS*COLS1024)
249
#define ROUNDS512 10
250
#define ROUNDS1024 14
251
252
typedef
enum
{
253
P512 = 0,
254
Q512 = 1,
255
P1024 = 2,
256
Q1024 = 3
257
} Variant;
258
259
#define mul1(b) ((u8) (b))
260
#define mul2(b) ((u8) ((b) >> 7 ? ((b) << 1) ^ 0x1b : ((b) << 1)))
261
#define mul3(b) (mul2(b) ^ mul1(b))
262
#define mul4(b) mul2(mul2(b))
263
#define mul5(b) (mul4(b) ^ mul1(b))
264
#define mul6(b) (mul4(b) ^ mul2(b))
265
#define mul7(b) (mul4(b) ^ mul2(b) ^ mul1(b))
266
267
/* NIST API begin */
268
typedef
unsigned
long
long
DataLength;
269
typedef
enum
{
270
SUCCESS = 0,
271
FAIL = 1,
272
BAD_HASHLEN = 2
273
} HashReturn;
274
/* NIST API end */
275
276
/* helper functions */
277
void
PrintHash(BitSequence *,
int
);
278
279
#endif
/* __groestl_ref_h */
280
281
#endif
// HAVE_GROESTL
Generated by
1.9.1