Changes in lib/sha1.c [523fb23:77bfd07]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/sha1.c
r523fb23 r77bfd07 36 36 */ 37 37 38 #include <string.h>39 38 #include "sha1.h" 40 39 … … 375 374 sha1_process_block(context); 376 375 } 377 378 #define HMAC_BLOCK_SIZE 64379 380 /* BitlBee addition: */381 void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, uint8_t Message_Digest[sha1_hash_size])382 {383 sha1_state_t sha1;384 uint8_t hash[sha1_hash_size];385 uint8_t key[HMAC_BLOCK_SIZE+1];386 int i;387 388 if( key_len == 0 )389 key_len = strlen( key_ );390 if( payload_len == 0 )391 payload_len = strlen( payload );392 393 /* Create K. If our current key is >64 chars we have to hash it,394 otherwise just pad. */395 memset( key, 0, HMAC_BLOCK_SIZE + 1 );396 if( key_len > HMAC_BLOCK_SIZE )397 {398 sha1_init( &sha1 );399 sha1_append( &sha1, (uint8_t*) key_, key_len );400 sha1_finish( &sha1, key );401 }402 else403 {404 memcpy( key, key_, key_len );405 }406 407 /* Inner part: H(K XOR 0x36, text) */408 sha1_init( &sha1 );409 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ )410 key[i] ^= 0x36;411 sha1_append( &sha1, key, HMAC_BLOCK_SIZE );412 sha1_append( &sha1, (const uint8_t*) payload, payload_len );413 sha1_finish( &sha1, hash );414 415 /* Final result: H(K XOR 0x5C, inner stuff) */416 sha1_init( &sha1 );417 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ )418 key[i] ^= 0x36 ^ 0x5c;419 sha1_append( &sha1, key, HMAC_BLOCK_SIZE );420 sha1_append( &sha1, hash, sha1_hash_size );421 sha1_finish( &sha1, Message_Digest );422 }
Note: See TracChangeset
for help on using the changeset viewer.