Mailing List Archive

Changing the encryption algorithm used for PGP/GPG private key
I've read various tutorials and posts regarding changing the algorithm used to encrypt my private PGP keys. However, nothing I have tried seems to work. I am using gpg4win:

> gpg (GnuPG) 2.3.4
> libgcrypt 1.9.4
> Copyright (C) 2021 g10 Code GmbH
> License GNU GPL-3.0-or-later <https://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.

> Home: C:\Users\[REDACTED]\AppData\Roaming\gnupg
> Supported algorithms:
> Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
> Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
> CAMELLIA128, CAMELLIA192, CAMELLIA256
> AEAD: EAX, OCB
> Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
> Compression: Uncompressed, ZIP, ZLIB, BZIP2

My gpg.conf file located at C:\Users\[REDACTED]\AppData\Roaming\gnupg\gpg.conf is

> personal-digest-preferences SHA512
> cert-digest-algo SHA512
> default-preference-list SHA512 SHA384 SHA256 SHA224 SHA1 AES256 AES192 AES ZLIB BZIP2 ZIP Uncompressed OCB EAX ks-modify
> personal-cipher-preferences AES256 AES192 AES
> s2k-mode 3
> s2k-cipher-algo AES256
> s2k-digest-algo SHA512
> s2k-count 65011712
> cipher-algo AES256

I then change the password via

> gpg -vv --expert --edit-key A7AA75FD6A11F453DE501E38D3E3B91787699C75
> passwd

Export the key

> gpg -vv --cipher-algo AES256 --export-secret-keys A7AA75FD6A11F453DE501E38D3E3B91787699C75 -a > key.txt

and then inspect it

> gpg --list-packets key.txt

which then outputs

> :secret key packet:
> ...
> iter+salt S2K, algo: 7, SHA1 protection, hash: 2,
> ...

This would seem to suggest that the key is still encrypted using AES128 (algo 7) and a SHA1 hash. Further, inspecting the contents of $GNUPGHOME/private-keys-v1.d/ shows files with the following lines

> ...
> (protected openpgp-s2k3-ocb-aes ((sha1 ...
> ...

What am I missing? Any help or advice would be very much appreciated.

Yours,
Dan

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users
RE: Changing the encryption algorithm used for PGP/GPG private key [ In reply to ]
Just to follow up that this isn't a gpgwin problem. I have a Debian installation and generated a test key using GnuPG and the same gpg.conf file. Here is the output

> gpg --list-packets test.key
> # off=0 ctb=95 tag=5 hlen=3 plen=1862
> :secret key packet:
> version 4, algo 1, created 1645171018, expires 0
> pkey[0]: [4096 bits]
> pkey[1]: [17 bits]
> iter+salt S2K, algo: 7, SHA1 protection, hash: 2, salt: 618B50CF0281AD75
> protect count: 23068672 (230)
> protect IV: 74 02 5e e0 92 12 8a 5e 53 aa 17 4a 40 e0 7e 8d
> skey[2]: [v4 protected]
> keyid: 45A023416F46CE6E

I have verified that gpg reads the gpg.conf file and understands it.

Any help would be very much appreciated.

Yours,
Dan



_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users
Re: Changing the encryption algorithm used for PGP/GPG private key [ In reply to ]
On Montag, 14. Februar 2022 10:36:25 CET Daniel Colquitt via Gnupg-users
wrote:
> I've read various tutorials and posts regarding changing the algorithm used
to encrypt my private PGP keys. However, nothing I have tried seems to work. I
am using gpg4win:
[...]
> My gpg.conf file located at
> C:\Users\[REDACTED]\AppData\Roaming\gnupg\gpg.conf is
> > personal-digest-preferences SHA512
> > cert-digest-algo SHA512
> > default-preference-list SHA512 SHA384 SHA256 SHA224 SHA1 AES256 AES192 AES
> > ZLIB BZIP2 ZIP Uncompressed OCB EAX ks-modify personal-cipher-preferences
> > AES256 AES192 AES
> > s2k-mode 3
> > s2k-cipher-algo AES256
> > s2k-digest-algo SHA512
> > s2k-count 65011712
> > cipher-algo AES256

As far as I can tell `man gpg` does not claim that any of these settings
influence the encryption of secret keys.

> > :secret key packet:
> > ...
> > iter+salt S2K, algo: 7, SHA1 protection, hash: 2,
> > ...
>
> This would seem to suggest that the key is still encrypted using AES128
> (algo 7) and a SHA1 hash.

Not sure about the encryption algo, but the usage of SHA-1 seems to be
mandatory (unless one wants to use a completely insecure two-octet checksum):
https://datatracker.ietf.org/doc/html/rfc4880#section-5.5.3

Regards,
Ingo
RE: Changing the encryption algorithm used for PGP/GPG private key [ In reply to ]
Thanks for responding, Ingo.

> As far as I can tell `man gpg` does not claim that any of these settings
> influence the encryption of secret keys.

According to the
manual<https://gnupg.org/documentation/manuals/gnupg/OpenPGP-Options.html#in
dex-s2k_002dcipher_002dalgo>, the --s2k-* flags control the algorithm used
for symmetric encryption if the --personal-cipher-preferences flag isn't
set.

Is the suggestion the gpg does not respect these flags when applying
symmetric encryption to keys?

Dan

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users
RE: Changing the encryption algorithm used for PGP/GPG private key [ In reply to ]
On 2/18/2022 at 3:12 AM, "Daniel Colquitt via Gnupg-users" wrote:Just
to follow up that this isn't a gpgwin problem. I have a Debian
installation and generated a test key using GnuPG and the same
gpg.conf file

=====

Try this:
In gpg.conf file add the option of
--expert
and in personal preferences, list only AES 256,
Not the other strengths.
Keep all of the s2k options you listed, and try generating a new key
again
Vedaal
Re: Changing the encryption algorithm used for PGP/GPG private key [ In reply to ]
Hi Vedaal,

> Try this:
> In gpg.conf file add the option of
> --expert
> and in personal preferences, list only AES 256,
> Not the other strengths.
> Keep all of the s2k options you listed, and try generating a new key again
> Vedaal

Many thanks for the suggestion, but I’m afraid that this still does not work for me.

It seems the gnupg ignores all s2k and cipher preference flags when encrypting private keys. If this is indeed the intended behaviour (although I have no idea why it should be), perhaps it would a good idea to add a warning to the man pages?

Dan