Esempio n. 1
0
        public static void DeriveKeyWithDisposedSecret(KeyDerivationAlgorithm a)
        {
            var s = SharedSecret.Import(Utilities.RandomBytes.Slice(0, 32));

            s.Dispose();
            Assert.Throws <ObjectDisposedException>(() => a.DeriveKey(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, AeadAlgorithm.ChaCha20Poly1305));
        }
Esempio n. 2
0
        public static void DeriveKeyWithNullAlgorithm(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

            using var k = new Key(x);
            using var s = x.Agree(k, k.PublicKey) !;

            Assert.Throws <ArgumentNullException>("algorithm", () => a.DeriveKey(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, null !));
        }
Esempio n. 3
0
        public static void DeriveKeySuccess(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;
            var y = AeadAlgorithm.ChaCha20Poly1305;

            using var k = new Key(x);
            using var s = x.Agree(k, k.PublicKey) !;
            using var i = a.DeriveKey(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, y);
            Assert.NotNull(k);
            Assert.Same(y, i.Algorithm);
        }
Esempio n. 4
0
        public static void DeriveKeyWithUnusedSalt(KeyDerivationAlgorithm a)
        {
            if (!a.SupportsSalt)
            {
                var x = KeyAgreementAlgorithm.X25519;

                using (var k = new Key(x))
                    using (var s = x.Agree(k, k.PublicKey))
                    {
                        Assert.Throws <ArgumentException>("salt", () => a.DeriveKey(s, new byte[1], ReadOnlySpan <byte> .Empty, null));
                    }
            }
        }
Esempio n. 5
0
 public static void DeriveKeyWithNullSecret(KeyDerivationAlgorithm a)
 {
     Assert.Throws <ArgumentNullException>("sharedSecret", () => a.DeriveKey(null, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, null));
 }