private bool isProcessingOkay( RsaKeyParameters pub, RsaKeyParameters prv, byte[] data, SecureRandom random) { 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 parameters = new RsaBlindingParameters(pub, blindFactor); // generate a blind signature blindSigner.Init(true, new ParametersWithRandom(parameters, random)); blindSigner.BlockUpdate(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, parameters); byte[] s = blindingEngine.ProcessBlock(blindedSig, 0, blindedSig.Length); //verify signature with PssSigner pssEng.Init(false, pub); pssEng.BlockUpdate(data, 0, data.Length); return pssEng.VerifySignature(s); }
private void testSig( int id, RsaKeyParameters pub, RsaKeyParameters prv, byte[] slt, byte[] msg, byte[] sig) { 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 parameters = new RsaBlindingParameters(pub, blindFactor); // generate a blind signature blindSigner.Init(true, new ParametersWithRandom(parameters, new FixedRandom(slt))); blindSigner.BlockUpdate(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, parameters); 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.BlockUpdate(msg, 0, msg.Length); if (!signer.VerifySignature(s)) { Fail("test " + id + " failed PssSigner verification"); } }