summaryrefslogtreecommitdiffstats
path: root/g10/passphrase.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-01-26 23:10:38 +0100
committerWerner Koch <wk@gnupg.org>2019-01-26 23:10:38 +0100
commitec13b1c562e34c0fcbc7b848ab6dc187b79cf2c1 (patch)
tree33ad3af6094e2a64625772e0f60104e48e8b917e /g10/passphrase.c
parentscd: Improve app selection for app "undefined". (diff)
downloadgnupg2-ec13b1c562e34c0fcbc7b848ab6dc187b79cf2c1.tar.xz
gnupg2-ec13b1c562e34c0fcbc7b848ab6dc187b79cf2c1.zip
gpg: Move S2K encoding function to a shared file.
* g10/passphrase.c (encode_s2k_iterations): Move function to ... * common/openpgp-s2k.c: new file. Remove default intialization code. * common/openpgpdefs.h (S2K_DECODE_COUNT): New to keep only one copy. * g10/call-agent.c (agent_get_s2k_count): Change to return the count and print an error. * agent/protect.c: Include openpgpdefs.h * g10/card-util.c (gen_kdf_data): Adjust for changes * g10/gpgcompose.c: Include call-agent.h. (sk_esk): Adjust for changes. * g10/passphrase (passphrase_to_dek): Adjust for changes. * g10/main.h (S2K_DECODE_COUNT): Remove macro. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'g10/passphrase.c')
-rw-r--r--g10/passphrase.c54
1 files changed, 2 insertions, 52 deletions
diff --git a/g10/passphrase.c b/g10/passphrase.c
index 10574ec6a..99a2c0dc2 100644
--- a/g10/passphrase.c
+++ b/g10/passphrase.c
@@ -48,57 +48,6 @@ static char *next_pw = NULL;
static char *last_pw = NULL;
-
-/* Pack an s2k iteration count into the form specified in 2440. If
- we're in between valid values, round up. With value 0 return the
- old default. */
-unsigned char
-encode_s2k_iterations (int iterations)
-{
- gpg_error_t err;
- unsigned char c=0;
- unsigned char result;
- unsigned int count;
-
- if (!iterations)
- {
- unsigned long mycnt;
-
- /* Ask the gpg-agent for a useful iteration count. */
- err = agent_get_s2k_count (&mycnt);
- if (err || mycnt < 65536)
- {
- /* Don't print an error if an older agent is used. */
- if (err && gpg_err_code (err) != GPG_ERR_ASS_PARAMETER)
- log_error (_("problem with the agent: %s\n"), gpg_strerror (err));
- /* Default to 65536 which we used up to 2.0.13. */
- return 96;
- }
- else if (mycnt >= 65011712)
- return 255; /* Largest possible value. */
- else
- return encode_s2k_iterations ((int)mycnt);
- }
-
- if (iterations <= 1024)
- return 0; /* Command line arg compatibility. */
-
- if (iterations >= 65011712)
- return 255;
-
- /* Need count to be in the range 16-31 */
- for (count=iterations>>6; count>=32; count>>=1)
- c++;
-
- result = (c<<4)|(count-16);
-
- if (S2K_DECODE_COUNT(result) < iterations)
- result++;
-
- return result;
-}
-
-
int
have_static_passphrase()
{
@@ -106,6 +55,7 @@ have_static_passphrase()
&& (opt.batch || opt.pinentry_mode == PINENTRY_MODE_LOOPBACK));
}
+
/* Return a static passphrase. The returned value is only valid as
long as no other passphrase related function is called. NULL may
be returned if no passphrase has been set; better use
@@ -342,7 +292,7 @@ passphrase_to_dek (int cipher_algo, STRING2KEY *s2k,
call out to gpg-agent and that should not be done during
option processing in main(). */
if (!opt.s2k_count)
- opt.s2k_count = encode_s2k_iterations (0);
+ opt.s2k_count = encode_s2k_iterations (agent_get_s2k_count ());
s2k->count = opt.s2k_count;
}
}