~cpick/mongrel2/release

« back to all changes in this revision

Viewing changes to src/polarssl/sha1.c

  • Committer: Chris Pick
  • Date: 2013-06-30 16:39:57 UTC
  • mfrom: (1106.1.15)
  • Revision ID: git-v1:ec39967acb6bc9867ed9b9dc3774304ca6b9c294
Merge tag 'v1.8.1' into debian

Hotfix for github issue 148

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include "polarssl/sha1.h"
36
36
 
37
 
#include <string.h>
 
37
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
38
38
#include <stdio.h>
 
39
#endif
39
40
 
40
41
/*
41
42
 * 32-bit integer manipulation macros (big endian)
234
235
/*
235
236
 * SHA-1 process buffer
236
237
 */
237
 
void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )
 
238
void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen )
238
239
{
239
 
    int fill;
 
240
    size_t fill;
240
241
    unsigned long left;
241
242
 
242
243
    if( ilen <= 0 )
245
246
    left = ctx->total[0] & 0x3F;
246
247
    fill = 64 - left;
247
248
 
248
 
    ctx->total[0] += ilen;
 
249
    ctx->total[0] += (unsigned long) ilen;
249
250
    ctx->total[0] &= 0xFFFFFFFF;
250
251
 
251
252
    if( ctx->total[0] < (unsigned long) ilen )
315
316
/*
316
317
 * output = SHA-1( input buffer )
317
318
 */
318
 
void sha1( const unsigned char *input, int ilen, unsigned char output[20] )
 
319
void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] )
319
320
{
320
321
    sha1_context ctx;
321
322
 
326
327
    memset( &ctx, 0, sizeof( sha1_context ) );
327
328
}
328
329
 
 
330
#if defined(POLARSSL_FS_IO)
329
331
/*
330
332
 * output = SHA-1( file contents )
331
333
 */
337
339
    unsigned char buf[1024];
338
340
 
339
341
    if( ( f = fopen( path, "rb" ) ) == NULL )
340
 
        return( 1 );
 
342
        return( POLARSSL_ERR_SHA1_FILE_IO_ERROR );
341
343
 
342
344
    sha1_starts( &ctx );
343
345
 
344
346
    while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
345
 
        sha1_update( &ctx, buf, (int) n );
 
347
        sha1_update( &ctx, buf, n );
346
348
 
347
349
    sha1_finish( &ctx, output );
348
350
 
351
353
    if( ferror( f ) != 0 )
352
354
    {
353
355
        fclose( f );
354
 
        return( 2 );
 
356
        return( POLARSSL_ERR_SHA1_FILE_IO_ERROR );
355
357
    }
356
358
 
357
359
    fclose( f );
358
360
    return( 0 );
359
361
}
 
362
#endif /* POLARSSL_FS_IO */
360
363
 
361
364
/*
362
365
 * SHA-1 HMAC context setup
363
366
 */
364
 
void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen )
 
367
void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, size_t keylen )
365
368
{
366
 
    int i;
 
369
    size_t i;
367
370
    unsigned char sum[20];
368
371
 
369
372
    if( keylen > 64 )
391
394
/*
392
395
 * SHA-1 HMAC process buffer
393
396
 */
394
 
void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen )
 
397
void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, size_t ilen )
395
398
{
396
399
    sha1_update( ctx, input, ilen );
397
400
}
424
427
/*
425
428
 * output = HMAC-SHA-1( hmac key, input buffer )
426
429
 */
427
 
void sha1_hmac( const unsigned char *key, int keylen,
428
 
                const unsigned char *input, int ilen,
 
430
void sha1_hmac( const unsigned char *key, size_t keylen,
 
431
                const unsigned char *input, size_t ilen,
429
432
                unsigned char output[20] )
430
433
{
431
434
    sha1_context ctx;