in Sources/aliyun-log-c-sdk/log_hmac-sha.c [67:101]
void log_hmac_sha1(void *dest, const void *key, uint16_t keylength_b, const void *msg, uint32_t msglength_b){ /* a one-shot*/
log_sha1_ctx_t s;
uint8_t i;
uint8_t buffer[LOG_SHA1_BLOCK_BYTES];
memset(buffer, 0, LOG_SHA1_BLOCK_BYTES);
/* if key is larger than a block we have to hash it*/
if (keylength_b > LOG_SHA1_BLOCK_BITS){
log_sha1((void*)buffer, key, keylength_b);
} else {
memcpy(buffer, key, (keylength_b+7)/8);
}
for (i=0; i<LOG_SHA1_BLOCK_BYTES; ++i){
buffer[i] ^= LOG_IPAD;
}
log_sha1_init(&s);
log_sha1_nextBlock(&s, buffer);
while (msglength_b >= LOG_SHA1_BLOCK_BITS){
log_sha1_nextBlock(&s, msg);
msg = (uint8_t*)msg + LOG_SHA1_BLOCK_BYTES;
msglength_b -= LOG_SHA1_BLOCK_BITS;
}
log_sha1_lastBlock(&s, msg, msglength_b);
/* since buffer still contains key xor ipad we can do ... */
for (i=0; i<LOG_SHA1_BLOCK_BYTES; ++i){
buffer[i] ^= LOG_IPAD ^ LOG_OPAD;
}
log_sha1_ctx2hash(dest, &s); /* save inner hash temporary to dest */
log_sha1_init(&s);
log_sha1_nextBlock(&s, buffer);
log_sha1_lastBlock(&s, dest, LOG_SHA1_HASH_BITS);
log_sha1_ctx2hash(dest, &s);
}