User | Revision | Line number | New contents of line |
Simon Cooksey |
0:fb7af294d5d9
|
1
|
/**
|
Simon Cooksey |
0:fb7af294d5d9
|
2
|
* \file pkcs12.h
|
Simon Cooksey |
0:fb7af294d5d9
|
3
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
4
|
* \brief PKCS#12 Personal Information Exchange Syntax
|
Simon Cooksey |
0:fb7af294d5d9
|
5
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
6
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
Simon Cooksey |
0:fb7af294d5d9
|
7
|
* SPDX-License-Identifier: Apache-2.0
|
Simon Cooksey |
0:fb7af294d5d9
|
8
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
9
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
Simon Cooksey |
0:fb7af294d5d9
|
10
|
* not use this file except in compliance with the License.
|
Simon Cooksey |
0:fb7af294d5d9
|
11
|
* You may obtain a copy of the License at
|
Simon Cooksey |
0:fb7af294d5d9
|
12
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
13
|
* http://www.apache.org/licenses/LICENSE-2.0
|
Simon Cooksey |
0:fb7af294d5d9
|
14
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
15
|
* Unless required by applicable law or agreed to in writing, software
|
Simon Cooksey |
0:fb7af294d5d9
|
16
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
Simon Cooksey |
0:fb7af294d5d9
|
17
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
Simon Cooksey |
0:fb7af294d5d9
|
18
|
* See the License for the specific language governing permissions and
|
Simon Cooksey |
0:fb7af294d5d9
|
19
|
* limitations under the License.
|
Simon Cooksey |
0:fb7af294d5d9
|
20
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
21
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
Simon Cooksey |
0:fb7af294d5d9
|
22
|
*/
|
Simon Cooksey |
0:fb7af294d5d9
|
23
|
#ifndef MBEDTLS_PKCS12_H
|
Simon Cooksey |
0:fb7af294d5d9
|
24
|
#define MBEDTLS_PKCS12_H
|
Simon Cooksey |
0:fb7af294d5d9
|
25
|
|
Simon Cooksey |
0:fb7af294d5d9
|
26
|
#include "md.h"
|
Simon Cooksey |
0:fb7af294d5d9
|
27
|
#include "cipher.h"
|
Simon Cooksey |
0:fb7af294d5d9
|
28
|
#include "asn1.h"
|
Simon Cooksey |
0:fb7af294d5d9
|
29
|
|
Simon Cooksey |
0:fb7af294d5d9
|
30
|
#include <stddef.h>
|
Simon Cooksey |
0:fb7af294d5d9
|
31
|
|
Simon Cooksey |
0:fb7af294d5d9
|
32
|
#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
|
Simon Cooksey |
0:fb7af294d5d9
|
33
|
#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
|
Simon Cooksey |
0:fb7af294d5d9
|
34
|
#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
|
Simon Cooksey |
0:fb7af294d5d9
|
35
|
#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
|
Simon Cooksey |
0:fb7af294d5d9
|
36
|
|
Simon Cooksey |
0:fb7af294d5d9
|
37
|
#define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
|
Simon Cooksey |
0:fb7af294d5d9
|
38
|
#define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */
|
Simon Cooksey |
0:fb7af294d5d9
|
39
|
#define MBEDTLS_PKCS12_DERIVE_MAC_KEY 3 /**< integrity / MAC key */
|
Simon Cooksey |
0:fb7af294d5d9
|
40
|
|
Simon Cooksey |
0:fb7af294d5d9
|
41
|
#define MBEDTLS_PKCS12_PBE_DECRYPT 0
|
Simon Cooksey |
0:fb7af294d5d9
|
42
|
#define MBEDTLS_PKCS12_PBE_ENCRYPT 1
|
Simon Cooksey |
0:fb7af294d5d9
|
43
|
|
Simon Cooksey |
0:fb7af294d5d9
|
44
|
#ifdef __cplusplus
|
Simon Cooksey |
0:fb7af294d5d9
|
45
|
extern "C" {
|
Simon Cooksey |
0:fb7af294d5d9
|
46
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
47
|
|
Simon Cooksey |
0:fb7af294d5d9
|
48
|
/**
|
Simon Cooksey |
0:fb7af294d5d9
|
49
|
* \brief PKCS12 Password Based function (encryption / decryption)
|
Simon Cooksey |
0:fb7af294d5d9
|
50
|
* for pbeWithSHAAnd128BitRC4
|
Simon Cooksey |
0:fb7af294d5d9
|
51
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
52
|
* \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
|
Simon Cooksey |
0:fb7af294d5d9
|
53
|
* \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
|
Simon Cooksey |
0:fb7af294d5d9
|
54
|
* \param pwd the password used (may be NULL if no password is used)
|
Simon Cooksey |
0:fb7af294d5d9
|
55
|
* \param pwdlen length of the password (may be 0)
|
Simon Cooksey |
0:fb7af294d5d9
|
56
|
* \param input the input data
|
Simon Cooksey |
0:fb7af294d5d9
|
57
|
* \param len data length
|
Simon Cooksey |
0:fb7af294d5d9
|
58
|
* \param output the output buffer
|
Simon Cooksey |
0:fb7af294d5d9
|
59
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
60
|
* \return 0 if successful, or a MBEDTLS_ERR_XXX code
|
Simon Cooksey |
0:fb7af294d5d9
|
61
|
*/
|
Simon Cooksey |
0:fb7af294d5d9
|
62
|
int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
|
Simon Cooksey |
0:fb7af294d5d9
|
63
|
const unsigned char *pwd, size_t pwdlen,
|
Simon Cooksey |
0:fb7af294d5d9
|
64
|
const unsigned char *input, size_t len,
|
Simon Cooksey |
0:fb7af294d5d9
|
65
|
unsigned char *output );
|
Simon Cooksey |
0:fb7af294d5d9
|
66
|
|
Simon Cooksey |
0:fb7af294d5d9
|
67
|
/**
|
Simon Cooksey |
0:fb7af294d5d9
|
68
|
* \brief PKCS12 Password Based function (encryption / decryption)
|
Simon Cooksey |
0:fb7af294d5d9
|
69
|
* for cipher-based and mbedtls_md-based PBE's
|
Simon Cooksey |
0:fb7af294d5d9
|
70
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
71
|
* \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
|
Simon Cooksey |
0:fb7af294d5d9
|
72
|
* \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
|
Simon Cooksey |
0:fb7af294d5d9
|
73
|
* \param cipher_type the cipher used
|
Simon Cooksey |
0:fb7af294d5d9
|
74
|
* \param md_type the mbedtls_md used
|
Simon Cooksey |
0:fb7af294d5d9
|
75
|
* \param pwd the password used (may be NULL if no password is used)
|
Simon Cooksey |
0:fb7af294d5d9
|
76
|
* \param pwdlen length of the password (may be 0)
|
Simon Cooksey |
0:fb7af294d5d9
|
77
|
* \param input the input data
|
Simon Cooksey |
0:fb7af294d5d9
|
78
|
* \param len data length
|
Simon Cooksey |
0:fb7af294d5d9
|
79
|
* \param output the output buffer
|
Simon Cooksey |
0:fb7af294d5d9
|
80
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
81
|
* \return 0 if successful, or a MBEDTLS_ERR_XXX code
|
Simon Cooksey |
0:fb7af294d5d9
|
82
|
*/
|
Simon Cooksey |
0:fb7af294d5d9
|
83
|
int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
|
Simon Cooksey |
0:fb7af294d5d9
|
84
|
mbedtls_cipher_type_t cipher_type, mbedtls_md_type_t md_type,
|
Simon Cooksey |
0:fb7af294d5d9
|
85
|
const unsigned char *pwd, size_t pwdlen,
|
Simon Cooksey |
0:fb7af294d5d9
|
86
|
const unsigned char *input, size_t len,
|
Simon Cooksey |
0:fb7af294d5d9
|
87
|
unsigned char *output );
|
Simon Cooksey |
0:fb7af294d5d9
|
88
|
|
Simon Cooksey |
0:fb7af294d5d9
|
89
|
/**
|
Simon Cooksey |
0:fb7af294d5d9
|
90
|
* \brief The PKCS#12 derivation function uses a password and a salt
|
Simon Cooksey |
0:fb7af294d5d9
|
91
|
* to produce pseudo-random bits for a particular "purpose".
|
Simon Cooksey |
0:fb7af294d5d9
|
92
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
93
|
* Depending on the given id, this function can produce an
|
Simon Cooksey |
0:fb7af294d5d9
|
94
|
* encryption/decryption key, an nitialization vector or an
|
Simon Cooksey |
0:fb7af294d5d9
|
95
|
* integrity key.
|
Simon Cooksey |
0:fb7af294d5d9
|
96
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
97
|
* \param data buffer to store the derived data in
|
Simon Cooksey |
0:fb7af294d5d9
|
98
|
* \param datalen length to fill
|
Simon Cooksey |
0:fb7af294d5d9
|
99
|
* \param pwd password to use (may be NULL if no password is used)
|
Simon Cooksey |
0:fb7af294d5d9
|
100
|
* \param pwdlen length of the password (may be 0)
|
Simon Cooksey |
0:fb7af294d5d9
|
101
|
* \param salt salt buffer to use
|
Simon Cooksey |
0:fb7af294d5d9
|
102
|
* \param saltlen length of the salt
|
Simon Cooksey |
0:fb7af294d5d9
|
103
|
* \param mbedtls_md mbedtls_md type to use during the derivation
|
Simon Cooksey |
0:fb7af294d5d9
|
104
|
* \param id id that describes the purpose (can be MBEDTLS_PKCS12_DERIVE_KEY,
|
Simon Cooksey |
0:fb7af294d5d9
|
105
|
* MBEDTLS_PKCS12_DERIVE_IV or MBEDTLS_PKCS12_DERIVE_MAC_KEY)
|
Simon Cooksey |
0:fb7af294d5d9
|
106
|
* \param iterations number of iterations
|
Simon Cooksey |
0:fb7af294d5d9
|
107
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
108
|
* \return 0 if successful, or a MD, BIGNUM type error.
|
Simon Cooksey |
0:fb7af294d5d9
|
109
|
*/
|
Simon Cooksey |
0:fb7af294d5d9
|
110
|
int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
Simon Cooksey |
0:fb7af294d5d9
|
111
|
const unsigned char *pwd, size_t pwdlen,
|
Simon Cooksey |
0:fb7af294d5d9
|
112
|
const unsigned char *salt, size_t saltlen,
|
Simon Cooksey |
0:fb7af294d5d9
|
113
|
mbedtls_md_type_t mbedtls_md, int id, int iterations );
|
Simon Cooksey |
0:fb7af294d5d9
|
114
|
|
Simon Cooksey |
0:fb7af294d5d9
|
115
|
#ifdef __cplusplus
|
Simon Cooksey |
0:fb7af294d5d9
|
116
|
}
|
Simon Cooksey |
0:fb7af294d5d9
|
117
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
118
|
|
Simon Cooksey |
0:fb7af294d5d9
|
119
|
#endif /* pkcs12.h */
|