kolombet / as3crypto

Automatically exported from code.google.com/p/as3crypto
1 stars 0 forks source link

CTRMode broken - pads final block even with NullPad #62

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Due to the way the inner loop is written, CTRMode will expand the source byte 
array to the next block size.  CTR mode is not supposed to use padding, and on 
many systems (including Java) you cannot specify a padding to use with CTR mode.

This means you can't use CTRMode in as3 to interact with these systems.

Overriding this and changing the inner loop to break when it hits the src 
length fixes this problem nicely:

for (var j:uint=0;j<blockSize;j++) {
  if ((i+j) >= src.length)
    break;
  src[i+j] ^= Xenc[j];
}

You can then interact with Java using CTR/NoPadding.

Original issue reported on code.google.com by cottl...@gmail.com on 18 May 2011 at 7:25