public bool CheckKey() { return (PoupardSternProof != null && _PermutationTestProof != null && PoupardStern.VerifyPoupardStern(_PublicKey._Key, PoupardSternProof, PoupardSetup) && PermutationTest.VerifyPermutationTest(_PublicKey._Key, PermutationTestProof, PermutationSetup)); }
public void GetR_Data() { var list = new BigInteger[samples]; for (int i = 0; i < samples; i++) { PoupardStern.GetR(keySize, out list[i]); } Console.WriteLine(String.Join(",", list.ToList())); }
public void SampleFromZnStar_Data() { BigK = samples; var keyPair = TestUtils.GeneratePrivate(Exp, keySize); var pubKey = (RsaKeyParameters)keyPair.Public; var Modulus = pubKey.Modulus; var list = new BigInteger[samples]; for (int i = 0; i < samples; i++) { list[i] = PoupardStern.SampleFromZnStar(pubKey, ps, i, BigK, keySize); } Console.WriteLine(String.Join(",", list.ToList())); }
public void GetW_Data() { var keyPair = TestUtils.GeneratePrivate(Exp, keySize); var pubKey = (RsaKeyParameters)keyPair.Public; BigK = 5000; var Modulus = pubKey.Modulus; BigInteger[] Datalist = new BigInteger[BigK]; // Initialize list of z values BigInteger[] zValues = new BigInteger[BigK]; // Generate the list of z Values for (int i = 0; i < BigK; i++) { zValues[i] = PoupardStern.SampleFromZnStar(pubKey, ps, i, BigK, keySize); } for (int i = 0; i < BigK; i++) { // Initialize list of x values. BigInteger[] xValues = new BigInteger[BigK]; // Generate r PoupardStern.GetR(keySize, out BigInteger r); for (int j = 0; j < BigK; j++) { // Compute x_i xValues[j] = zValues[j].ModPow(r, Modulus); } // Compute w PoupardStern.GetW(pubKey, ps, xValues, k, keySize, out BigInteger w); Datalist[i] = w; } Console.WriteLine(String.Join(",", Datalist.ToList())); }
public void SampleFromZnStarTest() { // SampleFromZnStar is really producing z_i that are <N int BigK = 129; // If k = 128 keySize = 2048; var keyPair = TestUtils.GeneratePrivate(Exp, keySize); var privKey = (RsaPrivateCrtKeyParameters)keyPair.Private; var pubKey = (RsaKeyParameters)keyPair.Public; var Modulus = pubKey.Modulus; for (int i = 0; i < BigK; i++) { var num = PoupardStern.SampleFromZnStar(pubKey, ps, i, BigK, keySize); // Assert that num is < N Assert.IsTrue(num.CompareTo(Modulus) < 0); } }
public void GetWTest() { var k = 128; var BigK = k + 1; var keyPair = TestUtils.GeneratePrivate(Exp, keySize); var pubKey = (RsaKeyParameters)keyPair.Public; var Modulus = pubKey.Modulus; // Initialize list of z values BigInteger[] zValues = new BigInteger[BigK]; // Generate the list of z Values for (int i = 0; i < BigK; i++) { zValues[i] = PoupardStern.SampleFromZnStar(pubKey, ps, i, BigK, keySize); } // Initialize list of x values. BigInteger[] xValues = new BigInteger[BigK]; // Generate r PoupardStern.GetR(keySize, out BigInteger r); for (int j = 0; j < BigK; j++) { // Compute x_i xValues[j] = zValues[j].ModPow(r, Modulus); } // Compute w PoupardStern.GetW(pubKey, ps, xValues, k, keySize, out BigInteger w); // Check that the bitLength of w equals to k. Assert.IsTrue(w.BitLength <= k); }
private static Tuple <RsaKey, RSAKeyData> LoadRSAKeyData(string dataDir, string keyName, bool noRSAProof) { RSAKeyData data = new RSAKeyData(); RsaKey key = null; { var rsaFile = Path.Combine(dataDir, keyName); if (!File.Exists(rsaFile)) { Logs.Configuration.LogWarning("RSA private key not found, please backup it. Creating..."); key = new RsaKey(); File.WriteAllBytes(rsaFile, key.ToBytes()); Logs.Configuration.LogInformation("RSA key saved (" + rsaFile + ")"); } else { Logs.Configuration.LogInformation("RSA private key found (" + rsaFile + ")"); key = new RsaKey(File.ReadAllBytes(rsaFile)); } } data.PublicKey = key.PubKey; if (!noRSAProof) { { var poupard = Path.Combine(dataDir, "ProofPoupard-" + keyName); PoupardSternProof poupardProof = null; if (!File.Exists(poupard)) { Logs.Configuration.LogInformation("Creating Poupard Stern proof..."); poupardProof = PoupardStern.ProvePoupardStern(key._Key, RSAKeyData.PoupardSetup); MemoryStream ms = new MemoryStream(); BitcoinStream bs = new BitcoinStream(ms, true); bs.ReadWriteC(ref poupardProof); File.WriteAllBytes(poupard, ms.ToArray()); Logs.Configuration.LogInformation("Poupard Stern proof created (" + poupard + ")"); } else { Logs.Configuration.LogInformation("Poupard Stern Proof found (" + poupard + ")"); var bytes = File.ReadAllBytes(poupard); MemoryStream ms = new MemoryStream(bytes); BitcoinStream bs = new BitcoinStream(ms, false); bs.ReadWriteC(ref poupardProof); } data.PoupardSternProof = poupardProof; } { var permutation = Path.Combine(dataDir, "ProofPermutation-" + keyName); PermutationTestProof permutationProof = null; if (!File.Exists(permutation)) { Logs.Configuration.LogInformation("Creating Permutation Test proof..."); permutationProof = PermutationTest.ProvePermutationTest(key._Key, RSAKeyData.PermutationSetup); MemoryStream ms = new MemoryStream(); BitcoinStream bs = new BitcoinStream(ms, true); bs.ReadWriteC(ref permutationProof); File.WriteAllBytes(permutation, ms.ToArray()); Logs.Configuration.LogInformation("Permutation Test proof created (" + permutation + ")"); } else { Logs.Configuration.LogInformation("Permutation Test Proof found (" + permutation + ")"); var bytes = File.ReadAllBytes(permutation); MemoryStream ms = new MemoryStream(bytes); BitcoinStream bs = new BitcoinStream(ms, false); bs.ReadWriteC(ref permutationProof); } data.PermutationTestProof = permutationProof; } } return(Tuple.Create(key, data)); }