# HMAC_Init_ex is return type void



## tuaris (Nov 7, 2014)

I'm trying to port some software over to FreeBSD 9.3, but I'm getting an error with the following section of code that uses the openssl/hmac.h library:


```
if (!HMAC_Init_ex(&ctx, &civ[0], 32, EVP_sha256(), NULL)
        || !HMAC_Update(&ctx, (unsigned char*) pHeader+4, SMSG_HDR_LEN-4)
        || !HMAC_Update(&ctx, (unsigned char*) pPayload, nPayload)
        || !HMAC_Update(&ctx, pPayload, nPayload)
        || !HMAC_Final(&ctx, sha256Hash, &nBytes)
        || nBytes != 32)
    {
```


```
could not convert 'HMAC_Init_ex((& ctx), ((const void*)(& civ[0])), 32, EVP_sha256(), 0u)' to 'bool'
```

and so on...

According to this page, https://www.freebsd.org/cgi/man.cgi?query=hmacapropos=0&sektion=3&manpath=FreeBSD 9.3-RELEASE&arch=default&format=html,  those functions are indeed void for FreeBSD 9.x.  However, in FreeBSD 10 (and other platforms), they are int: https://www.freebsd.org/cgi/man.cgi?query=hmac&apropos=0&sektion=3&manpath=FreeBSD 10.0-RELEASE&arch=default&format=html.

What changes can I make to the above code to have it compile? Note that I'm not very experienced with C/C++.


----------



## fonz (Nov 9, 2014)

The difference is that on 10.x they return 1 for success or 0 for failure, while on 9.x they do not return at all. So, assuming that the code inside the curly braces that comes after it is error handling code, I'd change

```
if (!HMAC_Init_ex(&ctx, &civ[0], 32, EVP_sha256(), NULL)
|| !HMAC_Update(&ctx, (unsigned char*) pHeader+4, SMSG_HDR_LEN-4)
|| !HMAC_Update(&ctx, (unsigned char*) pPayload, nPayload)
|| !HMAC_Update(&ctx, pPayload, nPayload)
|| !HMAC_Final(&ctx, sha256Hash, &nBytes)
|| nBytes != 32)
{
```
into

```
HMAC_Init_ex(&ctx, &civ[0], 32, EVP_sha256(), NULL);
HMAC_Update(&ctx, (unsigned char*) pHeader+4, SMSG_HDR_LEN-4);
HMAC_Update(&ctx, (unsigned char*) pPayload, nPayload);
HMAC_Update(&ctx, pPayload, nPayload);
HMAC_Final(&ctx, sha256Hash, &nBytes);
if (nBytes != 32)
{
```
Disclaimer: I haven't tested it, though!


----------

