when encrypting, use 128 byte buffers instead of 256 byte buffers because Pkcs7 padding

This commit is contained in:
Carson McManus 2021-08-24 23:24:17 -04:00
parent 4e09b98d07
commit ce2285d617

View file

@ -100,12 +100,13 @@ impl EntryEncryptor for LegacySdaCompatible {
let origsize = plaintext.len(); let origsize = plaintext.len();
let buffersize: usize = (origsize / 16 + (if origsize % 16 == 0 { 0 } else { 1 })) * 16; let buffersize: usize = (origsize / 16 + (if origsize % 16 == 0 { 0 } else { 1 })) * 16;
let mut buffer = vec![]; let mut buffer = vec![];
for chunk in plaintext.as_slice().chunks(256) { for chunk in plaintext.as_slice().chunks(128) {
let chunksize = chunk.len(); let chunksize = chunk.len();
let buffersize = (chunksize / 16 + (if chunksize % 16 == 0 { 0 } else { 1 })) * 16; let buffersize = (chunksize / 16 + (if chunksize % 16 == 0 { 0 } else { 1 })) * 16;
let mut chunkbuffer = vec![0xffu8; buffersize]; let mut chunkbuffer = vec![0xffu8; buffersize];
chunkbuffer[..chunksize].copy_from_slice(&chunk); chunkbuffer[..chunksize].copy_from_slice(&chunk);
if buffersize != chunksize { if buffersize != chunksize {
// pad the last chunk
chunkbuffer = Pkcs7::pad(&mut chunkbuffer, chunksize, buffersize) chunkbuffer = Pkcs7::pad(&mut chunkbuffer, chunksize, buffersize)
.unwrap() .unwrap()
.to_vec(); .to_vec();