Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ static int GetDerLengthLength(int payloadLength)
}
}

#if INTERNAL_ASYMMETRIC_IMPLEMENTATIONS
/// <summary>
/// Converts IeeeP1363 format to the specified signature format
/// </summary>
Expand Down Expand Up @@ -182,7 +181,6 @@ internal static byte[] ConvertSignatureToIeeeP1363(
currentFormat.ToString());
}
}
#endif

public static int BitsToBytes(int bitLength)
{
Expand Down Expand Up @@ -214,7 +212,6 @@ private static void CopySignatureField(ReadOnlySpan<byte> signatureField, Span<b
signatureField.CopyTo(response.Slice(writeOffset));
}

#if INTERNAL_ASYMMETRIC_IMPLEMENTATIONS
internal static byte[]? ConvertSignatureToIeeeP1363(
this DSA dsa,
DSASignatureFormat currentFormat,
Expand Down Expand Up @@ -263,6 +260,5 @@ private static void CopySignatureField(ReadOnlySpan<byte> signatureField, Span<b
return null;
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal enum CryptCreateHashFlags : int
internal static partial bool CryptCreateHash(
SafeProvHandle hProv,
int Algid,
SafeKeyHandle hKey,
SafeCapiKeyHandle hKey,
CryptCreateHashFlags dwFlags,
out SafeHashHandle phHash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal enum CryptDecryptFlags : int

[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
public static partial bool CryptDecrypt(
SafeKeyHandle hKey,
SafeCapiKeyHandle hKey,
SafeHashHandle hHash,
bool Final,
int dwFlags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ internal static partial bool CryptDeriveKey(
int Algid,
SafeHashHandle hBaseData,
int dwFlags,
out SafeKeyHandle phKey);
out SafeCapiKeyHandle phKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static partial class Advapi32
{
[GeneratedDllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public static partial bool CryptEncrypt(
SafeKeyHandle hKey,
SafeCapiKeyHandle hKey,
SafeHashHandle hHash,
bool Final,
int dwFlags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal static partial class Advapi32
{
[GeneratedDllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public static partial bool CryptExportKey(
SafeKeyHandle hKey,
SafeKeyHandle hExpKey,
SafeCapiKeyHandle hKey,
SafeCapiKeyHandle hExpKey,
int dwBlobType,
int dwFlags,
byte[]? pbData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal static partial class Interop
internal static partial class Advapi32
{
[GeneratedDllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
internal static partial bool CryptGenKey(SafeProvHandle hProv, int Algid, int dwFlags, out SafeKeyHandle phKey);
internal static partial bool CryptGenKey(SafeProvHandle hProv, int Algid, int dwFlags, out SafeCapiKeyHandle phKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal enum CryptGetKeyParamFlags : int

[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
public static partial bool CryptGetKeyParam(
SafeKeyHandle hKey,
SafeCapiKeyHandle hKey,
CryptGetKeyParamFlags dwParam,
byte[]? pbData,
ref int pdwDataLen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal static partial class Interop
internal static partial class Advapi32
{
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
internal static partial bool CryptGetUserKey(SafeProvHandle hProv, int dwKeySpec, out SafeKeyHandle phUserKey);
internal static partial bool CryptGetUserKey(SafeProvHandle hProv, int dwKeySpec, out SafeCapiKeyHandle phUserKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ internal static unsafe partial bool CryptImportKey(
SafeProvHandle hProv,
byte* pbData,
int dwDataLen,
SafeKeyHandle hPubKey,
SafeCapiKeyHandle hPubKey,
int dwFlags,
out SafeKeyHandle phKey);
out SafeCapiKeyHandle phKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ internal static partial class Interop
internal static partial class Advapi32
{
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
public static partial bool CryptSetKeyParam(SafeKeyHandle hKey, int dwParam, byte[] pbData, int dwFlags);
public static partial bool CryptSetKeyParam(SafeCapiKeyHandle hKey, int dwParam, byte[] pbData, int dwFlags);

[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
public static partial bool CryptSetKeyParam(SafeKeyHandle safeKeyHandle, int dwParam, ref int pdw, int dwFlags);
public static partial bool CryptSetKeyParam(SafeCapiKeyHandle safeKeyHandle, int dwParam, ref int pdw, int dwFlags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static partial bool CryptVerifySignature(
SafeHashHandle hHash,
byte[] pbSignature,
int dwSigLen,
SafeKeyHandle hPubKey,
SafeCapiKeyHandle hPubKey,
string? szDescription,
CryptSignAndVerifyHashFlags dwFlags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ namespace System.Security.Cryptography
/// of the key handle and provider handle. This also applies to hash handles, which point to a
/// CRYPT_HASH_CTX. Those structures are defined in COMCryptography.h
/// </summary>
internal sealed class SafeKeyHandle : SafeHandleZeroOrMinusOneIsInvalid
internal sealed class SafeCapiKeyHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private int _keySpec;
private bool _fPublicOnly;
private SafeProvHandle? _parent;

public SafeKeyHandle() : base(true)
public SafeCapiKeyHandle() : base(true)
{
SetHandle(IntPtr.Zero);
_keySpec = 0;
Expand Down Expand Up @@ -70,14 +70,14 @@ internal void SetParent(SafeProvHandle parent)
_parent.DangerousAddRef(ref ignored);
}

internal static SafeKeyHandle InvalidHandle
internal static SafeCapiKeyHandle InvalidHandle
{
get { return SafeHandleCache<SafeKeyHandle>.GetInvalidHandle(() => new SafeKeyHandle()); }
get { return SafeHandleCache<SafeCapiKeyHandle>.GetInvalidHandle(() => new SafeCapiKeyHandle()); }
}

protected override void Dispose(bool disposing)
{
if (!SafeHandleCache<SafeKeyHandle>.IsCachedInvalidHandle(this))
if (!SafeHandleCache<SafeCapiKeyHandle>.IsCachedInvalidHandle(this))
{
base.Dispose(disposing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static unsafe SafeKeyHandle BCryptImportKey(SafeAlgorithmHandle hAlg, R
}

[StructLayout(LayoutKind.Sequential)]
private struct BCRYPT_KEY_DATA_BLOB_HEADER
internal struct BCRYPT_KEY_DATA_BLOB_HEADER
{
public uint dwMagic;
public uint dwVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ internal static partial class Interop
{
internal static partial class NCrypt
{
internal const string NCRYPT_CIPHER_KEY_BLOB = "CipherKeyBlob";
internal const string NCRYPT_PKCS8_PRIVATE_KEY_BLOB = "PKCS8_PRIVATEKEY";

internal const int NCRYPT_CIPHER_KEY_BLOB_MAGIC = 0x52485043; //'CPHR'

[GeneratedDllImport(Interop.Libraries.NCrypt, CharSet = CharSet.Unicode)]
internal static partial ErrorCode NCryptOpenKey(SafeNCryptProviderHandle hProvider, out SafeNCryptKeyHandle phKey, string pszKeyName, int dwLegacyKeySpec, CngKeyOpenOptions dwFlags);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.Cryptography.Pal;
using System.Security.Cryptography.X509Certificates;

namespace Microsoft.Win32.SafeHandles
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ internal Asn1Tag PeekTag()
return Asn1Tag.Decode(_span, out _);
}

internal ReadOnlySpan<byte> PeekContentBytes()
{
AsnDecoder.ReadEncodedValue(
_span,
_ruleSet,
out int contentOffset,
out int contentLength,
out _);

return _span.Slice(contentOffset, contentLength);
}

internal ReadOnlySpan<byte> PeekEncodedValue()
{
AsnDecoder.ReadEncodedValue(_span, _ruleSet, out _, out _, out int consumed);
Expand Down
Loading