public Iso9796d2Signer(IAsymmetricBlockCipher cipher, IDigest digest, bool isImplicit) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) this.cipher = cipher; this.digest = digest; if (isImplicit) { trailer = 188; return; } if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("no valid trailer", "digest"); } trailer = IsoTrailers.GetTrailer(digest); }
public Iso9796d2Signer(IAsymmetricBlockCipher cipher, IDigest digest, bool isImplicit) { this.cipher = cipher; this.digest = digest; if (isImplicit) { this.trailer = 0xbc; } else { if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("no valid trailer", "digest"); } this.trailer = IsoTrailers.GetTrailer(digest); } }
/** * Generate a signer with either implicit or explicit trailers for X9.31. * * @param cipher base cipher to use for signature creation/verification * @param digest digest to use. * @param implicit whether or not the trailer is implicit or gives the hash. */ public X931Signer(IAsymmetricBlockCipher cipher, IDigest digest, bool isImplicit) { this.cipher = cipher; this.digest = digest; if (isImplicit) { trailer = IsoTrailers.TRAILER_IMPLICIT; } else if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("no valid trailer", "digest"); } else { trailer = IsoTrailers.GetTrailer(digest); } }
/// <summary> /// Generate a signer with either implicit or explicit trailers for ISO9796-2, scheme 2 or 3. /// </summary> /// <param name="cipher">base cipher to use for signature creation/verification</param> /// <param name="digest">digest to use.</param> /// <param name="saltLength">length of salt in bytes.</param> /// <param name="isImplicit">whether or not the trailer is implicit or gives the hash.</param> public Iso9796d2PssSigner( IAsymmetricBlockCipher cipher, IDigest digest, int saltLength, bool isImplicit) { this.cipher = cipher; this.digest = digest; this.hLen = digest.GetDigestSize(); this.saltLength = saltLength; if (isImplicit) { trailer = IsoTrailers.TRAILER_IMPLICIT; } else if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("no valid trailer", "digest"); } else { trailer = IsoTrailers.GetTrailer(digest); } }
public virtual void UpdateWithRecoveredMessage( byte[] signature) { byte[] block = cipher.ProcessBlock(signature, 0, signature.Length); // // adjust block size for leading zeroes if necessary // if (block.Length < (keyBits + 7) / 8) { byte[] tmp = new byte[(keyBits + 7) / 8]; Array.Copy(block, 0, tmp, tmp.Length - block.Length, block.Length); ClearBlock(block); block = tmp; } int tLength; if (((block[block.Length - 1] & 0xFF) ^ 0xBC) == 0) { tLength = 1; } else { int sigTrail = ((block[block.Length - 2] & 0xFF) << 8) | (block[block.Length - 1] & 0xFF); if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (sigTrail != IsoTrailers.GetTrailer(digest)) { throw new InvalidOperationException("signer initialised with wrong digest for trailer " + sigTrail); } tLength = 2; } // // calculate H(m2) // byte[] m2Hash = new byte[hLen]; digest.DoFinal(m2Hash, 0); // // remove the mask // byte[] dbMask = MaskGeneratorFunction1(block, block.Length - hLen - tLength, hLen, block.Length - hLen - tLength); for (int i = 0; i != dbMask.Length; i++) { block[i] ^= dbMask[i]; } block[0] &= 0x7f; // // find out how much padding we've got // int mStart = 0; while (mStart < block.Length) { if (block[mStart++] == 0x01) { break; } } if (mStart >= block.Length) { ClearBlock(block); } fullMessage = (mStart > 1); recoveredMessage = new byte[dbMask.Length - mStart - saltLength]; Array.Copy(block, mStart, recoveredMessage, 0, recoveredMessage.Length); recoveredMessage.CopyTo(mBuf, 0); preSig = signature; preBlock = block; preMStart = mStart; preTLength = tLength; }
public virtual bool VerifySignature(byte[] signature) { byte[] preBlock; if (this.preSig == null) { try { preBlock = this.cipher.ProcessBlock(signature, 0, signature.Length); } catch (Exception) { return(false); } } else { if (!Arrays.AreEqual(this.preSig, signature)) { throw new InvalidOperationException("updateWithRecoveredMessage called on different signature"); } preBlock = this.preBlock; this.preSig = null; this.preBlock = null; } if (((preBlock[0] & 0xc0) ^ 0x40) != 0) { return(this.ReturnFalse(preBlock)); } if (((preBlock[preBlock.Length - 1] & 15) ^ 12) != 0) { return(this.ReturnFalse(preBlock)); } int num = 0; if (((preBlock[preBlock.Length - 1] & 0xff) ^ 0xbc) == 0) { num = 1; } else { int num2 = ((preBlock[preBlock.Length - 2] & 0xff) << 8) | (preBlock[preBlock.Length - 1] & 0xff); if (IsoTrailers.NoTrailerAvailable(this.digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (num2 != IsoTrailers.GetTrailer(this.digest)) { throw new InvalidOperationException("signer initialised with wrong digest for trailer " + num2); } num = 2; } int index = 0; while (index != preBlock.Length) { if (((preBlock[index] & 15) ^ 10) == 0) { break; } index++; } index++; byte[] output = new byte[this.digest.GetDigestSize()]; int num4 = (preBlock.Length - num) - output.Length; if ((num4 - index) <= 0) { return(this.ReturnFalse(preBlock)); } if ((preBlock[0] & 0x20) == 0) { this.fullMessage = true; if (this.messageLength > (num4 - index)) { return(this.ReturnFalse(preBlock)); } this.digest.Reset(); this.digest.BlockUpdate(preBlock, index, num4 - index); this.digest.DoFinal(output, 0); bool flag2 = true; for (int i = 0; i != output.Length; i++) { preBlock[num4 + i] = (byte)(preBlock[num4 + i] ^ output[i]); if (preBlock[num4 + i] != 0) { flag2 = false; } } if (!flag2) { return(this.ReturnFalse(preBlock)); } this.recoveredMessage = new byte[num4 - index]; Array.Copy(preBlock, index, this.recoveredMessage, 0, this.recoveredMessage.Length); } else { this.fullMessage = false; this.digest.DoFinal(output, 0); bool flag3 = true; for (int i = 0; i != output.Length; i++) { preBlock[num4 + i] = (byte)(preBlock[num4 + i] ^ output[i]); if (preBlock[num4 + i] != 0) { flag3 = false; } } if (!flag3) { return(this.ReturnFalse(preBlock)); } this.recoveredMessage = new byte[num4 - index]; Array.Copy(preBlock, index, this.recoveredMessage, 0, this.recoveredMessage.Length); } if ((this.messageLength != 0) && !this.IsSameAs(this.mBuf, this.recoveredMessage)) { return(this.ReturnFalse(preBlock)); } this.ClearBlock(this.mBuf); this.ClearBlock(preBlock); return(true); }
public virtual void UpdateWithRecoveredMessage(byte[] signature) { byte[] sourceArray = this.cipher.ProcessBlock(signature, 0, signature.Length); if (((sourceArray[0] & 0xc0) ^ 0x40) != 0) { throw new InvalidCipherTextException("malformed signature"); } if (((sourceArray[sourceArray.Length - 1] & 15) ^ 12) != 0) { throw new InvalidCipherTextException("malformed signature"); } int num = 0; if (((sourceArray[sourceArray.Length - 1] & 0xff) ^ 0xbc) == 0) { num = 1; } else { int num2 = ((sourceArray[sourceArray.Length - 2] & 0xff) << 8) | (sourceArray[sourceArray.Length - 1] & 0xff); if (IsoTrailers.NoTrailerAvailable(this.digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (num2 != IsoTrailers.GetTrailer(this.digest)) { throw new InvalidOperationException("signer initialised with wrong digest for trailer " + num2); } num = 2; } int index = 0; index = 0; while (index != sourceArray.Length) { if (((sourceArray[index] & 15) ^ 10) == 0) { break; } index++; } index++; int num4 = (sourceArray.Length - num) - this.digest.GetDigestSize(); if ((num4 - index) <= 0) { throw new InvalidCipherTextException("malformed block"); } if ((sourceArray[0] & 0x20) == 0) { this.fullMessage = true; this.recoveredMessage = new byte[num4 - index]; Array.Copy(sourceArray, index, this.recoveredMessage, 0, this.recoveredMessage.Length); } else { this.fullMessage = false; this.recoveredMessage = new byte[num4 - index]; Array.Copy(sourceArray, index, this.recoveredMessage, 0, this.recoveredMessage.Length); } this.preSig = signature; this.preBlock = sourceArray; this.digest.BlockUpdate(this.recoveredMessage, 0, this.recoveredMessage.Length); this.messageLength = this.recoveredMessage.Length; this.recoveredMessage.CopyTo(this.mBuf, 0); }
public virtual void UpdateWithRecoveredMessage(byte[] signature) { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) byte[] array = cipher.ProcessBlock(signature, 0, signature.Length); if (array.Length < (keyBits + 7) / 8) { byte[] array2 = new byte[(keyBits + 7) / 8]; global::System.Array.Copy((global::System.Array)array, 0, (global::System.Array)array2, array2.Length - array.Length, array.Length); ClearBlock(array); array = array2; } int num; if (((array[array.Length - 1] & 0xFF) ^ 0xBC) == 0) { num = 1; } else { int num2 = ((array[array.Length - 2] & 0xFF) << 8) | (array[array.Length - 1] & 0xFF); if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (num2 != IsoTrailers.GetTrailer(digest)) { throw new InvalidOperationException(string.Concat((object)"signer initialised with wrong digest for trailer ", (object)num2)); } num = 2; } byte[] output = new byte[hLen]; digest.DoFinal(output, 0); byte[] array3 = MaskGeneratorFunction1(array, array.Length - hLen - num, hLen, array.Length - hLen - num); byte[] array4; for (int i = 0; i != array3.Length; i++) { byte[] array5 = (array4 = array); int num3 = i; global::System.IntPtr intPtr = (global::System.IntPtr)num3; array5[num3] = (byte)(array4[(long)intPtr] ^ array3[i]); } (array4 = array)[0] = (byte)(array4[0] & 0x7Fu); int num4 = 0; while (num4 < array.Length && array[num4++] != 1) { } if (num4 >= array.Length) { ClearBlock(array); } fullMessage = num4 > 1; recoveredMessage = new byte[array3.Length - num4 - saltLength]; global::System.Array.Copy((global::System.Array)array, num4, (global::System.Array)recoveredMessage, 0, recoveredMessage.Length); ((global::System.Array)recoveredMessage).CopyTo((global::System.Array)mBuf, 0); preSig = signature; preBlock = array; preMStart = num4; preTLength = num; }
/// <summary> return true if the signature represents a ISO9796-2 signature /// for the passed in message. /// </summary> public virtual bool VerifySignature(byte[] signature) { byte[] block; if (preSig == null) { try { block = cipher.ProcessBlock(signature, 0, signature.Length); } catch (Exception) { return(false); } } else { if (!Arrays.AreEqual(preSig, signature)) { throw new InvalidOperationException("updateWithRecoveredMessage called on different signature"); } block = preBlock; preSig = null; preBlock = null; } if (((block[0] & 0xC0) ^ 0x40) != 0) { return(ReturnFalse(block)); } if (((block[block.Length - 1] & 0xF) ^ 0xC) != 0) { return(ReturnFalse(block)); } int delta = 0; if (((block[block.Length - 1] & 0xFF) ^ 0xBC) == 0) { delta = 1; } else { int sigTrail = ((block[block.Length - 2] & 0xFF) << 8) | (block[block.Length - 1] & 0xFF); if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (sigTrail != IsoTrailers.GetTrailer(digest)) { throw new InvalidOperationException("signer initialised with wrong digest for trailer " + sigTrail); } delta = 2; } // // find out how much padding we've got // int mStart = 0; for (; mStart != block.Length; mStart++) { if (((block[mStart] & 0x0f) ^ 0x0a) == 0) { break; } } mStart++; // // check the hashes // byte[] hash = new byte[digest.GetDigestSize()]; int off = block.Length - delta - hash.Length; // // there must be at least one byte of message string // if ((off - mStart) <= 0) { return(ReturnFalse(block)); } // // if we contain the whole message as well, check the hash of that. // if ((block[0] & 0x20) == 0) { fullMessage = true; // check right number of bytes passed in. if (messageLength > off - mStart) { return(ReturnFalse(block)); } digest.Reset(); digest.BlockUpdate(block, mStart, off - mStart); digest.DoFinal(hash, 0); bool isOkay = true; for (int i = 0; i != hash.Length; i++) { block[off + i] ^= hash[i]; if (block[off + i] != 0) { isOkay = false; } } if (!isOkay) { return(ReturnFalse(block)); } recoveredMessage = new byte[off - mStart]; Array.Copy(block, mStart, recoveredMessage, 0, recoveredMessage.Length); } else { fullMessage = false; digest.DoFinal(hash, 0); bool isOkay = true; for (int i = 0; i != hash.Length; i++) { block[off + i] ^= hash[i]; if (block[off + i] != 0) { isOkay = false; } } if (!isOkay) { return(ReturnFalse(block)); } recoveredMessage = new byte[off - mStart]; Array.Copy(block, mStart, recoveredMessage, 0, recoveredMessage.Length); } // // if they've input a message check what we've recovered against // what was input. // if (messageLength != 0) { if (!IsSameAs(mBuf, recoveredMessage)) { return(ReturnFalse(block)); } } ClearBlock(mBuf); ClearBlock(block); messageLength = 0; return(true); }
public virtual void UpdateWithRecoveredMessage( byte[] signature) { byte[] block = cipher.ProcessBlock(signature, 0, signature.Length); if (((block[0] & 0xC0) ^ 0x40) != 0) { throw new InvalidCipherTextException("malformed signature"); } if (((block[block.Length - 1] & 0xF) ^ 0xC) != 0) { throw new InvalidCipherTextException("malformed signature"); } int delta = 0; if (((block[block.Length - 1] & 0xFF) ^ 0xBC) == 0) { delta = 1; } else { int sigTrail = ((block[block.Length - 2] & 0xFF) << 8) | (block[block.Length - 1] & 0xFF); if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (sigTrail != IsoTrailers.GetTrailer(digest)) { throw new InvalidOperationException("signer initialised with wrong digest for trailer " + sigTrail); } delta = 2; } // // find out how much padding we've got // int mStart = 0; for (mStart = 0; mStart != block.Length; mStart++) { if (((block[mStart] & 0x0f) ^ 0x0a) == 0) { break; } } mStart++; int off = block.Length - delta - digest.GetDigestSize(); // // there must be at least one byte of message string // if ((off - mStart) <= 0) { throw new InvalidCipherTextException("malformed block"); } // // if we contain the whole message as well, check the hash of that. // if ((block[0] & 0x20) == 0) { fullMessage = true; recoveredMessage = new byte[off - mStart]; Array.Copy(block, mStart, recoveredMessage, 0, recoveredMessage.Length); } else { fullMessage = false; recoveredMessage = new byte[off - mStart]; Array.Copy(block, mStart, recoveredMessage, 0, recoveredMessage.Length); } preSig = signature; preBlock = block; digest.BlockUpdate(recoveredMessage, 0, recoveredMessage.Length); messageLength = recoveredMessage.Length; recoveredMessage.CopyTo(mBuf, 0); }
public virtual bool VerifySignature(byte[] signature) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) byte[] array; if (preSig == null) { try { array = cipher.ProcessBlock(signature, 0, signature.Length); } catch (global::System.Exception) { return(false); } } else { if (!Arrays.AreEqual(preSig, signature)) { throw new InvalidOperationException("updateWithRecoveredMessage called on different signature"); } array = preBlock; preSig = null; preBlock = null; } if (((array[0] & 0xC0u) ^ 0x40u) != 0) { return(ReturnFalse(array)); } if (((array[array.Length - 1] & 0xFu) ^ 0xCu) != 0) { return(ReturnFalse(array)); } int num = 0; if (((array[array.Length - 1] & 0xFF) ^ 0xBC) == 0) { num = 1; } else { int num2 = ((array[array.Length - 2] & 0xFF) << 8) | (array[array.Length - 1] & 0xFF); if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (num2 != IsoTrailers.GetTrailer(digest)) { throw new InvalidOperationException(string.Concat((object)"signer initialised with wrong digest for trailer ", (object)num2)); } num = 2; } int i; for (i = 0; i != array.Length && ((array[i] & 0xFu) ^ 0xAu) != 0; i++) { } i++; byte[] array2 = new byte[digest.GetDigestSize()]; int num3 = array.Length - num - array2.Length; if (num3 - i <= 0) { return(ReturnFalse(array)); } if ((array[0] & 0x20) == 0) { fullMessage = true; if (messageLength > num3 - i) { return(ReturnFalse(array)); } digest.Reset(); digest.BlockUpdate(array, i, num3 - i); digest.DoFinal(array2, 0); bool flag = true; for (int j = 0; j != array2.Length; j++) { byte[] array3; byte[] array4 = (array3 = array); int num4 = num3 + j; global::System.IntPtr intPtr = (global::System.IntPtr)num4; array4[num4] = (byte)(array3[(long)intPtr] ^ array2[j]); if (array[num3 + j] != 0) { flag = false; } } if (!flag) { return(ReturnFalse(array)); } recoveredMessage = new byte[num3 - i]; global::System.Array.Copy((global::System.Array)array, i, (global::System.Array)recoveredMessage, 0, recoveredMessage.Length); } else { fullMessage = false; digest.DoFinal(array2, 0); bool flag2 = true; for (int k = 0; k != array2.Length; k++) { byte[] array3; byte[] array5 = (array3 = array); int num5 = num3 + k; global::System.IntPtr intPtr = (global::System.IntPtr)num5; array5[num5] = (byte)(array3[(long)intPtr] ^ array2[k]); if (array[num3 + k] != 0) { flag2 = false; } } if (!flag2) { return(ReturnFalse(array)); } recoveredMessage = new byte[num3 - i]; global::System.Array.Copy((global::System.Array)array, i, (global::System.Array)recoveredMessage, 0, recoveredMessage.Length); } if (messageLength != 0 && !IsSameAs(mBuf, recoveredMessage)) { return(ReturnFalse(array)); } ClearBlock(mBuf); ClearBlock(array); return(true); }
public virtual void UpdateWithRecoveredMessage(byte[] signature) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) byte[] array = cipher.ProcessBlock(signature, 0, signature.Length); if (((array[0] & 0xC0u) ^ 0x40u) != 0) { throw new InvalidCipherTextException("malformed signature"); } if (((array[array.Length - 1] & 0xFu) ^ 0xCu) != 0) { throw new InvalidCipherTextException("malformed signature"); } int num = 0; if (((array[array.Length - 1] & 0xFF) ^ 0xBC) == 0) { num = 1; } else { int num2 = ((array[array.Length - 2] & 0xFF) << 8) | (array[array.Length - 1] & 0xFF); if (IsoTrailers.NoTrailerAvailable(digest)) { throw new ArgumentException("unrecognised hash in signature"); } if (num2 != IsoTrailers.GetTrailer(digest)) { throw new InvalidOperationException(string.Concat((object)"signer initialised with wrong digest for trailer ", (object)num2)); } num = 2; } int num3 = 0; for (num3 = 0; num3 != array.Length && ((array[num3] & 0xFu) ^ 0xAu) != 0; num3++) { } num3++; int num4 = array.Length - num - digest.GetDigestSize(); if (num4 - num3 <= 0) { throw new InvalidCipherTextException("malformed block"); } if ((array[0] & 0x20) == 0) { fullMessage = true; recoveredMessage = new byte[num4 - num3]; global::System.Array.Copy((global::System.Array)array, num3, (global::System.Array)recoveredMessage, 0, recoveredMessage.Length); } else { fullMessage = false; recoveredMessage = new byte[num4 - num3]; global::System.Array.Copy((global::System.Array)array, num3, (global::System.Array)recoveredMessage, 0, recoveredMessage.Length); } preSig = signature; preBlock = array; digest.BlockUpdate(recoveredMessage, 0, recoveredMessage.Length); messageLength = recoveredMessage.Length; ((global::System.Array)recoveredMessage).CopyTo((global::System.Array)mBuf, 0); }