Esempio n. 1
0
        public static void DeriveBytesWithInfoOverlapping(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

            using var k = new Key(x);
            using var s = x.Agree(k, k.PublicKey) !;
            var b = new byte[200];

            Assert.Throws <ArgumentException>("bytes", () => a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, b.AsSpan(10, 100), b.AsSpan(60, 100)));
            Assert.Throws <ArgumentException>("bytes", () => a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, b.AsSpan(60, 100), b.AsSpan(10, 100)));
        }
Esempio n. 2
0
        public static void DeriveBytesWithDisposedSecret(KeyDerivationAlgorithm a)
        {
            var s = SharedSecret.Import(Utilities.RandomBytes.Slice(0, 32));

            s.Dispose();
            Assert.Throws <ObjectDisposedException>(() => a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, 0));
        }
Esempio n. 3
0
        public static void DeriveBytesWithNegativeCount(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

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

            Assert.Throws <ArgumentOutOfRangeException>("count", () => a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, -1));
        }
Esempio n. 4
0
        public static void DeriveBytesWithEmptySpan(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

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

            a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, Span <byte> .Empty);
        }
Esempio n. 5
0
        public static void DeriveBytesWithSaltOverlapping(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

            if (!a.SupportsSalt)
            {
                return;
            }

            using (var k = new Key(x))
                using (var s = x.Agree(k, k.PublicKey))
                {
                    var b = new byte[200];

                    Assert.Throws <ArgumentException>("bytes", () => a.DeriveBytes(s, b.AsSpan(10, 100), ReadOnlySpan <byte> .Empty, b.AsSpan(60, 100)));
                    Assert.Throws <ArgumentException>("bytes", () => a.DeriveBytes(s, b.AsSpan(60, 100), ReadOnlySpan <byte> .Empty, b.AsSpan(10, 100)));
                }
        }
Esempio n. 6
0
        public static void DeriveBytesWithMaxSpan(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

            using var k = new Key(x);
            using var s = x.Agree(k, k.PublicKey) !;
            var count = Math.Min(a.MaxCount, 500173);

            a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, new byte[count]);
        }
Esempio n. 7
0
        public static void DeriveBytesWithZeroCount(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

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

            var b = a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, 0);

            Assert.NotNull(b);
            Assert.Empty(b);
        }
Esempio n. 8
0
        public static void DeriveBytesWithMaxCount(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

            using var k = new Key(x);
            using var s = x.Agree(k, k.PublicKey) !;
            var count = Math.Min(a.MaxCount, 500173);

            var b = a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, count);

            Assert.NotNull(b);
            Assert.Equal(count, b.Length);
        }
Esempio n. 9
0
        public static void DeriveBytesWithUnusedSalt(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.DeriveBytes(s, new byte[1], ReadOnlySpan <byte> .Empty, 0));
                    }
            }
        }
Esempio n. 10
0
        public static void DeriveBytesWithCountTooLarge(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

            if (a.MaxCount == int.MaxValue)
            {
                return;
            }

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

            Assert.Throws <ArgumentOutOfRangeException>("count", () => a.DeriveBytes(s, ReadOnlySpan <byte> .Empty, ReadOnlySpan <byte> .Empty, a.MaxCount + 1));
        }
Esempio n. 11
0
        public static void DeriveBytesWithSpanTooLarge(KeyDerivationAlgorithm a)
        {
            var x = KeyAgreementAlgorithm.X25519;

            if (a.MaxCount == int.MaxValue)
            {
                return;
            }

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