36 #if defined(PBKDF2_ALG_NAME)
38 #define PBKDF2_CONCAT_INNER(name,suffix) name##suffix
39 #define PBKDF2_CONCAT(name,suffix) PBKDF2_CONCAT_INNER(name,suffix)
42 static void PBKDF2_CONCAT(PBKDF2_ALG_NAME,_f)
43 (PBKDF2_HMAC_STATE *state,
unsigned char *T,
unsigned char *U,
44 const unsigned char *password,
size_t passwordlen,
45 const unsigned char *salt,
size_t saltlen,
46 unsigned long count,
unsigned long blocknum)
49 be_store_word32(b, blocknum);
50 PBKDF2_HMAC_INIT(state, password, passwordlen);
51 PBKDF2_HMAC_UPDATE(state, salt, saltlen);
52 PBKDF2_HMAC_UPDATE(state, b,
sizeof(b));
53 PBKDF2_HMAC_FINALIZE(state, password, passwordlen, T);
55 PBKDF2_HMAC_INIT(state, password, passwordlen);
56 PBKDF2_HMAC_UPDATE(state, T, PBKDF2_HMAC_SIZE);
57 PBKDF2_HMAC_FINALIZE(state, password, passwordlen, U);
58 lw_xor_block(T, U, PBKDF2_HMAC_SIZE);
60 PBKDF2_HMAC_INIT(state, password, passwordlen);
61 PBKDF2_HMAC_UPDATE(state, U, PBKDF2_HMAC_SIZE);
62 PBKDF2_HMAC_FINALIZE(state, password, passwordlen, U);
63 lw_xor_block(T, U, PBKDF2_HMAC_SIZE);
70 (
unsigned char *out,
size_t outlen,
71 const unsigned char *password,
size_t passwordlen,
72 const unsigned char *salt,
size_t saltlen,
unsigned long count)
74 PBKDF2_HMAC_STATE state;
75 unsigned char U[PBKDF2_HMAC_SIZE];
76 unsigned long blocknum = 1;
78 if (outlen >= PBKDF2_HMAC_SIZE) {
79 PBKDF2_CONCAT(PBKDF2_ALG_NAME,_f)
80 (&state, out, U, password, passwordlen,
81 salt, saltlen, count, blocknum);
82 out += PBKDF2_HMAC_SIZE;
83 outlen -= PBKDF2_HMAC_SIZE;
85 unsigned char T[PBKDF2_HMAC_SIZE];
86 PBKDF2_CONCAT(PBKDF2_ALG_NAME,_f)
87 (&state, T, U, password, passwordlen,
88 salt, saltlen, count, blocknum);
89 memcpy(out, T, outlen);
90 aead_clean(T,
sizeof(T));
95 aead_clean(&state,
sizeof(state));
96 aead_clean(U,
sizeof(U));
103 #undef PBKDF2_ALG_NAME
104 #undef PBKDF2_HMAC_SIZE
105 #undef PBKDF2_HMAC_STATE
106 #undef PBKDF2_HMAC_INIT
107 #undef PBKDF2_HMAC_UPDATE
108 #undef PBKDF2_HMAC_FINALIZE