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
                }
            }
        }
Пример #2
0
        public static ECKeyPair generateKeyPair()
        {
            Curve25519KeyPair keyPair = Curve25519.getInstance(Curve25519ProviderType.BEST).generateKeyPair();

            return(new ECKeyPair(new DjbECPublicKey(keyPair.getPublicKey()),
                                 new DjbECPrivateKey(keyPair.getPrivateKey())));
        }
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        private static async Task <ResponsePair> MakeAttestationRequestAsync(PushServiceSocket socket,
                                                                             PushServiceSocket.ClientSet clientSet,
                                                                             string authorization,
                                                                             string enclaveName,
                                                                             Curve25519KeyPair keyPair)
        {
            RemoteAttestationRequest attestationRequest = new RemoteAttestationRequest(keyPair.getPublicKey());
            HttpResponseMessage      response           = await socket.MakeRequestAsync(clientSet, authorization, new List <string>(), $"/v1/attestation/{enclaveName}", "PUT", JsonUtil.ToJson(attestationRequest));

            HttpContent body = response.Content;

            if (body == null)
            {
                throw new MalformedResponseException("Empty response!");
            }

            return(new ResponsePair(await body.ReadAsStringAsync(), ParseCookies(response)));
        }