BeRTOS
util.c
Go to the documentation of this file.
00001 
00038 #include "util.h"
00039 #include <sec/kdf/pbkdf2.h>
00040 #include <sec/mac/hmac.h>
00041 #include <sec/hash/sha1.h>
00042 
00043 // FIXME: this macros should be generated by the wizard
00044 #define BERTOS_PROJECT_NAME   "bertos_project"
00045 
00046 #define SALT   (BERTOS_PROJECT_NAME "P2K_SALT")
00047 
00048 void password2key(const char *pwd, size_t pwd_len,
00049                   uint8_t *key, size_t key_len)
00050 {
00051     Kdf *kdf = PBKDF2_stackinit(hmac_stackinit(SHA1_stackinit()));
00052 
00053     kdf_begin(kdf, pwd, pwd_len, (uint8_t*)SALT, sizeof(SALT));
00054     kdf_read(kdf, key, key_len);
00055 
00056     // FIXME: how to purge the stack?
00057 }