From 02d4e0ffb896d2a47200b363c0118f7ef93176e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Thu, 22 Sep 2022 14:33:58 +0800 Subject: Merge crypt.h --- crypt.h | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 crypt.h (limited to 'crypt.h') diff --git a/crypt.h b/crypt.h deleted file mode 100644 index 7e7ea29..0000000 --- a/crypt.h +++ /dev/null @@ -1,35 +0,0 @@ -#include - -static inline void crypt_init() -{ - gcry_check_version("1.9.4"); -} - -static inline bool crypt_macmatch(const char *key, const char *query, - const char *hmac) -{ - gcry_mac_hd_t hd; - gcry_mac_open(&hd, GCRY_MAC_HMAC_SHA256, GCRY_MAC_FLAG_SECURE, NULL); - gcry_mac_setkey(hd, key, strlen(key)); - gcry_mac_write(hd, query, strlen(query)); - static size_t hmacsha256_len = 32; - unsigned char hmacsha256[hmacsha256_len]; - gcry_mac_read(hd, hmacsha256, &hmacsha256_len); - gcry_mac_close(hd); - char hmacsha256_str[hmacsha256_len * 2 + 1]; - hmacsha256_str[0] ='\0'; - for (int i = 0; i < hmacsha256_len; i++) - sprintf(hmacsha256_str, "%s%02x", hmacsha256_str, - hmacsha256[i]); - return !strcmp(hmac, hmacsha256_str); -} - -static inline void crypt_getnonce(char buf[], const size_t buf_len) -{ - buf[0] = '\0'; - const size_t nonce_len = buf_len / 2; - unsigned char nonce[nonce_len]; - gcry_create_nonce(nonce, nonce_len); - for (int i = 0; i < nonce_len; i++) - sprintf(buf, "%s%02x", buf, nonce[i]); -} -- cgit v1.2.3