blob: 0920cd1675542a0cd76183c182c64b16631755aa [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 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerf1f21fe2013-06-24 19:17:19 +02007 *
Manuel Pégourié-Gonnard860b5162015-01-28 17:12:07 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkerf1f21fe2013-06-24 19:17:19 +02009 *
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24#ifndef POLARSSL_PKCS12_H
25#define POLARSSL_PKCS12_H
26
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020027#include "md.h"
Paul Bakker38b50d72013-06-24 19:33:27 +020028#include "cipher.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020029#include "asn1.h"
30
Rich Evans00ab4702015-02-06 13:43:58 +000031#include <stddef.h>
32
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020033#define POLARSSL_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
34#define POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
35#define POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
Paul Bakker38b50d72013-06-24 19:33:27 +020036#define POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020037
Paul Bakkera36d23e2013-12-30 17:57:27 +010038#define PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
39#define PKCS12_DERIVE_IV 2 /**< initialization vector */
40#define PKCS12_DERIVE_MAC_KEY 3 /**< integrity / MAC key */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020041
Paul Bakker38b50d72013-06-24 19:33:27 +020042#define PKCS12_PBE_DECRYPT 0
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020043#define PKCS12_PBE_ENCRYPT 1
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020044
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020045#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * \brief PKCS12 Password Based function (encryption / decryption)
51 * for pbeWithSHAAnd128BitRC4
52 *
53 * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
54 * \param mode either PKCS12_PBE_ENCRYPT or PKCS12_PBE_DECRYPT
55 * \param pwd the password used (may be NULL if no password is used)
56 * \param pwdlen length of the password (may be 0)
57 * \param input the input data
58 * \param len data length
59 * \param output the output buffer
Paul Bakker38b50d72013-06-24 19:33:27 +020060 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +000061 * \return 0 if successful, or a POLARSSL_ERR_xxx code
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020062 */
63int pkcs12_pbe_sha1_rc4_128( asn1_buf *pbe_params, int mode,
64 const unsigned char *pwd, size_t pwdlen,
65 const unsigned char *input, size_t len,
66 unsigned char *output );
67
68/**
69 * \brief PKCS12 Password Based function (encryption / decryption)
Paul Bakker38b50d72013-06-24 19:33:27 +020070 * for cipher-based and md-based PBE's
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020071 *
72 * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
73 * \param mode either PKCS12_PBE_ENCRYPT or PKCS12_PBE_DECRYPT
Paul Bakker38b50d72013-06-24 19:33:27 +020074 * \param cipher_type the cipher used
75 * \param md_type the md used
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020076 * \param pwd the password used (may be NULL if no password is used)
77 * \param pwdlen length of the password (may be 0)
78 * \param input the input data
79 * \param len data length
80 * \param output the output buffer
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020081 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +000082 * \return 0 if successful, or a POLARSSL_ERR_xxx code
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020083 */
Paul Bakker38b50d72013-06-24 19:33:27 +020084int pkcs12_pbe( asn1_buf *pbe_params, int mode,
85 cipher_type_t cipher_type, md_type_t md_type,
86 const unsigned char *pwd, size_t pwdlen,
87 const unsigned char *input, size_t len,
88 unsigned char *output );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +020089
90/**
91 * \brief The PKCS#12 derivation function uses a password and a salt
92 * to produce pseudo-random bits for a particular "purpose".
93 *
94 * Depending on the given id, this function can produce an
95 * encryption/decryption key, an nitialization vector or an
96 * integrity key.
97 *
98 * \param data buffer to store the derived data in
99 * \param datalen length to fill
100 * \param pwd password to use (may be NULL if no password is used)
101 * \param pwdlen length of the password (may be 0)
102 * \param salt salt buffer to use
103 * \param saltlen length of the salt
104 * \param md md type to use during the derivation
105 * \param id id that describes the purpose (can be PKCS12_DERIVE_KEY,
106 * PKCS12_DERIVE_IV or PKCS12_DERIVE_MAC_KEY)
107 * \param iterations number of iterations
108 *
109 * \return 0 if successful, or a MD, BIGNUM type error.
110 */
111int pkcs12_derivation( unsigned char *data, size_t datalen,
112 const unsigned char *pwd, size_t pwdlen,
113 const unsigned char *salt, size_t saltlen,
114 md_type_t md, int id, int iterations );
115
116#ifdef __cplusplus
117}
118#endif
119
120#endif /* pkcs12.h */