blob: 5a23150bce809919a14c1b8971bb2e7c8b920aae [file] [log] [blame]
Paul Bakkerf518b162012-08-23 13:03:18 +00001/**
2 * \file pbkdf2.h
3 *
4 * \brief Password-Based Key Derivation Function 2 (from PKCS#5)
5 *
6 * \author Mathias Olsson <mathias@kompetensum.com>
7 *
8 * Copyright (C) 2006-2012, Brainspark B.V.
9 *
10 * This file is part of PolarSSL (http://www.polarssl.org)
11 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
12 *
13 * All rights reserved.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 */
29#ifndef POLARSSL_PBKDF2_H
30#define POLARSSL_PBKDF2_H
31
32#include <string.h>
33
34#include "md.h"
35
36#define POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA -0x007C /**< Bad input parameters to function. */
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/**
43 * \brief PKCS#5 PBKDF2 using HMAC
44 *
45 * \param ctx Generic HMAC context
46 * \param password Password to use when generating key
47 * \param plen Length of password
48 * \param salt Salt to use when generating key
49 * \param slen Length of salt
50 * \param iteration_count Iteration count
51 * \param key_length Length of generated key
52 * \param output Generated key. Must be at least as big as key_length
53 *
54 * \returns 0 on success, or a PolarSSL error code if verification fails.
55 */
56int pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
57 size_t plen, const unsigned char *salt, size_t slen,
58 unsigned int iteration_count,
59 unsigned long key_length, unsigned char *output );
60
61
62/**
63 * \brief Checkup routine
64 *
65 * \return 0 if successful, or 1 if the test failed
66 */
67int pbkdf2_self_test( int verbose );
68
69#ifdef __cplusplus
70}
71#endif
72
73#endif /* pbkdf2.h */