sha1.c File Reference

#include "polarssl/config.h"
#include "polarssl/sha1.h"
#include <stdio.h>
Include dependency graph for sha1.c:

Go to the source code of this file.

Defines

#define S(x, n)   ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
#define R(t)
#define P(a, b, c, d, e, x)
#define F(x, y, z)   (z ^ (x & (y ^ z)))
#define K   0x5A827999
#define F(x, y, z)   (x ^ y ^ z)
#define K   0x6ED9EBA1
#define F(x, y, z)   ((x & y) | (z & (x | y)))
#define K   0x8F1BBCDC
#define F(x, y, z)   (x ^ y ^ z)
#define K   0xCA62C1D6

Functions

void sha1_starts (sha1_context *ctx)
 SHA-1 context setup.
void sha1_process (sha1_context *ctx, const unsigned char data[64])
void sha1_update (sha1_context *ctx, const unsigned char *input, size_t ilen)
 SHA-1 process buffer.
void sha1_finish (sha1_context *ctx, unsigned char output[20])
 SHA-1 final digest.
void sha1 (const unsigned char *input, size_t ilen, unsigned char output[20])
 Output = SHA-1( input buffer ).
int sha1_file (const char *path, unsigned char output[20])
 Output = SHA-1( file contents ).
void sha1_hmac_starts (sha1_context *ctx, const unsigned char *key, size_t keylen)
 SHA-1 HMAC context setup.
void sha1_hmac_update (sha1_context *ctx, const unsigned char *input, size_t ilen)
 SHA-1 HMAC process buffer.
void sha1_hmac_finish (sha1_context *ctx, unsigned char output[20])
 SHA-1 HMAC final digest.
void sha1_hmac_reset (sha1_context *ctx)
 SHA-1 HMAC context reset.
void sha1_hmac (const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[20])
 Output = HMAC-SHA-1( hmac key, input buffer ).
int sha1_self_test (int verbose)
 Checkup routine.

Variables

static const unsigned char sha1_padding [64]
static unsigned char sha1_test_buf [3][57]
static const int sha1_test_buflen [3]
static const unsigned char sha1_test_sum [3][20]
static unsigned char sha1_hmac_test_key [7][26]
static const int sha1_hmac_test_keylen [7]
static unsigned char sha1_hmac_test_buf [7][74]
static const int sha1_hmac_test_buflen [7]
static const unsigned char sha1_hmac_test_sum [7][20]

Define Documentation

#define F ( x,
y,
 )     (x ^ y ^ z)
#define F ( x,
y,
 )     ((x & y) | (z & (x | y)))
#define F ( x,
y,
 )     (x ^ y ^ z)
#define F ( x,
y,
 )     (z ^ (x & (y ^ z)))
#define K   0xCA62C1D6
#define K   0x8F1BBCDC
#define K   0x6ED9EBA1
#define K   0x5A827999

Referenced by sha512_process().

#define P ( a,
b,
c,
d,
e,
 ) 
Value:
{                                                       \
    e += S(a,5) + F(b,c,d) + K + x; b = S(b,30);        \
}
#define R (  ) 
Value:
(                                                       \
    temp = W[(t -  3) & 0x0F] ^ W[(t - 8) & 0x0F] ^     \
           W[(t - 14) & 0x0F] ^ W[ t      & 0x0F],      \
    ( W[t & 0x0F] = S(temp,1) )                         \
)

Referenced by ecdsa_sign(), ecdsa_verify(), mpi_is_prime(), sha1_process(), sha256_process(), test_suite_ecp_fast_mod(), test_suite_ecp_small_mul(), test_suite_ecp_test_vect(), test_suite_mpi_div_int(), and test_suite_mpi_div_mpi().

#define S ( x,
 )     ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))

Function Documentation

void sha1 ( const unsigned char *  input,
size_t  ilen,
unsigned char  output[20] 
)

Output = SHA-1( input buffer ).

Parameters:
input buffer holding the data
ilen length of the input data
output SHA-1 checksum result

Definition at line 319 of file sha1.c.

