Ejemplo n.º 1
0
/*
 * Unallocate all CSR data
 */
void x509_csr_free( x509_csr *csr )
{
    x509_name *name_cur;
    x509_name *name_prv;

    if( csr == NULL )
        return;

    pk_free( &csr->pk );

#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
    polarssl_free( csr->sig_opts );
#endif

    name_cur = csr->subject.next;
    while( name_cur != NULL )
    {
        name_prv = name_cur;
        name_cur = name_cur->next;
        polarssl_zeroize( name_prv, sizeof( x509_name ) );
        polarssl_free( name_prv );
    }

    if( csr->raw.p != NULL )
    {
        polarssl_zeroize( csr->raw.p, csr->raw.len );
        polarssl_free( csr->raw.p );
    }

    polarssl_zeroize( csr, sizeof( x509_csr ) );
}
Ejemplo n.º 2
0
/*
 * Unallocate all CRL data
 */
void x509_crl_free( x509_crl *crl )
{
    x509_crl *crl_cur = crl;
    x509_crl *crl_prv;
    x509_name *name_cur;
    x509_name *name_prv;
    x509_crl_entry *entry_cur;
    x509_crl_entry *entry_prv;

    if( crl == NULL )
        return;

    do
    {
#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
        polarssl_free( crl_cur->sig_opts );
#endif

        name_cur = crl_cur->issuer.next;
        while( name_cur != NULL )
        {
            name_prv = name_cur;
            name_cur = name_cur->next;
            polarssl_zeroize( name_prv, sizeof( x509_name ) );
            polarssl_free( name_prv );
        }

        entry_cur = crl_cur->entry.next;
        while( entry_cur != NULL )
        {
            entry_prv = entry_cur;
            entry_cur = entry_cur->next;
            polarssl_zeroize( entry_prv, sizeof( x509_crl_entry ) );
            polarssl_free( entry_prv );
        }

        if( crl_cur->raw.p != NULL )
        {
            polarssl_zeroize( crl_cur->raw.p, crl_cur->raw.len );
            polarssl_free( crl_cur->raw.p );
        }

        crl_cur = crl_cur->next;
    }
    while( crl_cur != NULL );

    crl_cur = crl;
    do
    {
        crl_prv = crl_cur;
        crl_cur = crl_cur->next;

        polarssl_zeroize( crl_prv, sizeof( x509_crl ) );
        if( crl_prv != crl )
            polarssl_free( crl_prv );
    }
    while( crl_cur != NULL );
}
Ejemplo n.º 3
0
void md2_free( md2_context *ctx )
{
    if( ctx == NULL )
        return;

    polarssl_zeroize( ctx, sizeof( md2_context ) );
}
Ejemplo n.º 4
0
void havege_free( havege_state *hs )
{
    if( hs == NULL )
        return;

    polarssl_zeroize( hs, sizeof( havege_state ) );
}
Ejemplo n.º 5
0
/*
 * MD2 HMAC context setup
 */
void md2_hmac_starts( md2_context *ctx, const unsigned char *key,
                      size_t keylen )
{
    size_t i;
    unsigned char sum[16];

    if( keylen > 16 )
    {
        md2( key, keylen, sum );
        keylen = 16;
        key = sum;
    }

    memset( ctx->ipad, 0x36, 16 );
    memset( ctx->opad, 0x5C, 16 );

    for( i = 0; i < keylen; i++ )
    {
        ctx->ipad[i] = (unsigned char)( ctx->ipad[i] ^ key[i] );
        ctx->opad[i] = (unsigned char)( ctx->opad[i] ^ key[i] );
    }

    md2_starts( ctx );
    md2_update( ctx, ctx->ipad, 16 );

    polarssl_zeroize( sum, sizeof( sum ) );
}
Ejemplo n.º 6
0
void sha1_free( sha1_context *ctx )
{
    if( ctx == NULL )
        return;

    polarssl_zeroize( ctx, sizeof( sha1_context ) );
}
Ejemplo n.º 7
0
void blowfish_free( blowfish_context *ctx )
{
    if( ctx == NULL )
        return;

    polarssl_zeroize( ctx, sizeof( blowfish_context ) );
}
Ejemplo n.º 8
0
void x509write_csr_free( x509write_csr *ctx )
{
    asn1_free_named_data_list( &ctx->subject );
    asn1_free_named_data_list( &ctx->extensions );

    polarssl_zeroize( ctx, sizeof( x509write_csr ) );
}
Ejemplo n.º 9
0
void arc4_free( arc4_context *ctx )
{
    if( ctx == NULL )
        return;

    polarssl_zeroize( ctx, sizeof( arc4_context ) );
}
Ejemplo n.º 10
0
void aes_free( aes_context *ctx )
{
	//RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_CRYP, DISABLE); NO! if another ctx is active... at least, test that.

    if( ctx == NULL )
        return;

    polarssl_zeroize( ctx, sizeof( aes_context ) );
}
Ejemplo n.º 11
0
/*
 * Free (the components of) a pk_context
 */
void pk_free( pk_context *ctx )
{
    if( ctx == NULL || ctx->pk_info == NULL )
        return;

    ctx->pk_info->ctx_free_func( ctx->pk_ctx );

    polarssl_zeroize( ctx, sizeof( pk_context ) );
}
Ejemplo n.º 12
0
/*
 * Free an HMAC_DRBG context
 */
void hmac_drbg_free( hmac_drbg_context *ctx )
{
    if( ctx == NULL )
        return;

    md_free( &ctx->md_ctx );

    polarssl_zeroize( ctx, sizeof( hmac_drbg_context ) );
}
Ejemplo n.º 13
0
void cipher_free( cipher_context_t *ctx )
{
    if( ctx == NULL )
        return;

    if( ctx->cipher_ctx )
        ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx );

    polarssl_zeroize( ctx, sizeof(cipher_context_t) );
}
Ejemplo n.º 14
0
/*
 * Free an HMAC_DRBG context
 */
