blob: 34e824b73f8238aaf810b8ce344aba8916aa3ad7 [file] [log] [blame]
Paul Bakkerb0c19a42013-06-24 19:26:38 +02001/**
Paul Bakkerdcbfdcc2013-09-10 16:16:50 +02002 * \file pkcs5.h
Paul Bakkerb0c19a42013-06-24 19:26:38 +02003 *
4 * \brief PKCS#5 functions
5 *
6 * \author Mathias Olsson <mathias@kompetensum.com>
7 *
8 * Copyright (C) 2006-2013, 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_PKCS5_H
30#define POLARSSL_PKCS5_H
31
32#include <string.h>
33
Paul Bakker28144de2013-06-24 19:28:55 +020034#include "asn1.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +020035#include "md.h"
36
Paul Bakkerfa6a6202013-10-28 18:48:30 +010037#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakkerb0c19a42013-06-24 19:26:38 +020038#include <basetsd.h>
39typedef UINT32 uint32_t;
40#else
41#include <inttypes.h>
42#endif
43
Paul Bakker28144de2013-06-24 19:28:55 +020044#define POLARSSL_ERR_PKCS5_BAD_INPUT_DATA -0x3f80 /**< Bad input parameters to function. */
45#define POLARSSL_ERR_PKCS5_INVALID_FORMAT -0x3f00 /**< Unexpected ASN.1 data. */
46#define POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE -0x3e80 /**< Requested encryption or digest alg not available. */
47#define POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH -0x3e00 /**< Given private key password does not allow for correct decryption. */
48
49#define PKCS5_DECRYPT 0
50#define PKCS5_ENCRYPT 1
51
Paul Bakkerb0c19a42013-06-24 19:26:38 +020052#ifdef __cplusplus
53extern "C" {
54#endif
55
56/**
Paul Bakker28144de2013-06-24 19:28:55 +020057 * \brief PKCS#5 PBES2 function
58 *
59 * \param pbe_params the ASN.1 algorithm parameters
60 * \param mode either PKCS5_DECRYPT or PKCS5_ENCRYPT
61 * \param pwd password to use when generating key
Paul Bakkerdcbfdcc2013-09-10 16:16:50 +020062 * \param pwdlen length of password
Paul Bakker28144de2013-06-24 19:28:55 +020063 * \param data data to process
64 * \param datalen length of data
65 * \param output output buffer
66 *
67 * \returns 0 on success, or a PolarSSL error code if verification fails.
68 */
69int pkcs5_pbes2( asn1_buf *pbe_params, int mode,
70 const unsigned char *pwd, size_t pwdlen,
71 const unsigned char *data, size_t datalen,
72 unsigned char *output );
73
74/**
Paul Bakkerb0c19a42013-06-24 19:26:38 +020075 * \brief PKCS#5 PBKDF2 using HMAC
76 *
77 * \param ctx Generic HMAC context
78 * \param password Password to use when generating key
79 * \param plen Length of password
80 * \param salt Salt to use when generating key
81 * \param slen Length of salt
82 * \param iteration_count Iteration count
83 * \param key_length Length of generated key
84 * \param output Generated key. Must be at least as big as key_length
85 *
86 * \returns 0 on success, or a PolarSSL error code if verification fails.
87 */
88int pkcs5_pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
89 size_t plen, const unsigned char *salt, size_t slen,
90 unsigned int iteration_count,
91 uint32_t key_length, unsigned char *output );
92
93/**
94 * \brief Checkup routine
95 *
96 * \return 0 if successful, or 1 if the test failed
97 */
98int pkcs5_self_test( int verbose );
99
100#ifdef __cplusplus
101}
102#endif
103
104#endif /* pkcs5.h */