+
+char *csc_generateresetcode(time_t lockuntil, char *username) {
+ unsigned char digest[32];
+ static char hexbuf[sizeof(digest) * 2 + 1];
+ hmacsha256 hmac;
+ SHA256_CTX ctx;
+ char buf[1024];
+
+ snprintf(buf, sizeof(buf), "%s:%lu", username, lockuntil);
+
+ SHA256_Init(&ctx);
+ SHA256_Update(&ctx, (unsigned char *)buf, strlen(buf));
+ SHA256_Final(digest, &ctx);
+
+ hmac_printhex(digest, hexbuf, sizeof(digest));
+
+ hmacsha256_init(&hmac, (unsigned char *)codesecret->content, codesecret->length);
+ hmacsha256_update(&hmac, (unsigned char *)hexbuf, strlen(hexbuf));
+ hmacsha256_final(&hmac, digest);
+
+ hmac_printhex(digest, hexbuf, sizeof(digest));
+
+ return hexbuf;
+}
+
+int csc_verifyqticket(char *data, char *digest) {
+ hmacsha256 hmac;
+ unsigned char digestbuf[32];
+ char hexbuf[sizeof(digestbuf) * 2 + 1];
+
+ if(!ticketsecret)
+ return -1;
+
+ hmacsha256_init(&hmac, (unsigned char *)ticketsecret->content, ticketsecret->length);
+ hmacsha256_update(&hmac, (unsigned char *)data, strlen(data));
+ hmacsha256_final(&hmac, digestbuf);
+
+ hmac_printhex(digestbuf, hexbuf, sizeof(digestbuf));
+
+ if(!strcasecmp(hexbuf, digest))
+ return 0;
+
+ return 1;
+}