mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-11-03 20:33:16 +03:00 
			
		
		
		
	Explicit conversions and minor changes to prevent MSVC compiler warnings
This commit is contained in:
		@@ -379,7 +379,7 @@ static inline int cipher_get_iv_size( const cipher_context_t *ctx )
 | 
				
			|||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ctx->iv_size != 0 )
 | 
					    if( ctx->iv_size != 0 )
 | 
				
			||||||
        return ctx->iv_size;
 | 
					        return (int) ctx->iv_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ctx->cipher_info->iv_size;
 | 
					    return ctx->cipher_info->iv_size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,7 +44,7 @@ int asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
 | 
				
			|||||||
        if( *p - start < 1 )
 | 
					        if( *p - start < 1 )
 | 
				
			||||||
            return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
 | 
					            return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        *--(*p) = len;
 | 
					        *--(*p) = (unsigned char) len;
 | 
				
			||||||
        return( 1 );
 | 
					        return( 1 );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,7 +53,7 @@ int asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
 | 
				
			|||||||
        if( *p - start < 2 )
 | 
					        if( *p - start < 2 )
 | 
				
			||||||
            return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
 | 
					            return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        *--(*p) = len;
 | 
					        *--(*p) = (unsigned char) len;
 | 
				
			||||||
        *--(*p) = 0x81;
 | 
					        *--(*p) = 0x81;
 | 
				
			||||||
        return( 2 );
 | 
					        return( 2 );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -92,7 +92,7 @@ int asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    (*p) -= len;
 | 
					    (*p) -= len;
 | 
				
			||||||
    memcpy( *p, buf, len );
 | 
					    memcpy( *p, buf, len );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(POLARSSL_BIGNUM_C)
 | 
					#if defined(POLARSSL_BIGNUM_C)
 | 
				
			||||||
