intiial commit
Dependencies: MAX8614X USBDevice max32630hsp_test
Diff: main.cpp
- Revision:
- 22:1be3a5f0223e
- Parent:
- 21:0a4f90fb3451
- Child:
- 23:4afef8872432
--- a/main.cpp Fri Aug 17 00:11:10 2018 +0000 +++ b/main.cpp Fri Aug 17 02:26:39 2018 +0000 @@ -39,8 +39,9 @@ //#define DEBUG_ON 1 -void executeSha256(MAX8614X &m, uint8_t *challenge, unsigned int challengeLen, bool romID, uint32_t *response); +void executeSha256(MAX8614X &m, uint32_t *challenge, unsigned int challengeLen, bool romID, uint32_t *response); bool isTheChipAuthenicated(uint32_t *expectedResponse, uint32_t *chipResponse); +void xxx(uint32_t *inData); #define RESPONSE_LEN32 8 @@ -128,12 +129,12 @@ 0xfb0fc974, 0x2da0781e }; - uint8_t challenge_4[CHALLENGE8_LEN] = { // 160 bit, no ROM - 0x4c, 0x3c, 0x0a, 0xca, - 0x61, 0x8a, 0xbd, 0xf2, - 0x34, 0xd8, 0xb3, 0x41, - 0x12, 0x89, 0xf3, 0x78, - 0x65, 0xb6, 0x0d, 0xeb + uint32_t challenge_4[CHALLENGE8_LEN] = { // 160 bit, no ROM + 0x4c3c0aca, + 0x618abdf2, + 0x34d8b341, + 0x1289f378, + 0x65b60deb }; uint32_t expectedResponse_4_noRomID[RESPONSE_LEN32] = { // 160 bit, no ROM 0xae740f91, @@ -145,6 +146,14 @@ 0xc993d165, 0xe5ae5983 }; + + uint32_t challenge_14[CHALLENGE8_LEN] = { // 160 bit, no ROM +0x4c3c0aca, +0x618abdf2, +0x34d8b341, +0x1289f378, +0x65b60deb +}; uint32_t chip_response[RESPONSE_LEN32]; bool valid = 0; @@ -158,7 +167,7 @@ m.init(); //● Compare MAC from MAX86140 wth Host's precalculated MAC. - executeSha256(m, challenge_A, CHALLENGE8_LEN, 1, chip_response); +// executeSha256(m, challenge_A, CHALLENGE8_LEN, 1, chip_response); //● Check PASS or FAIL. valid = isTheChipAuthenicated(chip_response, expectedResponse_A_romID); if (valid) @@ -167,7 +176,7 @@ printf("\r\n Challenge A failed\r\n\r\n"); //● Compare MAC from MAX86140 wth Host's precalculated MAC. - executeSha256(m, challenge_1, CHALLENGE8_LEN, 1, chip_response); +// executeSha256(m, challenge_1, CHALLENGE8_LEN, 1, chip_response); //● Check PASS or FAIL. valid = isTheChipAuthenicated(chip_response, expectedResponse_1_romID); if (valid) @@ -175,14 +184,14 @@ else printf("\r\n Challenge 1 failed\r\n\r\n"); - executeSha256(m, challenge_2, CHALLENGE8_LEN, 0, chip_response); +// executeSha256(m, challenge_2, CHALLENGE8_LEN, 0, chip_response); valid = isTheChipAuthenicated(chip_response, expectedResponse_2_noRomID); if (valid) printf("\r\n Challenge 2 passed\r\n\r\n"); else printf("\r\n Challenge 2 failed\r\n\r\n"); - executeSha256(m, challenge_3, CHALLENGE8_LEN, 1, chip_response); +// executeSha256(m, challenge_3, CHALLENGE8_LEN, 1, chip_response); valid = isTheChipAuthenicated(chip_response, expectedResponse_3_romID); if (valid) printf("\r\n Challenge 3 passed\r\n\r\n"); @@ -195,7 +204,15 @@ printf("\r\n Challenge 4 passed\r\n\r\n"); else printf("\r\n Challenge 4 failed\r\n\r\n"); - +#if 0 + xxx(challenge_14); + executeSha(m, challenge_14, CHALLENGE8_LEN, 0, chip_response); + valid = isTheChipAuthenicated(chip_response, expectedResponse_4_noRomID); + if (valid) + printf("\r\n Challenge 4 passed\r\n\r\n"); + else + printf("\r\n Challenge 4 failed\r\n\r\n"); +#endif //● Disable SHA_EN bit ( Write 0 to SHA_EN bit). m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG, 0); while(1) { @@ -225,9 +242,32 @@ } } } - - -void executeSha256(MAX8614X &m, uint8_t *challenge, unsigned int challengeLen, bool romID, uint32_t *response) +void xxx(uint32_t *inData) +{ + int i, j, k; + uint8_t macData[256]; + uint8_t xData[256]; + uint32_t x32Data[64]; + k = 0; + for (i = 0; i < 5; i++) { + printf("%08x\n\r", inData[i]); + x32Data[i] = inData[i]; + for (j = 0; j <= 3; j++) { + xData[(i*4)+j] = x32Data[i] & 0xFF; +// printf("%02x %d \n\r", xData[k], k); + x32Data[i] = x32Data[i] >> 8; + //printf("%08x\n\r", x32Data[i]); + k++; + } + } + for (i = 0; i < 20; i++) { + if (!(i % 4)) + printf("\r\n "); + printf("%02x", xData[i]); + } + printf("\r\n "); +} +void executeSha256(MAX8614X &m, uint32_t *challenge, unsigned int challengeLen, bool romID, uint32_t *response) { int i, j, k; uint8_t macData[256]; @@ -249,7 +289,19 @@ // Enable Memory Write, Select Bank 0, address 0x00 to 0xFF m.writeRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, MAX8614X::MAX8614X_MEMCNTRL_WR_EN_MASK | MAX8614X::MAX8614X_MEMCNTRL_BANK0_MASK); -#ifdef DEBUG_ON + for (i = 0; i < 5; i++) { + printf("%08x\n\r", challenge[i]); + x32Data[i] = challenge[i]; + for (j = 0; j <= 3; j++) { + xData[(i*4)+j] = x32Data[i] & 0xFF; +// printf("%02x %d \n\r", xData[k], k); + x32Data[i] = x32Data[i] >> 8; + //printf("%08x\n\r", x32Data[i]); + k++; + } + } + +#ifdef 0 printf("\r\n Raw Input Data\r\n\r\n"); for (i = 0; i < challengeLen; i++) { if (!(i % 4)) @@ -259,7 +311,7 @@ printf("\r\n"); #endif - transformData(challenge, xData, challengeLen); + //transformData(challenge, xData, challengeLen); #ifdef DEBUG_ON printf("\r\n Transformed Input Data\r\n\r\n"); @@ -351,4 +403,4 @@ #endif response[i] = x32Data[i]; } -} \ No newline at end of file +}