Changeset 1014
- Timestamp:
- 04/24/11 10:57:21 (13 months ago)
- Location:
- trunk
- Files:
-
- 67 edited
-
ChangeLog (modified) (1 diff)
-
include/polarssl/aes.h (modified) (5 diffs)
-
include/polarssl/arc4.h (modified) (3 diffs)
-
include/polarssl/base64.h (modified) (3 diffs)
-
include/polarssl/bignum.h (modified) (21 diffs)
-
include/polarssl/camellia.h (modified) (5 diffs)
-
include/polarssl/cipher.h (modified) (7 diffs)
-
include/polarssl/debug.h (modified) (1 diff)
-
include/polarssl/des.h (modified) (3 diffs)
-
include/polarssl/dhm.h (modified) (5 diffs)
-
include/polarssl/md.h (modified) (14 diffs)
-
include/polarssl/md2.h (modified) (7 diffs)
-
include/polarssl/md4.h (modified) (6 diffs)
-
include/polarssl/md5.h (modified) (6 diffs)
-
include/polarssl/net.h (modified) (3 diffs)
-
include/polarssl/padlock.h (modified) (1 diff)
-
include/polarssl/pem.h (modified) (3 diffs)
-
include/polarssl/pkcs11.h (modified) (2 diffs)
-
include/polarssl/rsa.h (modified) (10 diffs)
-
include/polarssl/sha1.h (modified) (6 diffs)
-
include/polarssl/sha2.h (modified) (6 diffs)
-
include/polarssl/sha4.h (modified) (6 diffs)
-
include/polarssl/ssl.h (modified) (11 diffs)
-
include/polarssl/x509.h (modified) (7 diffs)
-
include/polarssl/xtea.h (modified) (3 diffs)
-
library/aes.c (modified) (5 diffs)
-
library/arc4.c (modified) (2 diffs)
-
library/base64.c (modified) (3 diffs)
-
library/bignum.c (modified) (55 diffs)
-
library/camellia.c (modified) (5 diffs)
-
library/cipher.c (modified) (4 diffs)
-
library/cipher_wrap.c (modified) (15 diffs)
-
library/debug.c (modified) (4 diffs)
-
library/des.c (modified) (3 diffs)
-
library/dhm.c (modified) (5 diffs)
-
library/havege.c (modified) (1 diff)
-
library/md.c (modified) (6 diffs)
-
library/md2.c (modified) (7 diffs)
-
library/md4.c (modified) (7 diffs)
-
library/md5.c (modified) (7 diffs)
-
library/md_wrap.c (modified) (33 diffs)
-
library/net.c (modified) (4 diffs)
-
library/padlock.c (modified) (2 diffs)
-
library/pem.c (modified) (7 diffs)
-
library/pkcs11.c (modified) (3 diffs)
-
library/rsa.c (modified) (15 diffs)
-
library/sha1.c (modified) (7 diffs)
-
library/sha2.c (modified) (7 diffs)
-
library/sha4.c (modified) (7 diffs)
-
library/ssl_cli.c (modified) (11 diffs)
-
library/ssl_srv.c (modified) (11 diffs)
-
library/ssl_tls.c (modified) (24 diffs)
-
library/x509parse.c (modified) (45 diffs)
-
library/xtea.c (modified) (5 diffs)
-
programs/aes/aescrypt2.c (modified) (1 diff)
-
programs/aes/crypt_and_hash.c (modified) (2 diffs)
-
programs/hash/generic_sum.c (modified) (1 diff)
-
programs/hash/md5sum.c (modified) (1 diff)
-
programs/hash/sha1sum.c (modified) (1 diff)
-
programs/hash/sha2sum.c (modified) (1 diff)
-
programs/pkey/dh_client.c (modified) (5 diffs)
-
programs/pkey/dh_server.c (modified) (3 diffs)
-
programs/pkey/rsa_sign.c (modified) (1 diff)
-
programs/pkey/rsa_verify.c (modified) (1 diff)
-
programs/pkey/rsa_verify_pss.c (modified) (1 diff)
-
programs/ssl/ssl_client2.c (modified) (1 diff)
-
tests/suites/test_suite_cipher.function (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r1011 r1014 6 6 (AES CTR, Camellia CTR, XTEA CBC) including the option to 7 7 enable and disable individual modes when needed 8 9 Changes 10 * Major argument / variable rewrite. Introduced use of size_t 11 instead of int for buffer lengths and loop variables for 12 better unsigned / signed use 8 13 9 14 = Version 0.99-pre4 released on 2011-04-01 -
trunk/include/polarssl/aes.h
r1011 r1014 27 27 #ifndef POLARSSL_AES_H 28 28 #define POLARSSL_AES_H 29 30 #include <string.h> 29 31 30 32 #define AES_ENCRYPT 1 … … 58 60 * \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH 59 61 */ 60 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize );62 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize ); 61 63 62 64 /** … … 69 71 * \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH 70 72 */ 71 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize );73 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int keysize ); 72 74 73 75 /** … … 102 104 int aes_crypt_cbc( aes_context *ctx, 103 105 int mode, 104 int length,106 size_t length, 105 107 unsigned char iv[16], 106 108 const unsigned char *input, … … 122 124 int aes_crypt_cfb128( aes_context *ctx, 123 125 int mode, 124 int length,126 size_t length, 125 127 int *iv_off, 126 128 unsigned char iv[16], -
trunk/include/polarssl/arc4.h
r913 r1014 28 28 #define POLARSSL_ARC4_H 29 29 30 #include <string.h> 31 30 32 /** 31 33 * \brief ARC4 context structure … … 50 52 * \param keylen length of the key 51 53 */ 52 void arc4_setup( arc4_context *ctx, const unsigned char *key, int keylen );54 void arc4_setup( arc4_context *ctx, const unsigned char *key, unsigned int keylen ); 53 55 54 56 /** … … 62 64 * \return 0 if successful 63 65 */ 64 int arc4_crypt( arc4_context *ctx, int length, const unsigned char *input,66 int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input, 65 67 unsigned char *output ); 66 68 -
trunk/include/polarssl/base64.h
r913 r1014 28 28 #define POLARSSL_BASE64_H 29 29 30 #include <string.h> 31 30 32 #define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL 0x0010 31 33 #define POLARSSL_ERR_BASE64_INVALID_CHARACTER 0x0012 … … 50 52 * required buffer size in *dlen 51 53 */ 52 int base64_encode( unsigned char *dst, int *dlen,53 const unsigned char *src, intslen );54 int base64_encode( unsigned char *dst, size_t *dlen, 55 const unsigned char *src, size_t slen ); 54 56 55 57 /** … … 69 71 * required buffer size in *dlen 70 72 */ 71 int base64_decode( unsigned char *dst, int *dlen,72 const unsigned char *src, intslen );73 int base64_decode( unsigned char *dst, size_t *dlen, 74 const unsigned char *src, size_t slen ); 73 75 74 76 /** -
trunk/include/polarssl/bignum.h
r997 r1014 29 29 30 30 #include <stdio.h> 31 #include <string.h> 31 32 32 33 #define POLARSSL_ERR_MPI_FILE_IO_ERROR 0x0002 … … 44 45 */ 45 46 #if defined(POLARSSL_HAVE_INT8) 47 typedef signed char t_s_int; 46 48 typedef unsigned char t_int; 47 49 typedef unsigned short t_dbl; 48 50 #else 49 51 #if defined(POLARSSL_HAVE_INT16) 52 typedef signed short t_s_int; 50 53 typedef unsigned short t_int; 51 54 typedef unsigned long t_dbl; 52 55 #else 56 typedef signed long t_s_int; 53 57 typedef unsigned long t_int; 54 58 #if defined(_MSC_VER) && defined(_M_IX86) … … 74 78 { 75 79 int s; /*!< integer sign */ 76 int n;/*!< total # of limbs */80 size_t n; /*!< total # of limbs */ 77 81 t_int *p; /*!< pointer to limbs */ 78 82 } … … 102 106 * 1 if memory allocation failed 103 107 */ 104 int mpi_grow( mpi *X, int nblimbs );108 int mpi_grow( mpi *X, size_t nblimbs ); 105 109 106 110 /** … … 132 136 * 1 if memory allocation failed 133 137 */ 134 int mpi_lset( mpi *X, int z );138 int mpi_lset( mpi *X, t_s_int z ); 135 139 136 140 /** … … 139 143 * \param X MPI to use 140 144 */ 141 int mpi_lsb( const mpi *X );145 size_t mpi_lsb( const mpi *X ); 142 146 143 147 /** … … 146 150 * \param X MPI to use 147 151 */ 148 int mpi_msb( const mpi *X );152 size_t mpi_msb( const mpi *X ); 149 153 150 154 /** … … 153 157 * \param X MPI to use 154 158 */ 155 int mpi_size( const mpi *X );159 size_t mpi_size( const mpi *X ); 156 160 157 161 /** … … 181 185 * minimum required buffer size in *slen. 182 186 */ 183 int mpi_write_string( const mpi *X, int radix, char *s, int *slen );187 int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ); 184 188 185 189 /** … … 218 222 * 1 if memory allocation failed 219 223 */ 220 int mpi_read_binary( mpi *X, const unsigned char *buf, int buflen );224 int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen ); 221 225 222 226 /** … … 230 234 * POLARSSL_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough 231 235 */ 232 int mpi_write_binary( const mpi *X, unsigned char *buf, int buflen );236 int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen ); 233 237 234 238 /** … … 241 245 * 1 if memory allocation failed 242 246 */ 243 int mpi_shift_l( mpi *X, int count );247 int mpi_shift_l( mpi *X, size_t count ); 244 248 245 249 /** … … 252 256 * 1 if memory allocation failed 253 257 */ 254 int mpi_shift_r( mpi *X, int count );258 int mpi_shift_r( mpi *X, size_t count ); 255 259 256 260 /** … … 288 292 * 0 if X is equal to z 289 293 */ 290 int mpi_cmp_int( const mpi *X, int z );294 int mpi_cmp_int( const mpi *X, t_s_int z ); 291 295 292 296 /** … … 348 352 * 1 if memory allocation failed 349 353 */ 350 int mpi_add_int( mpi *X, const mpi *A, int b );354 int mpi_add_int( mpi *X, const mpi *A, t_s_int b ); 351 355 352 356 /** … … 360 364 * 1 if memory allocation failed 361 365 */ 362 int mpi_sub_int( mpi *X, const mpi *A, int b );366 int mpi_sub_int( mpi *X, const mpi *A, t_s_int b ); 363 367 364 368 /** … … 386 390 * 1 if memory allocation failed 387 391 */ 388 int mpi_mul_int( mpi *X, const mpi *A, t_ int b );392 int mpi_mul_int( mpi *X, const mpi *A, t_s_int b ); 389 393 390 394 /** … … 418 422 * \note Either Q or R can be NULL. 419 423 */ 420 int mpi_div_int( mpi *Q, mpi *R, const mpi *A, int b );424 int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_s_int b ); 421 425 422 426 /** … … 446 450 * POLARSSL_ERR_MPI_NEGATIVE_VALUE if b < 0 447 451 */ 448 int mpi_mod_int( t_int *r, const mpi *A, int b );452 int mpi_mod_int( t_int *r, const mpi *A, t_s_int b ); 449 453 450 454 /** … … 478 482 * 1 if memory allocation failed 479 483 */ 480 int mpi_fill_random( mpi *X, int size, int (*f_rng)(void *), void *p_rng );484 int mpi_fill_random( mpi *X, size_t size, int (*f_rng)(void *), void *p_rng ); 481 485 482 486 /** … … 532 536 * POLARSSL_ERR_MPI_BAD_INPUT_DATA if nbits is < 3 533 537 */ 534 int mpi_gen_prime( mpi *X, int nbits, int dh_flag,538 int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, 535 539 int (*f_rng)(void *), void *p_rng ); 536 540 -
trunk/include/polarssl/camellia.h
r913 r1014 27 27 #ifndef POLARSSL_CAMELLIA_H 28 28 #define POLARSSL_CAMELLIA_H 29 30 #include <string.h> 29 31 30 32 #ifdef _MSC_VER … … 64 66 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH 65 67 */ 66 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize );68 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, unsigned int keysize ); 67 69 68 70 /** … … 75 77 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH 76 78 */ 77 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize );79 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, unsigned int keysize ); 78 80 79 81 /** … … 108 110 int camellia_crypt_cbc( camellia_context *ctx, 109 111 int mode, 110 int length,112 size_t length, 111 113 unsigned char iv[16], 112 114 const unsigned char *input, … … 128 130 int camellia_crypt_cfb128( camellia_context *ctx, 129 131 int mode, 130 int length,132 size_t length, 131 133 int *iv_off, 132 134 unsigned char iv[16], -
trunk/include/polarssl/cipher.h
r1011 r1014 97 97 98 98 /** Cipher key length, in bits (default length for variable sized ciphers) */ 99 int key_length;99 unsigned int key_length; 100 100 101 101 /** Name of the cipher */ … … 103 103 104 104 /** IV size, in bytes */ 105 int iv_size;105 unsigned int iv_size; 106 106 107 107 /** block size, in bytes */ 108 int block_size;108 unsigned int block_size; 109 109 110 110 /** Encrypt using CBC */ 111 int (*cbc_func)( void *ctx, operation_t mode, int length, unsigned char *iv,111 int (*cbc_func)( void *ctx, operation_t mode, size_t length, unsigned char *iv, 112 112 const unsigned char *input, unsigned char *output ); 113 113 114 114 /** Set key for encryption purposes */ 115 int (*setkey_enc_func)( void *ctx, const unsigned char *key, int key_length);115 int (*setkey_enc_func)( void *ctx, const unsigned char *key, unsigned int key_length); 116 116 117 117 /** Set key for decryption purposes */ 118 int (*setkey_dec_func)( void *ctx, const unsigned char *key, int key_length);118 int (*setkey_dec_func)( void *ctx, const unsigned char *key, unsigned int key_length); 119 119 120 120 /** Allocate a new context */ … … 143 143 144 144 /** Number of bytes that still need processing */ 145 int unprocessed_len;145 size_t unprocessed_len; 146 146 147 147 /** Current IV */ … … 168 168 * with the given cipher name. 169 169 * 170 * \param cipher_name Name of the cipher to search for.170 * \param cipher_name Name of the cipher to search for. 171 171 * 172 172 * \return the cipher information structure associated with the … … 216 216 * initialised. 217 217 */ 218 static inline int cipher_get_block_size( const cipher_context_t *ctx )218 static inline unsigned int cipher_get_block_size( const cipher_context_t *ctx ) 219 219 { 220 220 if( NULL == ctx || NULL == ctx->cipher_info ) … … 333 333 * \returns 0 on success, 1 if parameter verification fails. 334 334 */ 335 int cipher_update( cipher_context_t *ctx, const unsigned char *input, int ilen,336 unsigned char *output, int *olen );335 int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ilen, 336 unsigned char *output, size_t *olen ); 337 337 338 338 /** … … 348 348 * \returns 0 on success, 1 if parameter verification fails. 349 349 */ 350 int cipher_finish( cipher_context_t *ctx, unsigned char *output, int *olen);350 int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen); 351 351 352 352 -
trunk/include/polarssl/debug.h
r913 r1014 73 73 void debug_print_buf( const ssl_context *ssl, int level, 74 74 const char *file, int line, const char *text, 75 unsigned char *buf, int len );75 unsigned char *buf, size_t len ); 76 76 77 77 void debug_print_mpi( const ssl_context *ssl, int level, -
trunk/include/polarssl/des.h
r944 r1014 27 27 #ifndef POLARSSL_DES_H 28 28 #define POLARSSL_DES_H 29 30 #include <string.h> 29 31 30 32 #define DES_ENCRYPT 1 … … 172 174 int des_crypt_cbc( des_context *ctx, 173 175 int mode, 174 int length,176 size_t length, 175 177 unsigned char iv[8], 176 178 const unsigned char *input, … … 204 206 int des3_crypt_cbc( des3_context *ctx, 205 207 int mode, 206 int length,208 size_t length, 207 209 unsigned char iv[8], 208 210 const unsigned char *input, -
trunk/include/polarssl/dhm.h
r944 r1014 45 45 typedef struct 46 46 { 47 int len;/*!< size(P) in chars */47 size_t len; /*!< size(P) in chars */ 48 48 mpi P; /*!< prime modulus */ 49 49 mpi G; /*!< generator */ … … 90 90 */ 91 91 int dhm_make_params( dhm_context *ctx, int x_size, 92 unsigned char *output, int *olen,92 unsigned char *output, size_t *olen, 93 93 int (*f_rng)(void *), void *p_rng ); 94 94 … … 103 103 */ 104 104 int dhm_read_public( dhm_context *ctx, 105 const unsigned char *input, int ilen );105 const unsigned char *input, size_t ilen ); 106 106 107 107 /** … … 118 118 */ 119 119 int dhm_make_public( dhm_context *ctx, int x_size, 120 unsigned char *output, int olen,120 unsigned char *output, size_t olen, 121 121 int (*f_rng)(void *), void *p_rng ); 122 122 … … 131 131 */ 132 132 int dhm_calc_secret( dhm_context *ctx, 133 unsigned char *output, int *olen );133 unsigned char *output, size_t *olen ); 134 134 135 135 /* -
trunk/include/polarssl/md.h
r1008 r1014 30 30 #ifndef POLARSSL_MD_H 31 31 #define POLARSSL_MD_H 32 33 #include <string.h> 32 34 33 35 #ifdef _MSC_VER … … 67 69 68 70 /** Digest update function */ 69 void (*update_func)( void *ctx, const unsigned char *input, int ilen );71 void (*update_func)( void *ctx, const unsigned char *input, size_t ilen ); 70 72 71 73 /** Digest finalisation function */ … … 73 75 74 76 /** Generic digest function */ 75 void (*digest_func)( const unsigned char *input, int ilen,77 void (*digest_func)( const unsigned char *input, size_t ilen, 76 78 unsigned char *output ); 77 79 … … 80 82 81 83 /** HMAC Initialisation function */ 82 void (*hmac_starts_func)( void *ctx, const unsigned char *key, int keylen );84 void (*hmac_starts_func)( void *ctx, const unsigned char *key, size_t keylen ); 83 85 84 86 /** HMAC update function */ 85 void (*hmac_update_func)( void *ctx, const unsigned char *input, int ilen );87 void (*hmac_update_func)( void *ctx, const unsigned char *input, size_t ilen ); 86 88 87 89 /** HMAC finalisation function */ … … 92 94 93 95 /** Generic HMAC function */ 94 void (*hmac_func)( const unsigned char *key, int keylen,95 const unsigned char *input, int ilen,96 void (*hmac_func)( const unsigned char *key, size_t keylen, 97 const unsigned char *input, size_t ilen, 96 98 unsigned char *output ); 97 99 … … 136 138 * given digest name. 137 139 * 138 * \param md_name Name of the digest to search for.140 * \param md_name Name of the digest to search for. 139 141 * 140 142 * \return The message digest information associated with md_name or … … 185 187 * \return size of the message digest output. 186 188 */ 187 static inline unsigned char md_get_size ( const md_info_t *md_info)189 static inline unsigned char md_get_size( const md_info_t *md_info ) 188 190 { 189 191 return md_info->size; … … 197 199 * \return type of the message digest output. 198 200 */ 199 static inline md_type_t md_get_type ( const md_info_t *md_info )201 static inline md_type_t md_get_type( const md_info_t *md_info ) 200 202 { 201 203 return md_info->type; … … 209 211 * \return name of the message digest output. 210 212 */ 211 static inline const char *md_get_name ( const md_info_t *md_info )213 static inline const char *md_get_name( const md_info_t *md_info ) 212 214 { 213 215 return md_info->name; … … 232 234 * \returns 0 on success, 1 if parameter verification fails. 233 235 */ 234 int md_update( md_context_t *ctx, const unsigned char *input, int ilen );236 int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen ); 235 237 236 238 /** … … 254 256 * \returns 0 on success, 1 if parameter verification fails. 255 257 */ 256 int md( const md_info_t *md_info, const unsigned char *input, int ilen,258 int md( const md_info_t *md_info, const unsigned char *input, size_t ilen, 257 259 unsigned char *output ); 258 260 … … 278 280 * \returns 0 on success, 1 if parameter verification fails. 279 281 */ 280 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, int keylen );282 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen ); 281 283 282 284 /** … … 289 291 * \returns 0 on success, 1 if parameter verification fails. 290 292 */ 291 int md_hmac_update( md_context_t *ctx, const unsigned char *input, int ilen );293 int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen ); 292 294 293 295 /** … … 322 324 * \returns 0 on success, 1 if parameter verification fails. 323 325 */ 324 int md_hmac( const md_info_t *md_info, const unsigned char *key, int keylen,325 const unsigned char *input, int ilen,326 int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen, 327 const unsigned char *input, size_t ilen, 326 328 unsigned char *output ); 327 329 -
trunk/include/polarssl/md2.h
r913 r1014 28 28 #define POLARSSL_MD2_H 29 29 30 #include <string.h> 31 30 32 /** 31 33 * \brief MD2 context structure … … 39 41 unsigned char ipad[64]; /*!< HMAC: inner padding */ 40 42 unsigned char opad[64]; /*!< HMAC: outer padding */ 41 int left;/*!< amount of data in buffer */43 size_t left; /*!< amount of data in buffer */ 42 44 } 43 45 md2_context; … … 61 63 * \param ilen length of the input data 62 64 */ 63 void md2_update( md2_context *ctx, const unsigned char *input, int ilen );65 void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen ); 64 66 65 67 /** … … 78 80 * \param output MD2 checksum result 79 81 */ 80 void md2( const unsigned char *input, int ilen, unsigned char output[16] );82 void md2( const unsigned char *input, size_t ilen, unsigned char output[16] ); 81 83 82 84 /** … … 98 100 * \param keylen length of the HMAC key 99 101 */ 100 void md2_hmac_starts( md2_context *ctx, const unsigned char *key, int keylen );102 void md2_hmac_starts( md2_context *ctx, const unsigned char *key, size_t keylen ); 101 103 102 104 /** … … 107 109 * \param ilen length of the input data 108 110 */ 109 void md2_hmac_update( md2_context *ctx, const unsigned char *input, int ilen );111 void md2_hmac_update( md2_context *ctx, const unsigned char *input, size_t ilen ); 110 112 111 113 /** … … 133 135 * \param output HMAC-MD2 result 134 136 */ 135 void md2_hmac( const unsigned char *key, int keylen,136 const unsigned char *input, int ilen,137 void md2_hmac( const unsigned char *key, size_t keylen, 138 const unsigned char *input, size_t ilen, 137 139 unsigned char output[16] ); 138 140 -
trunk/include/polarssl/md4.h
r913 r1014 27 27 #ifndef POLARSSL_MD4_H 28 28 #define POLARSSL_MD4_H 29 30 #include <string.h> 29 31 30 32 /** … … 60 62 * \param ilen length of the input data 61 63 */ 62 void md4_update( md4_context *ctx, const unsigned char *input, int ilen );64 void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen ); 63 65 64 66 /** … … 77 79 * \param output MD4 checksum result 78 80 */ 79 void md4( const unsigned char *input, int ilen, unsigned char output[16] );81 void md4( const unsigned char *input, size_t ilen, unsigned char output[16] ); 80 82 81 83 /** … … 97 99 * \param keylen length of the HMAC key 98 100 */ 99 void md4_hmac_starts( md4_context *ctx, const unsigned char *key, int keylen );101 void md4_hmac_starts( md4_context *ctx, const unsigned char *key, size_t keylen ); 100 102 101 103 /** … … 106 108 * \param ilen length of the input data 107 109 */ 108 void md4_hmac_update( md4_context *ctx, const unsigned char *input, int ilen );110 void md4_hmac_update( md4_context *ctx, const unsigned char *input, size_t ilen ); 109 111 110 112 /** … … 132 134 * \param output HMAC-MD4 result 133 135 */ 134 void md4_hmac( const unsigned char *key, int keylen,135 const unsigned char *input, int ilen,136 void md4_hmac( const unsigned char *key, size_t keylen, 137 const unsigned char *input, size_t ilen, 136 138 unsigned char output[16] ); 137 139 -
trunk/include/polarssl/md5.h
r913 r1014 27 27 #ifndef POLARSSL_MD5_H 28 28 #define POLARSSL_MD5_H 29 30 #include <string.h> 29 31 30 32 /** … … 60 62 * \param ilen length of the input data 61 63 */ 62 void md5_update( md5_context *ctx, const unsigned char *input, int ilen );64 void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen ); 63 65 64 66 /** … … 77 79 * \param output MD5 checksum result 78 80 */ 79 void md5( const unsigned char *input, int ilen, unsigned char output[16] );81 void md5( const unsigned char *input, size_t ilen, unsigned char output[16] ); 80 82 81 83 /** … … 98 100 */ 99 101 void md5_hmac_starts( md5_context *ctx, 100 const unsigned char *key, int keylen );102 const unsigned char *key, size_t keylen ); 101 103 102 104 /** … … 108 110 */ 109 111 void md5_hmac_update( md5_context *ctx, 110 const unsigned char *input, int ilen );112 const unsigned char *input, size_t ilen ); 111 113 112 114 /** … … 134 136 * \param output HMAC-MD5 result 135 137 */ 136 void md5_hmac( const unsigned char *key, int keylen,137 const unsigned char *input, int ilen,138 void md5_hmac( const unsigned char *key, size_t keylen, 139 const unsigned char *input, size_t ilen, 138 140 unsigned char output[16] ); 139 141 -
trunk/include/polarssl/net.h
r913 r1014 27 27 #ifndef POLARSSL_NET_H 28 28 #define POLARSSL_NET_H 29 30 #include <string.h> 29 31 30 32 #define POLARSSL_ERR_NET_UNKNOWN_HOST -0x0F00 … … 125 127 * indicates read() is blocking. 126 128 */ 127 int net_recv( void *ctx, unsigned char *buf, int len );129 int net_recv( void *ctx, unsigned char *buf, size_t len ); 128 130 129 131 /** … … 139 141 * indicates write() is blocking. 140 142 */ 141 int net_send( void *ctx, unsigned char *buf, int len );143 int net_send( void *ctx, unsigned char *buf, size_t len ); 142 144 143 145 /** -
trunk/include/polarssl/padlock.h
r913 r1014 87 87 int padlock_xcryptcbc( aes_context *ctx, 88 88 int mode, 89 int length,89 size_t length, 90 90 unsigned char iv[16], 91 91 const unsigned char *input, -
trunk/include/polarssl/pem.h
r956 r1014 28 28 #define POLARSSL_PEM_H 29 29 30 #include <string.h> 31 30 32 /** 31 33 * \name PEM Error codes … … 50 52 { 51 53 unsigned char *buf; /*!< buffer for decoded data */ 52 int buflen;/*!< length of the buffer */54 size_t buflen; /*!< length of the buffer */ 53 55 unsigned char *info; /*!< buffer for extra header information */ 54 56 } … … 83 85 const unsigned char *data, 84 86 const unsigned char *pwd, 85 int pwdlen, int *use_len );87 size_t pwdlen, size_t *use_len ); 86 88 87 89 /** -
trunk/include/polarssl/pkcs11.h
r932 r1014 95 95 */ 96 96 int pkcs11_decrypt( pkcs11_context *ctx, 97 int mode, int *olen,97 int mode, size_t *olen, 98 98 const unsigned char *input, 99 99 unsigned char *output, … … 119 119 int mode, 120 120 int hash_id, 121 int hashlen,121 unsigned int hashlen, 122 122 const unsigned char *hash, 123 123 unsigned char *sig ); -
trunk/include/polarssl/rsa.h
r979 r1014 50 50 #define SIG_RSA_MD4 3 51 51 #define SIG_RSA_MD5 4 52 #define SIG_RSA_SHA1 553 #define SIG_RSA_SHA224 1454 #define SIG_RSA_SHA256 1155 #define SIG_RSA_SHA3841256 #define SIG_RSA_SHA512 1352 #define SIG_RSA_SHA1 5 53 #define SIG_RSA_SHA224 14 54 #define SIG_RSA_SHA256 11 55 #define SIG_RSA_SHA384 12 56 #define SIG_RSA_SHA512 13 57 57 58 58 #define RSA_PUBLIC 0 … … 65 65 #define RSA_CRYPT 2 66 66 67 #define ASN1_STR_CONSTRUCTED_SEQUENCE "\x30"68 #define ASN1_STR_NULL "\x05"69 #define ASN1_STR_OID "\x06"70 #define ASN1_STR_OCTET_STRING "\x04"71 72 #define OID_DIGEST_ALG_MDX "\x2A\x86\x48\x86\xF7\x0D\x02\x00"73 #define OID_HASH_ALG_SHA1 "\x2b\x0e\x03\x02\x1a"74 #define OID_HASH_ALG_SHA2X "\x60\x86\x48\x01\x65\x03\x04\x02\x00"75 76 #define OID_ISO_MEMBER_BODIES "\x2a"77 #define OID_ISO_IDENTIFIED_ORG "\x2b"67 #define ASN1_STR_CONSTRUCTED_SEQUENCE "\x30" 68 #define ASN1_STR_NULL "\x05" 69 #define ASN1_STR_OID "\x06" 70 #define ASN1_STR_OCTET_STRING "\x04" 71 72 #define OID_DIGEST_ALG_MDX "\x2A\x86\x48\x86\xF7\x0D\x02\x00" 73 #define OID_HASH_ALG_SHA1 "\x2b\x0e\x03\x02\x1a" 74 #define OID_HASH_ALG_SHA2X "\x60\x86\x48\x01\x65\x03\x04\x02\x00" 75 76 #define OID_ISO_MEMBER_BODIES "\x2a" 77 #define OID_ISO_IDENTIFIED_ORG "\x2b" 78 78 79 79 /* 80 80 * ISO Member bodies OID parts 81 81 */ 82 #define OID_COUNTRY_US "\x86\x48"83 #define OID_RSA_DATA_SECURITY "\x86\xf7\x0d"82 #define OID_COUNTRY_US "\x86\x48" 83 #define OID_RSA_DATA_SECURITY "\x86\xf7\x0d" 84 84 85 85 /* 86 86 * ISO Identified organization OID parts 87 87 */ 88 #define OID_OIW_SECSIG_SHA1 "\x0e\x03\x02\x1a"88 #define OID_OIW_SECSIG_SHA1 "\x0e\x03\x02\x1a" 89 89 90 90 /* … … 97 97 * Digest ::= OCTET STRING 98 98 */ 99 #define ASN1_HASH_MDX \100 ( \101 ASN1_STR_CONSTRUCTED_SEQUENCE "\x20" \102 ASN1_STR_CONSTRUCTED_SEQUENCE "\x0C" \103 ASN1_STR_OID "\x08" \104 OID_DIGEST_ALG_MDX\105 ASN1_STR_NULL "\x00"\106 ASN1_STR_OCTET_STRING "\x10" \99 #define ASN1_HASH_MDX \ 100 ( \ 101 ASN1_STR_CONSTRUCTED_SEQUENCE "\x20" \ 102 ASN1_STR_CONSTRUCTED_SEQUENCE "\x0C" \ 103 ASN1_STR_OID "\x08" \ 104 OID_DIGEST_ALG_MDX \ 105 ASN1_STR_NULL "\x00" \ 106 ASN1_STR_OCTET_STRING "\x10" \ 107 107 ) 108 108 109 #define ASN1_HASH_SHA1 \110 ASN1_STR_CONSTRUCTED_SEQUENCE "\x21" \111 ASN1_STR_CONSTRUCTED_SEQUENCE "\x09" \112 ASN1_STR_OID "\x05" \113 OID_HASH_ALG_SHA1\114 ASN1_STR_NULL "\x00" \109 #define ASN1_HASH_SHA1 \ 110 ASN1_STR_CONSTRUCTED_SEQUENCE "\x21" \ 111 ASN1_STR_CONSTRUCTED_SEQUENCE "\x09" \ 112 ASN1_STR_OID "\x05" \ 113 OID_HASH_ALG_SHA1 \ 114 ASN1_STR_NULL "\x00" \ 115 115 ASN1_STR_OCTET_STRING "\x14" 116 116 117 #define ASN1_HASH_SHA2X \118 ASN1_STR_CONSTRUCTED_SEQUENCE "\x11" \119 ASN1_STR_CONSTRUCTED_SEQUENCE "\x0d" \120 ASN1_STR_OID "\x09" \121 OID_HASH_ALG_SHA2X\122 ASN1_STR_NULL "\x00" \117 #define ASN1_HASH_SHA2X \ 118 ASN1_STR_CONSTRUCTED_SEQUENCE "\x11" \ 119 ASN1_STR_CONSTRUCTED_SEQUENCE "\x0d" \ 120 ASN1_STR_OID "\x09" \ 121 OID_HASH_ALG_SHA2X \ 122 ASN1_STR_NULL "\x00" \ 123 123 ASN1_STR_OCTET_STRING "\x00" 124 124 … … 129 129 { 130 130 int ver; /*!< always 0 */ 131 int len;/*!< size(N) in chars */131 size_t len; /*!< size(N) in chars */ 132 132 133 133 mpi N; /*!< public modulus */ … … 189 189 int (*f_rng)(void *), 190 190 void *p_rng, 191 int nbits, int exponent );191 unsigned int nbits, int exponent ); 192 192 193 193 /** … … 264 264 int (*f_rng)(void *), 265 265 void *p_rng, 266 int mode, intilen,266 int mode, size_t ilen, 267 267 const unsigned char *input, 268 268 unsigned char *output ); … … 276 276 * \param output buffer that will hold the plaintext 277 277 * \param olen will contain the plaintext length 278 * \param output_max_len maximum length of the output buffer278 * \param output_max_len maximum length of the output buffer 279 279 * 280 280 * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code … … 285 285 */ 286 286 int rsa_pkcs1_decrypt( rsa_context *ctx, 287 int mode, int *olen,287 int mode, size_t *olen, 288 288 const unsigned char *input, 289 289 unsigned char *output, 290 int output_max_len );290 size_t output_max_len ); 291 291 292 292 /** … … 319 319 int mode, 320 320 int hash_id, 321 int hashlen,321 unsigned int hashlen, 322 322 const unsigned char *hash, 323 323 unsigned char *sig ); … … 348 348 int mode, 349 349 int hash_id, 350 int hashlen,350 unsigned int hashlen, 351 351 const unsigned char *hash, 352 352 unsigned char *sig ); -
trunk/include/polarssl/sha1.h
r913 r1014 27 27 #ifndef POLARSSL_SHA1_H 28 28 #define POLARSSL_SHA1_H 29 30 #include <string.h> 29 31 30 32 /** … … 60 62 * \param ilen length of the input data 61 63 */ 62 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );64 void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen ); 63 65 64 66 /** … … 77 79 * \param output SHA-1 checksum result 78 80 */ 79 void sha1( const unsigned char *input, int ilen, unsigned char output[20] );81 void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ); 80 82 81 83 /** … … 97 99 * \param keylen length of the HMAC key 98 100 */ 99 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );101 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen ); 100 102 101 103 /** … … 106 108 * \param ilen length of the input data 107 109 */ 108 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );110 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen ); 109 111 110 112 /** … … 132 134 * \param output HMAC-SHA-1 result 133 135 */ 134 void sha1_hmac( const unsigned char *key, int keylen,135 const unsigned char *input, int ilen,136 void sha1_hmac( const unsigned char *key, size_t keylen, 137 const unsigned char *input, size_t ilen, 136 138 unsigned char output[20] ); 137 139 -
trunk/include/polarssl/sha2.h
r944 r1014 27 27 #ifndef POLARSSL_SHA2_H 28 28 #define POLARSSL_SHA2_H 29 30 #include <string.h> 29 31 30 32 /** … … 62 64 * \param ilen length of the input data 63 65 */ 64 void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen );66 void sha2_update( sha2_context *ctx, const unsigned char *input, size_t ilen ); 65 67 66 68 /** … … 80 82 * \param is224 0 = use SHA256, 1 = use SHA224 81 83 */ 82 void sha2( const unsigned char *input, int ilen,84 void sha2( const unsigned char *input, size_t ilen, 83 85 unsigned char output[32], int is224 ); 84 86 … … 103 105 * \param is224 0 = use SHA256, 1 = use SHA224 104 106 */ 105 void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, int keylen,107 void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, size_t keylen, 106 108 int is224 ); 107 109 … … 113 115 * \param ilen length of the input data 114 116 */ 115 void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, int ilen );117 void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, size_t ilen ); 116 118 117 119 /** … … 140 142 * \param is224 0 = use SHA256, 1 = use SHA224 141 143 */ 142 void sha2_hmac( const unsigned char *key, int keylen,143 const unsigned char *input, int ilen,144 void sha2_hmac( const unsigned char *key, size_t keylen, 145 const unsigned char *input, size_t ilen, 144 146 unsigned char output[32], int is224 ); 145 147 -
trunk/include/polarssl/sha4.h
r944 r1014 27 27 #ifndef POLARSSL_SHA4_H 28 28 #define POLARSSL_SHA4_H 29 30 #include <string.h> 29 31 30 32 #if defined(_MSC_VER) || defined(__WATCOMC__) … … 70 72 * \param ilen length of the input data 71 73 */ 72 void sha4_update( sha4_context *ctx, const unsigned char *input, int ilen );74 void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen ); 73 75 74 76 /** … … 88 90 * \param is384 0 = use SHA512, 1 = use SHA384 89 91 */ 90 void sha4( const unsigned char *input, int ilen,92 void sha4( const unsigned char *input, size_t ilen, 91 93 unsigned char output[64], int is384 ); 92 94 … … 111 113 * \param keylen length of the HMAC key 112 114 */ 113 void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, int keylen,115 void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, size_t keylen, 114 116 int is384 ); 115 117 … … 121 123 * \param ilen length of the input data 122 124 */ 123 void sha4_hmac_update( sha4_context *ctx, const unsigned char *input, int ilen );125 void sha4_hmac_update( sha4_context *ctx, const unsigned char *input, size_t ilen ); 124 126 125 127 /** … … 148 150 * \param is384 0 = use SHA512, 1 = use SHA384 149 151 */ 150 void sha4_hmac( const unsigned char *key, int keylen,151 const unsigned char *input, int ilen,152 void sha4_hmac( const unsigned char *key, size_t keylen, 153 const unsigned char *input, size_t ilen, 152 154 unsigned char output[64], int is384 ); 153 155 -
trunk/include/polarssl/ssl.h
r1008 r1014 205 205 time_t start; /*!< starting time */ 206 206 int ciphersuite; /*!< chosen ciphersuite */ 207 int length;/*!< session id length */207 size_t length; /*!< session id length */ 208 208 unsigned char id[32]; /*!< session identifier */ 209 209 unsigned char master[48]; /*!< the master secret */ … … 229 229 int (*f_rng)(void *); 230 230 void (*f_dbg)(void *, int, const char *); 231 int (*f_recv)(void *, unsigned char *, int);232 int (*f_send)(void *, unsigned char *, int);231 int (*f_recv)(void *, unsigned char *, size_t); 232 int (*f_send)(void *, unsigned char *, size_t); 233 233 int (*f_vrfy)(void *, x509_cert *, int, int); 234 234 … … 257 257 258 258 int in_msgtype; /*!< record header: message type */ 259 int in_msglen;/*!< record header: message length */260 int in_left;/*!< amount of data read so far */261 262 int in_hslen;/*!< current handshake message length */259 size_t in_msglen; /*!< record header: message length */ 260 size_t in_left; /*!< amount of data read so far */ 261 262 size_t in_hslen; /*!< current handshake message length */ 263 263 int nb_zero; /*!< # of 0-length encrypted messages */ 264 264 … … 271 271 272 272 int out_msgtype; /*!< record header: message type */ 273 int out_msglen;/*!< record header: message length */274 int out_left;/*!< amount of data not yet written */273 size_t out_msglen; /*!< record header: message length */ 274 size_t out_left; /*!< amount of data not yet written */ 275 275 276 276 /* … … 301 301 int do_crypt; /*!< en(de)cryption flag */ 302 302 int *ciphersuites; /*!< allowed ciphersuites */ 303 int pmslen;/*!< premaster length */304 int keylen;/*!< symmetric key length */305 int minlen;/*!< min. ciphertext length */306 int ivlen;/*!< IV length */307 int maclen;/*!< MAC length */303 size_t pmslen; /*!< premaster length */ 304 unsigned int keylen; /*!< symmetric key length */ 305 size_t minlen; /*!< min. ciphertext length */ 306 size_t ivlen; /*!< IV length */ 307 size_t maclen; /*!< MAC length */ 308 308 309 309 unsigned char randbytes[64]; /*!< random bytes */ … … 323 323 */ 324 324 unsigned char *hostname; 325 unsigned longhostname_len;325 size_t hostname_len; 326 326 }; 327 327 … … 448 448 */ 449 449 void ssl_set_bio( ssl_context *ssl, 450 int (*f_recv)(void *, unsigned char *, int), void *p_recv,451 int (*f_send)(void *, unsigned char *, int), void *p_send );450 int (*f_recv)(void *, unsigned char *, size_t), void *p_recv, 451 int (*f_send)(void *, unsigned char *, size_t), void *p_send ); 452 452 453 453 /** … … 557 557 * \return how many bytes are available in the read buffer 558 558 */ 559 int ssl_get_bytes_avail( const ssl_context *ssl );559 size_t ssl_get_bytes_avail( const ssl_context *ssl ); 560 560 561 561 /** … … 610 610 * or a negative error code. 611 611 */ 612 int ssl_read( ssl_context *ssl, unsigned char *buf, int len );612 int ssl_read( ssl_context *ssl, unsigned char *buf, size_t len ); 613 613 614 614 /** … … 626 626 * until it returns a positive value. 627 627 */ 628 int ssl_write( ssl_context *ssl, const unsigned char *buf, int len );628 int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len ); 629 629 630 630 /** … … 652 652 653 653 int ssl_read_record( ssl_context *ssl ); 654 int ssl_fetch_input( ssl_context *ssl, int nb_want );654 int ssl_fetch_input( ssl_context *ssl, size_t nb_want ); 655 655 656 656 int ssl_write_record( ssl_context *ssl ); -
trunk/include/polarssl/x509.h
r992 r1014 285 285 { 286 286 int tag; /**< ASN1 type, e.g. ASN1_UTF8_STRING. */ 287 int len;/**< ASN1 length, e.g. in octets. */287 size_t len; /**< ASN1 length, e.g. in octets. */ 288 288 unsigned char *p; /**< ASN1 data, e.g. in ASCII. */ 289 289 } … … 295 295 typedef struct _x509_bitstring 296 296 { 297 int len;/**< ASN1 length, e.g. in octets. */297 size_t len; /**< ASN1 length, e.g. in octets. */ 298 298 unsigned char unused_bits; /**< Number of unused bits at the end of the string */ 299 299 unsigned char *p; /**< Raw ASN1 data for the bit string */ … … 484 484 * \return 0 if successful, or a specific X509 or PEM error code 485 485 */ 486 int x509parse_crt( x509_cert *chain, const unsigned char *buf, int buflen );486 int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen ); 487 487 488 488 /** \ingroup x509_module */ … … 509 509 * \return 0 if successful, or a specific X509 or PEM error code 510 510 */ 511 int x509parse_crl( x509_crl *chain, const unsigned char *buf, int buflen );511 int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen ); 512 512 513 513 /** \ingroup x509_module */ … … 536 536 */ 537 537 int x509parse_key( rsa_context *rsa, 538 const unsigned char *key, int keylen,539 const unsigned char *pwd, int pwdlen );538 const unsigned char *key, size_t keylen, 539 const unsigned char *pwd, size_t pwdlen ); 540 540 541 541 /** \ingroup x509_module */ … … 563 563 */ 564 564 int x509parse_public_key( rsa_context *rsa, 565 const unsigned char *key, int keylen );565 const unsigned char *key, size_t keylen ); 566 566 567 567 /** \ingroup x509_module */ … … 586 586 * \return 0 if successful, or a specific X509 or PEM error code 587 587 */ 588 int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, int dhminlen );588 int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen ); 589 589 590 590 /** \ingroup x509_module */ -
trunk/include/polarssl/xtea.h
r1011 r1014 27 27 #ifndef POLARSSL_XTEA_H 28 28 #define POLARSSL_XTEA_H 29 30 #include <string.h> 29 31 30 32 #ifdef _MSC_VER … … 72 74 */ 73 75 int xtea_crypt_ecb( xtea_context *ctx, 74 int mode,75 unsigned char input[8],76 unsigned char output[8] );76 int mode, 77 unsigned char input[8], 78 unsigned char output[8] ); 77 79 78 80 /** … … 91 93 int xtea_crypt_cbc( xtea_context *ctx, 92 94 int mode, 93 int length,95 size_t length, 94 96 unsigned char iv[8], 95 97 unsigned char *input, -
trunk/library/aes.c
r1012 r1014 36 36 #include "polarssl/aes.h" 37 37 #include "polarssl/padlock.h" 38 39 #include <string.h>40 38 41 39 /* … … 442 440 * AES key schedule (encryption) 443 441 */ 444 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize )445 { 446 int i;442 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize ) 443 { 444 unsigned int i; 447 445 unsigned long *RK; 448 446 … … 547 545 * AES key schedule (decryption) 548 546 */ 549 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize )547 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int keysize ) 550 548 { 551 549 int i, j; … … 759 757 int aes_crypt_cbc( aes_context *ctx, 760 758 int mode, 761 int length,759 size_t length, 762 760 unsigned char iv[16], 763 761 const unsigned char *input, … … 824 822 int aes_crypt_cfb128( aes_context *ctx, 825 823 int mode, 826 int length,824 size_t length, 827 825 int *iv_off, 828 826 unsigned char iv[16], -
trunk/library/arc4.c
r897 r1014 38 38 * ARC4 key schedule 39 39 */ 40 void arc4_setup( arc4_context *ctx, const unsigned char *key, int keylen )40 void arc4_setup( arc4_context *ctx, const unsigned char *key, unsigned int keylen ) 41 41 { 42 int i, j, k, a; 42 int i, j, a; 43 unsigned int k; 43 44 unsigned char *m; 44 45 … … 66 67 * ARC4 cipher function 67 68 */ 68 int arc4_crypt( arc4_context *ctx, int length, const unsigned char *input,69 int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input, 69 70 unsigned char *output ) 70 71 { 71 int i, x, y, a, b; 72 int x, y, a, b; 73 size_t i; 72 74 unsigned char *m; 73 75 -
trunk/library/base64.c
r897 r1014 61 61 * Encode a buffer into base64 format 62 62 */ 63 int base64_encode( unsigned char *dst, int *dlen,64 const unsigned char *src, intslen )65 { 66 int i, n;63 int base64_encode( unsigned char *dst, size_t *dlen, 64 const unsigned char *src, size_t slen ) 65 { 66 size_t i, n; 67 67 int C1, C2, C3; 68 68 unsigned char *p; … … 124 124 * Decode a base64-formatted buffer 125 125 */ 126 int base64_decode( unsigned char *dst, int *dlen,127 const unsigned char *src, intslen )128 { 129 int i, j, n;126 int base64_decode( unsigned char *dst, size_t *dlen, 127 const unsigned char *src, size_t slen ) 128 { 129 size_t i, j, n; 130 130 unsigned long x; 131 131 unsigned char *p; … … 211 211 int base64_self_test( int verbose ) 212 212 { 213 int len;213 size_t len; 214 214 unsigned char *src, buffer[128]; 215 215 -
trunk/library/bignum.c
r997 r1014 38 38 #include "polarssl/bn_mul.h" 39 39 40 #include <string.h>41 40 #include <stdlib.h> 42 41 #include <stdarg.h> … … 103 102 * Enlarge to the specified number of limbs 104 103 */ 105 int mpi_grow( mpi *X, int nblimbs )104 int mpi_grow( mpi *X, size_t nblimbs ) 106 105 { 107 106 t_int *p; … … 133 132 int mpi_copy( mpi *X, const mpi *Y ) 134 133 { 135 int ret, i; 134 int ret; 135 size_t i; 136 136 137 137 if( X == Y ) … … 170 170 * Set value from integer 171 171 */ 172 int mpi_lset( mpi *X, int z )172 int mpi_lset( mpi *X, t_s_int z ) 173 173 { 174 174 int ret; … … 188 188 * Return the number of least significant bits 189 189 */ 190 int mpi_lsb( const mpi *X )191 { 192 int i, j, count = 0;190 size_t mpi_lsb( const mpi *X ) 191 { 192 size_t i, j, count = 0; 193 193 194 194 for( i = 0; i < X->n; i++ ) … … 203 203 * Return the number of most significant bits 204 204 */ 205 int mpi_msb( const mpi *X )206 { 207 int i, j;205 size_t mpi_msb( const mpi *X ) 206 { 207 size_t i, j; 208 208 209 209 for( i = X->n - 1; i > 0; i-- ) … … 211 211 break; 212 212 213 for( j = biL - 1; j >=0; j-- )214 if( ( ( X->p[i] >> j) & 1 ) != 0 )213 for( j = biL; j > 0; j-- ) 214 if( ( ( X->p[i] >> ( j - 1 ) ) & 1 ) != 0 ) 215 215 break; 216 216 217 return( ( i * biL ) + j + 1);217 return( ( i * biL ) + j ); 218 218 } 219 219 … … 221 221 * Return the total size in bytes 222 222 */ 223 int mpi_size( const mpi *X )223 size_t mpi_size( const mpi *X ) 224 224 { 225 225 return( ( mpi_msb( X ) + 7 ) >> 3 ); … … 248 248 int mpi_read_string( mpi *X, int radix, const char *s ) 249 249 { 250 int ret, i, j, n, slen; 250 int ret; 251 size_t i, j, slen, n; 251 252 t_int d; 252 253 mpi T; … … 266 267 MPI_CHK( mpi_lset( X, 0 ) ); 267 268 268 for( i = slen - 1, j = 0; i >=0; i--, j++ )269 { 270 if( i == 0 && s[i] == '-' )269 for( i = slen, j = 0; i > 0; i--, j++ ) 270 { 271 if( i == 1 && s[i - 1] == '-' ) 271 272 { 272 273 X->s = -1; … … 274 275 } 275 276 276 MPI_CHK( mpi_get_digit( &d, radix, s[i ] ) );277 MPI_CHK( mpi_get_digit( &d, radix, s[i - 1] ) ); 277 278 X->p[j / (2 * ciL)] |= d << ( (j % (2 * ciL)) << 2 ); 278 279 } … … 341 342 * Export into an ASCII string 342 343 */ 343 int mpi_write_string( const mpi *X, int radix, char *s, int *slen ) 344 { 345 int ret = 0, n; 344 int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ) 345 { 346 int ret = 0; 347 size_t n; 346 348 char *p; 347 349 mpi T; … … 369 371 if( radix == 16 ) 370 372 { 371 int c, i, j, k; 372 373 for( i = X->n - 1, k = 0; i >= 0; i-- ) 374 { 375 for( j = ciL - 1; j >= 0; j-- ) 373 int c; 374 size_t i, j, k; 375 376 for( i = X->n, k = 0; i > 0; i-- ) 377 { 378 for( j = ciL; j > 0; j-- ) 376 379 { 377 c = ( X->p[i ] >> (j<< 3) ) & 0xFF;378 379 if( c == 0 && k == 0 && ( i + j) != 0 )380 c = ( X->p[i - 1] >> ( ( j - 1 ) << 3) ) & 0xFF; 381 382 if( c == 0 && k == 0 && ( i + j + 3 ) != 0 ) 380 383 continue; 381 384 … … 411 414 { 412 415 t_int d; 413 int slen;416 size_t slen; 414 417 char *p; 415 418 char s[1024]; … … 436 439 int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout ) 437 440 { 438 int n, ret; 439 size_t slen; 440 size_t plen; 441 int ret; 442 size_t n, slen, plen; 441 443 char s[2048]; 442 444 … … 445 447 n -= 2; 446 448 447 MPI_CHK( mpi_write_string( X, radix, s, ( int *) &n ) );449 MPI_CHK( mpi_write_string( X, radix, s, (size_t *) &n ) ); 448 450 449 451 if( p == NULL ) p = ""; … … 471 473 * Import X from unsigned binary data, big endian 472 474 */ 473 int mpi_read_binary( mpi *X, const unsigned char *buf, int buflen ) 474 { 475 int ret, i, j, n; 475 int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen ) 476 { 477 int ret; 478 size_t i, j, n; 476 479 477 480 for( n = 0; n < buflen; n++ ) … … 482 485 MPI_CHK( mpi_lset( X, 0 ) ); 483 486 484 for( i = buflen - 1, j = 0; i >=n; i--, j++ )485 X->p[j / ciL] |= ((t_int) buf[i ]) << ((j % ciL) << 3);487 for( i = buflen, j = 0; i > n; i--, j++ ) 488 X->p[j / ciL] |= ((t_int) buf[i - 1]) << ((j % ciL) << 3); 486 489 487 490 cleanup: … … 493 496 * Export X into unsigned binary data, big endian 494 497 */ 495 int mpi_write_binary( const mpi *X, unsigned char *buf, int buflen )496 { 497 int i, j, n;498 int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen ) 499 { 500 size_t i, j, n; 498 501 499 502 n = mpi_size( X ); … … 513 516 * Left-shift: X <<= count 514 517 */ 515 int mpi_shift_l( mpi *X, int count ) 516 { 517 int ret, i, v0, t1; 518 int mpi_shift_l( mpi *X, size_t count ) 519 { 520 int ret; 521 size_t i, v0, t1; 518 522 t_int r0 = 0, r1; 519 523 … … 533 537 if( v0 > 0 ) 534 538 { 535 for( i = X->n - 1; i >=v0; i-- )536 X->p[i ] = X->p[i - v0];537 538 for( ; i > =0; i-- )539 X->p[i ] = 0;539 for( i = X->n; i > v0; i-- ) 540 X->p[i - 1] = X->p[i - v0 - 1]; 541 542 for( ; i > 0; i-- ) 543 X->p[i - 1] = 0; 540 544 } 541 545 … … 562 566 * Right-shift: X >>= count 563 567 */ 564 int mpi_shift_r( mpi *X, int count )565 { 566 int i, v0, v1;568 int mpi_shift_r( mpi *X, size_t count ) 569 { 570 size_t i, v0, v1; 567 571 t_int r0 = 0, r1; 568 572 … … 587 591 if( v1 > 0 ) 588 592 { 589 for( i = X->n - 1; i >=0; i-- )590 { 591 r1 = X->p[i ] << (biL - v1);592 X->p[i ] >>= v1;593 X->p[i ] |= r0;593 for( i = X->n; i > 0; i-- ) 594 { 595 r1 = X->p[i - 1] << (biL - v1); 596 X->p[i - 1] >>= v1; 597 X->p[i - 1] |= r0; 594 598 r0 = r1; 595 599 } … … 604 608 int mpi_cmp_abs( const mpi *X, const mpi *Y ) 605 609 { 606 int i, j;607 608 for( i = X->n - 1; i >=0; i-- )609 if( X->p[i ] != 0 )610 size_t i, j; 611 612 for( i = X->n; i > 0; i-- ) 613 if( X->p[i - 1] != 0 ) 610 614 break; 611 615 612 for( j = Y->n - 1; j >=0; j-- )613 if( Y->p[j ] != 0 )616 for( j = Y->n; j > 0; j-- ) 617 if( Y->p[j - 1] != 0 ) 614 618 break; 615 619 616 if( i < 0 && j <0 )620 if( i == 0 && j == 0 ) 617 621 return( 0 ); 618 622 … … 620 624 if( j > i ) return( -1 ); 621 625 622 for( ; i > =0; i-- )623 { 624 if( X->p[i ] > Y->p[i] ) return( 1 );625 if( X->p[i ] < Y->p[i] ) return( -1 );626 for( ; i > 0; i-- ) 627 { 628 if( X->p[i - 1] > Y->p[i - 1] ) return( 1 ); 629 if( X->p[i - 1] < Y->p[i - 1] ) return( -1 ); 626 630 } 627 631 … … 634 638 int mpi_cmp_mpi( const mpi *X, const mpi *Y ) 635 639 { 636 int i, j;637 638 for( i = X->n - 1; i >=0; i-- )639 if( X->p[i ] != 0 )640 size_t i, j; 641 642 for( i = X->n; i > 0; i-- ) 643 if( X->p[i - 1] != 0 ) 640 644 break; 641 645 642 for( j = Y->n - 1; j >=0; j-- )643 if( Y->p[j ] != 0 )646 for( j = Y->n; j > 0; j-- ) 647 if( Y->p[j - 1] != 0 ) 644 648 break; 645 649 646 if( i < 0 && j <0 )650 if( i == 0 && j == 0 ) 647 651 return( 0 ); 648 652 … … 653 657 if( Y->s > 0 && X->s < 0 ) return( -1 ); 654 658 655 for( ; i > =0; i-- )656 { 657 if( X->p[i ] > Y->p[i] ) return( X->s );658 if( X->p[i ] < Y->p[i] ) return( -X->s );659 for( ; i > 0; i-- ) 660 { 661 if( X->p[i - 1] > Y->p[i - 1] ) return( X->s ); 662 if( X->p[i - 1] < Y->p[i - 1] ) return( -X->s ); 659 663 } 660 664 … … 665 669 * Compare signed values 666 670 */ 667 int mpi_cmp_int( const mpi *X, int z )671 int mpi_cmp_int( const mpi *X, t_s_int z ) 668 672 { 669 673 mpi Y; … … 683 687 int mpi_add_abs( mpi *X, const mpi *A, const mpi *B ) 684 688 { 685 int ret, i, j; 689 int ret; 690 size_t i, j; 686 691 t_int *o, *p, c; 687 692 … … 699 704 X->s = 1; 700 705 701 for( j = B->n - 1; j >=0; j-- )702 if( B->p[j ] != 0 )706 for( j = B->n; j > 0; j-- ) 707 if( B->p[j - 1] != 0 ) 703 708 break; 704 709 705 MPI_CHK( mpi_grow( X, j + 1) );710 MPI_CHK( mpi_grow( X, j ) ); 706 711 707 712 o = B->p; p = X->p; c = 0; 708 713 709 for( i = 0; i < =j; i++, o++, p++ )714 for( i = 0; i < j; i++, o++, p++ ) 710 715 { 711 716 *p += c; c = ( *p < c ); … … 732 737 * Helper for mpi substraction 733 738 */ 734 static void mpi_sub_hlp( int n, t_int *s, t_int *d )735 { 736 int i;739 static void mpi_sub_hlp( size_t n, t_int *s, t_int *d ) 740 { 741 size_t i; 737 742 t_int c, z; 738 743 … … 756 761 { 757 762 mpi TB; 758 int ret, n; 763 int ret; 764 size_t n; 759 765 760 766 if( mpi_cmp_abs( A, B ) < 0 ) … … 779 785 ret = 0; 780 786 781 for( n = B->n - 1; n >=0; n-- )782 if( B->p[n ] != 0 )787 for( n = B->n; n > 0; n-- ) 788 if( B->p[n - 1] != 0 ) 783 789 break; 784 790 785 mpi_sub_hlp( n + 1, B->p, X->p );791 mpi_sub_hlp( n, B->p, X->p ); 786 792 787 793 cleanup: … … 857 863 * Signed addition: X = A + b 858 864 */ 859 int mpi_add_int( mpi *X, const mpi *A, int b )865 int mpi_add_int( mpi *X, const mpi *A, t_s_int b ) 860 866 { 861 867 mpi _B; … … 873 879 * Signed substraction: X = A - b 874 880 */ 875 int mpi_sub_int( mpi *X, const mpi *A, int b )881 int mpi_sub_int( mpi *X, const mpi *A, t_s_int b ) 876 882 { 877 883 mpi _B; … … 889 895 * Helper for mpi multiplication 890 896 */ 891 static void mpi_mul_hlp( int i, t_int *s, t_int *d, t_int b )897 static void mpi_mul_hlp( size_t i, t_int *s, t_int *d, t_int b ) 892 898 { 893 899 t_int c = 0, t = 0; … … 955 961 int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B ) 956 962 { 957 int ret, i, j; 963 int ret; 964 size_t i, j; 958 965 mpi TA, TB; 959 966 … … 963 970 if( X == B ) { MPI_CHK( mpi_copy( &TB, B ) ); B = &TB; } 964 971 965 for( i = A->n - 1; i >=0; i-- )966 if( A->p[i ] != 0 )972 for( i = A->n; i > 0; i-- ) 973 if( A->p[i - 1] != 0 ) 967 974 break; 968 975 969 for( j = B->n - 1; j >=0; j-- )970 if( B->p[j ] != 0 )976 for( j = B->n; j > 0; j-- ) 977 if( B->p[j - 1] != 0 ) 971 978 break; 972 979 973 MPI_CHK( mpi_grow( X, i + j + 2) );980 MPI_CHK( mpi_grow( X, i + j ) ); 974 981 MPI_CHK( mpi_lset( X, 0 ) ); 975 982 976 for( i++; j > =0; j-- )977 mpi_mul_hlp( i , A->p, X->p + j, B->p[j] );983 for( i++; j > 0; j-- ) 984 mpi_mul_hlp( i - 1, A->p, X->p + j - 1, B->p[j - 1] ); 978 985 979 986 X->s = A->s * B->s; … … 989 996 * Baseline multiplication: X = A * b 990 997 */ 991 int mpi_mul_int( mpi *X, const mpi *A, t_ int b )998 int mpi_mul_int( mpi *X, const mpi *A, t_s_int b ) 992 999 { 993 1000 mpi _B; … … 1007 1014 int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B ) 1008 1015 { 1009 int ret, i, n, t, k; 1016 int ret; 1017 size_t i, n, t, k; 1010 1018 mpi X, Y, Z, T1, T2; 1011 1019 … … 1170 1178 * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0 1171 1179 */ 1172 int mpi_div_int( mpi *Q, mpi *R, const mpi *A, int b )1180 int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_s_int b ) 1173 1181 { 1174 1182 mpi _B; … … 1209 1217 * Modulo: r = A mod b 1210 1218 */ 1211 int mpi_mod_int( t_int *r, const mpi *A, int b )1212 { 1213 int i;1219 int mpi_mod_int( t_int *r, const mpi *A, t_s_int b ) 1220 { 1221 size_t i; 1214 1222 t_int x, y, z; 1215 1223 … … 1238 1246 * general case 1239 1247 */ 1240 for( i = A->n - 1, y = 0; i >=0; i-- )1241 { 1242 x = A->p[i ];1248 for( i = A->n, y = 0; i > 0; i-- ) 1249 { 1250 x = A->p[i - 1]; 1243 1251 y = ( y << biH ) | ( x >> biH ); 1244 1252 z = y / b; … … 1286 1294 static void mpi_montmul( mpi *A, const mpi *B, const mpi *N, t_int mm, const mpi *T ) 1287 1295 { 1288 int i, n, m;1296 size_t i, n, m; 1289 1297 t_int u0, u1, *d; 1290 1298 … … 1337 1345 int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR ) 1338 1346 { 1339 int ret, i, j, wsize, wbits; 1340 int bufsize, nblimbs, nbits; 1347 int ret; 1348 size_t wbits, wsize, one = 1; 1349 size_t i, j, nblimbs; 1350 size_t bufsize, nbits; 1341 1351 t_int ei, mm, state; 1342 1352 mpi RR, T, W[64]; … … 1397 1407 * W[1 << (wsize - 1)] = W[1] ^ (wsize - 1) 1398 1408 */ 1399 j = 1<< (wsize - 1);1409 j = one << (wsize - 1); 1400 1410 1401 1411 MPI_CHK( mpi_grow( &W[j], N->n + 1 ) ); … … 1408 1418 * W[i] = W[i - 1] * W[1] 1409 1419 */ 1410 for( i = j + 1; i < ( 1<< wsize); i++ )1420 for( i = j + 1; i < (one << wsize); i++ ) 1411 1421 { 1412 1422 MPI_CHK( mpi_grow( &W[i], N->n + 1 ) ); … … 1488 1498 wbits <<= 1; 1489 1499 1490 if( (wbits & ( 1<< wsize)) != 0 )1500 if( (wbits & (one << wsize)) != 0 ) 1491 1501 mpi_montmul( X, &W[1], N, mm, &T ); 1492 1502 } … … 1499 1509 cleanup: 1500 1510 1501 for( i = ( 1 << (wsize - 1)); i < (1<< wsize); i++ )1511 for( i = (one << (wsize - 1)); i < (one << wsize); i++ ) 1502 1512 mpi_free( &W[i], NULL ); 1503 1513 … … 1514 1524 int mpi_gcd( mpi *G, const mpi *A, const mpi *B ) 1515 1525 { 1516 int ret, lz, lzt; 1526 int ret; 1527 size_t lz, lzt; 1517 1528 mpi TG, TA, TB; 1518 1529 … … 1560 1571 } 1561 1572 1562 int mpi_fill_random( mpi *X, int size, int (*f_rng)(void *), void *p_rng ) 1563 { 1564 int ret, k; 1573 int mpi_fill_random( mpi *X, size_t size, int (*f_rng)(void *), void *p_rng ) 1574 { 1575 int ret; 1576 size_t k; 1565 1577 unsigned char *p; 1566 1578 … … 1701 1713 int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ) 1702 1714 { 1703 int ret, i, j, n, s, xs; 1715 int ret, xs; 1716 size_t i, j, n, s; 1704 1717 mpi W, R, T, A, RR; 1705 1718 … … 1812 1825 * Prime number generation 1813 1826 */ 1814 int mpi_gen_prime( mpi *X, int nbits, int dh_flag,1827 int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, 1815 1828 int (*f_rng)(void *), void *p_rng ) 1816 1829 { 1817 int ret, k, n; 1830 int ret; 1831 size_t k, n; 1818 1832 mpi Y; 1819 1833 … … 1879 1893 #if defined(POLARSSL_SELF_TEST) 1880 1894 1881 #define GCD_PAIR_COUNT 31895 #define GCD_PAIR_COUNT 3 1882 1896 1883 1897 static const int gcd_pairs[GCD_PAIR_COUNT][3] = … … 2013 2027 { 2014 2028 MPI_CHK( mpi_lset( &X, gcd_pairs[i][0] ) ); 2015 MPI_CHK( mpi_lset( &Y, gcd_pairs[i][1] ) );2016 2017 MPI_CHK( mpi_gcd( &A, &X, &Y ) );2018 2019 if( mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 )2020 {2021 if( verbose != 0 )2022 printf( "failed at %d\n", i );2023 2024 return( 1 );2025 }2029 MPI_CHK( mpi_lset( &Y, gcd_pairs[i][1] ) ); 2030 2031 MPI_CHK( mpi_gcd( &A, &X, &Y ) ); 2032 2033 if( mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 ) 2034 { 2035 if( verbose != 0 ) 2036 printf( "failed at %d\n", i ); 2037 2038 return( 1 ); 2039 } 2026 2040 } 2027 2041 -
trunk/library/camellia.c
r1011 r1014 36 36 #include "polarssl/camellia.h" 37 37 38 #include <string.h>39 40 38 /* 41 39 * 32-bit integer manipulation macros (big endian) … … 310 308 * Camellia key schedule (encryption) 311 309 */ 312 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize ) 313 { 314 int i, idx; 310 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, unsigned int keysize ) 311 { 312 int idx; 313 size_t i; 315 314 uint32_t *RK; 316 315 unsigned char t[64]; … … 413 412 * Camellia key schedule (decryption) 414 413 */ 415 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize ) 416 { 417 int i, idx; 414 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, unsigned int keysize ) 415 { 416 int idx; 417 size_t i; 418 418 camellia_context cty; 419 419 uint32_t *RK; … … 527 527 int camellia_crypt_cbc( camellia_context *ctx, 528 528 int mode, 529 int length,529 size_t length, 530 530 unsigned char iv[16], 531 531 const unsigned char *input, … … 580 580 int camellia_crypt_cfb128( camellia_context *ctx, 581 581 int mode, 582 int length,582 size_t length, 583 583 int *iv_off, 584 584 unsigned char iv[16], -
trunk/library/cipher.c
r1008 r1014 35 35 #include "polarssl/cipher_wrap.h" 36 36 37 #include <string.h>38 37 #include <stdlib.h> 39 38 … … 197 196 } 198 197 199 int cipher_update( cipher_context_t *ctx, const unsigned char *input, int ilen,200 unsigned char *output, int *olen )201 { 202 int copy_len = 0;198 int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ilen, 199 unsigned char *output, size_t *olen ) 200 { 201 size_t copy_len = 0; 203 202 204 203 if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen || … … 287 286 } 288 287 289 static void add_pkcs_padding( unsigned char *output, unsigned charoutput_len,290 int data_len )291 { 292 unsigned charpadding_len = output_len - data_len;288 static void add_pkcs_padding( unsigned char *output, size_t output_len, 289 size_t data_len ) 290 { 291 size_t padding_len = output_len - data_len; 293 292 unsigned char i = 0; 294 293 295 294 for( i = 0; i < padding_len; i++ ) 296 output[data_len + i] = padding_len;295 output[data_len + i] = (unsigned char) padding_len; 297 296 } 298 297 299 298 static int get_pkcs_padding( unsigned char *input, unsigned char input_len, 300 int *data_len)299 size_t *data_len) 301 300 { 302 301 int i = 0; … … 320 319 } 321 320 322 int cipher_finish( cipher_context_t *ctx, unsigned char *output, int *olen)321 int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen) 323 322 { 324 323 if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen ) -
trunk/library/cipher_wrap.c
r1007 r1014 37 37 #include "polarssl/des.h" 38 38 39 #include <string.h>40 39 #include <stdlib.h> 41 40 42 41 #if defined(POLARSSL_AES_C) 43 42 44 int aes_crypt_cbc_wrap( void *ctx, operation_t operation, int length,43 int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 45 44 unsigned char *iv, const unsigned char *input, unsigned char *output ) 46 45 { … … 48 47 } 49 48 50 int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length )49 int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 51 50 { 52 51 return aes_setkey_dec( (aes_context *) ctx, key, key_length ); 53 52 } 54 53 55 int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length )54 int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 56 55 { 57 56 return aes_setkey_enc( (aes_context *) ctx, key, key_length ); … … 69 68 70 69 const cipher_info_t aes_128_cbc_info = { 71 POLARSSL_CIPHER_AES_128_CBC,72 POLARSSL_CIPHER_ID_AES,73 POLARSSL_MODE_CBC,74 128,75 "AES-128-CBC",76 16,77 16,78 aes_crypt_cbc_wrap,79 aes_setkey_enc_wrap,80 aes_setkey_dec_wrap,81 aes_ctx_alloc,82 aes_ctx_free70 POLARSSL_CIPHER_AES_128_CBC, 71 POLARSSL_CIPHER_ID_AES, 72 POLARSSL_MODE_CBC, 73 128, 74 "AES-128-CBC", 75 16, 76 16, 77 aes_crypt_cbc_wrap, 78 aes_setkey_enc_wrap, 79 aes_setkey_dec_wrap, 80 aes_ctx_alloc, 81 aes_ctx_free 83 82 }; 84 83 85 84 const cipher_info_t aes_192_cbc_info = { 86 POLARSSL_CIPHER_AES_192_CBC,87 POLARSSL_CIPHER_ID_AES,88 POLARSSL_MODE_CBC,89 192,90 "AES-192-CBC",91 16,92 16,93 aes_crypt_cbc_wrap,94 aes_setkey_enc_wrap,95 aes_setkey_dec_wrap,96 aes_ctx_alloc,97 aes_ctx_free85 POLARSSL_CIPHER_AES_192_CBC, 86 POLARSSL_CIPHER_ID_AES, 87 POLARSSL_MODE_CBC, 88 192, 89 "AES-192-CBC", 90 16, 91 16, 92 aes_crypt_cbc_wrap, 93 aes_setkey_enc_wrap, 94 aes_setkey_dec_wrap, 95 aes_ctx_alloc, 96 aes_ctx_free 98 97 }; 99 98 100 99 const cipher_info_t aes_256_cbc_info = { 101 POLARSSL_CIPHER_AES_256_CBC,102 POLARSSL_CIPHER_ID_AES,103 POLARSSL_MODE_CBC,104 256,105 "AES-256-CBC",106 16,107 16,108 aes_crypt_cbc_wrap,109 aes_setkey_enc_wrap,110 aes_setkey_dec_wrap,111 aes_ctx_alloc,112 aes_ctx_free100 POLARSSL_CIPHER_AES_256_CBC, 101 POLARSSL_CIPHER_ID_AES, 102 POLARSSL_MODE_CBC, 103 256, 104 "AES-256-CBC", 105 16, 106 16, 107 aes_crypt_cbc_wrap, 108 aes_setkey_enc_wrap, 109 aes_setkey_dec_wrap, 110 aes_ctx_alloc, 111 aes_ctx_free 113 112 }; 114 113 #endif … … 116 115 #if defined(POLARSSL_CAMELLIA_C) 117 116 118 int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, int length,117 int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 119 118 unsigned char *iv, const unsigned char *input, unsigned char *output ) 120 119 { … … 122 121 } 123 122 124 int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length )123 int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 125 124 { 126 125 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length ); 127 126 } 128 127 129 int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length )128 int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 130 129 { 131 130 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length ); … … 143 142 144 143 const cipher_info_t camellia_128_cbc_info = { 145 POLARSSL_CIPHER_CAMELLIA_128_CBC,146 POLARSSL_CIPHER_ID_CAMELLIA,147 POLARSSL_MODE_CBC,148 128,149 "CAMELLIA-128-CBC",150 16,151 16,152 camellia_crypt_cbc_wrap,153 camellia_setkey_enc_wrap,154 camellia_setkey_dec_wrap,155 camellia_ctx_alloc,156 camellia_ctx_free144 POLARSSL_CIPHER_CAMELLIA_128_CBC, 145 POLARSSL_CIPHER_ID_CAMELLIA, 146 POLARSSL_MODE_CBC, 147 128, 148 "CAMELLIA-128-CBC", 149 16, 150 16, 151 camellia_crypt_cbc_wrap, 152 camellia_setkey_enc_wrap, 153 camellia_setkey_dec_wrap, 154 camellia_ctx_alloc, 155 camellia_ctx_free 157 156 }; 158 157 159 158 const cipher_info_t camellia_192_cbc_info = { 160 POLARSSL_CIPHER_CAMELLIA_192_CBC,161 POLARSSL_CIPHER_ID_CAMELLIA,162 POLARSSL_MODE_CBC,163 192,164 "CAMELLIA-192-CBC",165 16,166 16,167 camellia_crypt_cbc_wrap,168 camellia_setkey_enc_wrap,169 camellia_setkey_dec_wrap,170 camellia_ctx_alloc,171 camellia_ctx_free159 POLARSSL_CIPHER_CAMELLIA_192_CBC, 160 POLARSSL_CIPHER_ID_CAMELLIA, 161 POLARSSL_MODE_CBC, 162 192, 163 "CAMELLIA-192-CBC", 164 16, 165 16, 166 camellia_crypt_cbc_wrap, 167 camellia_setkey_enc_wrap, 168 camellia_setkey_dec_wrap, 169 camellia_ctx_alloc, 170 camellia_ctx_free 172 171 }; 173 172 174 173 const cipher_info_t camellia_256_cbc_info = { 175 POLARSSL_CIPHER_CAMELLIA_256_CBC,176 POLARSSL_CIPHER_ID_CAMELLIA,177 POLARSSL_MODE_CBC,178 256,179 "CAMELLIA-256-CBC",180 16,181 16,182 camellia_crypt_cbc_wrap,183 camellia_setkey_enc_wrap,184 camellia_setkey_dec_wrap,185 camellia_ctx_alloc,186 camellia_ctx_free174 POLARSSL_CIPHER_CAMELLIA_256_CBC, 175 POLARSSL_CIPHER_ID_CAMELLIA, 176 POLARSSL_MODE_CBC, 177 256, 178 "CAMELLIA-256-CBC", 179 16, 180 16, 181 camellia_crypt_cbc_wrap, 182 camellia_setkey_enc_wrap, 183 camellia_setkey_dec_wrap, 184 camellia_ctx_alloc, 185 camellia_ctx_free 187 186 }; 188 187 #endif … … 190 189 #if defined(POLARSSL_DES_C) 191 190 192 int des_crypt_cbc_wrap( void *ctx, operation_t operation, int length,191 int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 193 192 unsigned char *iv, const unsigned char *input, unsigned char *output ) 194 193 { … … 196 195 } 197 196 198 int des3_crypt_cbc_wrap( void *ctx, operation_t operation, int length,197 int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 199 198 unsigned char *iv, const unsigned char *input, unsigned char *output ) 200 199 { … … 202 201 } 203 202 204 int des_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length )203 int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 205 204 { 206 205 ((void) key_length); … … 209 208 } 210 209 211 int des_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length )210 int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 212 211 { 213 212 ((void) key_length); … … 216 215 } 217 216 218 int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, int key_length )217 int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 219 218 { 220 219 ((void) key_length); … … 223 222 } 224 223 225 int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, int key_length )224 int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 226 225 { 227 226 ((void) key_length); … … 230 229 } 231 230 232 int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, int key_length )231 int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 233 232 { 234 233 ((void) key_length); … … 237 236 } 238 237 239 int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, int key_length )238 int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 240 239 { 241 240 ((void) key_length); … … 260 259 261 260 const cipher_info_t des_cbc_info = { 262 POLARSSL_CIPHER_DES_CBC,263 POLARSSL_CIPHER_ID_DES,264 POLARSSL_MODE_CBC,265 POLARSSL_KEY_LENGTH_DES,266 "DES-CBC",267 8,268 8,269 des_crypt_cbc_wrap,270 des_setkey_enc_wrap,271 des_setkey_dec_wrap,272 des_ctx_alloc,273 des_ctx_free261 POLARSSL_CIPHER_DES_CBC, 262 POLARSSL_CIPHER_ID_DES, 263 POLARSSL_MODE_CBC, 264 POLARSSL_KEY_LENGTH_DES, 265 "DES-CBC", 266 8, 267 8, 268 des_crypt_cbc_wrap, 269 des_setkey_enc_wrap, 270 des_setkey_dec_wrap, 271 des_ctx_alloc, 272 des_ctx_free 274 273 }; 275 274 276 275 const cipher_info_t des_ede_cbc_info = { 277 POLARSSL_CIPHER_DES_EDE_CBC,278 POLARSSL_CIPHER_ID_DES,279 POLARSSL_MODE_CBC,280 POLARSSL_KEY_LENGTH_DES_EDE,281 "DES-EDE-CBC",282 16,283 16,284 des3_crypt_cbc_wrap,285 des3_set2key_enc_wrap,286 des3_set2key_dec_wrap,287 des3_ctx_alloc,288 des_ctx_free276 POLARSSL_CIPHER_DES_EDE_CBC, 277 POLARSSL_CIPHER_ID_DES, 278 POLARSSL_MODE_CBC, 279 POLARSSL_KEY_LENGTH_DES_EDE, 280 "DES-EDE-CBC", 281 16, 282 16, 283 des3_crypt_cbc_wrap, 284 des3_set2key_enc_wrap, 285 des3_set2key_dec_wrap, 286 des3_ctx_alloc, 287 des_ctx_free 289 288 }; 290 289 291 290 const cipher_info_t des_ede3_cbc_info = { 292 POLARSSL_CIPHER_DES_EDE3_CBC,293 POLARSSL_CIPHER_ID_DES,294 POLARSSL_MODE_CBC,295 POLARSSL_KEY_LENGTH_DES_EDE3,296 "DES-EDE3-CBC",297 8,298 8,299 des3_crypt_cbc_wrap,300 des3_set3key_enc_wrap,301 des3_set3key_dec_wrap,302 des3_ctx_alloc,303 des_ctx_free291 POLARSSL_CIPHER_DES_EDE3_CBC, 292 POLARSSL_CIPHER_ID_DES, 293 POLARSSL_MODE_CBC, 294 POLARSSL_KEY_LENGTH_DES_EDE3, 295 "DES-EDE3-CBC", 296 8, 297 8, 298 des3_crypt_cbc_wrap, 299 des3_set3key_enc_wrap, 300 des3_set3key_dec_wrap, 301 des3_ctx_alloc, 302 des_ctx_free 304 303 }; 305 304 #endif -
trunk/library/debug.c
r985 r1014 88 88 void debug_print_buf( const ssl_context *ssl, int level, 89 89 const char *file, int line, const char *text, 90 unsigned char *buf, int len )91 { 92 char str[512]; 93 int i, maxlen = sizeof( str ) - 1;94 95 if( ssl->f_dbg == NULL || len < 0)90 unsigned char *buf, size_t len ) 91 { 92 char str[512]; 93 size_t i, maxlen = sizeof( str ) - 1; 94 95 if( ssl->f_dbg == NULL ) 96 96 return; 97 97 … … 133 133 { 134 134 char str[512]; 135 int i, j, k, n, maxlen = sizeof( str ) - 1, zeros = 1; 135 int j, k, maxlen = sizeof( str ) - 1, zeros = 1; 136 size_t i, n; 136 137 137 138 if( ssl->f_dbg == NULL || X == NULL ) … … 153 154 ssl->f_dbg( ssl->p_dbg, level, str ); 154 155 155 for( i = n , j = 0; i >=0; i-- )156 { 157 if( zeros && X->p[i ] == 0 )156 for( i = n + 1, j = 0; i > 0; i-- ) 157 { 158 if( zeros && X->p[i - 1] == 0 ) 158 159 continue; 159 160 160 161 for( k = sizeof( t_int ) - 1; k >= 0; k-- ) 161 162 { 162 if( zeros && ( ( X->p[i ] >> (k << 3) ) & 0xFF ) == 0 )163 if( zeros && ( ( X->p[i - 1] >> (k << 3) ) & 0xFF ) == 0 ) 163 164 continue; 164 165 else … … 177 178 178 179 snprintf( str, maxlen, " %02x", (unsigned int) 179 ( X->p[i ] >> (k << 3) ) & 0xFF );180 ( X->p[i - 1] >> (k << 3) ) & 0xFF ); 180 181 181 182 str[maxlen] = '\0'; -
trunk/library/des.c
r921 r1014 35 35 36 36 #include "polarssl/des.h" 37 38 #include <string.h>39 37 40 38 /* … … 612 610 int des_crypt_cbc( des_context *ctx, 613 611 int mode, 614 int length,612 size_t length, 615 613 unsigned char iv[8], 616 614 const unsigned char *input, … … 707 705 int des3_crypt_cbc( des3_context *ctx, 708 706 int mode, 709 int length,707 size_t length, 710 708 unsigned char iv[8], 711 709 const unsigned char *input, -
trunk/library/dhm.c
r1003 r1014 34 34 35 35 #include "polarssl/dhm.h" 36 37 #include <string.h>38 36 39 37 /* … … 129 127 */ 130 128 int dhm_make_params( dhm_context *ctx, int x_size, 131 unsigned char *output, int *olen,129 unsigned char *output, size_t *olen, 132 130 int (*f_rng)(void *), void *p_rng ) 133 131 { 134 int ret, n, n1, n2, n3; 132 int ret, n; 133 size_t n1, n2, n3; 135 134 unsigned char *p; 136 135 … … 187 186 */ 188 187 int dhm_read_public( dhm_context *ctx, 189 const unsigned char *input, int ilen )188 const unsigned char *input, size_t ilen ) 190 189 { 191 190 int ret; … … 204 203 */ 205 204 int dhm_make_public( dhm_context *ctx, int x_size, 206 unsigned char *output, int olen,205 unsigned char *output, size_t olen, 207 206 int (*f_rng)(void *), void *p_rng ) 208 207 { … … 242 241 */ 243 242 int dhm_calc_secret( dhm_context *ctx, 244 unsigned char *output, int *olen )243 unsigned char *output, size_t *olen ) 245 244 { 246 245 int ret; -
trunk/library/havege.c
r1008 r1014 35 35 #if defined(POLARSSL_HAVEGE_C) 36 36 37 #include "polarssl/havege.h" 38 #include "polarssl/timing.h" 39 37 40 #include <string.h> 38 41 #include <time.h> 39 40 #include "polarssl/havege.h"41 #include "polarssl/timing.h"42 42 43 43 /* ------------------------------------------------------------------------ -
trunk/library/md.c
r1008 r1014 35 35 #include "polarssl/md_wrap.h" 36 36 37 #include <string.h>38 37 #include <stdlib.h> 39 38 … … 191 190 } 192 191 193 int md_update( md_context_t *ctx, const unsigned char *input, int ilen )192 int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen ) 194 193 { 195 194 if( ctx == NULL || ctx->md_info == NULL ) … … 211 210 } 212 211 213 int md( const md_info_t *md_info, const unsigned char *input, int ilen,212 int md( const md_info_t *md_info, const unsigned char *input, size_t ilen, 214 213 unsigned char *output ) 215 214 { … … 230 229 } 231 230 232 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, int keylen )231 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen ) 233 232 { 234 233 if( ctx == NULL || ctx->md_info == NULL ) … … 240 239 } 241 240 242 int md_hmac_update( md_context_t *ctx, const unsigned char *input, int ilen )241 int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen ) 243 242 { 244 243 if( ctx == NULL || ctx->md_info == NULL ) … … 270 269 } 271 270 272 int md_hmac( const md_info_t *md_info, const unsigned char *key, int keylen,273 const unsigned char *input, int ilen,271 int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen, 272 const unsigned char *input, size_t ilen, 274 273 unsigned char *output ) 275 274 { -
trunk/library/md2.c
r897 r1014 36 36 #include "polarssl/md2.h" 37 37 38 #include <string.h>39 38 #include <stdio.h> 40 39 … … 117 116 * MD2 process buffer 118 117 */ 119 void md2_update( md2_context *ctx, const unsigned char *input, int ilen )120 { 121 int fill;118 void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen ) 119 { 120 size_t fill; 122 121 123 122 while( ilen > 0 ) … … 147 146 void md2_finish( md2_context *ctx, unsigned char output[16] ) 148 147 { 149 int i;148 size_t i; 150 149 unsigned char x; 151 150 … … 166 165 * output = MD2( input buffer ) 167 166 */ 168 void md2( const unsigned char *input, int ilen, unsigned char output[16] )167 void md2( const unsigned char *input, size_t ilen, unsigned char output[16] ) 169 168 { 170 169 md2_context ctx; … … 212 211 * MD2 HMAC context setup 213 212 */ 214 void md2_hmac_starts( md2_context *ctx, const unsigned char *key, int keylen )215 { 216 int i;213 void md2_hmac_starts( md2_context *ctx, const unsigned char *key, size_t keylen ) 214 { 215 size_t i; 217 216 unsigned char sum[16]; 218 217 … … 242 241 * MD2 HMAC process buffer 243 242 */ 244 void md2_hmac_update( md2_context *ctx, const unsigned char *input, int ilen )243 void md2_hmac_update( md2_context *ctx, const unsigned char *input, size_t ilen ) 245 244 { 246 245 md2_update( ctx, input, ilen ); … … 275 274 * output = HMAC-MD2( hmac key, input buffer ) 276 275 */ 277 void md2_hmac( const unsigned char *key, int keylen,278 const unsigned char *input, int ilen,276 void md2_hmac( const unsigned char *key, size_t keylen, 277 const unsigned char *input, size_t ilen, 279 278 unsigned char output[16] ) 280 279 { -
trunk/library/md4.c
r897 r1014 36 36 #include "polarssl/md4.h" 37 37 38 #include <string.h>39 38 #include <stdio.h> 40 39 … … 182 181 * MD4 process buffer 183 182 */ 184 void md4_update( md4_context *ctx, const unsigned char *input, int ilen )185 { 186 int fill;183 void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen ) 184 { 185 size_t fill; 187 186 unsigned long left; 188 187 … … 193 192 fill = 64 - left; 194 193 195 ctx->total[0] += ilen;194 ctx->total[0] += (unsigned long) ilen; 196 195 ctx->total[0] &= 0xFFFFFFFF; 197 196 … … 262 261 * output = MD4( input buffer ) 263 262 */ 264 void md4( const unsigned char *input, int ilen, unsigned char output[16] )263 void md4( const unsigned char *input, size_t ilen, unsigned char output[16] ) 265 264 { 266 265 md4_context ctx; … … 308 307 * MD4 HMAC context setup 309 308 */ 310 void md4_hmac_starts( md4_context *ctx, const unsigned char *key, int keylen )311 { 312 int i;309 void md4_hmac_starts( md4_context *ctx, const unsigned char *key, size_t keylen ) 310 { 311 size_t i; 313 312 unsigned char sum[16]; 314 313 … … 338 337 * MD4 HMAC process buffer 339 338 */ 340 void md4_hmac_update( md4_context *ctx, const unsigned char *input, int ilen )339 void md4_hmac_update( md4_context *ctx, const unsigned char *input, size_t ilen ) 341 340 { 342 341 md4_update( ctx, input, ilen ); … … 371 370 * output = HMAC-MD4( hmac key, input buffer ) 372 371 */ 373 void md4_hmac( const unsigned char *key, int keylen,374 const unsigned char *input, int ilen,372 void md4_hmac( const unsigned char *key, size_t keylen, 373 const unsigned char *input, size_t ilen, 375 374 unsigned char output[16] ) 376 375 { -
trunk/library/md5.c
r897 r1014 35 35 #include "polarssl/md5.h" 36 36 37 #include <string.h>38 37 #include <stdio.h> 39 38 … … 201 200 * MD5 process buffer 202 201 */ 203 void md5_update( md5_context *ctx, const unsigned char *input, int ilen )204 { 205 int fill;202 void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen ) 203 { 204 size_t fill; 206 205 unsigned long left; 207 206 … … 212 211 fill = 64 - left; 213 212 214 ctx->total[0] += ilen;213 ctx->total[0] += (unsigned long) ilen; 215 214 ctx->total[0] &= 0xFFFFFFFF; 216 215 … … 281 280 * output = MD5( input buffer ) 282 281 */ 283 void md5( const unsigned char *input, int ilen, unsigned char output[16] )282 void md5( const unsigned char *input, size_t ilen, unsigned char output[16] ) 284 283 { 285 284 md5_context ctx; … … 327 326 * MD5 HMAC context setup 328 327 */ 329 void md5_hmac_starts( md5_context *ctx, const unsigned char *key, int keylen )330 { 331 int i;328 void md5_hmac_starts( md5_context *ctx, const unsigned char *key, size_t keylen ) 329 { 330 size_t i; 332 331 unsigned char sum[16]; 333 332 … … 357 356 * MD5 HMAC process buffer 358 357 */ 359 void md5_hmac_update( md5_context *ctx, const unsigned char *input, int ilen )358 void md5_hmac_update( md5_context *ctx, const unsigned char *input, size_t ilen ) 360 359 { 361 360 md5_update( ctx, input, ilen ); … … 390 389 * output = HMAC-MD5( hmac key, input buffer ) 391 390 */ 392 void md5_hmac( const unsigned char *key, int keylen,393 const unsigned char *input, int ilen,391 void md5_hmac( const unsigned char *key, size_t keylen, 392 const unsigned char *input, size_t ilen, 394 393 unsigned char output[16] ) 395 394 { -
trunk/library/md_wrap.c
r1007 r1014 40 40 #include "polarssl/sha4.h" 41 41 42 #include <string.h>43 42 #include <stdlib.h> 44 43 … … 50 49 } 51 50 52 static void md2_update_wrap( void *ctx, const unsigned char *input, int ilen )51 static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 53 52 { 54 53 md2_update( (md2_context *) ctx, input, ilen ); … … 60 59 } 61 60 62 static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )61 static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 63 62 { 64 63 md2_hmac_starts( (md2_context *) ctx, key, keylen ); 65 64 } 66 65 67 static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )66 static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 68 67 { 69 68 md2_hmac_update( (md2_context *) ctx, input, ilen ); … … 91 90 92 91 const md_info_t md2_info = { 93 POLARSSL_MD_MD2,94 "MD2",95 16,96 md2_starts_wrap,97 md2_update_wrap,98 md2_finish_wrap,99 md2,100 md2_file,101 md2_hmac_starts_wrap,102 md2_hmac_update_wrap,103 md2_hmac_finish_wrap,104 md2_hmac_reset_wrap,105 md2_hmac,106 md2_ctx_alloc,107 md2_ctx_free,92 POLARSSL_MD_MD2, 93 "MD2", 94 16, 95 md2_starts_wrap, 96 md2_update_wrap, 97 md2_finish_wrap, 98 md2, 99 md2_file, 100 md2_hmac_starts_wrap, 101 md2_hmac_update_wrap, 102 md2_hmac_finish_wrap, 103 md2_hmac_reset_wrap, 104 md2_hmac, 105 md2_ctx_alloc, 106 md2_ctx_free, 108 107 }; 109 108 … … 117 116 } 118 117 119 void md4_update_wrap( void *ctx, const unsigned char *input, int ilen )118 void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 120 119 { 121 120 md4_update( (md4_context *) ctx, input, ilen ); … … 127 126 } 128 127 129 void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )128 void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 130 129 { 131 130 md4_hmac_starts( (md4_context *) ctx, key, keylen ); 132 131 } 133 132 134 void md4_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )133 void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 135 134 { 136 135 md4_hmac_update( (md4_context *) ctx, input, ilen ); … … 158 157 159 158 const md_info_t md4_info = { 160 POLARSSL_MD_MD4,161 "MD4",162 16,163 md4_starts_wrap,164 md4_update_wrap,165 md4_finish_wrap,166 md4,167 md4_file,168 md4_hmac_starts_wrap,169 md4_hmac_update_wrap,170 md4_hmac_finish_wrap,171 md4_hmac_reset_wrap,172 md4_hmac,173 md4_ctx_alloc,174 md4_ctx_free,159 POLARSSL_MD_MD4, 160 "MD4", 161 16, 162 md4_starts_wrap, 163 md4_update_wrap, 164 md4_finish_wrap, 165 md4, 166 md4_file, 167 md4_hmac_starts_wrap, 168 md4_hmac_update_wrap, 169 md4_hmac_finish_wrap, 170 md4_hmac_reset_wrap, 171 md4_hmac, 172 md4_ctx_alloc, 173 md4_ctx_free, 175 174 }; 176 175 … … 184 183 } 185 184 186 static void md5_update_wrap( void *ctx, const unsigned char *input, int ilen )185 static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 187 186 { 188 187 md5_update( (md5_context *) ctx, input, ilen ); … … 194 193 } 195 194 196 static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )195 static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 197 196 { 198 197 md5_hmac_starts( (md5_context *) ctx, key, keylen ); 199 198 } 200 199 201 static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )200 static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 202 201 { 203 202 md5_hmac_update( (md5_context *) ctx, input, ilen ); … … 225 224 226 225 const md_info_t md5_info = { 227 POLARSSL_MD_MD5,228 "MD5",229 16,230 md5_starts_wrap,231 md5_update_wrap,232 md5_finish_wrap,233 md5,234 md5_file,235 md5_hmac_starts_wrap,236 md5_hmac_update_wrap,237 md5_hmac_finish_wrap,238 md5_hmac_reset_wrap,239 md5_hmac,240 md5_ctx_alloc,241 md5_ctx_free,226 POLARSSL_MD_MD5, 227 "MD5", 228 16, 229 md5_starts_wrap, 230 md5_update_wrap, 231 md5_finish_wrap, 232 md5, 233 md5_file, 234 md5_hmac_starts_wrap, 235 md5_hmac_update_wrap, 236 md5_hmac_finish_wrap, 237 md5_hmac_reset_wrap, 238 md5_hmac, 239 md5_ctx_alloc, 240 md5_ctx_free, 242 241 }; 243 242 … … 251 250 } 252 251 253 void sha1_update_wrap( void *ctx, const unsigned char *input, int ilen )252 void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 254 253 { 255 254 sha1_update( (sha1_context *) ctx, input, ilen ); … … 261 260 } 262 261 263 void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )262 void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 264 263 { 265 264 sha1_hmac_starts( (sha1_context *) ctx, key, keylen ); 266 265 } 267 266 268 void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )267 void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 269 268 { 270 269 sha1_hmac_update( (sha1_context *) ctx, input, ilen ); … … 292 291 293 292 const md_info_t sha1_info = { 294 POLARSSL_MD_SHA1,295 "SHA1",296 20,297 sha1_starts_wrap,298 sha1_update_wrap,299 sha1_finish_wrap,300 sha1,301 sha1_file,302 sha1_hmac_starts_wrap,303 sha1_hmac_update_wrap,304 sha1_hmac_finish_wrap,305 sha1_hmac_reset_wrap,306 sha1_hmac,307 sha1_ctx_alloc,308 sha1_ctx_free,293 POLARSSL_MD_SHA1, 294 "SHA1", 295 20, 296 sha1_starts_wrap, 297 sha1_update_wrap, 298 sha1_finish_wrap, 299 sha1, 300 sha1_file, 301 sha1_hmac_starts_wrap, 302 sha1_hmac_update_wrap, 303 sha1_hmac_finish_wrap, 304 sha1_hmac_reset_wrap, 305 sha1_hmac, 306 sha1_ctx_alloc, 307 sha1_ctx_free, 309 308 }; 310 309 … … 321 320 } 322 321 323 void sha224_update_wrap( void *ctx, const unsigned char *input, int ilen )322 void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 324 323 { 325 324 sha2_update( (sha2_context *) ctx, input, ilen ); … … 331 330 } 332 331 333 void sha224_wrap( const unsigned char *input, int ilen,332 void sha224_wrap( const unsigned char *input, size_t ilen, 334 333 unsigned char *output ) 335 334 { … … 342 341 } 343 342 344 void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )343 void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 345 344 { 346 345 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 ); 347 346 } 348 347 349 void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )348 void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 350 349 { 351 350 sha2_hmac_update( (sha2_context *) ctx, input, ilen ); … … 362 361 } 363 362 364 void sha224_hmac_wrap( const unsigned char *key, int keylen,365 const unsigned char *input, int ilen,363 void sha224_hmac_wrap( const unsigned char *key, size_t keylen, 364 const unsigned char *input, size_t ilen, 366 365 unsigned char *output ) 367 366 { … … 380 379 381 380 const md_info_t sha224_info = { 382 POLARSSL_MD_SHA224,383 "SHA224",384 28,385 sha224_starts_wrap,386 sha224_update_wrap,387 sha224_finish_wrap,388 sha224_wrap,389 sha224_file_wrap,390 sha224_hmac_starts_wrap,391 sha224_hmac_update_wrap,392 sha224_hmac_finish_wrap,393 sha224_hmac_reset_wrap,394 sha224_hmac_wrap,395 sha224_ctx_alloc,396 sha224_ctx_free,381 POLARSSL_MD_SHA224, 382 "SHA224", 383 28, 384 sha224_starts_wrap, 385 sha224_update_wrap, 386 sha224_finish_wrap, 387 sha224_wrap, 388 sha224_file_wrap, 389 sha224_hmac_starts_wrap, 390 sha224_hmac_update_wrap, 391 sha224_hmac_finish_wrap, 392 sha224_hmac_reset_wrap, 393 sha224_hmac_wrap, 394 sha224_ctx_alloc, 395 sha224_ctx_free, 397 396 }; 398 397 … … 402 401 } 403 402 404 void sha256_update_wrap( void *ctx, const unsigned char *input, int ilen )403 void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 405 404 { 406 405 sha2_update( (sha2_context *) ctx, input, ilen ); … … 412 411 } 413 412 414 void sha256_wrap( const unsigned char *input, int ilen,413 void sha256_wrap( const unsigned char *input, size_t ilen, 415 414 unsigned char *output ) 416 415 { … … 423 422 } 424 423 425 void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )424 void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 426 425 { 427 426 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 ); 428 427 } 429 428 430 void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )429 void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 431 430 { 432 431 sha2_hmac_update( (sha2_context *) ctx, input, ilen ); … … 443 442 } 444 443 445 void sha256_hmac_wrap( const unsigned char *key, int keylen,446 const unsigned char *input, int ilen,444 void sha256_hmac_wrap( const unsigned char *key, size_t keylen, 445 const unsigned char *input, size_t ilen, 447 446 unsigned char *output ) 448 447 { … … 461 460 462 461 const md_info_t sha256_info = { 463 POLARSSL_MD_SHA256,464 "SHA256",465 32,466 sha256_starts_wrap,467 sha256_update_wrap,468 sha256_finish_wrap,469 sha256_wrap,470 sha256_file_wrap,471 sha256_hmac_starts_wrap,472 sha256_hmac_update_wrap,473 sha256_hmac_finish_wrap,474 sha256_hmac_reset_wrap,475 sha256_hmac_wrap,476 sha256_ctx_alloc,477 sha256_ctx_free,462 POLARSSL_MD_SHA256, 463 "SHA256", 464 32, 465 sha256_starts_wrap, 466 sha256_update_wrap, 467 sha256_finish_wrap, 468 sha256_wrap, 469 sha256_file_wrap, 470 sha256_hmac_starts_wrap, 471 sha256_hmac_update_wrap, 472 sha256_hmac_finish_wrap, 473 sha256_hmac_reset_wrap, 474 sha256_hmac_wrap, 475 sha256_ctx_alloc, 476 sha256_ctx_free, 478 477 }; 479 478 … … 487 486 } 488 487 489 void sha384_update_wrap( void *ctx, const unsigned char *input, int ilen )488 void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 490 489 { 491 490 sha4_update( (sha4_context *) ctx, input, ilen ); … … 497 496 } 498 497 499 void sha384_wrap( const unsigned char *input, int ilen,498 void sha384_wrap( const unsigned char *input, size_t ilen, 500 499 unsigned char *output ) 501 500 { … … 508 507 } 509 508 510 void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )509 void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 511 510 { 512 511 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 ); 513 512 } 514 513 515 void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )514 void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 516 515 { 517 516 sha4_hmac_update( (sha4_context *) ctx, input, ilen ); … … 528 527 } 529 528 530 void sha384_hmac_wrap( const unsigned char *key, int keylen,531 const unsigned char *input, int ilen,529 void sha384_hmac_wrap( const unsigned char *key, size_t keylen, 530 const unsigned char *input, size_t ilen, 532 531 unsigned char *output ) 533 532 { … … 546 545 547 546 const md_info_t sha384_info = { 548 POLARSSL_MD_SHA384,549 "SHA384",550 48,551 sha384_starts_wrap,552 sha384_update_wrap,553 sha384_finish_wrap,554 sha384_wrap,555 sha384_file_wrap,556 sha384_hmac_starts_wrap,557 sha384_hmac_update_wrap,558 sha384_hmac_finish_wrap,559 sha384_hmac_reset_wrap,560 sha384_hmac_wrap,561 sha384_ctx_alloc,562 sha384_ctx_free,547 POLARSSL_MD_SHA384, 548 "SHA384", 549 48, 550 sha384_starts_wrap, 551 sha384_update_wrap, 552 sha384_finish_wrap, 553 sha384_wrap, 554 sha384_file_wrap, 555 sha384_hmac_starts_wrap, 556 sha384_hmac_update_wrap, 557 sha384_hmac_finish_wrap, 558 sha384_hmac_reset_wrap, 559 sha384_hmac_wrap, 560 sha384_ctx_alloc, 561 sha384_ctx_free, 563 562 }; 564 563 … … 568 567 } 569 568 570 void sha512_update_wrap( void *ctx, const unsigned char *input, int ilen )569 void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 571 570 { 572 571 sha4_update( (sha4_context *) ctx, input, ilen ); … … 578 577 } 579 578 580 void sha512_wrap( const unsigned char *input, int ilen,579 void sha512_wrap( const unsigned char *input, size_t ilen, 581 580 unsigned char *output ) 582 581 { … … 589 588 } 590 589 591 void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen )590 void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 592 591 { 593 592 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 ); 594 593 } 595 594 596 void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen )595 void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 597 596 { 598 597 sha4_hmac_update( (sha4_context *) ctx, input, ilen ); … … 609 608 } 610 609 611 void sha512_hmac_wrap( const unsigned char *key, int keylen,612 const unsigned char *input, int ilen,610 void sha512_hmac_wrap( const unsigned char *key, size_t keylen, 611 const unsigned char *input, size_t ilen, 613 612 unsigned char *output ) 614 613 { … … 627 626 628 627 const md_info_t sha512_info = { 629 POLARSSL_MD_SHA512,630 "SHA512",631 64,632 sha512_starts_wrap,633 sha512_update_wrap,634 sha512_finish_wrap,635 sha512_wrap,636 sha512_file_wrap,637 sha512_hmac_starts_wrap,638 sha512_hmac_update_wrap,639 sha512_hmac_finish_wrap,640 sha512_hmac_reset_wrap,641 sha512_hmac_wrap,642 sha512_ctx_alloc,643 sha512_ctx_free,628 POLARSSL_MD_SHA512, 629 "SHA512", 630 64, 631 sha512_starts_wrap, 632 sha512_update_wrap, 633 sha512_finish_wrap, 634 sha512_wrap, 635 sha512_file_wrap, 636 sha512_hmac_starts_wrap, 637 sha512_hmac_update_wrap, 638 sha512_hmac_finish_wrap, 639 sha512_hmac_reset_wrap, 640 sha512_hmac_wrap, 641 sha512_ctx_alloc, 642 sha512_ctx_free, 644 643 }; 645 644 -
trunk/library/net.c
r897 r1014 41 41 #endif 42 42 43 #define read(fd,buf,len) recv(fd,buf, len,0)44 #define write(fd,buf,len) send(fd,buf, len,0)43 #define read(fd,buf,len) recv(fd,buf,(int) len,0) 44 #define write(fd,buf,len) send(fd,buf,(int) len,0) 45 45 #define close(fd) closesocket(fd) 46 46 … … 70 70 #endif 71 71 72 #include <string.h>73 72 #include <stdlib.h> 74 73 #include <stdio.h> … … 290 289 * Read at most 'len' characters 291 290 */ 292 int net_recv( void *ctx, unsigned char *buf, int len )291 int net_recv( void *ctx, unsigned char *buf, size_t len ) 293 292 { 294 293 int ret = read( *((int *) ctx), buf, len ); … … 322 321 * Write at most 'len' characters 323 322 */ 324 int net_send( void *ctx, unsigned char *buf, int len )323 int net_send( void *ctx, unsigned char *buf, size_t len ) 325 324 { 326 325 int ret = write( *((int *) ctx), buf, len ); -
trunk/library/padlock.c
r897 r1014 34 34 #if defined(POLARSSL_PADLOCK_C) 35 35 36 #include "polarssl/aes.h"37 36 #include "polarssl/padlock.h" 38 37 39 38 #if defined(POLARSSL_HAVE_X86) 40 41 #include <string.h>42 39 43 40 /* … … 116 113 int padlock_xcryptcbc( aes_context *ctx, 117 114 int mode, 118 int length,115 size_t length, 119 116 unsigned char iv[16], 120 117 const unsigned char *input, 121 118 unsigned char *output ) 122 119 { 123 int ebx, count; 120 int ebx; 121 size_t count; 124 122 unsigned long *rk; 125 123 unsigned long *iw; -
trunk/library/pem.c
r956 r1014 36 36 37 37 #include <stdlib.h> 38 #include <string.h>39 38 40 39 void pem_init( pem_context *ctx ) … … 47 46 * Read a 16-byte hex string and convert it to binary 48 47 */ 49 static int pem_get_iv( const unsigned char *s, unsigned char *iv, int iv_len )50 { 51 int i, j, k;48 static int pem_get_iv( const unsigned char *s, unsigned char *iv, size_t iv_len ) 49 { 50 size_t i, j, k; 52 51 53 52 memset( iv, 0, iv_len ); … … 68 67 } 69 68 70 static void pem_pbkdf1( unsigned char *key, int keylen,69 static void pem_pbkdf1( unsigned char *key, size_t keylen, 71 70 unsigned char *iv, 72 const unsigned char *pwd, int pwdlen )71 const unsigned char *pwd, size_t pwdlen ) 73 72 { 74 73 md5_context md5_ctx; 75 74 unsigned char md5sum[16]; 76 int use_len;75 size_t use_len; 77 76 78 77 /* … … 119 118 */ 120 119 static void pem_des_decrypt( unsigned char des_iv[8], 121 unsigned char *buf, int buflen,122 const unsigned char *pwd, int pwdlen )120 unsigned char *buf, size_t buflen, 121 const unsigned char *pwd, size_t pwdlen ) 123 122 { 124 123 des_context des_ctx; … … 139 138 */ 140 139 static void pem_des3_decrypt( unsigned char des3_iv[8], 141 unsigned char *buf, int buflen,142 const unsigned char *pwd, int pwdlen )140 unsigned char *buf, size_t buflen, 141 const unsigned char *pwd, size_t pwdlen ) 143 142 { 144 143 des3_context des3_ctx; … … 160 159 * Decrypt with AES-XXX-CBC, using PBKDF1 for key derivation 161 160 */ 162 static void pem_aes_decrypt( unsigned char aes_iv[16], int keylen,163 unsigned char *buf, int buflen,164 const unsigned char *pwd, int pwdlen )161 static void pem_aes_decrypt( unsigned char aes_iv[16], unsigned int keylen, 162 unsigned char *buf, size_t buflen, 163 const unsigned char *pwd, size_t pwdlen ) 165 164 { 166 165 aes_context aes_ctx; … … 180 179 #endif /* POLARSSL_MD5_C && (POLARSSL_AES_C || POLARSSL_DES_C) */ 181 180 182 int pem_read_buffer( pem_context *ctx, char *header, char *footer, const unsigned char *data, const unsigned char *pwd, int pwdlen, int *use_len ) 183 { 184 int ret, len, enc; 181 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 ) 182 { 183 int ret, enc; 184 size_t len; 185 185 unsigned char *buf; 186 186 unsigned char *s1, *s2; -
trunk/library/pkcs11.c
r932 r1014 33 33 34 34 #include <stdlib.h> 35 #include <string.h>36 35 37 36 int pkcs11_x509_cert_init( x509_cert *cert, pkcs11h_certificate_t pkcs11_cert ) … … 114 113 115 114 int pkcs11_decrypt( pkcs11_context *ctx, 116 int mode, int *olen,115 int mode, size_t *olen, 117 116 const unsigned char *input, 118 117 unsigned char *output, … … 154 153 int mode, 155 154 int hash_id, 156 int hashlen,155 unsigned int hashlen, 157 156 const unsigned char *hash, 158 157 unsigned char *sig ) -
trunk/library/rsa.c
r999 r1014 38 38 39 39 #include <stdlib.h> 40 #include <string.h>41 40 #include <stdio.h> 42 41 … … 62 61 int (*f_rng)(void *), 63 62 void *p_rng, 64 int nbits, int exponent )63 unsigned int nbits, int exponent ) 65 64 { 66 65 int ret; … … 207 206 unsigned char *output ) 208 207 { 209 int ret, olen; 208 int ret; 209 size_t olen; 210 210 mpi T; 211 211 … … 241 241 unsigned char *output ) 242 242 { 243 int ret, olen; 243 int ret; 244 size_t olen; 244 245 mpi T, T1, T2; 245 246 … … 302 303 * @param slen length of the source buffer 303 304 * @param md_ctx message digest context to use 304 * @param hlen length of the digest result 305 */ 306 static void mgf_mask( unsigned char *dst, int dlen, unsigned char *src, int slen, 305 */ 306 static void mgf_mask( unsigned char *dst, size_t dlen, unsigned char *src, size_t slen, 307 307 md_context_t *md_ctx ) 308 308 { … … 310 310 unsigned char counter[4]; 311 311 unsigned char *p; 312 int i, use_len, hlen; 312 unsigned int hlen; 313 size_t i, use_len; 313 314 314 315 memset( mask, 0, POLARSSL_MD_MAX_SIZE ); … … 348 349 int (*f_rng)(void *), 349 350 void *p_rng, 350 int mode, intilen,351 int mode, size_t ilen, 351 352 const unsigned char *input, 352 353 unsigned char *output ) 353 354 { 354 int nb_pad, olen;355 size_t nb_pad, olen; 355 356 unsigned char *p = output; 356 357 #if defined(POLARSSL_PKCS1_V21) 358 unsigned int i, hlen; 357 359 const md_info_t *md_info; 358 360 md_context_t md_ctx; 359 int i, hlen;360 361 #endif 361 362 … … 369 370 case RSA_PKCS_V15: 370 371 371 if( ilen < 0 ||olen < ilen + 11 )372 if( olen < ilen + 11 ) 372 373 return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); 373 374 … … 405 406 hlen = md_get_size( md_info ); 406 407 407 if( ilen < 0 ||olen < ilen + 2 * hlen + 2 || f_rng == NULL )408 if( olen < ilen + 2 * hlen + 2 || f_rng == NULL ) 408 409 return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); 409 410 … … 454 455 */ 455 456 int rsa_pkcs1_decrypt( rsa_context *ctx, 456 int mode, int *olen,457 int mode, size_t *olen, 457 458 const unsigned char *input, 458 459 unsigned char *output, 459 int output_max_len) 460 { 461 int ret, ilen; 460 size_t output_max_len) 461 { 462 int ret; 463 size_t ilen; 462 464 unsigned char *p; 463 465 unsigned char buf[1024]; 464 466 #if defined(POLARSSL_PKCS1_V21) 465 467 unsigned char lhash[POLARSSL_MD_MAX_SIZE]; 468 unsigned int hlen; 466 469 const md_info_t *md_info; 467 470 md_context_t md_ctx; 468 int hlen;469 471 #endif 470 472 … … 555 557 556 558 if (ilen - (int)(p - buf) > output_max_len) 557 return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );559 return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE ); 558 560 559 561 *olen = ilen - (int)(p - buf); … … 571 573 int mode, 572 574 int hash_id, 573 int hashlen,575 unsigned int hashlen, 574 576 const unsigned char *hash, 575 577 unsigned char *sig ) 576 578 { 577 int nb_pad, olen;579 size_t nb_pad, olen; 578 580 unsigned char *p = sig; 579 581 #if defined(POLARSSL_PKCS1_V21) 580 582 unsigned char salt[POLARSSL_MD_MAX_SIZE]; 583 unsigned int i, slen, hlen, offset = 0; 584 size_t msb; 581 585 const md_info_t *md_info; 582 586 md_context_t md_ctx; 583 int i, slen, hlen, msb, offset = 0;584 587 #else 585 588 (void) f_rng; … … 797 800 int mode, 798 801 int hash_id, 799 int hashlen,802 unsigned int hashlen, 800 803 const unsigned char *hash, 801 804 unsigned char *sig ) 802 805 { 803 int ret, len, siglen; 806 int ret; 807 size_t len, siglen; 804 808 unsigned char *p, c; 805 809 unsigned char buf[1024]; 806 810 #if defined(POLARSSL_PKCS1_V21) 807 811 unsigned char zeros[8]; 812 unsigned int hlen; 813 size_t slen, msb; 808 814 const md_info_t *md_info; 809 815 md_context_t md_ctx; 810 int slen, hlen, msb;811 816 #endif 812 817 siglen = ctx->len; … … 1079 1084 int rsa_self_test( int verbose ) 1080 1085 { 1081 int len;1086 size_t len; 1082 1087 rsa_context rsa; 1083 1088 unsigned char sha1sum[20]; … … 1129 1134 if( rsa_pkcs1_decrypt( &rsa, RSA_PRIVATE, &len, 1130 1135 rsa_ciphertext, rsa_decrypted, 1131 sizeof(rsa_decrypted) ) != 0 )1136 sizeof(rsa_decrypted) ) != 0 ) 1132 1137 { 1133 1138 if( verbose != 0 ) -
trunk/library/sha1.c
r897 r1014 35 35 #include "polarssl/sha1.h" 36 36 37 #include <string.h>38 37 #include <stdio.h> 39 38 … … 235 234 * SHA-1 process buffer 236 235 */ 237 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )238 { 239 int fill;236 void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen ) 237 { 238 size_t fill; 240 239 unsigned long left; 241 240 … … 246 245 fill = 64 - left; 247 246 248 ctx->total[0] += ilen;247 ctx->total[0] += (unsigned long) ilen; 249 248 ctx->total[0] &= 0xFFFFFFFF; 250 249 … … 316 315 * output = SHA-1( input buffer ) 317 316 */ 318 void sha1( const unsigned char *input, int ilen, unsigned char output[20] )317 void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ) 319 318 { 320 319 sha1_context ctx; … … 362 361 * SHA-1 HMAC context setup 363 362 */ 364 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen )365 { 366 int i;363 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen ) 364 { 365 size_t i; 367 366 unsigned char sum[20]; 368 367 … … 392 391 * SHA-1 HMAC process buffer 393 392 */ 394 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen )393 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen ) 395 394 { 396 395 sha1_update( ctx, input, ilen ); … … 425 424 * output = HMAC-SHA-1( hmac key, input buffer ) 426 425 */ 427 void sha1_hmac( const unsigned char *key, int keylen,428 const unsigned char *input, int ilen,426 void sha1_hmac( const unsigned char *key, size_t keylen, 427 const unsigned char *input, size_t ilen, 429 428 unsigned char output[20] ) 430 429 { -
trunk/library/sha2.c
r897 r1014 35 35 #include "polarssl/sha2.h" 36 36 37 #include <string.h>38 37 #include <stdio.h> 39 38 … … 231 230 * SHA-256 process buffer 232 231 */ 233 void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen )234 { 235 int fill;232 void sha2_update( sha2_context *ctx, const unsigned char *input, size_t ilen ) 233 { 234 size_t fill; 236 235 unsigned long left; 237 236 … … 242 241 fill = 64 - left; 243 242 244 ctx->total[0] += ilen;243 ctx->total[0] += (unsigned long) ilen; 245 244 ctx->total[0] &= 0xFFFFFFFF; 246 245 … … 317 316 * output = SHA-256( input buffer ) 318 317 */ 319 void sha2( const unsigned char *input, int ilen,318 void sha2( const unsigned char *input, size_t ilen, 320 319 unsigned char output[32], int is224 ) 321 320 { … … 364 363 * SHA-256 HMAC context setup 365 364 */ 366 void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, int keylen,365 void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, size_t keylen, 367 366 int is224 ) 368 367 { 369 int i;368 size_t i; 370 369 unsigned char sum[32]; 371 370 … … 395 394 * SHA-256 HMAC process buffer 396 395 */ 397 void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, int ilen )396 void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, size_t ilen ) 398 397 { 399 398 sha2_update( ctx, input, ilen ); … … 432 431 * output = HMAC-SHA-256( hmac key, input buffer ) 433 432 */ 434 void sha2_hmac( const unsigned char *key, int keylen,435 const unsigned char *input, int ilen,433 void sha2_hmac( const unsigned char *key, size_t keylen, 434 const unsigned char *input, size_t ilen, 436 435 unsigned char output[32], int is224 ) 437 436 { -
trunk/library/sha4.c
r897 r1014 35 35 #include "polarssl/sha4.h" 36 36 37 #include <string.h>38 37 #include <stdio.h> 39 38 … … 224 223 * SHA-512 process buffer 225 224 */ 226 void sha4_update( sha4_context *ctx, const unsigned char *input, int ilen )227 { 228 int fill;225 void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen ) 226 { 227 size_t fill; 229 228 unsigned int64 left; 230 229 … … 235 234 fill = (int)( 128 - left ); 236 235 237 ctx->total[0] += ilen;236 ctx->total[0] += (unsigned int64) ilen; 238 237 239 238 if( ctx->total[0] < (unsigned int64) ilen ) … … 315 314 * output = SHA-512( input buffer ) 316 315 */ 317 void sha4( const unsigned char *input, int ilen,316 void sha4( const unsigned char *input, size_t ilen, 318 317 unsigned char output[64], int is384 ) 319 318 { … … 362 361 * SHA-512 HMAC context setup 363 362 */ 364 void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, int keylen,363 void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, size_t keylen, 365 364 int is384 ) 366 365 { 367 int i;366 size_t i; 368 367 unsigned char sum[64]; 369 368 … … 394 393 */ 395 394 void sha4_hmac_update( sha4_context *ctx, 396 const unsigned char *input, int ilen )395 const unsigned char *input, size_t ilen ) 397 396 { 398 397 sha4_update( ctx, input, ilen ); … … 431 430 * output = HMAC-SHA-512( hmac key, input buffer ) 432 431 */ 433 void sha4_hmac( const unsigned char *key, int keylen,434 const unsigned char *input, int ilen,432 void sha4_hmac( const unsigned char *key, size_t keylen, 433 const unsigned char *input, size_t ilen, 435 434 unsigned char output[64], int is384 ) 436 435 { -
trunk/library/ssl_cli.c
r1003 r1014 35 35 #endif /* defined(POLARSSL_PKCS11_C) */ 36 36 37 #include <string.h>38 37 #include <stdlib.h> 39 38 #include <stdio.h> … … 42 41 static int ssl_write_client_hello( ssl_context *ssl ) 43 42 { 44 int ret, i, n; 43 int ret; 44 size_t i, n; 45 45 unsigned char *buf; 46 46 unsigned char *p; … … 175 175 { 176 176 time_t t; 177 int ret, i, n; 177 int ret, i; 178 size_t n; 178 179 int ext_len; 179 180 unsigned char *buf; … … 241 242 * 44+n . 44+n+m extensions 242 243 */ 243 if( n < 0 || n> 32 || ssl->in_hslen > 42 + n )244 if( n > 32 || ssl->in_hslen > 42 + n ) 244 245 { 245 246 ext_len = ( ( buf[42 + n] << 8 ) … … 251 252 } 252 253 253 if( n < 0 || n> 32 || ssl->in_hslen != 42 + n + ext_len )254 if( n > 32 || ssl->in_hslen != 42 + n + ext_len ) 254 255 { 255 256 SSL_DEBUG_MSG( 1, ( "bad server hello message" ) ); … … 322 323 static int ssl_parse_server_key_exchange( ssl_context *ssl ) 323 324 { 324 int ret, n; 325 int ret; 326 size_t n; 325 327 unsigned char *p, *end; 326 328 unsigned char hash[36]; … … 334 336 ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA && 335 337 ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA && 336 ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA)338 ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA) 337 339 { 338 340 SSL_DEBUG_MSG( 2, ( "<= skip parse server key exchange" ) ); … … 381 383 } 382 384 383 if( ( int)( end - p ) != ssl->peer_cert->rsa.len )385 if( (unsigned int)( end - p ) != ssl->peer_cert->rsa.len ) 384 386 { 385 387 SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) ); … … 519 521 static int ssl_write_client_key_exchange( ssl_context *ssl ) 520 522 { 521 int ret, i, n; 523 int ret; 524 size_t i, n; 522 525 523 526 SSL_DEBUG_MSG( 2, ( "=> write client key exchange" ) ); … … 527 530 ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA || 528 531 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA || 529 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA)532 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA) 530 533 { 531 534 #if !defined(POLARSSL_DHM_C) … … 626 629 static int ssl_write_certificate_verify( ssl_context *ssl ) 627 630 { 628 int ret = 0, n = 0; 631 int ret = 0; 632 size_t n = 0; 629 633 unsigned char hash[36]; 630 634 -
trunk/library/ssl_srv.c
r1003 r1014 35 35 #endif /* defined(POLARSSL_PKCS11_C) */ 36 36 37 #include <string.h>38 37 #include <stdlib.h> 39 38 #include <stdio.h> … … 42 41 static int ssl_parse_client_hello( ssl_context *ssl ) 43 42 { 44 int ret, i, j, n; 45 int ciph_len, sess_len; 46 int chal_len, comp_len; 43 int ret; 44 unsigned int i, j; 45 size_t n; 46 unsigned int ciph_len, sess_len; 47 unsigned int chal_len, comp_len; 47 48 unsigned char *buf, *p; 48 49 … … 138 139 } 139 140 140 if( sess_len < 0 || sess_len> 32 )141 if( sess_len > 32 ) 141 142 { 142 143 SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); … … 274 275 * Check the handshake message length 275 276 */ 276 if( buf[1] != 0 || n != 4 + ( ( buf[2] << 8 ) | buf[3] ) )277 if( buf[1] != 0 || n != (unsigned int) 4 + ( ( buf[2] << 8 ) | buf[3] ) ) 277 278 { 278 279 SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); … … 285 286 sess_len = buf[38]; 286 287 287 if( sess_len < 0 || sess_len> 32 )288 if( sess_len > 32 ) 288 289 { 289 290 SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); … … 461 462 static int ssl_write_certificate_request( ssl_context *ssl ) 462 463 { 463 int ret, n; 464 int ret; 465 size_t n; 464 466 unsigned char *buf, *p; 465 467 const x509_cert *crt; … … 526 528 static int ssl_write_server_key_exchange( ssl_context *ssl ) 527 529 { 528 int ret, n, rsa_key_len = 0; 530 int ret; 531 size_t n, rsa_key_len = 0; 529 532 unsigned char hash[36]; 530 533 md5_context md5; … … 537 540 ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA && 538 541 ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_128_SHA && 539 ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA)542 ssl->session->ciphersuite != SSL_EDH_RSA_CAMELLIA_256_SHA) 540 543 { 541 544 SSL_DEBUG_MSG( 2, ( "<= skip write server key exchange" ) ); … … 682 685 static int ssl_parse_client_key_exchange( ssl_context *ssl ) 683 686 { 684 int ret, i, n = 0; 687 int ret; 688 size_t i, n = 0; 685 689 686 690 SSL_DEBUG_MSG( 2, ( "=> parse client key exchange" ) ); … … 708 712 ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA || 709 713 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA || 710 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA)714 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA) 711 715 { 712 716 #if !defined(POLARSSL_DHM_C) … … 841 845 static int ssl_parse_certificate_verify( ssl_context *ssl ) 842 846 { 843 int n1, n2, ret; 847 int ret; 848 size_t n1, n2; 844 849 unsigned char hash[36]; 845 850 -
trunk/library/ssl_tls.c
r1008 r1014 43 43 #include "polarssl/ssl.h" 44 44 45 #include <string.h>46 45 #include <stdlib.h> 47 46 #include <time.h> … … 54 53 * Key material generation 55 54 */ 56 static int tls1_prf( unsigned char *secret, int slen, char *label,57 unsigned char *random, int rlen,58 unsigned char *dstbuf, int dlen )59 { 60 int nb, hs;61 int i, j, k;55 static int tls1_prf( unsigned char *secret, size_t slen, char *label, 56 unsigned char *random, size_t rlen, 57 unsigned char *dstbuf, size_t dlen ) 58 { 59 size_t nb, hs; 60 size_t i, j, k; 62 61 unsigned char *S1, *S2; 63 62 unsigned char tmp[128]; … … 140 139 if( ssl->resume == 0 ) 141 140 { 142 int len = ssl->pmslen;141 size_t len = ssl->pmslen; 143 142 144 143 SSL_DEBUG_BUF( 3, "premaster secret", ssl->premaster, len ); … … 432 431 */ 433 432 static void ssl_mac_md5( unsigned char *secret, 434 unsigned char *buf, int len,433 unsigned char *buf, size_t len, 435 434 unsigned char *ctr, int type ) 436 435 { … … 461 460 462 461 static void ssl_mac_sha1( unsigned char *secret, 463 unsigned char *buf, int len,462 unsigned char *buf, size_t len, 464 463 unsigned char *ctr, int type ) 465 464 { … … 494 493 static int ssl_encrypt_buf( ssl_context *ssl ) 495 494 { 496 int i, padlen;495 size_t i, padlen; 497 496 498 497 SSL_DEBUG_MSG( 2, ( "=> encrypt buf" ) ); … … 531 530 ssl->out_msglen += ssl->maclen; 532 531 533 for( i = 7; i >=0; i-- )534 if( ++ssl->out_ctr[i ] != 0 )532 for( i = 8; i > 0; i-- ) 533 if( ++ssl->out_ctr[i - 1] != 0 ) 535 534 break; 536 535 … … 557 556 { 558 557 unsigned char *enc_msg; 559 int enc_msglen;558 size_t enc_msglen; 560 559 561 560 padlen = ssl->ivlen - ( ssl->out_msglen + 1 ) % ssl->ivlen; … … 616 615 case 16: 617 616 #if defined(POLARSSL_AES_C) 618 if ( ssl->session->ciphersuite == SSL_RSA_AES_128_SHA ||619 ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA ||620 ssl->session->ciphersuite == SSL_RSA_AES_256_SHA ||621 ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA)622 {617 if ( ssl->session->ciphersuite == SSL_RSA_AES_128_SHA || 618 ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA || 619 ssl->session->ciphersuite == SSL_RSA_AES_256_SHA || 620 ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA) 621 { 623 622 aes_crypt_cbc( (aes_context *) ssl->ctx_enc, 624 623 AES_ENCRYPT, enc_msglen, 625 624 ssl->iv_enc, enc_msg, enc_msg); 626 625 break; 627 }626 } 628 627 #endif 629 628 630 629 #if defined(POLARSSL_CAMELLIA_C) 631 if ( ssl->session->ciphersuite == SSL_RSA_CAMELLIA_128_SHA ||632 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA ||633 ssl->session->ciphersuite == SSL_RSA_CAMELLIA_256_SHA ||634 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA)635 {630 if ( ssl->session->ciphersuite == SSL_RSA_CAMELLIA_128_SHA || 631 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA || 632 ssl->session->ciphersuite == SSL_RSA_CAMELLIA_256_SHA || 633 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA) 634 { 636 635 camellia_crypt_cbc( (camellia_context *) ssl->ctx_enc, 637 636 CAMELLIA_ENCRYPT, enc_msglen, 638 637 ssl->iv_enc, enc_msg, enc_msg ); 639 638 break; 640 }639 } 641 640 #endif 642 641 … … 653 652 static int ssl_decrypt_buf( ssl_context *ssl ) 654 653 { 655 int i, padlen;654 size_t i, padlen; 656 655 unsigned char tmp[20]; 657 656 … … 680 679 unsigned char *dec_msg; 681 680 unsigned char *dec_msg_result; 682 int dec_msglen;681 size_t dec_msglen; 683 682 684 683 /* … … 721 720 case 16: 722 721 #if defined(POLARSSL_AES_C) 723 if ( ssl->session->ciphersuite == SSL_RSA_AES_128_SHA ||724 ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA ||725 ssl->session->ciphersuite == SSL_RSA_AES_256_SHA ||726 ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA)727 {722 if ( ssl->session->ciphersuite == SSL_RSA_AES_128_SHA || 723 ssl->session->ciphersuite == SSL_EDH_RSA_AES_128_SHA || 724 ssl->session->ciphersuite == SSL_RSA_AES_256_SHA || 725 ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA) 726 { 728 727 aes_crypt_cbc( (aes_context *) ssl->ctx_dec, 729 728 AES_DECRYPT, dec_msglen, 730 729 ssl->iv_dec, dec_msg, dec_msg_result ); 731 730 break; 732 }731 } 733 732 #endif 734 733 735 734 #if defined(POLARSSL_CAMELLIA_C) 736 if ( ssl->session->ciphersuite == SSL_RSA_CAMELLIA_128_SHA ||737 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA ||738 ssl->session->ciphersuite == SSL_RSA_CAMELLIA_256_SHA ||739 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA)740 {735 if ( ssl->session->ciphersuite == SSL_RSA_CAMELLIA_128_SHA || 736 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_128_SHA || 737 ssl->session->ciphersuite == SSL_RSA_CAMELLIA_256_SHA || 738 ssl->session->ciphersuite == SSL_EDH_RSA_CAMELLIA_256_SHA) 739 { 741 740 camellia_crypt_cbc( (camellia_context *) ssl->ctx_dec, 742 741 CAMELLIA_DECRYPT, dec_msglen, 743 742 ssl->iv_dec, dec_msg, dec_msg_result ); 744 743 break; 745 }744 } 746 745 #endif 747 746 … … 852 851 ssl->nb_zero = 0; 853 852 854 for( i = 7; i >=0; i-- )855 if( ++ssl->in_ctr[i ] != 0 )853 for( i = 8; i > 0; i-- ) 854 if( ++ssl->in_ctr[i - 1] != 0 ) 856 855 break; 857 856 … … 864 863 * Fill the input message buffer 865 864 */ 866 int ssl_fetch_input( ssl_context *ssl, int nb_want ) 867 { 868 int ret, len; 865 int ssl_fetch_input( ssl_context *ssl, size_t nb_want ) 866 { 867 int ret; 868 size_t len; 869 869 870 870 SSL_DEBUG_MSG( 2, ( "=> fetch input" ) ); … … 925 925 int ssl_write_record( ssl_context *ssl ) 926 926 { 927 int ret, len = ssl->out_msglen; 927 int ret; 928 size_t len = ssl->out_msglen; 928 929 929 930 SSL_DEBUG_MSG( 2, ( "=> write record" ) ); … … 1182 1183 int ssl_write_certificate( ssl_context *ssl ) 1183 1184 { 1184 int ret, i, n; 1185 int ret; 1186 size_t i, n; 1185 1187 const x509_cert *crt; 1186 1188 … … 1278 1280 int ssl_parse_certificate( ssl_context *ssl ) 1279 1281 { 1280 int ret, i, n; 1282 int ret; 1283 size_t i, n; 1281 1284 1282 1285 SSL_DEBUG_MSG( 2, ( "=> parse certificate" ) ); … … 1622 1625 int ssl_parse_finished( ssl_context *ssl ) 1623 1626 { 1624 int ret, hash_len; 1625 md5_context md5; 1627 int ret; 1628 unsigned int hash_len; 1629 unsigned char buf[36]; 1630 md5_context md5; 1626 1631 sha1_context sha1; 1627 unsigned char buf[36];1628 1632 1629 1633 SSL_DEBUG_MSG( 2, ( "=> parse finished" ) ); … … 1759 1763 1760 1764 void ssl_set_bio( ssl_context *ssl, 1761 int (*f_recv)(void *, unsigned char *, int), void *p_recv,1762 int (*f_send)(void *, unsigned char *, int), void *p_send )1765 int (*f_recv)(void *, unsigned char *, size_t), void *p_recv, 1766 int (*f_send)(void *, unsigned char *, size_t), void *p_send ) 1763 1767 { 1764 1768 ssl->f_recv = f_recv; … … 1870 1874 * SSL get accessors 1871 1875 */ 1872 int ssl_get_bytes_avail( const ssl_context *ssl )1876 size_t ssl_get_bytes_avail( const ssl_context *ssl ) 1873 1877 { 1874 1878 return( ssl->in_offt == NULL ? 0 : ssl->in_msglen ); … … 2065 2069 * Receive application data decrypted from the SSL layer 2066 2070 */ 2067 int ssl_read( ssl_context *ssl, unsigned char *buf, int len ) 2068 { 2069 int ret, n; 2071 int ssl_read( ssl_context *ssl, unsigned char *buf, size_t len ) 2072 { 2073 int ret; 2074 size_t n; 2070 2075 2071 2076 SSL_DEBUG_MSG( 2, ( "=> read" ) ); … … 2125 2130 SSL_DEBUG_MSG( 2, ( "<= read" ) ); 2126 2131 2127 return( n );2132 return( (int) n ); 2128 2133 } 2129 2134 … … 2131 2136 * Send application data to be encrypted by the SSL layer 2132 2137 */ 2133 int ssl_write( ssl_context *ssl, const unsigned char *buf, int len ) 2134 { 2135 int ret, n; 2138 int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len ) 2139 { 2140 int ret; 2141 size_t n; 2136 2142 2137 2143 SSL_DEBUG_MSG( 2, ( "=> write" ) ); … … 2170 2176 SSL_DEBUG_MSG( 2, ( "<= write" ) ); 2171 2177 2172 return( n );2178 return( (int) n ); 2173 2179 } 2174 2180 -
trunk/library/x509parse.c
r1006 r1014 60 60 static int asn1_get_len( unsigned char **p, 61 61 const unsigned char *end, 62 int *len )62 size_t *len ) 63 63 { 64 64 if( ( end - *p ) < 1 ) … … 93 93 } 94 94 95 if( *len > ( int) ( end - *p ) )95 if( *len > (size_t) ( end - *p ) ) 96 96 return( POLARSSL_ERR_ASN1_OUT_OF_DATA ); 97 97 … … 101 101 static int asn1_get_tag( unsigned char **p, 102 102 const unsigned char *end, 103 int *len, int tag )103 size_t *len, int tag ) 104 104 { 105 105 if( ( end - *p ) < 1 ) … … 118 118 int *val ) 119 119 { 120 int ret, len; 120 int ret; 121 size_t len; 121 122 122 123 if( ( ret = asn1_get_tag( p, end, &len, ASN1_BOOLEAN ) ) != 0 ) … … 136 137 int *val ) 137 138 { 138 int ret, len; 139 int ret; 140 size_t len; 139 141 140 142 if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 ) … … 159 161 mpi *X ) 160 162 { 161 int ret, len; 163 int ret; 164 size_t len; 162 165 163 166 if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 ) … … 210 213 int tag) 211 214 { 212 int ret, len; 215 int ret; 216 size_t len; 213 217 x509_buf *buf; 214 218 … … 261 265 int *ver ) 262 266 { 263 int ret, len; 267 int ret; 268 size_t len; 264 269 265 270 if( ( ret = asn1_get_tag( p, end, &len, … … 322 327 x509_buf *alg ) 323 328 { 324 int ret, len; 329 int ret; 330 size_t len; 325 331 326 332 if( ( ret = asn1_get_tag( p, end, &len, … … 366 372 x509_name *cur ) 367 373 { 368 int ret, len; 374 int ret; 375 size_t len; 369 376 x509_buf *oid; 370 377 x509_buf *val; … … 423 430 x509_name *cur ) 424 431 { 425 int ret, len; 432 int ret; 433 size_t len; 426 434 const unsigned char *end2; 427 435 x509_name *use; … … 479 487 x509_time *time ) 480 488 { 481 int ret, len; 489 int ret; 490 size_t len; 482 491 char date[64]; 483 492 unsigned char tag; … … 548 557 x509_time *to ) 549 558 { 550 int ret, len; 559 int ret; 560 size_t len; 551 561 552 562 if( ( ret = asn1_get_tag( p, end, &len, … … 579 589 mpi *N, mpi *E ) 580 590 { 581 int ret, len, can_handle; 591 int ret, can_handle; 592 size_t len; 582 593 unsigned char *end2; 583 594 … … 652 663 x509_buf *sig ) 653 664 { 654 int ret, len; 665 int ret; 666 size_t len; 655 667 656 668 sig->tag = **p; … … 708 720 x509_buf *ext ) 709 721 { 710 int ret, len; 722 int ret; 723 size_t len; 711 724 712 725 if( *p == end ) … … 748 761 x509_buf *ext ) 749 762 { 750 int ret, len; 763 int ret; 764 size_t len; 751 765 752 766 if( ( ret = x509_get_ext( p, end, ext ) ) != 0 ) … … 779 793 int *max_pathlen ) 780 794 { 781 int ret, len; 795 int ret; 796 size_t len; 782 797 783 798 /* … … 894 909 x509_cert *crt ) 895 910 { 896 int ret, len; 911 int ret; 912 size_t len; 897 913 unsigned char *end_ext_data, *end_ext_octet; 898 914 … … 1018 1034 x509_crl_entry *entry ) 1019 1035 { 1020 int ret, entry_len; 1036 int ret; 1037 size_t entry_len; 1021 1038 x509_crl_entry *cur_entry = entry; 1022 1039 … … 1037 1054 while( *p < end ) 1038 1055 { 1039 int len2;1056 size_t len2; 1040 1057 1041 1058 if( ( ret = asn1_get_tag( p, end, &len2, … … 1101 1118 * Parse one or more certificates and add them to the chained list 1102 1119 */ 1103 int x509parse_crt( x509_cert *chain, const unsigned char *buf, int buflen ) 1104 { 1105 int ret, len, use_len; 1120 int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen ) 1121 { 1122 int ret; 1123 size_t len, use_len; 1106 1124 unsigned char *p, *end; 1107 1125 x509_cert *crt; … … 1208 1226 } 1209 1227 1210 if( len != ( int) ( end - p ) )1228 if( len != (size_t) ( end - p ) ) 1211 1229 { 1212 1230 x509_free( crt ); … … 1437 1455 * Parse one or more CRLs and add them to the chained list 1438 1456 */ 1439 int x509parse_crl( x509_crl *chain, const unsigned char *buf, int buflen ) 1440 { 1441 int ret, len, use_len; 1457 int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen ) 1458 { 1459 int ret; 1460 size_t len, use_len; 1442 1461 unsigned char *p, *end; 1443 1462 x509_crl *crl; … … 1544 1563 } 1545 1564 1546 if( len != ( int) ( end - p ) )1565 if( len != (size_t) ( end - p ) ) 1547 1566 { 1548 1567 x509_crl_free( crl ); … … 1795 1814 * Parse a private RSA key 1796 1815 */ 1797 int x509parse_key( rsa_context *rsa, const unsigned char *key, int keylen, 1798 const unsigned char *pwd, int pwdlen ) 1799 { 1800 int ret, len; 1816 int x509parse_key( rsa_context *rsa, const unsigned char *key, size_t keylen, 1817 const unsigned char *pwd, size_t pwdlen ) 1818 { 1819 int ret; 1820 size_t len; 1801 1821 unsigned char *p, *end; 1802 1822 #if defined(POLARSSL_PEM_C) … … 1943 1963 * Parse a public RSA key 1944 1964 */ 1945 int x509parse_public_key( rsa_context *rsa, const unsigned char *key, int keylen ) 1946 { 1947 int ret, len; 1965 int x509parse_public_key( rsa_context *rsa, const unsigned char *key, size_t keylen ) 1966 { 1967 int ret; 1968 size_t len; 1948 1969 unsigned char *p, *end; 1949 1970 x509_buf alg_oid; … … 2054 2075 * Parse DHM parameters 2055 2076 */ 2056 int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, int dhminlen ) 2057 { 2058 int ret, len; 2077 int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen ) 2078 { 2079 int ret; 2080 size_t len; 2059 2081 unsigned char *p, *end; 2060 2082 #if defined(POLARSSL_PEM_C) … … 2181 2203 // No quick fix possible 2182 2204 if ( res < 0 ) 2183 return( size + 20 );2205 return( (int) size + 20 ); 2184 2206 2185 2207 return res; … … 2196 2218 return( -1 ); \ 2197 2219 \ 2198 if ( ret > n ) {\2220 if ( (unsigned int) ret > n ) { \ 2199 2221 p[n - 1] = '\0'; \ 2200 2222 return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;\ 2201 2223 } \ 2202 2224 \ 2203 n -= ret;\2204 p += ret;\2225 n -= (unsigned int) ret; \ 2226 p += (unsigned int) ret; \ 2205 2227 } 2206 2228 … … 2211 2233 int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn ) 2212 2234 { 2213 int i, ret, n; 2235 int ret; 2236 size_t i, n; 2214 2237 unsigned char c; 2215 2238 const x509_name *name; … … 2295 2318 } 2296 2319 2297 return( size - n);2320 return( (int) ( size - n ) ); 2298 2321 } 2299 2322 … … 2304 2327 int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial ) 2305 2328 { 2306 int i, ret, nr, n; 2329 int ret; 2330 size_t i, n, nr; 2307 2331 char *p; 2308 2332 … … 2320 2344 } 2321 2345 2322 return( size - n);2346 return( (int) ( size - n ) ); 2323 2347 } 2324 2348 … … 2329 2353 const x509_cert *crt ) 2330 2354 { 2331 int n, ret; 2355 int ret; 2356 size_t n; 2332 2357 char *p; 2333 2358 … … 2390 2415 SAFE_SNPRINTF(); 2391 2416 2392 return( size - n);2417 return( (int) ( size - n ) ); 2393 2418 } 2394 2419 … … 2430 2455 int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid ) 2431 2456 { 2432 int ret, n, i; 2457 int ret; 2458 size_t i, n; 2433 2459 unsigned int value; 2434 2460 char *p; … … 2446 2472 /* TODO: value can overflow in value. */ 2447 2473 value = 0; 2448 for( i =1; i < oid->len; i++ )2474 for( i = 1; i < oid->len; i++ ) 2449 2475 { 2450 2476 value <<= 7; … … 2460 2486 } 2461 2487 2462 return( size - n);2488 return( (int) ( size - n ) ); 2463 2489 } 2464 2490 … … 2469 2495 const x509_crl *crl ) 2470 2496 { 2471 int i, n, nr, ret; 2497 int ret; 2498 size_t i, n, nr; 2472 2499 char *p; 2473 2500 const x509_crl_entry *entry; … … 2551 2578 SAFE_SNPRINTF(); 2552 2579 2553 return( size - n);2580 return( (int) ( size - n ) ); 2554 2581 } 2555 2582 … … 2628 2655 * \param out Buffer to receive the hash (Should be at least 64 bytes) 2629 2656 */ 2630 static void x509_hash( const unsigned char *in, int len, int alg,2657 static void x509_hash( const unsigned char *in, size_t len, int alg, 2631 2658 unsigned char *out ) 2632 2659 { … … 2732 2759 void *p_vrfy ) 2733 2760 { 2734 int cn_len;2761 size_t cn_len; 2735 2762 int hash_id; 2736 2763 int pathlen; … … 3000 3027 { 3001 3028 #if defined(POLARSSL_MD5_C) 3002 int ret, i, j; 3029 int ret; 3030 int flags; 3031 size_t i, j; 3003 3032 x509_cert cacert; 3004 3033 x509_cert clicert; … … 3054 3083 printf( "passed\n X.509 signature verify: "); 3055 3084 3056 ret = x509parse_verify( &clicert, &cacert, NULL, "PolarSSL Client 2", & i, NULL, NULL );3085 ret = x509parse_verify( &clicert, &cacert, NULL, "PolarSSL Client 2", &flags, NULL, NULL ); 3057 3086 if( ret != 0 ) 3058 3087 { 3059 printf("%02x", i);3088 printf("%02x", flags); 3060 3089 if( verbose != 0 ) 3061 3090 printf( "failed\n" ); -
trunk/library/xtea.c
r1011 r1014 30 30 #include "polarssl/xtea.h" 31 31 32 #include <string.h>33 34 32 /* 35 33 * 32-bit integer manipulation macros (big endian) … … 39 37 { \ 40 38 (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ 41 | ( (unsigned long) (b)[(i) + 1] << 16 ) \42 | ( (unsigned long) (b)[(i) + 2] << 8 ) \43 | ( (unsigned long) (b)[(i) + 3] ); \39 | ( (unsigned long) (b)[(i) + 1] << 16 ) \ 40 | ( (unsigned long) (b)[(i) + 2] << 8 ) \ 41 | ( (unsigned long) (b)[(i) + 3] ); \ 44 42 } 45 43 #endif … … 66 64 for( i = 0; i < 4; i++ ) 67 65 { 68 GET_ULONG_BE( ctx->k[i], key, i << 2 );66 GET_ULONG_BE( ctx->k[i], key, i << 2 ); 69 67 } 70 68 } … … 85 83 if( mode == XTEA_ENCRYPT ) 86 84 { 87 uint32_t sum = 0, delta = 0x9E3779B9;88 89 for( i = 0; i < 32; i++ )90 {91 v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]);92 sum += delta;93 v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]);94 }85 uint32_t sum = 0, delta = 0x9E3779B9; 86 87 for( i = 0; i < 32; i++ ) 88 { 89 v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]); 90 sum += delta; 91 v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]); 92 } 95 93 } 96 94 else /* XTEA_DECRYPT */ 97 95 { 98 uint32_t delta = 0x9E3779B9, sum = delta * 32;99 100 for( i = 0; i < 32; i++ )101 {102 v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]);103 sum -= delta;104 v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]);105 }96 uint32_t delta = 0x9E3779B9, sum = delta * 32; 97 98 for( i = 0; i < 32; i++ ) 99 { 100 v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]); 101 sum -= delta; 102 v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]); 103 } 106 104 } 107 105 … … 117 115 int xtea_crypt_cbc( xtea_context *ctx, 118 116 int mode, 119 int length,117 size_t length, 120 118 unsigned char iv[8], 121 119 unsigned char *input, -
trunk/programs/aes/aescrypt2.c
r952 r1014 56 56 { 57 57 int ret = 1, i, n; 58 int keylen, mode, lastn; 58 int mode, lastn; 59 size_t keylen; 59 60 FILE *fkey, *fin = NULL, *fout = NULL; 60 61 -
trunk/programs/aes/crypt_and_hash.c
r952 r1014 57 57 { 58 58 int ret = 1, i, n; 59 int keylen, mode, lastn, olen; 59 int mode, lastn; 60 size_t keylen, olen; 60 61 FILE *fkey, *fin = NULL, *fout = NULL; 61 62 … … 292 293 { 293 294 n = ( filesize - offset > cipher_get_block_size( &cipher_ctx ) ) ? 294 cipher_get_block_size( &cipher_ctx ) : ( int) ( filesize - offset );295 cipher_get_block_size( &cipher_ctx ) : (unsigned int) ( filesize - offset ); 295 296 296 297 if( fread( buffer, 1, n, fin ) != (size_t) n ) -
trunk/programs/hash/generic_sum.c
r941 r1014 84 84 n = sizeof( line ); 85 85 86 while( fgets( line, n - 1, f ) != NULL )86 while( fgets( line, (int) n - 1, f ) != NULL ) 87 87 { 88 88 n = strlen( line ); -
trunk/programs/hash/md5sum.c
r897 r1014 84 84 n = sizeof( line ); 85 85 86 while( fgets( line, n - 1, f ) != NULL )86 while( fgets( line, (int) n - 1, f ) != NULL ) 87 87 { 88 88 n = strlen( line ); -
trunk/programs/hash/sha1sum.c
r897 r1014 84 84 n = sizeof( line ); 85 85 86 while( fgets( line, n - 1, f ) != NULL )86 while( fgets( line, (int) n - 1, f ) != NULL ) 87 87 { 88 88 n = strlen( line ); -
trunk/programs/hash/sha2sum.c
r897 r1014 84 84 n = sizeof( line ); 85 85 86 while( fgets( line, n - 1, f ) != NULL )86 while( fgets( line, (int) n - 1, f ) != NULL ) 87 87 { 88 88 n = strlen( line ); -
trunk/programs/pkey/dh_client.c
r902 r1014 45 45 FILE *f; 46 46 47 int ret, n, buflen; 47 int ret; 48 size_t n, buflen; 48 49 int server_fd = -1; 49 50 … … 124 125 125 126 n = buflen = ( buf[0] << 8 ) | buf[1]; 126 if( buflen < 1 || buflen > (int)sizeof( buf ) )127 if( buflen < 1 || buflen > sizeof( buf ) ) 127 128 { 128 129 printf( " failed\n ! Got an invalid buffer length\n\n" ); … … 135 136 memset( buf, 0, sizeof( buf ) ); 136 137 137 if( ( ret = net_recv( &server_fd, buf, n ) ) != n )138 if( ( ret = net_recv( &server_fd, buf, n ) ) != (int) n ) 138 139 { 139 140 printf( " failed\n ! net_recv returned %d\n\n", ret ); … … 163 164 fflush( stdout ); 164 165 165 if( ( n = ( int)( end - p ) ) != rsa.len )166 if( ( n = (size_t) ( end - p ) ) != rsa.len ) 166 167 { 167 168 ret = 1; … … 193 194 } 194 195 195 if( ( ret = net_send( &server_fd, buf, n ) ) != n )196 if( ( ret = net_send( &server_fd, buf, n ) ) != (int) n ) 196 197 { 197 198 printf( " failed\n ! net_send returned %d\n\n", ret ); -
trunk/programs/pkey/dh_server.c
r979 r1014 45 45 FILE *f; 46 46 47 int ret, n, buflen; 47 int ret; 48 size_t n, buflen; 48 49 int listen_fd = -1; 49 50 int client_fd = -1; … … 178 179 179 180 if( ( ret = net_send( &client_fd, buf2, 2 ) ) != 2 || 180 ( ret = net_send( &client_fd, buf, buflen ) ) != buflen )181 ( ret = net_send( &client_fd, buf, buflen ) ) != (int) buflen ) 181 182 { 182 183 printf( " failed\n ! net_send returned %d\n\n", ret ); … … 193 194 n = dhm.len; 194 195 195 if( ( ret = net_recv( &client_fd, buf, n ) ) != n )196 if( ( ret = net_recv( &client_fd, buf, n ) ) != (int) n ) 196 197 { 197 198 printf( " failed\n ! net_recv returned %d\n\n", ret ); -
trunk/programs/pkey/rsa_sign.c
r979 r1014 37 37 { 38 38 FILE *f; 39 int ret, i; 39 int ret; 40 size_t i; 40 41 rsa_context rsa; 41 42 unsigned char hash[20]; -
trunk/programs/pkey/rsa_verify.c
r902 r1014 37 37 { 38 38 FILE *f; 39 int ret, i, c; 39 int ret, c; 40 size_t i; 40 41 rsa_context rsa; 41 42 unsigned char hash[20]; -
trunk/programs/pkey/rsa_verify_pss.c
r1008 r1014 44 44 { 45 45 FILE *f; 46 int ret, i; 46 int ret; 47 size_t i; 47 48 rsa_context rsa; 48 49 unsigned char hash[20]; -
trunk/programs/ssl/ssl_client2.c
r962 r1014 93 93 x509_cert clicert; 94 94 rsa_context rsa; 95 int i, j, n; 95 int i; 96 size_t j, n; 96 97 char *p, *q; 97 98 const int *list; -
trunk/tests/suites/test_suite_cipher.function
r998 r1014 5 5 BEGIN_CASE 6 6 enc_dec_buf:cipher_id:cipher_string:key_len:length: 7 int length = {length};7 size_t length = {length}; 8 8 unsigned char key[32]; 9 9 unsigned char iv[16]; … … 17 17 unsigned char decbuf[64]; 18 18 19 int outlen = 0;20 int enclen = 0;19 size_t outlen = 0; 20 size_t enclen = 0; 21 21 22 22 memset( key, 0, 32 ); … … 108 108 BEGIN_CASE 109 109 enc_dec_buf_multipart:cipher_id:key_len:first_length:second_length: 110 int first_length = {first_length};111 int second_length = {second_length};112 int length = first_length + second_length;110 size_t first_length = {first_length}; 111 size_t second_length = {second_length}; 112 size_t length = first_length + second_length; 113 113 unsigned char key[32]; 114 114 unsigned char iv[16]; … … 122 122 unsigned char decbuf[64]; 123 123 124 int outlen = 0;125 int totaloutlen = 0;126 int enclen = 0;124 size_t outlen = 0; 125 size_t totaloutlen = 0; 126 size_t enclen = 0; 127 127 128 128 memset( key, 0, 32 );
Note: See TracChangeset
for help on using the changeset viewer.


