From: Florian Forster Date: Tue, 28 Jan 2014 21:10:30 +0000 (+0100) Subject: Fix the dwDataLen parameter of CryptImportKey(). X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c0a0ead97cf5dc85429caae24cc2ffe65fb2805c;p=create_hmac.git 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. --- 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);