On Thu, Jan 24, 2019 at 8:28 AM Olli Savolainen
<[email protected]> wrote:
>
> Oh thanks, that actually seems to work. I had just forgotten the using 
> directive so it seemed like SHA256 enum value didn't seem to work.
> Just curious, why is SHA3 different, or have I just messed up somehow?

It is probably you, but we can't seem to get you to provide your code
so we are left to speculate and guess.

Works for me...

$ cat test.cxx
#include "rsa.h"
#include "osrng.h"
#include "pssr.h"
#include "sha.h"
#include "sha3.h"

#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
    using namespace CryptoPP;

    try
    {
        ////////////////////////////////////////////////
        // Generate keys
        AutoSeededRandomPool rng;

        InvertibleRSAFunction params;
        params.GenerateRandomWithKeySize(rng, 3072);

        RSA::PrivateKey privateKey(params);
        RSA::PublicKey publicKey(params);

        // Signing
        //RSASS<PSSR, SHA256>::Signer signer(privateKey);
        //RSASS<PSSR, SHA256>::Verifier verifier(publicKey);
        RSASS<PSSR, SHA3_256>::Signer signer(privateKey);
        RSASS<PSSR, SHA3_256>::Verifier verifier(publicKey);

        // Setup
        byte message[] = "RSA-PSSR Test";
        size_t messageLen = sizeof(message);

        ////////////////////////////////////////////////
        // Sign and Encode
        SecByteBlock signature(signer.MaxSignatureLength(messageLen));

        size_t signatureLen = signer.SignMessageWithRecovery(rng, message,
            messageLen, NULL, 0, signature);

        // Resize now we know the true size of the signature
        signature.resize(signatureLen);

        ////////////////////////////////////////////////
        // Verify and Recover
        SecByteBlock recovered(
            verifier.MaxRecoverableLengthFromSignatureLength(signatureLen)
        );

        DecodingResult result = verifier.RecoverMessage(recovered, NULL,
            0, signature, signatureLen);

        if (!result.isValidCoding) {
            throw Exception(Exception::OTHER_ERROR, "Invalid Signature");
        }

        ////////////////////////////////////////////////
        // Use recovered message
        //  MaxSignatureLength is likely larger than messageLength
        recovered.resize(result.messageLength);

        std::string rec((const char*)recovered.begin(), recovered.size());
        std::cout << rec << std::endl;
    }
    catch(const Exception& ex)
    {
        std::cerr << ex.what() << std::endl;
        return 1;
    }

    return 0;
}

-- 
You received this message because you are subscribed to "Crypto++ Users". More 
information about Crypto++ and this group is available at 
http://www.cryptopp.com and 
http://groups.google.com/forum/#!forum/cryptopp-users.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to