Exemplo n.º 1
0
        public IntegerPolynomial createMsgRep(byte[] msgHash, int r)
        {
            int N = param.N;
            int q = param.q;

            int c = 31 - IntUtils.numberOfLeadingZeros(q);
            int B = (c + 7) / 8;
            IntegerPolynomial i = new IntegerPolynomial(N);

            MemoryStream cbuf = new MemoryStream(msgHash.Length + 4);
            BinaryWriter bwr  = new BinaryWriter(cbuf);

            bwr.Write(msgHash);
            bwr.Write(r);
            Prng prng = new Prng(cbuf.ToArray(), param.hashAlg);

            for (int t = 0; t < N; t++)
            {
                byte[] o  = prng.nextBytes(B);
                int    hi = o[o.Length - 1];
                hi >>= 8 * B - c;
                hi <<= 8 * B - c;
                o[o.Length - 1] = (byte)hi;

                MemoryStream obuf = new MemoryStream(4);
                BinaryWriter bwr2 = new BinaryWriter(obuf);

                bwr2.Write(o);
                obuf.Position = 0;
                // reverse byte order so it matches the endianness of java ints
                i.Coeffs[t] = ArrayUtils.ReverseBytes(obuf.ToArray());
            }
            return(i);
        }
Exemplo n.º 2
0
        public IntegerPolynomial createMsgRep(byte[] msgHash, int r)
        {
            int N = param.N;
            int q = param.q;

            int c = 31 - IntUtils.numberOfLeadingZeros(q);
            int B = (c + 7) / 8;
            IntegerPolynomial i = new IntegerPolynomial(N);

            MemoryStream cbuf = new MemoryStream(msgHash.Length + 4);
            BinaryWriter bwr = new BinaryWriter(cbuf);
            bwr.Write(msgHash);
            bwr.Write(r);
            Prng prng = new Prng(cbuf.ToArray(), param.hashAlg);

            for (int t = 0; t < N; t++)
            {
                byte[] o = prng.nextBytes(B);
                int hi = o[o.Length - 1];
                hi >>= 8 * B - c;
                hi <<= 8 * B - c;
                o[o.Length - 1] = (byte)hi;

                MemoryStream obuf = new MemoryStream(4);
                BinaryWriter bwr2 = new BinaryWriter(obuf);

                bwr2.Write(o);
                obuf.Position = 0;
                // reverse byte order so it matches the endianness of java ints
                i.Coeffs[t] = ArrayUtils.ReverseBytes(obuf.ToArray());
            }
            return i;
        }