From c0a0ead97cf5dc85429caae24cc2ffe65fb2805c Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 28 Jan 2014 22:10:30 +0100 Subject: [PATCH] Fix the dwDataLen parameter of CryptImportKey(). According to the documentation (or rather, the example code) this parameter should specify the size of the entire structure, including the key material. sizeof(data) (4 or 8 bytes, depending on the architecture) is incorrect in any case however. --- create_hmac/create_hmac.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/create_hmac/create_hmac.c b/create_hmac/create_hmac.c index e966bca..e35c782 100644 --- a/create_hmac/create_hmac.c +++ b/create_hmac/create_hmac.c @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010 Florian Forster + * Copyright (c) 2010-2014 Florian Forster * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -75,10 +75,12 @@ static HCRYPTKEY create_hmac_key_exact (HCRYPTPROV hProv, * The "CRYPT_IPSEC_HMAC_KEY" is required to allow RC2 keys longer than * 16 byte. Again, this is documented on the "CryptImportKey" page as a * side note. */ - status = CryptImportKey (hProv, (BYTE *) data, sizeof (data), - /* public key = */ 0, - /* flags = */ CRYPT_IPSEC_HMAC_KEY, - &ret_key); + status = CryptImportKey (hProv, + /* pbData = */ (void *) data, + /* dwDataLen = */ data_size, + /* hPubKey = */ 0, + /* dwFlags = */ CRYPT_IPSEC_HMAC_KEY, + /* phKey = */ &ret_key); if (!status) { free (data); -- 2.11.0