protected override bool VerifySignatureCore( ReadOnlySpan <byte> hash, ReadOnlySpan <byte> signature, DSASignatureFormat signatureFormat) { Span <byte> stackBuf = stackalloc byte[WindowsMaxQSize]; ReadOnlySpan <byte> source = AdjustHashSizeIfNecessary(hash, stackBuf); if (signatureFormat == DSASignatureFormat.Rfc3279DerSequence) { // source.Length is the field size, in bytes, so just convert to bits. int fieldSizeBits = source.Length * 8; signature = this.ConvertSignatureToIeeeP1363(signatureFormat, signature, fieldSizeBits); } else if (signatureFormat != DSASignatureFormat.IeeeP1363FixedFieldConcatenation) { Debug.Fail($"Missing internal implementation handler for signature format {signatureFormat}"); throw new CryptographicException( SR.Cryptography_UnknownSignatureFormat, signatureFormat.ToString()); } using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { unsafe { return(CngCommon.VerifyHash(keyHandle, source, signature, AsymmetricPaddingMode.None, null)); } } }
public override byte[] CreateSignature(byte[] rgbHash) { if (rgbHash == null) { throw new ArgumentNullException(nameof(rgbHash)); } ReadOnlySpan <byte> source = rgbHash; byte[] arrayToReturnToArrayPool = AdjustHashSizeIfNecessaryWithArrayPool(ref source); try { using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { unsafe { return(CngCommon.SignHash(keyHandle, source, AsymmetricPaddingMode.None, null, source.Length * 2)); } } } finally { if (arrayToReturnToArrayPool != null) { Array.Clear(arrayToReturnToArrayPool, 0, source.Length); ArrayPool <byte> .Shared.Return(arrayToReturnToArrayPool); } } }
public override unsafe bool TryCreateSignature(ReadOnlySpan <byte> hash, Span <byte> destination, out int bytesWritten) { Span <byte> stackBuf = stackalloc byte[WindowsMaxQSize]; ReadOnlySpan <byte> source = AdjustHashSizeIfNecessary(hash, stackBuf); using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { return(CngCommon.TrySignHash(keyHandle, source, destination, AsymmetricPaddingMode.None, null, out bytesWritten)); } }
public override bool VerifySignature(ReadOnlySpan <byte> hash, ReadOnlySpan <byte> signature) { Span <byte> stackBuf = stackalloc byte[WindowsMaxQSize]; ReadOnlySpan <byte> source = AdjustHashSizeIfNecessary(hash, stackBuf); #endif using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { unsafe { return(CngCommon.VerifyHash(keyHandle, source, signature, AsymmetricPaddingMode.None, null)); } } }
public override byte[] CreateSignature(byte[] rgbHash) { ArgumentNullException.ThrowIfNull(rgbHash); Span <byte> stackBuf = stackalloc byte[WindowsMaxQSize]; ReadOnlySpan <byte> source = AdjustHashSizeIfNecessary(rgbHash, stackBuf); using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { unsafe { return(CngCommon.SignHash(keyHandle, source, AsymmetricPaddingMode.None, null, source.Length * 2)); } } }
public override byte[] CreateSignature(byte[] hash) { if (hash == null) { throw new ArgumentNullException(nameof(hash)); } hash = AdjustHashSizeIfNecessary(hash); using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { unsafe { byte[] signature = CngCommon.SignHash(keyHandle, hash, AsymmetricPaddingMode.None, null, hash.Length * 2); return(signature); } } }
public override unsafe bool TryCreateSignature(ReadOnlySpan <byte> hash, Span <byte> destination, out int bytesWritten) { byte[] arrayToReturnToArrayPool = AdjustHashSizeIfNecessaryWithArrayPool(ref hash); try { using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { return(CngCommon.TrySignHash(keyHandle, hash, destination, AsymmetricPaddingMode.None, null, out bytesWritten)); } } finally { if (arrayToReturnToArrayPool != null) { Array.Clear(arrayToReturnToArrayPool, 0, hash.Length); ArrayPool <byte> .Shared.Return(arrayToReturnToArrayPool); } } }
public override bool VerifySignature(ReadOnlySpan <byte> hash, ReadOnlySpan <byte> signature) { byte[] arrayToReturnToArrayPool = AdjustHashSizeIfNecessaryWithArrayPool(ref hash); try { using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { unsafe { return(CngCommon.VerifyHash(keyHandle, hash, signature, AsymmetricPaddingMode.None, null)); } } } finally { if (arrayToReturnToArrayPool != null) { Array.Clear(arrayToReturnToArrayPool, 0, hash.Length); ArrayPool <byte> .Shared.Return(arrayToReturnToArrayPool); } } }
public override bool VerifySignature(byte[] hash, byte[] signature) { if (hash == null) { throw new ArgumentNullException(nameof(hash)); } if (signature == null) { throw new ArgumentNullException(nameof(signature)); } hash = AdjustHashSizeIfNecessary(hash); using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { unsafe { bool verified = CngCommon.VerifyHash(keyHandle, hash, signature, AsymmetricPaddingMode.None, null); return(verified); } } }
public override unsafe bool TryCreateSignature(ReadOnlySpan <byte> hash, Span <byte> destination, out int bytesWritten) #endif { Span <byte> stackBuf = stackalloc byte[WindowsMaxQSize]; ReadOnlySpan <byte> source = AdjustHashSizeIfNecessary(hash, stackBuf); using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle()) { if (!CngCommon.TrySignHash(keyHandle, source, destination, AsymmetricPaddingMode.None, null, out bytesWritten)) { bytesWritten = 0; return(false); } } #if INTERNAL_ASYMMETRIC_IMPLEMENTATIONS if (signatureFormat == DSASignatureFormat.IeeeP1363FixedFieldConcatenation) { return(true); } if (signatureFormat != DSASignatureFormat.Rfc3279DerSequence) { Debug.Fail($"Missing internal implementation handler for signature format {signatureFormat}"); throw new CryptographicException( SR.Cryptography_UnknownSignatureFormat, signatureFormat.ToString()); } return(AsymmetricAlgorithmHelpers.TryConvertIeee1363ToDer( destination.Slice(0, bytesWritten), destination, out bytesWritten)); #else return(true); #endif }
protected override bool TryHashData(ReadOnlySpan <byte> source, Span <byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten) => CngCommon.TryHashData(source, destination, hashAlgorithm, out bytesWritten);
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) => CngCommon.HashData(data, hashAlgorithm);
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) => CngCommon.HashData(data, offset, count, hashAlgorithm);