aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-11 22:56:42 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-11 22:56:42 -0900
commit08e9ad179bad21d46d2389629f35e0bccf296ab3 (patch)
treea5048f715b10544ca396bb1ec7cf68dd37c45636
parent896dd1a61bb813fb7affcdb73ec6365dd20ea222 (diff)
downloadotputils-08e9ad179bad21d46d2389629f35e0bccf296ab3.tar.gz
otputils-08e9ad179bad21d46d2389629f35e0bccf296ab3.tar.bz2
otputils-08e9ad179bad21d46d2389629f35e0bccf296ab3.tar.xz
otputils-08e9ad179bad21d46d2389629f35e0bccf296ab3.zip
libotputil: adding otputil_otp_str()
-rw-r--r--include/otputil.h10
-rw-r--r--lib/libotputil/libotputil.sym1
-rw-r--r--lib/libotputil/lrfc2289-otp.c35
3 files changed, 46 insertions, 0 deletions
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(
381 const otputil_bv_t * bv ); 381 const otputil_bv_t * bv );
382 382
383 383
384_OTPUTIL_F char *
385otputil_otp_str(
386 const char * otp_pass,
387 const char * otp_seed,
388 int otp_seq,
389 int otp_hash,
390 char * dst,
391 size_t dstlen );
392
393
384//----------------// 394//----------------//
385// S/KEY functions // 395// S/KEY functions //
386//----------------// 396//----------------//
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
90otputil_otp_decode_len 90otputil_otp_decode_len
91otputil_otp_encode 91otputil_otp_encode
92otputil_otp_encode_len 92otputil_otp_encode_len
93otputil_otp_str
93# 94#
94# S/KEY functions (RFC 1760) 95# S/KEY functions (RFC 1760)
95otputil_skey_dict_value 96otputil_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(
124} 124}
125 125
126 126
127char *
128otputil_otp_str(
129 const char * otp_pass,
130 const char * otp_seed,
131 int otp_seq,
132 int otp_hash,
133 char * dst,
134 size_t dstlen )
135{
136 uint64_t val;
137 otputil_bv_t res;
138 uint8_t bv_val[8];
139 static char buff[32];
140
141 dstlen = ((dst)) ? dstlen : sizeof(buff);
142 dst = ((dst)) ? dst : buff;
143 res.bv_val = bv_val;
144 res.bv_len = sizeof(bv_val);
145
146 val = otputil_otp_code(otp_pass, otp_seed, otp_seq, otp_hash);
147
148 bv_val[0] = (val >> 56) & 0xff;
149 bv_val[1] = (val >> 48) & 0xff;
150 bv_val[2] = (val >> 40) & 0xff;
151 bv_val[3] = (val >> 32) & 0xff;
152 bv_val[4] = (val >> 24) & 0xff;
153 bv_val[5] = (val >> 16) & 0xff;
154 bv_val[6] = (val >> 8) & 0xff;
155 bv_val[7] = (val >> 0) & 0xff;
156 otputil_otp_encode(&res, dst, dstlen, OTPUTIL_ENC_SIXWORD);
157
158 return(dst);
159}
160
161
127/* end of source file */ 162/* end of source file */