News for hackers. Stuff that matters.
Re:How does Google Authenticator work? by jcims on Friday August 27, 2021 @03:25PM (#28331980)
You can also roll your own with https://github.com/pyauth/pyotp
Re:How does Google Authenticator work? by tyingq on Friday August 27, 2021 @05:44PM (#28333285)
It's almost overkill to bother with a library.

  #!/usr/bin/env python3
  import time, hmac, base64, struct
  def totp(seed,curtime,period,len):
      k = base64.b32decode(seed)
      mac = hmac.new(k, struct.pack('>Q', int(curtime/period)), 'sha1').digest()
      offset=mac[-1] & 0x0f
      otp=struct.unpack('>L', mac[offset:offset+4])[0] & 0x7fffffff
      return str(otp)[-len:].zfill(len)

  myseed='KRUGS4ZANFZSAYJAOJQW4ZDPNUQHG5DS' # use gpg or similar to store
  print(totp(myseed,time.time(),60,6))
Re:How does Google Authenticator work? by jjnoakes on Friday August 27, 2021 @08:25PM (#28334447)
True, I also type this in from memory whenever I need a quick TOTP calculation.
Re:How does Google Authenticator work? by tyingq on Friday August 27, 2021 @09:03PM (#28334614)
Meaning the core TOTP piece isn't much code, and a library might not store/encrypt the seed, display the data, etc, in a way that you want. The bulk of the code for an authenticator app isn't typically the TOTP bit.
Re:How does Google Authenticator work? by pennaMan on Saturday August 28, 2021 @02:05AM (#28335993)
You forgot to add the test cases :)
Re:How does Google Authenticator work? by codetrotter on Friday August 27, 2021 @03:35PM (#28332087)
> roll your own

Libraries for a couple of other languages:

https://crates.io/search?q=4226

https://pkg.go.dev/search?q=4226