VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/Whirlpool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto/Whirlpool.c')
-rw-r--r--src/Crypto/Whirlpool.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/Crypto/Whirlpool.c b/src/Crypto/Whirlpool.c
index 98ba318d..6a1fe8b4 100644
--- a/src/Crypto/Whirlpool.c
+++ b/src/Crypto/Whirlpool.c
@@ -867,158 +867,158 @@ void WhirlpoolTransform(uint64 *digest, const uint64 *block)
L[3] = Whirlpool_C[0*256 + K.ch[3 * 8 + 7]] ^ Whirlpool_C[1*256 + K.ch[2 * 8 + 6]] ^ Whirlpool_C[2*256 + K.ch[1 * 8 + 5]] ^ Whirlpool_C[3*256 + K.ch[0 * 8 + 4]] ^ Whirlpool_C[4*256 + K.ch[7 * 8 + 3]] ^ Whirlpool_C[5*256 + K.ch[6 * 8 + 2]] ^ Whirlpool_C[6*256 + K.ch[5 * 8 + 1]] ^ Whirlpool_C[7*256 + K.ch[4 * 8 + 0]];
L[4] = Whirlpool_C[0*256 + K.ch[4 * 8 + 7]] ^ Whirlpool_C[1*256 + K.ch[3 * 8 + 6]] ^ Whirlpool_C[2*256 + K.ch[2 * 8 + 5]] ^ Whirlpool_C[3*256 + K.ch[1 * 8 + 4]] ^ Whirlpool_C[4*256 + K.ch[0 * 8 + 3]] ^ Whirlpool_C[5*256 + K.ch[7 * 8 + 2]] ^ Whirlpool_C[6*256 + K.ch[6 * 8 + 1]] ^ Whirlpool_C[7*256 + K.ch[5 * 8 + 0]];
L[5] = Whirlpool_C[0*256 + K.ch[5 * 8 + 7]] ^ Whirlpool_C[1*256 + K.ch[4 * 8 + 6]] ^ Whirlpool_C[2*256 + K.ch[3 * 8 + 5]] ^ Whirlpool_C[3*256 + K.ch[2 * 8 + 4]] ^ Whirlpool_C[4*256 + K.ch[1 * 8 + 3]] ^ Whirlpool_C[5*256 + K.ch[0 * 8 + 2]] ^ Whirlpool_C[6*256 + K.ch[7 * 8 + 1]] ^ Whirlpool_C[7*256 + K.ch[6 * 8 + 0]];
L[6] = Whirlpool_C[0*256 + K.ch[6 * 8 + 7]] ^ Whirlpool_C[1*256 + K.ch[5 * 8 + 6]] ^ Whirlpool_C[2*256 + K.ch[4 * 8 + 5]] ^ Whirlpool_C[3*256 + K.ch[3 * 8 + 4]] ^ Whirlpool_C[4*256 + K.ch[2 * 8 + 3]] ^ Whirlpool_C[5*256 + K.ch[1 * 8 + 2]] ^ Whirlpool_C[6*256 + K.ch[0 * 8 + 1]] ^ Whirlpool_C[7*256 + K.ch[7 * 8 + 0]];
L[7] = Whirlpool_C[0*256 + K.ch[7 * 8 + 7]] ^ Whirlpool_C[1*256 + K.ch[6 * 8 + 6]] ^ Whirlpool_C[2*256 + K.ch[5 * 8 + 5]] ^ Whirlpool_C[3*256 + K.ch[4 * 8 + 4]] ^ Whirlpool_C[4*256 + K.ch[3 * 8 + 3]] ^ Whirlpool_C[5*256 + K.ch[2 * 8 + 2]] ^ Whirlpool_C[6*256 + K.ch[1 * 8 + 1]] ^ Whirlpool_C[7*256 + K.ch[0 * 8 + 0]];
L[0] = (K.ll[0] = L[0]) ^ Whirlpool_C[0*256 + state.ch[0 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[7 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[6 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[5 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[4 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[3 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[2 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[1 * 8 + 0]];
L[1] = (K.ll[1] = L[1]) ^ Whirlpool_C[0*256 + state.ch[1 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[0 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[7 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[6 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[5 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[4 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[3 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[2 * 8 + 0]];
L[2] = (K.ll[2] = L[2]) ^ Whirlpool_C[0*256 + state.ch[2 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[1 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[0 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[7 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[6 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[5 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[4 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[3 * 8 + 0]];
L[3] = (K.ll[3] = L[3]) ^ Whirlpool_C[0*256 + state.ch[3 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[2 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[1 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[0 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[7 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[6 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[5 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[4 * 8 + 0]];
L[4] = (K.ll[4] = L[4]) ^ Whirlpool_C[0*256 + state.ch[4 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[3 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[2 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[1 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[0 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[7 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[6 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[5 * 8 + 0]];
L[5] = (K.ll[5] = L[5]) ^ Whirlpool_C[0*256 + state.ch[5 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[4 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[3 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[2 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[1 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[0 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[7 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[6 * 8 + 0]];
L[6] = (K.ll[6] = L[6]) ^ Whirlpool_C[0*256 + state.ch[6 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[5 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[4 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[3 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[2 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[1 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[0 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[7 * 8 + 0]];
L[7] = (K.ll[7] = L[7]) ^ Whirlpool_C[0*256 + state.ch[7 * 8 + 7]] ^ Whirlpool_C[1*256 + state.ch[6 * 8 + 6]] ^ Whirlpool_C[2*256 + state.ch[5 * 8 + 5]] ^ Whirlpool_C[3*256 + state.ch[4 * 8 + 4]] ^ Whirlpool_C[4*256 + state.ch[3 * 8 + 3]] ^ Whirlpool_C[5*256 + state.ch[2 * 8 + 2]] ^ Whirlpool_C[6*256 + state.ch[1 * 8 + 1]] ^ Whirlpool_C[7*256 + state.ch[0 * 8 + 0]];
memcpy(state.ll, L, sizeof(L));
} while (++r < 10);
i = 0; do digest[i] ^= L[i] ^ (block)[i]; while (++i < 8);
}
}
static uint64 HashMultipleBlocks(WHIRLPOOL_CTX * const ctx, const uint64 *input, uint64 length)
{
uint64* dataBuf = ctx->data;
do
{
#if BYTE_ORDER == BIG_ENDIAN
WhirlpoolTransform(ctx->state, input);
#else
- CorrectEndianess(dataBuf, input, 64);
+ CorrectEndianness(dataBuf, input, 64);
WhirlpoolTransform(ctx->state, dataBuf);
#endif
input += 8;
length -= 64;
}
while (length >= 64);
return length;
}
/**
* Initialize the hashing state.
*/
void WHIRLPOOL_init(WHIRLPOOL_CTX * const ctx) {
ctx->countHi = 0;
ctx->countLo = 0;
memset (ctx->data, 0, 8 * sizeof (uint64));
memset (ctx->state, 0, 8 * sizeof (uint64));
}
/**
* Delivers input data to the hashing algorithm.
*
* @param source plaintext data to hash.
* @param sourceBits how many bits of plaintext to process.
*
* This method maintains the invariant: bufferBits < DIGESTBITS
*/
void WHIRLPOOL_add(const unsigned char * input,
unsigned __int32 sourceBytes,
WHIRLPOOL_CTX * const ctx)
{
uint64 num, oldCountLo = ctx->countLo, oldCountHi = ctx->countHi;
uint64 len = sourceBytes;
if ((ctx->countLo = oldCountLo + (uint64)len) < oldCountLo)
ctx->countHi++; // carry from low to high
if (ctx->countHi < oldCountHi)
return;
else
{
uint64* dataBuf = ctx->data;
- byte* data = (byte *)dataBuf;
+ uint8* data = (uint8 *)dataBuf;
num = oldCountLo & 63;
if (num != 0) // process left over data
{
if (num+len >= 64)
{
memcpy(data+num, input, (size_t) (64-num));
HashMultipleBlocks(ctx, dataBuf, 64);
input += (64-num);
len -= (64-num);
// drop through and do the rest
}
else
{
memcpy(data+num, input, (size_t) len);
return;
}
}
// now process the input data in blocks of 64 bytes and save the leftovers to ctx->data
if (len >= 64)
{
if (input == data)
{
HashMultipleBlocks(ctx, dataBuf, 64);
return;
}
else if (IsAligned16(input))
{
uint64 leftOver = HashMultipleBlocks(ctx, (uint64 *)input, len);
input += (len - leftOver);
len = leftOver;
}
else
do
{ // copy input first if it's not aligned correctly
memcpy(data, input, 64);
HashMultipleBlocks(ctx, dataBuf, 64);
input+=64;
len-=64;
} while (len >= 64);
}
if (len && data != input)
memcpy(data, input, (size_t) len);
}
}
/**
* Get the hash value from the hashing state.
*
* This method uses the invariant: bufferBits < DIGESTBITS
*/
void WHIRLPOOL_finalize(WHIRLPOOL_CTX * const ctx,
unsigned char * result)
{
unsigned int num = ctx->countLo & 63;
uint64* dataBuf = ctx->data;
uint64* stateBuf = ctx->state;
- byte* data = (byte *)dataBuf;
+ uint8* data = (uint8 *)dataBuf;
data[num++] = 0x80;
if (num <= 32)
memset(data+num, 0, 32-num);
else
{
memset(data+num, 0, 64-num);
HashMultipleBlocks(ctx, dataBuf, 64);
memset(data, 0, 32);
}
#if BYTE_ORDER == LITTLE_ENDIAN
- CorrectEndianess(dataBuf, dataBuf, 32);
+ CorrectEndianness(dataBuf, dataBuf, 32);
#endif
dataBuf[4] = 0;
dataBuf[5] = 0;
dataBuf[6] = (ctx->countLo >> (8*sizeof(uint64)-3)) + (ctx->countHi << 3);
dataBuf[7] = ctx->countLo << 3;
WhirlpoolTransform(stateBuf, dataBuf);
#if BYTE_ORDER == LITTLE_ENDIAN
- CorrectEndianess(stateBuf, stateBuf, 64);
+ CorrectEndianness(stateBuf, stateBuf, 64);
#endif
memcpy(result, stateBuf, 64);
}