summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-03-20 15:23:47 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-03-20 15:23:47 +0700
commit58cb9bd8b944b5c4269204eeab127de9203b9ac1 (patch)
treee23638c104f1ecf474994acf79dddef7fb7c198f
parentAdd tag bounds check to prevent old packet confusion. (diff)
downloadBouncyCastle.NET-ed25519-58cb9bd8b944b5c4269204eeab127de9203b9ac1.tar.xz
Add EdDsa_Legacy
-rw-r--r--crypto/src/bcpg/ModDetectionCodePacket.cs5
-rw-r--r--crypto/src/bcpg/PublicKeyAlgorithmTags.cs4
-rw-r--r--crypto/src/bcpg/PublicKeyPacket.cs2
-rw-r--r--crypto/src/bcpg/SignaturePacket.cs2
-rw-r--r--crypto/src/bcpg/UserAttributePacket.cs2
-rw-r--r--crypto/src/openpgp/PgpEncryptedDataGenerator.cs2
-rw-r--r--crypto/src/openpgp/PgpPublicKey.cs2
-rw-r--r--crypto/src/openpgp/PgpSecretKey.cs6
-rw-r--r--crypto/src/openpgp/PgpSignature.cs2
-rw-r--r--crypto/src/openpgp/PgpSignatureGenerator.cs4
-rw-r--r--crypto/src/openpgp/PgpUtilities.cs4
-rw-r--r--crypto/src/openpgp/PgpV3SignatureGenerator.cs14
-rw-r--r--crypto/test/src/openpgp/test/PgpEdDsaTest.cs4
13 files changed, 23 insertions, 30 deletions
diff --git a/crypto/src/bcpg/ModDetectionCodePacket.cs b/crypto/src/bcpg/ModDetectionCodePacket.cs
index 6bb23645a..ae8283aef 100644
--- a/crypto/src/bcpg/ModDetectionCodePacket.cs
+++ b/crypto/src/bcpg/ModDetectionCodePacket.cs
@@ -33,10 +33,9 @@ namespace Org.BouncyCastle.Bcpg
 			return (byte[]) digest.Clone();
         }
 
-		public override void Encode(
-            BcpgOutputStream bcpgOut)
+		public override void Encode(BcpgOutputStream bcpgOut)
         {
-            bcpgOut.WritePacket(PacketTag.ModificationDetectionCode, digest, false);
+            bcpgOut.WritePacket(PacketTag.ModificationDetectionCode, digest);
         }
     }
 }
diff --git a/crypto/src/bcpg/PublicKeyAlgorithmTags.cs b/crypto/src/bcpg/PublicKeyAlgorithmTags.cs
index 1dd041a5f..a309b65ae 100644
--- a/crypto/src/bcpg/PublicKeyAlgorithmTags.cs
+++ b/crypto/src/bcpg/PublicKeyAlgorithmTags.cs
@@ -14,7 +14,11 @@ namespace Org.BouncyCastle.Bcpg
         ECDsa = 19,				// Reserved for ECDSA
         ElGamalGeneral = 20,	// Elgamal (Encrypt or Sign)
         DiffieHellman = 21,		// Reserved for Diffie-Hellman (X9.42, as defined for IETF-S/MIME)
+
+        // TODO Mark obsolete once Ed25519, Ed448 available
+        //[Obsolete("Use Ed25519 or Ed448 instead")]
         EdDsa = 22,             // EdDSA - (internet draft, but appearing in use)
+        EdDsa_Legacy = 22,      // new name for old EdDSA tag.
 
         Experimental_1 = 100,
         Experimental_2 = 101,
diff --git a/crypto/src/bcpg/PublicKeyPacket.cs b/crypto/src/bcpg/PublicKeyPacket.cs
index b3b5d1600..89177ce84 100644
--- a/crypto/src/bcpg/PublicKeyPacket.cs
+++ b/crypto/src/bcpg/PublicKeyPacket.cs
@@ -50,7 +50,7 @@ namespace Org.BouncyCastle.Bcpg
             case PublicKeyAlgorithmTag.ECDsa:
                 key = new ECDsaPublicBcpgKey(bcpgIn);
                 break;
-            case PublicKeyAlgorithmTag.EdDsa:
+            case PublicKeyAlgorithmTag.EdDsa_Legacy:
                 key = new EdDsaPublicBcpgKey(bcpgIn);
                 break;
             default:
diff --git a/crypto/src/bcpg/SignaturePacket.cs b/crypto/src/bcpg/SignaturePacket.cs
index 99ca7df40..305039e1c 100644
--- a/crypto/src/bcpg/SignaturePacket.cs
+++ b/crypto/src/bcpg/SignaturePacket.cs
@@ -143,7 +143,7 @@ namespace Org.BouncyCastle.Bcpg
 				signature = new MPInteger[3]{ p, g, y };
                 break;
             case PublicKeyAlgorithmTag.ECDsa:
