0

OTP Google Acc の実装に取り​​組んでいます。互換性。

これまで、私は使用してきた

-RFC2104( http://www.ietf.org/rfc/rfc2104.txt )、

-RFC4226( http://www.ietf.org/rfc/rfc4226.txt )、

-RFC6238 ( https://www.rfc-editor.org/rfc/rfc6238 )、および次のスキーマ:

[疑似コード時間 OTP] ( http://en.wikipedia.org/wiki/Google_Authenticator#Pseudocode_for_Time_OTP )

function GoogleAuthenticatorCode(string secret)
 key := base32decode(secret)
 message := floor(current Unix time / 30)
 hash := HMAC-SHA1(key, message)
 offset := value of last nibble of hash
 truncatedHash := hash[offset..offset+3]  //4 bytes starting at the offset
 Set the first bit of truncatedHash to zero  //remove the most significant bit 
 code := truncatedHash mod 1000000
 pad code with 0 until length of code is 6
 return code 

" hash := HMAC-SHA1(key, message) " までは問題ありません。他のHMAC-SHA1コンバーターで結果を何度もチェックしました。(まあ、そう思います)。

しかし、その後、何かがうまくいかないと思います...明らかに、Google認証アプリ(Android)と同じコードを取得していないためです。(少なくとも、まだ 6 桁の値です)。

私がよく理解していると確信していない部分は次のとおりです。

 offset := value of last nibble of hash
 truncatedHash := hash[offset..offset+3]  //4 bytes starting at the offset
 Set the first bit of truncatedHash to zero  //remove the most significant bit 

誰かがこれについてより詳細な説明をしてもらえますか?

ありがとう、

4

1 に答える 1

0

offset私の推測では、 の値を間違って受け取る可能性があります。ステートメント

ハッシュの最後のニブルの値

ビットとバイトの順序の適切な定義がない場合、かなりあいまいです。引用されたウィキペディアのページには、多くの実装へのリンクがあります。この Java 実装は、コードをチェックするものだと思います。

byte[] hash = ...

// Dynamically truncate the hash
// OffsetBits are the low order bits of the last byte of the hash
int offset = hash[hash.length - 1] & 0xF;
于 2014-12-23T17:04:57.647 に答える