originalfly / crypto-js

Automatically exported from code.google.com/p/crypto-js
0 stars 0 forks source link

HmacSHA224 and HmacSHA384 give incorrect output #84

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

HmacSHA224 and HmacSHA384 appear to be giving incorrect hex output.

Here's an example showing different output between PHP 5.4.13 and CryptoJS 
v3.1.2:

// Not equal
// 59236d2047ae349e4aaddf08f75635dc88c75272e43423659ec0791a
hash_hmac('sha224', 'Message', 'Secret Passphrase');
// 352ea6a011d539e468974821c3d1a77691ce562e065ec49f21055eb0 
CryptoJS.HmacSHA224("Message", "Secret Passphrase").toString();

// Not equal
// 
84b318cc0232a370c1f8b8746afcb575fc2debc680122c7422fd425638896d0dcf9e905b8cd9c1d7
aed8d5439a2a2328
hash_hmac('sha384', 'Message', 'Secret Passphrase');
// 
7fab4d58c76251997559408ccc680718ad4813d056f37c65ea7c03780b81de3086a2f61edfaa0251
9d9916b3f4ae4a5c
CryptoJS.HmacSHA384("Message", "Secret Passphrase").toString();

The output strings are equal for the HmacSHA256 and HmacSHA512 variants:

// Equal
// 32c647602ab4c4c7543e9c50ae25e567c3354e1532b11649ce308e6e2568d205
hash_hmac('sha256', 'Message', 'Secret Passphrase');
CryptoJS.HmacSHA256("Message", "Secret Passphrase").toString();

// Equal
// 
c03f82cd6f9d03920d95caeedfa722d4e42325a18b049942ee5560787ad2aa394be6b95849c563ec
dd37495726cd6236529a721b563b9778dd6119939bcab7e1
hash_hmac('sha512', 'Message', 'Secret Passphrase');
CryptoJS.HmacSHA512("Message", "Secret Passphrase").toString();

I tested with:
rollups/hmac-shaXXX.js
rollups/shaXXX.js

Browsers: Chrome and Firefox

I also tested the non-hmac versions of sha224, sha256, sha384, and sha512 
between php (hash) and CryptoJS. There were no issues here. The strings were 
equal.

I wasn't 100% sure this was a CryptoJS problem so I tested with some C# code. 
The C# output backed up the php output. I used the built-in HMACSHA384 class 
and a 3rd-party hmac-sha224 class (http://hashlib.codeplex.com/).

Thanks.

Original issue reported on code.google.com by lace...@gmail.com on 17 Mar 2013 at 7:08

GoogleCodeExporter commented 8 years ago
Hi, 

I think CryptoJS Hmac issue.

HmacSHA224 and HmacSHA384 results are also different with OpenSSL.

% echo -n > aaa.txt
% openssl dgst -sha224 -hmac pass aaa.txt
% openssl dgst -sha384 -hmac pass aaa.txt

Thank you in advance for your quick fix.

Original comment by kenji.ur...@gmail.com on 25 Aug 2013 at 12:59

GoogleCodeExporter commented 8 years ago
For a temporary patch, you can use this copy of core.js.

https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js

Original comment by Jeff.Mott.OR on 29 Aug 2013 at 2:37

GoogleCodeExporter commented 8 years ago
Hi Jeff, thank you for the quick fix. It works fine.

Original comment by kenji.ur...@gmail.com on 24 Sep 2013 at 7:18

GoogleCodeExporter commented 8 years ago
I ran into this too, seems like a pretty serious bug. The patch seemed to work.

Original comment by p...@golfswingviewer.com on 5 Feb 2014 at 1:39