Skip to content

Commit

Permalink
chore(RSA): limit RSA Key Gen to 4096 bits (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
texastony authored Oct 7, 2022
1 parent fd2516f commit 2e35d92
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions aws-encryption-sdk-net/Source/Extern/RSAEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public static byte[] GetPublicKeyFromPrivateKeyPemString(string pem)
}

public static void GenerateKeyPairBytes(int strength, out byte[] publicKeyBytes, out byte[] privateKeyBytes) {
if (strength > 4096)
{
throw new ArgumentException("AWS Crypto will not generate an RSA Key greater than 4096.");
}
RsaKeyPairGenerator keygen = new RsaKeyPairGenerator();
SecureRandom secureRandom = new SecureRandom();
keygen.Init(new RsaKeyGenerationParameters(
Expand Down
3 changes: 2 additions & 1 deletion src/Crypto/RSAEncryption.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ module {:extern "RSAEncryption"} RSAEncryption {
}

method GenerateKeyPair(strength: StrengthBits)
returns (publicKey: PublicKey, privateKey: PrivateKey)
returns (publicKey: PublicKey, privateKey: PrivateKey)
requires strength <= 4096
ensures privateKey.Valid()
ensures publicKey.Valid()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ module TestRawRSAKeying {
)
requires |namespace| < UINT16_LIMIT
requires |name| < UINT16_LIMIT
requires keyStrength <= 4096
{
publicKey, privateKey := RSAEncryption.GenerateKeyPair(
keyStrength
Expand Down

0 comments on commit 2e35d92

Please sign in to comment.