how to EVP_SignInit_ex() ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to EVP_SignInit_ex() ?

coco coco
Sorry if this is a dumb question, I'm not sure why EVP_SignInit_ext() is
giving me unhandled exception error. My code is a very simple testing code:

        char * clearText = "testing openssl";
        char cryptText[MAX_LEN];
        char buf[MAX_LEN];
        unsigned char ubuf[MAX_LEN];
        unsigned char sig[MAX_LEN];
        unsigned int sigLen;

        EVP_PKEY key;
        EVP_MD_CTX sctx, vctx;

        int ret = EVP_PKEY_assign_RSA(&key, RSA_generate_key(1024, RSA_3, 0, 0));
        if (ret != 1)
                std::cout << "Generate rsa key failed..." << std::endl;

        EVP_SignInit_ex(&sctx, EVP_sha1(), NULL);
        EVP_SignUpdate(&sctx, clearText, strlen(clearText));
        memset(sig, 0, MAX_LEN);
        ret = EVP_SignFinal(&sctx, sig, &sigLen, &key);
        if (ret != 1)
                std::cout << "Signing failed..." << std::endl;

        EVP_VerifyInit_ex(&vctx, EVP_sha1(), NULL);
        EVP_VerifyUpdate(&vctx, clearText, strlen(clearText));
        ret = EVP_VerifyFinal(&vctx, sig, sigLen, &key);
        if (ret == 1)
                std::cout << "Signature is valid" << std::endl;
        else if (ret == 0)
                std::cout << "Signature is invalid..." << std::endl;
        else
                std::cout << "Verification failed..." << std::endl;

Everytime I get to EVP_SignInit_ex(), I get the error:

Unhandled exception at 0x1003dee6 in test.exe: 0xC0000005: Access violation
reading location 0xcccccccc.

This code is basically copied from the sample. Is there anyting I need to
initialize before that as well?

thanks in advance

cc

_________________________________________________________________
Don?t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: how to EVP_SignInit_ex() ?

Nils Larsch
coco coco wrote:

> Sorry if this is a dumb question, I'm not sure why EVP_SignInit_ext() is
> giving me unhandled exception error. My code is a very simple testing code:
>
>     char * clearText = "testing openssl";
>     char cryptText[MAX_LEN];
>     char buf[MAX_LEN];
>     unsigned char ubuf[MAX_LEN];
>     unsigned char sig[MAX_LEN];
>     unsigned int sigLen;
>
>     EVP_PKEY key;
>     EVP_MD_CTX sctx, vctx;
>
>     int ret = EVP_PKEY_assign_RSA(&key, RSA_generate_key(1024, RSA_3, 0,
> 0));
>     if (ret != 1)
>         std::cout << "Generate rsa key failed..." << std::endl;
>
>     EVP_SignInit_ex(&sctx, EVP_sha1(), NULL);
>     EVP_SignUpdate(&sctx, clearText, strlen(clearText));
>     memset(sig, 0, MAX_LEN);
>     ret = EVP_SignFinal(&sctx, sig, &sigLen, &key);
>     if (ret != 1)
>         std::cout << "Signing failed..." << std::endl;
...
> Everytime I get to EVP_SignInit_ex(), I get the error:
>
> Unhandled exception at 0x1003dee6 in test.exe: 0xC0000005: Access
> violation reading location 0xcccccccc.

try a EVP_MD_CTX_init() before using the EVP_MD_CTX objects

Nils
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: how to EVP_SignInit_ex() ?

coco coco
>
>try a EVP_MD_CTX_init() before using the EVP_MD_CTX objects
>

Thanks, not very familiar with openssl at all, this is the first time trying
to get
something quickly done with openssl.

Is there any developer guide, like giving better description of the API
provided by openssl, beside the O'Reilly book? It doesn't have to be
tutorial, I'm quite ok with crypto stuff in Java, but using openssl
has been a try-and-error process so far, and constantly need to
dive into the openssl code itself.

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: how to EVP_SignInit_ex() ?

Heikki Toivonen
coco coco wrote:
> Is there any developer guide, like giving better description of the API
> provided by openssl, beside the O'Reilly book? It doesn't have to be
> tutorial, I'm quite ok with crypto stuff in Java, but using openssl
> has been a try-and-error process so far, and constantly need to
> dive into the openssl code itself.

Then man pages/web pages. Incomplete, and sometimes hard to find, but
when you do find a documented function it is usually documented enough
to get you going. Start from http://www.openssl.org/docs/

Also the OpenSSL mailinglist archives (search) and general web searches
help.

There are also some tutorials/samples in the code.

--
  Heikki Toivonen


signature.asc (257 bytes) Download Attachment