totp.h 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #define OTP_ERROR (0)
  5. /*
  6. Must compute HMAC using passed arguments,
  7. output as char array through output.
  8. key is secret key.
  9. input is input number.
  10. output is an output buffer of the resulting HMAC operation.
  11. Must return 0 if error, or the length in bytes of the HMAC operation.
  12. */
  13. typedef int (*TOTP_ALGO)(const uint8_t* key, uint8_t key_length, const uint8_t* input, uint8_t input_length, uint8_t* output);
  14. /*
  15. Computes HMAC using SHA1
  16. */
  17. extern const TOTP_ALGO TOTP_ALGO_SHA1;
  18. /*
  19. Computes HMAC using SHA256
  20. */
  21. extern const TOTP_ALGO TOTP_ALGO_SHA256;
  22. /*
  23. Computes HMAC using SHA512
  24. */
  25. extern const TOTP_ALGO TOTP_ALGO_SHA512;
  26. /*
  27. Computes TOTP token
  28. Returns:
  29. TOTP token on success
  30. 0 otherwise
  31. */
  32. uint32_t totp_at(TOTP_ALGO algo, uint8_t digits, const uint8_t* plain_secret, uint8_t plain_secret_length, uint64_t for_time, float timezone, uint8_t interval);