コード例 #1
0
        public Blake2Hmac(Algorithm hashAlg, int hashBytes, ReadOnlySpan <byte> key)
        {
            alg           = hashAlg;
            HashSizeValue = hashBytes * 8;
            HashName      = alg.ToString();

            if (key.Length > 0)
            {
                KeyValue = key.ToArray();
            }

            impl = createIncrementalInstance();
        }
コード例 #2
0
        public Blake2Hmac(Algorithm hashAlg, int hashBytes, ReadOnlySpan <byte> key)
        {
            alg           = hashAlg;
            HashSizeValue = hashBytes * 8;
            HashName      = alg.ToString();

            if (key.Length > 0)
#if NETSTANDARD1_3
            { base.Key = key.ToArray(); }
#else
            { KeyValue = key.ToArray(); }
#endif

            impl = createIncrementalInstance();
        }
コード例 #3
0
    private static ReadOnlySpan <byte> compute(IBlake2Incremental impl, ReadOnlySpan <byte> data)
    {
        // every read and write after this will be unaligned
        if (tryReadAndAdvance(out byte byteVal, ref data))
        {
            impl.Update(byteVal);
        }

        // an enum (int) value
        if (tryReadAndAdvance(out DateTimeKind enumVal, ref data))
        {
            impl.Update(enumVal);
        }

        // advance to just shy of a block boundary to make sure we split a value across blocks sometimes
        if (data.Length >= sizeof(long) * 15)
        {
            impl.Update(MemoryMarshal.Cast <byte, long>(data.Slice(0, sizeof(long) * 15)));
            data = data.Slice(sizeof(long) * 15);
        }

        // a non-blittable value type
        if (tryReadAndAdvance(out Guid guidVal, ref data))
        {
            impl.Update(guidVal);
        }

        // a custom struct with a static ref field
        if (tryReadAndAdvance(out TestStruct testVal, ref data))
        {
            impl.Update(testVal);
        }

        impl.Update(data);

        return(impl.Finish());
    }