00-matt / minitotp Goto Github PK
View Code? Open in Web Editor NEWApplication and library for time-based one-time passwords as specified by RFC 6238
License: MIT License
Application and library for time-based one-time passwords as specified by RFC 6238
License: MIT License
I noticed this bug while using TOTP secrets generated by Pyotp. Generated secrets can sometimes contain nullbytes. This causes the strlen()
call in hotp.c to return an invalid length. I changed the mtotp_hotp()
and mtotp_totp()
functions within the library to require size_t secret_len
as an extra argument and removed the unsafe strlen()
call.
Examples (more was edited) :
minitotp.h
/**
* @brief Generate a one-time password.
*
* This method generates a one-time password as specified by RFC
* 4226. It uses a pre-shared secret and a counter to generate a
* unique code.
*
* @param secret The preshared secret.
* @param secret_len The length of the preshared secret.
* @param counter An 8-byte counter that changes after every
* login attempt. Should be synchronised between
* client and server.
* @param length Length of the produced one-time password. Must
* be at least 6.
* @param buf A buffer to store the OTP in. Must be at least
* length + 1 bytes.
*
* @return The one-time password as an ASCII string.
*/
char *mtotp_hotp(const char *secret, size_t secret_len, uint64_t counter, int length, char *buf);
hotp.c
char *mtotp_hotp(const char *secret, size_t secret_len, uint64_t counter, int length, char *buf) {
assert(length >= 6);
counter = htobe64(counter);
uint8_t hmac[20];
hmac_sha1((const uint8_t *)secret, secret_len, (const uint8_t *)&counter,
sizeof(counter), hmac);
uint32_t code = mod(dynamic_truncate(hmac), length);
pad_otp(code, length, buf);
return buf;
}
I would be happy to push the changes but I'm sure it will break the application you've created around the library. Feel free to contact me if you need help fixing this.
minitotp $ mtotp -t0 '123'
57074492
minitotp $ mtotp -t0 '456'
57074492
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.