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); }
/** * Returns the length of a signature made with this parameter set.<br/> * The length does not depend on the message size. * @return the length in bytes */ public int getOutputLength() { int logq = 32 - IntUtils.numberOfLeadingZeros(q - 1); // ceil(log q) int polyLen = (N * logq + 7) / 8; // length of a polynomial in bytes return(polyLen + 4); // add 4 for the retry count }