public override sealed void Initialize() { for (int i = 0; i < state.Length; i++) { state[i] = Configuration.ConfigValue[i]; } UbiParameters.StartNewBlockType(UbiType.Message); bytesFilled = 0; }
public void Init(byte[] key) { // Copy the configuration value to the state for (int i = 0; i < _state.Length; i++) { _state[i] = Configuration.ConfigValue[i]; } // Set up tweak for message block UbiParameters.StartNewBlockType(UbiType.Message); // Reset bytes filled _bytesFilled = 0; }
protected override byte[] HashFinal() { // special case for empty MAC key if (UbiParameters.BlockType == UbiType.Key && bytesFilled == 0) { return(null); } // Pad left over space in input buffer with zeros and copy to cipher input buffer for (int i = bytesFilled; i < inputBuffer.Length; i++) { inputBuffer[i] = 0; } InputBufferToCipherInput(); UbiParameters.IsFinalBlock = true; ProcessBlock(bytesFilled); for (int i = 0; i < cipherInput.Length; i++) { cipherInput[i] = 0; } // Do output block counter mode output var hash = new byte[outputBytes]; var oldState = new ulong[cipherStateWords]; for (int j = 0; j < state.Length; j++) { oldState[j] = state[j]; } for (int i = 0; i < outputBytes; i += cipherStateBytes) { UbiParameters.StartNewBlockType(UbiType.Out); UbiParameters.IsFinalBlock = true; ProcessBlock(8); // Output a chunk of the hash int outputSize = outputBytes - i; if (outputSize > cipherStateBytes) { outputSize = cipherStateBytes; } PutBytes(state, hash, i, outputSize); for (int j = 0; j < state.Length; j++) { state[j] = oldState[j]; } cipherInput[0]++; } return(hash); }
public int DoFinal(byte[] output, int outOff) { int i; // Pad left over space in input buffer with zeros // and copy to cipher input buffer for (i = _bytesFilled; i < _inputBuffer.Length; i++) { _inputBuffer[i] = 0; } InputBufferToCipherInput(); // Do final message block UbiParameters.IsFinalBlock = true; ProcessBlock(_bytesFilled); // Clear cipher input for (i = 0; i < _cipherInput.Length; i++) { _cipherInput[i] = 0; } // Do output block counter mode output int j; //var hash = new byte[_outputBytes]; var oldState = new ulong[_cipherStateWords]; // Save old state for (j = 0; j < _state.Length; j++) { oldState[j] = _state[j]; } for (i = 0; i < _outputBytes; i += _cipherStateBytes) { UbiParameters.StartNewBlockType(UbiType.Out); UbiParameters.IsFinalBlock = true; ProcessBlock(8); // Output a chunk of the hash int outputSize = _outputBytes - i; if (outputSize > _cipherStateBytes) { outputSize = _cipherStateBytes; } PutBytes(_state, output, outOff + i, outputSize); // Restore old state for (j = 0; j < _state.Length; j++) { _state[j] = oldState[j]; } // Increment counter _cipherInput[0]++; } //return hash; return(_outputBytes); }