[Botan-devel] Botan C++ vs TPLockBox

atlantida sotlef at atlantida.perm.ru
Mon Sep 24 13:08:15 EDT 2007


> This is very close to PKCS #7... what does it put into the bytes (if
> any) between the last byte of actual data and the byte with the length
> of the block? Does it just leave those as whatever they were in the
> last ciphertext block, or ?

It put zeroes between them. I try to translate this code from TPLockBox
to pseudo-C++:

void encryptInCBCmode(string& input, string& output, byte key[]) {
  int blockcount = input.size() / AES::BLOCK_SIZE;
  block, iv : Block; // some type Block
  
  iv = Block::set_random_IV(); //In Delphi it returns output
of /dev/random for linux 
  set_block(output, AES::encryptBlock(iv, key), sizeof(Block));

  //when encrypting, make sure we have a block with at least one free
  //byte at the end. used to store the odd byte count value [TPLockBox
comment]
  blockcount++;

  //process all except the last block
  for (int i = 0; i < blockcount-1; i++) {
    block = get_next_block(input, AES::BLOCK_SIZE);
    add_block(output, iv=AES::encryptBlock(block^iv, key),sizeof(Block);
  }
  
  byte last = input.size() % AES::BLOCK_SIZE;
  bzero(block, sizeof(block));		// space between size-byte and actual
data will be 'zero'
  block = get_next_block(input, last);
  block[AES::BLOCK_SIZE-1] = last;
  add_block(output,encryptBlock(block^iv, key),sizeof(Block));

//Encoder-decoder both libraries are capable :-)
  output = Base64Encode(output);
}

***** Decrypting for it will be: ******
void decryptInCBCmode(string& input, string& output, byte key[]) {
  int blockcount = input.size() / AES::BLOCK_SIZE;
  block, iv : Block;
  
  input = Base64Decode(input);
  iv = get_next_block(input, AES::BLOCK_SIZE);
  blockcount--;
  for (int i = 0; i < blockcount-1; i++) {
    block = get_next_block(input, AES::BLOCK_SIZE);
    add_block(output, iv = (decryptBlock(block, key) ^ iv),
sizeof(Block));
  }

  block = get_next_block(input, AES::BLOCK_SIZE);
  block = decryptBlock(block, key) ^ iv;
  int len = block[sizeof(Block)-1];
  add_block(output, block, len);
}

Is it same as PKCS #7? 




More information about the botan-devel mailing list