private static void VerifyConfigB(IBlake2BConfig a_Config, IBlake2BTreeConfig a_TreeConfig, bool a_IsSequential)
        {
            // digest length
            if ((a_Config.HashSize <= 0) || (a_Config.HashSize > 64))
            {
                throw new ArgumentOutOfRangeHashLibException(InvalidHashSize);
            }

            // Key length
            if (!a_Config.Key.Empty())
            {
                if (a_Config.Key.Length > 64)
                {
                    throw new ArgumentOutOfRangeHashLibException(InvalidKeyLength);
                }
            }

            // Salt length
            if (!a_Config.Salt.Empty())
            {
                if (a_Config.Salt.Length != 16)
                {
                    throw new ArgumentOutOfRangeHashLibException(InvalidSaltLength);
                }
            }

            // Personalisation length
            if (!a_Config.Personalisation.Empty())
            {
                if (a_Config.Personalisation.Length != 16)
                {
                    throw new ArgumentOutOfRangeHashLibException(InvalidPersonalisationLength);
                }
            }

            // Tree InnerHashSize
            if (a_TreeConfig != null)
            {
                if ((a_IsSequential) && ((a_TreeConfig.InnerHashSize != 0)))
                {
                    throw new ArgumentOutOfRangeHashLibException("a_TreeConfig.TreeIntermediateHashSize");
                }

                if (a_TreeConfig.InnerHashSize > 64)
                {
                    throw new ArgumentOutOfRangeHashLibException(TreeIncorrectInnerHashSize);
                }
            }
        }
        public static unsafe UInt64[] ConfigB(IBlake2BConfig a_Config, IBlake2BTreeConfig a_TreeConfig)
        {
            bool isSequential;

            byte[] buffer = new byte[64];

            isSequential = a_TreeConfig == null;
            if (isSequential)
            {
                a_TreeConfig = Blake2BTreeConfig.GetSequentialTreeConfig();
            }

            VerifyConfigB(a_Config, a_TreeConfig, isSequential);

            buffer[0] = (byte)a_Config.HashSize;
            buffer[1] = (byte)(a_Config.Key?.Length ?? 0);;

            if (a_TreeConfig != null)
            {
                buffer[2] = a_TreeConfig.FanOut;
                buffer[3] = a_TreeConfig.MaxDepth;
                Converters.ReadUInt32AsBytesLE(a_TreeConfig.LeafSize, ref buffer, 4);
                Converters.ReadUInt64AsBytesLE(a_TreeConfig.NodeOffset, ref buffer, 8);
                buffer[16] = a_TreeConfig.NodeDepth;
                buffer[17] = a_TreeConfig.InnerHashSize;
            }

            if (!a_Config.Salt.Empty())
            {
                Utils.Utils.Memmove(ref buffer, a_Config.Salt, 16 * sizeof(byte), 0, 32);
            }

            if (!a_Config.Personalisation.Empty())
            {
                Utils.Utils.Memmove(ref buffer, a_Config.Personalisation, 16 * sizeof(byte), 0, 48);
            }

            UInt64[] result = new UInt64[8];
            fixed(UInt64 *resultPtr = result)
            {
                fixed(byte *bufferPtr = buffer)
                {
                    Converters.le64_copy((IntPtr)bufferPtr, 0, (IntPtr)resultPtr, 0, buffer.Length * sizeof(byte));
                }
            }

            return(result);
        }
Example #3
0
        } = null;                                                         // blake2B tree config object

        public Blake2XBConfig(IBlake2BConfig a_Blake2BConfig = null, IBlake2BTreeConfig a_Blake2BTreeConfig = null)
        {
            Blake2BConfig     = a_Blake2BConfig;
            Blake2BTreeConfig = a_Blake2BTreeConfig;
        } // end cctr
Example #4
0
 ///////////////////////////////////////////
 /// <summary>
 /// Blake Hash Family
 /// </summary>
 ////////////////////////////////////////////
 ///
 public static IHash CreateBlake2B(IBlake2BConfig a_Config = null, IBlake2BTreeConfig a_TreeConfig = null)
 => new Blake2B(a_Config ?? Blake2BConfig.DefaultConfig, a_TreeConfig);
Example #5
0
 /// <summary>
 /// <br />Blake2B defaults to setting the expected output length <br />
 /// from the <c>HashSize</c> in the <c>Blake2BConfig</c> class. <br />In
 /// some cases, however, we do not want this, as the output length <br />
 /// of these instances is given by <c>Blake2BTreeConfig.InnerSize</c>
 /// instead. <br />
 /// </summary>
 private Blake2B Blake2BPCreateLeafParam(IBlake2BConfig a_Blake2BConfig, IBlake2BTreeConfig a_Blake2BTreeConfig)
 {
     return(new Blake2B(a_Blake2BConfig, a_Blake2BTreeConfig));
 }