summaryrefslogtreecommitdiffstats
path: root/agent/protect.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2018-12-11 18:12:51 +0100
committerWerner Koch <wk@gnupg.org>2018-12-11 18:12:51 +0100
commitcbcc8c19541fe8407f3b6588fce1535c64cf6b25 (patch)
treecc02d83240034f6089e321f16b2a6d821be7bbe6 /agent/protect.c
parentdirmngr: Retry another server from the pool on 502, 503, 504. (diff)
downloadgnupg2-cbcc8c19541fe8407f3b6588fce1535c64cf6b25.tar.xz
gnupg2-cbcc8c19541fe8407f3b6588fce1535c64cf6b25.zip
agent: Make the S2K calibration time runtime configurabe.
* agent/protect.c (s2k_calibration_time): New file global var. (calibrate_s2k_count): Use it here. (get_calibrated_s2k_count): Replace function static var by ... (s2k_calibrated_count): new file global var. (set_s2k_calibration_time): New function. * agent/gpg-agent.c (oS2KCalibration): New const. (opts): New option --s2k-calibration. (parse_rereadable_options): Parse that option. -- Note that using an unrelistic high value (like 60000) takes quite some time for calibration. GnuPG-bug-id: 3399 Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'agent/protect.c')
-rw-r--r--agent/protect.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/agent/protect.c b/agent/protect.c
index c7bd30b68..f95527f78 100644
--- a/agent/protect.c
+++ b/agent/protect.c
@@ -71,6 +71,13 @@ static const struct {
};
+/* The number of milliseconds we use in the S2K function and the
+ * calibrated count value. A count value of zero indicates that the
+ * calibration has not yet been done or needs to be done again. */
+static unsigned int s2k_calibration_time = AGENT_S2K_CALIBRATION;
+static unsigned long s2k_calibrated_count;
+
+
/* A helper object for time measurement. */
struct calibrate_time_s
{
@@ -175,11 +182,11 @@ calibrate_s2k_count (void)
ms = calibrate_s2k_count_one (count);
if (opt.verbose > 1)
log_info ("S2K calibration: %lu -> %lums\n", count, ms);
- if (ms > AGENT_S2K_CALIBRATION)
+ if (ms > s2k_calibration_time)
break;
}
- count = (unsigned long)(((double)count / ms) * AGENT_S2K_CALIBRATION);
+ count = (unsigned long)(((double)count / ms) * s2k_calibration_time);
count /= 1024;
count *= 1024;
if (count < 65536)
@@ -195,18 +202,30 @@ calibrate_s2k_count (void)
}
+/* Set the calibration time. This may be called early at startup or
+ * at any time. Thus it should one set variables. */
+void
+set_s2k_calibration_time (unsigned int milliseconds)
+{
+ if (!milliseconds)
+ milliseconds = AGENT_S2K_CALIBRATION;
+ else if (milliseconds > 60 * 1000)
+ milliseconds = 60 * 1000; /* Cap at 60 seconds. */
+ s2k_calibration_time = milliseconds;
+ s2k_calibrated_count = 0; /* Force re-calibration. */
+}
+
+
/* Return the calibrated S2K count. This is only public for the use
* of the Assuan getinfo s2k_count_cal command. */
unsigned long
get_calibrated_s2k_count (void)
{
- static unsigned long count;
-
- if (!count)
- count = calibrate_s2k_count ();
+ if (!s2k_calibrated_count)
+ s2k_calibrated_count = calibrate_s2k_count ();
/* Enforce a lower limit. */
- return count < 65536 ? 65536 : count;
+ return s2k_calibrated_count < 65536 ? 65536 : s2k_calibrated_count;
}