summaryrefslogtreecommitdiff
path: root/libs/libcurl/src/hmac.c
diff options
context:
space:
mode:
authordartraiden <wowemuh@gmail.com>2024-11-06 20:55:13 +0300
committerdartraiden <wowemuh@gmail.com>2024-11-06 21:41:16 +0300
commit5d2ecfef56e49a8e4bfad25a582ff1597987f717 (patch)
treecdb31e45b051830ecf50c74a84b8d2ac5aa6cfd9 /libs/libcurl/src/hmac.c
parent995e85e9e63553576fc285d937d4abbad369e7e4 (diff)
libcurl: update to 8.11.0
Diffstat (limited to 'libs/libcurl/src/hmac.c')
-rw-r--r--libs/libcurl/src/hmac.c70
1 files changed, 32 insertions, 38 deletions
diff --git a/libs/libcurl/src/hmac.c b/libs/libcurl/src/hmac.c
index 6deb339cfa..4a8cffe798 100644
--- a/libs/libcurl/src/hmac.c
+++ b/libs/libcurl/src/hmac.c
@@ -49,8 +49,6 @@
static const unsigned char hmac_ipad = 0x36;
static const unsigned char hmac_opad = 0x5C;
-
-
struct HMAC_context *
Curl_HMAC_init(const struct HMAC_params *hashparams,
const unsigned char *key,
@@ -62,42 +60,40 @@ Curl_HMAC_init(const struct HMAC_params *hashparams,
unsigned char b;
/* Create HMAC context. */
- i = sizeof(*ctxt) + 2 * hashparams->hmac_ctxtsize +
- hashparams->hmac_resultlen;
+ i = sizeof(*ctxt) + 2 * hashparams->ctxtsize + hashparams->resultlen;
ctxt = malloc(i);
if(!ctxt)
return ctxt;
- ctxt->hmac_hash = hashparams;
- ctxt->hmac_hashctxt1 = (void *) (ctxt + 1);
- ctxt->hmac_hashctxt2 = (void *) ((char *) ctxt->hmac_hashctxt1 +
- hashparams->hmac_ctxtsize);
+ ctxt->hash = hashparams;
+ ctxt->hashctxt1 = (void *) (ctxt + 1);
+ ctxt->hashctxt2 = (void *) ((char *) ctxt->hashctxt1 + hashparams->ctxtsize);
/* If the key is too long, replace it by its hash digest. */
- if(keylen > hashparams->hmac_maxkeylen) {
- (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, key, keylen);
- hkey = (unsigned char *) ctxt->hmac_hashctxt2 + hashparams->hmac_ctxtsize;
- (*hashparams->hmac_hfinal)(hkey, ctxt->hmac_hashctxt1);
+ if(keylen > hashparams->maxkeylen) {
+ hashparams->hinit(ctxt->hashctxt1);
+ hashparams->hupdate(ctxt->hashctxt1, key, keylen);
+ hkey = (unsigned char *) ctxt->hashctxt2 + hashparams->ctxtsize;
+ hashparams->hfinal(hkey, ctxt->hashctxt1);
key = hkey;
- keylen = hashparams->hmac_resultlen;
+ keylen = hashparams->resultlen;
}
/* Prime the two hash contexts with the modified key. */
- (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1);
- (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt2);
+ hashparams->hinit(ctxt->hashctxt1);
+ hashparams->hinit(ctxt->hashctxt2);
for(i = 0; i < keylen; i++) {
b = (unsigned char)(*key ^ hmac_ipad);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &b, 1);
+ hashparams->hupdate(ctxt->hashctxt1, &b, 1);
b = (unsigned char)(*key++ ^ hmac_opad);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &b, 1);
+ hashparams->hupdate(ctxt->hashctxt2, &b, 1);
}
- for(; i < hashparams->hmac_maxkeylen; i++) {
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &hmac_ipad, 1);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &hmac_opad, 1);
+ for(; i < hashparams->maxkeylen; i++) {
+ hashparams->hupdate(ctxt->hashctxt1, &hmac_ipad, 1);
+ hashparams->hupdate(ctxt->hashctxt2, &hmac_opad, 1);
}
/* Done, return pointer to HMAC context. */
@@ -105,31 +101,29 @@ Curl_HMAC_init(const struct HMAC_params *hashparams,
}
int Curl_HMAC_update(struct HMAC_context *ctxt,
- const unsigned char *data,
+ const unsigned char *ptr,
unsigned int len)
{
/* Update first hash calculation. */
- (*ctxt->hmac_hash->hmac_hupdate)(ctxt->hmac_hashctxt1, data, len);
+ ctxt->hash->hupdate(ctxt->hashctxt1, ptr, len);
return 0;
}
-int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *result)
+int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *output)
{
- const struct HMAC_params *hashparams = ctxt->hmac_hash;
+ const struct HMAC_params *hashparams = ctxt->hash;
- /* Do not get result if called with a null parameter: only release
+ /* Do not get output if called with a null parameter: only release
storage. */
- if(!result)
- result = (unsigned char *) ctxt->hmac_hashctxt2 +
- ctxt->hmac_hash->hmac_ctxtsize;
+ if(!output)
+ output = (unsigned char *) ctxt->hashctxt2 + ctxt->hash->ctxtsize;
- (*hashparams->hmac_hfinal)(result, ctxt->hmac_hashctxt1);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2,
- result, hashparams->hmac_resultlen);
- (*hashparams->hmac_hfinal)(result, ctxt->hmac_hashctxt2);
- free((char *) ctxt);
+ hashparams->hfinal(output, ctxt->hashctxt1);
+ hashparams->hupdate(ctxt->hashctxt2, output, hashparams->resultlen);
+ hashparams->hfinal(output, ctxt->hashctxt2);
+ free(ctxt);
return 0;
}
@@ -144,15 +138,15 @@ int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *result)
* hashparams [in] - The hash function (Curl_HMAC_MD5).
* key [in] - The key to use.
* keylen [in] - The length of the key.
- * data [in] - The data to encrypt.
- * datalen [in] - The length of the data.
+ * buf [in] - The data to encrypt.
+ * buflen [in] - The length of the data.
* output [in/out] - The output buffer.
*
* Returns CURLE_OK on success.
*/
CURLcode Curl_hmacit(const struct HMAC_params *hashparams,
const unsigned char *key, const size_t keylen,
- const unsigned char *data, const size_t datalen,
+ const unsigned char *buf, const size_t buflen,
unsigned char *output)
{
struct HMAC_context *ctxt =
@@ -162,7 +156,7 @@ CURLcode Curl_hmacit(const struct HMAC_params *hashparams,
return CURLE_OUT_OF_MEMORY;
/* Update the digest with the given challenge */
- Curl_HMAC_update(ctxt, data, curlx_uztoui(datalen));
+ Curl_HMAC_update(ctxt, buf, curlx_uztoui(buflen));
/* Finalise the digest */
Curl_HMAC_final(ctxt, output);