public BigInteger[] decode(BigInteger n, byte[] encoding) { int valueLength = BigIntegers.getUnsignedByteLength(n); if (encoding.length != valueLength * 2) { throw new IllegalArgumentException("Encoding has incorrect length"); } return new BigInteger[] { decodeValue(n, encoding, 0, valueLength), decodeValue(n, encoding, valueLength, valueLength), }; }
public byte[] encode(BigInteger n, BigInteger r, BigInteger s) { int valueLength = BigIntegers.getUnsignedByteLength(n); byte[] result = new byte[valueLength * 2]; encodeValue(n, r, result, 0, valueLength); encodeValue(n, s, result, valueLength, valueLength); return result; }
/** * generate a signature for the loaded message using the key we were * initialised with. */ public byte[] generateSignature() throws CryptoException { createSignatureBlock(trailer); BigInteger t = new BigInteger(1, cipher.processBlock(block, 0, block.length)); clearBlock(block); t = t.min(kParam.getModulus().subtract(t)); int size = BigIntegers.getUnsignedByteLength(kParam.getModulus()); return BigIntegers.asUnsignedByteArray(size, t); }
public BigInteger nextK() { byte[] t = new byte[BigIntegers.getUnsignedByteLength(n)]; for (;;) { int tOff = 0; while (tOff < t.length) { hMac.update(V, 0, V.length); hMac.doFinal(V, 0); int len = Math.min(t.length - tOff, V.length); System.arraycopy(V, 0, t, tOff, len); tOff += len; } BigInteger k = bitsToInt(t); if (k.compareTo(ZERO) > 0 && k.compareTo(n) < 0) { return k; } hMac.update(V, 0, V.length); hMac.update((byte)0x00); hMac.doFinal(K, 0); hMac.init(new KeyParameter(K)); hMac.update(V, 0, V.length); hMac.doFinal(V, 0); } }
Arrays.fill(K, (byte)0); int size = BigIntegers.getUnsignedByteLength(n); byte[] x = new byte[size]; byte[] dVal = BigIntegers.asUnsignedByteArray(d);