SSL_ROM_TEXT_SECTION
void hmac_drbg_free( hmac_drbg_context *ctx )
{
    if( ctx == NULL )
        return;

    md_free_ctx( &ctx->md_ctx );

    polarssl_zeroize( ctx, sizeof( hmac_drbg_context ) );
}
Ejemplo n.º 15
0
int cipher_free_ctx( cipher_context_t *ctx )
{
    if( ctx == NULL || ctx->cipher_info == NULL )
        return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;

    ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx );
    polarssl_zeroize( ctx, sizeof(cipher_context_t) );

    return 0;
}
Ejemplo n.º 16
0
void asn1_free_named_data( asn1_named_data *cur )
{
    if( cur == NULL )
        return;

    polarssl_free( cur->oid.p );
    polarssl_free( cur->val.p );

    polarssl_zeroize( cur, sizeof( asn1_named_data ) );
}
Ejemplo n.º 17
0
void entropy_free( entropy_context *ctx )
{
#if defined(POLARSSL_HAVEGE_C)
    havege_free( &ctx->havege_data );
#endif
    polarssl_zeroize( ctx, sizeof( entropy_context ) );
#if defined(POLARSSL_THREADING_C)
    polarssl_mutex_free( &ctx->mutex );
#endif
}
Ejemplo n.º 18
0
void md_free( md_context_t *ctx )
{
    if( ctx == NULL )
        return;

    if( ctx->md_ctx )
        ctx->md_info->ctx_free_func( ctx->md_ctx );

    polarssl_zeroize( ctx, sizeof( md_context_t ) );
}
Ejemplo n.º 19
0
/*
 * MD2 HMAC final digest
 */
void md2_hmac_finish( md2_context *ctx, unsigned char output[16] )
{
    unsigned char tmpbuf[16];

    md2_finish( ctx, tmpbuf );
    md2_starts( ctx );
    md2_update( ctx, ctx->opad, 16 );
    md2_update( ctx, tmpbuf, 16 );
    md2_finish( ctx, output );

    polarssl_zeroize( tmpbuf, sizeof( tmpbuf ) );
}
Ejemplo n.º 20
0
/*
 * Load one or more CRLs and add them to the chained list
 */
int x509_crl_parse_file( x509_crl *chain, const char *path )
{
    int ret;
    size_t n;
    unsigned char *buf;

    if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
        return( ret );

    ret = x509_crl_parse( chain, buf, n );

    polarssl_zeroize( buf, n + 1 );
    polarssl_free( buf );

    return( ret );
}
Ejemplo n.º 21
0
/*
 * Load and parse a public key
 */
int pk_parse_public_keyfile( pk_context *ctx, const char *path )
{
    int ret;
    size_t n;
    unsigned char *buf;

    if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
        return( ret );

    ret = pk_parse_public_key( ctx, buf, n );

    polarssl_zeroize( buf, n + 1 );
    polarssl_free( buf );

    return( ret );
}
Ejemplo n.º 22
0
int asn1_get_alg( unsigned char **p,
                  const unsigned char *end,
                  asn1_buf *alg, asn1_buf *params )
{
    int ret;
    size_t len;

    if( ( ret = asn1_get_tag( p, end, &len,
            ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 )
        return( ret );

    if( ( end - *p ) < 1 )
        return( POLARSSL_ERR_ASN1_OUT_OF_DATA );

    alg->tag = **p;
    end = *p + len;

    if( ( ret = asn1_get_tag( p, end, &alg->len, ASN1_OID ) ) != 0 )
        return( ret );

    alg->p = *p;
    *p += alg->len;

    if( *p == end )
    {
        polarssl_zeroize( params, sizeof(asn1_buf) );
        return( 0 );
    }

    params->tag = **p;
    (*p)++;

    if( ( ret = asn1_get_len( p, end, &params->len ) ) != 0 )
        return( ret );

    params->p = *p;
    *p += params->len;

    if( *p != end )
        return( POLARSSL_ERR_ASN1_LENGTH_MISMATCH );

    return( 0 );
}
Ejemplo n.º 23
0
/*
 * Load and parse a private key
 */
int pk_parse_keyfile( pk_context *ctx,
                      const char *path, const char *pwd )
{
    int ret;
    size_t n;
    unsigned char *buf;

    if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
        return( ret );

    if( pwd == NULL )
        ret = pk_parse_key( ctx, buf, n, NULL, 0 );
    else
        ret = pk_parse_key( ctx, buf, n,
                (const unsigned char *) pwd, strlen( pwd ) );

    polarssl_zeroize( buf, n + 1 );
    polarssl_free( buf );

    return( ret );
}
static void tts_free( void *ctx )
{
    polarssl_zeroize( ctx, sizeof( tts_context ) );
    polarssl_free( ctx );
}
Ejemplo n.º 25
0
static void rsa_alt_free_wrap( void *ctx )
{
    polarssl_zeroize( ctx, sizeof( rsa_alt_context ) );
    polarssl_free( ctx );
}
Ejemplo n.º 26
0
static void md5_ctx_free( void *ctx )
{
    polarssl_zeroize( ctx, sizeof( md5_context ) );
    polarssl_free( ctx );
}
Ejemplo n.º 27
0
static void sha384_ctx_free( void *ctx )
{
    polarssl_zeroize( ctx, sizeof( sha512_context ) );
    polarssl_free( ctx );
}
static void rainbow2_free( void *ctx )
{
    polarssl_zeroize( ctx, sizeof( rainbow2_context ) );
    polarssl_free( ctx );
}