Netthaw / TOTP-MCU

OTP library for C (All MCU)(Pure C)
MIT License
62 stars 12 forks source link

(RP2040) Library doesn't work #3

Closed Devnol closed 3 years ago

Devnol commented 3 years ago

Having made changes after your feedback in #2 I tried using the RFC4226 Test numbers to generate OTP tokens and have reasoned that your library does not work at all under the RP2040 MCU

#include <TOTP.h>
#include <stdio.h>
    uint8_t hmacKey[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30};
   uint8_t step = 0;
   TOTP(hmacKey, 6, 30);
    while (true) {

        uint32_t newCode = getCodeFromSteps(step);
        printf("Token: %d\n", newCode);
        step++;
        sleep_ms(1000);
    }

The above code snippet uses the shared hmac key ascii string "123456789012467890" and generates 10 codes with a step from 0 to 9 using your library.

According to Appendix D of the RFC4226, the OTP codes generated from those inputs should be:

Step OTP
0 755224
1 287082
2 359152
3 969429
4 338314
5 254676
6 287922
7 162583
8 399871
9 520489

However, using the above code and your library generates the following OTP codes:

Step OTP
0 186818
1 340335
2 781800
3 883048
4 082325
5 952379
6 546048
7 777669
8 736400
9 273848

This means that either your library doesn't work on the RP2040 MCU or that it doesn't correctly implement the HOTP and TOTP algorithms specified in the respective IETF RFC documents.

Could you please verify if this happens on your tested MCU or if it's an issue that is only present on my RP2040 MCU?

Thanks in advance.

Devnol commented 3 years ago

Never mind, I thought the second argument in TOTP() was the length of the returned key, not the input

Netthaw commented 3 years ago

Okay. By the way i updated Readme here. Sorry again. https://github.com/Netthaw/TOTP-MCU/commit/180d9f7aef0a454b784efb55163279cf5c17f08b#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R25

AkshaySQT commented 2 years ago

Hi, I'm getting 755224 for all 10 steps. Any idea what could be going wrong?!

Devnol commented 2 years ago

Perhaps you are either not incrementing the step or not updating the variable, without seeing your code it's hard to tell.