aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/libotputil/lrfc2289-otp.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libotputil/lrfc2289-otp.c')
-rw-r--r--lib/libotputil/lrfc2289-otp.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/lib/libotputil/lrfc2289-otp.c b/lib/libotputil/lrfc2289-otp.c
index 8257714..807c2da 100644
--- a/lib/libotputil/lrfc2289-otp.c
+++ b/lib/libotputil/lrfc2289-otp.c
@@ -75,7 +75,7 @@ otputil_otp_code(
75 int otp_hash, 75 int otp_hash,
76 uint64_t * otp_resultp ) 76 uint64_t * otp_resultp )
77{ 77{
78 char secret[OTPUTIL_OTP_PASS_MAX_LEN+OTPUTIL_OTP_SEED_MAX_LEN+1]; 78 unsigned char secret[OTPUTIL_OTP_PASS_MAX_LEN+OTPUTIL_OTP_SEED_MAX_LEN+1];
79 size_t len; 79 size_t len;
80 const EVP_MD * evp_md; 80 const EVP_MD * evp_md;
81 unsigned char md[EVP_MAX_MD_SIZE]; 81 unsigned char md[EVP_MAX_MD_SIZE];
@@ -110,8 +110,8 @@ otputil_otp_code(
110 return(-1); 110 return(-1);
111 111
112 // generate secret 112 // generate secret
113 bindle_strlcat(secret, otp_pass, sizeof(secret)); 113 bindle_strlcat((char *)secret, otp_pass, sizeof(secret));
114 secret_len = (unsigned)strlen(secret); 114 secret_len = (unsigned)strlen((char *)secret);
115 115
116 // generate hashes 116 // generate hashes
117 for(pos = 0; (pos <= otp_seq); pos++) 117 for(pos = 0; (pos <= otp_seq); pos++)
@@ -119,34 +119,26 @@ otputil_otp_code(
119 md_len = sizeof(md); 119 md_len = sizeof(md);
120 if (!(EVP_Digest(secret, secret_len, md, &md_len, evp_md, NULL))) 120 if (!(EVP_Digest(secret, secret_len, md, &md_len, evp_md, NULL)))
121 return(-1); 121 return(-1);
122 switch(otp_hash) 122 if ((otp_hash == OTPUTIL_MD_MD4) || (otp_hash == OTPUTIL_MD_MD5))
123 { 123 {
124 case OTPUTIL_MD_MD4:
125 for(u = 0; (u < 8); u++) 124 for(u = 0; (u < 8); u++)
126 md[u] ^= md[u+8]; 125 md[u] ^= md[u+8];
127 memcpy(secret, md, 8); 126 memcpy(secret, md, 8);
128 secret_len = 8; 127 secret_len = 8;
129 break; 128 } else
130 129 {
131 case OTPUTIL_MD_MD5: 130 for(u = 8; (u < md_len); u++)
132 for(u = 0; (u < 8); u++) 131 md[u%8] ^= md[u];
133 md[u] ^= md[u+8]; 132 secret[0] = md[3]; secret[1] = md[2]; secret[2] = md[1]; secret[3] = md[0];
134 memcpy(secret, md, 8); 133 secret[4] = md[7]; secret[5] = md[6]; secret[6] = md[5]; secret[7] = md[4];
135 secret_len = 8; 134 secret_len = 8;
136 break;
137
138 case OTPUTIL_MD_SHA1:
139 break;
140
141 default:
142 return(-1);
143 }; 135 };
144 }; 136 };
145 137
146 *otp_resultp = ((uint64_t)md[0] << 56) | ((uint64_t)md[1] << 48) 138 *otp_resultp = ((uint64_t)secret[0] << 56) | ((uint64_t)secret[1] << 48)
147 | ((uint64_t)md[2] << 40) | ((uint64_t)md[3] << 32) 139 | ((uint64_t)secret[2] << 40) | ((uint64_t)secret[3] << 32)
148 | ((uint64_t)md[4] << 24) | ((uint64_t)md[5] << 16) 140 | ((uint64_t)secret[4] << 24) | ((uint64_t)secret[5] << 16)
149 | ((uint64_t)md[6] << 8) | ((uint64_t)md[7] << 0); 141 | ((uint64_t)secret[6] << 8) | ((uint64_t)secret[7] << 0);
150 142
151 return(0); 143 return(0);
152} 144}