aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2013-01-07 14:37:50 +0000
committerWerner Koch <[email protected]>2013-01-07 14:37:50 +0000
commit7d00e52bd58d9e40c18dcc0122b2c236ef3318f5 (patch)
treeb734c50d95b0789475a222552cdf28791ddd326e
parentgpg: Add signature cache support to the keybox. (diff)
downloadgnupg-7d00e52bd58d9e40c18dcc0122b2c236ef3318f5.tar.gz
gnupg-7d00e52bd58d9e40c18dcc0122b2c236ef3318f5.zip
gpg: Allow generation of more than 4096 keys in one run.
* g10/getkey.c (cache_public_key): Make room in the cache if needed. -- To create the selfsigs, the key generation code makes use of the key cache. However, after 4096 the cache is filled up and then disabled. Thus generating more than 4096 keys in one run was not possible. We now clear the first half the inserted keys every time the cache gets full.
-rw-r--r--g10/getkey.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/g10/getkey.c b/g10/getkey.c
index 002a2be2b..0030f42c5 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -128,7 +128,7 @@ void
cache_public_key (PKT_public_key * pk)
{
#if MAX_PK_CACHE_ENTRIES
- pk_cache_entry_t ce;
+ pk_cache_entry_t ce, ce2;
u32 keyid[2];
if (pk_cache_disabled)
@@ -158,11 +158,25 @@ cache_public_key (PKT_public_key * pk)
if (pk_cache_entries >= MAX_PK_CACHE_ENTRIES)
{
- /* fixme: Use another algorithm to free some cache slots. */
- pk_cache_disabled = 1;
- if (opt.verbose > 1)
- log_info (_("too many entries in pk cache - disabled\n"));
- return;
+ int n;
+
+ /* Remove the last 50% of the entries. */
+ for (ce = pk_cache, n = 0; ce && n < pk_cache_entries/2; n++)
+ ce = ce->next;
+ if (ce != pk_cache && ce->next)
+ {
+ ce2 = ce->next;
+ ce->next = NULL;
+ ce = ce2;
+ for (; ce; ce = ce2)
+ {
+ ce2 = ce->next;
+ free_public_key (ce->pk);
+ xfree (ce);
+ pk_cache_entries--;
+ }
+ }
+ assert (pk_cache_entries < MAX_PK_CACHE_ENTRIES);
}
pk_cache_entries++;
ce = xmalloc (sizeof *ce);