return 0;
}
-void cipher_null_setiv ( void *ctx __unused, const void *iv __unused ) {
+void cipher_null_setiv ( void *ctx __unused, const void *iv __unused,
+ size_t ivlen __unused ) {
/* Do nothing */
}
*
* @v ctx Context
* @v iv Initialisation vector
+ * @v ivlen Initialisation vector length
* @v raw_cipher Underlying cipher algorithm
* @v cbc_ctx CBC context
*/
-static inline void cbc_setiv ( void *ctx __unused, const void *iv,
+static inline void cbc_setiv ( void *ctx __unused,
+ const void *iv, size_t ivlen,
struct cipher_algorithm *raw_cipher,
void *cbc_ctx ) {
+ assert ( ivlen == raw_cipher->blocksize );
memcpy ( cbc_ctx, iv, raw_cipher->blocksize );
}
return cbc_setkey ( &_cbc_name ## _ctx->raw_ctx, key, keylen, \
&_raw_cipher, &_cbc_name ## _ctx->cbc_ctx );\
} \
-static void _cbc_name ## _setiv ( void *ctx, const void *iv ) { \
+static void _cbc_name ## _setiv ( void *ctx, const void *iv, \
+ size_t ivlen ) { \
struct _cbc_name ## _context * _cbc_name ## _ctx = ctx; \
- cbc_setiv ( &_cbc_name ## _ctx->raw_ctx, iv, \
+ cbc_setiv ( &_cbc_name ## _ctx->raw_ctx, iv, ivlen, \
&_raw_cipher, &aes_cbc_ctx->cbc_ctx ); \
} \
static void _cbc_name ## _encrypt ( void *ctx, const void *src, \
*
* @v ctx Context
* @v iv Initialisation vector
+ * @v ivlen Initialisation vector length
*/
- void ( * setiv ) ( void *ctx, const void *iv );
+ void ( * setiv ) ( void *ctx, const void *iv, size_t ivlen );
/** Encrypt data
*
* @v ctx Context
}
static inline void cipher_setiv ( struct cipher_algorithm *cipher,
- void *ctx, const void *iv ) {
- cipher->setiv ( ctx, iv );
+ void *ctx, const void *iv, size_t ivlen ) {
+ cipher->setiv ( ctx, iv, ivlen );
}
static inline void cipher_encrypt ( struct cipher_algorithm *cipher,
extern void digest_null_final ( void *ctx, void *out );
extern int cipher_null_setkey ( void *ctx, const void *key, size_t keylen );
-extern void cipher_null_setiv ( void *ctx, const void *iv );
+extern void cipher_null_setiv ( void *ctx, const void *iv, size_t ivlen );
extern void cipher_null_encrypt ( void *ctx, const void *src, void *dst,
size_t len );
extern void cipher_null_decrypt ( void *ctx, const void *src, void *dst,
size_t keylen ) { \
return cipher_setkey ( &_raw_cipher, ctx, key, keylen ); \
} \
-static void _ecb_name ## _setiv ( void *ctx, const void *iv ) { \
- cipher_setiv ( &_raw_cipher, ctx, iv ); \
+static void _ecb_name ## _setiv ( void *ctx, const void *iv, \
+ size_t ivlen ) { \
+ cipher_setiv ( &_raw_cipher, ctx, iv, ivlen ); \
} \
static void _ecb_name ## _encrypt ( void *ctx, const void *src, \
void *dst, size_t len ) { \
}
/* Set initialisation vector */
- cipher_setiv ( peerblk->cipher, peerblk->cipherctx, msg->msg.iv.data );
+ cipher_setiv ( peerblk->cipher, peerblk->cipherctx, msg->msg.iv.data,
+ blksize );
return 0;
}
/* TX initialisation vector */
cipher_setiv ( tx_cipherspec->suite->cipher,
- tx_cipherspec->cipher_ctx, key );
+ tx_cipherspec->cipher_ctx, key, iv_size );
DBGC ( tls, "TLS %p TX IV:\n", tls );
DBGC_HD ( tls, key, iv_size );
key += iv_size;
/* RX initialisation vector */
cipher_setiv ( rx_cipherspec->suite->cipher,
- rx_cipherspec->cipher_ctx, key );
+ rx_cipherspec->cipher_ctx, key, iv_size );
DBGC ( tls, "TLS %p RX IV:\n", tls );
DBGC_HD ( tls, key, iv_size );
key += iv_size;
/* Initialise cipher */
okx ( cipher_setkey ( cipher, ctx, test->key, test->key_len ) == 0,
file, line );
- cipher_setiv ( cipher, ctx, test->iv );
+ cipher_setiv ( cipher, ctx, test->iv, test->iv_len );
/* Perform encryption */
cipher_encrypt ( cipher, ctx, test->plaintext, ciphertext, len );
/* Initialise cipher */
okx ( cipher_setkey ( cipher, ctx, test->key, test->key_len ) == 0,
file, line );
- cipher_setiv ( cipher, ctx, test->iv );
+ cipher_setiv ( cipher, ctx, test->iv, test->iv_len );
/* Perform encryption */
cipher_decrypt ( cipher, ctx, test->ciphertext, plaintext, len );
/* Initialise cipher */
rc = cipher_setkey ( cipher, ctx, key, key_len );
assert ( rc == 0 );
- cipher_setiv ( cipher, ctx, iv );
+ cipher_setiv ( cipher, ctx, iv, sizeof ( iv ) );
/* Profile cipher operation */
memset ( &profiler, 0, sizeof ( profiler ) );