| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #include "crypt-port.h" |
| #include "alg-hmac-sha1.h" |
| #include "alg-sha1.h" |
| |
| #include <stdlib.h> |
| |
| #if INCLUDE_sha1 |
| |
| |
| #define HMAC_IPAD 0x36 |
| #define HMAC_OPAD 0x5c |
| |
| |
| #ifndef HMAC_BLOCKSZ |
| # define HMAC_BLOCKSZ 64 |
| # define HASH_LENGTH 20 |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| void |
| hmac_sha1_process_data (const uint8_t *text, size_t text_len, |
| const uint8_t *key, size_t key_len, |
| void *resbuf) |
| { |
| struct sha1_ctx ctx; |
| |
| uint8_t k_ipad[HMAC_BLOCKSZ]; |
| |
| uint8_t k_opad[HMAC_BLOCKSZ]; |
| |
| unsigned char tk[HASH_LENGTH]; |
| size_t i; |
| |
| |
| |
| |
| |
| if (key_len > HMAC_BLOCKSZ) |
| { |
| struct sha1_ctx tctx; |
| |
| sha1_init_ctx (&tctx); |
| sha1_process_bytes (key, &tctx, key_len); |
| sha1_finish_ctx(&tctx, &tk); |
| |
| key = tk; |
| key_len = HASH_LENGTH; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| memset (k_ipad, HMAC_IPAD, sizeof k_ipad); |
| memset (k_opad, HMAC_OPAD, sizeof k_opad); |
| for (i = 0; i < key_len; i++) |
| { |
| k_ipad[i] ^= key[i]; |
| k_opad[i] ^= key[i]; |
| } |
| |
| |
| |
| |
| |
| |
| sha1_init_ctx (&ctx); |
| sha1_process_bytes (k_ipad, &ctx, HMAC_BLOCKSZ); |
| sha1_process_bytes (text, &ctx, text_len); |
| sha1_finish_ctx(&ctx, resbuf); |
| |
| |
| |
| |
| |
| |
| sha1_init_ctx (&ctx); |
| sha1_process_bytes (k_opad, &ctx, HMAC_BLOCKSZ); |
| sha1_process_bytes (resbuf, &ctx, HASH_LENGTH); |
| sha1_finish_ctx(&ctx, resbuf); |
| } |
| |
| #endif |