Exemplo n.º 1
0
        public void TestSha3_384()
        {
            var sha3_384    = new Sha3_384();
            var bytes       = Encoding.UTF8.GetBytes("abc");
            var hash        = sha3_384.ComputeHash(bytes);
            var sha3_384str = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();

            Assert.AreEqual(sha3_384str, "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25");
        }
Exemplo n.º 2
0
    private static Span <byte> GetKeyIV(ReadOnlySpan <byte> salt, ReadOnlySpan <byte> password)
    {
        // Hash: Sha3_384
        var hash = new Sha3_384();

        // SHA3-384(Salt[8] + Password[PasswordLength] + Previous Hash[48]) x StretchingCount => AES Key(32), IV(16).
        var bufferLength = SaltLength + password.Length + hash.HashBytes;
        var buffer       = new byte[bufferLength];
        var bufferSpan   = buffer.AsSpan();

        salt.CopyTo(bufferSpan);
        bufferSpan = bufferSpan.Slice(SaltLength);
        password.CopyTo(bufferSpan);
        bufferSpan = bufferSpan.Slice(password.Length);

        var hashSpan = bufferSpan;

        for (var i = 0; i < StretchingCount; i++)
        {
            hash.GetHash(buffer, hashSpan);
        }

        return(hashSpan);
    }