pkcs5.c File Reference

PKCS#5 functions. More...

#include "polarssl/config.h"
#include "polarssl/pkcs5.h"
#include "polarssl/asn1.h"
#include "polarssl/cipher.h"
#include "polarssl/oid.h"
#include <stdio.h>
Include dependency graph for pkcs5.c:

Go to the source code of this file.

Defines

#define MAX_TESTS   6

Functions

static int pkcs5_parse_pbkdf2_params (asn1_buf *params, asn1_buf *salt, int *iterations, int *keylen, md_type_t *md_type)
int pkcs5_pbes2 (asn1_buf *pbe_params, int mode, const unsigned char *pwd, size_t pwdlen, const unsigned char *data, size_t datalen, unsigned char *output)
 PKCS#5 PBES2 function.
int pkcs5_pbkdf2_hmac (md_context_t *ctx, const unsigned char *password, size_t plen, const unsigned char *salt, size_t slen, unsigned int iteration_count, uint32_t key_length, unsigned char *output)
 PKCS#5 PBKDF2 using HMAC.
int pkcs5_self_test (int verbose)
 Checkup routine.

Variables

size_t plen [MAX_TESTS]
unsigned char password [MAX_TESTS][32]
size_t slen [MAX_TESTS]
unsigned char salt [MAX_TESTS][40]
uint32_t it_cnt [MAX_TESTS]
uint32_t key_len [MAX_TESTS]
unsigned char result_key [MAX_TESTS][32]

Detailed Description

PKCS#5 functions.

Author:
Mathias Olsson <mathias@kompetensum.com>

Copyright (C) 2006-2013, Brainspark B.V.

This file is part of PolarSSL (http://www.polarssl.org) Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Definition in file pkcs5.c.


Define Documentation

#define MAX_TESTS   6

Definition at line 287 of file pkcs5.c.


Function Documentation

static int pkcs5_parse_pbkdf2_params ( asn1_buf params,
asn1_buf salt,
int *  iterations,
int *  keylen,
md_type_t md_type 
) [static]
int pkcs5_pbes2 ( asn1_buf pbe_params,
int  mode,
const unsigned char *  pwd,
size_t  pwdlen,
const unsigned char *  data,
size_t  datalen,
unsigned char *  output 
)

PKCS#5 PBES2 function.

Parameters:
pbe_params the ASN.1 algorithm parameters
mode either PKCS5_DECRYPT or PKCS5_ENCRYPT
pwd password to use when generating key
pwdlen length of password
data data to process
datalen length of data
output output buffer
Returns:
0 on success, or a PolarSSL error code if verification fails.

Definition at line 102 of file pkcs5.c.

References ASN1_CONSTRUCTED, asn1_get_alg(), ASN1_OCTET_STRING, ASN1_SEQUENCE, cipher_finish(), cipher_free_ctx(), cipher_info_from_type(), cipher_init_ctx(), cipher_reset(), cipher_set_iv(), cipher_setkey(), cipher_update(), iv, cipher_info_t::iv_size, key, cipher_info_t::key_length, _asn1_buf::len, md_free_ctx(), md_info_from_type(), md_init_ctx(), OID_CMP, oid_get_cipher_alg(), OID_PKCS5_PBKDF2, _asn1_buf::p, pkcs5_parse_pbkdf2_params(), pkcs5_pbkdf2_hmac(), POLARSSL_ERR_ASN1_UNEXPECTED_TAG, POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE, POLARSSL_ERR_PKCS5_INVALID_FORMAT, POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH, POLARSSL_MD_SHA1, salt, and _asn1_buf::tag.

Referenced by pk_parse_key_pkcs8_encrypted_der().

int pkcs5_pbkdf2_hmac ( md_context_t ctx,
const unsigned char *  password,
size_t  plen,
const unsigned char *  salt,
size_t  slen,
unsigned int  iteration_count,
uint32_t  key_length,
unsigned char *  output 
)

PKCS#5 PBKDF2 using HMAC.

Parameters:
ctx Generic HMAC context
password Password to use when generating key
plen Length of password
salt Salt to use when generating key
slen Length of salt
iteration_count Iteration count
key_length Length of generated key
output Generated key. Must be at least as big as key_length
Returns:
0 on success, or a PolarSSL error code if verification fails.

Definition at line 212 of file pkcs5.c.

References md_get_size(), md_hmac_finish(), md_hmac_starts(), md_hmac_update(), md_context_t::md_info, POLARSSL_ERR_PKCS5_BAD_INPUT_DATA, and POLARSSL_MD_MAX_SIZE.

Referenced by pbkdf2_hmac(), pkcs5_pbes2(), pkcs5_self_test(), and test_suite_pbkdf2_hmac().

int pkcs5_self_test ( int  verbose  ) 

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Definition at line 344 of file pkcs5.c.

References it_cnt, key, key_len, MAX_TESTS, md_free_ctx(), md_info_from_type(), md_init_ctx(), password, pkcs5_pbkdf2_hmac(), plen, POLARSSL_MD_SHA1, result_key, salt, and slen.

Referenced by pbkdf2_self_test().


Variable Documentation

uint32_t it_cnt[MAX_TESTS]
Initial value:
    { 1, 2, 4096, 16777216, 4096, 4096 }

Definition at line 315 of file pkcs5.c.

Referenced by pkcs5_self_test().

uint32_t key_len[MAX_TESTS]
unsigned char password[MAX_TESTS][32]
Initial value:
{
    "password",
    "password",
    "password",
    "password",
    "passwordPASSWORDpassword",
    "pass\0word",
}

Definition at line 292 of file pkcs5.c.

Referenced by pkcs5_self_test().

size_t plen[MAX_TESTS]
Initial value:
    { 8, 8, 8, 8, 24, 9 }

Definition at line 289 of file pkcs5.c.

Referenced by ecp_point_read_binary(), ecp_point_write_binary(), mpi_write_file(), and pkcs5_self_test().

unsigned char result_key[MAX_TESTS][32]
Initial value:
 
{
    { 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
      0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
      0x2f, 0xe0, 0x37, 0xa6 },
    { 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c,
      0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
      0xd8, 0xde, 0x89, 0x57 },
    { 0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
      0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
      0x65, 0xa4, 0x29, 0xc1 },
    { 0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4,
      0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c,
      0x26, 0x34, 0xe9, 0x84 },
    { 0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b,
      0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a,
      0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70,
      0x38 },
    { 0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
      0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3 },
}

Definition at line 322 of file pkcs5.c.

Referenced by pkcs5_self_test().

unsigned char salt[MAX_TESTS][40]
Initial value:
{
    "salt",
    "salt",
    "salt",
    "salt",
    "saltSALTsaltSALTsaltSALTsaltSALTsalt",
    "sa\0lt",
}

Definition at line 305 of file pkcs5.c.

Referenced by pkcs12_pbe_derive_key_iv(), pkcs5_pbes2(), pkcs5_self_test(), and rsa_rsassa_pss_sign().

size_t slen[MAX_TESTS]
Initial value:
    { 4, 4, 4, 4, 36, 5 }

Definition at line 302 of file pkcs5.c.

Referenced by mpi_read_file(), mpi_read_string(), mpi_write_file(), pkcs5_self_test(), rsa_rsassa_pss_sign(), and rsa_rsassa_pss_verify().


Generated on 9 Apr 2014 for PolarSSL v1.3.2 by  doxygen 1.6.1