public static ECKeyPair generateKeyPair() { Curve25519KeyPair keyPair = Curve25519.getInstance(Curve25519ProviderType.BEST).generateKeyPair(); return(new ECKeyPair(new DjbECPublicKey(keyPair.getPublicKey()), new DjbECPrivateKey(keyPair.getPrivateKey()))); }
public void testUniqueSignatures() { Curve25519KeyPair keys = curve25519.generateKeyPair(); Random random = new Random(); for (int i = 1; i <= 256; i++) { byte[] message = new byte[i]; random.NextBytes(message); byte[] signature = curve25519.calculateVrfSignature(keys.getPrivateKey(), message); byte[] vrf = curve25519.verifyVrfSignature(keys.getPublicKey(), message, signature); Assert.IsFalse(curve25519.verifySignature(keys.getPublicKey(), message, signature)); message[Math.Abs(random.Next(int.MaxValue)) % message.Length] ^= 0x01; try { curve25519.verifyVrfSignature(keys.getPublicKey(), message, signature); throw new InvalidOperationException("Should have failed"); } catch (VrfSignatureVerificationFailedException e) { // good } } }
public void testUniqueSignatureVector() { Curve25519KeyPair keys = new Curve25519KeyPair(PUBLIC_KEY, PRIVATE_KEY); byte[] signature = curve25519.calculateVrfSignature(keys.getPrivateKey(), MESSAGE); byte[] vrf = curve25519.verifyVrfSignature(keys.getPublicKey(), MESSAGE, signature); CollectionAssert.AreEqual(VRF, vrf); }
public RemoteAttestationKeys(Curve25519KeyPair keyPair, byte[] serverPublicEphemeral, byte[] serverPublicStatic) { byte[] ephemeralToEphemeral = Curve25519.getInstance(Curve25519.BEST).calculateAgreement(serverPublicEphemeral, keyPair.getPrivateKey()); byte[] ephemeralToStatic = Curve25519.getInstance(Curve25519.BEST).calculateAgreement(serverPublicStatic, keyPair.getPrivateKey()); byte[] masterSecret = ByteUtil.combine(ephemeralToEphemeral, ephemeralToStatic); byte[] publicKeys = ByteUtil.combine(keyPair.getPublicKey(), serverPublicEphemeral, serverPublicStatic); HkdfBytesGenerator generator = new HkdfBytesGenerator(new Sha256Digest()); generator.Init(new HkdfParameters(masterSecret, publicKeys, null)); generator.GenerateBytes(ClientKey, 0, ClientKey.Length); generator.GenerateBytes(ServerKey, 0, ServerKey.Length); }