2
2
* GCRYPT crypto backend implementation
4
4
* Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* version 2 as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
5
* Copyright (C) 2010-2012, Milan Broz
7
* This file is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This file is distributed in the hope that it will be useful,
11
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this file; if not, write to the Free Software
17
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
258
int crypt_pbkdf(const char *kdf, const char *hash,
259
const char *password, size_t password_length,
260
const char *salt, size_t salt_length,
261
char *key, size_t key_length,
262
unsigned int iterations)
264
#if USE_INTERNAL_PBKDF2
265
if (!kdf || strncmp(kdf, "pbkdf2", 6))
268
return pkcs5_pbkdf2(hash, password, password_length, salt, salt_length,
269
iterations, key_length, key);
271
#else /* USE_INTERNAL_PBKDF2 */
272
int hash_id = gcry_md_map_name(hash);
278
if (kdf && !strncmp(kdf, "pbkdf2", 6))
279
kdf_id = GCRY_KDF_PBKDF2;
283
if (gcry_kdf_derive(password, password_length, kdf_id, hash_id,
284
salt, salt_length, iterations, key_length, key))
288
#endif /* USE_INTERNAL_PBKDF2 */