@@ -126,7 +126,7 @@ int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X )
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* POLARSSL_BIGNUM_C */
 | 
					#endif /* POLARSSL_BIGNUM_C */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -140,7 +140,7 @@ int asn1_write_null( unsigned char **p, unsigned char *start )
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, 0) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, 0) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_NULL ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_NULL ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_oid( unsigned char **p, unsigned char *start,
 | 
					int asn1_write_oid( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -154,7 +154,7 @@ int asn1_write_oid( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len , asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len , asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len , asn1_write_tag( p, start, ASN1_OID ) );
 | 
					    ASN1_CHK_ADD( len , asn1_write_tag( p, start, ASN1_OID ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
 | 
					int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -175,7 +175,7 @@ int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start,
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start,
 | 
				
			||||||
                                       ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
					                                       ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean )
 | 
					int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean )
 | 
				
			||||||
@@ -192,7 +192,7 @@ int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean )
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BOOLEAN ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BOOLEAN ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_int( unsigned char **p, unsigned char *start, int val )
 | 
					int asn1_write_int( unsigned char **p, unsigned char *start, int val )
 | 
				
			||||||
@@ -222,7 +222,7 @@ int asn1_write_int( unsigned char **p, unsigned char *start, int val )
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_printable_string( unsigned char **p, unsigned char *start,
 | 
					int asn1_write_printable_string( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -237,7 +237,7 @@ int asn1_write_printable_string( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_PRINTABLE_STRING ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_PRINTABLE_STRING ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_ia5_string( unsigned char **p, unsigned char *start,
 | 
					int asn1_write_ia5_string( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -252,7 +252,7 @@ int asn1_write_ia5_string( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_IA5_STRING ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_IA5_STRING ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_bitstring( unsigned char **p, unsigned char *start,
 | 
					int asn1_write_bitstring( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -274,12 +274,12 @@ int asn1_write_bitstring( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Write unused bits
 | 
					    // Write unused bits
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
    *--(*p) = size * 8 - bits;
 | 
					    *--(*p) = (unsigned char) (size * 8 - bits);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BIT_STRING ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BIT_STRING ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int asn1_write_octet_string( unsigned char **p, unsigned char *start,
 | 
					int asn1_write_octet_string( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -293,7 +293,7 @@ int asn1_write_octet_string( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OCTET_STRING ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OCTET_STRING ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
asn1_named_data *asn1_store_named_data( asn1_named_data **head,
 | 
					asn1_named_data *asn1_store_named_data( asn1_named_data **head,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -137,7 +137,7 @@ int base64_decode( unsigned char *dst, size_t *dlen,
 | 
				
			|||||||
    uint32_t j, x;
 | 
					    uint32_t j, x;
 | 
				
			||||||
    unsigned char *p;
 | 
					    unsigned char *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for( i = j = n = 0; i < slen; i++ )
 | 
					    for( i = n = j = 0; i < slen; i++ )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if( ( slen - i ) >= 2 &&
 | 
					        if( ( slen - i ) >= 2 &&
 | 
				
			||||||
            src[i] == '\r' && src[i + 1] == '\n' )
 | 
					            src[i] == '\r' && src[i + 1] == '\n' )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -216,7 +216,7 @@ int cipher_update_ad( cipher_context_t *ctx,
 | 
				
			|||||||
#if defined(POLARSSL_GCM_C)
 | 
					#if defined(POLARSSL_GCM_C)
 | 
				
			||||||
    if( POLARSSL_MODE_GCM == ctx->cipher_info->mode )
 | 
					    if( POLARSSL_MODE_GCM == ctx->cipher_info->mode )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return gcm_starts( ctx->cipher_ctx, ctx->operation,
 | 
					        return gcm_starts( (gcm_context *) ctx->cipher_ctx, ctx->operation,
 | 
				
			||||||
                           ctx->iv, ctx->iv_size, ad, ad_len );
 | 
					                           ctx->iv, ctx->iv_size, ad, ad_len );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -257,7 +257,8 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile
 | 
				
			|||||||
    if( ctx->cipher_info->mode == POLARSSL_MODE_GCM )
 | 
					    if( ctx->cipher_info->mode == POLARSSL_MODE_GCM )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        *olen = ilen;
 | 
					        *olen = ilen;
 | 
				
			||||||
        return gcm_update( ctx->cipher_ctx, ilen, input, output );
 | 
					        return gcm_update( (gcm_context *) ctx->cipher_ctx, ilen, input,
 | 
				
			||||||
 | 
					                           output );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -414,7 +415,7 @@ static void add_pkcs_padding( unsigned char *output, size_t output_len,
 | 
				
			|||||||
static int get_pkcs_padding( unsigned char *input, size_t input_len,
 | 
					static int get_pkcs_padding( unsigned char *input, size_t input_len,
 | 
				
			||||||
        size_t *data_len )
 | 
					        size_t *data_len )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned int i, padding_len = 0;
 | 
					    size_t i, padding_len = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( NULL == input || NULL == data_len )
 | 
					    if( NULL == input || NULL == data_len )
 | 
				
			||||||
        return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
 | 
					        return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
 | 
				
			||||||
@@ -487,7 +488,7 @@ static void add_zeros_and_len_padding( unsigned char *output,
 | 
				
			|||||||
static int get_zeros_and_len_padding( unsigned char *input, size_t input_len,
 | 
					static int get_zeros_and_len_padding( unsigned char *input, size_t input_len,
 | 
				
			||||||
                                      size_t *data_len )
 | 
					                                      size_t *data_len )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned int i, padding_len = 0;
 | 
					    size_t i, padding_len = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( NULL == input || NULL == data_len )
 | 
					    if( NULL == input || NULL == data_len )
 | 
				
			||||||
        return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
 | 
					        return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
 | 
				
			||||||
@@ -514,7 +515,7 @@ static int get_zeros_and_len_padding( unsigned char *input, size_t input_len,
 | 
				
			|||||||
static void add_zeros_padding( unsigned char *output,
 | 
					static void add_zeros_padding( unsigned char *output,
 | 
				
			||||||
                               size_t output_len, size_t data_len )
 | 
					                               size_t output_len, size_t data_len )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned char i;
 | 
					    size_t i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for( i = data_len; i < output_len; i++ )
 | 
					    for( i = data_len; i < output_len; i++ )
 | 
				
			||||||
        output[i] = 0x00;
 | 
					        output[i] = 0x00;
 | 
				
			||||||
@@ -693,7 +694,7 @@ int cipher_write_tag( cipher_context_t *ctx,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#if defined(POLARSSL_GCM_C)
 | 
					#if defined(POLARSSL_GCM_C)
 | 
				
			||||||
    if( POLARSSL_MODE_GCM == ctx->cipher_info->mode )
 | 
					    if( POLARSSL_MODE_GCM == ctx->cipher_info->mode )
 | 
				
			||||||
        return gcm_finish( ctx->cipher_ctx, tag, tag_len );
 | 
					        return gcm_finish( (gcm_context *) ctx->cipher_ctx, tag, tag_len );
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
@@ -720,8 +721,11 @@ int cipher_check_tag( cipher_context_t *ctx,
 | 
				
			|||||||
        if( tag_len > sizeof( check_tag ) )
 | 
					        if( tag_len > sizeof( check_tag ) )
 | 
				
			||||||
            return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
 | 
					            return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if( 0 != ( ret = gcm_finish( ctx->cipher_ctx, check_tag, tag_len ) ) )
 | 
					        if( 0 != ( ret = gcm_finish( (gcm_context *) ctx->cipher_ctx,
 | 
				
			||||||
 | 
					                                     check_tag, tag_len ) ) )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
            return( ret );
 | 
					            return( ret );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Check the tag in "constant-time" */
 | 
					        /* Check the tag in "constant-time" */
 | 
				
			||||||
        for( diff = 0, i = 0; i < tag_len; i++ )
 | 
					        for( diff = 0, i = 0; i < tag_len; i++ )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,7 +108,8 @@ static int block_cipher_df( unsigned char *output,
 | 
				
			|||||||
    unsigned char *p = buf, *iv;
 | 
					    unsigned char *p = buf, *iv;
 | 
				
			||||||
    aes_context aes_ctx;
 | 
					    aes_context aes_ctx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i, j, buf_len, use_len;
 | 
					    int i, j;
 | 
				
			||||||
 | 
					    size_t buf_len, use_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset( buf, 0, CTR_DRBG_MAX_SEED_INPUT + CTR_DRBG_BLOCKSIZE + 16 );
 | 
					    memset( buf, 0, CTR_DRBG_MAX_SEED_INPUT + CTR_DRBG_BLOCKSIZE + 16 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -150,7 +151,8 @@ static int block_cipher_df( unsigned char *output,
 | 
				
			|||||||
            for( i = 0; i < CTR_DRBG_BLOCKSIZE; i++ )
 | 
					            for( i = 0; i < CTR_DRBG_BLOCKSIZE; i++ )
 | 
				
			||||||
                chain[i] ^= p[i];
 | 
					                chain[i] ^= p[i];
 | 
				
			||||||
            p += CTR_DRBG_BLOCKSIZE;
 | 
					            p += CTR_DRBG_BLOCKSIZE;
 | 
				
			||||||
            use_len -= CTR_DRBG_BLOCKSIZE;
 | 
					            use_len -= ( use_len >= CTR_DRBG_BLOCKSIZE ) ?
 | 
				
			||||||
 | 
					                       CTR_DRBG_BLOCKSIZE : use_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            aes_crypt_ecb( &aes_ctx, AES_ENCRYPT, chain, chain );
 | 
					            aes_crypt_ecb( &aes_ctx, AES_ENCRYPT, chain, chain );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -442,7 +442,7 @@ int ecp_tls_write_point( const ecp_group *grp, const ecp_point *pt,
 | 
				
			|||||||
    /*
 | 
					    /*
 | 
				
			||||||
     * write length to the first byte and update total length
 | 
					     * write length to the first byte and update total length
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    buf[0] = *olen;
 | 
					    buf[0] = (unsigned char) *olen;
 | 
				
			||||||
    ++*olen;
 | 
					    ++*olen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
@@ -1427,7 +1427,7 @@ int ecp_mul( ecp_group *grp, ecp_point *R,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    int ret;
 | 
					    int ret;
 | 
				
			||||||
    unsigned char w, m_is_odd, p_eq_g;
 | 
					    unsigned char w, m_is_odd, p_eq_g;
 | 
				
			||||||
    size_t pre_len, naf_len, i, j;
 | 
					    size_t pre_len = 1, naf_len, i, j;
 | 
				
			||||||
    signed char naf[ MAX_NAF_LEN ];
 | 
					    signed char naf[ MAX_NAF_LEN ];
 | 
				
			||||||
    ecp_point Q, *T = NULL, S[2];
 | 
					    ecp_point Q, *T = NULL, S[2];
 | 
				
			||||||
    mpi M;
 | 
					    mpi M;
 | 
				
			||||||
@@ -1469,7 +1469,7 @@ int ecp_mul( ecp_group *grp, ecp_point *R,
 | 
				
			|||||||
    if( w < 2 || w >= grp->nbits )
 | 
					    if( w < 2 || w >= grp->nbits )
 | 
				
			||||||
        w = 2;
 | 
					        w = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pre_len = 1 << ( w - 1 );
 | 
					    pre_len <<= ( w - 1 );
 | 
				
			||||||
    naf_len = grp->nbits / w + 1;
 | 
					    naf_len = grp->nbits / w + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@@ -1478,7 +1478,8 @@ int ecp_mul( ecp_group *grp, ecp_point *R,
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    if( ! p_eq_g || grp->T == NULL )
 | 
					    if( ! p_eq_g || grp->T == NULL )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if( ( T = polarssl_malloc( pre_len * sizeof( ecp_point ) ) ) == NULL )
 | 
					        T = (ecp_point *) polarssl_malloc( pre_len * sizeof( ecp_point ) );
 | 
				
			||||||
 | 
					        if( T == NULL )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            ret = POLARSSL_ERR_ECP_MALLOC_FAILED;
 | 
					            ret = POLARSSL_ERR_ECP_MALLOC_FAILED;
 | 
				
			||||||
            goto cleanup;
 | 
					            goto cleanup;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,7 +59,7 @@ int platform_entropy_poll( void *data, unsigned char *output, size_t len,
 | 
				
			|||||||
        return POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
 | 
					        return POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( CryptGenRandom( provider, len, output ) == FALSE )
 | 
					    if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE )
 | 
				
			||||||
        return POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
 | 
					        return POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CryptReleaseContext( provider, 0 );
 | 
					    CryptReleaseContext( provider, 0 );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -169,7 +169,12 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
 | 
				
			|||||||
    size_t len;
 | 
					    size_t len;
 | 
				
			||||||
    int use_ret;
 | 
					    int use_ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if( buflen == 0 )
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset( buf, 0x00, buflen );
 | 
					    memset( buf, 0x00, buflen );
 | 
				
			||||||
 | 
					    /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
 | 
				
			||||||
 | 
					    buflen -= 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ret < 0 )
 | 
					    if( ret < 0 )
 | 
				
			||||||
        ret = -ret;
 | 
					        ret = -ret;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,7 +68,7 @@ static int rsa_verify_wrap( void *ctx, md_type_t md_alg,
 | 
				
			|||||||
        return( POLARSSL_ERR_RSA_VERIFY_FAILED );
 | 
					        return( POLARSSL_ERR_RSA_VERIFY_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( rsa_pkcs1_verify( (rsa_context *) ctx, NULL, NULL,
 | 
					    return( rsa_pkcs1_verify( (rsa_context *) ctx, NULL, NULL,
 | 
				
			||||||
                RSA_PUBLIC, md_alg, hash_len, hash, sig ) );
 | 
					                RSA_PUBLIC, md_alg, (unsigned int) hash_len, hash, sig ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int rsa_sign_wrap( void *ctx, md_type_t md_alg,
 | 
					static int rsa_sign_wrap( void *ctx, md_type_t md_alg,
 | 
				
			||||||
@@ -79,7 +79,7 @@ static int rsa_sign_wrap( void *ctx, md_type_t md_alg,
 | 
				
			|||||||
    *sig_len = ((rsa_context *) ctx)->len;
 | 
					    *sig_len = ((rsa_context *) ctx)->len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( rsa_pkcs1_sign( (rsa_context *) ctx, f_rng, p_rng, RSA_PRIVATE,
 | 
					    return( rsa_pkcs1_sign( (rsa_context *) ctx, f_rng, p_rng, RSA_PRIVATE,
 | 
				
			||||||
                md_alg, hash_len, hash, sig ) );
 | 
					                md_alg, (unsigned int) hash_len, hash, sig ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int rsa_decrypt_wrap( void *ctx,
 | 
					static int rsa_decrypt_wrap( void *ctx,
 | 
				
			||||||
@@ -361,7 +361,7 @@ static int rsa_alt_sign_wrap( void *ctx, md_type_t md_alg,
 | 
				
			|||||||
    *sig_len = rsa_alt->key_len_func( rsa_alt->key );
 | 
					    *sig_len = rsa_alt->key_len_func( rsa_alt->key );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, RSA_PRIVATE,
 | 
					    return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, RSA_PRIVATE,
 | 
				
			||||||
                md_alg, hash_len, hash, sig ) );
 | 
					                md_alg, (unsigned int) hash_len, hash, sig ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int rsa_alt_decrypt_wrap( void *ctx,
 | 
					static int rsa_alt_decrypt_wrap( void *ctx,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -225,7 +225,7 @@ int pkcs12_derivation( unsigned char *data, size_t datalen,
 | 
				
			|||||||
                       const unsigned char *salt, size_t saltlen,
 | 
					                       const unsigned char *salt, size_t saltlen,
 | 
				
			||||||
                       md_type_t md_type, int id, int iterations )
 | 
					                       md_type_t md_type, int id, int iterations )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret, i;
 | 
					    int ret;
 | 
				
			||||||
    unsigned int j;
 | 
					    unsigned int j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unsigned char diversifier[128];
 | 
					    unsigned char diversifier[128];
 | 
				
			||||||
@@ -234,7 +234,7 @@ int pkcs12_derivation( unsigned char *data, size_t datalen,
 | 
				
			|||||||
    unsigned char *p;
 | 
					    unsigned char *p;
 | 
				
			||||||
    unsigned char c;
 | 
					    unsigned char c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    size_t hlen, use_len, v;
 | 
					    size_t hlen, use_len, v, i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const md_info_t *md_info;
 | 
					    const md_info_t *md_info;
 | 
				
			||||||
    md_context_t md_ctx;
 | 
					    md_context_t md_ctx;
 | 
				
			||||||
@@ -281,7 +281,7 @@ int pkcs12_derivation( unsigned char *data, size_t datalen,
 | 
				
			|||||||
            goto exit;
 | 
					            goto exit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Perform remaining ( iterations - 1 ) recursive hash calculations
 | 
					        // Perform remaining ( iterations - 1 ) recursive hash calculations
 | 
				
			||||||
        for( i = 1; i < iterations; i++ )
 | 
					        for( i = 1; i < (size_t) iterations; i++ )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if( ( ret = md( md_info, hash_output, hlen, hash_output ) ) != 0 )
 | 
					            if( ( ret = md( md_info, hash_output, hlen, hash_output ) ) != 0 )
 | 
				
			||||||
                goto exit;
 | 
					                goto exit;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -269,7 +269,7 @@ int pkcs5_pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
 | 
				
			|||||||
        use_len = ( key_length < md_size ) ? key_length : md_size;
 | 
					        use_len = ( key_length < md_size ) ? key_length : md_size;
 | 
				
			||||||
        memcpy( out_p, work, use_len );
 | 
					        memcpy( out_p, work, use_len );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        key_length -= use_len;
 | 
					        key_length -= (uint32_t) use_len;
 | 
				
			||||||
        out_p += use_len;
 | 
					        out_p += use_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for( i = 4; i > 0; i-- )
 | 
					        for( i = 4; i > 0; i-- )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,7 +71,7 @@ static int pk_write_rsa_pubkey( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* POLARSSL_RSA_C */
 | 
					#endif /* POLARSSL_RSA_C */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -99,7 +99,7 @@ static int pk_write_ec_pubkey( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    *p -= len;
 | 
					    *p -= len;
 | 
				
			||||||
    memcpy( *p, buf, len );
 | 
					    memcpy( *p, buf, len );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -120,7 +120,7 @@ static int pk_write_ec_param( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_oid( p, start, oid, oid_len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_oid( p, start, oid, oid_len ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* POLARSSL_ECP_C */
 | 
					#endif /* POLARSSL_ECP_C */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -142,7 +142,7 @@ int pk_write_pubkey( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
        return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE );
 | 
					        return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pk_write_pubkey_der( pk_context *key, unsigned char *buf, size_t size )
 | 
					int pk_write_pubkey_der( pk_context *key, unsigned char *buf, size_t size )
 | 
				
			||||||
@@ -189,7 +189,7 @@ int pk_write_pubkey_der( pk_context *key, unsigned char *buf, size_t size )
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( &c, buf, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( &c, buf, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( &c, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( &c, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pk_write_key_der( pk_context *key, unsigned char *buf, size_t size )
 | 
					int pk_write_key_der( pk_context *key, unsigned char *buf, size_t size )
 | 
				
			||||||
@@ -273,7 +273,7 @@ int pk_write_key_der( pk_context *key, unsigned char *buf, size_t size )
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
        return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE );
 | 
					        return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(POLARSSL_PEM_WRITE_C)
 | 
					#if defined(POLARSSL_PEM_WRITE_C)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1018,11 +1018,11 @@ int rsa_rsassa_pkcs1_v15_sign( rsa_context *ctx,
 | 
				
			|||||||
         * Digest ::= OCTET STRING
 | 
					         * Digest ::= OCTET STRING
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        *p++ = ASN1_SEQUENCE | ASN1_CONSTRUCTED;
 | 
					        *p++ = ASN1_SEQUENCE | ASN1_CONSTRUCTED;
 | 
				
			||||||
        *p++ = 0x08 + oid_size + hashlen;
 | 
					        *p++ = (unsigned char) ( 0x08 + oid_size + hashlen );
 | 
				
			||||||
        *p++ = ASN1_SEQUENCE | ASN1_CONSTRUCTED;
 | 
					        *p++ = ASN1_SEQUENCE | ASN1_CONSTRUCTED;
 | 
				
			||||||
        *p++ = 0x04 + oid_size;
 | 
					        *p++ = (unsigned char) ( 0x04 + oid_size );
 | 
				
			||||||
        *p++ = ASN1_OID;
 | 
					        *p++ = ASN1_OID;
 | 
				
			||||||
        *p++ = oid_size;
 | 
					        *p++ = oid_size & 0xFF;
 | 
				
			||||||
        memcpy( p, oid, oid_size );
 | 
					        memcpy( p, oid, oid_size );
 | 
				
			||||||
        p += oid_size;
 | 
					        p += oid_size;
 | 
				
			||||||
        *p++ = ASN1_NULL;
 | 
					        *p++ = ASN1_NULL;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1714,7 +1714,7 @@ static int ssl_write_client_key_exchange( ssl_context *ssl )
 | 
				
			|||||||
        i = 6;
 | 
					        i = 6;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ret = dhm_make_public( &ssl->handshake->dhm_ctx,
 | 
					        ret = dhm_make_public( &ssl->handshake->dhm_ctx,
 | 
				
			||||||
                                mpi_size( &ssl->handshake->dhm_ctx.P ),
 | 
					                                (int) mpi_size( &ssl->handshake->dhm_ctx.P ),
 | 
				
			||||||
                               &ssl->out_msg[i], n,
 | 
					                               &ssl->out_msg[i], n,
 | 
				
			||||||
                                ssl->f_rng, ssl->p_rng );
 | 
					                                ssl->f_rng, ssl->p_rng );
 | 
				
			||||||
        if( ret != 0 )
 | 
					        if( ret != 0 )
 | 
				
			||||||
@@ -1845,7 +1845,7 @@ static int ssl_write_client_key_exchange( ssl_context *ssl )
 | 
				
			|||||||
        ssl->out_msg[7 + ssl->psk_identity_len] = (unsigned char)( n      );
 | 
					        ssl->out_msg[7 + ssl->psk_identity_len] = (unsigned char)( n      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ret = dhm_make_public( &ssl->handshake->dhm_ctx,
 | 
					        ret = dhm_make_public( &ssl->handshake->dhm_ctx,
 | 
				
			||||||
                                mpi_size( &ssl->handshake->dhm_ctx.P ),
 | 
					                                (int) mpi_size( &ssl->handshake->dhm_ctx.P ),
 | 
				
			||||||
                               &ssl->out_msg[8 + ssl->psk_identity_len], n,
 | 
					                               &ssl->out_msg[8 + ssl->psk_identity_len], n,
 | 
				
			||||||
                                ssl->f_rng, ssl->p_rng );
 | 
					                                ssl->f_rng, ssl->p_rng );
 | 
				
			||||||
        if( ret != 0 )
 | 
					        if( ret != 0 )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1568,8 +1568,8 @@ static int ssl_write_server_hello( ssl_context *ssl )
 | 
				
			|||||||
#if defined(POLARSSL_HAVE_TIME)
 | 
					#if defined(POLARSSL_HAVE_TIME)
 | 
				
			||||||
    time_t t;
 | 
					    time_t t;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    int ret, n;
 | 
					    int ret;
 | 
				
			||||||
    size_t olen, ext_len = 0;
 | 
					    size_t olen, ext_len = 0, n;
 | 
				
			||||||
    unsigned char *buf, *p;
 | 
					    unsigned char *buf, *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SSL_DEBUG_MSG( 2, ( "=> write server hello" ) );
 | 
					    SSL_DEBUG_MSG( 2, ( "=> write server hello" ) );
 | 
				
			||||||
@@ -1813,7 +1813,7 @@ static int ssl_write_certificate_request( ssl_context *ssl )
 | 
				
			|||||||
    p[1 + ct_len++] = SSL_CERT_TYPE_ECDSA_SIGN;
 | 
					    p[1 + ct_len++] = SSL_CERT_TYPE_ECDSA_SIGN;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p[0] = ct_len++;
 | 
					    p[0] = (unsigned char) ct_len++;
 | 
				
			||||||
    p += ct_len;
 | 
					    p += ct_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sa_len = 0;
 | 
					    sa_len = 0;
 | 
				
			||||||
@@ -1969,7 +1969,7 @@ static int ssl_write_server_key_exchange( ssl_context *ssl )
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if( ( ret = dhm_make_params( &ssl->handshake->dhm_ctx,
 | 
					        if( ( ret = dhm_make_params( &ssl->handshake->dhm_ctx,
 | 
				
			||||||
                                      mpi_size( &ssl->handshake->dhm_ctx.P ),
 | 
					                                      (int) mpi_size( &ssl->handshake->dhm_ctx.P ),
 | 
				
			||||||
                                      p,
 | 
					                                      p,
 | 
				
			||||||
                                      &len, ssl->f_rng, ssl->p_rng ) ) != 0 )
 | 
					                                      &len, ssl->f_rng, ssl->p_rng ) ) != 0 )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,7 +80,8 @@ static int ssl_session_copy( ssl_session *dst, const ssl_session *src )
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        int ret;
 | 
					        int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if( ( dst->peer_cert = polarssl_malloc( sizeof(x509_crt) ) ) == NULL )
 | 
					        dst->peer_cert = (x509_crt *) polarssl_malloc( sizeof(x509_crt) );
 | 
				
			||||||
 | 
					        if( dst->peer_cert == NULL )
 | 
				
			||||||
            return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					            return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        x509_crt_init( dst->peer_cert );
 | 
					        x509_crt_init( dst->peer_cert );
 | 
				
			||||||
@@ -98,7 +99,8 @@ static int ssl_session_copy( ssl_session *dst, const ssl_session *src )
 | 
				
			|||||||
#if defined(POLARSSL_SSL_SESSION_TICKETS)
 | 
					#if defined(POLARSSL_SSL_SESSION_TICKETS)
 | 
				
			||||||
    if( src->ticket != NULL )
 | 
					    if( src->ticket != NULL )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if( ( dst->ticket = polarssl_malloc( src->ticket_len ) ) == NULL )
 | 
					        dst->ticket = (unsigned char *) polarssl_malloc( src->ticket_len );
 | 
				
			||||||
 | 
					        if( dst->ticket == NULL )
 | 
				
			||||||
            return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					            return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        memcpy( dst->ticket, src->ticket, src->ticket_len );
 | 
					        memcpy( dst->ticket, src->ticket, src->ticket_len );
 | 
				
			||||||
@@ -149,7 +151,7 @@ static int ssl3_prf( const unsigned char *secret, size_t slen,
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    for( i = 0; i < dlen / 16; i++ )
 | 
					    for( i = 0; i < dlen / 16; i++ )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        memset( padding, 'A' + i, 1 + i );
 | 
					        memset( padding, (unsigned char) ('A' + i), 1 + i );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        sha1_starts( &sha1 );
 | 
					        sha1_starts( &sha1 );
 | 
				
			||||||
        sha1_update( &sha1, padding, 1 + i );
 | 
					        sha1_update( &sha1, padding, 1 + i );
 | 
				
			||||||
@@ -362,7 +364,7 @@ int ssl_derive_keys( ssl_context *ssl )
 | 
				
			|||||||
    unsigned char *key2;
 | 
					    unsigned char *key2;
 | 
				
			||||||
    unsigned char *mac_enc;
 | 
					    unsigned char *mac_enc;
 | 
				
			||||||
    unsigned char *mac_dec;
 | 
					    unsigned char *mac_dec;
 | 
				
			||||||
    unsigned int iv_copy_len;
 | 
					    size_t iv_copy_len;
 | 
				
			||||||
    const cipher_info_t *cipher_info;
 | 
					    const cipher_info_t *cipher_info;
 | 
				
			||||||
    const md_info_t *md_info;
 | 
					    const md_info_t *md_info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1595,7 +1597,7 @@ static int ssl_decrypt_buf( ssl_context *ssl )
 | 
				
			|||||||
         * correctly. (We round down instead of up, so -56 is the correct
 | 
					         * correctly. (We round down instead of up, so -56 is the correct
 | 
				
			||||||
         * value for our calculations instead of -55)
 | 
					         * value for our calculations instead of -55)
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        int j, extra_run = 0;
 | 
					        size_t j, extra_run = 0;
 | 
				
			||||||
        extra_run = ( 13 + ssl->in_msglen + padlen + 8 ) / 64 -
 | 
					        extra_run = ( 13 + ssl->in_msglen + padlen + 8 ) / 64 -
 | 
				
			||||||
                    ( 13 + ssl->in_msglen          + 8 ) / 64;
 | 
					                    ( 13 + ssl->in_msglen          + 8 ) / 64;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3128,17 +3130,26 @@ static int ssl_handshake_init( ssl_context *ssl )
 | 
				
			|||||||
    if( ssl->transform_negotiate )
 | 
					    if( ssl->transform_negotiate )
 | 
				
			||||||
        ssl_transform_free( ssl->transform_negotiate );
 | 
					        ssl_transform_free( ssl->transform_negotiate );
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        ssl->transform_negotiate = polarssl_malloc( sizeof(ssl_transform) );
 | 
					    {
 | 
				
			||||||
 | 
					        ssl->transform_negotiate =
 | 
				
			||||||
 | 
					            (ssl_transform *) polarssl_malloc( sizeof(ssl_transform) );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ssl->session_negotiate )
 | 
					    if( ssl->session_negotiate )
 | 
				
			||||||
        ssl_session_free( ssl->session_negotiate );
 | 
					        ssl_session_free( ssl->session_negotiate );
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        ssl->session_negotiate = polarssl_malloc( sizeof(ssl_session) );
 | 
					    {
 | 
				
			||||||
 | 
					        ssl->session_negotiate =
 | 
				
			||||||
 | 
					            (ssl_session *) polarssl_malloc( sizeof(ssl_session) );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ssl->handshake )
 | 
					    if( ssl->handshake )
 | 
				
			||||||
        ssl_handshake_free( ssl->handshake );
 | 
					        ssl_handshake_free( ssl->handshake );
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        ssl->handshake = polarssl_malloc( sizeof(ssl_handshake_params) );
 | 
					    {
 | 
				
			||||||
 | 
					        ssl->handshake = (ssl_handshake_params *)
 | 
				
			||||||
 | 
					            polarssl_malloc( sizeof(ssl_handshake_params) );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ssl->handshake == NULL ||
 | 
					    if( ssl->handshake == NULL ||
 | 
				
			||||||
        ssl->transform_negotiate == NULL ||
 | 
					        ssl->transform_negotiate == NULL ||
 | 
				
			||||||
@@ -3329,7 +3340,8 @@ static int ssl_ticket_keys_init( ssl_context *ssl )
 | 
				
			|||||||
    if( ssl->ticket_keys != NULL )
 | 
					    if( ssl->ticket_keys != NULL )
 | 
				
			||||||
        return( 0 );
 | 
					        return( 0 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( tkeys = polarssl_malloc( sizeof( ssl_ticket_keys ) ) ) == NULL )
 | 
					    tkeys = (ssl_ticket_keys *) polarssl_malloc( sizeof(ssl_ticket_keys) );
 | 
				
			||||||
 | 
					    if( tkeys == NULL )
 | 
				
			||||||
        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( ret = ssl->f_rng( ssl->p_rng, tkeys->key_name, 16 ) ) != 0 )
 | 
					    if( ( ret = ssl->f_rng( ssl->p_rng, tkeys->key_name, 16 ) ) != 0 )
 | 
				
			||||||
@@ -3461,7 +3473,8 @@ static ssl_key_cert *ssl_add_key_cert( ssl_context *ssl )
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    ssl_key_cert *key_cert, *last;
 | 
					    ssl_key_cert *key_cert, *last;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( key_cert = polarssl_malloc( sizeof( ssl_key_cert ) ) ) == NULL )
 | 
					    key_cert = (ssl_key_cert *) polarssl_malloc( sizeof(ssl_key_cert) );
 | 
				
			||||||
 | 
					    if( key_cert == NULL )
 | 
				
			||||||
        return( NULL );
 | 
					        return( NULL );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset( key_cert, 0, sizeof( ssl_key_cert ) );
 | 
					    memset( key_cert, 0, sizeof( ssl_key_cert ) );
 | 
				
			||||||
@@ -3512,7 +3525,8 @@ int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert,
 | 
				
			|||||||
    if( key_cert == NULL )
 | 
					    if( key_cert == NULL )
 | 
				
			||||||
        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( key_cert->key = polarssl_malloc( sizeof( pk_context ) ) ) == NULL )
 | 
					    key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) );
 | 
				
			||||||
 | 
					    if( key_cert->key == NULL )
 | 
				
			||||||
        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pk_init( key_cert->key );
 | 
					    pk_init( key_cert->key );
 | 
				
			||||||
@@ -3521,7 +3535,7 @@ int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert,
 | 
				
			|||||||
    if( ret != 0 )
 | 
					    if( ret != 0 )
 | 
				
			||||||
        return( ret );
 | 
					        return( ret );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( ret = rsa_copy( key_cert->key->pk_ctx, rsa_key ) ) != 0 )
 | 
					    if( ( ret = rsa_copy( pk_rsa( *key_cert->key ), rsa_key ) ) != 0 )
 | 
				
			||||||
        return( ret );
 | 
					        return( ret );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    key_cert->cert = own_cert;
 | 
					    key_cert->cert = own_cert;
 | 
				
			||||||
@@ -3543,7 +3557,8 @@ int ssl_set_own_cert_alt( ssl_context *ssl, x509_crt *own_cert,
 | 
				
			|||||||
    if( key_cert == NULL )
 | 
					    if( key_cert == NULL )
 | 
				
			||||||
        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( key_cert->key = polarssl_malloc( sizeof( pk_context ) ) ) == NULL )
 | 
					    key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) );
 | 
				
			||||||
 | 
					    if( key_cert->key == NULL )
 | 
				
			||||||
        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pk_init( key_cert->key );
 | 
					    pk_init( key_cert->key );
 | 
				
			||||||
@@ -3575,8 +3590,8 @@ int ssl_set_psk( ssl_context *ssl, const unsigned char *psk, size_t psk_len,
 | 
				
			|||||||
    ssl->psk_len = psk_len;
 | 
					    ssl->psk_len = psk_len;
 | 
				
			||||||
    ssl->psk_identity_len = psk_identity_len;
 | 
					    ssl->psk_identity_len = psk_identity_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ssl->psk = polarssl_malloc( ssl->psk_len );
 | 
					    ssl->psk = (unsigned char *) polarssl_malloc( ssl->psk_len );
 | 
				
			||||||
    ssl->psk_identity = polarssl_malloc( ssl->psk_identity_len );
 | 
					    ssl->psk_identity = (unsigned char *) polarssl_malloc( ssl->psk_identity_len );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ssl->psk == NULL || ssl->psk_identity == NULL )
 | 
					    if( ssl->psk == NULL || ssl->psk_identity == NULL )
 | 
				
			||||||
        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
					        return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -159,7 +159,7 @@ static int x509_write_name( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SET ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SET ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int x509_write_names( unsigned char **p, unsigned char *start,
 | 
					int x509_write_names( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -180,7 +180,7 @@ int x509_write_names( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int x509_write_sig( unsigned char **p, unsigned char *start,
 | 
					int x509_write_sig( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -208,7 +208,7 @@ int x509_write_sig( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_algorithm_identifier( p, start, oid,
 | 
					    ASN1_CHK_ADD( len, asn1_write_algorithm_identifier( p, start, oid,
 | 
				
			||||||
                                                        oid_len, 0 ) );
 | 
					                                                        oid_len, 0 ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int x509_write_extension( unsigned char **p, unsigned char *start,
 | 
					static int x509_write_extension( unsigned char **p, unsigned char *start,
 | 
				
			||||||
@@ -235,7 +235,7 @@ static int x509_write_extension( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -261,7 +261,7 @@ int x509_write_extensions( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
        cur_ext = cur_ext->next;
 | 
					        cur_ext = cur_ext->next;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* POLARSSL_X509_CREATE_C */
 | 
					#endif /* POLARSSL_X509_CREATE_C */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -940,7 +940,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
 | 
				
			|||||||
    WCHAR szDir[MAX_PATH];
 | 
					    WCHAR szDir[MAX_PATH];
 | 
				
			||||||
    char filename[MAX_PATH];
 | 
					    char filename[MAX_PATH];
 | 
				
			||||||
	char *p;
 | 
						char *p;
 | 
				
			||||||
    int len = strlen( path );
 | 
					    int len = (int) strlen( path );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	WIN32_FIND_DATAW file_data;
 | 
						WIN32_FIND_DATAW file_data;
 | 
				
			||||||
    HANDLE hFind;
 | 
					    HANDLE hFind;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -270,7 +270,7 @@ static int x509_write_time( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
        ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_GENERALIZED_TIME ) );
 | 
					        ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_GENERALIZED_TIME ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
 | 
					int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
 | 
				
			||||||
@@ -396,7 +396,7 @@ int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PEM_BEGIN_CRT           "-----BEGIN CERTIFICATE-----\n"
 | 
					#define PEM_BEGIN_CRT           "-----BEGIN CERTIFICATE-----\n"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -209,7 +209,7 @@ int x509write_csr_der( x509write_csr *ctx, unsigned char *buf, size_t size,
 | 
				
			|||||||
    ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) );
 | 
				
			||||||
    ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
					    ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PEM_BEGIN_CSR           "-----BEGIN CERTIFICATE REQUEST-----\n"
 | 
					#define PEM_BEGIN_CSR           "-----BEGIN CERTIFICATE REQUEST-----\n"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,12 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
 | 
				
			|||||||
    size_t len;
 | 
					    size_t len;
 | 
				
			||||||
    int use_ret;
 | 
					    int use_ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if( buflen == 0 )
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset( buf, 0x00, buflen );
 | 
					    memset( buf, 0x00, buflen );
 | 
				
			||||||
 | 
					    /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
 | 
				
			||||||
 | 
					    buflen -= 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ret < 0 )
 | 
					    if( ret < 0 )
 | 
				
			||||||
        ret = -ret;
 | 
					        ret = -ret;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user