This library implements some hash and cryptographic algorithms.

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
  2. TODO

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)

The hash algorithms have been optimized for the mbed and you should get decent performance. However, I did not optimize the ciphers.

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 (around 2-3% slower) but it allows you to compute the hash of some data in several steps (by calling add function). This is the method you should use if you need to compute the hash from a large source and you don't have enough memory to store it in a single buffer.

Computing hash using method 2

#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;
}

TODO

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

All wikipages