-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Build target is .NET 8 now * SHA3 hash/MAC algorithms are now not the default anymore and being used as .NET replacements only * Separated base classes for asymmetric algorithms in PQC and non-PQC implementations (which have different serialization helpers) * Asymmetric key data is PKCS#8 now * Using AES-256-GCM AEAD (128 bit MAC) as default crypto algorithm for PAKE now * Default key exchange algorithm is NTRU now + Added Shake128/256 hash algorithms as .NET replacements + Added Ed25519 and Ed448 asymmetric signature algorithms + Added `BouncyCastleAsymmetricNonPqcPrivate/PublicSignatureKeyBase2` to support a signer which requires a context constructor parameter + Added ECDH algorithm as replacement for the .NET variant from wan24-Crypto + Added ECDSA algorithm as replacement for the .NET variant from wan24-Crypto + Added `BcEllipticCurves` ECDH and ECDSA elliptic curve helper + Added X25519 and X448 asymmetric key exchange algorithms + Added own serialization logic for FrodoKEM and NTRU and enabled the algorithms to be available per default + Added `CryptoEnvironment.(UpdateDefaultOptionsAfter)RemoveUnsupportedAlgorithms` - Fixed all SHA3 algorithms are considered to be post-quantum-safe - Fixed wrong asymmetric PQC key data serialization - Fixed PQC key exchange derive key from encapsulated secret methods had to clone the provided information (they'll be cleared from Bouncy Castle)
- Loading branch information
Showing
83 changed files
with
3,201 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
using wan24.Crypto.Tests; | ||
using wan24.Crypto; | ||
using wan24.Crypto.BC; | ||
using wan24.Crypto.Tests; | ||
|
||
namespace wan24_Crypto_Tests | ||
{ | ||
[TestClass] | ||
public class Asymmetric_Tests | ||
{ | ||
[TestMethod] | ||
public void AllAlgo_Tests() => AsymmetricTests.TestAllAlgorithms(); | ||
public void AllAlgo_Tests() | ||
{ | ||
Assert.IsTrue(AsymmetricHelper.Algorithms[AsymmetricEcDiffieHellmanAlgorithm.ALGORITHM_NAME] is AsymmetricBcEcDiffieHellmanAlgorithm); | ||
Assert.IsTrue(AsymmetricHelper.Algorithms[AsymmetricEcDsaAlgorithm.ALGORITHM_NAME] is AsymmetricBcEcDsaAlgorithm); | ||
AsymmetricTests.TestAllAlgorithms(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Security.Cryptography; | ||
using wan24.Core; | ||
using wan24.Crypto; | ||
using wan24.Crypto.BC; | ||
|
||
namespace wan24_Crypto_Tests | ||
{ | ||
[TestClass] | ||
public class Compatibility_Tests | ||
{ | ||
private static readonly byte[] TestData = [1, 2, 3]; | ||
|
||
[TestMethod] | ||
public void EcDh_Tests() | ||
{ | ||
using AsymmetricEcDiffieHellmanPrivateKey keyA = AsymmetricEcDiffieHellmanAlgorithm.Instance.CreateKeyPair(); | ||
using AsymmetricBcEcDiffieHellmanPublicKey pubKeyA = new(keyA.PublicKey.KeyData.Array.CloneArray()); | ||
using AsymmetricBcEcDiffieHellmanPrivateKey keyB = AsymmetricBcEcDiffieHellmanAlgorithm.Instance.CreateKeyPair(); | ||
(byte[] secretB, byte[] kexB) = keyB.GetKeyExchangeData(pubKeyA); | ||
byte[] secretA = keyA.DeriveKey(kexB); | ||
Assert.IsTrue(secretA.SequenceEqual(secretB)); | ||
} | ||
|
||
[TestMethod] | ||
public void EcDsa_Tests() | ||
{ | ||
using AsymmetricEcDsaPrivateKey netKey = AsymmetricEcDsaAlgorithm.Instance.CreateKeyPair(); | ||
using AsymmetricBcEcDsaPrivateKey bcKey = new(netKey.KeyData.Array); | ||
SignatureContainer signature = netKey.SignData(TestData); | ||
Assert.IsTrue(bcKey.PublicKey.ValidateSignature(signature, TestData, throwOnError: false), ".NET signature vlidation with Bouncy Castle failed"); | ||
signature = bcKey.SignData(TestData); | ||
Assert.IsTrue(netKey.PublicKey.ValidateSignature(signature, TestData, throwOnError: false), "Bouncy Castle signature vlidation with .NET failed"); | ||
} | ||
|
||
[TestMethod] | ||
public void Aes256Cbc_Tests() | ||
{ | ||
CryptoOptions options = new() | ||
{ | ||
LeaveOpen = true | ||
}; | ||
using MemoryStream raw = new(TestData); | ||
using MemoryStream cipher = new(); | ||
using MemoryStream decrypted = new(); | ||
EncryptionAes256CbcAlgorithm.Instance.Encrypt(raw, cipher, TestData, options); | ||
cipher.Position = 0; | ||
EncryptionAes256CbcAlgorithm.Instance.Decrypt(cipher, decrypted, TestData, options); | ||
Assert.IsTrue(decrypted.ToArray().SequenceEqual(TestData)); | ||
} | ||
|
||
[TestMethod] | ||
public void Sha3_Tests() | ||
{ | ||
if (!Shake128.IsSupported) return; | ||
byte[] a, b; | ||
foreach (HashAlgorithmBase[] algos in new HashAlgorithmBase[][]{ | ||
[HashSha3_256Algorithm.Instance, HashBcSha3_256Algorithm.Instance], | ||
[HashSha3_384Algorithm.Instance, HashBcSha3_384Algorithm.Instance], | ||
[HashSha3_512Algorithm.Instance, HashBcSha3_512Algorithm.Instance], | ||
}) | ||
{ | ||
a = algos[0].Hash(TestData); | ||
b = algos[1].Hash(TestData); | ||
Assert.IsTrue(a.SequenceEqual(b), $"{algos[0].GetType()} ({a.Length}/{b.Length})"); | ||
} | ||
foreach (MacAlgorithmBase[] algos in new MacAlgorithmBase[][]{ | ||
[MacHmacSha3_256Algorithm.Instance, MacBcHmacSha3_256Algorithm.Instance], | ||
[MacHmacSha3_384Algorithm.Instance, MacBcHmacSha3_384Algorithm.Instance], | ||
[MacHmacSha3_512Algorithm.Instance, MacBcHmacSha3_512Algorithm.Instance], | ||
}) | ||
{ | ||
a = algos[0].Mac(TestData, TestData); | ||
b = algos[1].Mac(TestData, TestData); | ||
Assert.IsTrue(a.SequenceEqual(b), $"{algos[0].GetType()} ({a.Length}/{b.Length})"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
using wan24.Crypto.Tests; | ||
using wan24.Crypto; | ||
using wan24.Crypto.BC; | ||
using wan24.Crypto.Tests; | ||
|
||
namespace wan24_Crypto_Tests | ||
{ | ||
[TestClass] | ||
public class Encryption_Tests | ||
{ | ||
[TestMethod] | ||
public async Task All_Tests() => await EncryptionTests.TestAllAlgorithms(); | ||
public async Task All_Tests() | ||
{ | ||
Assert.IsTrue(EncryptionHelper.Algorithms[EncryptionAes256CbcAlgorithm.ALGORITHM_NAME] is EncryptionBcAes256CbcAlgorithm); | ||
await EncryptionTests.TestAllAlgorithms(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
using wan24.Crypto.Tests; | ||
using wan24.Crypto; | ||
using wan24.Crypto.BC; | ||
using wan24.Crypto.Tests; | ||
|
||
namespace wan24_Crypto_Tests | ||
{ | ||
[TestClass] | ||
public class Hashing_Tests | ||
{ | ||
[TestMethod] | ||
public async Task All_Tests() => await HashingTests.TestAllAlgorithms(); | ||
public async Task All_Tests() | ||
{ | ||
Assert.IsTrue(HashHelper.Algorithms[HashSha3_256Algorithm.ALGORITHM_NAME] is HashBcSha3_256Algorithm); | ||
Assert.IsTrue(HashHelper.Algorithms[HashSha3_384Algorithm.ALGORITHM_NAME] is HashBcSha3_384Algorithm); | ||
Assert.IsTrue(HashHelper.Algorithms[HashSha3_512Algorithm.ALGORITHM_NAME] is HashBcSha3_512Algorithm); | ||
Assert.IsTrue(HashHelper.Algorithms[HashShake128Algorithm.ALGORITHM_NAME] is HashBcShake128Algorithm); | ||
Assert.IsTrue(HashHelper.Algorithms[HashShake256Algorithm.ALGORITHM_NAME] is HashBcShake256Algorithm); | ||
await HashingTests.TestAllAlgorithms(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
using wan24.Crypto.Tests; | ||
using wan24.Crypto; | ||
using wan24.Crypto.BC; | ||
using wan24.Crypto.Tests; | ||
|
||
namespace wan24_Crypto_Tests | ||
{ | ||
[TestClass] | ||
public class Mac_Tests | ||
{ | ||
[TestMethod] | ||
public async Task All_Tests() => await MacTests.TestAllAlgorithms(); | ||
public async Task All_Tests() | ||
{ | ||
Assert.IsTrue(MacHelper.Algorithms[MacHmacSha3_256Algorithm.ALGORITHM_NAME] is MacBcHmacSha3_256Algorithm); | ||
Assert.IsTrue(MacHelper.Algorithms[MacHmacSha3_384Algorithm.ALGORITHM_NAME] is MacBcHmacSha3_384Algorithm); | ||
Assert.IsTrue(MacHelper.Algorithms[MacHmacSha3_512Algorithm.ALGORITHM_NAME] is MacBcHmacSha3_512Algorithm); | ||
await MacTests.TestAllAlgorithms(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.