Remove apps cache for gethostbyname
[openssl.git] / apps / enc.c
index c6b8d2bbf2b9f02cc1a5d0427bf7587040e186df..e4d490f25848dd7ac84f65bb9ffd943e061f8118 100644 (file)
@@ -113,7 +113,7 @@ OPTIONS enc_options[] = {
     {"bufsize", OPT_BUFSIZE, 's', "Buffer size"},
     {"k", OPT_K, 's', "Passphrase"},
     {"kfile", OPT_KFILE, '<', "Fead passphrase from file"},
     {"bufsize", OPT_BUFSIZE, 's', "Buffer size"},
     {"k", OPT_K, 's', "Passphrase"},
     {"kfile", OPT_KFILE, '<', "Fead passphrase from file"},
-    {"K", OPT_UPPER_K, '-', "Same as -iv"},
+    {"K", OPT_UPPER_K, 's', "Raw key, in hex"},
     {"S", OPT_UPPER_S, 's', "Salt, in hex"},
     {"iv", OPT_IV, 's', "IV in hex"},
     {"md", OPT_MD, 's', "Use specified digest to create key from passphrase"},
     {"S", OPT_UPPER_S, 's', "Salt, in hex"},
     {"iv", OPT_IV, 's', "IV in hex"},
     {"md", OPT_MD, 's', "Use specified digest to create key from passphrase"},
@@ -313,13 +313,8 @@ int enc_main(int argc, char **argv)
     if (verbose)
         BIO_printf(bio_err, "bufsize=%d\n", bsize);
 
     if (verbose)
         BIO_printf(bio_err, "bufsize=%d\n", bsize);
 
-    strbuf = OPENSSL_malloc(SIZE);
-    buff = OPENSSL_malloc(EVP_ENCODE_LENGTH(bsize));
-    if ((buff == NULL) || (strbuf == NULL)) {
-        BIO_printf(bio_err, "OPENSSL_malloc failure %ld\n",
-                   (long)EVP_ENCODE_LENGTH(bsize));
-        goto end;
-    }
+    strbuf = app_malloc(SIZE, "strbuf");
+    buff = app_malloc(EVP_ENCODE_LENGTH(bsize), "evp buffer");
 
     if (debug) {
         BIO_set_callback(in, BIO_debug_callback);
 
     if (debug) {
         BIO_set_callback(in, BIO_debug_callback);
@@ -464,9 +459,14 @@ int enc_main(int argc, char **argv)
             else
                 OPENSSL_cleanse(str, strlen(str));
         }
             else
                 OPENSSL_cleanse(str, strlen(str));
         }
-        if ((hiv != NULL) && !set_hex(hiv, iv, sizeof iv)) {
-            BIO_printf(bio_err, "invalid hex iv value\n");
-            goto end;
+        if (hiv != NULL) {
+            int siz = EVP_CIPHER_iv_length(cipher);
+            if (siz == 0) {
+                BIO_printf(bio_err, "warning: iv not use by this cipher\n");
+            } else if (!set_hex(hiv, iv, sizeof iv)) {
+                BIO_printf(bio_err, "invalid hex iv value\n");
+                goto end;
+            }
         }
         if ((hiv == NULL) && (str == NULL)
             && EVP_CIPHER_iv_length(cipher) != 0) {
         }
         if ((hiv == NULL) && (str == NULL)
             && EVP_CIPHER_iv_length(cipher) != 0) {
@@ -478,7 +478,7 @@ int enc_main(int argc, char **argv)
             BIO_printf(bio_err, "iv undefined\n");
             goto end;
         }
             BIO_printf(bio_err, "iv undefined\n");
             goto end;
         }
-        if ((hkey != NULL) && !set_hex(hkey, key, sizeof key)) {
+        if ((hkey != NULL) && !set_hex(hkey, key, EVP_CIPHER_key_length(cipher))) {
             BIO_printf(bio_err, "invalid hex key value\n");
             goto end;
         }
             BIO_printf(bio_err, "invalid hex key value\n");
             goto end;
         }
@@ -569,10 +569,8 @@ int enc_main(int argc, char **argv)
     }
  end:
     ERR_print_errors(bio_err);
     }
  end:
     ERR_print_errors(bio_err);
-    if (strbuf != NULL)
-        OPENSSL_free(strbuf);
-    if (buff != NULL)
-        OPENSSL_free(buff);
+    OPENSSL_free(strbuf);
+    OPENSSL_free(buff);
     BIO_free(in);
     BIO_free_all(out);
     BIO_free(benc);
     BIO_free(in);
     BIO_free_all(out);
     BIO_free(benc);
@@ -580,8 +578,7 @@ int enc_main(int argc, char **argv)
 #ifdef ZLIB
     BIO_free(bzl);
 #endif
 #ifdef ZLIB
     BIO_free(bzl);
 #endif
-    if (pass)
-        OPENSSL_free(pass);
+    OPENSSL_free(pass);
     return (ret);
 }
 
     return (ret);
 }