How do I create a HMAC function to generate HOTP value?

Question:

I have written code to generate a 6 digit HOTP value every time a fuction is called. I created this since I want to learn how I can create something by reading a document and experiment with it. I used RFC4226 document as my requirements to achieve my task of generating OTP based on input, counter, Output size and the HMAC-SHA-1 algorithm.

The code works and it returns with a 6 digit OTP everytime the counter is increased. But the problem I do not understand is I tested my code with the test parameters provided in page:31 of RFC4226 document (Link I provided above paragraph). The vaues I get are not as same in that document, But I think I have followed everything mentioned in the document because I cannot seem to find where my mistake is. I know there are libraries to generate HOTP values but I wanted to experiment and learn how to build them myself.

It would be really helpful if anyone can help me o on this and let me know what do I need to do or where am I doing wrong

Asked By: Blueman7

||

Answers:

For byte_counter must apply:

byte_counter = i.to_bytes(8, byteorder='big')

so that the values in Appendix D can be reproduced.


Note that your implementation is not feature complete compared to the reference implementation in Appendix C (but perhaps a 1:1 port is not intended).

Answered By: Topaco
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.