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"); } }
/** * Unblinds a blinded text with a blinding factor and the respective used public key * @param key The public key previously used to generate the blinding factor and to blind the text * @param factor The supposedly private blinding factor * @param msg The blinded text * @return The unblinded text */ public static byte[] unblind(CipherParameters key, BigInteger factor, byte[] msg) { /* * Once again notice the usage of a RSABlindingEngine and respective Parameters */ RSABlindingEngine eng = new RSABlindingEngine(); RSABlindingParameters params = new RSABlindingParameters((RSAKeyParameters) key,factor); eng.init(false, params); /* * Another odd method. It returns the unblinded text. */ return eng.processBlock(msg, 0, msg.length); }
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); }