public void SetUp(int n, int f) { _deliveryService = new DeliveryService(); _broadcasts = new IConsensusProtocol[n]; _broadcasters = new IConsensusBroadcaster[n]; _resultInterceptors = new ProtocolInvoker <HoneyBadgerId, ISet <IRawShare> > [n]; var keygen = new TrustedKeyGen(n, f); var shares = keygen.GetPrivateShares().ToArray(); var pubKeys = new PublicKeySet(shares.Select(share => share.GetPublicKeyShare()), f); var tpkeKeygen = new Crypto.TPKE.TrustedKeyGen(n, f); var ecdsaKeys = Enumerable.Range(0, n) .Select(i => Crypto.GenerateRandomBytes(32)) .Select(x => x.ToPrivateKey()) .Select(k => new EcdsaKeyPair(k)) .ToArray(); _publicKeys = new PublicConsensusKeySet(n, f, tpkeKeygen.GetPubKey(), pubKeys, ecdsaKeys.Select(k => k.PublicKey)); _privateKeys = new IPrivateConsensusKeySet[n]; for (var i = 0; i < n; ++i) { _resultInterceptors[i] = new ProtocolInvoker <HoneyBadgerId, ISet <IRawShare> >(); _privateKeys[i] = new PrivateConsensusKeySet(ecdsaKeys[i], tpkeKeygen.GetPrivKey(i), shares[i]); _broadcasters[i] = new BroadcastSimulator(i, _publicKeys, _privateKeys[i], _deliveryService, true); } }
public void Test_AesGcmEncryptDecryptRoundTrip() { var key = Crypto.GenerateRandomBytes(32); var baseText = "0xf86d808504a817c800832dc6c0948e7b7262e0fa4616566591d51f998f16a79fb547880de0b6b3a76400008025a0115105d96a43f41a5ea562bb3e591cbfa431a8cdae9c3030457adca2cb854f78a012fb41922c53c73473563003667ed8e783359c91d95b42301e1955d530b1ca33" .HexToBytes(); const int n = 1000; var startTs = TimeUtils.CurrentTimeMillis(); for (var it = 0; it < n; ++it) { var plaintext = baseText.Concat(it.ToBytes()).ToArray(); var cipher = Crypto.AesGcmEncrypt(key, plaintext); var decrypted = Crypto.AesGcmDecrypt(key, cipher); Assert.IsTrue(plaintext.SequenceEqual(decrypted)); } var endTs = TimeUtils.CurrentTimeMillis(); Console.WriteLine($"{n} encrypt/decrypt: {endTs - startTs}ms, avg = {(double) (endTs - startTs) / n}"); }