Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mBuinoBlinky PB_Emma_Ethernet SLOTrashHTTP Garagem ... more
You are viewing an older revision! See the latest version
Homepage
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)
- implement HMAC (HMAC-MD5, HMAC-SHA1, HMA-SHA256)