aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-03 13:23:21 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-03 14:38:18 -0900
commite19a961d9166d892f2a9484441888701fa2d0dd8 (patch)
treed402c853114b6b59a4f7df91868ae6ada5461a03 /tests
parent352502b06eb8de133d99a0fed13fcc0711398f45 (diff)
downloadotputils-e19a961d9166d892f2a9484441888701fa2d0dd8.tar.gz
otputils-e19a961d9166d892f2a9484441888701fa2d0dd8.tar.bz2
otputils-e19a961d9166d892f2a9484441888701fa2d0dd8.tar.xz
otputils-e19a961d9166d892f2a9484441888701fa2d0dd8.zip
libotputil: adding ability to specify HMAC for HOTP/TOTP
Diffstat (limited to 'tests')
-rw-r--r--tests/test-hotp.c25
-rw-r--r--tests/test-totp.c11
2 files changed, 34 insertions, 2 deletions
diff --git a/tests/test-hotp.c b/tests/test-hotp.c
index 6522cbb..3dfb7ad 100644
--- a/tests/test-hotp.c
+++ b/tests/test-hotp.c
@@ -91,7 +91,9 @@ struct _test_data
91 const char * hotp_kb32; 91 const char * hotp_kb32;
92 uint64_t hotp_c; 92 uint64_t hotp_c;
93 int hotp_code; 93 int hotp_code;
94 int hotp_hmac;
94 int hotp_digits; 95 int hotp_digits;
96 int intpad;
95}; 97};
96 98
97 99
@@ -113,6 +115,7 @@ static testdata_t test_data[] =
113 // count 0 / 6 digits 115 // count 0 / 6 digits
114 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 116 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
115 .hotp_c = 0ULL, 117 .hotp_c = 0ULL,
118 .hotp_hmac = OTPUTIL_MD_SHA1,
116 .hotp_code = 755224, 119 .hotp_code = 755224,
117 .hotp_digits = 6, 120 .hotp_digits = 6,
118 }, 121 },
@@ -120,6 +123,7 @@ static testdata_t test_data[] =
120 // count 1 / 6 digits 123 // count 1 / 6 digits
121 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 124 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
122 .hotp_c = 1ULL, 125 .hotp_c = 1ULL,
126 .hotp_hmac = OTPUTIL_MD_SHA1,
123 .hotp_code = 287082, 127 .hotp_code = 287082,
124 .hotp_digits = 6, 128 .hotp_digits = 6,
125 }, 129 },
@@ -127,6 +131,7 @@ static testdata_t test_data[] =
127 // count 2 / 6 digits 131 // count 2 / 6 digits
128 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 132 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
129 .hotp_c = 2ULL, 133 .hotp_c = 2ULL,
134 .hotp_hmac = OTPUTIL_MD_SHA1,
130 .hotp_code = 359152, 135 .hotp_code = 359152,
131 .hotp_digits = 6, 136 .hotp_digits = 6,
132 }, 137 },
@@ -134,6 +139,7 @@ static testdata_t test_data[] =
134 // count 3 / 6 digits 139 // count 3 / 6 digits
135 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 140 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
136 .hotp_c = 3ULL, 141 .hotp_c = 3ULL,
142 .hotp_hmac = OTPUTIL_MD_SHA1,
137 .hotp_code = 969429, 143 .hotp_code = 969429,
138 .hotp_digits = 6, 144 .hotp_digits = 6,
139 }, 145 },
@@ -141,6 +147,7 @@ static testdata_t test_data[] =
141 // count 4 / 6 digits 147 // count 4 / 6 digits
142 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 148 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
143 .hotp_c = 4ULL, 149 .hotp_c = 4ULL,
150 .hotp_hmac = OTPUTIL_MD_SHA1,
144 .hotp_code = 338314, 151 .hotp_code = 338314,
145 .hotp_digits = 6, 152 .hotp_digits = 6,
146 }, 153 },
@@ -148,6 +155,7 @@ static testdata_t test_data[] =
148 // count 5 / 6 digits 155 // count 5 / 6 digits
149 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 156 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
150 .hotp_c = 5ULL, 157 .hotp_c = 5ULL,
158 .hotp_hmac = OTPUTIL_MD_SHA1,
151 .hotp_code = 254676, 159 .hotp_code = 254676,
152 .hotp_digits = 6, 160 .hotp_digits = 6,
153 }, 161 },
@@ -155,6 +163,7 @@ static testdata_t test_data[] =
155 // count 6 / 6 digits 163 // count 6 / 6 digits
156 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 164 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
157 .hotp_c = 6ULL, 165 .hotp_c = 6ULL,
166 .hotp_hmac = OTPUTIL_MD_SHA1,
158 .hotp_code = 287922, 167 .hotp_code = 287922,
159 .hotp_digits = 6, 168 .hotp_digits = 6,
160 }, 169 },
@@ -162,6 +171,7 @@ static testdata_t test_data[] =
162 // count 7 / 6 digits 171 // count 7 / 6 digits
163 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 172 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
164 .hotp_c = 7ULL, 173 .hotp_c = 7ULL,
174 .hotp_hmac = OTPUTIL_MD_SHA1,
165 .hotp_code = 162583, 175 .hotp_code = 162583,
166 .hotp_digits = 6, 176 .hotp_digits = 6,
167 }, 177 },
@@ -169,6 +179,7 @@ static testdata_t test_data[] =
169 // count 8 / 6 digits 179 // count 8 / 6 digits
170 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 180 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
171 .hotp_c = 8ULL, 181 .hotp_c = 8ULL,
182 .hotp_hmac = OTPUTIL_MD_SHA1,
172 .hotp_code = 399871, 183 .hotp_code = 399871,
173 .hotp_digits = 6, 184 .hotp_digits = 6,
174 }, 185 },
@@ -176,6 +187,7 @@ static testdata_t test_data[] =
176 // count 9 / 6 digits 187 // count 9 / 6 digits
177 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 188 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
178 .hotp_c = 9ULL, 189 .hotp_c = 9ULL,
190 .hotp_hmac = OTPUTIL_MD_SHA1,
179 .hotp_code = 520489, 191 .hotp_code = 520489,
180 .hotp_digits = 6, 192 .hotp_digits = 6,
181 }, 193 },
@@ -183,6 +195,7 @@ static testdata_t test_data[] =
183 // count 0 / 10 digits 195 // count 0 / 10 digits
184 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 196 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
185 .hotp_c = 0ULL, 197 .hotp_c = 0ULL,
198 .hotp_hmac = OTPUTIL_MD_SHA1,
186 .hotp_code = 1284755224, 199 .hotp_code = 1284755224,
187 .hotp_digits = 10, 200 .hotp_digits = 10,
188 }, 201 },
@@ -190,6 +203,7 @@ static testdata_t test_data[] =
190 // count 0 / 10 digits 203 // count 0 / 10 digits
191 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 204 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
192 .hotp_c = 1ULL, 205 .hotp_c = 1ULL,
206 .hotp_hmac = OTPUTIL_MD_SHA1,
193 .hotp_code = 1094287082, 207 .hotp_code = 1094287082,
194 .hotp_digits = 10, 208 .hotp_digits = 10,
195 }, 209 },
@@ -197,6 +211,7 @@ static testdata_t test_data[] =
197 // count 2 / 10 digits 211 // count 2 / 10 digits
198 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 212 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
199 .hotp_c = 2ULL, 213 .hotp_c = 2ULL,
214 .hotp_hmac = OTPUTIL_MD_SHA1,
200 .hotp_code = 137359152, 215 .hotp_code = 137359152,
201 .hotp_digits = 10, 216 .hotp_digits = 10,
202 }, 217 },
@@ -204,6 +219,7 @@ static testdata_t test_data[] =
204 // count 3 / 10 digits 219 // count 3 / 10 digits
205 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 220 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
206 .hotp_c = 3ULL, 221 .hotp_c = 3ULL,
222 .hotp_hmac = OTPUTIL_MD_SHA1,
207 .hotp_code = 1726969429, 223 .hotp_code = 1726969429,
208 .hotp_digits = 10, 224 .hotp_digits = 10,
209 }, 225 },
@@ -211,6 +227,7 @@ static testdata_t test_data[] =
211 // count 4 / 10 digits 227 // count 4 / 10 digits
212 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 228 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
213 .hotp_c = 4ULL, 229 .hotp_c = 4ULL,
230 .hotp_hmac = OTPUTIL_MD_SHA1,
214 .hotp_code = 1640338314, 231 .hotp_code = 1640338314,
215 .hotp_digits = 10, 232 .hotp_digits = 10,
216 }, 233 },
@@ -218,6 +235,7 @@ static testdata_t test_data[] =
218 // count 5 / 10 digits 235 // count 5 / 10 digits
219 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 236 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
220 .hotp_c = 5ULL, 237 .hotp_c = 5ULL,
238 .hotp_hmac = OTPUTIL_MD_SHA1,
221 .hotp_code = 868254676, 239 .hotp_code = 868254676,
222 .hotp_digits = 10, 240 .hotp_digits = 10,
223 }, 241 },
@@ -225,6 +243,7 @@ static testdata_t test_data[] =
225 // count 6 / 10 digits 243 // count 6 / 10 digits
226 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 244 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
227 .hotp_c = 6ULL, 245 .hotp_c = 6ULL,
246 .hotp_hmac = OTPUTIL_MD_SHA1,
228 .hotp_code = 1918287922, 247 .hotp_code = 1918287922,
229 .hotp_digits = 10, 248 .hotp_digits = 10,
230 }, 249 },
@@ -232,6 +251,7 @@ static testdata_t test_data[] =
232 // count 7 / 10 digits 251 // count 7 / 10 digits
233 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 252 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
234 .hotp_c = 7ULL, 253 .hotp_c = 7ULL,
254 .hotp_hmac = OTPUTIL_MD_SHA1,
235 .hotp_code = 82162583, 255 .hotp_code = 82162583,
236 .hotp_digits = 10, 256 .hotp_digits = 10,
237 }, 257 },
@@ -239,6 +259,7 @@ static testdata_t test_data[] =
239 // count 8 / 10 digits 259 // count 8 / 10 digits
240 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 260 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
241 .hotp_c = 8ULL, 261 .hotp_c = 8ULL,
262 .hotp_hmac = OTPUTIL_MD_SHA1,
242 .hotp_code = 673399871, 263 .hotp_code = 673399871,
243 .hotp_digits = 10, 264 .hotp_digits = 10,
244 }, 265 },
@@ -246,12 +267,14 @@ static testdata_t test_data[] =
246 // count 9 / 10 digits 267 // count 9 / 10 digits
247 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 268 .hotp_kb32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
248 .hotp_c = 9ULL, 269 .hotp_c = 9ULL,
270 .hotp_hmac = OTPUTIL_MD_SHA1,
249 .hotp_code = 645520489, 271 .hotp_code = 645520489,
250 .hotp_digits = 10, 272 .hotp_digits = 10,
251 }, 273 },
252 { 274 {
253 .hotp_kb32 = NULL, 275 .hotp_kb32 = NULL,
254 .hotp_c = 0, 276 .hotp_c = 0,
277 .hotp_hmac = 0,
255 .hotp_code = 0, 278 .hotp_code = 0,
256 .hotp_digits = 0, 279 .hotp_digits = 0,
257 }, 280 },
@@ -378,7 +401,7 @@ main(
378 return(1); 401 return(1);
379 }; 402 };
380 403
381 if ((hotp_code = otputil_hotp_code(hotp_k, p->hotp_c, p->hotp_digits)) == -1) 404 if ((hotp_code = otputil_hotp_code(hotp_k, p->hotp_c, p->hotp_hmac, p->hotp_digits)) == -1)
382 { 405 {
383 fprintf(stderr, "%s: otputil_hotp_code(): internal error\n", PROGRAM_NAME); 406 fprintf(stderr, "%s: otputil_hotp_code(): internal error\n", PROGRAM_NAME);
384 otputil_bvfree(hotp_k); 407 otputil_bvfree(hotp_k);
diff --git a/tests/test-totp.c b/tests/test-totp.c
index 615fbe9..76e0341 100644
--- a/tests/test-totp.c
+++ b/tests/test-totp.c
@@ -92,8 +92,10 @@ struct _test_data
92 uint64_t totp_t0; 92 uint64_t totp_t0;
93 uint64_t totp_tx; 93 uint64_t totp_tx;
94 uint64_t totp_time; 94 uint64_t totp_time;
95 int totp_hmac;
95 int totp_code; 96 int totp_code;
96 int totp_digits; 97 int totp_digits;
98 int intpad;
97}; 99};
98 100
99 101
@@ -117,6 +119,7 @@ static testdata_t test_data[] =
117 .totp_t0 = 0ULL, 119 .totp_t0 = 0ULL,
118 .totp_tx = 30ULL, 120 .totp_tx = 30ULL,
119 .totp_time = 59, 121 .totp_time = 59,
122 .totp_hmac = OTPUTIL_MD_SHA1,
120 .totp_code = 94287082, 123 .totp_code = 94287082,
121 .totp_digits = 8, 124 .totp_digits = 8,
122 }, 125 },
@@ -126,6 +129,7 @@ static testdata_t test_data[] =
126 .totp_t0 = 0ULL, 129 .totp_t0 = 0ULL,
127 .totp_tx = 30ULL, 130 .totp_tx = 30ULL,
128 .totp_time = 1111111109, 131 .totp_time = 1111111109,
132 .totp_hmac = OTPUTIL_MD_SHA1,
129 .totp_code = 7081804, // RFC states 07081804 133 .totp_code = 7081804, // RFC states 07081804
130 .totp_digits = 8, 134 .totp_digits = 8,
131 }, 135 },
@@ -135,6 +139,7 @@ static testdata_t test_data[] =
135 .totp_t0 = 0ULL, 139 .totp_t0 = 0ULL,
136 .totp_tx = 30ULL, 140 .totp_tx = 30ULL,
137 .totp_time = 1111111111, 141 .totp_time = 1111111111,
142 .totp_hmac = OTPUTIL_MD_SHA1,
138 .totp_code = 14050471, 143 .totp_code = 14050471,
139 .totp_digits = 8, 144 .totp_digits = 8,
140 }, 145 },
@@ -144,6 +149,7 @@ static testdata_t test_data[] =
144 .totp_t0 = 0ULL, 149 .totp_t0 = 0ULL,
145 .totp_tx = 30ULL, 150 .totp_tx = 30ULL,
146 .totp_time = 1234567890, 151 .totp_time = 1234567890,
152 .totp_hmac = OTPUTIL_MD_SHA1,
147 .totp_code = 89005924, 153 .totp_code = 89005924,
148 .totp_digits = 8, 154 .totp_digits = 8,
149 }, 155 },
@@ -153,6 +159,7 @@ static testdata_t test_data[] =
153 .totp_t0 = 0ULL, 159 .totp_t0 = 0ULL,
154 .totp_tx = 30ULL, 160 .totp_tx = 30ULL,
155 .totp_time = 2000000000, 161 .totp_time = 2000000000,
162 .totp_hmac = OTPUTIL_MD_SHA1,
156 .totp_code = 69279037, 163 .totp_code = 69279037,
157 .totp_digits = 8, 164 .totp_digits = 8,
158 }, 165 },
@@ -162,6 +169,7 @@ static testdata_t test_data[] =
162 .totp_t0 = 0ULL, 169 .totp_t0 = 0ULL,
163 .totp_tx = 30ULL, 170 .totp_tx = 30ULL,
164 .totp_time = 20000000000, 171 .totp_time = 20000000000,
172 .totp_hmac = OTPUTIL_MD_SHA1,
165 .totp_code = 65353130, 173 .totp_code = 65353130,
166 .totp_digits = 8, 174 .totp_digits = 8,
167 }, 175 },
@@ -170,6 +178,7 @@ static testdata_t test_data[] =
170 .totp_t0 = 0, 178 .totp_t0 = 0,
171 .totp_tx = 0, 179 .totp_tx = 0,
172 .totp_time = 0, 180 .totp_time = 0,
181 .totp_hmac = 0,
173 .totp_code = 0, 182 .totp_code = 0,
174 .totp_digits = 0, 183 .totp_digits = 0,
175 } 184 }
@@ -298,7 +307,7 @@ main(
298 return(1); 307 return(1);
299 }; 308 };
300 309
301 if ((totp_code = otputil_totp_code(totp_k, p->totp_t0, p->totp_tx, p->totp_time, p->totp_digits)) == -1) 310 if ((totp_code = otputil_totp_code(totp_k, p->totp_t0, p->totp_tx, p->totp_time, p->totp_hmac, p->totp_digits)) == -1)
302 { 311 {
303 fprintf(stderr, "%s: otputil_totp_code(): internal error\n", PROGRAM_NAME); 312 fprintf(stderr, "%s: otputil_totp_code(): internal error\n", PROGRAM_NAME);
304 otputil_bvfree(totp_k); 313 otputil_bvfree(totp_k);