Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: AES_example shaun_larada Smartage
Fork of Crypto by
HMAC.cpp
00001 #include "HMAC.h" 00002 #include <string.h> 00003 00004 HMAC::HMAC(HashAlgorithm *hashAlgo, uint8_t *k, uint32_t kl): 00005 algo(hashAlgo), 00006 keyLength(kl) 00007 { 00008 memcpy(key, k, keyLength); 00009 uint8_t buffer[64]; 00010 memcpy(buffer, key, keyLength); 00011 memset(&buffer[keyLength], 0, 64-keyLength); 00012 00013 for(int i = 0; i < 64; ++i) 00014 buffer[i] ^= 0x36; 00015 00016 algo->update(buffer, 64); 00017 } 00018 00019 HMAC::~HMAC() 00020 { 00021 delete algo; 00022 } 00023 00024 void HMAC::update(uint8_t *data, uint32_t length) 00025 { 00026 algo->update(data, length); 00027 } 00028 00029 void HMAC::finalize(uint8_t *hash) 00030 { 00031 uint8_t buffer[64], buffer2[64]; 00032 algo->finalize(buffer); 00033 00034 memcpy(buffer2, key, keyLength); 00035 memset(&buffer2[keyLength], 0, 64-keyLength); 00036 for(int i = 0; i < 64; ++i) 00037 buffer2[i] ^= 0x5C; 00038 00039 algo->update(buffer2, 64); 00040 algo->update(buffer, algo->outputSize()); 00041 algo->finalize(hash); 00042 } 00043
Generated on Mon Jul 18 2022 02:59:39 by
1.7.2
