Ejemplo n.º 1
0
        public static unsafe UInt32[] ConfigS(IBlake2SConfig a_Config, IBlake2STreeConfig a_TreeConfig)
        {
            bool isSequential;

            byte[] buffer = new byte[32];

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

            VerifyConfigS(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);
                buffer[8]  = (byte)a_TreeConfig.NodeOffset;
                buffer[9]  = (byte)(a_TreeConfig.NodeOffset >> 8);
                buffer[10] = (byte)(a_TreeConfig.NodeOffset >> 16);
                buffer[11] = (byte)(a_TreeConfig.NodeOffset >> 24);
                buffer[12] = (byte)(a_TreeConfig.NodeOffset >> 32);
                buffer[13] = (byte)(a_TreeConfig.NodeOffset >> 40);
                buffer[14] = a_TreeConfig.NodeDepth;
                buffer[15] = a_TreeConfig.InnerHashSize;
            }

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

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

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

            return(result);
        }
Ejemplo n.º 2
0
        private static void VerifyConfigS(IBlake2SConfig a_Config, IBlake2STreeConfig a_TreeConfig, bool a_IsSequential)
        {
            // digest length
            if ((a_Config.HashSize <= 0) || (a_Config.HashSize > 32))
            {
                throw new ArgumentOutOfRangeHashLibException(InvalidHashSize);
            }

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

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

            // Personalisation length
            if (!a_Config.Personalisation.Empty())
            {
                if (a_Config.Personalisation.Length != 8)
                {
                    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 > 32)
                {
                    throw new ArgumentOutOfRangeHashLibException(TreeIncorrectInnerHashSize);
                }
            }
        }
Ejemplo n.º 3
0
        } = null;                                                         // blake2S tree config object

        public Blake2XSConfig(IBlake2SConfig a_Blake2SConfig = null, IBlake2STreeConfig a_Blake2STreeConfig = null)
        {
            Blake2SConfig     = a_Blake2SConfig;
            Blake2STreeConfig = a_Blake2STreeConfig;
        } // end cctr
Ejemplo n.º 4
0
 public static IHash CreateBlake2S(IBlake2SConfig a_Config = null, IBlake2STreeConfig a_TreeConfig = null)
 => new Blake2S(a_Config ?? Blake2SConfig.DefaultConfig, a_TreeConfig);
Ejemplo n.º 5
0
 /// <summary>
 /// <br />Blake2S defaults to setting the expected output length <br />
 /// from the <c>HashSize</c> in the <c>Blake2SConfig</c> class. <br />In
 /// some cases, however, we do not want this, as the output length <br />
 /// of these instances is given by <c>Blake2STreeConfig.InnerSize</c>
 /// instead. <br />
 /// </summary>
 private Blake2S Blake2SPCreateLeafParam(IBlake2SConfig a_Blake2SConfig, IBlake2STreeConfig a_Blake2STreeConfig)
 {
     return(new Blake2S(a_Blake2SConfig, a_Blake2STreeConfig));
 }