00001 // Copyright 2006 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the 00015 // Free Software Foundation, Inc., 00016 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 #ifndef _LUCID_WHIRLPOOL_INTERNAL_H 00019 #define _LUCID_WHIRLPOOL_INTERNAL_H 00020 00021 #define ONE8 0xffU 00022 #define ONE16 0xffffU 00023 00024 #if UINT_MAX >= 4294967295UL 00025 #define ONE32 0xffffffffU 00026 #else 00027 #define ONE32 0xffffffffUL 00028 #endif 00029 00030 #define ONE64 0xffffffffffffffffULL 00031 00032 #define T8(x) ((x) & ONE8) 00033 #define T16(x) ((x) & ONE16) 00034 #define T32(x) ((x) & ONE32) 00035 #define T64(x) ((x) & ONE64) 00036 00037 /* 00038 * U8TO32_BIG(c) returns the 32-bit value stored in big-endian convention 00039 * in the unsigned char array pointed to by c. 00040 */ 00041 #define U8TO32_BIG(c) (((u32)T8(*(c)) << 24) | ((u32)T8(*((c) + 1)) << 16) | ((u32)T8(*((c) + 2)) << 8) | ((u32)T8(*((c) + 3)))) 00042 00043 /* 00044 * U8TO32_LITTLE(c) returns the 32-bit value stored in little-endian convention 00045 * in the unsigned char array pointed to by c. 00046 */ 00047 #define U8TO32_LITTLE(c) (((u32)T8(*(c))) | ((u32)T8(*((c) + 1)) << 8) | (u32)T8(*((c) + 2)) << 16) | ((u32)T8(*((c) + 3)) << 24)) 00048 00049 /* 00050 * U8TO32_BIG(c, v) stores the 32-bit-value v in big-endian convention 00051 * into the unsigned char array pointed to by c. 00052 */ 00053 #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) 00054 00055 /* 00056 * U8TO32_LITTLE(c, v) stores the 32-bit-value v in little-endian convention 00057 * into the unsigned char array pointed to by c. 00058 */ 00059 #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) 00060 00061 /* 00062 * ROTL32(v, n) returns the value of the 32-bit unsigned value v after 00063 * a rotation of n bits to the left. It might be replaced by the appropriate 00064 * architecture-specific macro. 00065 * 00066 * It evaluates v and n twice. 00067 * 00068 * The compiler might emit a warning if n is the constant 0. The result 00069 * is undefined if n is greater than 31. 00070 */ 00071 #define ROTL32(v, n) (T32((v) << (n)) | ((v) >> (32 - (n)))) 00072 #define ROTR64(v, n) (((v) >> (n)) | T64((v) << (64 - (n)))) 00073 00074 /* 00075 * The number of rounds of the internal dedicated block cipher. 00076 */ 00077 #define R 10 00078 00079 #endif