Example #1
0
    public void Default()
    {
        Span <byte> hash = stackalloc byte[HashConstants.Sha384Length];

        using var sha384 = DigestUtils.Create(DigestType.Sha384);
        sha384.UpdateFinal(_randombytes.Span, hash);
    }
Example #2
0
    public void MayFast()
    {
        Span <byte> hash = stackalloc byte[HashConstants.SM3Length];

        using var sm3 = DigestUtils.Create(DigestType.Sm3);
        sm3.UpdateFinal(_randombytes.Span, hash);
    }
        public static byte[] SHA1(ReadOnlySpan <byte> input)
        {
            var output = new byte[HashConstants.Sha1Length];

            using var hash = DigestUtils.Create(DigestType.Sha1);
            hash.UpdateFinal(input, output);
            return(output);
        }
Example #4
0
        public static ulong CalcCRC32(byte[] input, int len)
        {
            using var hash = DigestUtils.Create(DigestType.Crc32);
            var t = new byte[hash.Length];

            hash.UpdateFinal(input.AsSpan(0, len), t);
            return(BinaryPrimitives.ReadUInt32BigEndian(t));
        }
Example #5
0
        public static void SetCRC32(byte[] buffer)
        {
            using var hash = DigestUtils.Create(DigestType.Crc32);
            var t = new byte[hash.Length];

            hash.UpdateFinal(buffer.AsSpan(0, buffer.Length - 4), t);
            var x = ~BinaryPrimitives.ReadUInt32BigEndian(t);

            BinaryPrimitives.WriteUInt32LittleEndian(buffer.AsSpan(buffer.Length - 4), x);
        }
Example #6
0
 public static IMac Create(DigestType type, ReadOnlySpan <byte> key)
 {
     return(type switch
     {
         DigestType.Md5 => Create(key, HashAlgorithmName.MD5),
         DigestType.Sha1 => Create(key, HashAlgorithmName.SHA1),
         DigestType.Sha256 => Create(key, HashAlgorithmName.SHA256),
         DigestType.Sha384 => Create(key, HashAlgorithmName.SHA384),
         DigestType.Sha512 => Create(key, HashAlgorithmName.SHA512),
         _ => Create(key, DigestUtils.Create(type))
     });
Example #7
0
 public void CRC32C(string message, string expected)
 {
     TestC(new Crc32CSF(), message, expected);
     TestC(DigestUtils.Create(DigestType.Crc32C), message, expected);
 }