00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdint.h>
00023
00024 #include "whirlpool.h"
00025 #include "whirlpool_tables.h"
00026
00027 void whirlpool_transform(whirlpool_t * const context)
00028 {
00029 int i, r;
00030 uint64_t K[8];
00031 uint64_t block[8];
00032 uint64_t state[8];
00033 uint64_t L[8];
00034 uint8_t *buf = context->buf;
00035
00036
00037 for (i = 0; i < 8; i++, buf += 8) {
00038 block[i] = (((uint64_t)buf[0] ) << 56) ^
00039 (((uint64_t)buf[1] & 0xffL) << 48) ^
00040 (((uint64_t)buf[2] & 0xffL) << 40) ^
00041 (((uint64_t)buf[3] & 0xffL) << 32) ^
00042 (((uint64_t)buf[4] & 0xffL) << 24) ^
00043 (((uint64_t)buf[5] & 0xffL) << 16) ^
00044 (((uint64_t)buf[6] & 0xffL) << 8) ^
00045 (((uint64_t)buf[7] & 0xffL) );
00046 }
00047
00048
00049 state[0] = block[0] ^ (K[0] = context->hash[0]);
00050 state[1] = block[1] ^ (K[1] = context->hash[1]);
00051 state[2] = block[2] ^ (K[2] = context->hash[2]);
00052 state[3] = block[3] ^ (K[3] = context->hash[3]);
00053 state[4] = block[4] ^ (K[4] = context->hash[4]);
00054 state[5] = block[5] ^ (K[5] = context->hash[5]);
00055 state[6] = block[6] ^ (K[6] = context->hash[6]);
00056 state[7] = block[7] ^ (K[7] = context->hash[7]);
00057
00058
00059 for (r = 1; r <= R; r++) {
00060
00061 L[0] = C0[(int)(K[0] >> 56) ] ^
00062 C1[(int)(K[7] >> 48) & 0xff] ^
00063 C2[(int)(K[6] >> 40) & 0xff] ^
00064 C3[(int)(K[5] >> 32) & 0xff] ^
00065 C4[(int)(K[4] >> 24) & 0xff] ^
00066 C5[(int)(K[3] >> 16) & 0xff] ^
00067 C6[(int)(K[2] >> 8) & 0xff] ^
00068 C7[(int)(K[1] ) & 0xff] ^
00069 rc[r];
00070
00071 L[1] = C0[(int)(K[1] >> 56) ] ^
00072 C1[(int)(K[0] >> 48) & 0xff] ^
00073 C2[(int)(K[7] >> 40) & 0xff] ^
00074 C3[(int)(K[6] >> 32) & 0xff] ^
00075 C4[(int)(K[5] >> 24) & 0xff] ^
00076 C5[(int)(K[4] >> 16) & 0xff] ^
00077 C6[(int)(K[3] >> 8) & 0xff] ^
00078 C7[(int)(K[2] ) & 0xff];
00079
00080 L[2] = C0[(int)(K[2] >> 56) ] ^
00081 C1[(int)(K[1] >> 48) & 0xff] ^
00082 C2[(int)(K[0] >> 40) & 0xff] ^
00083 C3[(int)(K[7] >> 32) & 0xff] ^
00084 C4[(int)(K[6] >> 24) & 0xff] ^
00085 C5[(int)(K[5] >> 16) & 0xff] ^
00086 C6[(int)(K[4] >> 8) & 0xff] ^
00087 C7[(int)(K[3] ) & 0xff];
00088
00089 L[3] = C0[(int)(K[3] >> 56) ] ^
00090 C1[(int)(K[2] >> 48) & 0xff] ^
00091 C2[(int)(K[1] >> 40) & 0xff] ^
00092 C3[(int)(K[0] >> 32) & 0xff] ^
00093 C4[(int)(K[7] >> 24) & 0xff] ^
00094 C5[(int)(K[6] >> 16) & 0xff] ^
00095 C6[(int)(K[5] >> 8) & 0xff] ^
00096 C7[(int)(K[4] ) & 0xff];
00097
00098 L[4] = C0[(int)(K[4] >> 56) ] ^
00099 C1[(int)(K[3] >> 48) & 0xff] ^
00100 C2[(int)(K[2] >> 40) & 0xff] ^
00101 C3[(int)(K[1] >> 32) & 0xff] ^
00102 C4[(int)(K[0] >> 24) & 0xff] ^
00103 C5[(int)(K[7] >> 16) & 0xff] ^
00104 C6[(int)(K[6] >> 8) & 0xff] ^
00105 C7[(int)(K[5] ) & 0xff];
00106
00107 L[5] = C0[(int)(K[5] >> 56) ] ^
00108 C1[(int)(K[4] >> 48) & 0xff] ^
00109 C2[(int)(K[3] >> 40) & 0xff] ^
00110 C3[(int)(K[2] >> 32) & 0xff] ^
00111 C4[(int)(K[1] >> 24) & 0xff] ^
00112 C5[(int)(K[0] >> 16) & 0xff] ^
00113 C6[(int)(K[7] >> 8) & 0xff] ^
00114 C7[(int)(K[6] ) & 0xff];
00115
00116 L[6] = C0[(int)(K[6] >> 56) ] ^
00117 C1[(int)(K[5] >> 48) & 0xff] ^
00118 C2[(int)(K[4] >> 40) & 0xff] ^
00119 C3[(int)(K[3] >> 32) & 0xff] ^
00120 C4[(int)(K[2] >> 24) & 0xff] ^
00121 C5[(int)(K[1] >> 16) & 0xff] ^
00122 C6[(int)(K[0] >> 8) & 0xff] ^
00123 C7[(int)(K[7] ) & 0xff];
00124
00125 L[7] = C0[(int)(K[7] >> 56) ] ^
00126 C1[(int)(K[6] >> 48) & 0xff] ^
00127 C2[(int)(K[5] >> 40) & 0xff] ^
00128 C3[(int)(K[4] >> 32) & 0xff] ^
00129 C4[(int)(K[3] >> 24) & 0xff] ^
00130 C5[(int)(K[2] >> 16) & 0xff] ^
00131 C6[(int)(K[1] >> 8) & 0xff] ^
00132 C7[(int)(K[0] ) & 0xff];
00133
00134 K[0] = L[0];
00135 K[1] = L[1];
00136 K[2] = L[2];
00137 K[3] = L[3];
00138 K[4] = L[4];
00139 K[5] = L[5];
00140 K[6] = L[6];
00141 K[7] = L[7];
00142
00143
00144 L[0] = C0[(int)(state[0] >> 56) ] ^
00145 C1[(int)(state[7] >> 48) & 0xff] ^
00146 C2[(int)(state[6] >> 40) & 0xff] ^
00147 C3[(int)(state[5] >> 32) & 0xff] ^
00148 C4[(int)(state[4] >> 24) & 0xff] ^
00149 C5[(int)(state[3] >> 16) & 0xff] ^
00150 C6[(int)(state[2] >> 8) & 0xff] ^
00151 C7[(int)(state[1] ) & 0xff] ^
00152 K[0];
00153
00154 L[1] = C0[(int)(state[1] >> 56) ] ^
00155 C1[(int)(state[0] >> 48) & 0xff] ^
00156 C2[(int)(state[7] >> 40) & 0xff] ^
00157 C3[(int)(state[6] >> 32) & 0xff] ^
00158 C4[(int)(state[5] >> 24) & 0xff] ^
00159 C5[(int)(state[4] >> 16) & 0xff] ^
00160 C6[(int)(state[3] >> 8) & 0xff] ^
00161 C7[(int)(state[2] ) & 0xff] ^
00162 K[1];
00163
00164 L[2] = C0[(int)(state[2] >> 56) ] ^
00165 C1[(int)(state[1] >> 48) & 0xff] ^
00166 C2[(int)(state[0] >> 40) & 0xff] ^
00167 C3[(int)(state[7] >> 32) & 0xff] ^
00168 C4[(int)(state[6] >> 24) & 0xff] ^
00169 C5[(int)(state[5] >> 16) & 0xff] ^
00170 C6[(int)(state[4] >> 8) & 0xff] ^
00171 C7[(int)(state[3] ) & 0xff] ^
00172 K[2];
00173
00174 L[3] = C0[(int)(state[3] >> 56) ] ^
00175 C1[(int)(state[2] >> 48) & 0xff] ^
00176 C2[(int)(state[1] >> 40) & 0xff] ^
00177 C3[(int)(state[0] >> 32) & 0xff] ^
00178 C4[(int)(state[7] >> 24) & 0xff] ^
00179 C5[(int)(state[6] >> 16) & 0xff] ^
00180 C6[(int)(state[5] >> 8) & 0xff] ^
00181 C7[(int)(state[4] ) & 0xff] ^
00182 K[3];
00183
00184 L[4] = C0[(int)(state[4] >> 56) ] ^
00185 C1[(int)(state[3] >> 48) & 0xff] ^
00186 C2[(int)(state[2] >> 40) & 0xff] ^
00187 C3[(int)(state[1] >> 32) & 0xff] ^
00188 C4[(int)(state[0] >> 24) & 0xff] ^
00189 C5[(int)(state[7] >> 16) & 0xff] ^
00190 C6[(int)(state[6] >> 8) & 0xff] ^
00191 C7[(int)(state[5] ) & 0xff] ^
00192 K[4];
00193
00194 L[5] = C0[(int)(state[5] >> 56) ] ^
00195 C1[(int)(state[4] >> 48) & 0xff] ^
00196 C2[(int)(state[3] >> 40) & 0xff] ^
00197 C3[(int)(state[2] >> 32) & 0xff] ^
00198 C4[(int)(state[1] >> 24) & 0xff] ^
00199 C5[(int)(state[0] >> 16) & 0xff] ^
00200 C6[(int)(state[7] >> 8) & 0xff] ^
00201 C7[(int)(state[6] ) & 0xff] ^
00202 K[5];
00203
00204 L[6] = C0[(int)(state[6] >> 56) ] ^
00205 C1[(int)(state[5] >> 48) & 0xff] ^
00206 C2[(int)(state[4] >> 40) & 0xff] ^
00207 C3[(int)(state[3] >> 32) & 0xff] ^
00208 C4[(int)(state[2] >> 24) & 0xff] ^
00209 C5[(int)(state[1] >> 16) & 0xff] ^
00210 C6[(int)(state[0] >> 8) & 0xff] ^
00211 C7[(int)(state[7] ) & 0xff] ^
00212 K[6];
00213
00214 L[7] = C0[(int)(state[7] >> 56) ] ^
00215 C1[(int)(state[6] >> 48) & 0xff] ^
00216 C2[(int)(state[5] >> 40) & 0xff] ^
00217 C3[(int)(state[4] >> 32) & 0xff] ^
00218 C4[(int)(state[3] >> 24) & 0xff] ^
00219 C5[(int)(state[2] >> 16) & 0xff] ^
00220 C6[(int)(state[1] >> 8) & 0xff] ^
00221 C7[(int)(state[0] ) & 0xff] ^
00222 K[7];
00223
00224 state[0] = L[0];
00225 state[1] = L[1];
00226 state[2] = L[2];
00227 state[3] = L[3];
00228 state[4] = L[4];
00229 state[5] = L[5];
00230 state[6] = L[6];
00231 state[7] = L[7];
00232 }
00233
00234
00235 context->hash[0] ^= state[0] ^ block[0];
00236 context->hash[1] ^= state[1] ^ block[1];
00237 context->hash[2] ^= state[2] ^ block[2];
00238 context->hash[3] ^= state[3] ^ block[3];
00239 context->hash[4] ^= state[4] ^ block[4];
00240 context->hash[5] ^= state[5] ^ block[5];
00241 context->hash[6] ^= state[6] ^ block[6];
00242 context->hash[7] ^= state[7] ^ block[7];
00243 }