Enc doesn't support AEAD ciphers.
[openssl.git] / apps / enc.c
index 076225c4cb560ca8dd81160f54546a9562a713e5..d84c51dbcccbbd8da078aaaaa345bd1f177d9d5e 100644 (file)
@@ -129,6 +129,7 @@ int MAIN(int argc, char **argv)
        char *engine = NULL;
 #endif
        const EVP_MD *dgst=NULL;
+       int non_fips_allow = 0;
 
        apps_startup();
 
@@ -281,6 +282,8 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        md= *(++argv);
                        }
+               else if (strcmp(*argv,"-non-fips-allow") == 0)
+                       non_fips_allow = 1;
                else if ((argv[0][0] == '-') &&
                        ((c=EVP_get_cipherbyname(&(argv[0][1]))) != NULL))
                        {
@@ -328,6 +331,12 @@ bad:
         setup_engine(bio_err, engine, 0);
 #endif
 
+       if (cipher && EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)
+               {
+               BIO_printf(bio_err, "AEAD ciphers not supported by the enc utility\n");
+               goto end;
+               }
+
        if (md && (dgst=EVP_get_digestbyname(md)) == NULL)
                {
                BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
@@ -549,9 +558,13 @@ bad:
                                sptr = salt;
                        }
 
-                       EVP_BytesToKey(cipher,dgst,sptr,
-                               (unsigned char *)str,
-                               strlen(str),1,key,iv);
+                       if (!EVP_BytesToKey(cipher,dgst,sptr,
+                                           (unsigned char *)str,
+                                           strlen(str),1,key,iv))
+                               {
+                               BIO_printf(bio_err, "EVP_BytesToKey failed\n");
+                               goto end;
+                               }
                        /* zero the complete buffer or the string
                         * passed from the command line
                         * bug picked up by
@@ -589,6 +602,11 @@ bad:
                 */
 
                BIO_get_cipher_ctx(benc, &ctx);
+
+               if (non_fips_allow)
+                       EVP_CIPHER_CTX_set_flags(ctx,
+                               EVP_CIPH_FLAG_NON_FIPS_ALLOW);
+
                if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, enc))
                        {
                        BIO_printf(bio_err, "Error setting cipher %s\n",