Check key size in cipher_setkey()
diff --git a/library/cipher.c b/library/cipher.c
index ee2a1cd..c455ff9 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -638,6 +638,9 @@
     if( NULL == ctx || NULL == ctx->cipher_info )
         return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
 
+    if( (int) ctx->cipher_info->key_length != key_length )
+        return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
+
     ctx->key_length = key_length;
     ctx->operation = operation;