Changeset 537d9b9 for lib/sha1.c
- Timestamp:
- 2016-11-20T08:40:36Z (8 years ago)
- Children:
- 3f44e43
- Parents:
- ba52ac5 (diff), 9f03c47 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/sha1.c
rba52ac5 r537d9b9 24 24 #define HMAC_BLOCK_SIZE 64 25 25 26 /* BitlBee addition: */ 27 void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, guint8 digest[SHA1_HASH_SIZE])26 void b_hmac(GChecksumType checksum_type, const char *key_, size_t key_len, 27 const char *payload, size_t payload_len, guint8 **digest) 28 28 { 29 sha1_state_t sha1; 30 guint8 hash[SHA1_HASH_SIZE]; 29 GChecksum *checksum; 30 size_t hash_len; 31 guint8 *hash; 31 32 guint8 key[HMAC_BLOCK_SIZE + 1]; 32 33 int i; 34 35 hash_len = g_checksum_type_get_length(checksum_type); 36 37 if (hash_len == (size_t) -1) { 38 return; 39 } 40 41 hash = g_malloc(hash_len); 33 42 34 43 if (key_len == 0) { … … 43 52 memset(key, 0, HMAC_BLOCK_SIZE + 1); 44 53 if (key_len > HMAC_BLOCK_SIZE) { 45 sha1_init(&sha1); 46 sha1_append(&sha1, (guint8 *) key_, key_len); 47 sha1_finish(&sha1, key); 54 checksum = g_checksum_new(checksum_type); 55 g_checksum_update(checksum, (guint8 *) key_, key_len); 56 g_checksum_get_digest(checksum, key, &hash_len); 57 g_checksum_free(checksum); 48 58 } else { 49 59 memcpy(key, key_, key_len); … … 51 61 52 62 /* Inner part: H(K XOR 0x36, text) */ 53 sha1_init(&sha1);63 checksum = g_checksum_new(checksum_type); 54 64 for (i = 0; i < HMAC_BLOCK_SIZE; i++) { 55 65 key[i] ^= 0x36; 56 66 } 57 sha1_append(&sha1, key, HMAC_BLOCK_SIZE); 58 sha1_append(&sha1, (const guint8 *) payload, payload_len); 59 sha1_finish(&sha1, hash); 67 g_checksum_update(checksum, key, HMAC_BLOCK_SIZE); 68 g_checksum_update(checksum, (const guint8 *) payload, payload_len); 69 g_checksum_get_digest(checksum, hash, &hash_len); 70 g_checksum_free(checksum); 60 71 61 72 /* Final result: H(K XOR 0x5C, inner stuff) */ 62 sha1_init(&sha1);73 checksum = g_checksum_new(checksum_type); 63 74 for (i = 0; i < HMAC_BLOCK_SIZE; i++) { 64 75 key[i] ^= 0x36 ^ 0x5c; 65 76 } 66 sha1_append(&sha1, key, HMAC_BLOCK_SIZE); 67 sha1_append(&sha1, hash, SHA1_HASH_SIZE); 68 sha1_finish(&sha1, digest); 77 g_checksum_update(checksum, key, HMAC_BLOCK_SIZE); 78 g_checksum_update(checksum, hash, hash_len); 79 g_checksum_get_digest(checksum, *digest, &hash_len); 80 g_checksum_free(checksum); 81 82 g_free(hash); 69 83 } 84 85 void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, guint8 digest[SHA1_HASH_SIZE]) 86 { 87 b_hmac(G_CHECKSUM_SHA1, key_, key_len, payload, payload_len, &digest); 88 } 89 70 90 71 91 /* I think this follows the scheme described on:
Note: See TracChangeset
for help on using the changeset viewer.