protected override void Compress(ref SkeinState state, byte[] buffer, UInt64 bitCount) { var keyState = new UInt64[SKEIN_512_STATE_WORDS + 1]; var tweakState = new UInt64[3]; tweakState[0] = bitCount; tweakState[1] = (UInt64)state.Flags; keyState[0] = state.Hash[0]; keyState[1] = state.Hash[1]; keyState[2] = state.Hash[2]; keyState[3] = state.Hash[3]; keyState[4] = state.Hash[4]; keyState[5] = state.Hash[5]; keyState[6] = state.Hash[6]; keyState[7] = state.Hash[7]; keyState[8] = keyState[0] ^ keyState[1] ^ keyState[2] ^ keyState[3] ^ keyState[4] ^ keyState[5] ^ keyState[6] ^ keyState[7] ^ 0x5555555555555555; tweakState[2] = tweakState[0] ^ tweakState[1]; var block = ToBlock(buffer); var X = new UInt64[SKEIN_512_STATE_WORDS]; for (int i = 0; i < SKEIN_512_STATE_WORDS; i++) { X[i] = block[i]; } X[0] = block[0] + keyState[0]; X[1] = block[1] + keyState[1]; X[2] = block[2] + keyState[2]; X[3] = block[3] + keyState[3]; X[4] = block[4] + keyState[4]; X[5] = block[5] + keyState[5] + tweakState[0]; X[6] = block[6] + keyState[6] + tweakState[1]; X[7] = block[7] + keyState[7]; // 72 round plus injects EigthRounds(X, keyState, tweakState, 0); EigthRounds(X, keyState, tweakState, 1); EigthRounds(X, keyState, tweakState, 2); EigthRounds(X, keyState, tweakState, 3); EigthRounds(X, keyState, tweakState, 4); EigthRounds(X, keyState, tweakState, 5); EigthRounds(X, keyState, tweakState, 6); EigthRounds(X, keyState, tweakState, 7); EigthRounds(X, keyState, tweakState, 8); state.Hash[0] = X[0] ^ block[0]; state.Hash[1] = X[1] ^ block[1]; state.Hash[2] = X[2] ^ block[2]; state.Hash[3] = X[3] ^ block[3]; state.Hash[4] = X[4] ^ block[4]; state.Hash[5] = X[5] ^ block[5]; state.Hash[6] = X[6] ^ block[6]; state.Hash[7] = X[7] ^ block[7]; state.Flags &= ~SkeinFlags.First; // Disable "First" flag }
protected override byte[] FinalHash(SkeinState state) { var hashBytes = SKEIN_256_BLOCK_BYTES; var lastBytes = 8; if (this._bitLen == 224) { hashBytes -= 4; lastBytes = 4; } var result = new byte[hashBytes]; int h; for (h = 0; h < SKEIN_256_STATE_WORDS - 1; h++) { var completeBytes = BitConverter.GetBytes(state.Hash[h]); Buffer.BlockCopy(completeBytes, 0, result, h << 3, 8); } var finalBytes = BitConverter.GetBytes(state.Hash[h]); Buffer.BlockCopy(finalBytes, 0, result, h << 3, lastBytes); return(result); }
private SkeinState Init() { var result = new SkeinState(); result.Hash = new UInt64[this._stateWords]; for (int h = 0; h < this._stateWords; h++) { result.Hash[h] = this._initState[h]; } result.Flags = SetType(BlockType.MSG); return(result); }
protected override byte[] FinalHash(SkeinState state) { var hashBytes = SKEIN_512_BLOCK_BYTES; if (this._bitLen == 384) { hashBytes -= 16; } var result = new byte[hashBytes]; int hashCount = hashBytes / 8; for (int h = 0; h < hashCount; h++) { var bytes = BitConverter.GetBytes(state.Hash[h]); Buffer.BlockCopy(bytes, 0, result, h << 3, 8); } return(result); }
protected abstract byte[] FinalHash(SkeinState state);
protected abstract void Compress(ref SkeinState State, byte[] buffer, UInt64 bitCount);