aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/libotputil/lrfc1760-skey.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libotputil/lrfc1760-skey.c')
-rw-r--r--lib/libotputil/lrfc1760-skey.c42
1 files changed, 5 insertions, 37 deletions
diff --git a/lib/libotputil/lrfc1760-skey.c b/lib/libotputil/lrfc1760-skey.c
index 1853455..adb61a1 100644
--- a/lib/libotputil/lrfc1760-skey.c
+++ b/lib/libotputil/lrfc1760-skey.c
@@ -147,45 +147,13 @@ int
147otputil_skey_code( 147otputil_skey_code(
148 const char * skey_pass, 148 const char * skey_pass,
149 int skey_seq, 149 int skey_seq,
150 int skey_hash,
150 uint64_t * skey_resultp ) 151 uint64_t * skey_resultp )
151{ 152{
152 unsigned char secret[OTPUTIL_SKEY_PASS_MAX_LEN+1];
153 const EVP_MD * evp_md;
154 unsigned char md[EVP_MAX_MD_SIZE];
155 unsigned md_len;
156 unsigned secret_len;
157 unsigned u;
158 int pos;
159
160 assert(skey_pass != NULL); 153 assert(skey_pass != NULL);
161 154 skey_seq = (skey_seq >= 0) ? skey_seq : otputil_defaults.skey_seq;
162 // generate secret 155 skey_hash = ((skey_hash)) ? skey_hash : otputil_defaults.skey_hash;
163 secret_len = (int)strlen(skey_pass); 156 return(otputil_otp_code(skey_pass, NULL, skey_seq, skey_hash, skey_resultp));
164 if (secret_len > OTPUTIL_SKEY_PASS_MAX_LEN)
165 return(-1);
166 bindle_strlcpy((char *)secret, skey_pass, sizeof(secret));
167
168 // check otp_hash
169 evp_md = EVP_md4();
170
171 // generate hashes
172 for(pos = 0; (pos <= skey_seq); pos++)
173 {
174 md_len = sizeof(md);
175 if (!(EVP_Digest(secret, secret_len, md, &md_len, evp_md, NULL)))
176 return(-1);
177 for(u = 0; (u < 8); u++)
178 md[u] ^= md[u+8];
179 memcpy(secret, md, 8);
180 secret_len = 8;
181 };
182
183 *skey_resultp = ((uint64_t)secret[0] << 56) | ((uint64_t)secret[1] << 48)
184 | ((uint64_t)secret[2] << 40) | ((uint64_t)secret[3] << 32)
185 | ((uint64_t)secret[4] << 24) | ((uint64_t)secret[5] << 16)
186 | ((uint64_t)secret[6] << 8) | ((uint64_t)secret[7] << 0);
187
188 return(0);
189} 157}
190 158
191 159
@@ -206,7 +174,7 @@ otputil_skey_str(
206 res.bv_val = bv_val; 174 res.bv_val = bv_val;
207 res.bv_len = sizeof(bv_val); 175 res.bv_len = sizeof(bv_val);
208 176
209 if (otputil_skey_code(skey_pass, skey_seq, &val) == -1) 177 if (otputil_skey_code(skey_pass, skey_seq, 0, &val) == -1)
210 return(NULL); 178 return(NULL);
211 179
212 bv_val[0] = (val >> 56) & 0xff; 180 bv_val[0] = (val >> 56) & 0xff;