[Request - Answered] Library for TOTP or HOTP

Hi. Is there a library to generate TOTP or HOTP? It would be a good way to authenticate messages sent to and from one device to another (not spark).

Thanks.
adde

For everyone else’s benefit:

TOTP: Time-based One Time Password Link
HOTP: HMAC-based One Time Password Link

@addeswe I found this: http://www.lucadentella.it/en/totp-libreria-per-arduino/. Perhaps that could be ported? If I find some time I’ll try to do the port myself.

3 Likes

@harrisonhjones, there is also the Cryptosuite library to port but all can be done quickly. :smile:

2 Likes

Thanks for the vote of confidence!

Anyone interested in a working (but probably not pretty) Spark version of the library see the GitHub repo I just put up here

Here’s a demo of one of the examples in the library:

3 Likes

Holy schmoly that was quick! Thanks alot harrisonhjones! This will do it.
Short question. If you want a larger hmacKey, you just increment the line:

TOTP totp = TOTP(hmacKey, 10);
or:
TOTP totp = TOTP(hmacKey, sizeof(hmacKey));

1 Like

That would probably work. I’ll test it tonight. The only problem I see with using a larger key is that the QR code import won’t work the way it is now. That can be fixed however.

@addeswe, I was unable to get the library to work with keys of greater length than 10. You are welcome to help me out there. I will happily accept pull requests!