diff options
author | Roy Basmacier <roy.basmacier@keyfactor.com> | 2022-07-11 11:17:56 -0400 |
---|---|---|
committer | Roy Basmacier <roy.basmacier@keyfactor.com> | 2022-07-11 11:17:56 -0400 |
commit | 9797869ce3c1f2bf038b2054cfeea8b3754eace3 (patch) | |
tree | 617bc0a03a2c2d32f02864b12cbd3a63af4683fa | |
parent | minor reformatting (diff) | |
download | BouncyCastle.NET-ed25519-9797869ce3c1f2bf038b2054cfeea8b3754eace3.tar.xz |
Fixed static problem in Picnic
-rw-r--r-- | crypto/src/pqc/crypto/picnic/KMatrices.cs | 38 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/picnic/LowmcConstants.cs | 17 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/picnic/PicnicEngine.cs | 8 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/picnic/Tape.cs | 2 | ||||
-rw-r--r-- | crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs | 4 |
5 files changed, 41 insertions, 28 deletions
diff --git a/crypto/src/pqc/crypto/picnic/KMatrices.cs b/crypto/src/pqc/crypto/picnic/KMatrices.cs index 790e7c916..64e6be00a 100644 --- a/crypto/src/pqc/crypto/picnic/KMatrices.cs +++ b/crypto/src/pqc/crypto/picnic/KMatrices.cs @@ -1,12 +1,13 @@ +using Org.BouncyCastle.Utilities; + namespace Org.BouncyCastle.Pqc.Crypto.Picnic { - public class KMatrices + internal class KMatrices { private int nmatrices; private int rows; private int columns; private uint[] data; - private int matrixPointer; public KMatrices(int nmatrices, int rows, int columns, uint[] data) { @@ -14,18 +15,8 @@ namespace Org.BouncyCastle.Pqc.Crypto.Picnic this.rows = rows; this.columns = columns; this.data = data; - this.matrixPointer = 0; - } - - public int GetMatrixPointer() - { - return matrixPointer; - } - - public void SetMatrixPointer(int matrixPointer) - { - this.matrixPointer = matrixPointer; } + public int GetNmatrices() { @@ -52,4 +43,25 @@ namespace Org.BouncyCastle.Pqc.Crypto.Picnic return data; } } + + internal class KMatricesWithPointer + : KMatrices + { + private int matrixPointer; + public int GetMatrixPointer() + { + return matrixPointer; + } + + public void SetMatrixPointer(int matrixPointer) + { + this.matrixPointer = matrixPointer; + } + + public KMatricesWithPointer(KMatrices m) + : base(m.GetNmatrices(), m.GetRows(), m.GetColumns(), m.GetData()) + { + this.matrixPointer = 0; + } + } } \ No newline at end of file diff --git a/crypto/src/pqc/crypto/picnic/LowmcConstants.cs b/crypto/src/pqc/crypto/picnic/LowmcConstants.cs index 8e56ee568..52af2596c 100644 --- a/crypto/src/pqc/crypto/picnic/LowmcConstants.cs +++ b/crypto/src/pqc/crypto/picnic/LowmcConstants.cs @@ -207,15 +207,16 @@ public sealed class LowmcConstants // Functions to return individual matricies and round constants /* Return a pointer to the r-th matrix. The caller must know the dimensions */ - private KMatrices GET_MAT(KMatrices m, int r) + private KMatricesWithPointer GET_MAT(KMatrices m, int r) { - m.SetMatrixPointer(r*m.GetSize()); - return m; + KMatricesWithPointer mwp = new KMatricesWithPointer(m); + mwp.SetMatrixPointer(r*mwp.GetSize()); + return mwp; } /* Return the LowMC linear matrix for this round */ - internal KMatrices LMatrix(PicnicEngine engine, int round) + internal KMatricesWithPointer LMatrix(PicnicEngine engine, int round) { if(engine.stateSizeBits == 128) @@ -252,7 +253,7 @@ public sealed class LowmcConstants } /* Return the LowMC inverse linear layer matrix for this round */ - internal KMatrices LMatrixInv(PicnicEngine engine, int round) + internal KMatricesWithPointer LMatrixInv(PicnicEngine engine, int round) { if(engine.stateSizeBits == 129) { @@ -273,7 +274,7 @@ public sealed class LowmcConstants } /* Return the LowMC key matrix for this round */ - internal KMatrices KMatrix(PicnicEngine engine, int round) + internal KMatricesWithPointer KMatrix(PicnicEngine engine, int round) { if(engine.stateSizeBits == 128) { @@ -309,7 +310,7 @@ public sealed class LowmcConstants } /* Return the LowMC inverse key matrix for this round */ - internal KMatrices KMatrixInv(PicnicEngine engine, int round) + internal KMatricesWithPointer KMatrixInv(PicnicEngine engine, int round) { if(engine.stateSizeBits == 129) { @@ -331,7 +332,7 @@ public sealed class LowmcConstants /* Return the LowMC round constant for this round */ - internal KMatrices RConstant(PicnicEngine engine, int round) + internal KMatricesWithPointer RConstant(PicnicEngine engine, int round) { if(engine.stateSizeBits == 128) { diff --git a/crypto/src/pqc/crypto/picnic/PicnicEngine.cs b/crypto/src/pqc/crypto/picnic/PicnicEngine.cs index 24b618676..da6a9215c 100644 --- a/crypto/src/pqc/crypto/picnic/PicnicEngine.cs +++ b/crypto/src/pqc/crypto/picnic/PicnicEngine.cs @@ -556,7 +556,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Picnic mpc_xor_constant_verify(tmp, plaintext, 0, stateSizeWords, challenge); - KMatrices current = LowmcConstants.Instance.KMatrix(this, 0); + KMatricesWithPointer current = LowmcConstants.Instance.KMatrix(this, 0); matrix_mul_offset(tmp, 0, view1.inputShare, 0, current.GetData(), current.GetMatrixPointer()); @@ -1617,7 +1617,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Picnic mpc_xor_constant(slab, 3 * stateSizeWords, plaintext, 0, stateSizeWords); - KMatrices current = LowmcConstants.Instance.KMatrix(this, 0); + KMatricesWithPointer current = LowmcConstants.Instance.KMatrix(this, 0); for (int player = 0; player < 3; player++) { matrix_mul_offset(slab, player * stateSizeWords, views[player].inputShare, 0, @@ -2146,7 +2146,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Picnic uint[] roundKey = new uint[LOWMC_MAX_WORDS]; uint[] state = new uint[LOWMC_MAX_WORDS]; - KMatrices current = LowmcConstants.Instance.KMatrix(this, 0); + KMatricesWithPointer current = LowmcConstants.Instance.KMatrix(this, 0); matrix_mul(roundKey, maskedKey, current.GetData(), current.GetMatrixPointer()); // roundKey = maskedKey * KMatrix[0] xor_array(state, roundKey, plaintext, 0, stateSizeWords); // state = plaintext + roundKey @@ -2493,7 +2493,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Picnic System.Array.Copy(plaintext, 0, output, 0, stateSizeWords); } - KMatrices current = LowmcConstants.Instance.KMatrix(this, 0); + KMatricesWithPointer current = LowmcConstants.Instance.KMatrix(this, 0); matrix_mul(roundKey, key, current.GetData(), current.GetMatrixPointer()); xor_array(output, output, roundKey, 0, stateSizeWords); diff --git a/crypto/src/pqc/crypto/picnic/Tape.cs b/crypto/src/pqc/crypto/picnic/Tape.cs index 22170aea6..dd1a44de8 100644 --- a/crypto/src/pqc/crypto/picnic/Tape.cs +++ b/crypto/src/pqc/crypto/picnic/Tape.cs @@ -57,7 +57,7 @@ public class Tape // {System.out.printf("%08x ", key0[i]);}System.out.Println(); // key = key0 x KMatrix[0]^(-1) - KMatrices current = LowmcConstants.Instance.KMatrixInv(engine, 0); + KMatricesWithPointer current = LowmcConstants.Instance.KMatrixInv(engine, 0); engine.matrix_mul(key, key0, current.GetData(), current.GetMatrixPointer()); // System.out.print("key: "); diff --git a/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs b/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs index 99b649e6a..550a94c68 100644 --- a/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs +++ b/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs @@ -53,14 +53,14 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests }; [TestCaseSource(nameof(TestVectorFilesBasic))] - //[Parallelizable(ParallelScope.All)] + [Parallelizable(ParallelScope.All)] public void TestVectorsBasic(string testVectorFile) { RunTestVectorFile(testVectorFile); } [Explicit, TestCaseSource(nameof(TestVectorFilesExtra))] - //[Parallelizable(ParallelScope.All)] + [Parallelizable(ParallelScope.All)] public void TestVectorsExtra(string testVectorFile) { RunTestVectorFile(testVectorFile); |