From 4300f6c6aa4a0993b876c54dbcf882595560a206 Mon Sep 17 00:00:00 2001 From: Ayrx Date: Sun, 9 Feb 2014 15:15:13 +0800 Subject: Added test vectors for HOTP and TOTP algorithms. --- tests/test_utils.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'tests/test_utils.py') diff --git a/tests/test_utils.py b/tests/test_utils.py index 2f4a43c8..901c0281 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -826,3 +826,101 @@ def test_load_pkcs1_vectors(): ) ) assert vectors == expected + + +def test_load_hotp_vectors(): + vector_data = textwrap.dedent(""" + # HOTP Test Vectors + # RFC 4226 Appendix D + + COUNT = 0 + COUNTER = 0 + INTERMEDIATE = cc93cf18508d94934c64b65d8ba7667fb7cde4b0 + TRUNCATED = 4c93cf18 + HOTP = 755224 + + COUNT = 1 + COUNTER = 1 + INTERMEDIATE = 75a48a19d4cbe100644e8ac1397eea747a2d33ab + TRUNCATED = 41397eea + HOTP = 287082 + + COUNT = 2 + COUNTER = 2 + INTERMEDIATE = 0bacb7fa082fef30782211938bc1c5e70416ff44 + TRUNCATED = 82fef30 + HOTP = 359152 + + COUNT = 3 + COUNTER = 3 + INTERMEDIATE = 66c28227d03a2d5529262ff016a1e6ef76557ece + TRUNCATED = 66ef7655 + HOTP = 969429 + """).splitlines() + + assert load_nist_vectors(vector_data) == [ + { + "counter": b"0", + "intermediate": b"cc93cf18508d94934c64b65d8ba7667fb7cde4b0", + "truncated": b"4c93cf18", + "hotp": b"755224", + }, + { + "counter": b"1", + "intermediate": b"75a48a19d4cbe100644e8ac1397eea747a2d33ab", + "truncated": b"41397eea", + "hotp": b"287082", + }, + { + "counter": b"2", + "intermediate": b"0bacb7fa082fef30782211938bc1c5e70416ff44", + "truncated": b"82fef30", + "hotp": b"359152", + }, + { + "counter": b"3", + "intermediate": b"66c28227d03a2d5529262ff016a1e6ef76557ece", + "truncated": b"66ef7655", + "hotp": b"969429", + }, + ] + + +def test_load_totp_vectors(): + vector_data = textwrap.dedent(""" + # TOTP Test Vectors + # RFC 6238 Appendix B + + COUNT = 0 + TIME = 59 + TOTP = 94287082 + MODE = SHA1 + + COUNT = 1 + TIME = 59 + TOTP = 46119246 + MODE = SHA256 + + COUNT = 2 + TIME = 59 + TOTP = 90693936 + MODE = SHA512 + """).splitlines() + + assert load_nist_vectors(vector_data) == [ + { + "time": b"59", + "totp": b"94287082", + "mode": b"SHA1", + }, + { + "time": b"59", + "totp": b"46119246", + "mode": b"SHA256", + }, + { + "time": b"59", + "totp": b"90693936", + "mode": b"SHA512", + }, + ] -- cgit v1.2.3 From efc68383ecb17c88fe1df8ed84b3f3d0e08a6dfc Mon Sep 17 00:00:00 2001 From: Ayrx Date: Mon, 10 Feb 2014 00:01:05 +0800 Subject: Updated vectors to include secret. --- tests/test_utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/test_utils.py') diff --git a/tests/test_utils.py b/tests/test_utils.py index 901c0281..a0571ad6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -838,24 +838,30 @@ def test_load_hotp_vectors(): INTERMEDIATE = cc93cf18508d94934c64b65d8ba7667fb7cde4b0 TRUNCATED = 4c93cf18 HOTP = 755224 + SECRET = 12345678901234567890 COUNT = 1 COUNTER = 1 INTERMEDIATE = 75a48a19d4cbe100644e8ac1397eea747a2d33ab TRUNCATED = 41397eea HOTP = 287082 + SECRET = 12345678901234567890 + COUNT = 2 COUNTER = 2 INTERMEDIATE = 0bacb7fa082fef30782211938bc1c5e70416ff44 TRUNCATED = 82fef30 HOTP = 359152 + SECRET = 12345678901234567890 + COUNT = 3 COUNTER = 3 INTERMEDIATE = 66c28227d03a2d5529262ff016a1e6ef76557ece TRUNCATED = 66ef7655 HOTP = 969429 + SECRET = 12345678901234567890 """).splitlines() assert load_nist_vectors(vector_data) == [ @@ -864,24 +870,28 @@ def test_load_hotp_vectors(): "intermediate": b"cc93cf18508d94934c64b65d8ba7667fb7cde4b0", "truncated": b"4c93cf18", "hotp": b"755224", + "secret": b"12345678901234567890", }, { "counter": b"1", "intermediate": b"75a48a19d4cbe100644e8ac1397eea747a2d33ab", "truncated": b"41397eea", "hotp": b"287082", + "secret": b"12345678901234567890", }, { "counter": b"2", "intermediate": b"0bacb7fa082fef30782211938bc1c5e70416ff44", "truncated": b"82fef30", "hotp": b"359152", + "secret": b"12345678901234567890", }, { "counter": b"3", "intermediate": b"66c28227d03a2d5529262ff016a1e6ef76557ece", "truncated": b"66ef7655", "hotp": b"969429", + "secret": b"12345678901234567890", }, ] @@ -895,16 +905,19 @@ def test_load_totp_vectors(): TIME = 59 TOTP = 94287082 MODE = SHA1 + SECRET = 12345678901234567890 COUNT = 1 TIME = 59 TOTP = 46119246 MODE = SHA256 + SECRET = 12345678901234567890 COUNT = 2 TIME = 59 TOTP = 90693936 MODE = SHA512 + SECRET = 12345678901234567890 """).splitlines() assert load_nist_vectors(vector_data) == [ @@ -912,15 +925,18 @@ def test_load_totp_vectors(): "time": b"59", "totp": b"94287082", "mode": b"SHA1", + "secret": b"12345678901234567890", }, { "time": b"59", "totp": b"46119246", "mode": b"SHA256", + "secret": b"12345678901234567890", }, { "time": b"59", "totp": b"90693936", "mode": b"SHA512", + "secret": b"12345678901234567890", }, ] -- cgit v1.2.3