encrypt icon indicating copy to clipboard operation
encrypt copied to clipboard

padded_block_cipher_impl.dart "init" method doesn't check for 192 or 256 bits. Just the 128 bits

Open graviaDaemon opened this issue 3 years ago • 0 comments

I've been running into the error "Key length must be 128/192/256 bits' a lot when I know 100% sure I have a key of 256 bits, but after running through the stacktrace, I found that you have this init method. Upon closer inspection I came to the conclusion that the method fails to check for the higher two bit values.

if ( (kc != 4 ) && (kc != 6) && (kc != 8 ) ) || ( (kc*4) != key.lengthInBytes ) ) {
    throw ArgumentError('Key length must be 128/192/256 bits');
}

Should this not be:

if (( kc != 4 ) && (kc != 6) && (kc != 8 )) 
    || ( (( kc * 4 ) != key.lengthInBytes )  && (( kc * 6  ) != key.lengthInBytes ) && ((kc * 8 ) != key.lengthInBytes )) {
    throw ArgumentError('Key length must be 128/192/256 bits');
}

I could be wrong ofcourse, but still it bothered me a little that I keep running into this issue

graviaDaemon avatar Nov 04 '21 15:11 graviaDaemon