| 63 | } |
| 64 | |
| 65 | bool sha256hmac_hex(const char *str, char out_hash_hex[65], const char *secret, int secret_len) { |
| 66 | if (!str) return false; |
| 67 | |
| 68 | unsigned char hash[SHA256_DIGEST_LENGTH]; // 32 |
| 69 | |
| 70 | sha256hmac(str, hash, secret, secret_len); |
| 71 | |
| 72 | for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { |
| 73 | sprintf(out_hash_hex + (i * 2), "%02x", hash[i]); |
| 74 | } |
| 75 | out_hash_hex[SHA256_DIGEST_STRING_LENGTH - 1] = 0; |
| 76 | |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * It would be more efficient to use a variation of KMP to |