.name = "aes",
.ctxsize = sizeof ( struct aes_context ),
.blocksize = AES_BLOCKSIZE,
+ .alignsize = 0,
.authsize = 0,
.setkey = aes_setkey,
.setiv = cipher_null_setiv,
.name = "ARC4",
.ctxsize = ARC4_CTX_SIZE,
.blocksize = 1,
+ .alignsize = 1,
.authsize = 0,
.setkey = arc4_setkey,
.setiv = cipher_null_setiv,
.name = "null",
.ctxsize = 0,
.blocksize = 1,
+ .alignsize = 1,
.authsize = 0,
.setkey = cipher_null_setkey,
.setiv = cipher_null_setiv,
.name = #_cbc_name, \
.ctxsize = sizeof ( struct _cbc_name ## _context ), \
.blocksize = _blocksize, \
+ .alignsize = _blocksize, \
.authsize = 0, \
.setkey = _cbc_name ## _setkey, \
.setiv = _cbc_name ## _setiv, \
const char *name;
/** Context size */
size_t ctxsize;
- /** Block size */
+ /** Block size
+ *
+ * Every call to encrypt() or decrypt() must be for a multiple
+ * of this size.
+ */
size_t blocksize;
+ /** Alignment size
+ *
+ * Every call to encrypt() or decrypt() must begin at a
+ * multiple of this offset from the start of the stream.
+ * (Equivalently: all but the last call to encrypt() or
+ * decrypt() must be for a multiple of this size.)
+ *
+ * For ciphers supporting additional data, the main data
+ * stream and additional data stream are both considered to
+ * begin at offset zero.
+ */
+ size_t alignsize;
/** Authentication tag size */
size_t authsize;
/** Set key
.name = #_ecb_name, \
.ctxsize = sizeof ( _raw_context ), \
.blocksize = _blocksize, \
+ .alignsize = _blocksize, \
.authsize = 0, \
.setkey = _ecb_name ## _setkey, \
.setiv = _ecb_name ## _setiv, \
.name = #_gcm_name, \
.ctxsize = sizeof ( struct _gcm_name ## _context ), \
.blocksize = 1, \
+ .alignsize = sizeof ( union gcm_block ), \
.authsize = sizeof ( union gcm_block ), \
.setkey = _gcm_name ## _setkey, \
.setiv = _gcm_name ## _setiv, \
*/
void cipher_okx ( struct cipher_test *test, const char *file,
unsigned int line ) {
+ struct cipher_algorithm *cipher = test->cipher;
+ size_t len = test->len;
+ /* Sanity checks */
+ okx ( cipher->blocksize != 0, file, line );
+ okx ( ( len % cipher->blocksize ) == 0, file, line );
+ okx ( ( cipher->alignsize % cipher->blocksize ) == 0, file, line );
+
+ /* Report encryption test result */
cipher_encrypt_okx ( test, file, line );
+
+ /* Report decryption test result */
cipher_decrypt_okx ( test, file, line );
}