[openssl] master update
tomas at openssl.org
tomas at openssl.org
Fri Jan 21 14:44:58 UTC 2022
The branch master has been updated
via e1cd94f2dca4056ce042c62b89c468dffc088033 (commit)
from 8c2e588bcf0de61880ec8a956ef57ad6b8a50163 (commit)
- Log -----------------------------------------------------------------
commit e1cd94f2dca4056ce042c62b89c468dffc088033
Author: Philip Prindeville <philipp at redfish-solutions.com>
Date: Tue Dec 21 22:00:38 2021 -0700
Standardize progress callback for dhparam, dsaparam, etc.
Signed-off-by: Philip Prindeville <philipp at redfish-solutions.com>
Reviewed-by: Matt Caswell <matt at openssl.org>
Reviewed-by: Tomas Mraz <tomas at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17359)
-----------------------------------------------------------------------
Summary of changes:
apps/dhparam.c | 14 +-------------
apps/dsaparam.c | 23 +----------------------
apps/genpkey.c | 29 ++---------------------------
apps/include/apps.h | 3 +++
apps/lib/s_cb.c | 13 +++++++++++++
apps/req.c | 21 +--------------------
6 files changed, 21 insertions(+), 82 deletions(-)
diff --git a/apps/dhparam.c b/apps/dhparam.c
index 9fe0eedfc2..4a67a52d4a 100644
--- a/apps/dhparam.c
+++ b/apps/dhparam.c
@@ -31,7 +31,6 @@
#define DEFBITS 2048
static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh);
-static int gendh_cb(EVP_PKEY_CTX *ctx);
typedef enum OPTION_choice {
OPT_COMMON,
@@ -188,7 +187,7 @@ int dhparam_main(int argc, char **argv)
alg);
goto end;
}
- EVP_PKEY_CTX_set_cb(ctx, gendh_cb);
+ EVP_PKEY_CTX_set_cb(ctx, progress_cb);
EVP_PKEY_CTX_set_app_data(ctx, bio_err);
BIO_printf(bio_err,
"Generating %s parameters, %d bit long %sprime\n",
@@ -399,14 +398,3 @@ static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh)
return pkey;
}
-static int gendh_cb(EVP_PKEY_CTX *ctx)
-{
- int p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
- BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
- static const char symbols[] = ".+*\n";
- char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?';
-
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index 08f912340a..708cb9a648 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include "apps.h"
#include <time.h>
#include <string.h>
#include "apps.h"
@@ -25,8 +24,6 @@
static int verbose = 0;
-static int gendsa_cb(EVP_PKEY_CTX *ctx);
-
typedef enum OPTION_choice {
OPT_COMMON,
OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_TEXT,
@@ -160,9 +157,9 @@ int dsaparam_main(int argc, char **argv)
" Your key size is %d! Larger key size may behave not as expected.\n",
OPENSSL_DSA_MAX_MODULUS_BITS, numbits);
- EVP_PKEY_CTX_set_cb(ctx, gendsa_cb);
EVP_PKEY_CTX_set_app_data(ctx, bio_err);
if (verbose) {
+ EVP_PKEY_CTX_set_cb(ctx, progress_cb);
BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n",
num);
BIO_printf(bio_err, "This could take some time\n");
@@ -235,21 +232,3 @@ int dsaparam_main(int argc, char **argv)
return ret;
}
-static int gendsa_cb(EVP_PKEY_CTX *ctx)
-{
- static const char symbols[] = ".+*\n";
- int p;
- char c;
- BIO *b;
-
- if (!verbose)
- return 1;
-
- b = EVP_PKEY_CTX_get_app_data(ctx);
- p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
- c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?';
-
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}
diff --git a/apps/genpkey.c b/apps/genpkey.c
index f4c8f92c34..0f2a97137a 100644
--- a/apps/genpkey.c
+++ b/apps/genpkey.c
@@ -19,8 +19,6 @@ static int quiet;
static int init_keygen_file(EVP_PKEY_CTX **pctx, const char *file, ENGINE *e,
OSSL_LIB_CTX *libctx, const char *propq);
-static int genpkey_cb(EVP_PKEY_CTX *ctx);
-
typedef enum OPTION_choice {
OPT_COMMON,
OPT_ENGINE, OPT_OUTFORM, OPT_OUT, OPT_PASS, OPT_PARAMFILE,
@@ -181,7 +179,8 @@ int genpkey_main(int argc, char **argv)
if (out == NULL)
goto end;
- EVP_PKEY_CTX_set_cb(ctx, genpkey_cb);
+ if (!quiet)
+ EVP_PKEY_CTX_set_cb(ctx, progress_cb);
EVP_PKEY_CTX_set_app_data(ctx, bio_err);
pkey = do_param ? app_paramgen(ctx, algname)
@@ -319,27 +318,3 @@ int init_gen_str(EVP_PKEY_CTX **pctx,
}
-static int genpkey_cb(EVP_PKEY_CTX *ctx)
-{
- char c = '*';
- BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
-
- if (quiet)
- return 1;
-
- switch (EVP_PKEY_CTX_get_keygen_info(ctx, 0)) {
- case 0:
- c = '.';
- break;
- case 1:
- c = '+';
- break;
- case 3:
- c = '\n';
- break;
- }
-
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}
diff --git a/apps/include/apps.h b/apps/include/apps.h
index f06d01cd37..b6dbe74fa9 100644
--- a/apps/include/apps.h
+++ b/apps/include/apps.h
@@ -94,6 +94,9 @@ typedef struct args_st {
/* We need both wrap and the "real" function because libcrypto uses both. */
int wrap_password_callback(char *buf, int bufsiz, int verify, void *cb_data);
+/* progress callback for dsaparam, dhparam, req, genpkey, etc. */
+int progress_cb(EVP_PKEY_CTX *ctx);
+
int chopup_args(ARGS *arg, char *buf);
void dump_cert_text(BIO *out, X509 *x);
void print_name(BIO *out, const char *title, const X509_NAME *nm);
diff --git a/apps/lib/s_cb.c b/apps/lib/s_cb.c
index 77ddbc9d7b..d6d49d666c 100644
--- a/apps/lib/s_cb.c
+++ b/apps/lib/s_cb.c
@@ -1574,3 +1574,16 @@ void ssl_print_secure_renegotiation_notes(BIO *bio, SSL *s)
BIO_printf(bio, "This TLS version forbids renegotiation.\n");
}
}
+
+int progress_cb(EVP_PKEY_CTX *ctx)
+{
+ BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
+ int p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
+ static const char symbols[] = ".+*\n";
+ char c = (p >= 0 && (size_t)p <= sizeof(symbols) - 1) ? symbols[p] : '?';
+
+ BIO_write(b, &c, 1);
+ (void)BIO_flush(b);
+ return 1;
+}
+
diff --git a/apps/req.c b/apps/req.c
index eaff69faa4..45de46d393 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -62,7 +62,6 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def,
static int add_DN_object(X509_NAME *n, char *text, const char *def,
char *value, int nid, int n_min, int n_max,
unsigned long chtype, int mval);
-static int genpkey_cb(EVP_PKEY_CTX *ctx);
static int build_data(char *text, const char *def, char *value,
int n_min, int n_max, char *buf, const int buf_size,
const char *desc1, const char *desc2);
@@ -663,7 +662,7 @@ int req_main(int argc, char **argv)
}
}
- EVP_PKEY_CTX_set_cb(genctx, genpkey_cb);
+ EVP_PKEY_CTX_set_cb(genctx, progress_cb);
EVP_PKEY_CTX_set_app_data(genctx, bio_err);
pkey = app_keygen(genctx, keyalgstr, newkey_len, verbose);
@@ -1649,21 +1648,3 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
return gctx;
}
-static int genpkey_cb(EVP_PKEY_CTX *ctx)
-{
- char c = '*';
- BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
- int p;
- p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
- if (p == 0)
- c = '.';
- if (p == 1)
- c = '+';
- if (p == 2)
- c = '*';
- if (p == 3)
- c = '\n';
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}
More information about the openssl-commits
mailing list