References sha1_finish(), sha1_starts(), and sha1_update().

Referenced by rsa_self_test(), sha1_hmac_starts(), ssl3_prf(), ssl_calc_finished_ssl(), ssl_calc_finished_tls(), ssl_calc_verify_ssl(), ssl_calc_verify_tls(), ssl_parse_server_key_exchange(), ssl_write_server_key_exchange(), test_suite_sha1(), x509write_crt_set_authority_key_identifier(), and x509write_crt_set_subject_key_identifier().

int sha1_file ( const char *  path,
unsigned char  output[20] 
)

Output = SHA-1( file contents ).

Parameters:
path input file name
output SHA-1 checksum result
Returns:
0 if successful, or POLARSSL_ERR_SHA1_FILE_IO_ERROR

Definition at line 334 of file sha1.c.

References POLARSSL_ERR_SHA1_FILE_IO_ERROR, sha1_finish(), sha1_starts(), and sha1_update().

Referenced by sha1_file_wrap(), and test_suite_sha1_file().

void sha1_finish ( sha1_context ctx,
unsigned char  output[20] 
)
void sha1_hmac ( const unsigned char *  key,
size_t  keylen,
const unsigned char *  input,
size_t  ilen,
unsigned char  output[20] 
)

Output = HMAC-SHA-1( hmac key, input buffer ).

Parameters:
key HMAC secret key
keylen length of the HMAC key
input buffer holding the data
ilen length of the input data
output HMAC-SHA-1 result

Definition at line 430 of file sha1.c.

References sha1_hmac_finish(), sha1_hmac_starts(), and sha1_hmac_update().

Referenced by test_suite_sha1_hmac(), and tls1_prf().

void sha1_hmac_finish ( sha1_context ctx,
unsigned char  output[20] 
)

SHA-1 HMAC final digest.

Parameters:
ctx HMAC context
output SHA-1 HMAC checksum result

Definition at line 405 of file sha1.c.

References sha1_context::opad, sha1_finish(), sha1_starts(), and sha1_update().

Referenced by sha1_hmac(), sha1_hmac_finish_wrap(), and sha1_self_test().

void sha1_hmac_reset ( sha1_context ctx  ) 

SHA-1 HMAC context reset.

Parameters:
ctx HMAC context to be reset

Definition at line 421 of file sha1.c.

References sha1_context::ipad, sha1_starts(), and sha1_update().

Referenced by sha1_hmac_reset_wrap().

void sha1_hmac_starts ( sha1_context ctx,
const unsigned char *  key,
size_t  keylen 
)

SHA-1 HMAC context setup.

Parameters:
ctx HMAC context to be initialized
key HMAC secret key
keylen length of the HMAC key

Definition at line 367 of file sha1.c.

References sha1_context::ipad, sha1_context::opad, sha1(), sha1_starts(), and sha1_update().

Referenced by sha1_hmac(), sha1_hmac_starts_wrap(), and sha1_self_test().

void sha1_hmac_update ( sha1_context ctx,
const unsigned char *  input,
size_t  ilen 
)

SHA-1 HMAC process buffer.

Parameters:
ctx HMAC context
input buffer holding the data
ilen length of the input data

Definition at line 397 of file sha1.c.

References sha1_update().

Referenced by sha1_hmac(), sha1_hmac_update_wrap(), and sha1_self_test().

void sha1_process ( sha1_context ctx,
const unsigned char  data[64] 
)

Definition at line 81 of file sha1.c.

References A, GET_UINT32_BE, P, R, and sha1_context::state.

Referenced by sha1_process_wrap(), and sha1_update().

int sha1_self_test ( int  verbose  ) 
void sha1_starts ( sha1_context ctx  ) 
void sha1_update ( sha1_context ctx,
const unsigned char *  input,
size_t  ilen 
)

Variable Documentation

unsigned char sha1_hmac_test_buf[7][74] [static]
Initial value:
{
    { "Hi There" },
    { "what do ya want for nothing?" },
    { "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" },
    { "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" },
    { "Test With Truncation" },
    { "Test Using Larger Than Block-Size Key - Hash Key First" },
    { "Test Using Larger Than Block-Size Key and Larger"
      " Than One Block-Size Data" }
}

