Beispiel #1
0
/* 'do it all in one go' subroutine     */
void hmac_sha1(const unsigned char key[], unsigned int key_len,
               const unsigned char data[], unsigned int data_len,
               unsigned char mac[], unsigned int mac_len)
{   hmac_ctx    cx[1];

    hmac_sha1_begin(cx);
    hmac_sha1_key(key, key_len, cx);
    hmac_sha1_data(data, data_len, cx);
    hmac_sha1_end(mac, mac_len, cx);
}
Beispiel #2
0
void authenticate_decrypt(void* buf, u32 len)
{
#ifdef GLADMAN_HMAC
 hmac_sha1_data(buf, len, &hmac);
#else
 if (hmac_process(&hmac, buf, len) != CRYPT_OK)
  Z_ERROR("Failed to authenticate");
#endif
 if (ctr_decrypt(buf, buf, len, &ctr) != CRYPT_OK)
  Z_ERROR("Failed to decrypt");
}
Beispiel #3
0
/* compute and output the MAC value */
void hmac_sha1_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1])
{   unsigned char dig[OUT_BLOCK_LENGTH];
    unsigned int i;

    /* if no data has been entered perform a null data phase        */
    if(cx->klen != HMAC_IN_DATA)
        hmac_sha1_data((const unsigned char*)0, 0, cx);

    sha1_end(dig, cx->ctx);         /* complete the inner hash      */

    /* set outer key value using opad and removing ipad */
    for(i = 0; i < IN_BLOCK_LENGTH / sizeof(ARCH_WORD_32); ++i)
        cx->key[i] ^= 0x36363636 ^ 0x5c5c5c5c;

    /* perform the outer hash operation */
    sha1_begin(cx->ctx);
    sha1_hash(cx->key, IN_BLOCK_LENGTH, cx->ctx);
    sha1_hash(dig, OUT_BLOCK_LENGTH, cx->ctx);
    sha1_end(dig, cx->ctx);

    /* output the hash value            */
    for(i = 0; i < mac_len; ++i)
        mac[i] = dig[i];
}