Changeset 1014


Ignore:
Timestamp:
04/24/11 10:57:21 (13 months ago)
Author:
paul
Message:
  • Major type rewrite of int to size_t for most variables and arguments used for buffer lengths and loops
Location:
trunk
Files:
67 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r1011 r1014  
    66     (AES CTR, Camellia CTR, XTEA CBC) including the option to 
    77         enable and disable individual modes when needed 
     8 
     9Changes 
     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 
    813 
    914= Version 0.99-pre4 released on 2011-04-01 
  • trunk/include/polarssl/aes.h

    r1011 r1014  
    2727#ifndef POLARSSL_AES_H 
    2828#define POLARSSL_AES_H 
     29 
     30#include <string.h> 
    2931 
    3032#define AES_ENCRYPT     1 
     
    5860 * \return         0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH 
    5961 */ 
    60 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize ); 
     62int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize ); 
    6163 
    6264/** 
     
    6971 * \return         0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH 
    7072 */ 
    71 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize ); 
     73int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int keysize ); 
    7274 
    7375/** 
     
    102104int aes_crypt_cbc( aes_context *ctx, 
    103105                    int mode, 
    104                     int length, 
     106                    size_t length, 
    105107                    unsigned char iv[16], 
    106108                    const unsigned char *input, 
     
    122124int aes_crypt_cfb128( aes_context *ctx, 
    123125                       int mode, 
    124                        int length, 
     126                       size_t length, 
    125127                       int *iv_off, 
    126128                       unsigned char iv[16], 
  • trunk/include/polarssl/arc4.h

    r913 r1014  
    2828#define POLARSSL_ARC4_H 
    2929 
     30#include <string.h> 
     31 
    3032/** 
    3133 * \brief          ARC4 context structure 
     
    5052 * \param keylen   length of the key 
    5153 */ 
    52 void arc4_setup( arc4_context *ctx, const unsigned char *key, int keylen ); 
     54void arc4_setup( arc4_context *ctx, const unsigned char *key, unsigned int keylen ); 
    5355 
    5456/** 
     
    6264 * \return         0 if successful 
    6365 */ 
    64 int arc4_crypt( arc4_context *ctx, int length, const unsigned char *input, 
     66int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input, 
    6567                unsigned char *output ); 
    6668 
  • trunk/include/polarssl/base64.h

    r913 r1014  
    2828#define POLARSSL_BASE64_H 
    2929 
     30#include <string.h> 
     31 
    3032#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL               0x0010 
    3133#define POLARSSL_ERR_BASE64_INVALID_CHARACTER              0x0012 
     
    5052 *                 required buffer size in *dlen 
    5153 */ 
    52 int base64_encode( unsigned char *dst, int *dlen, 
    53                    const unsigned char *src, int slen ); 
     54int base64_encode( unsigned char *dst, size_t *dlen, 
     55                   const unsigned char *src, size_t slen ); 
    5456 
    5557/** 
     
    6971 *                 required buffer size in *dlen 
    7072 */ 
    71 int base64_decode( unsigned char *dst, int *dlen, 
    72                    const unsigned char *src, int slen ); 
     73int base64_decode( unsigned char *dst, size_t *dlen, 
     74                   const unsigned char *src, size_t slen ); 
    7375 
    7476/** 
  • trunk/include/polarssl/bignum.h

    r997 r1014  
    2929 
    3030#include <stdio.h> 
     31#include <string.h> 
    3132 
    3233#define POLARSSL_ERR_MPI_FILE_IO_ERROR                     0x0002 
     
    4445 */ 
    4546#if defined(POLARSSL_HAVE_INT8) 
     47typedef signed char t_s_int; 
    4648typedef unsigned char  t_int; 
    4749typedef unsigned short t_dbl; 
    4850#else 
    4951#if defined(POLARSSL_HAVE_INT16) 
     52typedef signed short t_s_int; 
    5053typedef unsigned short t_int; 
    5154typedef unsigned long  t_dbl; 
    5255#else 
     56  typedef signed long t_s_int; 
    5357  typedef unsigned long t_int; 
    5458  #if defined(_MSC_VER) && defined(_M_IX86) 
     
    7478{ 
    7579    int s;              /*!<  integer sign      */ 
    76     int n;              /*!<  total # of limbs  */ 
     80    size_t n;           /*!<  total # of limbs  */ 
    7781    t_int *p;           /*!<  pointer to limbs  */ 
    7882} 
     
    102106 *                 1 if memory allocation failed 
    103107 */ 
    104 int mpi_grow( mpi *X, int nblimbs ); 
     108int mpi_grow( mpi *X, size_t nblimbs ); 
    105109 
    106110/** 
     
    132136 *                 1 if memory allocation failed 
    133137 */ 
    134 int mpi_lset( mpi *X, int z ); 
     138int mpi_lset( mpi *X, t_s_int z ); 
    135139 
    136140/** 
     
    139143 * \param X        MPI to use 
    140144 */ 
    141 int mpi_lsb( const mpi *X ); 
     145size_t mpi_lsb( const mpi *X ); 
    142146 
    143147/** 
     
    146150 * \param X        MPI to use 
    147151 */ 
    148 int mpi_msb( const mpi *X ); 
     152size_t mpi_msb( const mpi *X ); 
    149153 
    150154/** 
     
    153157 * \param X        MPI to use 
    154158 */ 
    155 int mpi_size( const mpi *X ); 
     159size_t mpi_size( const mpi *X ); 
    156160 
    157161/** 
     
    181185 *                 minimum required buffer size in *slen. 
    182186 */ 
    183 int mpi_write_string( const mpi *X, int radix, char *s, int *slen ); 
     187int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ); 
    184188 
    185189/** 
     
    218222 *                 1 if memory allocation failed 
    219223 */ 
    220 int mpi_read_binary( mpi *X, const unsigned char *buf, int buflen ); 
     224int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen ); 
    221225 
    222226/** 
     
    230234 *                 POLARSSL_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough 
    231235 */ 
    232 int mpi_write_binary( const mpi *X, unsigned char *buf, int buflen ); 
     236int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen ); 
    233237 
    234238/** 
     
    241245 *                 1 if memory allocation failed 
    242246 */ 
    243 int mpi_shift_l( mpi *X, int count ); 
     247int mpi_shift_l( mpi *X, size_t count ); 
    244248 
    245249/** 
     
    252256 *                 1 if memory allocation failed 
    253257 */ 
    254 int mpi_shift_r( mpi *X, int count ); 
     258int mpi_shift_r( mpi *X, size_t count ); 
    255259 
    256260/** 
     
    288292 *                 0 if X is equal to z 
    289293 */ 
    290 int mpi_cmp_int( const mpi *X, int z ); 
     294int mpi_cmp_int( const mpi *X, t_s_int z ); 
    291295 
    292296/** 
     
    348352 *                 1 if memory allocation failed 
    349353 */ 
    350 int mpi_add_int( mpi *X, const mpi *A, int b ); 
     354int mpi_add_int( mpi *X, const mpi *A, t_s_int b ); 
    351355 
    352356/** 
     
    360364 *                 1 if memory allocation failed 
    361365 */ 
    362 int mpi_sub_int( mpi *X, const mpi *A, int b ); 
     366int mpi_sub_int( mpi *X, const mpi *A, t_s_int b ); 
    363367 
    364368/** 
     
    386390 *                 1 if memory allocation failed 
    387391 */ 
    388 int mpi_mul_int( mpi *X, const mpi *A, t_int b ); 
     392int mpi_mul_int( mpi *X, const mpi *A, t_s_int b ); 
    389393 
    390394/** 
     
    418422 * \note           Either Q or R can be NULL. 
    419423 */ 
    420 int mpi_div_int( mpi *Q, mpi *R, const mpi *A, int b ); 
     424int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_s_int b ); 
    421425 
    422426/** 
     
    446450 *                 POLARSSL_ERR_MPI_NEGATIVE_VALUE if b < 0 
    447451 */ 
    448 int mpi_mod_int( t_int *r, const mpi *A, int b ); 
     452int mpi_mod_int( t_int *r, const mpi *A, t_s_int b ); 
    449453 
    450454/** 
     
    478482 *                 1 if memory allocation failed 
    479483 */ 
    480 int mpi_fill_random( mpi *X, int size, int (*f_rng)(void *), void *p_rng ); 
     484int mpi_fill_random( mpi *X, size_t size, int (*f_rng)(void *), void *p_rng ); 
    481485 
    482486/** 
     
    532536 *                 POLARSSL_ERR_MPI_BAD_INPUT_DATA if nbits is < 3 
    533537 */ 
    534 int mpi_gen_prime( mpi *X, int nbits, int dh_flag, 
     538int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, 
    535539                   int (*f_rng)(void *), void *p_rng ); 
    536540 
  • trunk/include/polarssl/camellia.h

    r913 r1014  
    2727#ifndef POLARSSL_CAMELLIA_H 
    2828#define POLARSSL_CAMELLIA_H 
     29 
     30#include <string.h> 
    2931 
    3032#ifdef _MSC_VER 
     
    6466 * \return         0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH 
    6567 */ 
    66 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize ); 
     68int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, unsigned int keysize ); 
    6769 
    6870/** 
     
    7577 * \return         0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH 
    7678 */ 
    77 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize ); 
     79int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, unsigned int keysize ); 
    7880 
    7981/** 
     
    108110int camellia_crypt_cbc( camellia_context *ctx, 
    109111                    int mode, 
    110                     int length, 
     112                    size_t length, 
    111113                    unsigned char iv[16], 
    112114                    const unsigned char *input, 
     
    128130int camellia_crypt_cfb128( camellia_context *ctx, 
    129131                       int mode, 
    130                        int length, 
     132                       size_t length, 
    131133                       int *iv_off, 
    132134                       unsigned char iv[16], 
  • trunk/include/polarssl/cipher.h

    r1011 r1014  
    9797 
    9898    /** Cipher key length, in bits (default length for variable sized ciphers) */ 
    99     int key_length; 
     99    unsigned int key_length; 
    100100 
    101101    /** Name of the cipher */ 
     
    103103 
    104104    /** IV size, in bytes */ 
    105     int iv_size; 
     105    unsigned int iv_size; 
    106106 
    107107    /** block size, in bytes */ 
    108     int block_size; 
     108    unsigned int block_size; 
    109109 
    110110    /** 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, 
    112112            const unsigned char *input, unsigned char *output ); 
    113113 
    114114    /** 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); 
    116116 
    117117    /** 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); 
    119119 
    120120    /** Allocate a new context */ 
     
    143143 
    144144    /** Number of bytes that still need processing */ 
    145     int unprocessed_len; 
     145    size_t unprocessed_len; 
    146146 
    147147    /** Current IV */ 
     
    168168 *                      with the given cipher name. 
    169169 * 
    170  * \param cipher_name   Name of the cipher to search for. 
     170 * \param cipher_name   Name of the cipher to search for. 
    171171 * 
    172172 * \return              the cipher information structure associated with the 
     
    216216 *                      initialised. 
    217217 */ 
    218 static inline int cipher_get_block_size( const cipher_context_t *ctx ) 
     218static inline unsigned int cipher_get_block_size( const cipher_context_t *ctx ) 
    219219{ 
    220220    if( NULL == ctx || NULL == ctx->cipher_info ) 
     
    333333 * \returns             0 on success, 1 if parameter verification fails. 
    334334 */ 
    335 int cipher_update( cipher_context_t *ctx, const unsigned char *input, int ilen, 
    336         unsigned char *output, int *olen ); 
     335int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ilen, 
     336        unsigned char *output, size_t *olen ); 
    337337 
    338338/** 
     
    348348 * \returns             0 on success, 1 if parameter verification fails. 
    349349 */ 
    350 int cipher_finish( cipher_context_t *ctx, unsigned char *output, int *olen); 
     350int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen); 
    351351 
    352352 
  • trunk/include/polarssl/debug.h

    r913 r1014  
    7373void debug_print_buf( const ssl_context *ssl, int level, 
    7474                      const char *file, int line, const char *text, 
    75                       unsigned char *buf, int len ); 
     75                      unsigned char *buf, size_t len ); 
    7676 
    7777void debug_print_mpi( const ssl_context *ssl, int level, 
  • trunk/include/polarssl/des.h

    r944 r1014  
    2727#ifndef POLARSSL_DES_H 
    2828#define POLARSSL_DES_H 
     29 
     30#include <string.h> 
    2931 
    3032#define DES_ENCRYPT     1 
     
    172174int des_crypt_cbc( des_context *ctx, 
    173175                    int mode, 
    174                     int length, 
     176                    size_t length, 
    175177                    unsigned char iv[8], 
    176178                    const unsigned char *input, 
     
    204206int des3_crypt_cbc( des3_context *ctx, 
    205207                     int mode, 
    206                      int length, 
     208                     size_t length, 
    207209                     unsigned char iv[8], 
    208210                     const unsigned char *input, 
  • trunk/include/polarssl/dhm.h

    r944 r1014  
    4545typedef struct 
    4646{ 
    47     int len;    /*!<  size(P) in chars  */ 
     47    size_t len; /*!<  size(P) in chars  */ 
    4848    mpi P;      /*!<  prime modulus     */ 
    4949    mpi G;      /*!<  generator         */ 
     
    9090 */ 
    9191int dhm_make_params( dhm_context *ctx, int x_size, 
    92                      unsigned char *output, int *olen, 
     92                     unsigned char *output, size_t *olen, 
    9393                     int (*f_rng)(void *), void *p_rng ); 
    9494 
     
    103103 */ 
    104104int dhm_read_public( dhm_context *ctx, 
    105                      const unsigned char *input, int ilen ); 
     105                     const unsigned char *input, size_t ilen ); 
    106106 
    107107/** 
     
    118118 */ 
    119119int dhm_make_public( dhm_context *ctx, int x_size, 
    120                      unsigned char *output, int olen, 
     120                     unsigned char *output, size_t olen, 
    121121                     int (*f_rng)(void *), void *p_rng ); 
    122122 
     
    131131 */ 
    132132int dhm_calc_secret( dhm_context *ctx, 
    133                      unsigned char *output, int *olen ); 
     133                     unsigned char *output, size_t *olen ); 
    134134 
    135135/* 
  • trunk/include/polarssl/md.h

    r1008 r1014  
    3030#ifndef POLARSSL_MD_H 
    3131#define POLARSSL_MD_H 
     32 
     33#include <string.h> 
    3234 
    3335#ifdef _MSC_VER 
     
    6769 
    6870    /** 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 ); 
    7072 
    7173    /** Digest finalisation function */ 
     
    7375 
    7476    /** Generic digest function */ 
    75     void (*digest_func)( const unsigned char *input, int ilen, 
     77    void (*digest_func)( const unsigned char *input, size_t ilen, 
    7678                            unsigned char *output ); 
    7779 
     
    8082 
    8183    /** 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 ); 
    8385 
    8486    /** 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 ); 
    8688 
    8789    /** HMAC finalisation function */ 
     
    9294 
    9395    /** 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, 
    9698                    unsigned char *output ); 
    9799 
     
    136138 *                  given digest name. 
    137139 * 
    138  * \param md_name       Name of the digest to search for. 
     140 * \param md_name   Name of the digest to search for. 
    139141 * 
    140142 * \return          The message digest information associated with md_name or 
     
    185187 * \return          size of the message digest output. 
    186188 */ 
    187 static inline unsigned char md_get_size ( const md_info_t *md_info) 
     189static inline unsigned char md_get_size( const md_info_t *md_info ) 
    188190{ 
    189191    return md_info->size; 
     
    197199 * \return          type of the message digest output. 
    198200 */ 
    199 static inline md_type_t md_get_type ( const md_info_t *md_info ) 
     201static inline md_type_t md_get_type( const md_info_t *md_info ) 
    200202{ 
    201203    return md_info->type; 
     
    209211 * \return          name of the message digest output. 
    210212 */ 
    211 static inline const char *md_get_name ( const md_info_t *md_info ) 
     213static inline const char *md_get_name( const md_info_t *md_info ) 
    212214{ 
    213215    return md_info->name; 
     
    232234 * \returns        0 on success, 1 if parameter verification fails. 
    233235 */ 
    234 int md_update( md_context_t *ctx, const unsigned char *input, int ilen ); 
     236int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen ); 
    235237 
    236238/** 
     
    254256 * \returns        0 on success, 1 if parameter verification fails. 
    255257 */ 
    256 int md( const md_info_t *md_info, const unsigned char *input, int ilen, 
     258int md( const md_info_t *md_info, const unsigned char *input, size_t ilen, 
    257259        unsigned char *output ); 
    258260 
     
    278280 * \returns        0 on success, 1 if parameter verification fails. 
    279281 */ 
    280 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, int keylen ); 
     282int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen ); 
    281283 
    282284/** 
     
    289291 * \returns        0 on success, 1 if parameter verification fails. 
    290292 */ 
    291 int md_hmac_update( md_context_t *ctx, const unsigned char *input, int ilen ); 
     293int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen ); 
    292294 
    293295/** 
     
    322324 * \returns        0 on success, 1 if parameter verification fails. 
    323325 */ 
    324 int md_hmac( const md_info_t *md_info, const unsigned char *key, int keylen, 
    325                 const unsigned char *input, int ilen, 
     326int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen, 
     327                const unsigned char *input, size_t ilen, 
    326328                unsigned char *output ); 
    327329 
  • trunk/include/polarssl/md2.h

    r913 r1014  
    2828#define POLARSSL_MD2_H 
    2929 
     30#include <string.h> 
     31 
    3032/** 
    3133 * \brief          MD2 context structure 
     
    3941    unsigned char ipad[64];     /*!< HMAC: inner padding        */ 
    4042    unsigned char opad[64];     /*!< HMAC: outer padding        */ 
    41     int left;                   /*!< amount of data in buffer   */ 
     43    size_t left;                /*!< amount of data in buffer   */ 
    4244} 
    4345md2_context; 
     
    6163 * \param ilen     length of the input data 
    6264 */ 
    63 void md2_update( md2_context *ctx, const unsigned char *input, int ilen ); 
     65void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen ); 
    6466 
    6567/** 
     
    7880 * \param output   MD2 checksum result 
    7981 */ 
    80 void md2( const unsigned char *input, int ilen, unsigned char output[16] ); 
     82void md2( const unsigned char *input, size_t ilen, unsigned char output[16] ); 
    8183 
    8284/** 
     
    98100 * \param keylen   length of the HMAC key 
    99101 */ 
    100 void md2_hmac_starts( md2_context *ctx, const unsigned char *key, int keylen ); 
     102void md2_hmac_starts( md2_context *ctx, const unsigned char *key, size_t keylen ); 
    101103 
    102104/** 
     
    107109 * \param ilen     length of the input data 
    108110 */ 
    109 void md2_hmac_update( md2_context *ctx, const unsigned char *input, int ilen ); 
     111void md2_hmac_update( md2_context *ctx, const unsigned char *input, size_t ilen ); 
    110112 
    111113/** 
     
    133135 * \param output   HMAC-MD2 result 
    134136 */ 
    135 void md2_hmac( const unsigned char *key, int keylen, 
    136                const unsigned char *input, int ilen, 
     137void md2_hmac( const unsigned char *key, size_t keylen, 
     138               const unsigned char *input, size_t ilen, 
    137139               unsigned char output[16] ); 
    138140 
  • trunk/include/polarssl/md4.h

    r913 r1014  
    2727#ifndef POLARSSL_MD4_H 
    2828#define POLARSSL_MD4_H 
     29 
     30#include <string.h> 
    2931 
    3032/** 
     
    6062 * \param ilen     length of the input data 
    6163 */ 
    62 void md4_update( md4_context *ctx, const unsigned char *input, int ilen ); 
     64void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen ); 
    6365 
    6466/** 
     
    7779 * \param output   MD4 checksum result 
    7880 */ 
    79 void md4( const unsigned char *input, int ilen, unsigned char output[16] ); 
     81void md4( const unsigned char *input, size_t ilen, unsigned char output[16] ); 
    8082 
    8183/** 
     
    9799 * \param keylen   length of the HMAC key 
    98100 */ 
    99 void md4_hmac_starts( md4_context *ctx, const unsigned char *key, int keylen ); 
     101void md4_hmac_starts( md4_context *ctx, const unsigned char *key, size_t keylen ); 
    100102 
    101103/** 
     
    106108 * \param ilen     length of the input data 
    107109 */ 
    108 void md4_hmac_update( md4_context *ctx, const unsigned char *input, int ilen ); 
     110void md4_hmac_update( md4_context *ctx, const unsigned char *input, size_t ilen ); 
    109111 
    110112/** 
     
    132134 * \param output   HMAC-MD4 result 
    133135 */ 
    134 void md4_hmac( const unsigned char *key, int keylen, 
    135                const unsigned char *input, int ilen, 
     136void md4_hmac( const unsigned char *key, size_t keylen, 
     137               const unsigned char *input, size_t ilen, 
    136138               unsigned char output[16] ); 
    137139 
  • trunk/include/polarssl/md5.h

    r913 r1014  
    2727#ifndef POLARSSL_MD5_H 
    2828#define POLARSSL_MD5_H 
     29 
     30#include <string.h> 
    2931 
    3032/** 
     
    6062 * \param ilen     length of the input data 
    6163 */ 
    62 void md5_update( md5_context *ctx, const unsigned char *input, int ilen ); 
     64void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen ); 
    6365 
    6466/** 
     
    7779 * \param output   MD5 checksum result 
    7880 */ 
    79 void md5( const unsigned char *input, int ilen, unsigned char output[16] ); 
     81void md5( const unsigned char *input, size_t ilen, unsigned char output[16] ); 
    8082 
    8183/** 
     
    98100 */ 
    99101void md5_hmac_starts( md5_context *ctx, 
    100                       const unsigned char *key, int keylen ); 
     102                      const unsigned char *key, size_t keylen ); 
    101103 
    102104/** 
     
    108110 */ 
    109111void md5_hmac_update( md5_context *ctx, 
    110                       const unsigned char *input, int ilen ); 
     112                      const unsigned char *input, size_t ilen ); 
    111113 
    112114/** 
     
    134136 * \param output   HMAC-MD5 result 
    135137 */ 
    136 void md5_hmac( const unsigned char *key, int keylen, 
    137                const unsigned char *input, int ilen, 
     138void md5_hmac( const unsigned char *key, size_t keylen, 
     139               const unsigned char *input, size_t ilen, 
    138140               unsigned char output[16] ); 
    139141 
  • trunk/include/polarssl/net.h

    r913 r1014  
    2727#ifndef POLARSSL_NET_H 
    2828#define POLARSSL_NET_H 
     29 
     30#include <string.h> 
    2931 
    3032#define POLARSSL_ERR_NET_UNKNOWN_HOST                      -0x0F00 
     
    125127 *                 indicates read() is blocking. 
    126128 */ 
    127 int net_recv( void *ctx, unsigned char *buf, int len ); 
     129int net_recv( void *ctx, unsigned char *buf, size_t len ); 
    128130 
    129131/** 
     
    139141 *                 indicates write() is blocking. 
    140142 */ 
    141 int net_send( void *ctx, unsigned char *buf, int len ); 
     143int net_send( void *ctx, unsigned char *buf, size_t len ); 
    142144 
    143145/** 
  • trunk/include/polarssl/padlock.h

    r913 r1014  
    8787int padlock_xcryptcbc( aes_context *ctx, 
    8888                       int mode, 
    89                        int length, 
     89                       size_t length, 
    9090                       unsigned char iv[16], 
    9191                       const unsigned char *input, 
  • trunk/include/polarssl/pem.h

    r956 r1014  
    2828#define POLARSSL_PEM_H 
    2929 
     30#include <string.h> 
     31 
    3032/** 
    3133 * \name PEM Error codes 
     
    5052{ 
    5153    unsigned char *buf;     /*!< buffer for decoded data             */ 
    52     int buflen;             /*!< length of the buffer                */ 
     54    size_t buflen;          /*!< length of the buffer                */ 
    5355    unsigned char *info;    /*!< buffer for extra header information */ 
    5456} 
     
    8385                     const unsigned char *data, 
    8486                     const unsigned char *pwd, 
    85                      int pwdlen, int *use_len ); 
     87                     size_t pwdlen, size_t *use_len ); 
    8688 
    8789/** 
  • trunk/include/polarssl/pkcs11.h

    r932 r1014  
    9595 */ 
    9696int pkcs11_decrypt( pkcs11_context *ctx, 
    97                        int mode, int *olen, 
     97                       int mode, size_t *olen, 
    9898                       const unsigned char *input, 
    9999                       unsigned char *output, 
     
    119119                    int mode, 
    120120                    int hash_id, 
    121                     int hashlen, 
     121                    unsigned int hashlen, 
    122122                    const unsigned char *hash, 
    123123                    unsigned char *sig ); 
  • trunk/include/polarssl/rsa.h

    r979 r1014  
    5050#define SIG_RSA_MD4     3 
    5151#define SIG_RSA_MD5     4 
    52 #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 
     52#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 
    5757 
    5858#define RSA_PUBLIC      0 
     
    6565#define RSA_CRYPT       2 
    6666 
    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" 
    7878 
    7979/* 
    8080 * ISO Member bodies OID parts 
    8181 */ 
    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" 
    8484 
    8585/* 
    8686 * ISO Identified organization OID parts 
    8787 */ 
    88 #define OID_OIW_SECSIG_SHA1             "\x0e\x03\x02\x1a" 
     88#define OID_OIW_SECSIG_SHA1             "\x0e\x03\x02\x1a" 
    8989 
    9090/* 
     
    9797 * Digest ::= OCTET STRING 
    9898 */ 
    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"              \ 
    107107) 
    108108 
    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"                    \ 
    115115      ASN1_STR_OCTET_STRING "\x14" 
    116116 
    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"                    \ 
    123123      ASN1_STR_OCTET_STRING "\x00" 
    124124 
     
    129129{ 
    130130    int ver;                    /*!<  always 0          */ 
    131     int len;                    /*!<  size(N) in chars  */ 
     131    size_t len;                 /*!<  size(N) in chars  */ 
    132132 
    133133    mpi N;                      /*!<  public modulus    */ 
     
    189189                 int (*f_rng)(void *), 
    190190                 void *p_rng, 
    191                  int nbits, int exponent ); 
     191                 unsigned int nbits, int exponent ); 
    192192 
    193193/** 
     
    264264                       int (*f_rng)(void *), 
    265265                       void *p_rng, 
    266                        int mode, int ilen, 
     266                       int mode, size_t ilen, 
    267267                       const unsigned char *input, 
    268268                       unsigned char *output ); 
     
    276276 * \param output   buffer that will hold the plaintext 
    277277 * \param olen     will contain the plaintext length 
    278  * \param output_max_len        maximum length of the output buffer 
     278 * \param output_max_len    maximum length of the output buffer 
    279279 * 
    280280 * \return         0 if successful, or an POLARSSL_ERR_RSA_XXX error code 
     
    285285 */ 
    286286int rsa_pkcs1_decrypt( rsa_context *ctx, 
    287                        int mode, int *olen, 
     287                       int mode, size_t *olen, 
    288288                       const unsigned char *input, 
    289289                       unsigned char *output, 
    290                                int output_max_len ); 
     290                       size_t output_max_len ); 
    291291 
    292292/** 
     
    319319                    int mode, 
    320320                    int hash_id, 
    321                     int hashlen, 
     321                    unsigned int hashlen, 
    322322                    const unsigned char *hash, 
    323323                    unsigned char *sig ); 
     
    348348                      int mode, 
    349349                      int hash_id, 
    350                       int hashlen, 
     350                      unsigned int hashlen, 
    351351                      const unsigned char *hash, 
    352352                      unsigned char *sig ); 
  • trunk/include/polarssl/sha1.h

    r913 r1014  
    2727#ifndef POLARSSL_SHA1_H 
    2828#define POLARSSL_SHA1_H 
     29 
     30#include <string.h> 
    2931 
    3032/** 
     
    6062 * \param ilen     length of the input data 
    6163 */ 
    62 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ); 
     64void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen ); 
    6365 
    6466/** 
     
    7779 * \param output   SHA-1 checksum result 
    7880 */ 
    79 void sha1( const unsigned char *input, int ilen, unsigned char output[20] ); 
     81void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ); 
    8082 
    8183/** 
     
    9799 * \param keylen   length of the HMAC key 
    98100 */ 
    99 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen ); 
     101void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen ); 
    100102 
    101103/** 
     
    106108 * \param ilen     length of the input data 
    107109 */ 
    108 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen ); 
     110void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen ); 
    109111 
    110112/** 
     
    132134 * \param output   HMAC-SHA-1 result 
    133135 */ 
    134 void sha1_hmac( const unsigned char *key, int keylen, 
    135                 const unsigned char *input, int ilen, 
     136void sha1_hmac( const unsigned char *key, size_t keylen, 
     137                const unsigned char *input, size_t ilen, 
    136138                unsigned char output[20] ); 
    137139 
  • trunk/include/polarssl/sha2.h

    r944 r1014  
    2727#ifndef POLARSSL_SHA2_H 
    2828#define POLARSSL_SHA2_H 
     29 
     30#include <string.h> 
    2931 
    3032/** 
     
    6264 * \param ilen     length of the input data 
    6365 */ 
    64 void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen ); 
     66void sha2_update( sha2_context *ctx, const unsigned char *input, size_t ilen ); 
    6567 
    6668/** 
     
    8082 * \param is224    0 = use SHA256, 1 = use SHA224 
    8183 */ 
    82 void sha2( const unsigned char *input, int ilen, 
     84void sha2( const unsigned char *input, size_t ilen, 
    8385           unsigned char output[32], int is224 ); 
    8486 
     
    103105 * \param is224    0 = use SHA256, 1 = use SHA224 
    104106 */ 
    105 void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, int keylen, 
     107void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, size_t keylen, 
    106108                       int is224 ); 
    107109 
     
    113115 * \param ilen     length of the input data 
    114116 */ 
    115 void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, int ilen ); 
     117void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, size_t ilen ); 
    116118 
    117119/** 
     
    140142 * \param is224    0 = use SHA256, 1 = use SHA224 
    141143 */ 
    142 void sha2_hmac( const unsigned char *key, int keylen, 
    143                 const unsigned char *input, int ilen, 
     144void sha2_hmac( const unsigned char *key, size_t keylen, 
     145                const unsigned char *input, size_t ilen, 
    144146                unsigned char output[32], int is224 ); 
    145147 
  • trunk/include/polarssl/sha4.h

    r944 r1014  
    2727#ifndef POLARSSL_SHA4_H 
    2828#define POLARSSL_SHA4_H 
     29 
     30#include <string.h> 
    2931 
    3032#if defined(_MSC_VER) || defined(__WATCOMC__) 
     
    7072 * \param ilen     length of the input data 
    7173 */ 
    72 void sha4_update( sha4_context *ctx, const unsigned char *input, int ilen ); 
     74void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen ); 
    7375 
    7476/** 
     
    8890 * \param is384    0 = use SHA512, 1 = use SHA384 
    8991 */ 
    90 void sha4( const unsigned char *input, int ilen, 
     92void sha4( const unsigned char *input, size_t ilen, 
    9193           unsigned char output[64], int is384 ); 
    9294 
     
    111113 * \param keylen   length of the HMAC key 
    112114 */ 
    113 void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, int keylen, 
     115void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, size_t keylen, 
    114116                       int is384 ); 
    115117 
     
    121123 * \param ilen     length of the input data 
    122124 */ 
    123 void sha4_hmac_update( sha4_context *ctx, const unsigned char *input, int ilen ); 
     125void sha4_hmac_update( sha4_context *ctx, const unsigned char *input, size_t ilen ); 
    124126 
    125127/** 
     
    148150 * \param is384    0 = use SHA512, 1 = use SHA384 
    149151 */ 
    150 void sha4_hmac( const unsigned char *key, int keylen, 
    151                 const unsigned char *input, int ilen, 
     152void sha4_hmac( const unsigned char *key, size_t keylen, 
     153                const unsigned char *input, size_t ilen, 
    152154                unsigned char output[64], int is384 ); 
    153155 
  • trunk/include/polarssl/ssl.h

    r1008 r1014  
    205205    time_t start;               /*!< starting time      */ 
    206206    int ciphersuite;            /*!< chosen ciphersuite */ 
    207     int length;                 /*!< session id length  */ 
     207    size_t length;              /*!< session id length  */ 
    208208    unsigned char id[32];       /*!< session identifier */ 
    209209    unsigned char master[48];   /*!< the master secret  */ 
     
    229229    int  (*f_rng)(void *); 
    230230    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); 
    233233    int (*f_vrfy)(void *, x509_cert *, int, int); 
    234234 
     
    257257 
    258258    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 */ 
    263263    int nb_zero;                /*!< # of 0-length encrypted messages */ 
    264264 
     
    271271 
    272272    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   */ 
    275275 
    276276    /* 
     
    301301    int do_crypt;                       /*!<  en(de)cryption flag     */ 
    302302    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              */ 
    308308 
    309309    unsigned char randbytes[64];        /*!<  random bytes            */ 
     
    323323     */ 
    324324    unsigned char *hostname; 
    325     unsigned long  hostname_len; 
     325    size_t         hostname_len; 
    326326}; 
    327327 
     
    448448 */ 
    449449void 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 ); 
    452452 
    453453/** 
     
    557557 * \return         how many bytes are available in the read buffer 
    558558 */ 
    559 int ssl_get_bytes_avail( const ssl_context *ssl ); 
     559size_t ssl_get_bytes_avail( const ssl_context *ssl ); 
    560560 
    561561/** 
     
    610610 *                 or a negative error code. 
    611611 */ 
    612 int ssl_read( ssl_context *ssl, unsigned char *buf, int len ); 
     612int ssl_read( ssl_context *ssl, unsigned char *buf, size_t len ); 
    613613 
    614614/** 
     
    626626 *                 until it returns a positive value. 
    627627 */ 
    628 int ssl_write( ssl_context *ssl, const unsigned char *buf, int len ); 
     628int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len ); 
    629629 
    630630/** 
     
    652652 
    653653int ssl_read_record( ssl_context *ssl ); 
    654 int ssl_fetch_input( ssl_context *ssl, int nb_want ); 
     654int ssl_fetch_input( ssl_context *ssl, size_t nb_want ); 
    655655 
    656656int ssl_write_record( ssl_context *ssl ); 
  • trunk/include/polarssl/x509.h

    r992 r1014  
    285285{ 
    286286    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. */ 
    288288    unsigned char *p;       /**< ASN1 data, e.g. in ASCII. */ 
    289289} 
     
    295295typedef struct _x509_bitstring 
    296296{ 
    297     int len;                    /**< ASN1 length, e.g. in octets. */ 
     297    size_t len;                 /**< ASN1 length, e.g. in octets. */ 
    298298    unsigned char unused_bits;  /**< Number of unused bits at the end of the string */ 
    299299    unsigned char *p;           /**< Raw ASN1 data for the bit string */ 
     
    484484 * \return         0 if successful, or a specific X509 or PEM error code 
    485485 */ 
    486 int x509parse_crt( x509_cert *chain, const unsigned char *buf, int buflen ); 
     486int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen ); 
    487487 
    488488/** \ingroup x509_module */ 
     
    509509 * \return         0 if successful, or a specific X509 or PEM error code 
    510510 */ 
    511 int x509parse_crl( x509_crl *chain, const unsigned char *buf, int buflen ); 
     511int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen ); 
    512512 
    513513/** \ingroup x509_module */ 
     
    536536 */ 
    537537int 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 ); 
    540540 
    541541/** \ingroup x509_module */ 
     
    563563 */ 
    564564int x509parse_public_key( rsa_context *rsa, 
    565                    const unsigned char *key, int keylen ); 
     565                   const unsigned char *key, size_t keylen ); 
    566566 
    567567/** \ingroup x509_module */ 
     
    586586 * \return         0 if successful, or a specific X509 or PEM error code 
    587587 */ 
    588 int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, int dhminlen ); 
     588int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen ); 
    589589 
    590590/** \ingroup x509_module */ 
  • trunk/include/polarssl/xtea.h

    r1011 r1014  
    2727#ifndef POLARSSL_XTEA_H 
    2828#define POLARSSL_XTEA_H 
     29 
     30#include <string.h> 
    2931 
    3032#ifdef _MSC_VER 
     
    7274 */ 
    7375int 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] ); 
    7779 
    7880/** 
     
    9193int xtea_crypt_cbc( xtea_context *ctx, 
    9294                    int mode, 
    93                     int length, 
     95                    size_t length, 
    9496                    unsigned char iv[8], 
    9597                    unsigned char *input, 
  • trunk/library/aes.c

    r1012 r1014  
    3636#include "polarssl/aes.h" 
    3737#include "polarssl/padlock.h" 
    38  
    39 #include <string.h> 
    4038 
    4139/* 
     
    442440 * AES key schedule (encryption) 
    443441 */ 
    444 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize ) 
    445 { 
    446     int i; 
     442int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize ) 
     443{ 
     444    unsigned int i; 
    447445    unsigned long *RK; 
    448446 
     
    547545 * AES key schedule (decryption) 
    548546 */ 
    549 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize ) 
     547int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int keysize ) 
    550548{ 
    551549    int i, j; 
     
    759757int aes_crypt_cbc( aes_context *ctx, 
    760758                    int mode, 
    761                     int length, 
     759                    size_t length, 
    762760                    unsigned char iv[16], 
    763761                    const unsigned char *input, 
     
    824822int aes_crypt_cfb128( aes_context *ctx, 
    825823                       int mode, 
    826                        int length, 
     824                       size_t length, 
    827825                       int *iv_off, 
    828826                       unsigned char iv[16], 
  • trunk/library/arc4.c

    r897 r1014  
    3838 * ARC4 key schedule 
    3939 */ 
    40 void arc4_setup( arc4_context *ctx, const unsigned char *key, int keylen ) 
     40void arc4_setup( arc4_context *ctx, const unsigned char *key, unsigned int keylen ) 
    4141{ 
    42     int i, j, k, a; 
     42    int i, j, a; 
     43    unsigned int k; 
    4344    unsigned char *m; 
    4445 
     
    6667 * ARC4 cipher function 
    6768 */ 
    68 int arc4_crypt( arc4_context *ctx, int length, const unsigned char *input, 
     69int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input, 
    6970                unsigned char *output ) 
    7071{ 
    71     int i, x, y, a, b; 
     72    int x, y, a, b; 
     73    size_t i; 
    7274    unsigned char *m; 
    7375 
  • trunk/library/base64.c

    r897 r1014  
    6161 * Encode a buffer into base64 format 
    6262 */ 
    63 int base64_encode( unsigned char *dst, int *dlen, 
    64                    const unsigned char *src, int slen ) 
    65 { 
    66     int i, n; 
     63int base64_encode( unsigned char *dst, size_t *dlen, 
     64                   const unsigned char *src, size_t slen ) 
     65{ 
     66    size_t i, n; 
    6767    int C1, C2, C3; 
    6868    unsigned char *p; 
     
    124124 * Decode a base64-formatted buffer 
    125125 */ 
    126 int base64_decode( unsigned char *dst, int *dlen, 
    127                    const unsigned char *src, int slen ) 
    128 { 
    129     int i, j, n; 
     126int base64_decode( unsigned char *dst, size_t *dlen, 
     127                   const unsigned char *src, size_t slen ) 
     128{ 
     129    size_t i, j, n; 
    130130    unsigned long x; 
    131131    unsigned char *p; 
     
    211211int base64_self_test( int verbose ) 
    212212{ 
    213     int len; 
     213    size_t len; 
    214214    unsigned char *src, buffer[128]; 
    215215 
  • trunk/library/bignum.c

    r997 r1014  
    3838#include "polarssl/bn_mul.h" 
    3939 
    40 #include <string.h> 
    4140#include <stdlib.h> 
    4241#include <stdarg.h> 
     
    103102 * Enlarge to the specified number of limbs 
    104103 */ 
    105 int mpi_grow( mpi *X, int nblimbs ) 
     104int mpi_grow( mpi *X, size_t nblimbs ) 
    106105{ 
    107106    t_int *p; 
     
    133132int mpi_copy( mpi *X, const mpi *Y ) 
    134133{ 
    135     int ret, i; 
     134    int ret; 
     135    size_t i; 
    136136 
    137137    if( X == Y ) 
     
    170170 * Set value from integer 
    171171 */ 
    172 int mpi_lset( mpi *X, int z ) 
     172int mpi_lset( mpi *X, t_s_int z ) 
    173173{ 
    174174    int ret; 
     
    188188 * Return the number of least significant bits 
    189189 */ 
    190 int mpi_lsb( const mpi *X ) 
    191 { 
    192     int i, j, count = 0; 
     190size_t mpi_lsb( const mpi *X ) 
     191{ 
     192    size_t i, j, count = 0; 
    193193 
    194194    for( i = 0; i < X->n; i++ ) 
     
    203203 * Return the number of most significant bits 
    204204 */ 
    205 int mpi_msb( const mpi *X ) 
    206 { 
    207     int i, j; 
     205size_t mpi_msb( const mpi *X ) 
     206{ 
     207    size_t i, j; 
    208208 
    209209    for( i = X->n - 1; i > 0; i-- ) 
     
    211211            break; 
    212212 
    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 ) 
    215215            break; 
    216216 
    217     return( ( i * biL ) + j + 1 ); 
     217    return( ( i * biL ) + j ); 
    218218} 
    219219 
     
    221221 * Return the total size in bytes 
    222222 */ 
    223 int mpi_size( const mpi *X ) 
     223size_t mpi_size( const mpi *X ) 
    224224{ 
    225225    return( ( mpi_msb( X ) + 7 ) >> 3 ); 
     
    248248int mpi_read_string( mpi *X, int radix, const char *s ) 
    249249{ 
    250     int ret, i, j, n, slen; 
     250    int ret; 
     251    size_t i, j, slen, n; 
    251252    t_int d; 
    252253    mpi T; 
     
    266267        MPI_CHK( mpi_lset( X, 0 ) ); 
    267268 
    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] == '-' ) 
    271272            { 
    272273                X->s = -1; 
     
    274275            } 
    275276 
    276             MPI_CHK( mpi_get_digit( &d, radix, s[i] ) ); 
     277            MPI_CHK( mpi_get_digit( &d, radix, s[i - 1] ) ); 
    277278            X->p[j / (2 * ciL)] |= d << ( (j % (2 * ciL)) << 2 ); 
    278279        } 
     
    341342 * Export into an ASCII string 
    342343 */ 
    343 int mpi_write_string( const mpi *X, int radix, char *s, int *slen ) 
    344 { 
    345     int ret = 0, n; 
     344int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ) 
     345{ 
     346    int ret = 0; 
     347    size_t n; 
    346348    char *p; 
    347349    mpi T; 
     
    369371    if( radix == 16 ) 
    370372    { 
    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-- ) 
    376379            { 
    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 ) 
    380383                    continue; 
    381384 
     
    411414{ 
    412415    t_int d; 
    413     int slen; 
     416    size_t slen; 
    414417    char *p; 
    415418    char s[1024]; 
     
    436439int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout ) 
    437440{ 
    438     int n, ret; 
    439     size_t slen; 
    440     size_t plen; 
     441    int ret; 
     442    size_t n, slen, plen; 
    441443    char s[2048]; 
    442444 
     
    445447    n -= 2; 
    446448 
    447     MPI_CHK( mpi_write_string( X, radix, s, (int *) &n ) ); 
     449    MPI_CHK( mpi_write_string( X, radix, s, (size_t *) &n ) ); 
    448450 
    449451    if( p == NULL ) p = ""; 
     
    471473 * Import X from unsigned binary data, big endian 
    472474 */ 
    473 int mpi_read_binary( mpi *X, const unsigned char *buf, int buflen ) 
    474 { 
    475     int ret, i, j, n; 
     475int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen ) 
     476{ 
     477    int ret; 
     478    size_t i, j, n; 
    476479 
    477480    for( n = 0; n < buflen; n++ ) 
     
    482485    MPI_CHK( mpi_lset( X, 0 ) ); 
    483486 
    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); 
    486489 
    487490cleanup: 
     
    493496 * Export X into unsigned binary data, big endian 
    494497 */ 
    495 int mpi_write_binary( const mpi *X, unsigned char *buf, int buflen ) 
    496 { 
    497     int i, j, n; 
     498int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen ) 
     499{ 
     500    size_t i, j, n; 
    498501 
    499502    n = mpi_size( X ); 
     
    513516 * Left-shift: X <<= count 
    514517 */ 
    515 int mpi_shift_l( mpi *X, int count ) 
    516 { 
    517     int ret, i, v0, t1; 
     518int mpi_shift_l( mpi *X, size_t count ) 
     519{ 
     520    int ret; 
     521    size_t i, v0, t1; 
    518522    t_int r0 = 0, r1; 
    519523 
     
    533537    if( v0 > 0 ) 
    534538    { 
    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; 
    540544    } 
    541545 
     
    562566 * Right-shift: X >>= count 
    563567 */ 
    564 int mpi_shift_r( mpi *X, int count ) 
    565 { 
    566     int i, v0, v1; 
     568int mpi_shift_r( mpi *X, size_t count ) 
     569{ 
     570    size_t i, v0, v1; 
    567571    t_int r0 = 0, r1; 
    568572 
     
    587591    if( v1 > 0 ) 
    588592    { 
    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; 
    594598            r0 = r1; 
    595599        } 
     
    604608int mpi_cmp_abs( const mpi *X, const mpi *Y ) 
    605609{ 
    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 ) 
    610614            break; 
    611615 
    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 ) 
    614618            break; 
    615619 
    616     if( i < 0 && j < 0 ) 
     620    if( i == 0 && j == 0 ) 
    617621        return( 0 ); 
    618622 
     
    620624    if( j > i ) return( -1 ); 
    621625 
    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 ); 
    626630    } 
    627631 
     
    634638int mpi_cmp_mpi( const mpi *X, const mpi *Y ) 
    635639{ 
    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 ) 
    640644            break; 
    641645 
    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 ) 
    644648            break; 
    645649 
    646     if( i < 0 && j < 0 ) 
     650    if( i == 0 && j == 0 ) 
    647651        return( 0 ); 
    648652 
     
    653657    if( Y->s > 0 && X->s < 0 ) return( -1 ); 
    654658 
    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 ); 
    659663    } 
    660664 
     
    665669 * Compare signed values 
    666670 */ 
    667 int mpi_cmp_int( const mpi *X, int z ) 
     671int mpi_cmp_int( const mpi *X, t_s_int z ) 
    668672{ 
    669673    mpi Y; 
     
    683687int mpi_add_abs( mpi *X, const mpi *A, const mpi *B ) 
    684688{ 
    685     int ret, i, j; 
     689    int ret; 
     690    size_t i, j; 
    686691    t_int *o, *p, c; 
    687692 
     
    699704    X->s = 1; 
    700705 
    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 ) 
    703708            break; 
    704709 
    705     MPI_CHK( mpi_grow( X, j + 1 ) ); 
     710    MPI_CHK( mpi_grow( X, j ) ); 
    706711 
    707712    o = B->p; p = X->p; c = 0; 
    708713 
    709     for( i = 0; i <= j; i++, o++, p++ ) 
     714    for( i = 0; i < j; i++, o++, p++ ) 
    710715    { 
    711716        *p +=  c; c  = ( *p <  c ); 
     
    732737 * Helper for mpi substraction 
    733738 */ 
    734 static void mpi_sub_hlp( int n, t_int *s, t_int *d ) 
    735 { 
    736     int i; 
     739static void mpi_sub_hlp( size_t n, t_int *s, t_int *d ) 
     740{ 
     741    size_t i; 
    737742    t_int c, z; 
    738743 
     
    756761{ 
    757762    mpi TB; 
    758     int ret, n; 
     763    int ret; 
     764    size_t n; 
    759765 
    760766    if( mpi_cmp_abs( A, B ) < 0 ) 
     
    779785    ret = 0; 
    780786 
    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 ) 
    783789            break; 
    784790 
    785     mpi_sub_hlp( n + 1, B->p, X->p ); 
     791    mpi_sub_hlp( n, B->p, X->p ); 
    786792 
    787793cleanup: 
     
    857863 * Signed addition: X = A + b 
    858864 */ 
    859 int mpi_add_int( mpi *X, const mpi *A, int b ) 
     865int mpi_add_int( mpi *X, const mpi *A, t_s_int b ) 
    860866{ 
    861867    mpi _B; 
     
    873879 * Signed substraction: X = A - b 
    874880 */ 
    875 int mpi_sub_int( mpi *X, const mpi *A, int b ) 
     881int mpi_sub_int( mpi *X, const mpi *A, t_s_int b ) 
    876882{ 
    877883    mpi _B; 
     
    889895 * Helper for mpi multiplication 
    890896 */  
    891 static void mpi_mul_hlp( int i, t_int *s, t_int *d, t_int b ) 
     897static void mpi_mul_hlp( size_t i, t_int *s, t_int *d, t_int b ) 
    892898{ 
    893899    t_int c = 0, t = 0; 
     
    955961int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B ) 
    956962{ 
    957     int ret, i, j; 
     963    int ret; 
     964    size_t i, j; 
    958965    mpi TA, TB; 
    959966 
     
    963970    if( X == B ) { MPI_CHK( mpi_copy( &TB, B ) ); B = &TB; } 
    964971 
    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 ) 
    967974            break; 
    968975 
    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 ) 
    971978            break; 
    972979 
    973     MPI_CHK( mpi_grow( X, i + j + 2 ) ); 
     980    MPI_CHK( mpi_grow( X, i + j ) ); 
    974981    MPI_CHK( mpi_lset( X, 0 ) ); 
    975982 
    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] ); 
    978985 
    979986    X->s = A->s * B->s; 
     
    989996 * Baseline multiplication: X = A * b 
    990997 */ 
    991 int mpi_mul_int( mpi *X, const mpi *A, t_int b ) 
     998int mpi_mul_int( mpi *X, const mpi *A, t_s_int b ) 
    992999{ 
    9931000    mpi _B; 
     
    10071014int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B ) 
    10081015{ 
    1009     int ret, i, n, t, k; 
     1016    int ret; 
     1017    size_t i, n, t, k; 
    10101018    mpi X, Y, Z, T1, T2; 
    10111019 
     
    11701178 *         POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0 
    11711179 */ 
    1172 int mpi_div_int( mpi *Q, mpi *R, const mpi *A, int b ) 
     1180int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_s_int b ) 
    11731181{ 
    11741182    mpi _B; 
     
    12091217 * Modulo: r = A mod b 
    12101218 */ 
    1211 int mpi_mod_int( t_int *r, const mpi *A, int b ) 
    1212 { 
    1213     int i; 
     1219int mpi_mod_int( t_int *r, const mpi *A, t_s_int b ) 
     1220{ 
     1221    size_t i; 
    12141222    t_int x, y, z; 
    12151223 
     
    12381246     * general case 
    12391247     */ 
    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]; 
    12431251        y  = ( y << biH ) | ( x >> biH ); 
    12441252        z  = y / b; 
     
    12861294static void mpi_montmul( mpi *A, const mpi *B, const mpi *N, t_int mm, const mpi *T ) 
    12871295{ 
    1288     int i, n, m; 
     1296    size_t i, n, m; 
    12891297    t_int u0, u1, *d; 
    12901298 
     
    13371345int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR ) 
    13381346{ 
    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; 
    13411351    t_int ei, mm, state; 
    13421352    mpi RR, T, W[64]; 
     
    13971407         * W[1 << (wsize - 1)] = W[1] ^ (wsize - 1) 
    13981408         */ 
    1399         j =  1 << (wsize - 1); 
     1409        j =  one << (wsize - 1); 
    14001410 
    14011411        MPI_CHK( mpi_grow( &W[j], N->n + 1 ) ); 
     
    14081418         * W[i] = W[i - 1] * W[1] 
    14091419         */ 
    1410         for( i = j + 1; i < (1 << wsize); i++ ) 
     1420        for( i = j + 1; i < (one << wsize); i++ ) 
    14111421        { 
    14121422            MPI_CHK( mpi_grow( &W[i], N->n + 1 ) ); 
     
    14881498        wbits <<= 1; 
    14891499 
    1490         if( (wbits & (1 << wsize)) != 0 ) 
     1500        if( (wbits & (one << wsize)) != 0 ) 
    14911501            mpi_montmul( X, &W[1], N, mm, &T ); 
    14921502    } 
     
    14991509cleanup: 
    15001510 
    1501     for( i = (1 << (wsize - 1)); i < (1 << wsize); i++ ) 
     1511    for( i = (one << (wsize - 1)); i < (one << wsize); i++ ) 
    15021512        mpi_free( &W[i], NULL ); 
    15031513 
     
    15141524int mpi_gcd( mpi *G, const mpi *A, const mpi *B ) 
    15151525{ 
    1516     int ret, lz, lzt; 
     1526    int ret; 
     1527    size_t lz, lzt; 
    15171528    mpi TG, TA, TB; 
    15181529 
     
    15601571} 
    15611572 
    1562 int mpi_fill_random( mpi *X, int size, int (*f_rng)(void *), void *p_rng ) 
    1563 { 
    1564     int ret, k; 
     1573int mpi_fill_random( mpi *X, size_t size, int (*f_rng)(void *), void *p_rng ) 
     1574{ 
     1575    int ret; 
     1576    size_t k; 
    15651577    unsigned char *p; 
    15661578 
     
    17011713int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ) 
    17021714{ 
    1703     int ret, i, j, n, s, xs; 
     1715    int ret, xs; 
     1716    size_t i, j, n, s; 
    17041717    mpi W, R, T, A, RR; 
    17051718 
     
    18121825 * Prime number generation 
    18131826 */ 
    1814 int mpi_gen_prime( mpi *X, int nbits, int dh_flag, 
     1827int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, 
    18151828                   int (*f_rng)(void *), void *p_rng ) 
    18161829{ 
    1817     int ret, k, n; 
     1830    int ret; 
     1831    size_t k, n; 
    18181832    mpi Y; 
    18191833 
     
    18791893#if defined(POLARSSL_SELF_TEST) 
    18801894 
    1881 #define GCD_PAIR_COUNT  3 
     1895#define GCD_PAIR_COUNT  3 
    18821896 
    18831897static const int gcd_pairs[GCD_PAIR_COUNT][3] = 
     
    20132027    { 
    20142028        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            } 
    20262040    } 
    20272041 
  • trunk/library/camellia.c

    r1011 r1014  
    3636#include "polarssl/camellia.h" 
    3737 
    38 #include <string.h> 
    39  
    4038/* 
    4139 * 32-bit integer manipulation macros (big endian) 
     
    310308 * Camellia key schedule (encryption) 
    311309 */ 
    312 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize ) 
    313 { 
    314     int i, idx; 
     310int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, unsigned int keysize ) 
     311{ 
     312    int idx; 
     313    size_t i; 
    315314    uint32_t *RK; 
    316315    unsigned char t[64]; 
     
    413412 * Camellia key schedule (decryption) 
    414413 */ 
    415 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize ) 
    416 { 
    417     int i, idx; 
     414int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, unsigned int keysize ) 
     415{ 
     416    int idx; 
     417    size_t i; 
    418418    camellia_context cty; 
    419419    uint32_t *RK; 
     
    527527int camellia_crypt_cbc( camellia_context *ctx, 
    528528                    int mode, 
    529                     int length, 
     529                    size_t length, 
    530530                    unsigned char iv[16], 
    531531                    const unsigned char *input, 
     
    580580int camellia_crypt_cfb128( camellia_context *ctx, 
    581581                       int mode, 
    582                        int length, 
     582                       size_t length, 
    583583                       int *iv_off, 
    584584                       unsigned char iv[16], 
  • trunk/library/cipher.c

    r1008 r1014  
    3535#include "polarssl/cipher_wrap.h" 
    3636 
    37 #include <string.h> 
    3837#include <stdlib.h> 
    3938 
     
    197196} 
    198197 
    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; 
     198int 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; 
    203202 
    204203    if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen || 
     
    287286} 
    288287 
    289 static void add_pkcs_padding( unsigned char *output, unsigned char output_len, 
    290         int data_len ) 
    291 { 
    292     unsigned char padding_len = output_len - data_len; 
     288static 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; 
    293292    unsigned char i = 0; 
    294293 
    295294    for( i = 0; i < padding_len; i++ ) 
    296         output[data_len + i] = padding_len; 
     295        output[data_len + i] = (unsigned char) padding_len; 
    297296} 
    298297 
    299298static int get_pkcs_padding( unsigned char *input, unsigned char input_len, 
    300         int *data_len) 
     299        size_t *data_len) 
    301300{ 
    302301    int i = 0; 
     
    320319} 
    321320 
    322 int cipher_finish( cipher_context_t *ctx, unsigned char *output, int *olen) 
     321int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen) 
    323322{ 
    324323    if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen ) 
  • trunk/library/cipher_wrap.c

    r1007 r1014  
    3737#include "polarssl/des.h" 
    3838 
    39 #include <string.h> 
    4039#include <stdlib.h> 
    4140 
    4241#if defined(POLARSSL_AES_C) 
    4342 
    44 int aes_crypt_cbc_wrap( void *ctx, operation_t operation, int length, 
     43int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 
    4544        unsigned char *iv, const unsigned char *input, unsigned char *output ) 
    4645{ 
     
    4847} 
    4948 
    50 int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length ) 
     49int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    5150{ 
    5251    return aes_setkey_dec( (aes_context *) ctx, key, key_length ); 
    5352} 
    5453 
    55 int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length ) 
     54int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    5655{ 
    5756    return aes_setkey_enc( (aes_context *) ctx, key, key_length ); 
     
    6968 
    7069const 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_free 
     70    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 
    8382}; 
    8483 
    8584const 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_free 
     85    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 
    9897}; 
    9998 
    10099const 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_free 
     100    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 
    113112}; 
    114113#endif 
     
    116115#if defined(POLARSSL_CAMELLIA_C) 
    117116 
    118 int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, int length, 
     117int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 
    119118        unsigned char *iv, const unsigned char *input, unsigned char *output ) 
    120119{ 
     
    122121} 
    123122 
    124 int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length ) 
     123int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    125124{ 
    126125    return camellia_setkey_dec( (camellia_context *) ctx, key, key_length ); 
    127126} 
    128127 
    129 int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length ) 
     128int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    130129{ 
    131130    return camellia_setkey_enc( (camellia_context *) ctx, key, key_length ); 
     
    143142 
    144143const 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_free 
     144    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 
    157156}; 
    158157 
    159158const 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_free 
     159    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 
    172171}; 
    173172 
    174173const 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_free 
     174    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 
    187186}; 
    188187#endif 
     
    190189#if defined(POLARSSL_DES_C) 
    191190 
    192 int des_crypt_cbc_wrap( void *ctx, operation_t operation, int length, 
     191int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 
    193192        unsigned char *iv, const unsigned char *input, unsigned char *output ) 
    194193{ 
     
    196195} 
    197196 
    198 int des3_crypt_cbc_wrap( void *ctx, operation_t operation, int length, 
     197int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, 
    199198        unsigned char *iv, const unsigned char *input, unsigned char *output ) 
    200199{ 
     
    202201} 
    203202 
    204 int des_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length ) 
     203int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    205204{ 
    206205    ((void) key_length); 
     
    209208} 
    210209 
    211 int des_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length ) 
     210int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    212211{ 
    213212    ((void) key_length); 
     
    216215} 
    217216 
    218 int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, int key_length ) 
     217int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    219218{ 
    220219    ((void) key_length); 
     
    223222} 
    224223 
    225 int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, int key_length ) 
     224int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    226225{ 
    227226    ((void) key_length); 
     
    230229} 
    231230 
    232 int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, int key_length ) 
     231int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    233232{ 
    234233    ((void) key_length); 
     
    237236} 
    238237 
    239 int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, int key_length ) 
     238int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) 
    240239{ 
    241240    ((void) key_length); 
     
    260259 
    261260const 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_free 
     261    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 
    274273}; 
    275274 
    276275const 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_free 
     276    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 
    289288}; 
    290289 
    291290const 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_free 
     291    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 
    304303}; 
    305304#endif 
  • trunk/library/debug.c

    r985 r1014  
    8888void debug_print_buf( const ssl_context *ssl, int level, 
    8989                      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 ) 
    9696        return; 
    9797 
     
    133133{ 
    134134    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; 
    136137 
    137138    if( ssl->f_dbg == NULL || X == NULL ) 
     
    153154    ssl->f_dbg( ssl->p_dbg, level, str ); 
    154155 
    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 ) 
    158159            continue; 
    159160 
    160161        for( k = sizeof( t_int ) - 1; k >= 0; k-- ) 
    161162        { 
    162             if( zeros && ( ( X->p[i] >> (k << 3) ) & 0xFF ) == 0 ) 
     163            if( zeros && ( ( X->p[i - 1] >> (k << 3) ) & 0xFF ) == 0 ) 
    163164                continue; 
    164165            else 
     
    177178 
    178179            snprintf( str, maxlen, " %02x", (unsigned int) 
    179                       ( X->p[i] >> (k << 3) ) & 0xFF ); 
     180                      ( X->p[i - 1] >> (k << 3) ) & 0xFF ); 
    180181 
    181182            str[maxlen] = '\0'; 
  • trunk/library/des.c

    r921 r1014  
    3535 
    3636#include "polarssl/des.h" 
    37  
    38 #include <string.h> 
    3937 
    4038/* 
     
    612610int des_crypt_cbc( des_context *ctx, 
    613611                    int mode, 
    614                     int length, 
     612                    size_t length, 
    615613                    unsigned char iv[8], 
    616614                    const unsigned char *input, 
     
    707705int des3_crypt_cbc( des3_context *ctx, 
    708706                     int mode, 
    709                      int length, 
     707                     size_t length, 
    710708                     unsigned char iv[8], 
    711709                     const unsigned char *input, 
  • trunk/library/dhm.c

    r1003 r1014  
    3434 
    3535#include "polarssl/dhm.h" 
    36  
    37 #include <string.h> 
    3836 
    3937/* 
     
    129127 */ 
    130128int dhm_make_params( dhm_context *ctx, int x_size, 
    131                      unsigned char *output, int *olen, 
     129                     unsigned char *output, size_t *olen, 
    132130                     int (*f_rng)(void *), void *p_rng ) 
    133131{ 
    134     int ret, n, n1, n2, n3; 
     132    int ret, n; 
     133    size_t n1, n2, n3; 
    135134    unsigned char *p; 
    136135 
     
    187186 */ 
    188187int dhm_read_public( dhm_context *ctx, 
    189                      const unsigned char *input, int ilen ) 
     188                     const unsigned char *input, size_t ilen ) 
    190189{ 
    191190    int ret; 
     
    204203 */ 
    205204int dhm_make_public( dhm_context *ctx, int x_size, 
    206                      unsigned char *output, int olen, 
     205                     unsigned char *output, size_t olen, 
    207206                     int (*f_rng)(void *), void *p_rng ) 
    208207{ 
     
    242241 */ 
    243242int dhm_calc_secret( dhm_context *ctx, 
    244                      unsigned char *output, int *olen ) 
     243                     unsigned char *output, size_t *olen ) 
    245244{ 
    246245    int ret; 
  • trunk/library/havege.c

    r1008 r1014  
    3535#if defined(POLARSSL_HAVEGE_C) 
    3636 
     37#include "polarssl/havege.h" 
     38#include "polarssl/timing.h" 
     39 
    3740#include <string.h> 
    3841#include <time.h> 
    39  
    40 #include "polarssl/havege.h" 
    41 #include "polarssl/timing.h" 
    4242 
    4343/* ------------------------------------------------------------------------ 
  • trunk/library/md.c

    r1008 r1014  
    3535#include "polarssl/md_wrap.h" 
    3636 
    37 #include <string.h> 
    3837#include <stdlib.h> 
    3938 
     
    191190} 
    192191 
    193 int md_update( md_context_t *ctx, const unsigned char *input, int ilen ) 
     192int md_update( md_context_t *ctx, const unsigned char *input, size_t ilen ) 
    194193{ 
    195194    if( ctx == NULL || ctx->md_info == NULL ) 
     
    211210} 
    212211 
    213 int md( const md_info_t *md_info, const unsigned char *input, int ilen, 
     212int md( const md_info_t *md_info, const unsigned char *input, size_t ilen, 
    214213            unsigned char *output ) 
    215214{ 
     
    230229} 
    231230 
    232 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, int keylen ) 
     231int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen ) 
    233232{ 
    234233    if( ctx == NULL || ctx->md_info == NULL ) 
     
    240239} 
    241240 
    242 int md_hmac_update( md_context_t *ctx, const unsigned char *input, int ilen ) 
     241int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen ) 
    243242{ 
    244243    if( ctx == NULL || ctx->md_info == NULL ) 
     
    270269} 
    271270 
    272 int md_hmac( const md_info_t *md_info, const unsigned char *key, int keylen, 
    273                 const unsigned char *input, int ilen, 
     271int md_hmac( const md_info_t *md_info, const unsigned char *key, size_t keylen, 
     272                const unsigned char *input, size_t ilen, 
    274273                unsigned char *output ) 
    275274{ 
  • trunk/library/md2.c

    r897 r1014  
    3636#include "polarssl/md2.h" 
    3737 
    38 #include <string.h> 
    3938#include <stdio.h> 
    4039 
     
    117116 * MD2 process buffer 
    118117 */ 
    119 void md2_update( md2_context *ctx, const unsigned char *input, int ilen ) 
    120 { 
    121     int fill; 
     118void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen ) 
     119{ 
     120    size_t fill; 
    122121 
    123122    while( ilen > 0 ) 
     
    147146void md2_finish( md2_context *ctx, unsigned char output[16] ) 
    148147{ 
    149     int i; 
     148    size_t i; 
    150149    unsigned char x; 
    151150 
     
    166165 * output = MD2( input buffer ) 
    167166 */ 
    168 void md2( const unsigned char *input, int ilen, unsigned char output[16] ) 
     167void md2( const unsigned char *input, size_t ilen, unsigned char output[16] ) 
    169168{ 
    170169    md2_context ctx; 
     
    212211 * MD2 HMAC context setup 
    213212 */ 
    214 void md2_hmac_starts( md2_context *ctx, const unsigned char *key, int keylen ) 
    215 { 
    216     int i; 
     213void md2_hmac_starts( md2_context *ctx, const unsigned char *key, size_t keylen ) 
     214{ 
     215    size_t i; 
    217216    unsigned char sum[16]; 
    218217 
     
    242241 * MD2 HMAC process buffer 
    243242 */ 
    244 void md2_hmac_update( md2_context *ctx, const unsigned char *input, int ilen ) 
     243void md2_hmac_update( md2_context *ctx, const unsigned char *input, size_t ilen ) 
    245244{ 
    246245    md2_update( ctx, input, ilen ); 
     
    275274 * output = HMAC-MD2( hmac key, input buffer ) 
    276275 */ 
    277 void md2_hmac( const unsigned char *key, int keylen, 
    278                const unsigned char *input, int ilen, 
     276void md2_hmac( const unsigned char *key, size_t keylen, 
     277               const unsigned char *input, size_t ilen, 
    279278               unsigned char output[16] ) 
    280279{ 
  • trunk/library/md4.c

    r897 r1014  
    3636#include "polarssl/md4.h" 
    3737 
    38 #include <string.h> 
    3938#include <stdio.h> 
    4039 
     
    182181 * MD4 process buffer 
    183182 */ 
    184 void md4_update( md4_context *ctx, const unsigned char *input, int ilen ) 
    185 { 
    186     int fill; 
     183void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen ) 
     184{ 
     185    size_t fill; 
    187186    unsigned long left; 
    188187 
     
    193192    fill = 64 - left; 
    194193 
    195     ctx->total[0] += ilen; 
     194    ctx->total[0] += (unsigned long) ilen; 
    196195    ctx->total[0] &= 0xFFFFFFFF; 
    197196 
     
    262261 * output = MD4( input buffer ) 
    263262 */ 
    264 void md4( const unsigned char *input, int ilen, unsigned char output[16] ) 
     263void md4( const unsigned char *input, size_t ilen, unsigned char output[16] ) 
    265264{ 
    266265    md4_context ctx; 
     
    308307 * MD4 HMAC context setup 
    309308 */ 
    310 void md4_hmac_starts( md4_context *ctx, const unsigned char *key, int keylen ) 
    311 { 
    312     int i; 
     309void md4_hmac_starts( md4_context *ctx, const unsigned char *key, size_t keylen ) 
     310{ 
     311    size_t i; 
    313312    unsigned char sum[16]; 
    314313 
     
    338337 * MD4 HMAC process buffer 
    339338 */ 
    340 void md4_hmac_update( md4_context *ctx, const unsigned char *input, int ilen ) 
     339void md4_hmac_update( md4_context *ctx, const unsigned char *input, size_t ilen ) 
    341340{ 
    342341    md4_update( ctx, input, ilen ); 
     
    371370 * output = HMAC-MD4( hmac key, input buffer ) 
    372371 */ 
    373 void md4_hmac( const unsigned char *key, int keylen, 
    374                const unsigned char *input, int ilen, 
     372void md4_hmac( const unsigned char *key, size_t keylen, 
     373               const unsigned char *input, size_t ilen, 
    375374               unsigned char output[16] ) 
    376375{ 
  • trunk/library/md5.c

    r897 r1014  
    3535#include "polarssl/md5.h" 
    3636 
    37 #include <string.h> 
    3837#include <stdio.h> 
    3938 
     
    201200 * MD5 process buffer 
    202201 */ 
    203 void md5_update( md5_context *ctx, const unsigned char *input, int ilen ) 
    204 { 
    205     int fill; 
     202void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen ) 
     203{ 
     204    size_t fill; 
    206205    unsigned long left; 
    207206 
     
    212211    fill = 64 - left; 
    213212 
    214     ctx->total[0] += ilen; 
     213    ctx->total[0] += (unsigned long) ilen; 
    215214    ctx->total[0] &= 0xFFFFFFFF; 
    216215 
     
    281280 * output = MD5( input buffer ) 
    282281 */ 
    283 void md5( const unsigned char *input, int ilen, unsigned char output[16] ) 
     282void md5( const unsigned char *input, size_t ilen, unsigned char output[16] ) 
    284283{ 
    285284    md5_context ctx; 
     
    327326 * MD5 HMAC context setup 
    328327 */ 
    329 void md5_hmac_starts( md5_context *ctx, const unsigned char *key, int keylen ) 
    330 { 
    331     int i; 
     328void md5_hmac_starts( md5_context *ctx, const unsigned char *key, size_t keylen ) 
     329{ 
     330    size_t i; 
    332331    unsigned char sum[16]; 
    333332 
     
    357356 * MD5 HMAC process buffer 
    358357 */ 
    359 void md5_hmac_update( md5_context *ctx, const unsigned char *input, int ilen ) 
     358void md5_hmac_update( md5_context *ctx, const unsigned char *input, size_t ilen ) 
    360359{ 
    361360    md5_update( ctx, input, ilen ); 
     
    390389 * output = HMAC-MD5( hmac key, input buffer ) 
    391390 */ 
    392 void md5_hmac( const unsigned char *key, int keylen, 
    393                const unsigned char *input, int ilen, 
     391void md5_hmac( const unsigned char *key, size_t keylen, 
     392               const unsigned char *input, size_t ilen, 
    394393               unsigned char output[16] ) 
    395394{ 
  • trunk/library/md_wrap.c

    r1007 r1014  
    4040#include "polarssl/sha4.h" 
    4141 
    42 #include <string.h> 
    4342#include <stdlib.h> 
    4443 
     
    5049} 
    5150 
    52 static void md2_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     51static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    5352{ 
    5453    md2_update( (md2_context *) ctx, input, ilen ); 
     
    6059} 
    6160 
    62 static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     61static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    6362{ 
    6463    md2_hmac_starts( (md2_context *) ctx, key, keylen ); 
    6564} 
    6665 
    67 static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     66static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    6867{ 
    6968    md2_hmac_update( (md2_context *) ctx, input, ilen ); 
     
    9190 
    9291const 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, 
    108107}; 
    109108 
     
    117116} 
    118117 
    119 void md4_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     118void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    120119{ 
    121120    md4_update( (md4_context *) ctx, input, ilen ); 
     
    127126} 
    128127 
    129 void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     128void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    130129{ 
    131130    md4_hmac_starts( (md4_context *) ctx, key, keylen ); 
    132131} 
    133132 
    134 void md4_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     133void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    135134{ 
    136135    md4_hmac_update( (md4_context *) ctx, input, ilen ); 
     
    158157 
    159158const 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, 
    175174}; 
    176175 
     
    184183} 
    185184 
    186 static void md5_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     185static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    187186{ 
    188187    md5_update( (md5_context *) ctx, input, ilen ); 
     
    194193} 
    195194 
    196 static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     195static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    197196{ 
    198197    md5_hmac_starts( (md5_context *) ctx, key, keylen ); 
    199198} 
    200199 
    201 static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     200static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    202201{ 
    203202    md5_hmac_update( (md5_context *) ctx, input, ilen ); 
     
    225224 
    226225const 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, 
    242241}; 
    243242 
     
    251250} 
    252251 
    253 void sha1_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     252void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    254253{ 
    255254    sha1_update( (sha1_context *) ctx, input, ilen ); 
     
    261260} 
    262261 
    263 void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     262void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    264263{ 
    265264    sha1_hmac_starts( (sha1_context *) ctx, key, keylen ); 
    266265} 
    267266 
    268 void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     267void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    269268{ 
    270269    sha1_hmac_update( (sha1_context *) ctx, input, ilen ); 
     
    292291 
    293292const 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, 
    309308}; 
    310309 
     
    321320} 
    322321 
    323 void sha224_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     322void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    324323{ 
    325324    sha2_update( (sha2_context *) ctx, input, ilen ); 
     
    331330} 
    332331 
    333 void sha224_wrap( const unsigned char *input, int ilen, 
     332void sha224_wrap( const unsigned char *input, size_t ilen, 
    334333                    unsigned char *output ) 
    335334{ 
     
    342341} 
    343342 
    344 void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     343void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    345344{ 
    346345    sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 ); 
    347346} 
    348347 
    349 void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     348void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    350349{ 
    351350    sha2_hmac_update( (sha2_context *) ctx, input, ilen ); 
     
    362361} 
    363362 
    364 void sha224_hmac_wrap( const unsigned char *key, int keylen, 
    365         const unsigned char *input, int ilen, 
     363void sha224_hmac_wrap( const unsigned char *key, size_t keylen, 
     364        const unsigned char *input, size_t ilen, 
    366365        unsigned char *output ) 
    367366{ 
     
    380379 
    381380const 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, 
    397396}; 
    398397 
     
    402401} 
    403402 
    404 void sha256_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     403void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    405404{ 
    406405    sha2_update( (sha2_context *) ctx, input, ilen ); 
     
    412411} 
    413412 
    414 void sha256_wrap( const unsigned char *input, int ilen, 
     413void sha256_wrap( const unsigned char *input, size_t ilen, 
    415414                    unsigned char *output ) 
    416415{ 
     
    423422} 
    424423 
    425 void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     424void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    426425{ 
    427426    sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 ); 
    428427} 
    429428 
    430 void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     429void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    431430{ 
    432431    sha2_hmac_update( (sha2_context *) ctx, input, ilen ); 
     
    443442} 
    444443 
    445 void sha256_hmac_wrap( const unsigned char *key, int keylen, 
    446         const unsigned char *input, int ilen, 
     444void sha256_hmac_wrap( const unsigned char *key, size_t keylen, 
     445        const unsigned char *input, size_t ilen, 
    447446        unsigned char *output ) 
    448447{ 
     
    461460 
    462461const 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, 
    478477}; 
    479478 
     
    487486} 
    488487 
    489 void sha384_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     488void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    490489{ 
    491490    sha4_update( (sha4_context *) ctx, input, ilen ); 
     
    497496} 
    498497 
    499 void sha384_wrap( const unsigned char *input, int ilen, 
     498void sha384_wrap( const unsigned char *input, size_t ilen, 
    500499                    unsigned char *output ) 
    501500{ 
     
    508507} 
    509508 
    510 void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     509void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    511510{ 
    512511    sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 ); 
    513512} 
    514513 
    515 void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     514void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    516515{ 
    517516    sha4_hmac_update( (sha4_context *) ctx, input, ilen ); 
     
    528527} 
    529528 
    530 void sha384_hmac_wrap( const unsigned char *key, int keylen, 
    531         const unsigned char *input, int ilen, 
     529void sha384_hmac_wrap( const unsigned char *key, size_t keylen, 
     530        const unsigned char *input, size_t ilen, 
    532531        unsigned char *output ) 
    533532{ 
     
    546545 
    547546const 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, 
    563562}; 
    564563 
     
    568567} 
    569568 
    570 void sha512_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     569void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    571570{ 
    572571    sha4_update( (sha4_context *) ctx, input, ilen ); 
     
    578577} 
    579578 
    580 void sha512_wrap( const unsigned char *input, int ilen, 
     579void sha512_wrap( const unsigned char *input, size_t ilen, 
    581580                    unsigned char *output ) 
    582581{ 
     
    589588} 
    590589 
    591 void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, int keylen ) 
     590void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 
    592591{ 
    593592    sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 ); 
    594593} 
    595594 
    596 void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, int ilen ) 
     595void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 
    597596{ 
    598597    sha4_hmac_update( (sha4_context *) ctx, input, ilen ); 
     
    609608} 
    610609 
    611 void sha512_hmac_wrap( const unsigned char *key, int keylen, 
    612         const unsigned char *input, int ilen, 
     610void sha512_hmac_wrap( const unsigned char *key, size_t keylen, 
     611        const unsigned char *input, size_t ilen, 
    613612        unsigned char *output ) 
    614613{ 
     
    627626 
    628627const 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, 
    644643}; 
    645644 
  • trunk/library/net.c

    r897 r1014  
    4141#endif 
    4242 
    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) 
    4545#define close(fd)               closesocket(fd) 
    4646 
     
    7070#endif 
    7171 
    72 #include <string.h> 
    7372#include <stdlib.h> 
    7473#include <stdio.h> 
     
    290289 * Read at most 'len' characters 
    291290 */ 
    292 int net_recv( void *ctx, unsigned char *buf, int len ) 
     291int net_recv( void *ctx, unsigned char *buf, size_t len ) 
    293292{  
    294293    int ret = read( *((int *) ctx), buf, len ); 
     
    322321 * Write at most 'len' characters 
    323322 */ 
    324 int net_send( void *ctx, unsigned char *buf, int len ) 
     323int net_send( void *ctx, unsigned char *buf, size_t len ) 
    325324{ 
    326325    int ret = write( *((int *) ctx), buf, len ); 
  • trunk/library/padlock.c

    r897 r1014  
    3434#if defined(POLARSSL_PADLOCK_C) 
    3535 
    36 #include "polarssl/aes.h" 
    3736#include "polarssl/padlock.h" 
    3837 
    3938#if defined(POLARSSL_HAVE_X86) 
    40  
    41 #include <string.h> 
    4239 
    4340/* 
     
    116113int padlock_xcryptcbc( aes_context *ctx, 
    117114                       int mode, 
    118                        int length, 
     115                       size_t length, 
    119116                       unsigned char iv[16], 
    120117                       const unsigned char *input, 
    121118                       unsigned char *output ) 
    122119{ 
    123     int ebx, count; 
     120    int ebx; 
     121    size_t count; 
    124122    unsigned long *rk; 
    125123    unsigned long *iw; 
  • trunk/library/pem.c

    r956 r1014  
    3636 
    3737#include <stdlib.h> 
    38 #include <string.h> 
    3938 
    4039void pem_init( pem_context *ctx ) 
     
    4746 * Read a 16-byte hex string and convert it to binary 
    4847 */ 
    49 static int pem_get_iv( const unsigned char *s, unsigned char *iv, int iv_len ) 
    50 { 
    51     int i, j, k; 
     48static int pem_get_iv( const unsigned char *s, unsigned char *iv, size_t iv_len ) 
     49{ 
     50    size_t i, j, k; 
    5251 
    5352    memset( iv, 0, iv_len ); 
     
    6867} 
    6968 
    70 static void pem_pbkdf1( unsigned char *key, int keylen, 
     69static void pem_pbkdf1( unsigned char *key, size_t keylen, 
    7170                        unsigned char *iv, 
    72                         const unsigned char *pwd, int pwdlen ) 
     71                        const unsigned char *pwd, size_t pwdlen ) 
    7372{ 
    7473    md5_context md5_ctx; 
    7574    unsigned char md5sum[16]; 
    76     int use_len; 
     75    size_t use_len; 
    7776 
    7877    /* 
     
    119118 */ 
    120119static 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 ) 
    123122{ 
    124123    des_context des_ctx; 
     
    139138 */ 
    140139static 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 ) 
    143142{ 
    144143    des3_context des3_ctx; 
     
    160159 * Decrypt with AES-XXX-CBC, using PBKDF1 for key derivation 
    161160 */ 
    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 ) 
     161static 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 ) 
    165164{ 
    166165    aes_context aes_ctx; 
     
    180179#endif /* POLARSSL_MD5_C && (POLARSSL_AES_C || POLARSSL_DES_C) */ 
    181180 
    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; 
     181int 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; 
    185185    unsigned char *buf; 
    186186    unsigned char *s1, *s2; 
  • trunk/library/pkcs11.c

    r932 r1014  
    3333 
    3434#include <stdlib.h> 
    35 #include <string.h> 
    3635 
    3736int pkcs11_x509_cert_init( x509_cert *cert, pkcs11h_certificate_t pkcs11_cert ) 
     
    114113 
    115114int pkcs11_decrypt( pkcs11_context *ctx, 
    116                        int mode, int *olen, 
     115                       int mode, size_t *olen, 
    117116                       const unsigned char *input, 
    118117                       unsigned char *output, 
     
    154153                    int mode, 
    155154                    int hash_id, 
    156                     int hashlen, 
     155                    unsigned int hashlen, 
    157156                    const unsigned char *hash, 
    158157                    unsigned char *sig ) 
  • trunk/library/rsa.c

    r999 r1014  
    3838 
    3939#include <stdlib.h> 
    40 #include <string.h> 
    4140#include <stdio.h> 
    4241 
     
    6261        int (*f_rng)(void *), 
    6362        void *p_rng, 
    64         int nbits, int exponent ) 
     63        unsigned int nbits, int exponent ) 
    6564{ 
    6665    int ret; 
     
    207206                unsigned char *output ) 
    208207{ 
    209     int ret, olen; 
     208    int ret; 
     209    size_t olen; 
    210210    mpi T; 
    211211 
     
    241241                 unsigned char *output ) 
    242242{ 
    243     int ret, olen; 
     243    int ret; 
     244    size_t olen; 
    244245    mpi T, T1, T2; 
    245246 
     
    302303 * @param slen      length of the source buffer 
    303304 * @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 */ 
     306static void mgf_mask( unsigned char *dst, size_t dlen, unsigned char *src, size_t slen,   
    307307                       md_context_t *md_ctx ) 
    308308{ 
     
    310310    unsigned char counter[4]; 
    311311    unsigned char *p; 
    312     int i, use_len, hlen; 
     312    unsigned int hlen; 
     313    size_t i, use_len; 
    313314 
    314315    memset( mask, 0, POLARSSL_MD_MAX_SIZE ); 
     
    348349                       int (*f_rng)(void *), 
    349350                       void *p_rng, 
    350                        int mode, int ilen, 
     351                       int mode, size_t ilen, 
    351352                       const unsigned char *input, 
    352353                       unsigned char *output ) 
    353354{ 
    354     int nb_pad, olen; 
     355    size_t nb_pad, olen; 
    355356    unsigned char *p = output; 
    356357#if defined(POLARSSL_PKCS1_V21) 
     358    unsigned int i, hlen; 
    357359    const md_info_t *md_info; 
    358360    md_context_t md_ctx; 
    359     int i, hlen; 
    360361#endif 
    361362 
     
    369370        case RSA_PKCS_V15: 
    370371 
    371             if( ilen < 0 || olen < ilen + 11 ) 
     372            if( olen < ilen + 11 ) 
    372373                return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); 
    373374 
     
    405406            hlen = md_get_size( md_info ); 
    406407 
    407             if( ilen < 0 || olen < ilen + 2 * hlen + 2 || f_rng == NULL ) 
     408            if( olen < ilen + 2 * hlen + 2 || f_rng == NULL ) 
    408409                return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); 
    409410 
     
    454455 */ 
    455456int rsa_pkcs1_decrypt( rsa_context *ctx, 
    456                        int mode, int *olen, 
     457                       int mode, size_t *olen, 
    457458                       const unsigned char *input, 
    458459                       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; 
    462464    unsigned char *p; 
    463465    unsigned char buf[1024]; 
    464466#if defined(POLARSSL_PKCS1_V21) 
    465467    unsigned char lhash[POLARSSL_MD_MAX_SIZE]; 
     468    unsigned int hlen; 
    466469    const md_info_t *md_info; 
    467470    md_context_t md_ctx; 
    468     int hlen; 
    469471#endif 
    470472 
     
    555557 
    556558    if (ilen - (int)(p - buf) > output_max_len) 
    557         return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE ); 
     559        return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE ); 
    558560 
    559561    *olen = ilen - (int)(p - buf); 
     
    571573                    int mode, 
    572574                    int hash_id, 
    573                     int hashlen, 
     575                    unsigned int hashlen, 
    574576                    const unsigned char *hash, 
    575577                    unsigned char *sig ) 
    576578{ 
    577     int nb_pad, olen; 
     579    size_t nb_pad, olen; 
    578580    unsigned char *p = sig; 
    579581#if defined(POLARSSL_PKCS1_V21) 
    580582    unsigned char salt[POLARSSL_MD_MAX_SIZE]; 
     583    unsigned int i, slen, hlen, offset = 0; 
     584    size_t msb; 
    581585    const md_info_t *md_info; 
    582586    md_context_t md_ctx; 
    583     int i, slen, hlen, msb, offset = 0; 
    584587#else 
    585588    (void) f_rng; 
     
    797800                      int mode, 
    798801                      int hash_id, 
    799                       int hashlen, 
     802                      unsigned int hashlen, 
    800803                      const unsigned char *hash, 
    801804                      unsigned char *sig ) 
    802805{ 
    803     int ret, len, siglen; 
     806    int ret; 
     807    size_t len, siglen; 
    804808    unsigned char *p, c; 
    805809    unsigned char buf[1024]; 
    806810#if defined(POLARSSL_PKCS1_V21) 
    807811    unsigned char zeros[8]; 
     812    unsigned int hlen; 
     813    size_t slen, msb; 
    808814    const md_info_t *md_info; 
    809815    md_context_t md_ctx; 
    810     int slen, hlen, msb; 
    811816#endif 
    812817    siglen = ctx->len; 
     
    10791084int rsa_self_test( int verbose ) 
    10801085{ 
    1081     int len; 
     1086    size_t len; 
    10821087    rsa_context rsa; 
    10831088    unsigned char sha1sum[20]; 
     
    11291134    if( rsa_pkcs1_decrypt( &rsa, RSA_PRIVATE, &len, 
    11301135                           rsa_ciphertext, rsa_decrypted, 
    1131                            sizeof(rsa_decrypted) ) != 0 ) 
     1136                           sizeof(rsa_decrypted) ) != 0 ) 
    11321137    { 
    11331138        if( verbose != 0 ) 
  • trunk/library/sha1.c

    r897 r1014  
    3535#include "polarssl/sha1.h" 
    3636 
    37 #include <string.h> 
    3837#include <stdio.h> 
    3938 
     
    235234 * SHA-1 process buffer 
    236235 */ 
    237 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ) 
    238 { 
    239     int fill; 
     236void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen ) 
     237{ 
     238    size_t fill; 
    240239    unsigned long left; 
    241240 
     
    246245    fill = 64 - left; 
    247246 
    248     ctx->total[0] += ilen; 
     247    ctx->total[0] += (unsigned long) ilen; 
    249248    ctx->total[0] &= 0xFFFFFFFF; 
    250249 
     
    316315 * output = SHA-1( input buffer ) 
    317316 */ 
    318 void sha1( const unsigned char *input, int ilen, unsigned char output[20] ) 
     317void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ) 
    319318{ 
    320319    sha1_context ctx; 
     
    362361 * SHA-1 HMAC context setup 
    363362 */ 
    364 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen ) 
    365 { 
    366     int i; 
     363void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen ) 
     364{ 
     365    size_t i; 
    367366    unsigned char sum[20]; 
    368367 
     
    392391 * SHA-1 HMAC process buffer 
    393392 */ 
    394 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen ) 
     393void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen ) 
    395394{ 
    396395    sha1_update( ctx, input, ilen ); 
     
    425424 * output = HMAC-SHA-1( hmac key, input buffer ) 
    426425 */ 
    427 void sha1_hmac( const unsigned char *key, int keylen, 
    428                 const unsigned char *input, int ilen, 
     426void sha1_hmac( const unsigned char *key, size_t keylen, 
     427                const unsigned char *input, size_t ilen, 
    429428                unsigned char output[20] ) 
    430429{ 
  • trunk/library/sha2.c

    r897 r1014  
    3535#include "polarssl/sha2.h" 
    3636 
    37 #include <string.h> 
    3837#include <stdio.h> 
    3938 
     
    231230 * SHA-256 process buffer 
    232231 */ 
    233 void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen ) 
    234 { 
    235     int fill; 
     232void sha2_update( sha2_context *ctx, const unsigned char *input, size_t ilen ) 
     233{ 
     234    size_t fill; 
    236235    unsigned long left; 
    237236 
     
    242241    fill = 64 - left; 
    243242 
    244     ctx->total[0] += ilen; 
     243    ctx->total[0] += (unsigned long) ilen; 
    245244    ctx->total[0] &= 0xFFFFFFFF; 
    246245 
     
    317316 * output = SHA-256( input buffer ) 
    318317 */ 
    319 void sha2( const unsigned char *input, int ilen, 
     318void sha2( const unsigned char *input, size_t ilen, 
    320319           unsigned char output[32], int is224 ) 
    321320{ 
     
    364363 * SHA-256 HMAC context setup 
    365364 */ 
    366 void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, int keylen, 
     365void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, size_t keylen, 
    367366                       int is224 ) 
    368367{ 
    369     int i; 
     368    size_t i; 
    370369    unsigned char sum[32]; 
    371370 
     
    395394 * SHA-256 HMAC process buffer 
    396395 */ 
    397 void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, int ilen ) 
     396void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, size_t ilen ) 
    398397{ 
    399398    sha2_update( ctx, input, ilen ); 
     
    432431 * output = HMAC-SHA-256( hmac key, input buffer ) 
    433432 */ 
    434 void sha2_hmac( const unsigned char *key, int keylen, 
    435                 const unsigned char *input, int ilen, 
     433void sha2_hmac( const unsigned char *key, size_t keylen, 
     434                const unsigned char *input, size_t ilen, 
    436435                unsigned char output[32], int is224 ) 
    437436{ 
  • trunk/library/sha4.c

    r897 r1014  
    3535#include "polarssl/sha4.h" 
    3636 
    37 #include <string.h> 
    3837#include <stdio.h> 
    3938 
     
    224223 * SHA-512 process buffer 
    225224 */ 
    226 void sha4_update( sha4_context *ctx, const unsigned char *input, int ilen ) 
    227 { 
    228     int fill; 
     225void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen ) 
     226{ 
     227    size_t fill; 
    229228    unsigned int64 left; 
    230229 
     
    235234    fill = (int)( 128 - left ); 
    236235 
    237     ctx->total[0] += ilen; 
     236    ctx->total[0] += (unsigned int64) ilen; 
    238237 
    239238    if( ctx->total[0] < (unsigned int64) ilen ) 
     
    315314 * output = SHA-512( input buffer ) 
    316315 */ 
    317 void sha4( const unsigned char *input, int ilen, 
     316void sha4( const unsigned char *input, size_t ilen, 
    318317           unsigned char output[64], int is384 ) 
    319318{ 
     
    362361 * SHA-512 HMAC context setup 
    363362 */ 
    364 void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, int keylen, 
     363void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, size_t keylen, 
    365364                       int is384 ) 
    366365{ 
    367     int i; 
     366    size_t i; 
    368367    unsigned char sum[64]; 
    369368 
     
    394393 */ 
    395394void sha4_hmac_update( sha4_context  *ctx, 
    396                        const unsigned char *input, int ilen ) 
     395                       const unsigned char *input, size_t ilen ) 
    397396{ 
    398397    sha4_update( ctx, input, ilen ); 
     
    431430 * output = HMAC-SHA-512( hmac key, input buffer ) 
    432431 */ 
    433 void sha4_hmac( const unsigned char *key, int keylen, 
    434                 const unsigned char *input, int ilen, 
     432void sha4_hmac( const unsigned char *key, size_t keylen, 
     433                const unsigned char *input, size_t ilen, 
    435434                unsigned char output[64], int is384 ) 
    436435{ 
  • trunk/library/ssl_cli.c

    r1003 r1014  
    3535#endif /* defined(POLARSSL_PKCS11_C) */ 
    3636 
    37 #include <string.h> 
    3837#include <stdlib.h> 
    3938#include <stdio.h> 
     
    4241static int ssl_write_client_hello( ssl_context *ssl ) 
    4342{ 
    44     int ret, i, n; 
     43    int ret; 
     44    size_t i, n; 
    4545    unsigned char *buf; 
    4646    unsigned char *p; 
     
    175175{ 
    176176    time_t t; 
    177     int ret, i, n; 
     177    int ret, i; 
     178    size_t n; 
    178179    int ext_len; 
    179180    unsigned char *buf; 
     
    241242     *   44+n . 44+n+m extensions 
    242243     */ 
    243     if( n < 0 || n > 32 || ssl->in_hslen > 42 + n ) 
     244    if( n > 32 || ssl->in_hslen > 42 + n ) 
    244245    { 
    245246        ext_len = ( ( buf[42 + n] <<  8 ) 
     
    251252    } 
    252253 
    253     if( n < 0 || n > 32 || ssl->in_hslen != 42 + n + ext_len ) 
     254    if( n > 32 || ssl->in_hslen != 42 + n + ext_len ) 
    254255    { 
    255256        SSL_DEBUG_MSG( 1, ( "bad server hello message" ) ); 
     
    322323static int ssl_parse_server_key_exchange( ssl_context *ssl ) 
    323324{ 
    324     int ret, n; 
     325    int ret; 
     326    size_t n; 
    325327    unsigned char *p, *end; 
    326328    unsigned char hash[36]; 
     
    334336        ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA && 
    335337        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) 
    337339    { 
    338340        SSL_DEBUG_MSG( 2, ( "<= skip parse server key exchange" ) ); 
     
    381383    } 
    382384 
    383     if( (int)( end - p ) != ssl->peer_cert->rsa.len ) 
     385    if( (unsigned int)( end - p ) != ssl->peer_cert->rsa.len ) 
    384386    { 
    385387        SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) ); 
     
    519521static int ssl_write_client_key_exchange( ssl_context *ssl ) 
    520522{ 
    521     int ret, i, n; 
     523    int ret; 
     524    size_t i, n; 
    522525 
    523526    SSL_DEBUG_MSG( 2, ( "=> write client key exchange" ) ); 
     
    527530        ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA || 
    528531        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) 
    530533    { 
    531534#if !defined(POLARSSL_DHM_C) 
     
    626629static int ssl_write_certificate_verify( ssl_context *ssl ) 
    627630{ 
    628     int ret = 0, n = 0; 
     631    int ret = 0; 
     632    size_t n = 0; 
    629633    unsigned char hash[36]; 
    630634 
  • trunk/library/ssl_srv.c

    r1003 r1014  
    3535#endif /* defined(POLARSSL_PKCS11_C) */ 
    3636 
    37 #include <string.h> 
    3837#include <stdlib.h> 
    3938#include <stdio.h> 
     
    4241static int ssl_parse_client_hello( ssl_context *ssl ) 
    4342{ 
    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; 
    4748    unsigned char *buf, *p; 
    4849 
     
    138139        } 
    139140 
    140         if( sess_len < 0 || sess_len > 32 ) 
     141        if( sess_len > 32 ) 
    141142        { 
    142143            SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); 
     
    274275         * Check the handshake message length 
    275276         */ 
    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] ) ) 
    277278        { 
    278279            SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); 
     
    285286        sess_len = buf[38]; 
    286287 
    287         if( sess_len < 0 || sess_len > 32 ) 
     288        if( sess_len > 32 ) 
    288289        { 
    289290            SSL_DEBUG_MSG( 1, ( "bad client hello message" ) ); 
     
    461462static int ssl_write_certificate_request( ssl_context *ssl ) 
    462463{ 
    463     int ret, n; 
     464    int ret; 
     465    size_t n; 
    464466    unsigned char *buf, *p; 
    465467    const x509_cert *crt; 
     
    526528static int ssl_write_server_key_exchange( ssl_context *ssl ) 
    527529{ 
    528     int ret, n, rsa_key_len = 0; 
     530    int ret; 
     531    size_t n, rsa_key_len = 0; 
    529532    unsigned char hash[36]; 
    530533    md5_context md5; 
     
    537540        ssl->session->ciphersuite != SSL_EDH_RSA_AES_256_SHA && 
    538541        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) 
    540543    { 
    541544        SSL_DEBUG_MSG( 2, ( "<= skip write server key exchange" ) ); 
     
    682685static int ssl_parse_client_key_exchange( ssl_context *ssl ) 
    683686{ 
    684     int ret, i, n = 0; 
     687    int ret; 
     688    size_t i, n = 0; 
    685689 
    686690    SSL_DEBUG_MSG( 2, ( "=> parse client key exchange" ) ); 
     
    708712        ssl->session->ciphersuite == SSL_EDH_RSA_AES_256_SHA || 
    709713        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) 
    711715    { 
    712716#if !defined(POLARSSL_DHM_C) 
     
    841845static int ssl_parse_certificate_verify( ssl_context *ssl ) 
    842846{ 
    843     int n1, n2, ret; 
     847    int ret; 
     848    size_t n1, n2; 
    844849    unsigned char hash[36]; 
    845850 
  • trunk/library/ssl_tls.c

    r1008 r1014  
    4343#include "polarssl/ssl.h" 
    4444 
    45 #include <string.h> 
    4645#include <stdlib.h> 
    4746#include <time.h> 
     
    5453 * Key material generation 
    5554 */ 
    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; 
     55static 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; 
    6261    unsigned char *S1, *S2; 
    6362    unsigned char tmp[128]; 
     
    140139    if( ssl->resume == 0 ) 
    141140    { 
    142         int len = ssl->pmslen; 
     141        size_t len = ssl->pmslen; 
    143142 
    144143        SSL_DEBUG_BUF( 3, "premaster secret", ssl->premaster, len ); 
     
    432431 */ 
    433432static void ssl_mac_md5( unsigned char *secret, 
    434                          unsigned char *buf, int len, 
     433                         unsigned char *buf, size_t len, 
    435434                         unsigned char *ctr, int type ) 
    436435{ 
     
    461460 
    462461static void ssl_mac_sha1( unsigned char *secret, 
    463                           unsigned char *buf, int len, 
     462                          unsigned char *buf, size_t len, 
    464463                          unsigned char *ctr, int type ) 
    465464{ 
     
    494493static int ssl_encrypt_buf( ssl_context *ssl ) 
    495494{ 
    496     int i, padlen; 
     495    size_t i, padlen; 
    497496 
    498497    SSL_DEBUG_MSG( 2, ( "=> encrypt buf" ) ); 
     
    531530    ssl->out_msglen += ssl->maclen; 
    532531 
    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 ) 
    535534            break; 
    536535 
     
    557556    { 
    558557        unsigned char *enc_msg; 
    559         int enc_msglen; 
     558        size_t enc_msglen; 
    560559 
    561560        padlen = ssl->ivlen - ( ssl->out_msglen + 1 ) % ssl->ivlen; 
     
    616615            case 16: 
    617616#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        { 
    623622                    aes_crypt_cbc( (aes_context *) ssl->ctx_enc, 
    624623                        AES_ENCRYPT, enc_msglen, 
    625624                        ssl->iv_enc, enc_msg, enc_msg); 
    626625                    break; 
    627                 } 
     626        } 
    628627#endif 
    629628 
    630629#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        { 
    636635                    camellia_crypt_cbc( (camellia_context *) ssl->ctx_enc, 
    637636                        CAMELLIA_ENCRYPT, enc_msglen, 
    638637                        ssl->iv_enc, enc_msg, enc_msg ); 
    639638                    break; 
    640                 } 
     639        } 
    641640#endif 
    642641 
     
    653652static int ssl_decrypt_buf( ssl_context *ssl ) 
    654653{ 
    655     int i, padlen; 
     654    size_t i, padlen; 
    656655    unsigned char tmp[20]; 
    657656 
     
    680679        unsigned char *dec_msg; 
    681680        unsigned char *dec_msg_result; 
    682         int dec_msglen; 
     681        size_t dec_msglen; 
    683682 
    684683        /* 
     
    721720            case 16: 
    722721#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        { 
    728727                    aes_crypt_cbc( (aes_context *) ssl->ctx_dec, 
    729728                       AES_DECRYPT, dec_msglen, 
    730729                       ssl->iv_dec, dec_msg, dec_msg_result ); 
    731730                    break; 
    732                 } 
     731        } 
    733732#endif 
    734733 
    735734#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        { 
    741740                    camellia_crypt_cbc( (camellia_context *) ssl->ctx_dec, 
    742741                       CAMELLIA_DECRYPT, dec_msglen, 
    743742                       ssl->iv_dec, dec_msg, dec_msg_result ); 
    744743                    break; 
    745                 } 
     744        } 
    746745#endif 
    747746 
     
    852851        ssl->nb_zero = 0; 
    853852             
    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 ) 
    856855            break; 
    857856 
     
    864863 * Fill the input message buffer 
    865864 */ 
    866 int ssl_fetch_input( ssl_context *ssl, int nb_want ) 
    867 { 
    868     int ret, len; 
     865int ssl_fetch_input( ssl_context *ssl, size_t nb_want ) 
     866{ 
     867    int ret; 
     868    size_t len; 
    869869 
    870870    SSL_DEBUG_MSG( 2, ( "=> fetch input" ) ); 
     
    925925int ssl_write_record( ssl_context *ssl ) 
    926926{ 
    927     int ret, len = ssl->out_msglen; 
     927    int ret; 
     928    size_t len = ssl->out_msglen; 
    928929 
    929930    SSL_DEBUG_MSG( 2, ( "=> write record" ) ); 
     
    11821183int ssl_write_certificate( ssl_context *ssl ) 
    11831184{ 
    1184     int ret, i, n; 
     1185    int ret; 
     1186    size_t i, n; 
    11851187    const x509_cert *crt; 
    11861188 
     
    12781280int ssl_parse_certificate( ssl_context *ssl ) 
    12791281{ 
    1280     int ret, i, n; 
     1282    int ret; 
     1283    size_t i, n; 
    12811284 
    12821285    SSL_DEBUG_MSG( 2, ( "=> parse certificate" ) ); 
     
    16221625int ssl_parse_finished( ssl_context *ssl ) 
    16231626{ 
    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; 
    16261631    sha1_context sha1; 
    1627     unsigned char buf[36]; 
    16281632 
    16291633    SSL_DEBUG_MSG( 2, ( "=> parse finished" ) ); 
     
    17591763 
    17601764void 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 ) 
    17631767{ 
    17641768    ssl->f_recv     = f_recv; 
     
    18701874 * SSL get accessors 
    18711875 */ 
    1872 int ssl_get_bytes_avail( const ssl_context *ssl ) 
     1876size_t ssl_get_bytes_avail( const ssl_context *ssl ) 
    18731877{ 
    18741878    return( ssl->in_offt == NULL ? 0 : ssl->in_msglen ); 
     
    20652069 * Receive application data decrypted from the SSL layer 
    20662070 */ 
    2067 int ssl_read( ssl_context *ssl, unsigned char *buf, int len ) 
    2068 { 
    2069     int ret, n; 
     2071int ssl_read( ssl_context *ssl, unsigned char *buf, size_t len ) 
     2072{ 
     2073    int ret; 
     2074    size_t n; 
    20702075 
    20712076    SSL_DEBUG_MSG( 2, ( "=> read" ) ); 
     
    21252130    SSL_DEBUG_MSG( 2, ( "<= read" ) ); 
    21262131 
    2127     return( n ); 
     2132    return( (int) n ); 
    21282133} 
    21292134 
     
    21312136 * Send application data to be encrypted by the SSL layer 
    21322137 */ 
    2133 int ssl_write( ssl_context *ssl, const unsigned char *buf, int len ) 
    2134 { 
    2135     int ret, n; 
     2138int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len ) 
     2139{ 
     2140    int ret; 
     2141    size_t n; 
    21362142 
    21372143    SSL_DEBUG_MSG( 2, ( "=> write" ) ); 
     
    21702176    SSL_DEBUG_MSG( 2, ( "<= write" ) ); 
    21712177 
    2172     return( n ); 
     2178    return( (int) n ); 
    21732179} 
    21742180 
  • trunk/library/x509parse.c

    r1006 r1014  
    6060static int asn1_get_len( unsigned char **p, 
    6161                         const unsigned char *end, 
    62                          int *len ) 
     62                         size_t *len ) 
    6363{ 
    6464    if( ( end - *p ) < 1 ) 
     
    9393    } 
    9494 
    95     if( *len > (int) ( end - *p ) ) 
     95    if( *len > (size_t) ( end - *p ) ) 
    9696        return( POLARSSL_ERR_ASN1_OUT_OF_DATA ); 
    9797 
     
    101101static int asn1_get_tag( unsigned char **p, 
    102102                         const unsigned char *end, 
    103                          int *len, int tag ) 
     103                         size_t *len, int tag ) 
    104104{ 
    105105    if( ( end - *p ) < 1 ) 
     
    118118                          int *val ) 
    119119{ 
    120     int ret, len; 
     120    int ret; 
     121    size_t len; 
    121122 
    122123    if( ( ret = asn1_get_tag( p, end, &len, ASN1_BOOLEAN ) ) != 0 ) 
     
    136137                         int *val ) 
    137138{ 
    138     int ret, len; 
     139    int ret; 
     140    size_t len; 
    139141 
    140142    if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 ) 
     
    159161                         mpi *X ) 
    160162{ 
    161     int ret, len; 
     163    int ret; 
     164    size_t len; 
    162165 
    163166    if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 ) 
     
    210213                          int tag) 
    211214{ 
    212     int ret, len; 
     215    int ret; 
     216    size_t len; 
    213217    x509_buf *buf; 
    214218 
     
    261265                             int *ver ) 
    262266{ 
    263     int ret, len; 
     267    int ret; 
     268    size_t len; 
    264269 
    265270    if( ( ret = asn1_get_tag( p, end, &len, 
     
    322327                         x509_buf *alg ) 
    323328{ 
    324     int ret, len; 
     329    int ret; 
     330    size_t len; 
    325331 
    326332    if( ( ret = asn1_get_tag( p, end, &len, 
     
    366372                                     x509_name *cur ) 
    367373{ 
    368     int ret, len; 
     374    int ret; 
     375    size_t len; 
    369376    x509_buf *oid; 
    370377    x509_buf *val; 
     
    423430                          x509_name *cur ) 
    424431{ 
    425     int ret, len; 
     432    int ret; 
     433    size_t len; 
    426434    const unsigned char *end2; 
    427435    x509_name *use;  
     
    479487                          x509_time *time ) 
    480488{ 
    481     int ret, len; 
     489    int ret; 
     490    size_t len; 
    482491    char date[64]; 
    483492    unsigned char tag; 
     
    548557                           x509_time *to ) 
    549558{ 
    550     int ret, len; 
     559    int ret; 
     560    size_t len; 
    551561 
    552562    if( ( ret = asn1_get_tag( p, end, &len, 
     
    579589                            mpi *N, mpi *E ) 
    580590{ 
    581     int ret, len, can_handle; 
     591    int ret, can_handle; 
     592    size_t len; 
    582593    unsigned char *end2; 
    583594 
     
    652663                         x509_buf *sig ) 
    653664{ 
    654     int ret, len; 
     665    int ret; 
     666    size_t len; 
    655667 
    656668    sig->tag = **p; 
     
    708720                         x509_buf *ext ) 
    709721{ 
    710     int ret, len; 
     722    int ret; 
     723    size_t len; 
    711724 
    712725    if( *p == end ) 
     
    748761                             x509_buf *ext ) 
    749762{ 
    750     int ret, len; 
     763    int ret; 
     764    size_t len; 
    751765 
    752766    if( ( ret = x509_get_ext( p, end, ext ) ) != 0 ) 
     
    779793                                       int *max_pathlen ) 
    780794{ 
    781     int ret, len; 
     795    int ret; 
     796    size_t len; 
    782797 
    783798    /* 
     
    894909                             x509_cert *crt ) 
    895910{ 
    896     int ret, len; 
     911    int ret; 
     912    size_t len; 
    897913    unsigned char *end_ext_data, *end_ext_octet; 
    898914 
     
    10181034                             x509_crl_entry *entry ) 
    10191035{ 
    1020     int ret, entry_len; 
     1036    int ret; 
     1037    size_t entry_len; 
    10211038    x509_crl_entry *cur_entry = entry; 
    10221039 
     
    10371054    while( *p < end ) 
    10381055    { 
    1039         int len2; 
     1056        size_t len2; 
    10401057 
    10411058        if( ( ret = asn1_get_tag( p, end, &len2, 
     
    11011118 * Parse one or more certificates and add them to the chained list 
    11021119 */ 
    1103 int x509parse_crt( x509_cert *chain, const unsigned char *buf, int buflen ) 
    1104 { 
    1105     int ret, len, use_len; 
     1120int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen ) 
     1121{ 
     1122    int ret; 
     1123    size_t len, use_len; 
    11061124    unsigned char *p, *end; 
    11071125    x509_cert *crt; 
     
    12081226    } 
    12091227 
    1210     if( len != (int) ( end - p ) ) 
     1228    if( len != (size_t) ( end - p ) ) 
    12111229    { 
    12121230        x509_free( crt ); 
     
    14371455 * Parse one or more CRLs and add them to the chained list 
    14381456 */ 
    1439 int x509parse_crl( x509_crl *chain, const unsigned char *buf, int buflen ) 
    1440 { 
    1441     int ret, len, use_len; 
     1457int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen ) 
     1458{ 
     1459    int ret; 
     1460    size_t len, use_len; 
    14421461    unsigned char *p, *end; 
    14431462    x509_crl *crl; 
     
    15441563    } 
    15451564 
    1546     if( len != (int) ( end - p ) ) 
     1565    if( len != (size_t) ( end - p ) ) 
    15471566    { 
    15481567        x509_crl_free( crl ); 
     
    17951814 * Parse a private RSA key 
    17961815 */ 
    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; 
     1816int 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; 
    18011821    unsigned char *p, *end; 
    18021822#if defined(POLARSSL_PEM_C) 
     
    19431963 * Parse a public RSA key 
    19441964 */ 
    1945 int x509parse_public_key( rsa_context *rsa, const unsigned char *key, int keylen ) 
    1946 { 
    1947     int ret, len; 
     1965int x509parse_public_key( rsa_context *rsa, const unsigned char *key, size_t keylen ) 
     1966{ 
     1967    int ret; 
     1968    size_t len; 
    19481969    unsigned char *p, *end; 
    19491970    x509_buf alg_oid; 
     
    20542075 * Parse DHM parameters 
    20552076 */ 
    2056 int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, int dhminlen ) 
    2057 { 
    2058     int ret, len; 
     2077int x509parse_dhm( dhm_context *dhm, const unsigned char *dhmin, size_t dhminlen ) 
     2078{ 
     2079    int ret; 
     2080    size_t len; 
    20592081    unsigned char *p, *end; 
    20602082#if defined(POLARSSL_PEM_C) 
     
    21812203    // No quick fix possible 
    21822204    if ( res < 0 ) 
    2183         return( size + 20 ); 
     2205        return( (int) size + 20 ); 
    21842206     
    21852207    return res; 
     
    21962218        return( -1 );                           \ 
    21972219                                                \ 
    2198     if ( ret > n ) {                            \ 
     2220    if ( (unsigned int) ret > n ) {             \ 
    21992221        p[n - 1] = '\0';                        \ 
    22002222        return POLARSSL_ERR_DEBUG_BUF_TOO_SMALL;\ 
    22012223    }                                           \ 
    22022224                                                \ 
    2203     n -= ret;                                   \ 
    2204     p += ret;                                   \ 
     2225    n -= (unsigned int) ret;                    \ 
     2226    p += (unsigned int) ret;                    \ 
    22052227} 
    22062228 
     
    22112233int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn ) 
    22122234{ 
    2213     int i, ret, n; 
     2235    int ret; 
     2236    size_t i, n; 
    22142237    unsigned char c; 
    22152238    const x509_name *name; 
     
    22952318    } 
    22962319 
    2297     return( size - n ); 
     2320    return( (int) ( size - n ) ); 
    22982321} 
    22992322 
     
    23042327int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial ) 
    23052328{ 
    2306     int i, ret, nr, n; 
     2329    int ret; 
     2330    size_t i, n, nr; 
    23072331    char *p; 
    23082332 
     
    23202344    } 
    23212345 
    2322     return( size - n ); 
     2346    return( (int) ( size - n ) ); 
    23232347} 
    23242348 
     
    23292353                         const x509_cert *crt ) 
    23302354{ 
    2331     int n, ret; 
     2355    int ret; 
     2356    size_t n; 
    23322357    char *p; 
    23332358 
     
    23902415    SAFE_SNPRINTF(); 
    23912416 
    2392     return( size - n ); 
     2417    return( (int) ( size - n ) ); 
    23932418} 
    23942419 
     
    24302455int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid ) 
    24312456{ 
    2432     int ret, n, i; 
     2457    int ret; 
     2458    size_t i, n; 
    24332459    unsigned int value; 
    24342460    char *p; 
     
    24462472    /* TODO: value can overflow in value. */ 
    24472473    value = 0; 
    2448     for( i=1; i < oid->len; i++ ) 
     2474    for( i = 1; i < oid->len; i++ ) 
    24492475    { 
    24502476        value <<= 7; 
     
    24602486    } 
    24612487 
    2462     return( size - n ); 
     2488    return( (int) ( size - n ) ); 
    24632489} 
    24642490 
     
    24692495                        const x509_crl *crl ) 
    24702496{ 
    2471     int i, n, nr, ret; 
     2497    int ret; 
     2498    size_t i, n, nr; 
    24722499    char *p; 
    24732500    const x509_crl_entry *entry; 
     
    25512578    SAFE_SNPRINTF(); 
    25522579 
    2553     return( size - n ); 
     2580    return( (int) ( size - n ) ); 
    25542581} 
    25552582 
     
    26282655 * \param out   Buffer to receive the hash (Should be at least 64 bytes) 
    26292656 */ 
    2630 static void x509_hash( const unsigned char *in, int len, int alg, 
     2657static void x509_hash( const unsigned char *in, size_t len, int alg, 
    26312658                       unsigned char *out ) 
    26322659{ 
     
    27322759                      void *p_vrfy ) 
    27332760{ 
    2734     int cn_len; 
     2761    size_t cn_len; 
    27352762    int hash_id; 
    27362763    int pathlen; 
     
    30003027{ 
    30013028#if defined(POLARSSL_MD5_C) 
    3002     int ret, i, j; 
     3029    int ret; 
     3030    int flags; 
     3031    size_t i, j; 
    30033032    x509_cert cacert; 
    30043033    x509_cert clicert; 
     
    30543083        printf( "passed\n  X.509 signature verify: "); 
    30553084 
    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 ); 
    30573086    if( ret != 0 ) 
    30583087    { 
    3059         printf("%02x", i); 
     3088        printf("%02x", flags); 
    30603089        if( verbose != 0 ) 
    30613090            printf( "failed\n" ); 
  • trunk/library/xtea.c

    r1011 r1014  
    3030#include "polarssl/xtea.h" 
    3131 
    32 #include <string.h> 
    33  
    3432/* 
    3533 * 32-bit integer manipulation macros (big endian) 
     
    3937{                                                       \ 
    4038    (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]       );       \ 
    4442} 
    4543#endif 
     
    6664    for( i = 0; i < 4; i++ ) 
    6765    { 
    68         GET_ULONG_BE( ctx->k[i], key, i << 2 ); 
     66        GET_ULONG_BE( ctx->k[i], key, i << 2 ); 
    6967    } 
    7068} 
     
    8583    if( mode == XTEA_ENCRYPT ) 
    8684    { 
    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        } 
    9593    } 
    9694    else /* XTEA_DECRYPT */ 
    9795    { 
    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        } 
    106104    } 
    107105 
     
    117115int xtea_crypt_cbc( xtea_context *ctx, 
    118116                    int mode, 
    119                     int length, 
     117                    size_t length, 
    120118                    unsigned char iv[8], 
    121119                    unsigned char *input, 
  • trunk/programs/aes/aescrypt2.c

    r952 r1014  
    5656{ 
    5757    int ret = 1, i, n; 
    58     int keylen, mode, lastn; 
     58    int mode, lastn; 
     59    size_t keylen; 
    5960    FILE *fkey, *fin = NULL, *fout = NULL; 
    6061 
  • trunk/programs/aes/crypt_and_hash.c

    r952 r1014  
    5757{ 
    5858    int ret = 1, i, n; 
    59     int keylen, mode, lastn, olen; 
     59    int mode, lastn; 
     60    size_t keylen, olen; 
    6061    FILE *fkey, *fin = NULL, *fout = NULL; 
    6162 
     
    292293        { 
    293294            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 ); 
    295296 
    296297            if( fread( buffer, 1, n, fin ) != (size_t) n ) 
  • trunk/programs/hash/generic_sum.c

    r941 r1014  
    8484    n = sizeof( line ); 
    8585 
    86     while( fgets( line, n - 1, f ) != NULL ) 
     86    while( fgets( line, (int) n - 1, f ) != NULL ) 
    8787    { 
    8888        n = strlen( line ); 
  • trunk/programs/hash/md5sum.c

    r897 r1014  
    8484    n = sizeof( line ); 
    8585 
    86     while( fgets( line, n - 1, f ) != NULL ) 
     86    while( fgets( line, (int) n - 1, f ) != NULL ) 
    8787    { 
    8888        n = strlen( line ); 
  • trunk/programs/hash/sha1sum.c

    r897 r1014  
    8484    n = sizeof( line ); 
    8585 
    86     while( fgets( line, n - 1, f ) != NULL ) 
     86    while( fgets( line, (int) n - 1, f ) != NULL ) 
    8787    { 
    8888        n = strlen( line ); 
  • trunk/programs/hash/sha2sum.c

    r897 r1014  
    8484    n = sizeof( line ); 
    8585 
    86     while( fgets( line, n - 1, f ) != NULL ) 
     86    while( fgets( line, (int) n - 1, f ) != NULL ) 
    8787    { 
    8888        n = strlen( line ); 
  • trunk/programs/pkey/dh_client.c

    r902 r1014  
    4545    FILE *f; 
    4646 
    47     int ret, n, buflen; 
     47    int ret; 
     48    size_t n, buflen; 
    4849    int server_fd = -1; 
    4950 
     
    124125 
    125126    n = buflen = ( buf[0] << 8 ) | buf[1]; 
    126     if( buflen < 1 || buflen > (int) sizeof( buf ) ) 
     127    if( buflen < 1 || buflen > sizeof( buf ) ) 
    127128    { 
    128129        printf( " failed\n  ! Got an invalid buffer length\n\n" ); 
     
    135136    memset( buf, 0, sizeof( buf ) ); 
    136137 
    137     if( ( ret = net_recv( &server_fd, buf, n ) ) != n ) 
     138    if( ( ret = net_recv( &server_fd, buf, n ) ) != (int) n ) 
    138139    { 
    139140        printf( " failed\n  ! net_recv returned %d\n\n", ret ); 
     
    163164    fflush( stdout ); 
    164165 
    165     if( ( n = (int)( end - p ) ) != rsa.len ) 
     166    if( ( n = (size_t) ( end - p ) ) != rsa.len ) 
    166167    { 
    167168        ret = 1; 
     
    193194    } 
    194195 
    195     if( ( ret = net_send( &server_fd, buf, n ) ) != n ) 
     196    if( ( ret = net_send( &server_fd, buf, n ) ) != (int) n ) 
    196197    { 
    197198        printf( " failed\n  ! net_send returned %d\n\n", ret ); 
  • trunk/programs/pkey/dh_server.c

    r979 r1014  
    4545    FILE *f; 
    4646 
    47     int ret, n, buflen; 
     47    int ret; 
     48    size_t n, buflen; 
    4849    int listen_fd = -1; 
    4950    int client_fd = -1; 
     
    178179 
    179180    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 ) 
    181182    { 
    182183        printf( " failed\n  ! net_send returned %d\n\n", ret ); 
     
    193194    n = dhm.len; 
    194195 
    195     if( ( ret = net_recv( &client_fd, buf, n ) ) != n ) 
     196    if( ( ret = net_recv( &client_fd, buf, n ) ) != (int) n ) 
    196197    { 
    197198        printf( " failed\n  ! net_recv returned %d\n\n", ret ); 
  • trunk/programs/pkey/rsa_sign.c

    r979 r1014  
    3737{ 
    3838    FILE *f; 
    39     int ret, i; 
     39    int ret; 
     40    size_t i; 
    4041    rsa_context rsa; 
    4142    unsigned char hash[20]; 
  • trunk/programs/pkey/rsa_verify.c

    r902 r1014  
    3737{ 
    3838    FILE *f; 
    39     int ret, i, c; 
     39    int ret, c; 
     40    size_t i; 
    4041    rsa_context rsa; 
    4142    unsigned char hash[20]; 
  • trunk/programs/pkey/rsa_verify_pss.c

    r1008 r1014  
    4444{ 
    4545    FILE *f; 
    46     int ret, i; 
     46    int ret; 
     47    size_t i; 
    4748    rsa_context rsa; 
    4849    unsigned char hash[20]; 
  • trunk/programs/ssl/ssl_client2.c

    r962 r1014  
    9393    x509_cert clicert; 
    9494    rsa_context rsa; 
    95     int i, j, n; 
     95    int i; 
     96    size_t j, n; 
    9697    char *p, *q; 
    9798    const int *list; 
  • trunk/tests/suites/test_suite_cipher.function

    r998 r1014  
    55BEGIN_CASE 
    66enc_dec_buf:cipher_id:cipher_string:key_len:length: 
    7     int length = {length}; 
     7    size_t length = {length}; 
    88    unsigned char key[32]; 
    99    unsigned char iv[16]; 
     
    1717    unsigned char decbuf[64]; 
    1818 
    19     int outlen = 0; 
    20     int enclen = 0; 
     19    size_t outlen = 0; 
     20    size_t enclen = 0; 
    2121 
    2222    memset( key, 0, 32 ); 
     
    108108BEGIN_CASE 
    109109enc_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; 
    113113    unsigned char key[32]; 
    114114    unsigned char iv[16]; 
     
    122122    unsigned char decbuf[64]; 
    123123 
    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; 
    127127 
    128128    memset( key, 0, 32 ); 
Note: See TracChangeset for help on using the changeset viewer.

What are you looking for?