Definition at line 492 of file sha1.c.

Referenced by sha1_self_test().

const int sha1_hmac_test_buflen[7] [static]
Initial value:
{
    8, 28, 50, 50, 20, 54, 73
}

Definition at line 512 of file sha1.c.

Referenced by sha1_self_test().

unsigned char sha1_hmac_test_key[7][26] [static]
Initial value:
{
    { "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
      "\x0B\x0B\x0B\x0B" },
    { "Jefe" },
    { "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
      "\xAA\xAA\xAA\xAA" },
    { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
      "\x11\x12\x13\x14\x15\x16\x17\x18\x19" },
    { "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C"
      "\x0C\x0C\x0C\x0C" },
    { "" }, 
    { "" }
}

Definition at line 472 of file sha1.c.

Referenced by sha1_self_test().

const int sha1_hmac_test_keylen[7] [static]
Initial value:
{
    20, 4, 20, 25, 20, 80, 80
}

Definition at line 487 of file sha1.c.

Referenced by sha1_self_test().

const unsigned char sha1_hmac_test_sum[7][20] [static]
Initial value:
{
    { 0xB6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xE2, 0x8B,
      0xC0, 0xB6, 0xFB, 0x37, 0x8C, 0x8E, 0xF1, 0x46, 0xBE, 0x00 },
    { 0xEF, 0xFC, 0xDF, 0x6A, 0xE5, 0xEB, 0x2F, 0xA2, 0xD2, 0x74,
      0x16, 0xD5, 0xF1, 0x84, 0xDF, 0x9C, 0x25, 0x9A, 0x7C, 0x79 },
    { 0x12, 0x5D, 0x73, 0x42, 0xB9, 0xAC, 0x11, 0xCD, 0x91, 0xA3,
      0x9A, 0xF4, 0x8A, 0xA1, 0x7B, 0x4F, 0x63, 0xF1, 0x75, 0xD3 },
    { 0x4C, 0x90, 0x07, 0xF4, 0x02, 0x62, 0x50, 0xC6, 0xBC, 0x84,
      0x14, 0xF9, 0xBF, 0x50, 0xC8, 0x6C, 0x2D, 0x72, 0x35, 0xDA },
    { 0x4C, 0x1A, 0x03, 0x42, 0x4B, 0x55, 0xE0, 0x7F, 0xE7, 0xF2,
      0x7B, 0xE1 },
    { 0xAA, 0x4A, 0xE5, 0xE1, 0x52, 0x72, 0xD0, 0x0E, 0x95, 0x70,
      0x56, 0x37, 0xCE, 0x8A, 0x3B, 0x55, 0xED, 0x40, 0x21, 0x12 },
    { 0xE8, 0xE9, 0x9D, 0x0F, 0x45, 0x23, 0x7D, 0x78, 0x6D, 0x6B,
      0xBA, 0xA7, 0x96, 0x5C, 0x78, 0x08, 0xBB, 0xFF, 0x1A, 0x91 }
}

Definition at line 517 of file sha1.c.

Referenced by sha1_self_test().

const unsigned char sha1_padding[64] [static]
Initial value:
{
 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 277 of file sha1.c.

Referenced by sha1_finish().

unsigned char sha1_test_buf[3][57] [static]
Initial value:
 
{
    { "abc" },
    { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
    { "" }
}

Definition at line 447 of file sha1.c.

Referenced by sha1_self_test().

const int sha1_test_buflen[3] [static]
Initial value:
{
    3, 56, 1000
}

Definition at line 454 of file sha1.c.

Referenced by sha1_self_test().

const unsigned char sha1_test_sum[3][20] [static]
Initial value:
{
    { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
      0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
    { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
      0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
    { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
      0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
}

Definition at line 459 of file sha1.c.

Referenced by sha1_self_test().


Generated on 9 Apr 2014 for PolarSSL v1.3.2 by  doxygen 1.6.1