int otp_verify_user_1 (OtpContext *ctx, const char *passwd) { OtpKey key1, key2; if (otp_parse (key1, passwd, ctx->alg)) { ctx->err = "Syntax error in reply"; return -1; } memcpy (key2, key1, sizeof(key1)); ctx->alg->next (key2); if (memcmp (ctx->key, key2, sizeof(key2)) == 0) { --ctx->n; memcpy (ctx->key, key1, sizeof(key1)); return 0; } else return -1; }
static int test_one(OtpKey key1, char *name, char *val, void (*print)(OtpKey,char*, size_t), OtpAlgorithm *alg) { char buf[256]; OtpKey key2; (*print)(key1, buf, sizeof(buf)); printf ("%s: %s, ", name, buf); if (strcmp (buf, val) != 0) { printf ("failed(*%s* != *%s*)\n", buf, val); return 1; } if (otp_parse (key2, buf, alg)) { printf ("parse of %s failed\n", name); return 1; } if (memcmp (key1, key2, OTPKEYSIZE) != 0) { printf ("key1 != key2, "); } printf ("success\n"); return 0; }