whirlpool.h

Go to the documentation of this file.
00001 
00002 /*  $Id: whirlpool.h 632 2006-03-12 20:18:16Z icreedon $    */
00003 
00004 #ifndef PORTABLE_C__
00005 #define PORTABLE_C__
00006 
00007 #include <limits.h>
00008 
00009 /* Definition of minimum-width integer types
00010  * 
00011  * u8   -> unsigned integer type, at least 8 bits, equivalent to unsigned char
00012  * u16  -> unsigned integer type, at least 16 bits
00013  * u32  -> unsigned integer type, at least 32 bits
00014  *
00015  * s8, s16, s32  -> signed counterparts of u8, u16, u32
00016  *
00017  * Always use macro's T8(), T16() or T32() to obtain exact-width results,
00018  * i.e., to specify the size of the result of each expression.
00019  */
00020 
00021 typedef signed char s8;
00022 typedef unsigned char u8;
00023 
00024 #if UINT_MAX >= 4294967295UL
00025 
00026 typedef signed short s16;
00027 typedef signed int s32;
00028 typedef unsigned short u16;
00029 typedef unsigned int u32;
00030 
00031 #define ONE32   0xffffffffU
00032 
00033 #else
00034 
00035 typedef signed int s16;
00036 typedef signed long s32;
00037 typedef unsigned int u16;
00038 typedef unsigned long u32;
00039 
00040 #define ONE32   0xffffffffUL
00041 
00042 #endif
00043 
00044 #define ONE8    0xffU
00045 #define ONE16   0xffffU
00046 
00047 #define T8(x)   ((x) & ONE8)
00048 #define T16(x)  ((x) & ONE16)
00049 #define T32(x)  ((x) & ONE32)
00050 
00051 #ifdef _MSC_VER
00052 typedef unsigned __int64 u64;
00053 typedef signed __int64 s64;
00054 #define LL(v)   (v##i64)
00055 #define ONE64   LL(0xffffffffffffffff)
00056 #else  /* !_MSC_VER */
00057 typedef unsigned long long u64;
00058 typedef signed long long s64;
00059 #define LL(v)   (v##ULL)
00060 #define ONE64   LL(0xffffffffffffffff)
00061 #endif /* ?_MSC_VER */
00062 #define T64(x)  ((x) & ONE64)
00063 #define ROTR64(v, n)   (((v) >> (n)) | T64((v) << (64 - (n))))
00064 /*
00065  * Note: the test is used to detect native 64-bit architectures;
00066  * if the unsigned long is strictly greater than 32-bit, it is
00067  * assumed to be at least 64-bit. This will not work correctly
00068  * on (old) 36-bit architectures (PDP-11 for instance).
00069  *
00070  * On non-64-bit architectures, "long long" is used.
00071  */
00072 
00073 /*
00074  * U8TO32_BIG(c) returns the 32-bit value stored in big-endian convention
00075  * in the unsigned char array pointed to by c.
00076  */
00077 #define U8TO32_BIG(c)  (((u32)T8(*(c)) << 24) | ((u32)T8(*((c) + 1)) << 16) | ((u32)T8(*((c) + 2)) << 8) | ((u32)T8(*((c) + 3))))
00078 
00079 /*
00080  * U8TO32_LITTLE(c) returns the 32-bit value stored in little-endian convention
00081  * in the unsigned char array pointed to by c.
00082  */
00083 #define U8TO32_LITTLE(c)  (((u32)T8(*(c))) | ((u32)T8(*((c) + 1)) << 8) | (u32)T8(*((c) + 2)) << 16) | ((u32)T8(*((c) + 3)) << 24))
00084 
00085 /*
00086  * U8TO32_BIG(c, v) stores the 32-bit-value v in big-endian convention
00087  * into the unsigned char array pointed to by c.
00088  */
00089 #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)
00090 
00091 /*
00092  * U8TO32_LITTLE(c, v) stores the 32-bit-value v in little-endian convention
00093  * into the unsigned char array pointed to by c.
00094  */
00095 #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)
00096 
00097 /*
00098  * ROTL32(v, n) returns the value of the 32-bit unsigned value v after
00099  * a rotation of n bits to the left. It might be replaced by the appropriate
00100  * architecture-specific macro.
00101  *
00102  * It evaluates v and n twice.
00103  *
00104  * The compiler might emit a warning if n is the constant 0. The result
00105  * is undefined if n is greater than 31.
00106  */
00107 #define ROTL32(v, n)   (T32((v) << (n)) | ((v) >> (32 - (n))))
00108 
00109 /*
00110  * Whirlpool-specific definitions.
00111  */
00112 
00113 #define DIGESTBYTES 64
00114 #define DIGESTBITS  (8*DIGESTBYTES) /* 512 */
00115 
00116 #define WBLOCKBYTES 64
00117 #define WBLOCKBITS  (8*WBLOCKBYTES) /* 512 */
00118 
00119 #define LENGTHBYTES 32
00120 #define LENGTHBITS  (8*LENGTHBYTES) /* 256 */
00121 
00122 typedef struct NESSIEstruct {
00123     u8  bitLength[LENGTHBYTES]; /* global number of hashed bits (256-bit counter) */
00124     u8  buffer[WBLOCKBYTES];    /* buffer of data to hash */
00125     int bufferBits;             /* current number of bits on the buffer */
00126     int bufferPos;              /* current (possibly incomplete) byte slot on the buffer */
00127     u64 hash[DIGESTBYTES/8];    /* the hashing state */
00128 } NESSIEstruct;
00129 
00130 #endif   /* PORTABLE_C__ */
00131 
00132 
00133 /* prototypes */ /* 2006-03-06 creedon */
00134 
00135 void NESSIEinit (NESSIEstruct * const);
00136 void NESSIEadd (const unsigned char * const, unsigned long, NESSIEstruct * const);
00137 void NESSIEfinalize (NESSIEstruct * const, unsigned char * const);
00138 void makeNESSIETestVectors ();
00139 void testAPI (void);
00140 

Generated on Wed May 31 18:20:04 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6