protected static Xor ( byte block, byte val ) : void | ||
block | byte | |
val | byte | |
Résultat | void |
protected virtual void UpdateHASH(byte[] LSub) { OcbBlockCipher.Xor(this.OffsetHASH, LSub); OcbBlockCipher.Xor(this.hashBlock, this.OffsetHASH); this.hashCipher.ProcessBlock(this.hashBlock, 0, this.hashBlock, 0); OcbBlockCipher.Xor(this.Sum, this.hashBlock); }
public virtual int DoFinal(byte[] output, int outOff) { byte[] array = null; if (!this.forEncryption) { if (this.mainBlockPos < this.macSize) { throw new InvalidCipherTextException("data too short"); } this.mainBlockPos -= this.macSize; array = new byte[this.macSize]; Array.Copy(this.mainBlock, this.mainBlockPos, array, 0, this.macSize); } if (this.hashBlockPos > 0) { OcbBlockCipher.OCB_extend(this.hashBlock, this.hashBlockPos); this.UpdateHASH(this.L_Asterisk); } if (this.mainBlockPos > 0) { if (this.forEncryption) { OcbBlockCipher.OCB_extend(this.mainBlock, this.mainBlockPos); OcbBlockCipher.Xor(this.Checksum, this.mainBlock); } OcbBlockCipher.Xor(this.OffsetMAIN, this.L_Asterisk); byte[] array2 = new byte[16]; this.hashCipher.ProcessBlock(this.OffsetMAIN, 0, array2, 0); OcbBlockCipher.Xor(this.mainBlock, array2); Check.OutputLength(output, outOff, this.mainBlockPos, "Output buffer too short"); Array.Copy(this.mainBlock, 0, output, outOff, this.mainBlockPos); if (!this.forEncryption) { OcbBlockCipher.OCB_extend(this.mainBlock, this.mainBlockPos); OcbBlockCipher.Xor(this.Checksum, this.mainBlock); } } OcbBlockCipher.Xor(this.Checksum, this.OffsetMAIN); OcbBlockCipher.Xor(this.Checksum, this.L_Dollar); this.hashCipher.ProcessBlock(this.Checksum, 0, this.Checksum, 0); OcbBlockCipher.Xor(this.Checksum, this.Sum); this.macBlock = new byte[this.macSize]; Array.Copy(this.Checksum, 0, this.macBlock, 0, this.macSize); int num = this.mainBlockPos; if (this.forEncryption) { Check.OutputLength(output, outOff, num + this.macSize, "Output buffer too short"); Array.Copy(this.macBlock, 0, output, outOff + num, this.macSize); num += this.macSize; } else if (!Arrays.ConstantTimeAreEqual(this.macBlock, array)) { throw new InvalidCipherTextException("mac check in OCB failed"); } this.Reset(false); return(num); }
protected virtual void ProcessMainBlock(byte[] output, int outOff) { Check.DataLength(output, outOff, 16, "Output buffer too short"); if (this.forEncryption) { OcbBlockCipher.Xor(this.Checksum, this.mainBlock); this.mainBlockPos = 0; } OcbBlockCipher.Xor(this.OffsetMAIN, this.GetLSub(OcbBlockCipher.OCB_ntz(this.mainBlockCount += 1L))); OcbBlockCipher.Xor(this.mainBlock, this.OffsetMAIN); this.mainCipher.ProcessBlock(this.mainBlock, 0, this.mainBlock, 0); OcbBlockCipher.Xor(this.mainBlock, this.OffsetMAIN); Array.Copy(this.mainBlock, 0, output, outOff, 16); if (!this.forEncryption) { OcbBlockCipher.Xor(this.Checksum, this.mainBlock); Array.Copy(this.mainBlock, 16, this.mainBlock, 0, this.macSize); this.mainBlockPos = this.macSize; } }