diff options
-rw-r--r-- | crypto/src/pqc/crypto/ntrup/NtruPKeyParameters.cs | 17 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntrup/NtruPParameters.cs | 72 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntrup/NtruPPrivateKeyParameters.cs | 21 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntrup/NtruPPublicKeyParameters.cs | 21 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimeEngine.cs (renamed from crypto/src/pqc/crypto/ntrup/NtruPEngine.cs) | 8 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimeKemExtractor.cs (renamed from crypto/src/pqc/crypto/ntrup/NtruPKemExtractor.cs) | 18 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimeKemGenerator.cs (renamed from crypto/src/pqc/crypto/ntrup/NtruPKemGenerator.cs) | 16 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyGenerationParameters.cs (renamed from crypto/src/pqc/crypto/ntrup/NtruPKeyGenerationParameters.cs) | 10 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyPairGenerator.cs (renamed from crypto/src/pqc/crypto/ntrup/NtruPKeyPairGenerator.cs) | 10 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyParameters.cs | 17 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimeParameters.cs | 72 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimePrivateKeyParameters.cs | 20 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/ntruprime/NtruPrimePublicKeyParameters.cs | 19 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_1013.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_ntrulp_1013.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_1277.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_ntrulp_1277.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_653.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_ntrulp_653.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_761.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_ntrulp_761.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_857.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_ntrulp_857.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_953.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_ntrulp_953.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_sntrup_1013.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_sntrup_1013.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_sntrup_1277.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_sntrup_1277.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_sntrup_653.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_sntrup_653.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_sntrup_761.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_sntrup_761.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_sntrup_857.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_sntrup_857.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/data/pqc/ntruprime/kat_kem_sntrup_953.rsp (renamed from crypto/test/data/pqc/ntru/kat_kem_sntrup_953.rsp) | 0 | ||||
-rw-r--r-- | crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs (renamed from crypto/test/src/pqc/crypto/test/NtruPVectorTest.cs) | 55 |
26 files changed, 186 insertions, 190 deletions
diff --git a/crypto/src/pqc/crypto/ntrup/NtruPKeyParameters.cs b/crypto/src/pqc/crypto/ntrup/NtruPKeyParameters.cs deleted file mode 100644 index 96bd4ca8e..000000000 --- a/crypto/src/pqc/crypto/ntrup/NtruPKeyParameters.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Org.BouncyCastle.Crypto; - -namespace Org.BouncyCastle.pqc.crypto.NtruP -{ - public class NtruPKeyParameters : AsymmetricKeyParameter - { - private NtruPParameters _pParameters; - - public NtruPKeyParameters(bool isPrivate, NtruPParameters pParameters) : base(isPrivate) - { - this._pParameters = pParameters; - } - - public NtruPParameters PParameters => _pParameters; - - } -} \ No newline at end of file diff --git a/crypto/src/pqc/crypto/ntrup/NtruPParameters.cs b/crypto/src/pqc/crypto/ntrup/NtruPParameters.cs deleted file mode 100644 index 82c7c8e13..000000000 --- a/crypto/src/pqc/crypto/ntrup/NtruPParameters.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.ComponentModel; -using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Crypto.Digests; -using Org.BouncyCastle.Crypto.Modes; - -namespace Org.BouncyCastle.pqc.crypto.NtruP -{ - public class NtruPParameters : ICipherParameters - { - - private String name; - private int p; - private int q; - private int _roundedBytes; - private bool LPR; - private int _w; - private int _rqBytes; - private int _tau0; - private int _tau1; - private int _tau2; - private int _tau3; - private int _skBytes; - private int _pkBytes; - private int _ctBytes; - private NtruPEngine _pEngine; - - public NtruPParameters(String name, int p, int q, bool LPR, int w, int tau0, - int tau1, int tau2, int tau3, int skBytes, int pkBytes, int ctBytes, int roundedBytes, int rqBytes) - { - this.name = name; - this.p = p; - this.q = q; - this.LPR = LPR; - this._w = w; - this._tau0 = tau0; - this._tau1 = tau1; - this._tau2 = tau2; - this._tau3 = tau3; - - // KEM Parameters - this._roundedBytes = roundedBytes; - this._rqBytes = rqBytes; - this._skBytes = skBytes; - this._pkBytes = pkBytes; - this._ctBytes = ctBytes; - this._pEngine = new NtruPEngine(p,q, LPR, w, tau0, tau1, tau2, tau3, skBytes, pkBytes, ctBytes, roundedBytes, rqBytes); - } - - public static NtruPParameters ntrulpr653 = new NtruPParameters("NTRU_LPRime_653", 653, 4621, true, 252, 2175,113,2031,290,1125,897,1025, 865, -1); - public static NtruPParameters ntrulpr761 = new NtruPParameters("NTRU_LPRime_761", 761, 4591, true, 250, 2156,114,2007,287,1294,1039,1167, 1007, -1); - public static NtruPParameters ntrulpr857 = new NtruPParameters("NTRU_LPRime_857", 857, 5167, true, 281, 2433,101,2265,324,1463,1184,1312, 1152, -1); - public static NtruPParameters ntrulpr953 = new NtruPParameters("NTRU_LPRime_953", 953, 6343, true, 345, 2997,82,2798,400,1652,1349,1477, 1317, -1); - public static NtruPParameters ntrulpr1013 = new NtruPParameters("NTRU_LPRime_1013", 1013, 7177, true, 392, 3367,73,3143,449,1773,1455,1583, 1423, -1); - public static NtruPParameters ntrulpr1277 = new NtruPParameters("NTRU_LPRime_1277", 1277, 7879, true, 429, 3724,66,3469,496,2231,1847,1975, 1815, -1); - - public static NtruPParameters sntrup653 = new NtruPParameters("SNTRU_Prime_653", 653, 4621, false, 288, -1,-1,-1,-1,1518,994,897, 865, 994); - public static NtruPParameters sntrup761 = new NtruPParameters("SNTRU_Prime_761", 761, 4591, false, 286, -1,-1,-1,-1,1763,1158,1039, 1007, 1158); - public static NtruPParameters sntrup857 = new NtruPParameters("SNTRU_Prime_857", 857, 5167, false, 322, -1,-1,-1,-1,1999,1322,1184, 1152, 1322); - public static NtruPParameters sntrup953 = new NtruPParameters("SNTRU_Prime_953", 953, 6343, false, 396, -1,-1,-1,-1,2254,1505,1349, 1317, 1505); - public static NtruPParameters sntrup1013 = new NtruPParameters("SNTRU_Prime_1013", 1013, 7177, false, 448, -1,-1,-1,-1,2417,1623,1455, 1423, 1623); - public static NtruPParameters sntrup1277 = new NtruPParameters("SNTRU_Prime_1277", 1277, 7879, false, 492, -1,-1,-1,-1,3059,2067,1847, 1815, 2067); - - public int P => p; - public bool lpr => LPR; - - public int Q => q; - - internal NtruPEngine PEngine => _pEngine; - - } -} \ No newline at end of file diff --git a/crypto/src/pqc/crypto/ntrup/NtruPPrivateKeyParameters.cs b/crypto/src/pqc/crypto/ntrup/NtruPPrivateKeyParameters.cs deleted file mode 100644 index ff70aa241..000000000 --- a/crypto/src/pqc/crypto/ntrup/NtruPPrivateKeyParameters.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using Org.BouncyCastle.Utilities; - -namespace Org.BouncyCastle.pqc.crypto.NtruP -{ - public class NtruPPrivateKeyParameters : NtruPKeyParameters - { - private byte[] privKey; - public byte[] PrivateKey => Arrays.Clone(privKey); - - public NtruPPrivateKeyParameters(NtruPParameters pParameters, byte[] privKey) : base(true, pParameters) - { - this.privKey = Arrays.Clone(privKey); - } - - public byte[] GetEncoded() - { - return PrivateKey; - } - } -} \ No newline at end of file diff --git a/crypto/src/pqc/crypto/ntrup/NtruPPublicKeyParameters.cs b/crypto/src/pqc/crypto/ntrup/NtruPPublicKeyParameters.cs deleted file mode 100644 index c7a00d9f3..000000000 --- a/crypto/src/pqc/crypto/ntrup/NtruPPublicKeyParameters.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Org.BouncyCastle.Utilities; - -namespace Org.BouncyCastle.pqc.crypto.NtruP -{ - public class NtruPPublicKeyParameters : NtruPKeyParameters - { - public byte[] pubKey; - - public byte[] PublicKey => Arrays.Clone(pubKey); - - public byte[] GetEncoded() - { - return PublicKey; - } - - public NtruPPublicKeyParameters(NtruPParameters pParameters, byte[] pubKey) : base(false,pParameters) - { - this.pubKey = Arrays.Clone(pubKey); - } - } -} \ No newline at end of file diff --git a/crypto/src/pqc/crypto/ntrup/NtruPEngine.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimeEngine.cs index f78abbf7c..701a53cee 100644 --- a/crypto/src/pqc/crypto/ntrup/NtruPEngine.cs +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimeEngine.cs @@ -8,9 +8,9 @@ using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Modes; using Org.BouncyCastle.Crypto.Parameters; -namespace Org.BouncyCastle.pqc.crypto.NtruP +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime { - internal class NtruPEngine + internal class NtruPrimeEngine { // Key Sizes private readonly int _skBytes; // [KEM] Size of secret key @@ -53,7 +53,7 @@ namespace Org.BouncyCastle.pqc.crypto.NtruP public int CipherTextSize => _ctBytes; public int SessionKeySize => SessionKeyBytes; - public NtruPEngine(int p, int q, bool lpr, int w, int tau0, + public NtruPrimeEngine(int p, int q, bool lpr, int w, int tau0, int tau1, int tau2, int tau3, int skBytes, int pkBytes, int ctBytes, int roundedBytes, int rqBytes) { this._p = p; @@ -1281,4 +1281,4 @@ namespace Org.BouncyCastle.pqc.crypto.NtruP } } -} \ No newline at end of file +} diff --git a/crypto/src/pqc/crypto/ntrup/NtruPKemExtractor.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKemExtractor.cs index 6149e1112..9e3c65b10 100644 --- a/crypto/src/pqc/crypto/ntrup/NtruPKemExtractor.cs +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKemExtractor.cs @@ -1,20 +1,20 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Pqc.Crypto.Frodo; -namespace Org.BouncyCastle.pqc.crypto.NtruP +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime { - public class NtruPKEMExtractor : IEncapsulatedSecretExtractor + public class NtruPrimeKEMExtractor : IEncapsulatedSecretExtractor { - private NtruPEngine _pEngine; - private NtruPKeyParameters _pKey; + private NtruPrimeEngine _pEngine; + private NtruPrimeKeyParameters _pKey; - public NtruPKEMExtractor(NtruPKeyParameters privParams) + public NtruPrimeKEMExtractor(NtruPrimeKeyParameters privParams) { this._pKey = privParams; - InitCipher(_pKey.PParameters); + InitCipher(_pKey.Parameters); } - private void InitCipher(NtruPParameters param) + private void InitCipher(NtruPrimeParameters param) { _pEngine = param.PEngine; } @@ -22,7 +22,7 @@ namespace Org.BouncyCastle.pqc.crypto.NtruP public byte[] ExtractSecret(byte[] encapsulation) { byte[] session_key = new byte[_pEngine.SessionKeySize]; - _pEngine.kem_dec(session_key, encapsulation, ((NtruPPrivateKeyParameters)_pKey).PrivateKey); + _pEngine.kem_dec(session_key, encapsulation, ((NtruPrimePrivateKeyParameters)_pKey).privKey); return session_key; } @@ -32,4 +32,4 @@ namespace Org.BouncyCastle.pqc.crypto.NtruP } } -} \ No newline at end of file +} diff --git a/crypto/src/pqc/crypto/ntrup/NtruPKemGenerator.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKemGenerator.cs index 0fb2633e8..9c2e0461b 100644 --- a/crypto/src/pqc/crypto/ntrup/NtruPKemGenerator.cs +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKemGenerator.cs @@ -3,25 +3,25 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; -namespace Org.BouncyCastle.pqc.crypto.NtruP +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime { - public class NtruPKemGenerator : IEncapsulatedSecretGenerator + public class NtruPrimeKemGenerator : IEncapsulatedSecretGenerator { private SecureRandom sr; - public NtruPKemGenerator(SecureRandom sr) + public NtruPrimeKemGenerator(SecureRandom sr) { this.sr = sr; } public ISecretWithEncapsulation GenerateEncapsulated(AsymmetricKeyParameter recipientKey) { - NtruPPublicKeyParameters key = (NtruPPublicKeyParameters)recipientKey; - NtruPEngine pEngine = key.PParameters.PEngine; + NtruPrimePublicKeyParameters key = (NtruPrimePublicKeyParameters)recipientKey; + NtruPrimeEngine pEngine = key.Parameters.PEngine; byte[] cipherText = new byte[pEngine.CipherTextSize]; byte[] sessionKey = new byte[pEngine.SessionKeySize]; - pEngine.kem_enc(cipherText, sessionKey,key.PublicKey, sr); - return new NtruPKemGenerator.SecretWithEncapsulationImpl(sessionKey, cipherText); + pEngine.kem_enc(cipherText, sessionKey,key.pubKey, sr); + return new NtruPrimeKemGenerator.SecretWithEncapsulationImpl(sessionKey, cipherText); } public class SecretWithEncapsulationImpl : ISecretWithEncapsulation @@ -74,4 +74,4 @@ namespace Org.BouncyCastle.pqc.crypto.NtruP } } -} \ No newline at end of file +} diff --git a/crypto/src/pqc/crypto/ntrup/NtruPKeyGenerationParameters.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyGenerationParameters.cs index 7f96dfce6..56e7315ae 100644 --- a/crypto/src/pqc/crypto/ntrup/NtruPKeyGenerationParameters.cs +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyGenerationParameters.cs @@ -1,18 +1,18 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Security; -namespace Org.BouncyCastle.pqc.crypto.NtruP +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime { public class NtruKeyGenerationParameters : KeyGenerationParameters { - private NtruPParameters _pParameters; + private NtruPrimeParameters _pParameters; - public NtruKeyGenerationParameters(SecureRandom random, NtruPParameters ntruPParameters) : base(random,256) + public NtruKeyGenerationParameters(SecureRandom random, NtruPrimeParameters ntruPParameters) : base(random,256) { this._pParameters = ntruPParameters; } - public NtruPParameters PParameters => _pParameters; + public NtruPrimeParameters PParameters => _pParameters; } -} \ No newline at end of file +} diff --git a/crypto/src/pqc/crypto/ntrup/NtruPKeyPairGenerator.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyPairGenerator.cs index fbbd66281..eff4828f8 100644 --- a/crypto/src/pqc/crypto/ntrup/NtruPKeyPairGenerator.cs +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyPairGenerator.cs @@ -1,7 +1,7 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Security; -namespace Org.BouncyCastle.pqc.crypto.NtruP +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime { public class NtruKeyPairGenerator { @@ -26,13 +26,13 @@ namespace Org.BouncyCastle.pqc.crypto.NtruP private AsymmetricCipherKeyPair GenKeyPair() { - NtruPEngine pEngine = ntruParams.PParameters.PEngine; + NtruPrimeEngine pEngine = ntruParams.PParameters.PEngine; byte[] sk = new byte[pEngine.PrivateKeySize]; byte[] pk = new byte[pEngine.PublicKeySize]; pEngine.kem_keypair( pk,sk,random); - NtruPPublicKeyParameters pubKey = new NtruPPublicKeyParameters(ntruParams.PParameters, pk); - NtruPPrivateKeyParameters privKey = new NtruPPrivateKeyParameters(ntruParams.PParameters, sk); + NtruPrimePublicKeyParameters pubKey = new NtruPrimePublicKeyParameters(ntruParams.PParameters, pk); + NtruPrimePrivateKeyParameters privKey = new NtruPrimePrivateKeyParameters(ntruParams.PParameters, sk); return new AsymmetricCipherKeyPair(pubKey, privKey); } @@ -66,4 +66,4 @@ namespace Org.BouncyCastle.pqc.crypto.NtruP // } } -} \ No newline at end of file +} diff --git a/crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyParameters.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyParameters.cs new file mode 100644 index 000000000..fb77d8567 --- /dev/null +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimeKeyParameters.cs @@ -0,0 +1,17 @@ +using Org.BouncyCastle.Crypto; + +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime +{ + public class NtruPrimeKeyParameters : AsymmetricKeyParameter + { + private NtruPrimeParameters _pParameters; + + public NtruPrimeKeyParameters(bool isPrivate, NtruPrimeParameters pParameters) : base(isPrivate) + { + this._pParameters = pParameters; + } + + public NtruPrimeParameters Parameters => _pParameters; + + } +} diff --git a/crypto/src/pqc/crypto/ntruprime/NtruPrimeParameters.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimeParameters.cs new file mode 100644 index 000000000..3cf691565 --- /dev/null +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimeParameters.cs @@ -0,0 +1,72 @@ +using System; +using System.ComponentModel; +using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Crypto.Digests; +using Org.BouncyCastle.Crypto.Modes; + +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime +{ + public class NtruPrimeParameters : ICipherParameters + { + + private String name; + private int p; + private int q; + private int _roundedBytes; + private bool LPR; + private int _w; + private int _rqBytes; + private int _tau0; + private int _tau1; + private int _tau2; + private int _tau3; + private int _skBytes; + private int _pkBytes; + private int _ctBytes; + private NtruPrimeEngine _pEngine; + + public NtruPrimeParameters(String name, int p, int q, bool LPR, int w, int tau0, + int tau1, int tau2, int tau3, int skBytes, int pkBytes, int ctBytes, int roundedBytes, int rqBytes) + { + this.name = name; + this.p = p; + this.q = q; + this.LPR = LPR; + this._w = w; + this._tau0 = tau0; + this._tau1 = tau1; + this._tau2 = tau2; + this._tau3 = tau3; + + // KEM Parameters + this._roundedBytes = roundedBytes; + this._rqBytes = rqBytes; + this._skBytes = skBytes; + this._pkBytes = pkBytes; + this._ctBytes = ctBytes; + this._pEngine = new NtruPrimeEngine(p,q, LPR, w, tau0, tau1, tau2, tau3, skBytes, pkBytes, ctBytes, roundedBytes, rqBytes); + } + + public static NtruPrimeParameters ntrulpr653 = new NtruPrimeParameters("NTRU_LPRime_653", 653, 4621, true, 252, 2175,113,2031,290,1125,897,1025, 865, -1); + public static NtruPrimeParameters ntrulpr761 = new NtruPrimeParameters("NTRU_LPRime_761", 761, 4591, true, 250, 2156,114,2007,287,1294,1039,1167, 1007, -1); + public static NtruPrimeParameters ntrulpr857 = new NtruPrimeParameters("NTRU_LPRime_857", 857, 5167, true, 281, 2433,101,2265,324,1463,1184,1312, 1152, -1); + public static NtruPrimeParameters ntrulpr953 = new NtruPrimeParameters("NTRU_LPRime_953", 953, 6343, true, 345, 2997,82,2798,400,1652,1349,1477, 1317, -1); + public static NtruPrimeParameters ntrulpr1013 = new NtruPrimeParameters("NTRU_LPRime_1013", 1013, 7177, true, 392, 3367,73,3143,449,1773,1455,1583, 1423, -1); + public static NtruPrimeParameters ntrulpr1277 = new NtruPrimeParameters("NTRU_LPRime_1277", 1277, 7879, true, 429, 3724,66,3469,496,2231,1847,1975, 1815, -1); + + public static NtruPrimeParameters sntrup653 = new NtruPrimeParameters("SNTRU_Prime_653", 653, 4621, false, 288, -1,-1,-1,-1,1518,994,897, 865, 994); + public static NtruPrimeParameters sntrup761 = new NtruPrimeParameters("SNTRU_Prime_761", 761, 4591, false, 286, -1,-1,-1,-1,1763,1158,1039, 1007, 1158); + public static NtruPrimeParameters sntrup857 = new NtruPrimeParameters("SNTRU_Prime_857", 857, 5167, false, 322, -1,-1,-1,-1,1999,1322,1184, 1152, 1322); + public static NtruPrimeParameters sntrup953 = new NtruPrimeParameters("SNTRU_Prime_953", 953, 6343, false, 396, -1,-1,-1,-1,2254,1505,1349, 1317, 1505); + public static NtruPrimeParameters sntrup1013 = new NtruPrimeParameters("SNTRU_Prime_1013", 1013, 7177, false, 448, -1,-1,-1,-1,2417,1623,1455, 1423, 1623); + public static NtruPrimeParameters sntrup1277 = new NtruPrimeParameters("SNTRU_Prime_1277", 1277, 7879, false, 492, -1,-1,-1,-1,3059,2067,1847, 1815, 2067); + + public int P => p; + public bool lpr => LPR; + + public int Q => q; + + internal NtruPrimeEngine PEngine => _pEngine; + + } +} diff --git a/crypto/src/pqc/crypto/ntruprime/NtruPrimePrivateKeyParameters.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimePrivateKeyParameters.cs new file mode 100644 index 000000000..69cfc4744 --- /dev/null +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimePrivateKeyParameters.cs @@ -0,0 +1,20 @@ +using System; +using Org.BouncyCastle.Utilities; + +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime +{ + public class NtruPrimePrivateKeyParameters : NtruPrimeKeyParameters + { + internal byte[] privKey; + + public NtruPrimePrivateKeyParameters(NtruPrimeParameters pParameters, byte[] privKey) : base(true, pParameters) + { + this.privKey = Arrays.Clone(privKey); + } + + public byte[] GetEncoded() + { + return Arrays.Clone(privKey); + } + } +} diff --git a/crypto/src/pqc/crypto/ntruprime/NtruPrimePublicKeyParameters.cs b/crypto/src/pqc/crypto/ntruprime/NtruPrimePublicKeyParameters.cs new file mode 100644 index 000000000..265382455 --- /dev/null +++ b/crypto/src/pqc/crypto/ntruprime/NtruPrimePublicKeyParameters.cs @@ -0,0 +1,19 @@ +using Org.BouncyCastle.Utilities; + +namespace Org.BouncyCastle.Pqc.Crypto.NtruPrime +{ + public class NtruPrimePublicKeyParameters : NtruPrimeKeyParameters + { + internal byte[] pubKey; + + public byte[] GetEncoded() + { + return Arrays.Clone(pubKey); + } + + public NtruPrimePublicKeyParameters(NtruPrimeParameters pParameters, byte[] pubKey) : base(false,pParameters) + { + this.pubKey = Arrays.Clone(pubKey); + } + } +} diff --git a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_1013.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_1013.rsp index 98733a7ba..98733a7ba 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_1013.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_1013.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_1277.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_1277.rsp index e52b124d7..e52b124d7 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_1277.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_1277.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_653.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_653.rsp index 5d2a9577b..5d2a9577b 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_653.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_653.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_761.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_761.rsp index 5dc57d164..5dc57d164 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_761.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_761.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_857.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_857.rsp index 666b983c4..666b983c4 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_857.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_857.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_953.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_953.rsp index 9d508e889..9d508e889 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_ntrulp_953.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_ntrulp_953.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_sntrup_1013.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_1013.rsp index 96ff11d52..96ff11d52 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_sntrup_1013.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_1013.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_sntrup_1277.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_1277.rsp index 19b6de594..19b6de594 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_sntrup_1277.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_1277.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_sntrup_653.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_653.rsp index 408d83dbd..408d83dbd 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_sntrup_653.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_653.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_sntrup_761.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_761.rsp index aff180198..aff180198 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_sntrup_761.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_761.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_sntrup_857.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_857.rsp index 68aa0da67..68aa0da67 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_sntrup_857.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_857.rsp diff --git a/crypto/test/data/pqc/ntru/kat_kem_sntrup_953.rsp b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_953.rsp index 7260b7506..7260b7506 100644 --- a/crypto/test/data/pqc/ntru/kat_kem_sntrup_953.rsp +++ b/crypto/test/data/pqc/ntruprime/kat_kem_sntrup_953.rsp diff --git a/crypto/test/src/pqc/crypto/test/NtruPVectorTest.cs b/crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs index 0e8557dcc..29d5292fa 100644 --- a/crypto/test/src/pqc/crypto/test/NtruPVectorTest.cs +++ b/crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs @@ -3,8 +3,7 @@ using System.Collections.Generic; using System.IO; using NUnit.Framework; using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Pqc.Crypto.Frodo; -using Org.BouncyCastle.pqc.crypto.NtruP; +using Org.BouncyCastle.Pqc.Crypto.NtruPrime; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Encoders; using Org.BouncyCastle.Utilities.Test; @@ -12,15 +11,15 @@ using Org.BouncyCastle.Utilities.Test; namespace Org.BouncyCastle.Pqc.Crypto.Tests { [TestFixture] - public class NtruPVectorTest + public class NtruPrimeVectorTest { [Test] public void TestParameters() { // Console.WriteLine("Testing"); - // Console.WriteLine(NtruPParameters.ntrulpr653.P); - // Console.WriteLine(NtruPParameters.ntrulpr653.Q); - // Console.WriteLine(NtruPParameters.ntrulpr653.lpr); + // Console.WriteLine(NtruPrimeParameters.ntrulpr653.P); + // Console.WriteLine(NtruPrimeParameters.ntrulpr653.Q); + // Console.WriteLine(NtruPrimeParameters.ntrulpr653.lpr); } [Test] @@ -42,28 +41,28 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests "kat_kem_sntrup_1277.rsp", }; - NtruPParameters[] parameters = + NtruPrimeParameters[] parameters = { - NtruPParameters.ntrulpr653, - NtruPParameters.ntrulpr761, - NtruPParameters.ntrulpr857, - NtruPParameters.ntrulpr953, - NtruPParameters.ntrulpr1013, - NtruPParameters.ntrulpr1277, - NtruPParameters.sntrup653, - NtruPParameters.sntrup761, - NtruPParameters.sntrup857, - NtruPParameters.sntrup953, - NtruPParameters.sntrup1013, - NtruPParameters.sntrup1277, + NtruPrimeParameters.ntrulpr653, + NtruPrimeParameters.ntrulpr761, + NtruPrimeParameters.ntrulpr857, + NtruPrimeParameters.ntrulpr953, + NtruPrimeParameters.ntrulpr1013, + NtruPrimeParameters.ntrulpr1277, + NtruPrimeParameters.sntrup653, + NtruPrimeParameters.sntrup761, + NtruPrimeParameters.sntrup857, + NtruPrimeParameters.sntrup953, + NtruPrimeParameters.sntrup1013, + NtruPrimeParameters.sntrup1277, }; for (int fileIndex = 0; fileIndex != files.Length; fileIndex++) { String name = files[fileIndex]; Console.Write("Testing " + name + "..."); - Console.WriteLine("pqc.ntru."+ name); - StreamReader src = new StreamReader(SimpleTest.GetTestDataAsStream("pqc.ntru." + name)); + Console.WriteLine("pqc.ntruprime."+ name); + StreamReader src = new StreamReader(SimpleTest.GetTestDataAsStream("pqc.ntruprime." + name)); String line = null; Dictionary<String, String> buf = new Dictionary<string, string>(); @@ -94,7 +93,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests NistSecureRandom random = new NistSecureRandom(seed, null); - NtruPParameters ntruPParameters = parameters[fileIndex]; + NtruPrimeParameters ntruPParameters = parameters[fileIndex]; NtruKeyPairGenerator kpGen = new NtruKeyPairGenerator(); NtruKeyGenerationParameters genParams = new NtruKeyGenerationParameters(random,ntruPParameters); @@ -103,15 +102,15 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests kpGen.Init(genParams); AsymmetricCipherKeyPair kp = kpGen.GenerateKeyPair(); - NtruPPublicKeyParameters pubParams = (NtruPPublicKeyParameters) kp.Public; - NtruPPrivateKeyParameters privParams = (NtruPPrivateKeyParameters) kp.Private; + NtruPrimePublicKeyParameters pubParams = (NtruPrimePublicKeyParameters) kp.Public; + NtruPrimePrivateKeyParameters privParams = (NtruPrimePrivateKeyParameters) kp.Private; // Check public and private key - Assert.True(Arrays.AreEqual(pk,pubParams.PublicKey), $"{name} {count} : public key"); - Assert.True(Arrays.AreEqual(sk,privParams.PrivateKey), $"{name} {count} : private key"); + Assert.True(Arrays.AreEqual(pk,pubParams.GetEncoded()), $"{name} {count} : public key"); + Assert.True(Arrays.AreEqual(sk,privParams.GetEncoded()), $"{name} {count} : private key"); // Encapsulation - NtruPKemGenerator ntruPEncCipher = new NtruPKemGenerator(random); + NtruPrimeKemGenerator ntruPEncCipher = new NtruPrimeKemGenerator(random); ISecretWithEncapsulation secWenc = ntruPEncCipher.GenerateEncapsulated(pubParams); byte[] generatedCT = secWenc.GetEncapsulation(); @@ -123,7 +122,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests Assert.True(Arrays.AreEqual(ss, secret), name + " " + count + ": kem_enc secret"); // Decapsulation - NtruPKEMExtractor ntruDecCipher = new NtruPKEMExtractor(privParams); + NtruPrimeKEMExtractor ntruDecCipher = new NtruPrimeKEMExtractor(privParams); byte[] dec_key = ntruDecCipher.ExtractSecret(generatedCT); // Check decapsulation secret |