diff options
author | Matt Caswell <matt@openssl.org> | 2019-04-03 16:53:22 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2019-04-19 09:31:54 +0100 |
commit | f4a129bb8dc26488e29b06e06e96a76c93f966be (patch) | |
tree | f0404d2d692d3fb97ba36001d9b1ca5bf162dd81 | |
parent | 861b8f8747965bf98d9dd328196b8092e709c99d (diff) |
Add support in the default provider for 192/128 bit AES ECB
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8700)
-rw-r--r-- | crypto/evp/evp_enc.c | 2 | ||||
-rw-r--r-- | providers/common/ciphers/aes.c | 64 | ||||
-rw-r--r-- | providers/common/include/internal/provider_algs.h | 2 | ||||
-rw-r--r-- | providers/default/defltprov.c | 2 |
4 files changed, 70 insertions, 0 deletions
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 7b9fae39b8..6dbc7147e4 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -140,6 +140,8 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, if (tmpcipher->prov == NULL) { switch(tmpcipher->nid) { case NID_aes_256_ecb: + case NID_aes_192_ecb: + case NID_aes_128_ecb: break; default: goto legacy; diff --git a/providers/common/ciphers/aes.c b/providers/common/ciphers/aes.c index a73f20cd73..6a46e86910 100644 --- a/providers/common/ciphers/aes.c +++ b/providers/common/ciphers/aes.c @@ -146,6 +146,28 @@ static void *aes_256_ecb_newctx(void) return ctx; } +static void *aes_192_ecb_newctx(void) +{ + PROV_AES_KEY *ctx = OPENSSL_zalloc(sizeof(*ctx)); + + ctx->pad = 1; + ctx->keylen = 192 / 8; + ctx->ciph = PROV_AES_CIPHER_ecb(); + ctx->mode = EVP_CIPH_ECB_MODE; + return ctx; +} + +static void *aes_128_ecb_newctx(void) +{ + PROV_AES_KEY *ctx = OPENSSL_zalloc(sizeof(*ctx)); + + ctx->pad = 1; + ctx->keylen = 128 / 8; + ctx->ciph = PROV_AES_CIPHER_ecb(); + ctx->mode = EVP_CIPH_ECB_MODE; + return ctx; +} + static void aes_freectx(void *vctx) { PROV_AES_KEY *ctx = (PROV_AES_KEY *)vctx; @@ -168,6 +190,16 @@ static size_t key_length_256(void) return 256 / 8; } +static size_t key_length_192(void) +{ + return 192 / 8; +} + +static size_t key_length_128(void) +{ + return 128 / 8; +} + static int aes_get_params(void *vctx, const OSSL_PARAM params[]) { PROV_AES_KEY *ctx = (PROV_AES_KEY *)vctx; @@ -209,3 +241,35 @@ const OSSL_DISPATCH aes256ecb_functions[] = { { OSSL_FUNC_CIPHER_SET_PARAMS, (void (*)(void))aes_set_params }, { 0, NULL } }; + +const OSSL_DISPATCH aes192ecb_functions[] = { + { OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))aes_192_ecb_newctx }, + { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))aes_einit }, + { OSSL_FUNC_CIPHER_ENCRYPT_UPDATE, (void (*)(void))aes_update }, + { OSSL_FUNC_CIPHER_ENCRYPT_FINAL, (void (*)(void))aes_efinal }, + { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))aes_dinit }, + { OSSL_FUNC_CIPHER_DECRYPT_UPDATE, (void (*)(void))aes_update }, + { OSSL_FUNC_CIPHER_DECRYPT_FINAL, (void (*)(void))aes_dfinal }, + { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))aes_freectx }, + { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))aes_dupctx }, + { OSSL_FUNC_CIPHER_KEY_LENGTH, (void (*)(void))key_length_192 }, + { OSSL_FUNC_CIPHER_GET_PARAMS, (void (*)(void))aes_get_params }, + { OSSL_FUNC_CIPHER_SET_PARAMS, (void (*)(void))aes_set_params }, + { 0, NULL } +}; + +const OSSL_DISPATCH aes128ecb_functions[] = { + { OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))aes_128_ecb_newctx }, + { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))aes_einit }, + { OSSL_FUNC_CIPHER_ENCRYPT_UPDATE, (void (*)(void))aes_update }, + { OSSL_FUNC_CIPHER_ENCRYPT_FINAL, (void (*)(void))aes_efinal }, + { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))aes_dinit }, + { OSSL_FUNC_CIPHER_DECRYPT_UPDATE, (void (*)(void))aes_update }, + { OSSL_FUNC_CIPHER_DECRYPT_FINAL, (void (*)(void))aes_dfinal }, + { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))aes_freectx }, + { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))aes_dupctx }, + { OSSL_FUNC_CIPHER_KEY_LENGTH, (void (*)(void))key_length_128 }, + { OSSL_FUNC_CIPHER_GET_PARAMS, (void (*)(void))aes_get_params }, + { OSSL_FUNC_CIPHER_SET_PARAMS, (void (*)(void))aes_set_params }, + { 0, NULL } +}; diff --git a/providers/common/include/internal/provider_algs.h b/providers/common/include/internal/provider_algs.h index 4e0fc552d6..b03d4f43fc 100644 --- a/providers/common/include/internal/provider_algs.h +++ b/providers/common/include/internal/provider_algs.h @@ -12,3 +12,5 @@ extern const OSSL_DISPATCH sha256_functions[]; /* Ciphers */ extern const OSSL_DISPATCH aes256ecb_functions[]; +extern const OSSL_DISPATCH aes192ecb_functions[]; +extern const OSSL_DISPATCH aes128ecb_functions[]; diff --git a/providers/default/defltprov.c b/providers/default/defltprov.c index 5cfbf695c7..1d98485253 100644 --- a/providers/default/defltprov.c +++ b/providers/default/defltprov.c @@ -57,6 +57,8 @@ static const OSSL_ALGORITHM deflt_digests[] = { static const OSSL_ALGORITHM deflt_ciphers[] = { { "AES-256-ECB", "default=yes", aes256ecb_functions }, + { "AES-192-ECB", "default=yes", aes192ecb_functions }, + { "AES-128-ECB", "default=yes", aes128ecb_functions }, { NULL, NULL, NULL } }; |