diff --git a/include/security/oath.h b/include/security/oath.h index e897162..7dfed25 100644 --- a/include/security/oath.h +++ b/include/security/oath.h @@ -42,10 +42,6 @@ struct oath_key *oath_key_from_uri(const char *); struct oath_key *oath_key_from_file(const char *); char *oath_key_to_uri(const struct oath_key *); -#define DUMMY_LABEL ("oath-dummy-key") -#define DUMMY_LABELLEN (sizeof DUMMY_LABEL) -#define DUMMY_KEYLEN 64 - struct oath_key *oath_dummy_key(enum oath_mode, enum oath_hash, unsigned int); unsigned int oath_hotp(const uint8_t *, size_t, uint64_t, unsigned int); diff --git a/include/security/oath_constants.h b/include/security/oath_constants.h index 1838d61..465c64c 100644 --- a/include/security/oath_constants.h +++ b/include/security/oath_constants.h @@ -76,4 +76,9 @@ enum oath_hash { */ #define OATH_MAX_LABELLEN 64 +/* + * Label to use for dummy keys + */ +#define OATH_DUMMY_LABEL "oath-dummy-key" + #endif diff --git a/lib/liboath/oath_hotp.c b/lib/liboath/oath_hotp.c index 9642f9e..28d0d63 100644 --- a/lib/liboath/oath_hotp.c +++ b/lib/liboath/oath_hotp.c @@ -127,7 +127,7 @@ oath_hotp_match(struct oath_key *k, unsigned int response, int window) return (-1); if (k->counter >= UINT64_MAX - window) return (-1); - dummy = (memcmp(k->label, DUMMY_LABEL, DUMMY_LABELLEN) == 0); + dummy = (strcmp(k->label, OATH_DUMMY_LABEL) == 0); for (int i = 0; i < window; ++i) { code = oath_hotp(k->key, k->keylen, k->counter + i, k->digits); if (code == response && !dummy) { diff --git a/lib/liboath/oath_key.c b/lib/liboath/oath_key.c index 98ff3dc..45878bd 100644 --- a/lib/liboath/oath_key.c +++ b/lib/liboath/oath_key.c @@ -310,8 +310,8 @@ oath_dummy_key(enum oath_mode mode, enum oath_hash hash, unsigned int digits) key->counter = 0; key->timestep = 30; key->hash = hash; - memcpy(key->label, DUMMY_LABEL, DUMMY_LABELLEN); - key->labellen = DUMMY_LABELLEN; - key->keylen = DUMMY_KEYLEN; + strcpy(key->label, "oath-dummy-key"); + key->labellen = strlen(key->label); + key->keylen = sizeof key->key; return (key); } diff --git a/lib/liboath/oath_totp.c b/lib/liboath/oath_totp.c index f21b21a..4c3e2c4 100644 --- a/lib/liboath/oath_totp.c +++ b/lib/liboath/oath_totp.c @@ -83,7 +83,7 @@ oath_totp_match(const struct oath_key *k, unsigned int response, int window) if (k->timestep == 0) return (-1); seq = time(NULL) / k->timestep; - dummy = (memcmp(k->label, DUMMY_LABEL, DUMMY_LABELLEN) == 0); + dummy = (strcmp(k->label, OATH_DUMMY_LABEL) == 0); for (int i = -window; i <= window; ++i) { code = oath_hotp(k->key, k->keylen, seq + i, k->digits); if (code == response && !dummy)