Switch EVP_CIPHERs to C99 initializers
We're using it in parts of EVP already and this is much more readable.
Change-Id: I42f30b83331cafdabd4f5d995b61176458e906bc
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67567
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
diff --git a/crypto/cipher_extra/e_des.c b/crypto/cipher_extra/e_des.c
index baf0be0..62ac2a0 100644
--- a/crypto/cipher_extra/e_des.c
+++ b/crypto/cipher_extra/e_des.c
@@ -85,16 +85,14 @@
}
static const EVP_CIPHER evp_des_cbc = {
- /* nid = */ NID_des_cbc,
- /* block_size = */ 8,
- /* key_len = */ 8,
- /* iv_len = */ 8,
- /* ctx_size = */ sizeof(EVP_DES_KEY),
- /* flags = */ EVP_CIPH_CBC_MODE,
- /* init = */ des_init_key,
- /* cipher = */ des_cbc_cipher,
- /* cleanup = */ NULL,
- /* ctrl = */ NULL,
+ .nid = NID_des_cbc,
+ .block_size = 8,
+ .key_len = 8,
+ .iv_len = 8,
+ .ctx_size = sizeof(EVP_DES_KEY),
+ .flags = EVP_CIPH_CBC_MODE,
+ .init = des_init_key,
+ .cipher = des_cbc_cipher,
};
const EVP_CIPHER *EVP_des_cbc(void) { return &evp_des_cbc; }
@@ -114,16 +112,14 @@
}
static const EVP_CIPHER evp_des_ecb = {
- /* nid = */ NID_des_ecb,
- /* block_size = */ 8,
- /* key_len = */ 8,
- /* iv_len = */ 0,
- /* ctx_size = */ sizeof(EVP_DES_KEY),
- /* flags = */ EVP_CIPH_ECB_MODE,
- /* init = */ des_init_key,
- /* cipher = */ des_ecb_cipher,
- /* cleanup = */ NULL,
- /* ctrl = */ NULL,
+ .nid = NID_des_ecb,
+ .block_size = 8,
+ .key_len = 8,
+ .iv_len = 0,
+ .ctx_size = sizeof(EVP_DES_KEY),
+ .flags = EVP_CIPH_ECB_MODE,
+ .init = des_init_key,
+ .cipher = des_ecb_cipher,
};
const EVP_CIPHER *EVP_des_ecb(void) { return &evp_des_ecb; }
@@ -153,16 +149,14 @@
}
static const EVP_CIPHER evp_des_ede3_cbc = {
- /* nid = */ NID_des_ede3_cbc,
- /* block_size = */ 8,
- /* key_len = */ 24,
- /* iv_len = */ 8,
- /* ctx_size = */ sizeof(DES_EDE_KEY),
- /* flags = */ EVP_CIPH_CBC_MODE,
- /* init = */ des_ede3_init_key,
- /* cipher = */ des_ede3_cbc_cipher,
- /* cleanup = */ NULL,
- /* ctrl = */ NULL,
+ .nid = NID_des_ede3_cbc,
+ .block_size = 8,
+ .key_len = 24,
+ .iv_len = 8,
+ .ctx_size = sizeof(DES_EDE_KEY),
+ .flags = EVP_CIPH_CBC_MODE,
+ .init = des_ede3_init_key,
+ .cipher = des_ede3_cbc_cipher,
};
const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; }
@@ -178,16 +172,14 @@
}
static const EVP_CIPHER evp_des_ede_cbc = {
- /* nid = */ NID_des_ede_cbc,
- /* block_size = */ 8,
- /* key_len = */ 16,
- /* iv_len = */ 8,
- /* ctx_size = */ sizeof(DES_EDE_KEY),
- /* flags = */ EVP_CIPH_CBC_MODE,
- /* init = */ des_ede_init_key,
- /* cipher = */ des_ede3_cbc_cipher,
- /* cleanup = */ NULL,
- /* ctrl = */ NULL,
+ .nid = NID_des_ede_cbc,
+ .block_size = 8,
+ .key_len = 16,
+ .iv_len = 8,
+ .ctx_size = sizeof(DES_EDE_KEY),
+ .flags = EVP_CIPH_CBC_MODE,
+ .init = des_ede_init_key,
+ .cipher = des_ede3_cbc_cipher,
};
const EVP_CIPHER *EVP_des_ede_cbc(void) { return &evp_des_ede_cbc; }
@@ -208,31 +200,27 @@
}
static const EVP_CIPHER evp_des_ede = {
- /* nid = */ NID_des_ede_ecb,
- /* block_size = */ 8,
- /* key_len = */ 16,
- /* iv_len = */ 0,
- /* ctx_size = */ sizeof(DES_EDE_KEY),
- /* flags = */ EVP_CIPH_ECB_MODE,
- /* init = */ des_ede_init_key,
- /* cipher = */ des_ede_ecb_cipher,
- /* cleanup = */ NULL,
- /* ctrl = */ NULL,
+ .nid = NID_des_ede_ecb,
+ .block_size = 8,
+ .key_len = 16,
+ .iv_len = 0,
+ .ctx_size = sizeof(DES_EDE_KEY),
+ .flags = EVP_CIPH_ECB_MODE,
+ .init = des_ede_init_key,
+ .cipher = des_ede_ecb_cipher,
};
const EVP_CIPHER *EVP_des_ede(void) { return &evp_des_ede; }
static const EVP_CIPHER evp_des_ede3 = {
- /* nid = */ NID_des_ede3_ecb,
- /* block_size = */ 8,
- /* key_len = */ 24,
- /* iv_len = */ 0,
- /* ctx_size = */ sizeof(DES_EDE_KEY),
- /* flags = */ EVP_CIPH_ECB_MODE,
- /* init = */ des_ede3_init_key,
- /* cipher = */ des_ede_ecb_cipher,
- /* cleanup = */ NULL,
- /* ctrl = */ NULL,
+ .nid = NID_des_ede3_ecb,
+ .block_size = 8,
+ .key_len = 24,
+ .iv_len = 0,
+ .ctx_size = sizeof(DES_EDE_KEY),
+ .flags = EVP_CIPH_ECB_MODE,
+ .init = des_ede3_init_key,
+ .cipher = des_ede_ecb_cipher,
};
const EVP_CIPHER *EVP_des_ede3(void) { return &evp_des_ede3; }
diff --git a/crypto/cipher_extra/e_null.c b/crypto/cipher_extra/e_null.c
index 10a5c26..ad99df9 100644
--- a/crypto/cipher_extra/e_null.c
+++ b/crypto/cipher_extra/e_null.c
@@ -78,9 +78,13 @@
}
static const EVP_CIPHER n_cipher = {
- NID_undef, 1 /* block size */, 0 /* key_len */, 0 /* iv_len */,
- 0 /* ctx_size */, 0 /* flags */, null_init_key, null_cipher,
- NULL /* cleanup */, NULL /* ctrl */,
+ .nid = NID_undef,
+ .block_size = 1,
+ .key_len = 0,
+ .iv_len = 0,
+ .ctx_size = 0,
+ .init = null_init_key,
+ .cipher = null_cipher,
};
const EVP_CIPHER *EVP_enc_null(void) { return &n_cipher; }
diff --git a/crypto/cipher_extra/e_rc2.c b/crypto/cipher_extra/e_rc2.c
index acc99ad..c2a143e 100644
--- a/crypto/cipher_extra/e_rc2.c
+++ b/crypto/cipher_extra/e_rc2.c
@@ -427,35 +427,29 @@
}
static const EVP_CIPHER rc2_40_cbc = {
- NID_rc2_40_cbc,
- 8 /* block size */,
- 5 /* 40 bit */,
- 8 /* iv len */,
- sizeof(EVP_RC2_KEY),
- EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
- rc2_init_key,
- rc2_cbc_cipher,
- NULL,
- rc2_ctrl,
+ .nid = NID_rc2_40_cbc,
+ .block_size = 8,
+ .key_len = 5 /* 40 bit */,
+ .iv_len = 8,
+ .ctx_size = sizeof(EVP_RC2_KEY),
+ .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
+ .init = rc2_init_key,
+ .cipher = rc2_cbc_cipher,
+ .ctrl = rc2_ctrl,
};
-const EVP_CIPHER *EVP_rc2_40_cbc(void) {
- return &rc2_40_cbc;
-}
+const EVP_CIPHER *EVP_rc2_40_cbc(void) { return &rc2_40_cbc; }
static const EVP_CIPHER rc2_cbc = {
- NID_rc2_cbc,
- 8 /* block size */,
- 16 /* 128 bit */,
- 8 /* iv len */,
- sizeof(EVP_RC2_KEY),
- EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
- rc2_init_key,
- rc2_cbc_cipher,
- NULL,
- rc2_ctrl,
+ .nid = NID_rc2_cbc,
+ .block_size = 8,
+ .key_len = 16 /* 128 bit */,
+ .iv_len = 8,
+ .ctx_size = sizeof(EVP_RC2_KEY),
+ .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
+ .init = rc2_init_key,
+ .cipher = rc2_cbc_cipher,
+ .ctrl = rc2_ctrl,
};
-const EVP_CIPHER *EVP_rc2_cbc(void) {
- return &rc2_cbc;
-}
+const EVP_CIPHER *EVP_rc2_cbc(void) { return &rc2_cbc; }
diff --git a/crypto/cipher_extra/e_rc4.c b/crypto/cipher_extra/e_rc4.c
index e252ad8..0c3404f 100644
--- a/crypto/cipher_extra/e_rc4.c
+++ b/crypto/cipher_extra/e_rc4.c
@@ -81,10 +81,14 @@
}
static const EVP_CIPHER rc4 = {
- NID_rc4, 1 /* block_size */, 16 /* key_size */,
- 0 /* iv_len */, sizeof(RC4_KEY), EVP_CIPH_VARIABLE_LENGTH,
- rc4_init_key, rc4_cipher, NULL /* cleanup */,
- NULL /* ctrl */,
+ .nid = NID_rc4,
+ .block_size = 1,
+ .key_len = 16,
+ .iv_len = 0,
+ .ctx_size = sizeof(RC4_KEY),
+ .flags = EVP_CIPH_VARIABLE_LENGTH,
+ .init = rc4_init_key,
+ .cipher = rc4_cipher,
};
const EVP_CIPHER *EVP_rc4(void) { return &rc4; }
diff --git a/decrepit/blowfish/blowfish.c b/decrepit/blowfish/blowfish.c
index 654cd86..82acb5f 100644
--- a/decrepit/blowfish/blowfish.c
+++ b/decrepit/blowfish/blowfish.c
@@ -594,27 +594,36 @@
}
static const EVP_CIPHER bf_ecb = {
- NID_bf_ecb, BF_BLOCK /* block_size */,
- 16 /* key_size */, BF_BLOCK /* iv_len */,
- sizeof(BF_KEY), EVP_CIPH_ECB_MODE | EVP_CIPH_VARIABLE_LENGTH,
- bf_init_key, bf_ecb_cipher,
- NULL /* cleanup */, NULL /* ctrl */,
+ .nid = NID_bf_ecb,
+ .block_size = BF_BLOCK,
+ .key_len = 16,
+ .iv_len = BF_BLOCK,
+ .ctx_size = sizeof(BF_KEY),
+ .flags = EVP_CIPH_ECB_MODE | EVP_CIPH_VARIABLE_LENGTH,
+ .init = bf_init_key,
+ .cipher = bf_ecb_cipher,
};
static const EVP_CIPHER bf_cbc = {
- NID_bf_cbc, BF_BLOCK /* block_size */,
- 16 /* key_size */, BF_BLOCK /* iv_len */,
- sizeof(BF_KEY), EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH,
- bf_init_key, bf_cbc_cipher,
- NULL /* cleanup */, NULL /* ctrl */,
+ .nid = NID_bf_cbc,
+ .block_size = BF_BLOCK,
+ .key_len = 16,
+ .iv_len = BF_BLOCK,
+ .ctx_size = sizeof(BF_KEY),
+ .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH,
+ .init = bf_init_key,
+ .cipher = bf_cbc_cipher,
};
static const EVP_CIPHER bf_cfb = {
- NID_bf_cfb64, 1 /* block_size */,
- 16 /* key_size */, BF_BLOCK /* iv_len */,
- sizeof(BF_KEY), EVP_CIPH_CFB_MODE | EVP_CIPH_VARIABLE_LENGTH,
- bf_init_key, bf_cfb_cipher,
- NULL /* cleanup */, NULL /* ctrl */,
+ .nid = NID_bf_cfb64,
+ .block_size = 1,
+ .key_len = 16,
+ .iv_len = BF_BLOCK,
+ .ctx_size = sizeof(BF_KEY),
+ .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_VARIABLE_LENGTH,
+ .init = bf_init_key,
+ .cipher = bf_cfb_cipher,
};
const EVP_CIPHER *EVP_bf_ecb(void) { return &bf_ecb; }
diff --git a/decrepit/cast/cast.c b/decrepit/cast/cast.c
index 9e87b3f..f6f1963 100644
--- a/decrepit/cast/cast.c
+++ b/decrepit/cast/cast.c
@@ -437,19 +437,25 @@
}
static const EVP_CIPHER cast5_ecb = {
- NID_cast5_ecb, CAST_BLOCK,
- CAST_KEY_LENGTH, CAST_BLOCK /* iv_len */,
- sizeof(CAST_KEY), EVP_CIPH_ECB_MODE | EVP_CIPH_VARIABLE_LENGTH,
- cast_init_key, cast_ecb_cipher,
- NULL /* cleanup */, NULL /* ctrl */,
+ .nid = NID_cast5_ecb,
+ .block_size = CAST_BLOCK,
+ .key_len = CAST_KEY_LENGTH,
+ .iv_len = CAST_BLOCK,
+ .ctx_size = sizeof(CAST_KEY),
+ .flags = EVP_CIPH_ECB_MODE | EVP_CIPH_VARIABLE_LENGTH,
+ .init = cast_init_key,
+ .cipher = cast_ecb_cipher,
};
static const EVP_CIPHER cast5_cbc = {
- NID_cast5_cbc, CAST_BLOCK,
- CAST_KEY_LENGTH, CAST_BLOCK /* iv_len */,
- sizeof(CAST_KEY), EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH,
- cast_init_key, cast_cbc_cipher,
- NULL /* cleanup */, NULL /* ctrl */,
+ .nid = NID_cast5_cbc,
+ .block_size = CAST_BLOCK,
+ .key_len = CAST_KEY_LENGTH,
+ .iv_len = CAST_BLOCK,
+ .ctx_size = sizeof(CAST_KEY),
+ .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH,
+ .init = cast_init_key,
+ .cipher = cast_cbc_cipher,
};
const EVP_CIPHER *EVP_cast5_ecb(void) { return &cast5_ecb; }
diff --git a/decrepit/cfb/cfb.c b/decrepit/cfb/cfb.c
index 12709a4..0ac3228 100644
--- a/decrepit/cfb/cfb.c
+++ b/decrepit/cfb/cfb.c
@@ -52,24 +52,36 @@
}
static const EVP_CIPHER aes_128_cfb128 = {
- NID_aes_128_cfb128, 1 /* block_size */, 16 /* key_size */,
- 16 /* iv_len */, sizeof(EVP_CFB_CTX), EVP_CIPH_CFB_MODE,
- aes_cfb_init_key, aes_cfb128_cipher, NULL /* cleanup */,
- NULL /* ctrl */,
+ .nid = NID_aes_128_cfb128,
+ .block_size = 1,
+ .key_len = 16,
+ .iv_len = 16,
+ .ctx_size = sizeof(EVP_CFB_CTX),
+ .flags = EVP_CIPH_CFB_MODE,
+ .init = aes_cfb_init_key,
+ .cipher = aes_cfb128_cipher,
};
static const EVP_CIPHER aes_192_cfb128 = {
- NID_aes_192_cfb128, 1 /* block_size */, 24 /* key_size */,
- 16 /* iv_len */, sizeof(EVP_CFB_CTX), EVP_CIPH_CFB_MODE,
- aes_cfb_init_key, aes_cfb128_cipher, NULL /* cleanup */,
- NULL /* ctrl */,
+ .nid = NID_aes_192_cfb128,
+ .block_size = 1,
+ .key_len = 24,
+ .iv_len = 16,
+ .ctx_size = sizeof(EVP_CFB_CTX),
+ .flags = EVP_CIPH_CFB_MODE,
+ .init = aes_cfb_init_key,
+ .cipher = aes_cfb128_cipher,
};
static const EVP_CIPHER aes_256_cfb128 = {
- NID_aes_256_cfb128, 1 /* block_size */, 32 /* key_size */,
- 16 /* iv_len */, sizeof(EVP_CFB_CTX), EVP_CIPH_CFB_MODE,
- aes_cfb_init_key, aes_cfb128_cipher, NULL /* cleanup */,
- NULL /* ctrl */,
+ .nid = NID_aes_256_cfb128,
+ .block_size = 1,
+ .key_len = 32,
+ .iv_len = 16,
+ .ctx_size = sizeof(EVP_CFB_CTX),
+ .flags = EVP_CIPH_CFB_MODE,
+ .init = aes_cfb_init_key,
+ .cipher = aes_cfb128_cipher,
};
const EVP_CIPHER *EVP_aes_128_cfb128(void) { return &aes_128_cfb128; }
diff --git a/decrepit/xts/xts.c b/decrepit/xts/xts.c
index b44d6f4..47c7044 100644
--- a/decrepit/xts/xts.c
+++ b/decrepit/xts/xts.c
@@ -229,16 +229,16 @@
}
static const EVP_CIPHER aes_256_xts = {
- NID_aes_256_xts,
- 1 /* block_size */,
- 64 /* key_size (2 AES keys) */,
- 16 /* iv_len */,
- sizeof(EVP_AES_XTS_CTX),
- EVP_CIPH_XTS_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_ALWAYS_CALL_INIT |
- EVP_CIPH_CTRL_INIT | EVP_CIPH_CUSTOM_COPY,
- aes_xts_init_key,
- aes_xts_cipher,
- NULL /* cleanup */,
- aes_xts_ctrl};
+ .nid = NID_aes_256_xts,
+ .block_size = 1,
+ .key_len = 64 /* 2 AES-256 keys */,
+ .iv_len = 16,
+ .ctx_size = sizeof(EVP_AES_XTS_CTX),
+ .flags = EVP_CIPH_XTS_MODE | EVP_CIPH_CUSTOM_IV |
+ EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT |
+ EVP_CIPH_CUSTOM_COPY,
+ .init = aes_xts_init_key,
+ .cipher = aes_xts_cipher,
+ .ctrl = aes_xts_ctrl};
const EVP_CIPHER *EVP_aes_256_xts(void) { return &aes_256_xts; }