diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-15 08:16:18 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-15 08:16:18 +0800 |
commit | 792ef642fa03eda4af5bc3535487faacef4fcf65 (patch) | |
tree | a045931056d6b085e8e5919df6c55f2d4f46aabc /crypt.h | |
parent | 68d6d53ad97d3496a857ae28eb9c73c7cfaba69d (diff) |
Nonce string size uses formula
Less efficient, but it's more about clarity for now.
Variable name shortened a bit.
Nonce size made static.
Diffstat (limited to 'crypt.h')
-rw-r--r-- | crypt.h | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -12,15 +12,16 @@ static inline bool crypt_maccmp(const char *key, const char *query, 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)); - size_t hmac_sha256_len = 32; - unsigned char hmac_sha256[hmac_sha256_len + 1]; - gcry_mac_read(hd, hmac_sha256, &hmac_sha256_len); + static size_t hmacsha256_len = 32; + unsigned char hmacsha256[hmacsha256_len + 1]; + gcry_mac_read(hd, hmacsha256, &hmacsha256_len); gcry_mac_close(hd); - char hmac_sha256_str[65] = { [0] = '\0' }; - for (int i = 0; i < hmac_sha256_len; i++) - sprintf(hmac_sha256_str, "%s%02x", hmac_sha256_str, - hmac_sha256[i]); - return !strcmp(hmac, hmac_sha256_str); + 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 *string, const size_t string_len) |