Coder Social home page Coder Social logo

minitotp's People

Contributors

00-matt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

minitotp's Issues

Incompatibility with secrets containing nullbytes.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.