Francois Berder / Crypto

Dependents:   mBuinoBlinky PB_Emma_Ethernet SLOTrashHTTP Garagem ... more

You are viewing an older revision! See the latest version

Homepage

Table of Contents

  1. Computing hash

This library implements the following algorithms :

  • RC4
  • AES (AES-128, AES-192, AES-256)
  • MD2
  • MD5
  • SHA-1
  • SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512)

TODO

  • implement DES and 3DES (currently working on it)
  • implement HMAC (HMAC-MD5, HMAC-SHA1, HMA-SHA256)

Computing hash

You can compute the hash of some data in two different ways. The first one is the easiest, each hash algorithm has a static method that takes some data and compute the hash from it.

Computing hash using method 1

#include "Crypto.h"
#include "mbed.h"

static const char msg[] = "mbed is great !";

int main()
{
    uint8_t digest[16];
    MD2::computeDigest(digest, (uint8_t*)msg, strlen(msg));
    printf("digest: ");
    for(int i = 0; i < 16; ++i)
        printf("%02x", digest[i]);
    printf("\n");
    
    return 0;
}

The second one is slightly slower but it computes the hash as you get it.

Computing hash using method 1

#include "Crypto.h"
#include "mbed.h"

static const char msg[] = "mbed is great !";

int main()
{
    uint8_t digest[16];
    MD2 h;
    h.add((uint8_t*)msg, strlen(msg));
    h.computeDigest(digest);
    printf("digest: ");
    for(int i = 0; i < 16; ++i)
        printf("%02x", digest[i]);
    printf("\n");
    
    return 0;
}

All wikipages