diff options
Diffstat (limited to 'lib/libotputil/lmisc.c')
| -rw-r--r-- | lib/libotputil/lmisc.c | 53 |
1 files changed, 48 insertions, 5 deletions
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[] | ||
| 78 | static 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 | ||
| 222 | const char * | ||
| 223 | otputil_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 | |||
| 204 | int | 234 | int |
| 205 | otputil_str2md( | 235 | otputil_str2md( |
| 206 | const char * str ) | 236 | const char * str ) |
| @@ -214,6 +244,19 @@ otputil_str2md( | |||
| 214 | } | 244 | } |
| 215 | 245 | ||
| 216 | 246 | ||
| 247 | int | ||
| 248 | otputil_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 | |||
| 217 | uintmax_t | 260 | uintmax_t |
| 218 | otputil_upow( | 261 | otputil_upow( |
| 219 | uintmax_t base, | 262 | uintmax_t base, |
