From 40d2788ae085e4ea47ae597dc2680cdf93317144 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 30 Aug 2017 09:35:55 -0400 Subject: [PATCH] Implement OTP counter feature for counter values of 0. --- core/c/mpw-algorithm_v0.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/c/mpw-algorithm_v0.c b/core/c/mpw-algorithm_v0.c index 1b28b4b3..676af24f 100644 --- a/core/c/mpw-algorithm_v0.c +++ b/core/c/mpw-algorithm_v0.c @@ -18,6 +18,7 @@ #include #include +#include #include "mpw-util.h" #include "base64.h" @@ -25,6 +26,7 @@ #define MP_N 32768LU #define MP_r 8U #define MP_p 2U +#define MP_otp_window 5 * 60 /* s */ // Algorithm version helpers. static const char *mpw_templateForType_v0(MPResultType type, uint16_t templateIndex) { @@ -86,7 +88,9 @@ static MPSiteKey mpw_siteKey_v0( const char *keyScope = mpw_scopeForPurpose( keyPurpose ); trc( "keyScope: %s\n", keyScope ); - // TODO: Implement MPCounterValueTOTP + // OTP counter value. + if (siteCounter == MPCounterValueTOTP) + siteCounter = ((uint32_t)time(NULL) / MP_otp_window) * MP_otp_window; // Calculate the site seed. trc( "siteSalt: keyScope=%s | #siteName=%s | siteName=%s | siteCounter=%s | #keyContext=%s | keyContext=%s\n",