我試圖編程HMAC_MD5代碼時遇到了一些問題。函數HMAC_MD5:返回成功,但沒有值
我在C工作在STM32F4微處理器上。
這裏是我的(更新)代碼:
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_HASH, ENABLE); static uint8_t
static Challenge[16] = "ldopwhjtsnkiaq8f";
static uint8_t Key[16] = "abcdefghijklmnop";
static uint8_t* HMAC_Key;
static uint8_t* HMAC_Input;
static uint8_t HMAC_Response1[16];
static uint8_t HMAC_Response2[16];
int m = 0;
HMAC_Input = &Challenge[0];
HMAC_Key = &Key[0];
ErrorStatus Result = ERROR;
for(m=0;m<16;m++){
HMAC_Response1[m]=1;
HMAC_Response2[m]=2;
}
Result = HASH_MD5(HMAC_Input, 16, HMAC_Response1);
Result = HMAC_MD5(HMAC_Key, 16, HMAC_Input, 16, HMAC_Response2);
這是HMAC_MD5功能的官方描述(https://github.com/espruino/Espruino/blob/master/targetlibs/stm32f4/lib/stm32f4xx_hash_md5.c):
/**
* @brief Compute the HMAC MD5 digest.
* @param Key: pointer to the Key used for HMAC.
* @param Keylen: length of the Key used for HMAC.
* @param Input: pointer to the Input buffer to be treated.
* @param Ilen: length of the Input buffer
* @param Output: the returned digest
* @retval An ErrorStatus enumeration value:
* - SUCCESS: digest computation done
* - ERROR: digest computation failed
*/
ErrorStatus HMAC_MD5(uint8_t *Key, uint32_t Keylen, uint8_t *Input,
uint32_t Ilen, uint8_t Output[16])
該函數返回值 「成功」,但摘要「輸出」仍爲空(滿''0')。
我沒有從編譯器(Attolic TrueStudio)得到任何警告,我也無法更改密鑰或挑戰(串聯)的值,因爲服務器已經在使用較舊的系統運行。
你是什麼意思'「輸出」仍然是空的'?零?一個測試模式(之前寫入的非零,以便能夠檢測零寫入)仍在那裏? 「結果」如何初始化?不是,如在報價中?將其初始化爲「SUCCESS」以外的內容。 – Yunnosch
您可能想要創建一個實際的[mcve]。對於「V」,你可以假設讀者有可用的庫,即你不需要提供它。 – Yunnosch
是的,'輸出'滿了零('\ 0')。我沒有初始化'Result'和'HMAC_Response'。現在,我已經完成了,帶有ERROR和'1',但是我得到了相同的結果(SUCCES和\ 0)。 好吧,我會嘗試一個「M,C和V例子」 – Indri