blob: 4bd5018af539eb54ce1ed0c2c105dac165ebe436 [file] [log] [blame]
Paul Bakkerf1f21fe2013-06-24 19:17:19 +02001/**
2 * \file pkcs12.h
3 *
4 * \brief PKCS#12 Personal Information Exchange Syntax
5 *
6 * Copyright (C) 2006-2013, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_PKCS12_H
28#define POLARSSL_PKCS12_H
29
30#include <string.h>
31
32#include "md.h"
Paul Bakker38b50d72013-06-24 19:33:27 +020033#include "cipher.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020034#include "asn1.h"
35
36#define POLARSSL_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
37#define POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
38#define POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
Paul Bakker38b50d72013-06-24 19:33:27 +020039#define POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020040
Paul Bakkera36d23e2013-12-30 17:57:27 +010041#define PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
42#define PKCS12_DERIVE_IV 2 /**< initialization vector */
43#define PKCS12_DERIVE_MAC_KEY 3 /**< integrity / MAC key */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020044
Paul Bakker38b50d72013-06-24 19:33:27 +020045#define PKCS12_PBE_DECRYPT 0
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020046#define PKCS12_PBE_ENCRYPT 1
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020047
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020048#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * \brief PKCS12 Password Based function (encryption / decryption)
54 * for pbeWithSHAAnd128BitRC4
55 *
56 * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
57 * \param mode either PKCS12_PBE_ENCRYPT or PKCS12_PBE_DECRYPT
58 * \param pwd the password used (may be NULL if no password is used)
59 * \param pwdlen length of the password (may be 0)
60 * \param input the input data
61 * \param len data length
62 * \param output the output buffer
Paul Bakker38b50d72013-06-24 19:33:27 +020063 *
64 * \return 0 if successful, or a PolarSSL error code
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020065 */
66int pkcs12_pbe_sha1_rc4_128( asn1_buf *pbe_params, int mode,
67 const unsigned char *pwd, size_t pwdlen,
68 const unsigned char *input, size_t len,
69 unsigned char *output );
70
71/**
72 * \brief PKCS12 Password Based function (encryption / decryption)
Paul Bakker38b50d72013-06-24 19:33:27 +020073 * for cipher-based and md-based PBE's
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020074 *
75 * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
76 * \param mode either PKCS12_PBE_ENCRYPT or PKCS12_PBE_DECRYPT
Paul Bakker38b50d72013-06-24 19:33:27 +020077 * \param cipher_type the cipher used
78 * \param md_type the md used
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020079 * \param pwd the password used (may be NULL if no password is used)
80 * \param pwdlen length of the password (may be 0)
81 * \param input the input data
82 * \param len data length
83 * \param output the output buffer
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020084 *
Paul Bakker38b50d72013-06-24 19:33:27 +020085 * \return 0 if successful, or a PolarSSL error code
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020086 */
Paul Bakker38b50d72013-06-24 19:33:27 +020087int pkcs12_pbe( asn1_buf *pbe_params, int mode,
88 cipher_type_t cipher_type, md_type_t md_type,
89 const unsigned char *pwd, size_t pwdlen,
90 const unsigned char *input, size_t len,
91 unsigned char *output );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020092
93/**
94 * \brief The PKCS#12 derivation function uses a password and a salt
95 * to produce pseudo-random bits for a particular "purpose".
96 *
97 * Depending on the given id, this function can produce an
98 * encryption/decryption key, an nitialization vector or an
99 * integrity key.
100 *
101 * \param data buffer to store the derived data in
102 * \param datalen length to fill
103 * \param pwd password to use (may be NULL if no password is used)
104 * \param pwdlen length of the password (may be 0)
105 * \param salt salt buffer to use
106 * \param saltlen length of the salt
107 * \param md md type to use during the derivation
108 * \param id id that describes the purpose (can be PKCS12_DERIVE_KEY,
109 * PKCS12_DERIVE_IV or PKCS12_DERIVE_MAC_KEY)
110 * \param iterations number of iterations
111 *
112 * \return 0 if successful, or a MD, BIGNUM type error.
113 */
114int pkcs12_derivation( unsigned char *data, size_t datalen,
115 const unsigned char *pwd, size_t pwdlen,
116 const unsigned char *salt, size_t saltlen,
117 md_type_t md, int id, int iterations );
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif /* pkcs12.h */