> From: Jakob Bohm [mailto:jb-open...@wisemo.com]
> Sent: Tuesday, November 15, 2011 2:28 PM
> 
> On 11/15/2011 11:39 AM, Henrik Grindal Bakken wrote:
> > Jonas Schnelli
> > <jonas.schne...@include7.ch>  writes:
> >
> >>> #include<openssl-1.0.0e/include/openssl/hmac.h>
> >>> #include<openssl-1.0.0e/include/openssl/evp.h>
> >>> #include<string.h>
> >>>
> >>> char  key[20] = { 0 };
> >>>
> >>> int
> >>> main()
> >>> {
> >>>     HMAC_CTX *  context;
> >>>
> >>>     context = (HMAC_CTX *) malloc(sizeof(*context));
> >>
> >> Do you need to malloc the context (a pointer) ?
> >> I don't think so.
> >> Remove the line?
> >
> > That won't work, but you can do
> >       HMAC_CTX context;
> >
> > and use&context instead of context.
>
> Why would that be any different?
> 
> When OpenSSL gets a HMAC_CTX*, it shouldn't care if it points to
> memory on the stack or the heap, as long as that memory is
> sizeof(HMAC_CTX) big and maybe appropriately initialized.

Err ... yes, that's the point. The original code used malloc to allocate memory 
for an HMAC_CTX, and did it right (apart from not checking that malloc 
succeeded). Henrik's version allocated memory for an HMAC_CTX structure 
automatically, and was equally right. Jonas's version didn't allocate memory 
for an HMAC_CTX at all, and passed an uninitialized pointer to subsequent 
function calls instead of a pointer to an HMAC_CTX.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to