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 /* md5.h
igrokhotkov 0:83f3dcfa5c8f 2 *
igrokhotkov 0:83f3dcfa5c8f 3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
igrokhotkov 0:83f3dcfa5c8f 4 *
igrokhotkov 0:83f3dcfa5c8f 5 * This file is part of CyaSSL.
igrokhotkov 0:83f3dcfa5c8f 6 *
igrokhotkov 0:83f3dcfa5c8f 7 * CyaSSL is free software; you can redistribute it and/or modify
igrokhotkov 0:83f3dcfa5c8f 8 * it under the terms of the GNU General Public License as published by
igrokhotkov 0:83f3dcfa5c8f 9 * the Free Software Foundation; either version 2 of the License, or
igrokhotkov 0:83f3dcfa5c8f 10 * (at your option) any later version.
igrokhotkov 0:83f3dcfa5c8f 11 *
igrokhotkov 0:83f3dcfa5c8f 12 * CyaSSL is distributed in the hope that it will be useful,
igrokhotkov 0:83f3dcfa5c8f 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
igrokhotkov 0:83f3dcfa5c8f 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
igrokhotkov 0:83f3dcfa5c8f 15 * GNU General Public License for more details.
igrokhotkov 0:83f3dcfa5c8f 16 *
igrokhotkov 0:83f3dcfa5c8f 17 * You should have received a copy of the GNU General Public License
igrokhotkov 0:83f3dcfa5c8f 18 * along with this program; if not, write to the Free Software
igrokhotkov 0:83f3dcfa5c8f 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
igrokhotkov 0:83f3dcfa5c8f 20 */
igrokhotkov 0:83f3dcfa5c8f 21
igrokhotkov 0:83f3dcfa5c8f 22 #ifndef NO_MD5
igrokhotkov 0:83f3dcfa5c8f 23
igrokhotkov 0:83f3dcfa5c8f 24 #ifndef CTAO_CRYPT_MD5_H
igrokhotkov 0:83f3dcfa5c8f 25 #define CTAO_CRYPT_MD5_H
igrokhotkov 0:83f3dcfa5c8f 26
igrokhotkov 0:83f3dcfa5c8f 27 #include "types.h"
igrokhotkov 0:83f3dcfa5c8f 28
igrokhotkov 0:83f3dcfa5c8f 29 #ifdef __cplusplus
igrokhotkov 0:83f3dcfa5c8f 30 extern "C" {
igrokhotkov 0:83f3dcfa5c8f 31 #endif
igrokhotkov 0:83f3dcfa5c8f 32
igrokhotkov 0:83f3dcfa5c8f 33
igrokhotkov 0:83f3dcfa5c8f 34 /* in bytes */
igrokhotkov 0:83f3dcfa5c8f 35 enum {
igrokhotkov 0:83f3dcfa5c8f 36 #ifdef STM32F2_CRYPTO
igrokhotkov 0:83f3dcfa5c8f 37 MD5_REG_SIZE = 4, /* STM32 register size, bytes */
igrokhotkov 0:83f3dcfa5c8f 38 #endif
igrokhotkov 0:83f3dcfa5c8f 39 MD5 = 0, /* hash type unique */
igrokhotkov 0:83f3dcfa5c8f 40 MD5_BLOCK_SIZE = 64,
igrokhotkov 0:83f3dcfa5c8f 41 MD5_DIGEST_SIZE = 16,
igrokhotkov 0:83f3dcfa5c8f 42 MD5_PAD_SIZE = 56
igrokhotkov 0:83f3dcfa5c8f 43 };
igrokhotkov 0:83f3dcfa5c8f 44
igrokhotkov 0:83f3dcfa5c8f 45
igrokhotkov 0:83f3dcfa5c8f 46 /* MD5 digest */
igrokhotkov 0:83f3dcfa5c8f 47 typedef struct Md5 {
igrokhotkov 0:83f3dcfa5c8f 48 word32 buffLen; /* in bytes */
igrokhotkov 0:83f3dcfa5c8f 49 word32 loLen; /* length in bytes */
igrokhotkov 0:83f3dcfa5c8f 50 word32 hiLen; /* length in bytes */
igrokhotkov 0:83f3dcfa5c8f 51 word32 digest[MD5_DIGEST_SIZE / sizeof(word32)];
igrokhotkov 0:83f3dcfa5c8f 52 word32 buffer[MD5_BLOCK_SIZE / sizeof(word32)];
igrokhotkov 0:83f3dcfa5c8f 53 } Md5;
igrokhotkov 0:83f3dcfa5c8f 54
igrokhotkov 0:83f3dcfa5c8f 55
igrokhotkov 0:83f3dcfa5c8f 56 CYASSL_API void InitMd5(Md5*);
igrokhotkov 0:83f3dcfa5c8f 57 CYASSL_API void Md5Update(Md5*, const byte*, word32);
igrokhotkov 0:83f3dcfa5c8f 58 CYASSL_API void Md5Final(Md5*, byte*);
igrokhotkov 0:83f3dcfa5c8f 59
igrokhotkov 0:83f3dcfa5c8f 60
igrokhotkov 0:83f3dcfa5c8f 61 #ifdef __cplusplus
igrokhotkov 0:83f3dcfa5c8f 62 } /* extern "C" */
igrokhotkov 0:83f3dcfa5c8f 63 #endif
igrokhotkov 0:83f3dcfa5c8f 64
igrokhotkov 0:83f3dcfa5c8f 65 #endif /* CTAO_CRYPT_MD5_H */
igrokhotkov 0:83f3dcfa5c8f 66 #endif /* NO_MD5 */