void CopyBlock(byte[] inputBuffer, int inputOffset) { int remaining_bytes = inputBuffer.Length - inputOffset; int input_count = System.Math.Min(BlockSize, remaining_bytes); if (input_count != BlockSize) { Array.Clear(mX, 0, mX.Length); } Bits.ArrayCopy(inputBuffer, inputOffset, mX, 0, input_count); }
protected override byte[] ProcessFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount) { // it's okay to modify inputBuffer here since it's the final block and it's actually BlockHashAlgorithm's internal buffer ulong msg_bit_length = ((ulong)TotalBytesProcessed + (ulong)inputCount) << 3; if (inputOffset > 0 && inputCount > 0) { // memmove the bytes starting at inputOffset to the start of the buffer Array.Copy(inputBuffer, inputOffset, inputBuffer, 0, inputCount); } inputOffset = 0; Array.Clear(inputBuffer, inputCount, BlockSize - inputCount); // write the padding byte then align up to the next word boundary (proceeding bytes are already zero due to above Clear) int input_offset = inputCount; inputBuffer[input_offset++] = (byte)Version; // padding byte input_offset = IntegerMath.Align(IntegerMath.kInt64AlignmentBit, input_offset); // if we don't have enough space to encode the length, process what we have now as a block. // remaining bytes are still all zero, due to above Clear. if (input_offset > (BlockSize - sizeof(ulong))) { ProcessBlock(inputBuffer, inputOffset, 1); input_offset = 0; Array.Clear(inputBuffer, 0, BlockSize); } // write out the number of bytes that were processed before finalization for (input_offset = BlockSize - sizeof(ulong) ; msg_bit_length != 0 ; inputBuffer[input_offset] = (byte)msg_bit_length, msg_bit_length >>= 8, ++input_offset) { } ProcessBlock(inputBuffer, inputOffset, 1); if (HashValue == null) { HashValue = new byte[HashSizeValue / kWordCount]; } Bits.ArrayCopy(mRegs, 0, HashValue, 0, mRegs.Length); return(HashValue); }
public bool TryGetAsTiger192(byte[] buffer, int offset = 0) { if (buffer == null) { return(false); } if ((buffer.Length - offset) < (kHashSize / Bits.kByteBitCount)) { return(false); } // This would only ever happen if Initialize wasn't called if (mRegs != null && mRegs.Length >= 3) { Bits.ArrayCopy(mRegs, 0, buffer, offset, mRegs.Length); return(true); } return(false); }