This library implements some hash and cryptographic algorithms.
Dependents: mBuinoBlinky PB_Emma_Ethernet SLOTrashHTTP Garagem ... more
This library implements the following algorithms :
- RC4
- AES (AES-128, AES-192, AES-256)
- DES
- Triple DES (EDE)
- MD2
- MD4
- 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. Also, I did not test extensively these algorithms : it should work but you may find some bugs. Block ciphers support two modes : ECB and CBC.
Warning
If you are using SHA-384 or SHA-512, be aware that it produces large binary files and the compilation (using the online compiler) takes much longer to execute. It may happen that the compiler stops because it timed-out. In this case, just compile again and it should work.
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 hash[16]; MD2::computeHash(hash, (uint8_t*)msg, strlen(msg)); printf("hash: "); for(int i = 0; i < 16; ++i) printf("%02x", hash[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 update method). 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 hash[16]; MD2 h; h.update((uint8_t*)msg, strlen(msg)); h.finalize(hash); printf("hash: "); for(int i = 0; i < 16; ++i) printf("%02x", hash[i]); printf("\n"); return 0; }
TODO
- optimize ciphers
- add doc
History
CBC mode completed
2014-05-11, by feb11 [Sun, 11 May 2014 13:36:45 +0000] rev 14
CBC mode completed
fixed warnings + fixed errors if compiling with gcc arm compiler
2014-05-11, by feb11 [Sun, 11 May 2014 11:14:51 +0000] rev 13
fixed warnings + fixed errors if compiling with gcc arm compiler
removed mbed library
2014-04-08, by feb11 [Tue, 08 Apr 2014 19:39:25 +0000] rev 12
removed mbed library
fixed bug in HMAC
2013-10-02, by feb11 [Wed, 02 Oct 2013 16:39:00 +0000] rev 11
fixed bug in HMAC
implemented HMAC
2013-09-24, by feb11 [Tue, 24 Sep 2013 07:19:04 +0000] rev 10
implemented HMAC
implemented MD4
2013-09-16, by feb11 [Mon, 16 Sep 2013 08:35:36 +0000] rev 9
implemented MD4
refactored public API for ciphers & added TDES
2013-09-14, by feb11 [Sat, 14 Sep 2013 20:54:59 +0000] rev 8
refactored public API for ciphers & added TDES
added DES (not tested yet)
2013-09-14, by feb11 [Sat, 14 Sep 2013 18:21:32 +0000] rev 7
added DES (not tested yet)
change public API for hash + small improvements for hash + rearrange code
2013-09-12, by feb11 [Thu, 12 Sep 2013 16:03:43 +0000] rev 6
change public API for hash + small improvements for hash + rearrange code
change API & small improvements in SHA-2
2013-09-12, by feb11 [Thu, 12 Sep 2013 15:08:51 +0000] rev 5
change API & small improvements in SHA-2