Don't Increment IV for Partial Blocks in Unit Tests am: 3f040e0a9d am: 4b380dfb1b
am: dfd6df5cf9
Change-Id: I2fa15c7971020a7e9c0beed5400450d0206e412a
This commit is contained in:
@@ -2492,6 +2492,7 @@ class OEMCryptoSessionTestsDecryptTests
|
|||||||
(size < AES_BLOCK_SIZE))) {
|
(size < AES_BLOCK_SIZE))) {
|
||||||
memcpy(&(*out_buffer)[buffer_index], &in_buffer[buffer_index],
|
memcpy(&(*out_buffer)[buffer_index], &in_buffer[buffer_index],
|
||||||
size);
|
size);
|
||||||
|
block_offset = 0; // Next block should be complete.
|
||||||
} else {
|
} else {
|
||||||
if (cipher_mode_ == OEMCrypto_CipherMode_CTR) {
|
if (cipher_mode_ == OEMCrypto_CipherMode_CTR) {
|
||||||
uint8_t aes_output[AES_BLOCK_SIZE];
|
uint8_t aes_output[AES_BLOCK_SIZE];
|
||||||
@@ -2501,7 +2502,15 @@ class OEMCryptoSessionTestsDecryptTests
|
|||||||
aes_output[n + block_offset] ^
|
aes_output[n + block_offset] ^
|
||||||
in_buffer[buffer_index + n];
|
in_buffer[buffer_index + n];
|
||||||
}
|
}
|
||||||
ctr128_inc64(1, iv);
|
if (size + block_offset < AES_BLOCK_SIZE) {
|
||||||
|
// Partial block. Don't increment iv. Compute next block offset.
|
||||||
|
block_offset = block_offset + size;
|
||||||
|
} else {
|
||||||
|
EXPECT_EQ(AES_BLOCK_SIZE, block_offset + size);
|
||||||
|
// Full block. Increment iv, and set offset to 0 for next block.
|
||||||
|
ctr128_inc64(1, iv);
|
||||||
|
block_offset = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
uint8_t aes_input[AES_BLOCK_SIZE];
|
uint8_t aes_input[AES_BLOCK_SIZE];
|
||||||
for (size_t n = 0; n < size; n++) {
|
for (size_t n = 0; n < size; n++) {
|
||||||
@@ -2509,13 +2518,12 @@ class OEMCryptoSessionTestsDecryptTests
|
|||||||
}
|
}
|
||||||
AES_encrypt(aes_input, &(*out_buffer)[buffer_index], &aes_key);
|
AES_encrypt(aes_input, &(*out_buffer)[buffer_index], &aes_key);
|
||||||
memcpy(iv, &(*out_buffer)[buffer_index], AES_BLOCK_SIZE);
|
memcpy(iv, &(*out_buffer)[buffer_index], AES_BLOCK_SIZE);
|
||||||
|
// CBC mode should always start on block boundary.
|
||||||
|
block_offset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer_index += size;
|
buffer_index += size;
|
||||||
block_offset = 0;
|
|
||||||
}
|
}
|
||||||
block_offset =
|
|
||||||
(block_offset + subsample_size_[i].encrypted_size) % AES_BLOCK_SIZE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user