1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
13
/* PKCS #5, Algorithm #1 */
16
int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
17
const unsigned char *salt,
18
int iteration_count, int hash_idx,
19
unsigned char *out, unsigned long *outlen)
26
_ARGCHK(password != NULL);
27
_ARGCHK(salt != NULL);
29
_ARGCHK(outlen != NULL);
32
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
37
md = XMALLOC(sizeof(hash_state));
38
buf = XMALLOC(MAXBLOCKSIZE);
39
if (md == NULL || buf == NULL) {
49
/* hash initial password + salt */
50
if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
53
if ((err = hash_descriptor[hash_idx].process(md, password, password_len)) != CRYPT_OK) {
56
if ((err = hash_descriptor[hash_idx].process(md, salt, 8)) != CRYPT_OK) {
59
if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
63
while (--iteration_count) {
66
if ((err = hash_memory(hash_idx, buf, hash_descriptor[hash_idx].hashsize, buf, &x)) != CRYPT_OK) {
71
/* copy upto outlen bytes */
72
for (x = 0; x < hash_descriptor[hash_idx].hashsize && x < *outlen; x++) {
79
zeromem(buf, MAXBLOCKSIZE);
80
zeromem(md, sizeof(hash_state));