asmcrypto / asmcrypto.js

JavaScript Cryptographic Library with performance in mind.
MIT License
659 stars 182 forks source link

Why does ECB encryption return 32 octets with a block size of 16? #137

Open ghost opened 6 years ago

ghost commented 6 years ago

Hi, I'm trying to use the currently undocumented ECB functions. I'm puzzled as to why the encrypt function returns 32 octets when it looks like a block size of 16 is specified as the default. Here's my test:

// ECB test
var asmcrypto = require('./asmcrypto.all');
var utils = require('./utils.js');

// AEC-ECB(000000000012345677E4D611358EAF17,8b84eedec100067d670971dd2aa700cf)
var hex_data    = "000000000012345677E4D611358EAF17";
var hex_key     = "8b84eedec100067d670971dd2aa700cf";
var hex_padding = "";

console.log("encrypt("+hex_data+","+hex_key+")");
var ecb_encrypted = asmcrypto.AES_ECB.encrypt( utils.hexToU8A(hex_data), utils.hexToU8A(hex_key), utils.hexToU8A(hex_padding));
console.log(asmcrypto.bytes_to_hex(ecb_encrypted));

and this produces the following output:

encrypt(000000000012345677E4D611358EAF17,8b84eedec100067d670971dd2aa700cf)
b2021754866e87226cf5b7f4232d216a7e1ba4becd78a1741240f6e18e623a43

The first 16 octets are my expected result:

b2021754866e87226cf5b7f4232d216a

What are the 16 which follow?

Thanks

alippai commented 6 years ago

Can you check version 2.0, please? The API may be changed.

ghost commented 6 years ago

It looks like the fix has been regressed. I just ran my test code against the same asmcrypto code I was using last year and compared with the latest from head, cloned a few minutes ago.

From HEAD:

encrypt(000000000012345677E4D611358EAF17,8b84eedec100067d670971dd2aa700cf)
b2021754866e87226cf5b7f4232d216a7e1ba4becd78a1741240f6e18e623a43
------
decrypt(b2021754866e87226cf5b7f4232d216a7e1ba4becd78a1741240f6e18e623a43,8b84eedec100067d670971dd2aa700cf)
000000000012345677e4d611358eaf17

Last year's code

encrypt(000000000012345677E4D611358EAF17,8b84eedec100067d670971dd2aa700cf)
b2021754866e87226cf5b7f4232d216a
------
decrypt(b2021754866e87226cf5b7f4232d216a,8b84eedec100067d670971dd2aa700cf)
000000000012345677e4d611358eaf17
alippai commented 6 years ago

I see the error cause now, we will fix it shortly and add these test cases. Thanks!