53#if !defined(MBEDTLS_CONFIG_FILE)
56#include MBEDTLS_CONFIG_FILE
59#if defined(MBEDTLS_PKCS12_C)
68#if defined(MBEDTLS_ARC4_C)
72#if defined(MBEDTLS_DES_C)
76#if defined(MBEDTLS_ASN1_PARSE_C)
112#define PKCS12_MAX_PWDLEN 128
115 const unsigned char *
pwd,
size_t pwdlen,
116 unsigned char *
key,
size_t keylen,
117 unsigned char *iv,
size_t ivlen )
119 int ret, iterations = 0;
122 unsigned char unipwd[PKCS12_MAX_PWDLEN * 2 + 2];
124 if( pwdlen > PKCS12_MAX_PWDLEN )
128 memset( &unipwd, 0,
sizeof(unipwd) );
130 if( (
ret = pkcs12_parse_pbe_params( pbe_params, &salt,
131 &iterations ) ) != 0 )
134 for(
i = 0;
i < pwdlen;
i++ )
135 unipwd[
i * 2 + 1] =
pwd[
i];
138 salt.
p, salt.
len, md_type,
144 if( iv ==
NULL || ivlen == 0 )
148 salt.
p, salt.
len, md_type,
156#undef PKCS12_MAX_PWDLEN
159 const unsigned char *
pwd,
size_t pwdlen,
160 const unsigned char *
data,
size_t len,
161 unsigned char *output )
163#if !defined(MBEDTLS_ARC4_C)
174 unsigned char key[16];
201 const unsigned char *
pwd,
size_t pwdlen,
202 const unsigned char *
data,
size_t len,
203 unsigned char *output )
206 unsigned char key[32];
207 unsigned char iv[16];
213 if( cipher_info ==
NULL )
218 if( (
ret = pkcs12_pbe_derive_key_iv( pbe_params, md_type,
pwd, pwdlen,
220 iv, cipher_info->
iv_size ) ) != 0 )
240 output, &olen ) ) != 0 )
258static void pkcs12_fill_buffer(
unsigned char *
data,
size_t data_len,
259 const unsigned char *
filler,
size_t fill_len )
261 unsigned char *
p =
data;
264 while( data_len > 0 )
266 use_len = ( data_len > fill_len ) ? fill_len : data_len;
274 const unsigned char *
pwd,
size_t pwdlen,
275 const unsigned char *salt,
size_t saltlen,
281 unsigned char diversifier[128];
282 unsigned char salt_block[128], pwd_block[128], hash_block[128];
287 size_t hlen, use_len,
v,
i;
293 if(
datalen > 128 || pwdlen > 64 || saltlen > 64 )
297 if( md_info ==
NULL )
311 memset( diversifier, (
unsigned char)
id,
v );
313 pkcs12_fill_buffer( salt_block,
v, salt, saltlen );
314 pkcs12_fill_buffer( pwd_block,
v,
pwd, pwdlen );
336 for(
i = 1;
i < (
size_t) iterations;
i++ )
338 if( (
ret =
mbedtls_md( md_info, hash_output, hlen, hash_output ) ) != 0 )
343 memcpy(
p, hash_output, use_len );
351 pkcs12_fill_buffer( hash_block,
v, hash_output, hlen );
354 for(
i =
v;
i > 0;
i-- )
355 if( ++hash_block[
i - 1] != 0 )
360 for(
i =
v;
i > 0;
i-- )
362 j = salt_block[
i - 1] + hash_block[
i - 1] +
c;
363 c = (
unsigned char) (
j >> 8);
364 salt_block[
i - 1] =
j & 0xFF;
369 for(
i =
v;
i > 0;
i-- )
371 j = pwd_block[
i - 1] + hash_block[
i - 1] +
c;
372 c = (
unsigned char) (
j >> 8);
373 pwd_block[
i - 1] =
j & 0xFF;
void pwd(int argc, const char *argv[])
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info)
This function initializes and fills the cipher-context structure with the appropriate values....
mbedtls_cipher_type_t
Supported {cipher type, cipher mode} pairs.
int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, const unsigned char *key, int key_bitlen, const mbedtls_operation_t operation)
This function sets the key to use with the given context.
int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx)
This function resets the cipher state.
int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len)
This function sets the initialization vector (IV) or nonce.
int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen)
The generic cipher finalization function. If data still needs to be flushed from an incomplete block,...
void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx)
This function initializes a cipher_context as NONE.
void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx)
This function frees and clears the cipher-specific context of ctx. Freeing ctx itself remains the res...
int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
The generic cipher update function. It encrypts or decrypts using the given cipher context....
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum const GLfloat * params
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
#define MBEDTLS_ASN1_OCTET_STRING
#define MBEDTLS_ASN1_SEQUENCE
int mbedtls_asn1_get_int(unsigned char **p, const unsigned char *end, int *val)
Retrieve an integer ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
#define MBEDTLS_ASN1_CONSTRUCTED
#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH
int mbedtls_asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the tag. Check for the requested tag. Updates the pointer to immediately be...
int const JOCTET unsigned int datalen
int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac)
This function selects the message digest algorithm to use, and allocates internal structures.
mbedtls_md_type_t
Supported message digests.
int mbedtls_md_starts(mbedtls_md_context_t *ctx)
This function starts a message-digest computation.
int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the message-digest of a buffer, with respect to a configurable message-diges...
int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing message-digest computation.
#define MBEDTLS_MD_MAX_SIZE
void mbedtls_md_init(mbedtls_md_context_t *ctx)
This function initializes a message-digest context without binding it to a particular message-digest ...
int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output)
This function finishes the digest operation, and writes the result to the output buffer.
unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
This function extracts the message-digest size from the message-digest information structure.
void mbedtls_md_free(mbedtls_md_context_t *ctx)
This function clears the internal structure of ctx and frees any embedded internal structure,...
#define memcpy(s1, s2, n)
static const char filler[0x1000]
PKCS#12 Personal Information Exchange Syntax.
int mbedtls_pkcs12_derivation(unsigned char *data, size_t datalen, const unsigned char *pwd, size_t pwdlen, const unsigned char *salt, size_t saltlen, mbedtls_md_type_t mbedtls_md, int id, int iterations)
The PKCS#12 derivation function uses a password and a salt to produce pseudo-random bits for a partic...
#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT
#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH
#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA
#define MBEDTLS_PKCS12_DERIVE_IV
#define MBEDTLS_PKCS12_DERIVE_KEY
#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE
int mbedtls_pkcs12_pbe(mbedtls_asn1_buf *pbe_params, int mode, mbedtls_cipher_type_t cipher_type, mbedtls_md_type_t md_type, const unsigned char *pwd, size_t pwdlen, const unsigned char *input, size_t len, unsigned char *output)
PKCS12 Password Based function (encryption / decryption) for cipher-based and mbedtls_md-based PBE's.
int mbedtls_pkcs12_pbe_sha1_rc4_128(mbedtls_asn1_buf *pbe_params, int mode, const unsigned char *pwd, size_t pwdlen, const unsigned char *input, size_t len, unsigned char *output)
PKCS12 Password Based function (encryption / decryption) for pbeWithSHAAnd128BitRC4.
#define mbedtls_md_info_from_type
#define mbedtls_cipher_info_from_type
The ARCFOUR stream cipher.
int mbedtls_arc4_crypt(mbedtls_arc4_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
ARC4 cipher function.
void mbedtls_arc4_setup(mbedtls_arc4_context *ctx, const unsigned char *key, unsigned int keylen)
ARC4 key schedule.
void mbedtls_arc4_init(mbedtls_arc4_context *ctx)
Initialize ARC4 context.
void mbedtls_arc4_free(mbedtls_arc4_context *ctx)
Clear ARC4 context.
Configuration options (set of defines)