diff options
Diffstat (limited to 'agent')
-rw-r--r-- | agent/agent.h | 2 | ||||
-rw-r--r-- | agent/command.c | 36 | ||||
-rw-r--r-- | agent/protect.c | 29 |
3 files changed, 51 insertions, 16 deletions
diff --git a/agent/agent.h b/agent/agent.h index 47cc34562..687635dc7 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -486,8 +486,10 @@ gpg_error_t agent_protect_and_store (ctrl_t ctrl, gcry_sexp_t s_skey, char **passphrase_addr); /*-- protect.c --*/ +unsigned long get_calibrated_s2k_count (void); unsigned long get_standard_s2k_count (void); unsigned char get_standard_s2k_count_rfc4880 (void); +unsigned long get_standard_s2k_time (void); int agent_protect (const unsigned char *plainkey, const char *passphrase, unsigned char **result, size_t *resultlen, unsigned long s2k_count, int use_ocb); diff --git a/agent/command.c b/agent/command.c index 3b249b1bd..7c7e8a4bc 100644 --- a/agent/command.c +++ b/agent/command.c @@ -2843,20 +2843,22 @@ static const char hlp_getinfo[] = "Multipurpose function to return a variety of information.\n" "Supported values for WHAT are:\n" "\n" - " version - Return the version of the program.\n" - " pid - Return the process id of the server.\n" - " socket_name - Return the name of the socket.\n" + " version - Return the version of the program.\n" + " pid - Return the process id of the server.\n" + " socket_name - Return the name of the socket.\n" " ssh_socket_name - Return the name of the ssh socket.\n" - " scd_running - Return OK if the SCdaemon is already running.\n" - " s2k_count - Return the calibrated S2K count.\n" + " scd_running - Return OK if the SCdaemon is already running.\n" + " s2k_time - Return the time in milliseconds required for S2K.\n" + " s2k_count - Return the standard S2K count.\n" + " s2k_count_cal - Return the calibrated S2K count.\n" " std_env_names - List the names of the standard environment.\n" " std_session_env - List the standard session environment.\n" " std_startup_env - List the standard startup environment.\n" - " cmd_has_option\n" - " - Returns OK if the command CMD implements the option OPT.\n" - " connections - Return number of active connections.\n" - " jent_active - Returns OK if Libgcrypt's JENT is active.\n" - " restricted - Returns OK if the connection is in restricted mode.\n"; + " connections - Return number of active connections.\n" + " jent_active - Returns OK if Libgcrypt's JENT is active.\n" + " restricted - Returns OK if the connection is in restricted mode.\n" + " cmd_has_option CMD OPT\n" + " - Returns OK if command CMD has option OPT.\n"; static gpg_error_t cmd_getinfo (assuan_context_t ctx, char *line) { @@ -3014,6 +3016,20 @@ cmd_getinfo (assuan_context_t ctx, char *line) rc = gpg_error (GPG_ERR_FALSE); #endif } + else if (!strcmp (line, "s2k_count_cal")) + { + char numbuf[50]; + + snprintf (numbuf, sizeof numbuf, "%lu", get_calibrated_s2k_count ()); + rc = assuan_send_data (ctx, numbuf, strlen (numbuf)); + } + else if (!strcmp (line, "s2k_time")) + { + char numbuf[50]; + + snprintf (numbuf, sizeof numbuf, "%lu", get_standard_s2k_time ()); + rc = assuan_send_data (ctx, numbuf, strlen (numbuf)); + } else rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT"); return rc; diff --git a/agent/protect.c b/agent/protect.c index 9b4ba9143..fe44f18c3 100644 --- a/agent/protect.c +++ b/agent/protect.c @@ -191,16 +191,13 @@ calibrate_s2k_count (void) } - -/* Return the standard S2K count. */ +/* Return the calibrated S2K count. This is only public for the use + * of the Assuan getinfo s2k_count_cal command. */ unsigned long -get_standard_s2k_count (void) +get_calibrated_s2k_count (void) { static unsigned long count; - if (opt.s2k_count) - return opt.s2k_count < 65536 ? 65536 : opt.s2k_count; - if (!count) count = calibrate_s2k_count (); @@ -209,6 +206,26 @@ get_standard_s2k_count (void) } +/* Return the standard S2K count. */ +unsigned long +get_standard_s2k_count (void) +{ + if (opt.s2k_count) + return opt.s2k_count < 65536 ? 65536 : opt.s2k_count; + + return get_calibrated_s2k_count (); +} + + +/* Return the milliseconds required for the standard S2K + * operation. */ +unsigned long +get_standard_s2k_time (void) +{ + return calibrate_s2k_count_one (get_standard_s2k_count ()); +} + + /* Same as get_standard_s2k_count but return the count in the encoding as described by rfc4880. */ unsigned char |