-            case PublicKeyAlgorithmTag.EdDsa:
+            case PublicKeyAlgorithmTag.EdDsa_Legacy:
                 MPInteger ecR = new MPInteger(bcpgIn);
                 MPInteger ecS = new MPInteger(bcpgIn);
                 signature = new MPInteger[2]{ ecR, ecS };
diff --git a/crypto/src/bcpg/UserAttributePacket.cs b/crypto/src/bcpg/UserAttributePacket.cs
index 0be24e006..e976f1215 100644
--- a/crypto/src/bcpg/UserAttributePacket.cs
+++ b/crypto/src/bcpg/UserAttributePacket.cs
@@ -46,7 +46,7 @@ namespace Org.BouncyCastle.Bcpg
                 subpackets[i].Encode(bOut);
             }
 
-            bcpgOut.WritePacket(PacketTag.UserAttribute, bOut.ToArray(), false);
+            bcpgOut.WritePacket(PacketTag.UserAttribute, bOut.ToArray());
         }
     }
 }
diff --git a/crypto/src/openpgp/PgpEncryptedDataGenerator.cs b/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
index 29d90c6fa..a6482db6c 100644
--- a/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
+++ b/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
@@ -122,7 +122,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                         throw new PgpException("Can't use DSA for encryption.");
                     case PublicKeyAlgorithmTag.ECDsa:
                         throw new PgpException("Can't use ECDSA for encryption.");
-                    case PublicKeyAlgorithmTag.EdDsa:
+                    case PublicKeyAlgorithmTag.EdDsa_Legacy:
                         throw new PgpException("Can't use EdDSA for encryption.");
                     default:
                         throw new PgpException("unknown asymmetric algorithm: " + pubKey.Algorithm);
diff --git a/crypto/src/openpgp/PgpPublicKey.cs b/crypto/src/openpgp/PgpPublicKey.cs
index 1fadcff64..8b3575909 100644
--- a/crypto/src/openpgp/PgpPublicKey.cs
+++ b/crypto/src/openpgp/PgpPublicKey.cs
@@ -594,7 +594,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                         return GetECKey("ECDH", ecdhK);
                     }
                 }
