MCPcopy Create free account
hub / github.com/apache/trafficserver / cryptoMessageDigestGet

Function cryptoMessageDigestGet

plugins/experimental/access_control/utils.cc:201–219  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

199 * @return the number of character actually written to the buffer.
200 */
201size_t
202cryptoMessageDigestGet(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.

Callers 2

calcMessageDigestFunction · 0.85
test_utils.ccFile · 0.85

Calls 1

cryptoErrStrFunction · 0.85

Tested by

no test coverage detected