2
0

Currently unused implementation of HOTP.

This commit is contained in:
Maarten Billemont 2017-08-30 09:40:37 -04:00
parent 23af56c150
commit 6fa8ee53cd
2 changed files with 35 additions and 0 deletions

View File

@ -313,6 +313,35 @@ uint8_t const *mpw_aes_decrypt(const uint8_t *key, const size_t keySize, const u
return mpw_aes( false, key, keySize, cipherBuf, bufSize ); return mpw_aes( false, key, keySize, cipherBuf, bufSize );
} }
#if UNUSED
const char *mpw_hotp(const uint8_t *key, size_t keySize, uint64_t movingFactor, uint8_t digits, uint8_t truncationOffset) {
// Hash the moving factor with the key.
uint8_t counter[8];
mpw_uint64( movingFactor, counter );
uint8_t hash[20];
hmac_sha1( key, keySize, counter, sizeof( counter ), hash );
// Determine the offset to select OTP bytes from.
int offset;
if ((truncationOffset >= 0) && (truncationOffset < (sizeof( hash ) - 4)))
offset = truncationOffset;
else
offset = hash[sizeof( hash ) - 1] & 0xf;
// Select four bytes from the truncation offset.
uint32_t otp = 0U
| ((hash[offset + 0] & 0x7f) << 24)
| ((hash[offset + 1] & 0xff) << 16)
| ((hash[offset + 2] & 0xff) << 8)
| ((hash[offset + 3] & 0xff) << 0);
// Render the OTP as `digits` decimal digits.
otp %= (int)pow(10, digits);
return strdup( mpw_str( "%0*d", digits, otp ) );
}
#endif
MPKeyID mpw_id_buf(const void *buf, size_t length) { MPKeyID mpw_id_buf(const void *buf, size_t length) {
if (!buf) if (!buf)

View File

@ -175,6 +175,12 @@ uint8_t const *mpw_aes_encrypt(
* @return A new bufSize allocated buffer containing the plainBuf. */ * @return A new bufSize allocated buffer containing the plainBuf. */
uint8_t const *mpw_aes_decrypt( uint8_t const *mpw_aes_decrypt(
const uint8_t *key, const size_t keySize, const uint8_t *cipherBuf, const size_t bufSize); const uint8_t *key, const size_t keySize, const uint8_t *cipherBuf, const size_t bufSize);
/** Calculate an OTP using RFC-4226.
* @return A newly allocated string containing exactly `digits` decimal OTP digits. */
#if UNUSED
const char *mpw_hotp(
const uint8_t *key, size_t keySize, uint64_t movingFactor, uint8_t digits, uint8_t truncationOffset);
#endif
//// Visualizers. //// Visualizers.