* @brief Calculate message digest * * @param digestType digest name * @param data ptr to input message for calculating the digest * @param dataLen message length * @param key ptr to a counted string containing the key (secret) * @param keyLen key length * @param out ptr to where to store the digest * @param outLen length of the out buffer (must be at least MAX_MSGDIGEST_BUFFER_SIZE) * @re
| 199 | * @return the number of character actually written to the buffer. |
| 200 | */ |
| 201 | size_t |
| 202 | cryptoMessageDigestGet(const char *digestType, const char *data, size_t dataLen, const char *key, size_t keyLen, char *out, |
| 203 | size_t /* outLen ATS_UNUSED */) |
| 204 | { |
| 205 | const EVP_MD *md = nullptr; |
| 206 | unsigned int len = 0; |
| 207 | char buffer[256]; |
| 208 | |
| 209 | if (!(md = EVP_get_digestbyname(digestType))) { |
| 210 | AccessControlError("unknown digest name '%s'", digestType); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | if (!HMAC(md, reinterpret_cast<const unsigned char *>(key), keyLen, reinterpret_cast<const unsigned char *>(data), dataLen, |
| 215 | reinterpret_cast<unsigned char *>(out), &len)) { |
| 216 | AccessControlError("failed to get the signing hash: %s", cryptoErrStr(buffer, sizeof(buffer))); |
| 217 | } |
| 218 | return len; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * @brief Check if 2 message digests are the same using a constant-time openssl function to avoid timing attacks. |
no test coverage detected