Skip to content

Commit 66b1fb1

Browse files
authored
Performance | Use lower-allocation AlwaysEncrypted primitives (#3612)
1 parent 33a8d53 commit 66b1fb1

File tree

10 files changed

+268
-848
lines changed

10 files changed

+268
-848
lines changed

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@
999999
<Compile Include="$(CommonSourceRoot)System\Buffers\ArrayBufferWriter.netfx.cs">
10001000
<Link>System\Buffers\ArrayBufferWriter.netfx.cs</Link>
10011001
</Compile>
1002+
<Compile Include="$(CommonSourceRoot)System\Diagnostics\CodeAnalysis.cs">
1003+
<Link>System\Diagnostics\CodeAnalysis.cs</Link>
1004+
</Compile>
10021005
<Compile Include="$(CommonSourceRoot)System\IO\StreamExtensions.netfx.cs">
10031006
<Link>System\IO\StreamExtensions.netfx.cs</Link>
10041007
</Compile>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.Windows.cs

Lines changed: 118 additions & 310 deletions
Large diffs are not rendered by default.

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.netcore.Unix.cs

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,14 @@
66

77
using System;
88

9+
#nullable enable
10+
911
namespace Microsoft.Data.SqlClient
1012
{
11-
/// <summary>
12-
/// Provides implementation similar to certificate store provider.
13-
/// A CEK encrypted with certificate provider should be decryptable by this provider and vice versa.
14-
///
15-
/// Envolope Format for the encrypted column encryption key
16-
/// version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature
17-
/// version: A single byte indicating the format version.
18-
/// keyPathLength: Length of the keyPath.
19-
/// ciphertextLength: ciphertext length
20-
/// keyPath: keyPath used to encrypt the column encryption key. This is only used for troubleshooting purposes and is not verified during decryption.
21-
/// ciphertext: Encrypted column encryption key
22-
/// signature: Signature of the entire byte array. Signature is validated before decrypting the column encryption key.
23-
/// </summary>
13+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml' path='docs/members[@name="SqlColumnEncryptionCngProvider"]/SqlColumnEncryptionCngProvider/*' />
2414
public class SqlColumnEncryptionCngProvider : SqlColumnEncryptionKeyStoreProvider
2515
{
26-
/// <summary>
27-
/// Name for the CNG key store provider.
28-
/// </summary>
16+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml' path='docs/members[@name="SqlColumnEncryptionCngProvider"]/ProviderName/*' />
2917
public const string ProviderName = @"MSSQL_CNG_STORE";
3018

3119
/// <summary>
@@ -38,51 +26,26 @@ public class SqlColumnEncryptionCngProvider : SqlColumnEncryptionKeyStoreProvide
3826
/// </summary>
3927
internal const string KeyPathReference = @"Microsoft Cryptography API: Next Generation (CNG) provider";
4028

41-
/// <summary>
42-
/// This function uses the asymmetric key specified by the key path
43-
/// and decrypts an encrypted CEK with RSA encryption algorithm.
44-
/// </summary>
45-
/// <param name="masterKeyPath">Complete path of an asymmetric key in CNG</param>
46-
/// <param name="encryptionAlgorithm">Asymmetric Key Encryption Algorithm</param>
47-
/// <param name="encryptedColumnEncryptionKey">Encrypted Column Encryption Key</param>
48-
/// <returns>Plain text column encryption key</returns>
49-
public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey)
29+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml' path='docs/members[@name="SqlColumnEncryptionCngProvider"]/DecryptColumnEncryptionKey/*' />
30+
public override byte[] DecryptColumnEncryptionKey(string? masterKeyPath, string? encryptionAlgorithm, byte[]? encryptedColumnEncryptionKey)
5031
{
5132
throw new PlatformNotSupportedException();
5233
}
5334

54-
/// <summary>
55-
/// This function uses the asymmetric key specified by the key path
56-
/// and encrypts CEK with RSA encryption algorithm.
57-
/// </summary>
58-
/// <param name="masterKeyPath">Complete path of an asymmetric key in AKV</param>
59-
/// <param name="encryptionAlgorithm">Asymmetric Key Encryption Algorithm</param>
60-
/// <param name="columnEncryptionKey">The plaintext column encryption key</param>
61-
/// <returns>Encrypted column encryption key</returns>
62-
public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey)
35+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml' path='docs/members[@name="SqlColumnEncryptionCngProvider"]/EncryptColumnEncryptionKey/*' />
36+
public override byte[] EncryptColumnEncryptionKey(string? masterKeyPath, string? encryptionAlgorithm, byte[]? columnEncryptionKey)
6337
{
6438
throw new PlatformNotSupportedException();
6539
}
6640

67-
/// <summary>
68-
/// Throws NotSupportedException. In this version of .NET Framework this provider does not support signing column master key metadata.
69-
/// </summary>
70-
/// <param name="masterKeyPath">Complete path of an asymmetric key. Path format is specific to a key store provider.</param>
71-
/// <param name="allowEnclaveComputations">Boolean indicating whether this key can be sent to trusted enclave</param>
72-
/// <returns>Encrypted column encryption key</returns>
73-
public override byte[] SignColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations)
41+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml' path='docs/members[@name="SqlColumnEncryptionCngProvider"]/SignColumnMasterKeyMetadata/*' />
42+
public override byte[] SignColumnMasterKeyMetadata(string? masterKeyPath, bool allowEnclaveComputations)
7443
{
7544
throw new PlatformNotSupportedException();
7645
}
7746

78-
/// <summary>
79-
/// Throws NotSupportedException. In this version of .NET Framework this provider does not support verifying signatures of column master key metadata.
80-
/// </summary>
81-
/// <param name="masterKeyPath">Complete path of an asymmetric key. Path format is specific to a key store provider.</param>
82-
/// <param name="allowEnclaveComputations">Boolean indicating whether this key can be sent to trusted enclave</param>
83-
/// <param name="signature">Signature for the master key metadata</param>
84-
/// <returns>Boolean indicating whether the master key metadata can be verified based on the provided signature</returns>
85-
public override bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations, byte[] signature)
47+
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml' path='docs/members[@name="SqlColumnEncryptionCngProvider"]/VerifyColumnMasterKeyMetadata/*' />
48+
public override bool VerifyColumnMasterKeyMetadata(string? masterKeyPath, bool allowEnclaveComputations, byte[]? signature)
8649
{
8750
throw new PlatformNotSupportedException();
8851
}

0 commit comments

Comments
 (0)