]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add support in the default provider for 192/128 bit AES ECB
authorMatt Caswell <matt@openssl.org>
Wed, 3 Apr 2019 15:53:22 +0000 (16:53 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 19 Apr 2019 08:31:54 +0000 (09:31 +0100)
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8700)

crypto/evp/evp_enc.c
providers/common/ciphers/aes.c
providers/common/include/internal/provider_algs.h
providers/default/defltprov.c

index 7b9fae39b897f9e9638c7ede4222c304ce699d7a..6dbc7147e41c9011750b716ee86af785b8c75542 100644 (file)
@@ -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;
index a73f20cd73bf5a2d4c00b96910f2f7bd53e303f3..6a46e869100179c8d0e491f162da9a5ad6b86cbf 100644 (file)
@@ -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 }
+};
index 4e0fc552d63c17fd20d79c85cf4ce5092be6ce7d..b03d4f43fcfa14be036f8c064d1c24b2df0ae2c0 100644 (file)
@@ -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[];
index 5cfbf695c73b57dbebe775cb5c69a18ed18c0524..1d98485253e068e97563a051fe5c2f9d2a964efd 100644 (file)
@@ -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 }
 };