diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 11:16:39 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 11:16:39 +0700 |
commit | 7ab750bc8ad1952914c4217773e954bf23c62179 (patch) | |
tree | c91efec693a1364cb4814cb4a4c277cab26b4bfd /crypto/src | |
parent | Generics migration in Tls (diff) | |
download | BouncyCastle.NET-ed25519-7ab750bc8ad1952914c4217773e954bf23c62179.tar.xz |
Generics migration in Pqc
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/pqc/crypto/lms/HSS.cs | 13 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/lms/HSSPrivateKeyParameters.cs | 70 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/lms/LMSSignature.cs | 3 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/sphincsplus/Fors.cs | 6 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/sphincsplus/HT.cs | 6 |
5 files changed, 45 insertions, 53 deletions
diff --git a/crypto/src/pqc/crypto/lms/HSS.cs b/crypto/src/pqc/crypto/lms/HSS.cs index 8fc5dee3b..556ffac26 100644 --- a/crypto/src/pqc/crypto/lms/HSS.cs +++ b/crypto/src/pqc/crypto/lms/HSS.cs @@ -1,6 +1,5 @@ using System; -using System.Collections; -using Org.BouncyCastle.Utilities; +using System.Collections.Generic; namespace Org.BouncyCastle.Pqc.Crypto.Lms { @@ -63,8 +62,8 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms return new HSSPrivateKeyParameters( parameters.GetDepth(), - Platform.CreateArrayList(keys), - Platform.CreateArrayList(sig), + new List<LMSPrivateKeyParameters>(keys), + new List<LMSSignature>(sig), 0, hssKeyMaxIndex); } @@ -103,7 +102,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms int L = keyPair.L; int d = L; - IList prv = keyPair.GetKeys(); + var prv = keyPair.GetKeys(); while ((prv[d - 1] as LMSPrivateKeyParameters).GetIndex() == 1 << ((prv[(d - 1)] as LMSPrivateKeyParameters ).GetSigParameters().GetH())) { d = d - 1; @@ -136,8 +135,8 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms { RangeTestKeys(keyPair); - IList keys = keyPair.GetKeys(); - IList sig = keyPair.GetSig(); + var keys = keyPair.GetKeys(); + var sig = keyPair.GetSig(); nextKey = keyPair.GetKeys()[L - 1] as LMSPrivateKeyParameters; diff --git a/crypto/src/pqc/crypto/lms/HSSPrivateKeyParameters.cs b/crypto/src/pqc/crypto/lms/HSSPrivateKeyParameters.cs index 8e4b2463b..fc85af1aa 100644 --- a/crypto/src/pqc/crypto/lms/HSSPrivateKeyParameters.cs +++ b/crypto/src/pqc/crypto/lms/HSSPrivateKeyParameters.cs @@ -1,37 +1,34 @@ - using System; -using System.Collections; using System.Collections.Generic; using System.IO; + using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.IO; -using Org.BouncyCastle.Utilities.Collections; // using static Org.BouncyCastle.Pqc.Crypto.Lms.HSS.rangeTestKeys; namespace Org.BouncyCastle.Pqc.Crypto.Lms { - public class HSSPrivateKeyParameters : LMSKeyParameters, ILMSContextBasedSigner { private int l; private bool isShard; - private IList keys; //LMSPrivateKeyParameters - private IList sig; //LMSSignature + private IList<LMSPrivateKeyParameters> keys; + private IList<LMSSignature> sig; private long indexLimit; private long index = 0; private HSSPublicKeyParameters publicKey; - public HSSPrivateKeyParameters(int l, IList keys, IList sig, long index, long indexLimit) + public HSSPrivateKeyParameters(int l, IList<LMSPrivateKeyParameters> keys, IList<LMSSignature> sig, long index, + long indexLimit) :base(true) { - this.l = l; - this.keys = Platform.CreateArrayList(keys); - this.sig = Platform.CreateArrayList(sig); + this.keys = new List<LMSPrivateKeyParameters>(keys); + this.sig = new List<LMSSignature>(sig); this.index = index; this.indexLimit = indexLimit; this.isShard = false; @@ -42,15 +39,16 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms ResetKeyToIndex(); } - private HSSPrivateKeyParameters(int l, IList keys, IList sig, long index, long indexLimit, bool isShard) + private HSSPrivateKeyParameters(int l, IList<LMSPrivateKeyParameters> keys, IList<LMSSignature> sig, long index, + long indexLimit, bool isShard) :base(true) { this.l = l; // this.keys = new UnmodifiableListProxy(keys); // this.sig = new UnmodifiableListProxy(sig); - this.keys = Platform.CreateArrayList(keys); - this.sig = Platform.CreateArrayList(sig); + this.keys = new List<LMSPrivateKeyParameters>(keys); + this.sig = new List<LMSSignature>(sig); this.index = index; this.indexLimit = indexLimit; this.isShard = isShard; @@ -97,8 +95,8 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms bool limited = BitConverter.ToBoolean(data, 0); - ArrayList keys = new ArrayList(); - ArrayList signatures = new ArrayList(); + var keys = new List<LMSPrivateKeyParameters>(); + var signatures = new List<LMSSignature>(); for (int t = 0; t < d; t++) { @@ -183,12 +181,12 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms } } - protected void UpdateHierarchy(IList newKeys, IList newSig) + protected void UpdateHierarchy(IList<LMSPrivateKeyParameters> newKeys, IList<LMSSignature> newSig) { lock (this) { - keys = Platform.CreateArrayList(newKeys); - sig = Platform.CreateArrayList(newSig); + keys = new List<LMSPrivateKeyParameters>(newKeys); + sig = new List<LMSSignature>(newSig); } } @@ -222,11 +220,8 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms { lock (this) { - if (GetUsagesRemaining() < usageCount) - { throw new ArgumentException("usageCount exceeds usages remaining in current leaf"); - } long maxIndexForShard = index + usageCount; long shardStartIndex = index; @@ -236,10 +231,11 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms // index += usageCount; - IList keys = new ArrayList(this.GetKeys()); - IList sig = new ArrayList(this.GetSig()); + var keys = new List<LMSPrivateKeyParameters>(this.GetKeys()); + var sig = new List<LMSSignature>(this.GetSig()); - HSSPrivateKeyParameters shard = MakeCopy(new HSSPrivateKeyParameters(l, keys, sig, shardStartIndex, maxIndexForShard, true)); + HSSPrivateKeyParameters shard = MakeCopy(new HSSPrivateKeyParameters(l, keys, sig, shardStartIndex, + maxIndexForShard, true)); ResetKeyToIndex(); @@ -248,7 +244,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms } - public IList GetKeys() + public IList<LMSPrivateKeyParameters> GetKeys() { lock (this) { @@ -256,7 +252,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms } } - internal IList GetSig() + internal IList<LMSSignature>GetSig() { lock (this) { @@ -273,7 +269,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms void ResetKeyToIndex() { // Extract the original keys - IList originalKeys = GetKeys(); + var originalKeys = GetKeys(); long[] qTreePath = new long[originalKeys.Count]; @@ -404,7 +400,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms byte[] childI = new byte[16]; Array.Copy(postImage, 0, childI, 0, childI.Length); - IList newKeys = Platform.CreateArrayList(keys); + var newKeys = new List<LMSPrivateKeyParameters>(keys); // // We need the parameters from the LMS key we are replacing. @@ -414,15 +410,13 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms newKeys[d] = LMS.GenerateKeys(oldPk.GetSigParameters(), oldPk.GetOtsParameters(), 0, childI, childRootSeed); - IList newSig = Platform.CreateArrayList(sig); + var newSig = new List<LMSSignature>(sig); newSig[d - 1] = LMS.GenerateSign(newKeys[d - 1] as LMSPrivateKeyParameters, (newKeys[d] as LMSPrivateKeyParameters).GetPublicKey().ToByteArray()); - - this.keys = Platform.CreateArrayList(newKeys); - this.sig = Platform.CreateArrayList(newSig); - + this.keys = new List<LMSPrivateKeyParameters>(newKeys); + this.sig = new List<LMSSignature>(newSig); } public override bool Equals(Object o) @@ -454,14 +448,14 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms { return false; } - if (!CompareArrayLists(keys, that.keys)) + if (!CompareLists(keys, that.keys)) { return false; } - return CompareArrayLists(sig, that.sig); + return CompareLists(sig, that.sig); } - private bool CompareArrayLists(IList arr1, IList arr2) + private bool CompareLists<T>(IList<T> arr1, IList<T> arr2) { for (int i=0; i<arr1.Count && i<arr2.Count; i++) { @@ -529,8 +523,8 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms { HSS.RangeTestKeys(this); - IList keys = this.GetKeys(); - IList sig = this.GetSig(); + var keys = this.GetKeys(); + var sig = this.GetSig(); nextKey = this.GetKeys()[(L - 1)] as LMSPrivateKeyParameters; diff --git a/crypto/src/pqc/crypto/lms/LMSSignature.cs b/crypto/src/pqc/crypto/lms/LMSSignature.cs index d777ee75e..8769160b4 100644 --- a/crypto/src/pqc/crypto/lms/LMSSignature.cs +++ b/crypto/src/pqc/crypto/lms/LMSSignature.cs @@ -1,7 +1,6 @@ using System; -using System.Collections; using System.IO; -using Org.BouncyCastle.Pqc.Crypto.Lms; + using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.IO; diff --git a/crypto/src/pqc/crypto/sphincsplus/Fors.cs b/crypto/src/pqc/crypto/sphincsplus/Fors.cs index 164a6e9f0..af86eec10 100644 --- a/crypto/src/pqc/crypto/sphincsplus/Fors.cs +++ b/crypto/src/pqc/crypto/sphincsplus/Fors.cs @@ -1,5 +1,6 @@ +using System; +using System.Collections.Generic; -using System.Collections; using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Pqc.Crypto.SphincsPlus @@ -17,8 +18,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.SphincsPlus // Output: n-byte root node - top node on Stack byte[] TreeHash(byte[] skSeed, uint s, int z, byte[] pkSeed, Adrs adrsParam) { - - IList stack = Platform.CreateArrayList(); + var stack = new List<NodeEntry>(); if (s % (1 << z) != 0) { diff --git a/crypto/src/pqc/crypto/sphincsplus/HT.cs b/crypto/src/pqc/crypto/sphincsplus/HT.cs index 765fb8d4a..2cd149f0d 100644 --- a/crypto/src/pqc/crypto/sphincsplus/HT.cs +++ b/crypto/src/pqc/crypto/sphincsplus/HT.cs @@ -1,6 +1,6 @@ - -using System.Collections; +using System; using System.Collections.Generic; + using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Pqc.Crypto.SphincsPlus @@ -155,7 +155,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.SphincsPlus { Adrs adrs = new Adrs(adrsParam); - IList stack = Platform.CreateArrayList(); + var stack = new List<NodeEntry>(); if (s % (1 << (int)z) != 0) { |