blob: 00bfa50e2f912240f1788358eeda48101b6fdd65 [file] [log] [blame]
Paul Bakkercf6e95d2013-06-12 13:18:15 +02001/**
2 * \file pkcs12.h
3 *
4 * \brief PKCS#12 Personal Information Exchange Syntax
5 *
Manuel Pégourié-Gonnard0edee5e2015-01-26 15:29:40 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkercf6e95d2013-06-12 13:18:15 +02007 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkercf6e95d2013-06-12 13:18:15 +02009 *
10 * 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
27#include <string.h>
28
29#include "md.h"
Paul Bakker14a222c2013-06-18 16:35:48 +020030#include "cipher.h"
Paul Bakkercf6e95d2013-06-12 13:18:15 +020031#include "asn1.h"
32
33#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 Bakker14a222c2013-06-18 16:35:48 +020036#define POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
Paul Bakkercf6e95d2013-06-12 13:18:15 +020037
Manuel Pégourié-Gonnard7bf9f7e2014-11-17 11:20:21 +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 Bakkercf6e95d2013-06-12 13:18:15 +020041
Paul Bakker14a222c2013-06-18 16:35:48 +020042#define PKCS12_PBE_DECRYPT 0
Paul Bakkercf6e95d2013-06-12 13:18:15 +020043#define PKCS12_PBE_ENCRYPT 1
Paul Bakkercf6e95d2013-06-12 13:18:15 +020044
45/*
46 * PKCS#12 PBE types
47 */
48#define OID_PKCS12 "\x2a\x86\x48\x86\xf7\x0d\x01\x0c"
49#define OID_PKCS12_PBE_SHA1_RC4_128 OID_PKCS12 "\x01\x01"
50#define OID_PKCS12_PBE_SHA1_DES3_EDE_CBC OID_PKCS12 "\x01\x03"
51#define OID_PKCS12_PBE_SHA1_DES2_EDE_CBC OID_PKCS12 "\x01\x04"
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/**
58 * \brief PKCS12 Password Based function (encryption / decryption)
59 * for pbeWithSHAAnd128BitRC4
60 *
61 * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
62 * \param mode either PKCS12_PBE_ENCRYPT or PKCS12_PBE_DECRYPT
63 * \param pwd the password used (may be NULL if no password is used)
64 * \param pwdlen length of the password (may be 0)
65 * \param input the input data
66 * \param len data length
67 * \param output the output buffer
Paul Bakker14a222c2013-06-18 16:35:48 +020068 *
69 * \return 0 if successful, or a PolarSSL error code
Paul Bakkercf6e95d2013-06-12 13:18:15 +020070 */
71int pkcs12_pbe_sha1_rc4_128( asn1_buf *pbe_params, int mode,
72 const unsigned char *pwd, size_t pwdlen,
73 const unsigned char *input, size_t len,
74 unsigned char *output );
75
76/**
77 * \brief PKCS12 Password Based function (encryption / decryption)
Paul Bakker14a222c2013-06-18 16:35:48 +020078 * for cipher-based and md-based PBE's
Paul Bakkercf6e95d2013-06-12 13:18:15 +020079 *
80 * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
81 * \param mode either PKCS12_PBE_ENCRYPT or PKCS12_PBE_DECRYPT
Paul Bakker14a222c2013-06-18 16:35:48 +020082 * \param cipher_type the cipher used
83 * \param md_type the md used
Paul Bakkercf6e95d2013-06-12 13:18:15 +020084 * \param pwd the password used (may be NULL if no password is used)
85 * \param pwdlen length of the password (may be 0)
86 * \param input the input data
87 * \param len data length
88 * \param output the output buffer
Paul Bakkercf6e95d2013-06-12 13:18:15 +020089 *
Paul Bakker14a222c2013-06-18 16:35:48 +020090 * \return 0 if successful, or a PolarSSL error code
Paul Bakkercf6e95d2013-06-12 13:18:15 +020091 */
Paul Bakker14a222c2013-06-18 16:35:48 +020092int pkcs12_pbe( asn1_buf *pbe_params, int mode,
93 cipher_type_t cipher_type, md_type_t md_type,
94 const unsigned char *pwd, size_t pwdlen,
95 const unsigned char *input, size_t len,
96 unsigned char *output );
Paul Bakkercf6e95d2013-06-12 13:18:15 +020097
98/**
99 * \brief The PKCS#12 derivation function uses a password and a salt
100 * to produce pseudo-random bits for a particular "purpose".
101 *
102 * Depending on the given id, this function can produce an
103 * encryption/decryption key, an nitialization vector or an
104 * integrity key.
105 *
106 * \param data buffer to store the derived data in
107 * \param datalen length to fill
108 * \param pwd password to use (may be NULL if no password is used)
109 * \param pwdlen length of the password (may be 0)
110 * \param salt salt buffer to use
111 * \param saltlen length of the salt
112 * \param md md type to use during the derivation
113 * \param id id that describes the purpose (can be PKCS12_DERIVE_KEY,
114 * PKCS12_DERIVE_IV or PKCS12_DERIVE_MAC_KEY)
115 * \param iterations number of iterations
116 *
117 * \return 0 if successful, or a MD, BIGNUM type error.
118 */
119int pkcs12_derivation( unsigned char *data, size_t datalen,
120 const unsigned char *pwd, size_t pwdlen,
121 const unsigned char *salt, size_t saltlen,
122 md_type_t md, int id, int iterations );
123
124#ifdef __cplusplus
125}
126#endif
127
128#endif /* pkcs12.h */