From 4d76b664d26d0a77b77c02de1ddb3252e695717a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Thu, 15 Nov 2018 18:17:35 +0100 Subject: [PATCH] Merge counter and lastused. To prevent replay attacks, HOTP uses a counter, while TOTP keeps track of the time the key was last used. Since these values have the same type and are never used at the same time, merge them into an anonymous union. --- include/cryb/oath_types.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/cryb/oath_types.h b/include/cryb/oath_types.h index b01cd90..d9ad829 100644 --- a/include/cryb/oath_types.h +++ b/include/cryb/oath_types.h @@ -47,9 +47,11 @@ typedef struct { oath_mode mode; oath_hash hash; unsigned int digits; - uint64_t counter; /* HOTP only */ + union { + uint64_t counter; /* HOTP */ + uint64_t lastused; /* TOTP */ + }; unsigned int timestep; /* TOTP only - in seconds */ - uint64_t lastused; /* TOTP only */ /* housekeeping */ unsigned int dummy:1; /* dummy key, always fail */