From cec85495030de209df9bd064a36fa18586d978b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Mon, 15 Dec 2014 16:42:31 +0000 Subject: [PATCH] Change the meaning of the window parameter to always indicate the number of codes to check *in addition* to the current code. Note that for TOTP, the window goes in both directions; a window of 1 means to check the current code plus the previous and next. git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@849 185d5e19-27fe-0310-9dcf-9bff6b9f3609 --- lib/liboath/oath_hotp.c | 6 +++--- lib/liboath/oath_totp.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/liboath/oath_hotp.c b/lib/liboath/oath_hotp.c index f22c83a..f748612 100644 --- a/lib/liboath/oath_hotp.c +++ b/lib/liboath/oath_hotp.c @@ -121,13 +121,13 @@ oath_hotp_match(struct oath_key *k, unsigned int response, int window) if (k == NULL) return (-1); - if (window < 1) + if (window < 0) return (-1); if (k->mode != om_hotp) return (-1); - if (k->counter >= UINT64_MAX - window) + if (k->counter >= UINT64_MAX - window - 1) return (-1); - for (int i = 0; i < window; ++i) { + for (int i = 0; i <= window; ++i) { code = oath_hotp(k->key, k->keylen, k->counter + i, k->digits); if (code == response && !k->dummy) { k->counter = k->counter + i + 1; diff --git a/lib/liboath/oath_totp.c b/lib/liboath/oath_totp.c index baf81ef..09c473a 100644 --- a/lib/liboath/oath_totp.c +++ b/lib/liboath/oath_totp.c @@ -81,7 +81,7 @@ oath_totp_match(struct oath_key *k, unsigned int response, int window) if (k == NULL) return (-1); - if (window < 1) + if (window < 0) return (-1); if (k->mode != om_totp) return (-1);