aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-09 16:32:15 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-09 17:23:58 -0900
commit2c537f473283080b16c19b32f816211012168d4a (patch)
tree0790f9dbafb0e844258220b2e6223382ab8cc064 /tests
parent8abad80f4bc1a390e82eaa1bc55d06722906a13b (diff)
downloadotputils-2c537f473283080b16c19b32f816211012168d4a.tar.gz
otputils-2c537f473283080b16c19b32f816211012168d4a.tar.bz2
otputils-2c537f473283080b16c19b32f816211012168d4a.tar.xz
otputils-2c537f473283080b16c19b32f816211012168d4a.zip
test-otp-encode: adding test
Diffstat (limited to 'tests')
-rw-r--r--tests/otp-data.c351
-rw-r--r--tests/otp-data.h82
-rw-r--r--tests/test-otp-encode.c249
3 files changed, 682 insertions, 0 deletions
diff --git a/tests/otp-data.c b/tests/otp-data.c
new file mode 100644
index 0000000..24296a9
--- /dev/null
+++ b/tests/otp-data.c
@@ -0,0 +1,351 @@
1/*
2 * OTP Utilities
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of David M. Syzdek nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30/*
31 * @file tests/otp-data.c
32 */
33#define _TESTS_OTP_DATA_C 1
34
35///////////////
36// //
37// Headers //
38// //
39///////////////
40#pragma mark - Headers
41
42#ifdef HAVE_CONFIG_H
43#include <config.h>
44#endif
45
46#include <inttypes.h>
47#include <otputil.h>
48
49#include "otp-data.h"
50
51
52/////////////////
53// //
54// Variables //
55// //
56/////////////////
57#pragma mark - Variables
58
59#pragma mark otp_test_data[]
60otptest_t otp_test_data[] =
61{
62 // RFC 2289 Appendix C - OTP Verification Examples: MD4 ENCODINGS
63 {
64 .method = OTPUTIL_MD_MD4,
65 .pass = "This is a test.",
66 .seed = "TeSt",
67 .count = 0,
68 .hex = "D185 4218 EBBB 0B51",
69 .six = "ROME MUG FRED SCAN LIVE LACE",
70 .dat.bv_val = (uint8_t []){ 0xD1, 0x85, 0x42, 0x18, 0xEB, 0xBB, 0x0B, 0x51 },
71 .dat.bv_len = 8,
72 },
73 {
74 .method = OTPUTIL_MD_MD4,
75 .pass = "This is a test.",
76 .seed = "TeSt",
77 .count = 1,
78 .hex = "6347 3EF0 1CD0 B444",
79 .six = "CARD SAD MINI RYE COL KIN",
80 .dat.bv_val = (uint8_t []){ 0x63, 0x47, 0x3E, 0xF0, 0x1C, 0xD0, 0xB4, 0x44 },
81 .dat.bv_len = 8,
82 },
83 {
84 .method = OTPUTIL_MD_MD4,
85 .pass = "This is a test.",
86 .seed = "TeSt",
87 .count = 99,
88 .hex = "C5E6 1277 6E6C 237A",
89 .six = "NOTE OUT IBIS SINK NAVE MODE",
90 .dat.bv_val = (uint8_t []){ 0xC5, 0xE6, 0x12, 0x77, 0x6E, 0x6C, 0x23, 0x7A },
91 .dat.bv_len = 8,
92 },
93 {
94 .method = OTPUTIL_MD_MD4,
95 .pass = "AbCdEfGhIjK",
96 .seed = "alpha1",
97 .count = 0,
98 .hex = "5007 6F47 EB1A DE4E",
99 .six = "AWAY SEN ROOK SALT LICE MAP",
100 .dat.bv_val = (uint8_t []){ 0x50, 0x07, 0x6F, 0x47, 0xEB, 0x1A, 0xDE, 0x4E },
101 .dat.bv_len = 8,
102 },
103 {
104 .method = OTPUTIL_MD_MD4,
105 .pass = "AbCdEfGhIjK",
106 .seed = "alpha1",
107 .count = 1,
108 .hex = "65D2 0D19 49B5 F7AB",
109 .six = "CHEW GRIM WU HANG BUCK SAID",
110 .dat.bv_val = (uint8_t []){ 0x65, 0xD2, 0x0D, 0x19, 0x49, 0xB5, 0xF7, 0xAB },
111 .dat.bv_len = 8,
112 },
113 {
114 .method = OTPUTIL_MD_MD4,
115 .pass = "AbCdEfGhIjK",
116 .seed = "alpha1",
117 .count = 99,
118 .hex = "D150 C82C CE6F 62D1",
119 .six = "ROIL FREE COG HUNK WAIT COCA",
120 .dat.bv_val = (uint8_t []){ 0xD1, 0x50, 0xC8, 0x2C, 0xCE, 0x6F, 0x62, 0xD1 },
121 .dat.bv_len = 8,
122 },
123 {
124 .method = OTPUTIL_MD_MD4,
125 .pass = "OTP's are good",
126 .seed = "correct",
127 .count = 0,
128 .hex = "849C 79D4 F6F5 5388",
129 .six = "FOOL STEM DONE TOOL BECK NILE",
130 .dat.bv_val = (uint8_t []){ 0x84, 0x9C, 0x79, 0xD4, 0xF6, 0xF5, 0x53, 0x88 },
131 .dat.bv_len = 8,
132 },
133 {
134 .method = OTPUTIL_MD_MD4,
135 .pass = "OTP's are good",
136 .seed = "correct",
137 .count = 1,
138 .hex = "8C09 92FB 2508 47B1",
139 .six = "GIST AMOS MOOT AIDS FOOD SEEM",
140 .dat.bv_val = (uint8_t []){ 0x8C, 0x09, 0x92, 0xFB, 0x25, 0x08, 0x47, 0xB1 },
141 .dat.bv_len = 8,
142 },
143 {
144 .method = OTPUTIL_MD_MD4,
145 .pass = "OTP's are good",
146 .seed = "correct",
147 .count = 99,
148 .hex = "3F3B F4B4 145F D74B",
149 .six = "TAG SLOW NOV MIN WOOL KENO",
150 .dat.bv_val = (uint8_t []){ 0x3F, 0x3B, 0xF4, 0xB4, 0x14, 0x5F, 0xD7, 0x4B },
151 .dat.bv_len = 8,
152 },
153
154 // RFC 2289 Appendix C - OTP Verification Examples: MD5 ENCODINGS
155 {
156 .method = OTPUTIL_MD_MD5,
157 .pass = "This is a test.",
158 .seed = "TeSt",
159 .count = 0,
160 .hex = "9E87 6134 D904 99DD",
161 .six = "INCH SEA ANNE LONG AHEM TOUR",
162 .dat.bv_val = (uint8_t []){ 0x9E, 0x87, 0x61, 0x34, 0xD9, 0x04, 0x99, 0xDD },
163 .dat.bv_len = 8,
164 },
165 {
166 .method = OTPUTIL_MD_MD5,
167 .pass = "This is a test.",
168 .seed = "TeSt",
169 .count = 1,
170 .hex = "7965 E054 36F5 029F",
171 .six = "EASE OIL FUM CURE AWRY AVIS",
172 .dat.bv_val = (uint8_t []){ 0x79, 0x65, 0xE0, 0x54, 0x36, 0xF5, 0x02, 0x9F },
173 .dat.bv_len = 8,
174 },
175 {
176 .method = OTPUTIL_MD_MD5,
177 .pass = "This is a test.",
178 .seed = "TeSt",
179 .count = 99,
180 .hex = "50FE 1962 C496 5880",
181 .six = "BAIL TUFT BITS GANG CHEF THY",
182 .dat.bv_val = (uint8_t []){ 0x50, 0xFE, 0x19, 0x62, 0xC4, 0x96, 0x58, 0x80 },
183 .dat.bv_len = 8,
184 },
185 {
186 .method = OTPUTIL_MD_MD5,
187 .pass = "AbCdEfGhIjK",
188 .seed = "alpha1",
189 .count = 0,
190 .hex = "8706 6DD9 644B F206",
191 .six = "FULL PEW DOWN ONCE MORT ARC",
192 .dat.bv_val = (uint8_t []){ 0x87, 0x06, 0x6D, 0xD9, 0x64, 0x4B, 0xF2, 0x06 },
193 .dat.bv_len = 8,
194 },
195 {
196 .method = OTPUTIL_MD_MD5,
197 .pass = "AbCdEfGhIjK",
198 .seed = "alpha1",
199 .count = 1,
200 .hex = "7CD3 4C10 40AD D14B",
201 .six = "FACT HOOF AT FIST SITE KENT",
202 .dat.bv_val = (uint8_t []){ 0x7C, 0xD3, 0x4C, 0x10, 0x40, 0xAD, 0xD1, 0x4B },
203 .dat.bv_len = 8,
204 },
205 {
206 .method = OTPUTIL_MD_MD5,
207 .pass = "AbCdEfGhIjK",
208 .seed = "alpha1",
209 .count = 99,
210 .hex = "5AA3 7A81 F212 146C",
211 .six = "BODE HOP JAKE STOW JUT RAP",
212 .dat.bv_val = (uint8_t []){ 0x5A, 0xA3, 0x7A, 0x81, 0xF2, 0x12, 0x14, 0x6C },
213 .dat.bv_len = 8,
214 },
215 {
216 .method = OTPUTIL_MD_MD5,
217 .pass = "OTP's are good",
218 .seed = "correct",
219 .count = 0,
220 .hex = "F205 7539 43DE 4CF9",
221 .six = "ULAN NEW ARMY FUSE SUIT EYED",
222 .dat.bv_val = (uint8_t []){ 0xF2, 0x05, 0x75, 0x39, 0x43, 0xDE, 0x4C, 0xF9 },
223 .dat.bv_len = 8,
224 },
225 {
226 .method = OTPUTIL_MD_MD5,
227 .pass = "OTP's are good",
228 .seed = "correct",
229 .count = 1,
230 .hex = "DDCD AC95 6F23 4937",
231 .six = "SKIM CULT LOB SLAM POE HOWL",
232 .dat.bv_val = (uint8_t []){ 0xDD, 0xCD, 0xAC, 0x95, 0x6F, 0x23, 0x49, 0x37 },
233 .dat.bv_len = 8,
234 },
235 {
236 .method = OTPUTIL_MD_MD5,
237 .pass = "OTP's are good",
238 .seed = "correct",
239 .count = 99,
240 .hex = "B203 E28F A525 BE47",
241 .six = "LONG IVY JULY AJAR BOND LEE",
242 .dat.bv_val = (uint8_t []){ 0xB2, 0x03, 0xE2, 0x8F, 0xA5, 0x25, 0xBE, 0x47 },
243 .dat.bv_len = 8,
244 },
245
246 // RFC 2289 Appendix C - OTP Verification Examples: SHA1 ENCODINGS
247 {
248 .method = OTPUTIL_MD_SHA1,
249 .pass = "This is a test.",
250 .seed = "TeSt",
251 .count = 0,
252 .hex = "BB9E 6AE1 979D 8FF4",
253 .six = "MILT VARY MAST OK SEES WENT",
254 .dat.bv_val = (uint8_t []){ 0xBB, 0x9E, 0x6A, 0xE1, 0x97, 0x9D, 0x8F, 0xF4 },
255 .dat.bv_len = 8,
256 },
257 {
258 .method = OTPUTIL_MD_SHA1,
259 .pass = "This is a test.",
260 .seed = "TeSt",
261 .count = 1,
262 .hex = "63D9 3663 9734 385B",
263 .six = "CART OTTO HIVE ODE VAT NUT",
264 .dat.bv_val = (uint8_t []){ 0x63, 0xD9, 0x36, 0x63, 0x97, 0x34, 0x38, 0x5B },
265 .dat.bv_len = 8,
266 },
267 {
268 .method = OTPUTIL_MD_SHA1,
269 .pass = "This is a test.",
270 .seed = "TeSt",
271 .count = 99,
272 .hex = "87FE C776 8B73 CCF9",
273 .six = "GAFF WAIT SKID GIG SKY EYED",
274 .dat.bv_val = (uint8_t []){ 0x87, 0xFE, 0xC7, 0x76, 0x8B, 0x73, 0xCC, 0xF9 },
275 .dat.bv_len = 8,
276 },
277 {
278 .method = OTPUTIL_MD_SHA1,
279 .pass = "AbCdEfGhIjK",
280 .seed = "alpha1",
281 .count = 0,
282 .hex = "AD85 F658 EBE3 83C9",
283 .six = "LEST OR HEEL SCOT ROB SUIT",
284 .dat.bv_val = (uint8_t []){ 0xAD, 0x85, 0xF6, 0x58, 0xEB, 0xE3, 0x83, 0xC9 },
285 .dat.bv_len = 8,
286 },
287 {
288 .method = OTPUTIL_MD_SHA1,
289 .pass = "AbCdEfGhIjK",
290 .seed = "alpha1",
291 .count = 1,
292 .hex = "D07C E229 B5CF 119B",
293 .six = "RITE TAKE GELD COST TUNE RECK",
294 .dat.bv_val = (uint8_t []){ 0xD0, 0x7C, 0xE2, 0x29, 0xB5, 0xCF, 0x11, 0x9B },
295 .dat.bv_len = 8,
296 },
297 {
298 .method = OTPUTIL_MD_SHA1,
299 .pass = "AbCdEfGhIjK",
300 .seed = "alpha1",
301 .count = 99,
302 .hex = "27BC 7103 5AAF 3DC6",
303 .six = "MAY STAR TIN LYON VEDA STAN",
304 .dat.bv_val = (uint8_t []){ 0x27, 0xBC, 0x71, 0x03, 0x5A, 0xAF, 0x3D, 0xC6 },
305 .dat.bv_len = 8,
306 },
307 {
308 .method = OTPUTIL_MD_SHA1,
309 .pass = "OTP's are good",
310 .seed = "correct",
311 .count = 0,
312 .hex = "D51F 3E99 BF8E 6F0B",
313 .six = "RUST WELT KICK FELL TAIL FRAU",
314 .dat.bv_val = (uint8_t []){ 0xD5, 0x1F, 0x3E, 0x99, 0xBF, 0x8E, 0x6F, 0x0B },
315 .dat.bv_len = 8,
316 },
317 {
318 .method = OTPUTIL_MD_SHA1,
319 .pass = "OTP's are good",
320 .seed = "correct",
321 .count = 1,
322 .hex = "82AE B52D 9437 74E4",
323 .six = "FLIT DOSE ALSO MEW DRUM DEFY",
324 .dat.bv_val = (uint8_t []){ 0x82, 0xAE, 0xB5, 0x2D, 0x94, 0x37, 0x74, 0xE4 },
325 .dat.bv_len = 8,
326 },
327 {
328 .method = OTPUTIL_MD_SHA1,
329 .pass = "OTP's are good",
330 .seed = "correct",
331 .count = 99,
332 .hex = "4F29 6A74 FE15 67EC",
333 .six = "AURA ALOE HURL WING BERG WAIT",
334 .dat.bv_val = (uint8_t []){ 0x4F, 0x29, 0x6A, 0x74, 0xFE, 0x15, 0x67, 0xEC },
335 .dat.bv_len = 8,
336 },
337
338 // end of array
339 {
340 .method = 0,
341 .pass = NULL,
342 .seed = NULL,
343 .hex = NULL,
344 .six = NULL,
345 .dat.bv_val = NULL,
346 .dat.bv_len = 0,
347 },
348};
349
350
351/* end of source file */
diff --git a/tests/otp-data.h b/tests/otp-data.h
new file mode 100644
index 0000000..db2bc75
--- /dev/null
+++ b/tests/otp-data.h
@@ -0,0 +1,82 @@
1/*
2 * OTP Utilities
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of David M. Syzdek nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30/*
31 * @file tests/otp-data.c
32 */
33#ifndef _TESTS_OTP_DATA_H
34#define _TESTS_OTP_DATA_H 1
35
36///////////////
37// //
38// Headers //
39// //
40///////////////
41#pragma mark - Headers
42
43#ifdef HAVE_CONFIG_H
44#include <config.h>
45#endif
46
47#include <inttypes.h>
48#include <otputil.h>
49
50
51/////////////////
52// //
53// Datatypes //
54// //
55/////////////////
56#pragma mark - Datatypes
57
58typedef struct _otp_test_data otptest_t;
59struct _otp_test_data
60{
61 const otputil_bv_t dat;
62 int count;
63 int method;
64 const char * hex;
65 const char * six;
66 const char * seed;
67 const char * pass;
68};
69
70
71/////////////////
72// //
73// Variables //
74// //
75/////////////////
76#pragma mark - Variables
77
78extern otptest_t otp_test_data[];
79
80
81#endif
82/* end of header */
diff --git a/tests/test-otp-encode.c b/tests/test-otp-encode.c
new file mode 100644
index 0000000..c806387
--- /dev/null
+++ b/tests/test-otp-encode.c
@@ -0,0 +1,249 @@
1/*
2 * OTP Utilities
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of David M. Syzdek nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30/*
31 * @file tests/test-otp-encode.c
32 */
33#define _TESTS_TEST_OTP_ENCODE_C 1
34
35///////////////
36// //
37// Headers //
38// //
39///////////////
40#pragma mark - Headers
41
42#ifdef HAVE_CONFIG_H
43#include <config.h>
44#endif
45
46#include <errno.h>
47#include <assert.h>
48#include <getopt.h>
49#include <stdio.h>
50#include <string.h>
51#include <strings.h>
52#include <inttypes.h>
53
54#include <otputil.h>
55
56#include "otp-data.h"
57
58
59///////////////////
60// //
61// Definitions //
62// //
63///////////////////
64#pragma mark - Definitions
65
66#ifndef PROGRAM_NAME
67#define PROGRAM_NAME "test-otp-encode"
68#endif
69#ifndef PACKAGE_BUGREPORT
70#define PACKAGE_BUGREPORT "david@syzdek.net"
71#endif
72#ifndef PACKAGE_COPYRIGHT
73#define PACKAGE_COPYRIGHT ""
74#endif
75#ifndef PACKAGE_NAME
76#define PACKAGE_NAME ""
77#endif
78#ifndef PACKAGE_VERSION
79#define PACKAGE_VERSION ""
80#endif
81
82
83/////////////////
84// //
85// Variables //
86// //
87/////////////////
88#pragma mark - Variables
89
90static int verbose = 0;
91static int quiet = 0;
92static int ignore_errors = 0;
93
94
95//////////////////
96// //
97// Prototypes //
98// //
99//////////////////
100#pragma mark - Prototypes
101
102int
103main(
104 int argc,
105 char * argv[] );
106
107
108/////////////////
109// //
110// Functions //
111// //
112/////////////////
113#pragma mark - Functions
114
115int
116main(
117 int argc,
118 char * argv[] )
119{
120 int c;
121 int opt_index;
122 int pos;
123 char buff[128];
124 otptest_t * rec;
125 int errs;
126
127 // getopt options
128 static const char * short_opt = "chqVv";
129 static struct option long_opt[] =
130 {
131 {"help", no_argument, NULL, 'h' },
132 {"quiet", no_argument, NULL, 'q' },
133 {"silent", no_argument, NULL, 'q' },
134 {"version", no_argument, NULL, 'V' },
135 {"verbose", no_argument, NULL, 'v' },
136 { NULL, 0, NULL, 0 }
137 };
138
139 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
140 {
141 switch(c)
142 {
143 case -1: /* no more arguments */
144 case 0: /* long options toggles */
145 break;
146
147 case 'c':
148 ignore_errors = 1;
149 break;
150
151 case 'h':
152 printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME);
153 printf("OPTIONS:\n");
154 printf(" -c report errors, but continue\n");
155 printf(" -h, --help print this help and exit\n");
156 printf(" -q, --quiet, --silent do not print messages\n");
157 printf(" -V, --version print version number and exit\n");
158 printf(" -v, --verbose print verbose messages\n");
159 printf("\n");
160 return(0);
161
162 case 'q':
163 quiet++;
164 break;
165
166 case 'V':
167 printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION);
168 printf("Written by David M. Syzdek.\n");
169 return(0);
170
171 case 'v':
172 verbose++;
173 break;
174
175 case '?':
176 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
177 return(1);
178
179 default:
180 fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c);
181 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
182 return(1);
183 };
184 };
185
186 errs = 0;
187
188 if (!(quiet))
189 {
190 printf("Hash Pass Phrase Seed Cnt Hex Six Word Format\n");
191 printf("=========================================================================================\n");
192 };
193 for(pos = 0; ((otp_test_data[pos].hex)); pos++)
194 {
195 rec = &otp_test_data[pos];
196
197 if (!(quiet))
198 {
199 printf("%-5s ", otputil_md2str(rec->method));
200 printf("%-17s ", rec->pass);
201 printf("%-9s ", rec->seed);
202 printf("%2i ", rec->count);
203 printf("%-20s ", rec->hex);
204 printf("%s\n", rec->six);
205 };
206
207 // test HEX encoding
208 if (!(otputil_otp_encode(&rec->dat, buff, sizeof(buff), OTPUTIL_ENC_HEX)))
209 {
210 printf("%s: buffer is too small for result\n", rec->hex);
211 if (!(ignore_errors))
212 return(1);
213 errs++;
214 continue;
215 };
216 if ((strcasecmp(rec->hex, buff)))
217 {
218 printf("hex encoding: expected \"%s\", but received \"%s\"\n", rec->hex, buff);
219 if (!(ignore_errors))
220 return(1);
221 errs++;
222 };
223
224 // test six word encoding
225 if (!(otputil_otp_encode(&rec->dat, buff, sizeof(buff), OTPUTIL_ENC_SIXWORD)))
226 {
227 printf("%s: buffer is too small for result\n", rec->hex);
228 if (!(ignore_errors))
229 return(1);
230 errs++;
231 continue;
232 };
233 if ((strcasecmp(rec->six, buff)))
234 {
235 printf("six word encoding: expected \"%s\", but received \"%s\"\n", rec->six, buff);
236 if (!(ignore_errors))
237 return(1);
238 errs++;
239 };
240 };
241
242 if (!(quiet))
243 printf("%i errors encountered\n", errs);
244
245 return( ((errs)) ? 1 : 0 );
246}
247
248
249/* end of source file */