aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-16 19:07:16 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-16 19:07:16 -0900
commit56c7a93dcdd9ea16848636a3dd56cde15a871297 (patch)
tree28aa0b4fa245af4be04c43d1be893728b94d0c31
parentf277f973607e117e10bc93f47174048f230784c4 (diff)
downloadotputils-56c7a93dcdd9ea16848636a3dd56cde15a871297.tar.gz
otputils-56c7a93dcdd9ea16848636a3dd56cde15a871297.tar.bz2
otputils-56c7a93dcdd9ea16848636a3dd56cde15a871297.tar.xz
otputils-56c7a93dcdd9ea16848636a3dd56cde15a871297.zip
libotputil: adding otputil_meth2str() and otputil_str2meth()
-rw-r--r--include/otputil.h10
-rw-r--r--lib/libotputil/libotputil.sym2
-rw-r--r--lib/libotputil/lmisc.c53
3 files changed, 60 insertions, 5 deletions
diff --git a/include/otputil.h b/include/otputil.h
index eae91bc..8b08583 100644
--- a/include/otputil.h
+++ b/include/otputil.h
@@ -327,11 +327,21 @@ otputil_md2str(
327 int hmac ); 327 int hmac );
328 328
329 329
330_OTPUTIL_F const char *
331otputil_meth2str(
332 int hmac );
333
334
330_OTPUTIL_F int 335_OTPUTIL_F int
331otputil_str2md( 336otputil_str2md(
332 const char * str ); 337 const char * str );
333 338
334 339
340_OTPUTIL_F int
341otputil_str2meth(
342 const char * str );
343
344
335//---------------------// 345//---------------------//
336// Front-end functions // 346// Front-end functions //
337//---------------------// 347//---------------------//
diff --git a/lib/libotputil/libotputil.sym b/lib/libotputil/libotputil.sym
index 4ad91f4..3c3c4c2 100644
--- a/lib/libotputil/libotputil.sym
+++ b/lib/libotputil/libotputil.sym
@@ -74,7 +74,9 @@ otputil_debug
74otputil_err2string 74otputil_err2string
75otputil_getpass 75otputil_getpass
76otputil_md2str 76otputil_md2str
77otputil_meth2str
77otputil_str2md 78otputil_str2md
79otputil_str2meth
78# 80#
79# front-end functions 81# front-end functions
80otputil_code 82otputil_code
diff --git a/lib/libotputil/lmisc.c b/lib/libotputil/lmisc.c
index 67ebd3d..1ec3c78 100644
--- a/lib/libotputil/lmisc.c
+++ b/lib/libotputil/lmisc.c
@@ -74,6 +74,24 @@ static const otputil_map_t otputil_md_list[] =
74}; 74};
75 75
76 76
77#pragma mark otputil_meth_list[]
78static const otputil_map_t otputil_meth_list[] =
79{
80 { .map_name = "none", .map_id = 0 },
81 { .map_name = "HOTP", .map_id = OTPUTIL_METH_HOTP },
82 { .map_name = "OTP", .map_id = OTPUTIL_METH_OTP },
83 { .map_name = "S/KEY", .map_id = OTPUTIL_METH_SKEY },
84 { .map_name = "TOTP", .map_id = OTPUTIL_METH_TOTP },
85 // duplicates
86 { .map_name = "RFC1760", .map_id = OTPUTIL_METH_RFC1760 },
87 { .map_name = "RFC2289", .map_id = OTPUTIL_METH_RFC2289 },
88 { .map_name = "RFC4226", .map_id = OTPUTIL_METH_RFC4226 },
89 { .map_name = "RFC6238", .map_id = OTPUTIL_METH_RFC6238 },
90 { .map_name = "SKEY", .map_id = OTPUTIL_METH_SKEY },
91 { .map_name = NULL, .map_id = 0 },
92};
93
94
77///////////////// 95/////////////////
78// // 96// //
79// Functions // 97// Functions //
@@ -94,19 +112,19 @@ otputil_debug(
94 112
95 fprintf(fs, "OTPUtils Options:\n"); 113 fprintf(fs, "OTPUtils Options:\n");
96 fprintf(fs, " OTPUTIL_OPT_DESC: %s\n", (((tud->util_desc)) ? tud->util_desc : "n/a")); 114 fprintf(fs, " OTPUTIL_OPT_DESC: %s\n", (((tud->util_desc)) ? tud->util_desc : "n/a"));
97 fprintf(fs, " OTPUTIL_OPT_METHOD: %i\n", tud->util_method); 115 fprintf(fs, " OTPUTIL_OPT_METHOD: %s (%i)\n", otputil_meth2str(tud->util_method), tud->util_method);
98 fprintf(fs, "\n"); 116 fprintf(fs, "\n");
99 117
100 fprintf(fs, "HOTP (RFC 4226) Options:\n"); 118 fprintf(fs, "HOTP (RFC 4226) Options:\n");
101 fprintf(fs, " OTPUTIL_OPT_HOTP_C: %" PRIu64 "\n", tud->hotp_c); 119 fprintf(fs, " OTPUTIL_OPT_HOTP_C: %" PRIu64 "\n", tud->hotp_c);
102 fprintf(fs, " OTPUTIL_OPT_HOTP_DIGITS: %i\n", tud->hotp_digits); 120 fprintf(fs, " OTPUTIL_OPT_HOTP_DIGITS: %i\n", tud->hotp_digits);
103 fprintf(fs, " OTPUTIL_OPT_HOTP_HMAC: %s\n", otputil_md2str(tud->hotp_hmac)); 121 fprintf(fs, " OTPUTIL_OPT_HOTP_HMAC: %s (%i)\n", otputil_md2str(tud->hotp_hmac), tud->hotp_hmac);
104 fprintf(fs, " OTPUTIL_OPT_HOTP_KSTR: %s\n", otputil_bvbase32(((tud->hotp_k)) ? tud->hotp_k : default_bv)); 122 fprintf(fs, " OTPUTIL_OPT_HOTP_KSTR: %s\n", otputil_bvbase32(((tud->hotp_k)) ? tud->hotp_k : default_bv));
105 fprintf(fs, "\n"); 123 fprintf(fs, "\n");
106 124
107 fprintf(fs, "OTP (RFC 2289) Options:\n"); 125 fprintf(fs, "OTP (RFC 2289) Options:\n");
108 fprintf(fs, " OTPUTIL_OPT_OTP_ENCODE: %i\n", tud->otp_encoding); 126 fprintf(fs, " OTPUTIL_OPT_OTP_ENCODE: %i\n", tud->otp_encoding);
109 fprintf(fs, " OTPUTIL_OPT_OTP_HASH: %s\n", otputil_md2str(tud->otp_hash)); 127 fprintf(fs, " OTPUTIL_OPT_OTP_HASH: %s (%i)\n", otputil_md2str(tud->otp_hash), tud->otp_hash);
110 fprintf(fs, " OTPUTIL_OPT_OTP_PASS: %s\n", (((tud->otp_pass)) ? tud->otp_pass : "n/a")); 128 fprintf(fs, " OTPUTIL_OPT_OTP_PASS: %s\n", (((tud->otp_pass)) ? tud->otp_pass : "n/a"));
111 fprintf(fs, " OTPUTIL_OPT_OTP_SEED: %s\n", (((tud->otp_seed)) ? tud->otp_seed : "n/a")); 129 fprintf(fs, " OTPUTIL_OPT_OTP_SEED: %s\n", (((tud->otp_seed)) ? tud->otp_seed : "n/a"));
112 fprintf(fs, " OTPUTIL_OPT_OTP_SEQ: %i\n", tud->otp_seq); 130 fprintf(fs, " OTPUTIL_OPT_OTP_SEQ: %i\n", tud->otp_seq);
@@ -114,14 +132,14 @@ otputil_debug(
114 132
115 fprintf(fs, "S/KEY (RFC 1760) Options:\n"); 133 fprintf(fs, "S/KEY (RFC 1760) Options:\n");
116 fprintf(fs, " OTPUTIL_OPT_SKEY_ENCODE: %i\n", tud->skey_encoding); 134 fprintf(fs, " OTPUTIL_OPT_SKEY_ENCODE: %i\n", tud->skey_encoding);
117 fprintf(fs, " OTPUTIL_OPT_SKEY_HASH: %s\n", otputil_md2str(tud->skey_hash)); 135 fprintf(fs, " OTPUTIL_OPT_SKEY_HASH: %s (%i)\n", otputil_md2str(tud->skey_hash), tud->skey_hash);
118 fprintf(fs, " OTPUTIL_OPT_SKEY_PASS: %s\n", (((tud->skey_pass)) ? tud->skey_pass : "n/a")); 136 fprintf(fs, " OTPUTIL_OPT_SKEY_PASS: %s\n", (((tud->skey_pass)) ? tud->skey_pass : "n/a"));
119 fprintf(fs, " OTPUTIL_OPT_SKEY_SEQ: %i\n", tud->skey_seq); 137 fprintf(fs, " OTPUTIL_OPT_SKEY_SEQ: %i\n", tud->skey_seq);
120 fprintf(fs, "\n"); 138 fprintf(fs, "\n");
121 139
122 fprintf(fs, "TOTP (RFC 6238) Options:\n"); 140 fprintf(fs, "TOTP (RFC 6238) Options:\n");
123 fprintf(fs, " OTPUTIL_OPT_TOTP_DIGITS: %i\n", tud->totp_digits); 141 fprintf(fs, " OTPUTIL_OPT_TOTP_DIGITS: %i\n", tud->totp_digits);
124 fprintf(fs, " OTPUTIL_OPT_TOTP_HMAC: %s\n", otputil_md2str(tud->totp_hmac)); 142 fprintf(fs, " OTPUTIL_OPT_TOTP_HMAC: %s (%i)\n", otputil_md2str(tud->totp_hmac), tud->totp_hmac);
125 fprintf(fs, " OTPUTIL_OPT_TOTP_KSTR: %s\n", otputil_bvbase32(((tud->totp_k)) ? tud->totp_k : default_bv)); 143 fprintf(fs, " OTPUTIL_OPT_TOTP_KSTR: %s\n", otputil_bvbase32(((tud->totp_k)) ? tud->totp_k : default_bv));
126 fprintf(fs, " OTPUTIL_OPT_TOTP_T0: %" PRIu64 "\n", tud->totp_t0); 144 fprintf(fs, " OTPUTIL_OPT_TOTP_T0: %" PRIu64 "\n", tud->totp_t0);
127 fprintf(fs, " OTPUTIL_OPT_TOTP_TIME: %" PRIu64 "\n", tud->totp_time); 145 fprintf(fs, " OTPUTIL_OPT_TOTP_TIME: %" PRIu64 "\n", tud->totp_time);
@@ -201,6 +219,18 @@ otputil_md2str(
201} 219}
202 220
203 221
222const char *
223otputil_meth2str(
224 int md )
225{
226 int x;
227 for(x = 0; ((otputil_meth_list[x].map_name)); x++)
228 if (md == otputil_meth_list[x].map_id)
229 return(otputil_meth_list[x].map_name);
230 return(NULL);
231}
232
233
204int 234int
205otputil_str2md( 235otputil_str2md(
206 const char * str ) 236 const char * str )
@@ -214,6 +244,19 @@ otputil_str2md(
214} 244}
215 245
216 246
247int
248otputil_str2meth(
249 const char * str )
250{
251 int x;
252 assert(str != NULL);
253 for(x = 0; ((otputil_meth_list[x].map_name)); x++)
254 if (!(strcasecmp(str, otputil_meth_list[x].map_name)))
255 return(otputil_meth_list[x].map_id);
256 return(-1);
257}
258
259
217uintmax_t 260uintmax_t
218otputil_upow( 261otputil_upow(
219 uintmax_t base, 262 uintmax_t base,