private void testSig( int id, RSAKeyParameters pub, RSAKeyParameters prv, byte[] slt, byte[] msg, byte[] sig) throws Exception { RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator(); RSABlindingEngine blindingEngine = new RSABlindingEngine(); PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20); PSSSigner signer = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20); blindFactorGen.init(pub); BigInteger blindFactor = blindFactorGen.generateBlindingFactor(); RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor); // generate a blind signature blindSigner.init(true, new ParametersWithRandom(params, new FixedRandom(slt))); blindSigner.update(msg, 0, msg.length); byte[] blindedData = blindSigner.generateSignature(); RSAEngine signerEngine = new RSAEngine(); signerEngine.init(true, prv); byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length); // unblind the signature blindingEngine.init(false, params); byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length); //signature verification if (!areEqual(s, sig)) { fail("test " + id + " failed generation"); } //verify signature with PSSSigner signer.init(false, pub); signer.update(msg, 0, msg.length); if (!signer.verifySignature(s)) { fail("test " + id + " failed PSSSigner verification"); } }
/** * Generates a blinding factor for the given public key * @param pubKey The public key for the blinding process * @return The resulting blinding factor */ public static BigInteger generateBlindingFactor(CipherParameters pubKey) { RSABlindingFactorGenerator gen = new RSABlindingFactorGenerator(); gen.init(pubKey); return gen.generateBlindingFactor(); }
private boolean isProcessingOkay( RSAKeyParameters pub, RSAKeyParameters prv, byte[] data, SecureRandom random) throws Exception { RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator(); RSABlindingEngine blindingEngine = new RSABlindingEngine(); PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20); PSSSigner pssEng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20); random.nextBytes(data); blindFactorGen.init(pub); BigInteger blindFactor = blindFactorGen.generateBlindingFactor(); RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor); // generate a blind signature blindSigner.init(true, new ParametersWithRandom(params, random)); blindSigner.update(data, 0, data.length); byte[] blindedData = blindSigner.generateSignature(); RSAEngine signerEngine = new RSAEngine(); signerEngine.init(true, prv); byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length); // unblind the signature blindingEngine.init(false, params); byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length); //verify signature with PSSSigner pssEng.init(false, pub); pssEng.update(data, 0, data.length); return pssEng.verifySignature(s); }