A simple CyaSSL-based HMAC-MD5 implementation. Licensed under GPL v2.

Dependents:   RFrec_full RFtrans_full

The output will be base64-encoded, with trailing "==", like this:

j62o/jZsAZD9i9m+32lIuQ==

Example

#include "mbed.h"
#include "hmac_md5.h"

Serial pc(USBTX, USBRX); // tx, rx

void main(void)
{
    
    const char * key = "MySecretKey";
    
    const char * text = "message to be signed";
    
    char output[26];
    
    HMAC_MD5(key, text, output);

    printf("result = %s\n", output);

    while(true){}
}
Committer:
igrokhotkov
Date:
Wed Feb 06 20:35:03 2013 +0000
Revision:
0:83f3dcfa5c8f
initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igrokhotkov 0:83f3dcfa5c8f 1 #include "hmac_md5.h"
igrokhotkov 0:83f3dcfa5c8f 2 #include "hmac.h"
igrokhotkov 0:83f3dcfa5c8f 3 #include "coding.h"
igrokhotkov 0:83f3dcfa5c8f 4
igrokhotkov 0:83f3dcfa5c8f 5 void HMAC_MD5(const char * szKey, const char * szText, char * szOutput)
igrokhotkov 0:83f3dcfa5c8f 6 {
igrokhotkov 0:83f3dcfa5c8f 7 Hmac hmac;
igrokhotkov 0:83f3dcfa5c8f 8 char hmacOutput[MD5_DIGEST_SIZE + 1];
igrokhotkov 0:83f3dcfa5c8f 9
igrokhotkov 0:83f3dcfa5c8f 10 HmacSetKey(&hmac, MD5, (const byte *) szKey, strlen(szKey));
igrokhotkov 0:83f3dcfa5c8f 11 HmacUpdate(&hmac, (const byte *) szText, strlen(szText));
igrokhotkov 0:83f3dcfa5c8f 12
igrokhotkov 0:83f3dcfa5c8f 13 HmacFinal(&hmac, (byte *) hmacOutput);
igrokhotkov 0:83f3dcfa5c8f 14
igrokhotkov 0:83f3dcfa5c8f 15 int encodedLength = 25;
igrokhotkov 0:83f3dcfa5c8f 16 Base64_Encode((const byte *) hmacOutput, MD5_DIGEST_SIZE, (byte *) szOutput, (word32*) &encodedLength);
igrokhotkov 0:83f3dcfa5c8f 17 szOutput[encodedLength] = 0;
igrokhotkov 0:83f3dcfa5c8f 18
igrokhotkov 0:83f3dcfa5c8f 19 }