I successfully tried Rabin key generation and signing after surveyed
cryptopp 5.6.0 source code and documents.

// to generate a Rabin key pair
    CryptoPP::Integer p = CryptoPP::Integer();
    CryptoPP::Integer q = CryptoPP::Integer();
    CryptoPP::Integer n = CryptoPP::Integer();
    CryptoPP::InvertibleRabinFunction decryptor;
    decryptor.Initialize(rng,1024);
    CryptoPP::RabinFunction encryptor(decryptor);
    CryptoPP::HexEncoder privFile(new CryptoPP::FileSink
("private.rabin")); // Hex Encoder
    decryptor.DEREncode(privFile);
    privFile.MessageEnd();
    CryptoPP::HexEncoder pubFile(new CryptoPP::FileSink
("public.rabin")); // Hex Encoder
    encryptor.DEREncode(pubFile);
    pubFile.MessageEnd();
    std::cout<<"\n n:"<<encryptor.GetModulus();
    std::cout<<"\n p:"<<decryptor.GetPrime1();
    std::cout<<"\n q:"<<decryptor.GetPrime2();
    if(decryptor.Validate(rng, 9)) std::cout<<"\n good Rabin key."
<<std::endl;

// to sign by Rabin
    CryptoPP::AutoSeededRandomPool rng;
    std::string signedString;
    try{
        std::string PrivateKeyFile = "private.rabin";
        CryptoPP::FileSource privFile(PrivateKeyFile.c_str(), true,
new CryptoPP::HexDecoder);
        CryptoPP::RabinSS<PSSR, SHA>::Signer priv(privFile);
        CryptoPP::RabinSS<PSSR, SHA>::Verifier pub(priv);
    //if(SignatureValidate(priv,pub)) std::cout<<"\n good Rabin
signature"<<std::endl;
        // Sign Away...
        CryptoPP::StringSource(message, msgLength, true,
            new CryptoPP::SignerFilter( rng, priv,
                new CryptoPP::HexEncoder(
                    new CryptoPP::StringSink(signedString)
                ) // HexEncoder
            ) // SignerFilter
        ); // StringSource
    }catch(CryptoPP::Exception& e){
        std::cerr << "Error: " << e.what() << std::endl;
        return "";
    }catch(...){
        std::cerr << "Unknown Error" << std::endl;
        return "";
    }

Both of Rabin key generation and signing are successful, however, the
verification procedure always gives "Unknown Error (signature can not
be verified!)" message.

The following code is for verifying Rabin's signature.
I tried to modify the code several ways many times.
Could you help me to correct it? Thank you.

// verify by Rabin
        byte *signatureX = (byte*)malloc(sizeof(byte)*10240);
        signatureX = (byte*)signedString.c_str();
        std::cout<<"rabin verify"<<std::endl;
        // to verify by Rabin
        try{
        std::string PublicKeyFile = "public.rabin";
        CryptoPP::FileSource pubFile(PublicKeyFile.c_str(), true,
                                     new CryptoPP::HexDecoder );
        CryptoPP::RabinSS<PSSR, SHA>::Verifier pub(pubFile);
        //CryptoPP::RabinSS<PSSR, SHA>::Verifier pub();
        std::cout<<pub.GetTrapdoorFunction().GetModulus();
        CryptoPP::StringSource SignatureString(signedString.c_str(),
true, NULL);

        // Sanity Check
        if (SignatureString.MaxRetrievable() != pub.SignatureLength())
{
            throw std::string( "Signature File Size Problem" );
        }
        CryptoPP::SecByteBlock signature(pub.SignatureLength());
        SignatureString.Get(signature, signature.size() );

        // Prepare Verifier
        CryptoPP::VerifierFilter *verifierFilter = new
CryptoPP::VerifierFilter(pub);
        verifierFilter->Put(signature, pub.SignatureLength());

        // Invoke Verifier
        CryptoPP::StringSource(message, true, verifierFilter );

        // Paydirt
        if( false == verifierFilter->GetLastResult() ){
            throw std::string( "Signature Verification Failed" );
        }

        std::cout << "Signature Verified" << std::endl;
        return true;
    }catch( CryptoPP::Exception& e ){
        std::cerr << "Error: " << e.what() << std::endl;
        return false;
    }catch(...){
        std::cerr<<"Unknown Error (signature can not be verified!)"<<
std::endl;
        return false;
    }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to