Просмотр исходного кода

crypto: properly initialize key and iv to 0, add comment regarding the size of IV

- properly initialize key and iv to 0, otherwise invalid data might be printed
- the initialization vector for AES will be always AES blocksize, e.g. 128 bits
Henning Westerholt 4 лет назад
Родитель
Сommit
e9624bc482
1 измененных файлов с 3 добавлено и 1 удалено
  1. 3 1
      src/modules/crypto/crypto_aes.c

+ 3 - 1
src/modules/crypto/crypto_aes.c

@@ -76,7 +76,9 @@ int crypto_aes_init(unsigned char *key_data, int key_data_len,
 {
 	int i, nrounds = 5;
 	int x;
-	unsigned char key[32], iv[32];
+	unsigned char key[32], iv[32]; /* IV is only 16 bytes, but makes it easier */
+	memset(key, 0, sizeof(key));
+	memset(iv, 0, sizeof(iv));
 
 	/*
 	 * Gen key & IV for AES 256 CBC mode. A SHA1 digest is used to hash