Exemple #1
0
        public int DoOutput(byte[] output, int outOff, int outLen)
        {
            if (firstOutput)
            {
                if (!initialised)
                {
                    throw new InvalidOperationException("KMAC not initialized");
                }

                byte[] encOut = XofUtilities.RightEncode(0);

                cshake.BlockUpdate(encOut, 0, encOut.Length);

                firstOutput = false;
            }

            return(cshake.DoOutput(output, outOff, outLen));
        }
Exemple #2
0
        public int DoFinal(byte[] output, int outOff, int outLen)
        {
            if (firstOutput)
            {
                if (!initialised)
                {
                    throw new InvalidOperationException("KMAC not initialized");
                }

                byte[] encOut = XofUtilities.RightEncode(outLen * 8);

                cshake.BlockUpdate(encOut, 0, encOut.Length);
            }

            int rv = cshake.DoFinal(output, outOff, outLen);

            Reset();

            return(rv);
        }
Exemple #3
0
        private void bytePad(byte[] X, int w)
        {
            byte[] bytes = XofUtilities.LeftEncode(w);
            BlockUpdate(bytes, 0, bytes.Length);
            byte[] encX = encode(X);
            BlockUpdate(encX, 0, encX.Length);

            int required = w - ((bytes.Length + encX.Length) % w);

            if (required > 0 && required != w)
            {
                while (required > padding.Length)
                {
                    BlockUpdate(padding, 0, padding.Length);
                    required -= padding.Length;
                }

                BlockUpdate(padding, 0, required);
            }
        }
Exemple #4
0
 private static byte[] encode(byte[] X)
 {
     return(Arrays.Concatenate(XofUtilities.LeftEncode(X.Length * 8), X));
 }