Mercurial > dropbear
comparison libtomcrypt/src/misc/pkcs5/pkcs_5_2.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include <tomcrypt.h> | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file pkcs_5_2.c | 12 @file pkcs_5_2.c |
15 LTC_PKCS #5, Algorithm #2, Tom St Denis | 13 PKCS #5, Algorithm #2, Tom St Denis |
16 */ | 14 */ |
17 #ifdef LTC_PKCS_5 | 15 #ifdef LTC_PKCS_5 |
18 | 16 |
19 /** | 17 /** |
20 Execute LTC_PKCS #5 v2 | 18 Execute PKCS #5 v2 |
21 @param password The input password (or key) | 19 @param password The input password (or key) |
22 @param password_len The length of the password (octets) | 20 @param password_len The length of the password (octets) |
23 @param salt The salt (or nonce) | 21 @param salt The salt (or nonce) |
24 @param salt_len The length of the salt (octets) | 22 @param salt_len The length of the salt (octets) |
25 @param iteration_count # of iterations desired for LTC_PKCS #5 v2 [read specs for more] | 23 @param iteration_count # of iterations desired for PKCS #5 v2 [read specs for more] |
26 @param hash_idx The index of the hash desired | 24 @param hash_idx The index of the hash desired |
27 @param out [out] The destination for this algorithm | 25 @param out [out] The destination for this algorithm |
28 @param outlen [in/out] The max size and resulting size of the algorithm output | 26 @param outlen [in/out] The max size and resulting size of the algorithm output |
29 @return CRYPT_OK if successful | 27 @return CRYPT_OK if successful |
30 */ | 28 */ |
31 int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, | 29 int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, |
32 const unsigned char *salt, unsigned long salt_len, | 30 const unsigned char *salt, unsigned long salt_len, |
33 int iteration_count, int hash_idx, | 31 int iteration_count, int hash_idx, |
34 unsigned char *out, unsigned long *outlen) | 32 unsigned char *out, unsigned long *outlen) |
35 { | 33 { |
36 int err, itts; | 34 int err, itts; |
67 blkno = 1; | 65 blkno = 1; |
68 stored = 0; | 66 stored = 0; |
69 while (left != 0) { | 67 while (left != 0) { |
70 /* process block number blkno */ | 68 /* process block number blkno */ |
71 zeromem(buf[0], MAXBLOCKSIZE*2); | 69 zeromem(buf[0], MAXBLOCKSIZE*2); |
72 | 70 |
73 /* store current block number and increment for next pass */ | 71 /* store current block number and increment for next pass */ |
74 STORE32H(blkno, buf[1]); | 72 STORE32H(blkno, buf[1]); |
75 ++blkno; | 73 ++blkno; |
76 | 74 |
77 /* get PRF(P, S||int(blkno)) */ | 75 /* get PRF(P, S||int(blkno)) */ |
78 if ((err = hmac_init(hmac, hash_idx, password, password_len)) != CRYPT_OK) { | 76 if ((err = hmac_init(hmac, hash_idx, password, password_len)) != CRYPT_OK) { |
79 goto LBL_ERR; | 77 goto LBL_ERR; |
80 } | 78 } |
81 if ((err = hmac_process(hmac, salt, salt_len)) != CRYPT_OK) { | 79 if ((err = hmac_process(hmac, salt, salt_len)) != CRYPT_OK) { |
82 goto LBL_ERR; | 80 goto LBL_ERR; |
83 } | 81 } |
122 } | 120 } |
123 | 121 |
124 #endif | 122 #endif |
125 | 123 |
126 | 124 |
127 /* $Source$ */ | 125 /* ref: $Format:%D$ */ |
128 /* $Revision$ */ | 126 /* git commit: $Format:%H$ */ |
129 /* $Date$ */ | 127 /* commit time: $Format:%ai$ */ |