|
@@ -42,28 +42,34 @@ static int decode_packet (SPProtoDecoder *o, uint8_t *in, int in_len, uint8_t **
|
|
|
plaintext = in;
|
|
plaintext = in;
|
|
|
plaintext_len = in_len;
|
|
plaintext_len = in_len;
|
|
|
} else {
|
|
} else {
|
|
|
- // check length
|
|
|
|
|
|
|
+ // input must be a multiple of blocks size
|
|
|
if (in_len % o->enc_block_size != 0) {
|
|
if (in_len % o->enc_block_size != 0) {
|
|
|
DEBUG("packet size not a multiple of block size");
|
|
DEBUG("packet size not a multiple of block size");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // input must have an IV block
|
|
|
if (in_len < o->enc_block_size) {
|
|
if (in_len < o->enc_block_size) {
|
|
|
DEBUG("packet does not have an IV");
|
|
DEBUG("packet does not have an IV");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// check if we have encryption key
|
|
// check if we have encryption key
|
|
|
if (!o->have_encryption_key) {
|
|
if (!o->have_encryption_key) {
|
|
|
DEBUG("have no encryption key");
|
|
DEBUG("have no encryption key");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// copy IV as BEncryption_Decrypt changes the IV
|
|
// copy IV as BEncryption_Decrypt changes the IV
|
|
|
uint8_t iv[o->enc_block_size];
|
|
uint8_t iv[o->enc_block_size];
|
|
|
memcpy(iv, in, o->enc_block_size);
|
|
memcpy(iv, in, o->enc_block_size);
|
|
|
|
|
+
|
|
|
// decrypt
|
|
// decrypt
|
|
|
uint8_t *ciphertext = in + o->enc_block_size;
|
|
uint8_t *ciphertext = in + o->enc_block_size;
|
|
|
int ciphertext_len = in_len - o->enc_block_size;
|
|
int ciphertext_len = in_len - o->enc_block_size;
|
|
|
plaintext = o->buf;
|
|
plaintext = o->buf;
|
|
|
BEncryption_Decrypt(&o->encryptor, ciphertext, plaintext, ciphertext_len, iv);
|
|
BEncryption_Decrypt(&o->encryptor, ciphertext, plaintext, ciphertext_len, iv);
|
|
|
|
|
+
|
|
|
// read padding
|
|
// read padding
|
|
|
if (ciphertext_len < o->enc_block_size) {
|
|
if (ciphertext_len < o->enc_block_size) {
|
|
|
DEBUG("packet does not have a padding block");
|
|
DEBUG("packet does not have a padding block");
|