From 08e9ad179bad21d46d2389629f35e0bccf296ab3 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Wed, 11 Jan 2023 22:56:42 -0900 Subject: libotputil: adding otputil_otp_str() --- include/otputil.h | 10 ++++++++++ lib/libotputil/libotputil.sym | 1 + lib/libotputil/lrfc2289-otp.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/include/otputil.h b/include/otputil.h index cb690d4..f549eb2 100644 --- a/include/otputil.h +++ b/include/otputil.h @@ -381,6 +381,16 @@ otputil_otp_encode_len( const otputil_bv_t * bv ); +_OTPUTIL_F char * +otputil_otp_str( + const char * otp_pass, + const char * otp_seed, + int otp_seq, + int otp_hash, + char * dst, + size_t dstlen ); + + //----------------// // S/KEY functions // //----------------// diff --git a/lib/libotputil/libotputil.sym b/lib/libotputil/libotputil.sym index cd4b5a6..c3faedb 100644 --- a/lib/libotputil/libotputil.sym +++ b/lib/libotputil/libotputil.sym @@ -90,6 +90,7 @@ otputil_otp_decode otputil_otp_decode_len otputil_otp_encode otputil_otp_encode_len +otputil_otp_str # # S/KEY functions (RFC 1760) otputil_skey_dict_value diff --git a/lib/libotputil/lrfc2289-otp.c b/lib/libotputil/lrfc2289-otp.c index e037f83..a9d55e4 100644 --- a/lib/libotputil/lrfc2289-otp.c +++ b/lib/libotputil/lrfc2289-otp.c @@ -124,4 +124,39 @@ otputil_otp_code( } +char * +otputil_otp_str( + const char * otp_pass, + const char * otp_seed, + int otp_seq, + int otp_hash, + char * dst, + size_t dstlen ) +{ + uint64_t val; + otputil_bv_t res; + uint8_t bv_val[8]; + static char buff[32]; + + dstlen = ((dst)) ? dstlen : sizeof(buff); + dst = ((dst)) ? dst : buff; + res.bv_val = bv_val; + res.bv_len = sizeof(bv_val); + + val = otputil_otp_code(otp_pass, otp_seed, otp_seq, otp_hash); + + bv_val[0] = (val >> 56) & 0xff; + bv_val[1] = (val >> 48) & 0xff; + bv_val[2] = (val >> 40) & 0xff; + bv_val[3] = (val >> 32) & 0xff; + bv_val[4] = (val >> 24) & 0xff; + bv_val[5] = (val >> 16) & 0xff; + bv_val[6] = (val >> 8) & 0xff; + bv_val[7] = (val >> 0) & 0xff; + otputil_otp_encode(&res, dst, dstlen, OTPUTIL_ENC_SIXWORD); + + return(dst); +} + + /* end of source file */ -- cgit v1.2.3