diff options
| author | David M. Syzdek <david@syzdek.net> | 2023-01-10 13:18:42 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2023-01-10 13:26:36 -0900 |
| commit | 1709d84dae4b68d832023b1972060b8c2967e9bf (patch) | |
| tree | c79d624ced5b6548dee72f7647d11917bb6a1cdb | |
| parent | 0bbcb4cfee37e373cf988b5e0d10363db7c8c1e0 (diff) | |
| download | otputils-1709d84dae4b68d832023b1972060b8c2967e9bf.tar.gz otputils-1709d84dae4b68d832023b1972060b8c2967e9bf.tar.bz2 otputils-1709d84dae4b68d832023b1972060b8c2967e9bf.tar.xz otputils-1709d84dae4b68d832023b1972060b8c2967e9bf.zip | |
libotputil: adding otputil_skey_dict_value()
| -rw-r--r-- | include/otputil.h | 5 | ||||
| -rw-r--r-- | lib/libotputil/libotputil.sym | 1 | ||||
| -rw-r--r-- | lib/libotputil/lrfc1760-skey.c | 70 |
3 files changed, 76 insertions, 0 deletions
diff --git a/include/otputil.h b/include/otputil.h index a398979..b2ad625 100644 --- a/include/otputil.h +++ b/include/otputil.h | |||
| @@ -370,6 +370,11 @@ otputil_otp_encode_len( | |||
| 370 | //----------------// | 370 | //----------------// |
| 371 | #pragma mark S/KEY functions (RFC 1760) | 371 | #pragma mark S/KEY functions (RFC 1760) |
| 372 | 372 | ||
| 373 | _OTPUTIL_F int | ||
| 374 | otputil_skey_dict_value( | ||
| 375 | const char * word ); | ||
| 376 | |||
| 377 | |||
| 373 | _OTPUTIL_F const char * | 378 | _OTPUTIL_F const char * |
| 374 | otputil_skey_dict_word( | 379 | otputil_skey_dict_word( |
| 375 | int value ); | 380 | int value ); |
diff --git a/lib/libotputil/libotputil.sym b/lib/libotputil/libotputil.sym index 17c94e9..148d615 100644 --- a/lib/libotputil/libotputil.sym +++ b/lib/libotputil/libotputil.sym | |||
| @@ -85,6 +85,7 @@ otputil_otp_decode_len | |||
| 85 | otputil_otp_encode | 85 | otputil_otp_encode |
| 86 | otputil_otp_encode_len | 86 | otputil_otp_encode_len |
| 87 | # S/KEY functions (RFC 1760) | 87 | # S/KEY functions (RFC 1760) |
| 88 | otputil_skey_dict_value | ||
| 88 | otputil_skey_dict_word | 89 | otputil_skey_dict_word |
| 89 | # TOTP functions (RFC 6238) | 90 | # TOTP functions (RFC 6238) |
| 90 | otputil_totp_code | 91 | otputil_totp_code |
diff --git a/lib/libotputil/lrfc1760-skey.c b/lib/libotputil/lrfc1760-skey.c index bb79414..f152cd4 100644 --- a/lib/libotputil/lrfc1760-skey.c +++ b/lib/libotputil/lrfc1760-skey.c | |||
| @@ -47,6 +47,30 @@ | |||
| 47 | #include "lrfc1760-skey-dict.h" | 47 | #include "lrfc1760-skey-dict.h" |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | ////////////////// | ||
| 51 | // // | ||
| 52 | // Prototypes // | ||
| 53 | // // | ||
| 54 | ////////////////// | ||
| 55 | #pragma mark - Prototypes | ||
| 56 | |||
| 57 | //-----------------------// | ||
| 58 | // dictionary prototypes // | ||
| 59 | //-----------------------// | ||
| 60 | #pragma mark dictionary prototypes | ||
| 61 | |||
| 62 | static int | ||
| 63 | otputil_skey_cmp( | ||
| 64 | const void * a, | ||
| 65 | const void * b ); | ||
| 66 | |||
| 67 | |||
| 68 | static int | ||
| 69 | otputil_skey_cmp_key( | ||
| 70 | const void * a, | ||
| 71 | const void * b ); | ||
| 72 | |||
| 73 | |||
| 50 | ///////////////// | 74 | ///////////////// |
| 51 | // // | 75 | // // |
| 52 | // Functions // | 76 | // Functions // |
| @@ -54,6 +78,52 @@ | |||
| 54 | ///////////////// | 78 | ///////////////// |
| 55 | #pragma mark - Functions | 79 | #pragma mark - Functions |
| 56 | 80 | ||
| 81 | //----------------------// | ||
| 82 | // dictionary functions // | ||
| 83 | //----------------------// | ||
| 84 | #pragma mark dictionary functions | ||
| 85 | |||
| 86 | int | ||
| 87 | otputil_skey_cmp( | ||
| 88 | const void * a, | ||
| 89 | const void * b ) | ||
| 90 | { | ||
| 91 | const char * x = *((const char * const *)a); | ||
| 92 | const char * y = *((const char * const *)b); | ||
| 93 | size_t x_len = ((x)) ? strlen(x) : 0; | ||
| 94 | size_t y_len = ((y)) ? strlen(y) : 0; | ||
| 95 | |||
| 96 | if ( ((x)) && (!(y)) ) | ||
| 97 | return(-1); | ||
| 98 | if ( (!(x)) && ((y)) ) | ||
| 99 | return(1); | ||
| 100 | |||
| 101 | if ((x_len < 4) && (y_len > 3)) | ||
| 102 | return(-1); | ||
| 103 | if ((x_len > 3) && (y_len < 4)) | ||
| 104 | return(1); | ||
| 105 | |||
| 106 | return(strcasecmp(x, y)); | ||
| 107 | } | ||
| 108 | |||
| 109 | |||
| 110 | int | ||
| 111 | otputil_skey_cmp_key( | ||
| 112 | const void * a, | ||
| 113 | const void * b ) | ||
| 114 | { | ||
| 115 | return(otputil_skey_cmp(&a, b)); | ||
| 116 | } | ||
| 117 | |||
| 118 | |||
| 119 | int | ||
| 120 | otputil_skey_dict_value( | ||
| 121 | const char * word ) | ||
| 122 | { | ||
| 123 | return((int)bindle_bindex(word, otputil_skey_rfc1760_dict, 2048, sizeof(char *), 0, NULL, &otputil_skey_cmp_key)); | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 57 | const char * | 127 | const char * |
| 58 | otputil_skey_dict_word( | 128 | otputil_skey_dict_word( |
| 59 | int value ) | 129 | int value ) |
