Cleanup up non-prototyped functions (static) and const-correctness
More fixes based on the compiler directives -Wcast-qual -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations. Not everything with regards to -Wcast-qual has been fixed as some have unwanted consequences for the rest of the code.
This commit is contained in:
parent
169b7f4a13
commit
b6c5d2e1a6
@ -86,7 +86,7 @@ void pem_init( pem_context *ctx );
|
||||
*
|
||||
* \return 0 on success, ior a specific PEM error code
|
||||
*/
|
||||
int pem_read_buffer( pem_context *ctx, char *header, char *footer,
|
||||
int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
|
||||
const unsigned char *data,
|
||||
const unsigned char *pwd,
|
||||
size_t pwdlen, size_t *use_len );
|
||||
|
@ -383,11 +383,11 @@ struct _ssl_handshake_params
|
||||
sha2_context fin_sha2;
|
||||
sha4_context fin_sha4;
|
||||
|
||||
void (*update_checksum)(ssl_context *, unsigned char *, size_t);
|
||||
void (*update_checksum)(ssl_context *, const unsigned char *, size_t);
|
||||
void (*calc_verify)(ssl_context *, unsigned char *);
|
||||
void (*calc_finished)(ssl_context *, unsigned char *, int);
|
||||
int (*tls_prf)(unsigned char *, size_t, char *,
|
||||
unsigned char *, size_t,
|
||||
int (*tls_prf)(const unsigned char *, size_t, const char *,
|
||||
const unsigned char *, size_t,
|
||||
unsigned char *, size_t);
|
||||
|
||||
size_t pmslen; /*!< premaster length */
|
||||
|
@ -66,7 +66,7 @@ extern "C" {
|
||||
* \param ctx XTEA context to be initialized
|
||||
* \param key the secret key
|
||||
*/
|
||||
void xtea_setup( xtea_context *ctx, unsigned char key[16] );
|
||||
void xtea_setup( xtea_context *ctx, const unsigned char key[16] );
|
||||
|
||||
/**
|
||||
* \brief XTEA cipher function
|
||||
@ -80,7 +80,7 @@ void xtea_setup( xtea_context *ctx, unsigned char key[16] );
|
||||
*/
|
||||
int xtea_crypt_ecb( xtea_context *ctx,
|
||||
int mode,
|
||||
unsigned char input[8],
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8] );
|
||||
|
||||
/**
|
||||
@ -100,7 +100,7 @@ int xtea_crypt_cbc( xtea_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[8],
|
||||
unsigned char *input,
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* CTR_DRBG implementation based on AES-256 (NIST SP 800-90)
|
||||
*
|
||||
* Copyright (C) 2006-2011, Brainspark B.V.
|
||||
* 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>
|
||||
@ -42,7 +42,7 @@
|
||||
* Non-public function wrapped by ctr_crbg_init(). Necessary to allow NIST
|
||||
* tests to succeed (which require known length fixed entropy)
|
||||
*/
|
||||
int ctr_drbg_init_entropy_len(
|
||||
static int ctr_drbg_init_entropy_len(
|
||||
ctr_drbg_context *ctx,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
@ -92,14 +92,14 @@ void ctr_drbg_set_entropy_len( ctr_drbg_context *ctx, size_t len )
|
||||
{
|
||||
ctx->entropy_len = len;
|
||||
}
|
||||
|
||||
|
||||
void ctr_drbg_set_reseed_interval( ctr_drbg_context *ctx, int interval )
|
||||
{
|
||||
ctx->reseed_interval = interval;
|
||||
}
|
||||
|
||||
int block_cipher_df( unsigned char *output,
|
||||
const unsigned char *data, size_t data_len )
|
||||
|
||||
static int block_cipher_df( unsigned char *output,
|
||||
const unsigned char *data, size_t data_len )
|
||||
{
|
||||
unsigned char buf[CTR_DRBG_MAX_SEED_INPUT + CTR_DRBG_BLOCKSIZE + 16];
|
||||
unsigned char tmp[CTR_DRBG_SEEDLEN];
|
||||
@ -180,7 +180,7 @@ int block_cipher_df( unsigned char *output,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int ctr_drbg_update_internal( ctr_drbg_context *ctx,
|
||||
static int ctr_drbg_update_internal( ctr_drbg_context *ctx,
|
||||
const unsigned char data[CTR_DRBG_SEEDLEN] )
|
||||
{
|
||||
unsigned char tmp[CTR_DRBG_SEEDLEN];
|
||||
@ -449,7 +449,8 @@ unsigned char result_nopr[16] =
|
||||
0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f };
|
||||
|
||||
int test_offset;
|
||||
int ctr_drbg_self_test_entropy( void *data, unsigned char *buf, size_t len )
|
||||
static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf,
|
||||
size_t len )
|
||||
{
|
||||
unsigned char *p = data;
|
||||
memcpy( buf, p + test_offset, len );
|
||||
|
@ -1296,7 +1296,7 @@ int ecp_self_test( int verbose )
|
||||
ecp_point R;
|
||||
mpi m;
|
||||
unsigned long add_c_prev, dbl_c_prev;
|
||||
char *exponents[] =
|
||||
const char *exponents[] =
|
||||
{
|
||||
"000000000000000000000000000000000000000000000000", /* zero */
|
||||
"000000000000000000000000000000000000000000000001", /* one */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Entropy accumulator implementation
|
||||
*
|
||||
* Copyright (C) 2006-2011, Brainspark B.V.
|
||||
* 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>
|
||||
@ -81,14 +81,14 @@ int entropy_add_source( entropy_context *ctx,
|
||||
/*
|
||||
* Entropy accumulator update
|
||||
*/
|
||||
int entropy_update( entropy_context *ctx, unsigned char source_id,
|
||||
const unsigned char *data, size_t len )
|
||||
static int entropy_update( entropy_context *ctx, unsigned char source_id,
|
||||
const unsigned char *data, size_t len )
|
||||
{
|
||||
unsigned char header[2];
|
||||
unsigned char tmp[ENTROPY_BLOCK_SIZE];
|
||||
size_t use_len = len;
|
||||
const unsigned char *p = data;
|
||||
|
||||
|
||||
if( use_len > ENTROPY_BLOCK_SIZE )
|
||||
{
|
||||
sha4( data, len, tmp, 0 );
|
||||
@ -102,7 +102,7 @@ int entropy_update( entropy_context *ctx, unsigned char source_id,
|
||||
|
||||
sha4_update( &ctx->accumulator, header, 2 );
|
||||
sha4_update( &ctx->accumulator, p, use_len );
|
||||
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* NIST SP800-38D compliant GCM implementation
|
||||
*
|
||||
* Copyright (C) 2006-2012, Brainspark B.V.
|
||||
* 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>
|
||||
@ -123,7 +123,8 @@ static const uint64_t last4[16] =
|
||||
0x9180, 0x8da0, 0xa9c0, 0xb5e0
|
||||
};
|
||||
|
||||
void gcm_mult( gcm_context *ctx, const unsigned char x[16], unsigned char output[16] )
|
||||
static void gcm_mult( gcm_context *ctx, const unsigned char x[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
int i = 0;
|
||||
unsigned char z[16];
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2010, Brainspark B.V.
|
||||
* 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>
|
||||
@ -76,7 +76,7 @@ static void md2_finish_wrap( void *ctx, unsigned char *output )
|
||||
md2_finish( (md2_context *) ctx, output );
|
||||
}
|
||||
|
||||
int md2_file_wrap( const char *path, unsigned char *output )
|
||||
static int md2_file_wrap( const char *path, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_FS_IO)
|
||||
return md2_file( path, output );
|
||||
@ -246,7 +246,7 @@ static void md5_finish_wrap( void *ctx, unsigned char *output )
|
||||
md5_finish( (md5_context *) ctx, output );
|
||||
}
|
||||
|
||||
int md5_file_wrap( const char *path, unsigned char *output )
|
||||
static int md5_file_wrap( const char *path, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_FS_IO)
|
||||
return md5_file( path, output );
|
||||
|
@ -351,7 +351,7 @@ static const oid_descriptor_t *oid_descriptor_from_buf(
|
||||
const unsigned char *oid,
|
||||
size_t len )
|
||||
{
|
||||
const unsigned char *p = (unsigned char *) struct_set;
|
||||
const unsigned char *p = (const unsigned char *) struct_set;
|
||||
const oid_descriptor_t *cur;
|
||||
|
||||
if( struct_set == NULL || oid == NULL )
|
||||
|
@ -178,7 +178,9 @@ static void pem_aes_decrypt( unsigned char aes_iv[16], unsigned int keylen,
|
||||
|
||||
#endif /* POLARSSL_MD5_C && (POLARSSL_AES_C || POLARSSL_DES_C) */
|
||||
|
||||
int pem_read_buffer( pem_context *ctx, char *header, char *footer, const unsigned char *data, const unsigned char *pwd, size_t pwdlen, size_t *use_len )
|
||||
int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
|
||||
const unsigned char *data, const unsigned char *pwd,
|
||||
size_t pwdlen, size_t *use_len )
|
||||
{
|
||||
int ret, enc;
|
||||
size_t len;
|
||||
|
@ -195,9 +195,9 @@ static int ssl_parse_signature_algorithms_ext( ssl_context *ssl,
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_ECP_C)
|
||||
int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
size_t len )
|
||||
static int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
size_t len )
|
||||
{
|
||||
size_t list_size;
|
||||
const unsigned char *p;
|
||||
@ -231,9 +231,9 @@ int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int ssl_parse_supported_point_formats( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
size_t len )
|
||||
static int ssl_parse_supported_point_formats( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
size_t len )
|
||||
{
|
||||
size_t list_size;
|
||||
const unsigned char *p;
|
||||
|
@ -96,8 +96,9 @@ static size_t ssl_rsa_key_len( void *ctx )
|
||||
/*
|
||||
* Key material generation
|
||||
*/
|
||||
static int ssl3_prf( unsigned char *secret, size_t slen, char *label,
|
||||
unsigned char *random, size_t rlen,
|
||||
static int ssl3_prf( const unsigned char *secret, size_t slen,
|
||||
const char *label,
|
||||
const unsigned char *random, size_t rlen,
|
||||
unsigned char *dstbuf, size_t dlen )
|
||||
{
|
||||
size_t i;
|
||||
@ -140,13 +141,14 @@ static int ssl3_prf( unsigned char *secret, size_t slen, char *label,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int tls1_prf( unsigned char *secret, size_t slen, char *label,
|
||||
unsigned char *random, size_t rlen,
|
||||
static int tls1_prf( const unsigned char *secret, size_t slen,
|
||||
const char *label,
|
||||
const unsigned char *random, size_t rlen,
|
||||
unsigned char *dstbuf, size_t dlen )
|
||||
{
|
||||
size_t nb, hs;
|
||||
size_t i, j, k;
|
||||
unsigned char *S1, *S2;
|
||||
const unsigned char *S1, *S2;
|
||||
unsigned char tmp[128];
|
||||
unsigned char h_i[20];
|
||||
|
||||
@ -200,8 +202,9 @@ static int tls1_prf( unsigned char *secret, size_t slen, char *label,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int tls_prf_sha256( unsigned char *secret, size_t slen, char *label,
|
||||
unsigned char *random, size_t rlen,
|
||||
static int tls_prf_sha256( const unsigned char *secret, size_t slen,
|
||||
const char *label,
|
||||
const unsigned char *random, size_t rlen,
|
||||
unsigned char *dstbuf, size_t dlen )
|
||||
{
|
||||
size_t nb;
|
||||
@ -240,8 +243,9 @@ static int tls_prf_sha256( unsigned char *secret, size_t slen, char *label,
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_SHA4_C)
|
||||
static int tls_prf_sha384( unsigned char *secret, size_t slen, char *label,
|
||||
unsigned char *random, size_t rlen,
|
||||
static int tls_prf_sha384( const unsigned char *secret, size_t slen,
|
||||
const char *label,
|
||||
const unsigned char *random, size_t rlen,
|
||||
unsigned char *dstbuf, size_t dlen )
|
||||
{
|
||||
size_t nb;
|
||||
@ -280,9 +284,9 @@ static int tls_prf_sha384( unsigned char *secret, size_t slen, char *label,
|
||||
}
|
||||
#endif
|
||||
|
||||
static void ssl_update_checksum_start(ssl_context *, unsigned char *, size_t);
|
||||
static void ssl_update_checksum_md5sha1(ssl_context *, unsigned char *, size_t);
|
||||
static void ssl_update_checksum_sha256(ssl_context *, unsigned char *, size_t);
|
||||
static void ssl_update_checksum_start(ssl_context *, const unsigned char *, size_t);
|
||||
static void ssl_update_checksum_md5sha1(ssl_context *, const unsigned char *, size_t);
|
||||
static void ssl_update_checksum_sha256(ssl_context *, const unsigned char *, size_t);
|
||||
|
||||
static void ssl_calc_verify_ssl(ssl_context *,unsigned char *);
|
||||
static void ssl_calc_verify_tls(ssl_context *,unsigned char *);
|
||||
@ -293,7 +297,7 @@ static void ssl_calc_finished_tls(ssl_context *,unsigned char *,int);
|
||||
static void ssl_calc_finished_tls_sha256(ssl_context *,unsigned char *,int);
|
||||
|
||||
#if defined(POLARSSL_SHA4_C)
|
||||
static void ssl_update_checksum_sha384(ssl_context *, unsigned char *, size_t);
|
||||
static void ssl_update_checksum_sha384(ssl_context *, const unsigned char *, size_t);
|
||||
static void ssl_calc_verify_tls_sha384(ssl_context *,unsigned char *);
|
||||
static void ssl_calc_finished_tls_sha384(ssl_context *,unsigned char *,int);
|
||||
#endif
|
||||
@ -2229,8 +2233,8 @@ void ssl_optimize_checksum( ssl_context *ssl,
|
||||
ssl->handshake->update_checksum = ssl_update_checksum_sha256;
|
||||
}
|
||||
|
||||
static void ssl_update_checksum_start( ssl_context *ssl, unsigned char *buf,
|
||||
size_t len )
|
||||
static void ssl_update_checksum_start( ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len )
|
||||
{
|
||||
md5_update( &ssl->handshake->fin_md5 , buf, len );
|
||||
sha1_update( &ssl->handshake->fin_sha1, buf, len );
|
||||
@ -2240,22 +2244,22 @@ static void ssl_update_checksum_start( ssl_context *ssl, unsigned char *buf,
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ssl_update_checksum_md5sha1( ssl_context *ssl, unsigned char *buf,
|
||||
size_t len )
|
||||
static void ssl_update_checksum_md5sha1( ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len )
|
||||
{
|
||||
md5_update( &ssl->handshake->fin_md5 , buf, len );
|
||||
sha1_update( &ssl->handshake->fin_sha1, buf, len );
|
||||
}
|
||||
|
||||
static void ssl_update_checksum_sha256( ssl_context *ssl, unsigned char *buf,
|
||||
size_t len )
|
||||
static void ssl_update_checksum_sha256( ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len )
|
||||
{
|
||||
sha2_update( &ssl->handshake->fin_sha2, buf, len );
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_SHA4_C)
|
||||
static void ssl_update_checksum_sha384( ssl_context *ssl, unsigned char *buf,
|
||||
size_t len )
|
||||
static void ssl_update_checksum_sha384( ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len )
|
||||
{
|
||||
sha4_update( &ssl->handshake->fin_sha4, buf, len );
|
||||
}
|
||||
@ -2382,7 +2386,7 @@ static void ssl_calc_finished_tls(
|
||||
md5_finish( &md5, padbuf );
|
||||
sha1_finish( &sha1, padbuf + 16 );
|
||||
|
||||
ssl->handshake->tls_prf( session->master, 48, (char *) sender,
|
||||
ssl->handshake->tls_prf( session->master, 48, sender,
|
||||
padbuf, 36, buf, len );
|
||||
|
||||
SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
|
||||
@ -2428,7 +2432,7 @@ static void ssl_calc_finished_tls_sha256(
|
||||
|
||||
sha2_finish( &sha2, padbuf );
|
||||
|
||||
ssl->handshake->tls_prf( session->master, 48, (char *) sender,
|
||||
ssl->handshake->tls_prf( session->master, 48, sender,
|
||||
padbuf, 32, buf, len );
|
||||
|
||||
SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
|
||||
@ -2474,7 +2478,7 @@ static void ssl_calc_finished_tls_sha384(
|
||||
|
||||
sha4_finish( &sha4, padbuf );
|
||||
|
||||
ssl->handshake->tls_prf( session->master, 48, (char *) sender,
|
||||
ssl->handshake->tls_prf( session->master, 48, sender,
|
||||
padbuf, 48, buf, len );
|
||||
|
||||
SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
|
||||
@ -2689,7 +2693,7 @@ int ssl_parse_finished( ssl_context *ssl )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int ssl_handshake_init( ssl_context *ssl )
|
||||
static int ssl_handshake_init( ssl_context *ssl )
|
||||
{
|
||||
if( ssl->transform_negotiate )
|
||||
ssl_transform_free( ssl->transform_negotiate );
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* X.509 certificate and private key decoding
|
||||
*
|
||||
* Copyright (C) 2006-2011, Brainspark B.V.
|
||||
* 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>
|
||||
@ -1113,8 +1113,8 @@ static int x509_get_sig_alg( const x509_buf *sig_oid, md_type_t *md_alg,
|
||||
/*
|
||||
* Parse and fill a single X.509 certificate in DER format
|
||||
*/
|
||||
int x509parse_crt_der_core( x509_cert *crt, const unsigned char *buf,
|
||||
size_t buflen )
|
||||
static int x509parse_crt_der_core( x509_cert *crt, const unsigned char *buf,
|
||||
size_t buflen )
|
||||
{
|
||||
int ret;
|
||||
size_t len;
|
||||
@ -1813,7 +1813,7 @@ int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
|
||||
/*
|
||||
* Load all data from a file into a given buffer.
|
||||
*/
|
||||
int load_file( const char *path, unsigned char **buf, size_t *n )
|
||||
static int load_file( const char *path, unsigned char **buf, size_t *n )
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
@ -1994,7 +1994,7 @@ int x509parse_keyfile( rsa_context *rsa, const char *path, const char *pwd )
|
||||
ret = x509parse_key( rsa, buf, n, NULL, 0 );
|
||||
else
|
||||
ret = x509parse_key( rsa, buf, n,
|
||||
(unsigned char *) pwd, strlen( pwd ) );
|
||||
(const unsigned char *) pwd, strlen( pwd ) );
|
||||
|
||||
memset( buf, 0, n + 1 );
|
||||
free( buf );
|
||||
@ -3101,7 +3101,7 @@ static int x509parse_verifycrl(x509_cert *crt, x509_cert *ca,
|
||||
return flags;
|
||||
}
|
||||
|
||||
int x509_wildcard_verify( const char *cn, x509_buf *name )
|
||||
static int x509_wildcard_verify( const char *cn, x509_buf *name )
|
||||
{
|
||||
size_t i;
|
||||
size_t cn_idx = 0;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* X509 buffer writing functionality
|
||||
*
|
||||
* Copyright (C) 2006-2012, Brainspark B.V.
|
||||
* 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>
|
||||
@ -109,8 +109,8 @@ int x509_write_key_der( unsigned char *buf, size_t size, rsa_context *rsa )
|
||||
return( len );
|
||||
}
|
||||
|
||||
int x509_write_name( unsigned char **p, unsigned char *start, char *oid,
|
||||
char *name )
|
||||
static int x509_write_name( unsigned char **p, unsigned char *start, char *oid,
|
||||
char *name )
|
||||
{
|
||||
int ret;
|
||||
size_t string_len = 0;
|
||||
@ -141,8 +141,8 @@ int x509_write_name( unsigned char **p, unsigned char *start, char *oid,
|
||||
return( len );
|
||||
}
|
||||
|
||||
int x509_write_sig( unsigned char **p, unsigned char *start, const char *oid,
|
||||
unsigned char *sig, size_t size )
|
||||
static int x509_write_sig( unsigned char **p, unsigned char *start,
|
||||
const char *oid, unsigned char *sig, size_t size )
|
||||
{
|
||||
int ret;
|
||||
size_t len = 0;
|
||||
@ -209,7 +209,7 @@ int x509_write_cert_req( unsigned char *buf, size_t size, rsa_context *rsa,
|
||||
while( cur != NULL )
|
||||
{
|
||||
ASN1_CHK_ADD( sub_len, x509_write_name( &c, tmp_buf, cur->oid, cur->name ) );
|
||||
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ int x509_write_cert_req( unsigned char *buf, size_t size, rsa_context *rsa,
|
||||
|
||||
ASN1_CHK_ADD( len, asn1_write_len( &c, tmp_buf, len ) );
|
||||
ASN1_CHK_ADD( len, asn1_write_tag( &c, tmp_buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
|
||||
|
||||
|
||||
md( md_info_from_type( md_alg ), c, len, hash );
|
||||
|
||||
rsa_pkcs1_sign( rsa, NULL, NULL, RSA_PRIVATE, md_alg, 0, hash, sig );
|
||||
@ -232,10 +232,10 @@ int x509_write_cert_req( unsigned char *buf, size_t size, rsa_context *rsa,
|
||||
|
||||
c2 = buf + size - 1;
|
||||
ASN1_CHK_ADD( sig_len, x509_write_sig( &c2, buf, sig_oid, sig, rsa->len ) );
|
||||
|
||||
|
||||
c2 -= len;
|
||||
memcpy( c2, c, len );
|
||||
|
||||
memcpy( c2, c, len );
|
||||
|
||||
len += sig_len;
|
||||
ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) );
|
||||
ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
|
||||
|
@ -57,7 +57,7 @@
|
||||
/*
|
||||
* XTEA key schedule
|
||||
*/
|
||||
void xtea_setup( xtea_context *ctx, unsigned char key[16] )
|
||||
void xtea_setup( xtea_context *ctx, const unsigned char key[16] )
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -72,13 +72,13 @@ void xtea_setup( xtea_context *ctx, unsigned char key[16] )
|
||||
/*
|
||||
* XTEA encrypt function
|
||||
*/
|
||||
int xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
|
||||
unsigned char output[8])
|
||||
int xtea_crypt_ecb( xtea_context *ctx, int mode,
|
||||
const unsigned char input[8], unsigned char output[8])
|
||||
{
|
||||
uint32_t *k, v0, v1, i;
|
||||
|
||||
k = ctx->k;
|
||||
|
||||
|
||||
GET_UINT32_BE( v0, input, 0 );
|
||||
GET_UINT32_BE( v1, input, 4 );
|
||||
|
||||
@ -114,27 +114,24 @@ int xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
|
||||
/*
|
||||
* XTEA-CBC buffer encryption/decryption
|
||||
*/
|
||||
int xtea_crypt_cbc( xtea_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[8],
|
||||
unsigned char *input,
|
||||
int xtea_crypt_cbc( xtea_context *ctx, int mode, size_t length,
|
||||
unsigned char iv[8], const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
int i;
|
||||
unsigned char temp[8];
|
||||
|
||||
if(length % 8)
|
||||
if( length % 8 )
|
||||
return( POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH );
|
||||
|
||||
if( mode == XTEA_DECRYPT )
|
||||
if( mode == XTEA_DECRYPT )
|
||||
{
|
||||
while( length > 0 )
|
||||
{
|
||||
memcpy( temp, input, 8 );
|
||||
xtea_crypt_ecb( ctx, mode, input, output );
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
for(i = 0; i < 8; i++)
|
||||
output[i] = (unsigned char)( output[i] ^ iv[i] );
|
||||
|
||||
memcpy( iv, temp, 8 );
|
||||
@ -143,8 +140,8 @@ int xtea_crypt_cbc( xtea_context *ctx,
|
||||
output += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
while( length > 0 )
|
||||
{
|
||||
@ -153,7 +150,7 @@ int xtea_crypt_cbc( xtea_context *ctx,
|
||||
|
||||
xtea_crypt_ecb( ctx, mode, output, output );
|
||||
memcpy( iv, output, 8 );
|
||||
|
||||
|
||||
input += 8;
|
||||
output += 8;
|
||||
length -= 8;
|
||||
@ -225,7 +222,7 @@ int xtea_self_test( int verbose )
|
||||
|
||||
memcpy( buf, xtea_test_pt[i], 8 );
|
||||
|
||||
xtea_setup( &ctx, (unsigned char *) xtea_test_key[i] );
|
||||
xtea_setup( &ctx, xtea_test_key[i] );
|
||||
xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, buf, buf );
|
||||
|
||||
if( memcmp( buf, xtea_test_ct[i], 8 ) != 0 )
|
||||
|
@ -28,7 +28,7 @@ typedef UINT32 uint32_t;
|
||||
}
|
||||
#endif
|
||||
|
||||
int unhexify(unsigned char *obuf, const char *ibuf)
|
||||
static int unhexify(unsigned char *obuf, const char *ibuf)
|
||||
{
|
||||
unsigned char c, c2;
|
||||
int len = strlen(ibuf) / 2;
|
||||
@ -62,7 +62,7 @@ int unhexify(unsigned char *obuf, const char *ibuf)
|
||||
return len;
|
||||
}
|
||||
|
||||
void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
|
||||
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
|
||||
{
|
||||
unsigned char l, h;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user