-                case PublicKeyAlgorithmTag.EdDsa:
+                case PublicKeyAlgorithmTag.EdDsa_Legacy:
                 {
                     EdDsaPublicBcpgKey eddsaK = (EdDsaPublicBcpgKey)publicPk.Key;
                     var curveOid = eddsaK.CurveOid;
diff --git a/crypto/src/openpgp/PgpSecretKey.cs b/crypto/src/openpgp/PgpSecretKey.cs
index f6e36715f..627b6788a 100644
--- a/crypto/src/openpgp/PgpSecretKey.cs
+++ b/crypto/src/openpgp/PgpSecretKey.cs
@@ -77,7 +77,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                     ECPrivateKeyParameters ecK = (ECPrivateKeyParameters)privKey.Key;
                     secKey = new ECSecretBcpgKey(ecK.D);
                     break;
-                case PublicKeyAlgorithmTag.EdDsa:
+                case PublicKeyAlgorithmTag.EdDsa_Legacy:
                 {
                     if (privKey.Key is Ed25519PrivateKeyParameters ed25519K)
                     {
@@ -441,7 +441,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                     case PublicKeyAlgorithmTag.RsaSign:
                     case PublicKeyAlgorithmTag.Dsa:
                     case PublicKeyAlgorithmTag.ECDsa:
-                    case PublicKeyAlgorithmTag.EdDsa:
+                    case PublicKeyAlgorithmTag.EdDsa_Legacy:
                     case PublicKeyAlgorithmTag.ElGamalGeneral:
                         return true;
                     default:
@@ -733,7 +733,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                     privateKey = new ECPrivateKeyParameters("ECDSA", ecdsaPriv.X, ecdsaPub.CurveOid);
                     break;
                 }
-                case PublicKeyAlgorithmTag.EdDsa:
+                case PublicKeyAlgorithmTag.EdDsa_Legacy:
                 {
                     EdDsaPublicBcpgKey eddsaPub = (EdDsaPublicBcpgKey)pubPk.Key;
                     EdSecretBcpgKey ecdsaPriv = new EdSecretBcpgKey(bcpgIn);
diff --git a/crypto/src/openpgp/PgpSignature.cs b/crypto/src/openpgp/PgpSignature.cs
index d1146183a..d6ffc0f74 100644
--- a/crypto/src/openpgp/PgpSignature.cs
+++ b/crypto/src/openpgp/PgpSignature.cs
@@ -370,7 +370,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 				{
 					signature = sigValues[0].Value.ToByteArrayUnsigned();
 				}
-                else if (KeyAlgorithm == PublicKeyAlgorithmTag.EdDsa)
+                else if (KeyAlgorithm == PublicKeyAlgorithmTag.EdDsa_Legacy)
                 {
 					if (sigValues.Length != 2)
 						throw new InvalidOperationException();
diff --git a/crypto/src/openpgp/PgpSignatureGenerator.cs b/crypto/src/openpgp/PgpSignatureGenerator.cs
index 64d256653..7ff771997 100644
--- a/crypto/src/openpgp/PgpSignatureGenerator.cs
+++ b/crypto/src/openpgp/PgpSignatureGenerator.cs
@@ -60,7 +60,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 				ICipherParameters cp = key;
 
 				// TODO Ask SignerUtilities whether random is permitted?
-				if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa)
+				if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa_Legacy)
 				{
 					// EdDSA signers don't expect a SecureRandom
 				}
@@ -262,7 +262,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 			byte[] fingerPrint = new byte[2]{ digest[0], digest[1] };
 
 			MPInteger[] sigValues;
-            if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa)
+            if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa_Legacy)
             {
                 int sigLen = sigBytes.Length;
                 if (sigLen == Ed25519.SignatureSize)
diff --git a/crypto/src/openpgp/PgpUtilities.cs b/crypto/src/openpgp/PgpUtilities.cs
index 82f65bd08..fa04f5f46 100644
--- a/crypto/src/openpgp/PgpUtilities.cs
+++ b/crypto/src/openpgp/PgpUtilities.cs
@@ -150,7 +150,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             case PublicKeyAlgorithmTag.ECDsa:
                 encAlg = "ECDSA";
                 break;
-            case PublicKeyAlgorithmTag.EdDsa:
+            case PublicKeyAlgorithmTag.EdDsa_Legacy:
                 encAlg = "EdDSA";
                 break;
             case PublicKeyAlgorithmTag.ElGamalEncrypt: // in some malformed cases.
@@ -546,7 +546,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
         {
             switch (publicKeyAlgorithm)
             {
-            case PublicKeyAlgorithmTag.EdDsa:
+            case PublicKeyAlgorithmTag.EdDsa_Legacy:
             {
                 ISigner signer;
                 if (key is Ed25519PrivateKeyParameters || key is Ed25519PublicKeyParameters)
diff --git a/crypto/src/openpgp/PgpV3SignatureGenerator.cs b/crypto/src/openpgp/PgpV3SignatureGenerator.cs
index 03dd8795d..538b6d140 100644
--- a/crypto/src/openpgp/PgpV3SignatureGenerator.cs
+++ b/crypto/src/openpgp/PgpV3SignatureGenerator.cs
@@ -24,7 +24,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             PublicKeyAlgorithmTag	keyAlgorithm,
             HashAlgorithmTag		hashAlgorithm)
         {
-            if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa)
+            if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa_Legacy)
                 throw new ArgumentException("Invalid algorithm for V3 signature", nameof(keyAlgorithm));
 
             this.keyAlgorithm = keyAlgorithm;
@@ -52,17 +52,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             try
             {
                 ICipherParameters cp = key;
-
-                // TODO Ask SignerUtilities whether random is permitted?
-                if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa)
-                {
-                    // EdDSA signers don't expect a SecureRandom
-                }
-                else
-                {
-                    cp = ParameterUtilities.WithRandom(cp, random);
-                }
-
+                cp = ParameterUtilities.WithRandom(cp, random);
                 sig.Init(true, cp);
             }
             catch (InvalidKeyException e)
diff --git a/crypto/test/src/openpgp/test/PgpEdDsaTest.cs b/crypto/test/src/openpgp/test/PgpEdDsaTest.cs
index c5b25320c..f67d19a7f 100644
--- a/crypto/test/src/openpgp/test/PgpEdDsaTest.cs
+++ b/crypto/test/src/openpgp/test/PgpEdDsaTest.cs
@@ -131,7 +131,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
             Ed25519KeyPairGenerator edKp = new Ed25519KeyPairGenerator();
             edKp.Init(new Ed25519KeyGenerationParameters(random));
 
-            PgpKeyPair dsaKeyPair = new PgpKeyPair(PublicKeyAlgorithmTag.EdDsa, edKp.GenerateKeyPair(), DateTime.UtcNow);
+            PgpKeyPair dsaKeyPair = new PgpKeyPair(PublicKeyAlgorithmTag.EdDsa_Legacy, edKp.GenerateKeyPair(), DateTime.UtcNow);
 
             X25519KeyPairGenerator dhKp = new X25519KeyPairGenerator();
             dhKp.Init(new X25519KeyGenerationParameters(random));
@@ -211,7 +211,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
 
             IsTrue(secRing.GetSecretKey().IsSigningKey);
 
-            PgpSignatureGenerator pgpGen = new PgpSignatureGenerator(PublicKeyAlgorithmTag.EdDsa, HashAlgorithmTag.Sha256);
+            PgpSignatureGenerator pgpGen = new PgpSignatureGenerator(PublicKeyAlgorithmTag.EdDsa_Legacy, HashAlgorithmTag.Sha256);
 
             pgpGen.InitSign(PgpSignature.SubkeyBinding, secRing.GetSecretKey().ExtractPrivateKey(null));