ft_otp
全体像のざっくりの理解
TOTP: Time based One Time Password
TOTP:: Master Key -> Time -> OTP
HOTP: HMAC One Time Password
code: hotp.bnf
TOTP = HOTP(K, T)
T = (Current Unix time - T0) / X, where the default floor function is used in the computation.
K = shared secret between client and server; each HOTP generator has a different and unique secret K.
T0 = 0
X = 30
HOTP(K,C) = Truncate(HMAC-SHA-1(K,C))
C = 8-byte counter value, the moving factor. This counter MUST be synchronized between the HOTP generator (client) and the HOTP validator (server).
Digit = 6
Step 1: Generate an HMAC-SHA-1 value
Let HS = HMAC-SHA-1(K,C) // HS is a 20-byte string
Step 2: Generate a 4-byte string (Dynamic Truncation)
Let Sbits = DT(HS) // DT, defined below, returns a 31-bit string
DT(String) // String = String[0]...String[19]
Let OffsetBits be the low-order 4 bits of String[19]
Offset = StToNum(OffsetBits) // 0 <= OffSet <= 15
Let P = String[OffSet]...String[OffSet+3]
Return the Last 31 bits of P
Step 3: Compute an HOTP value
Let Snum = StToNum(Sbits) // Convert S to a number in 0...2^{31}-1
Return D = Snum mod 10^Digit // D is a number in the range 0...10^{Digit}-1
低レイヤーの理解
✅SHA-1 を理解する
RFC 2104 - HMAC: Keyed-Hashing for Message Authentication
上記Truncateを理解する
✅高レイヤーの描き出し
✅データ構造の策定
✅環境構築
⏳debug環境
✅テストの作成
設計
構築
✅コーディング
✅RED
✅GREEN
✅CLEAN