You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SymmetricKeyAlgorithmTag comments say AES (7/8/9) and Twofish (10) are "Reserved"; they're assigned, while Safer (5) is the reserved one #733
In SymmetricKeyAlgorithmTag, the comments on Aes128 = 7, Aes192 = 8, Aes256 = 9 and Twofish = 10 all start with "Reserved for". RFC 4880 and
RFC 9580 both assign these IDs, and bc-csharp implements all four. AES-128 is
the cipher RFC 9580 requires every implementation to support. On the other
hand, Safer = 5 is reserved by both RFCs, and its comment reads like a normal
supported algorithm.
The PublicKeyAlgorithmTag comments have the same pattern.
Safer=5,// Safer-SK128 (13 rounds) [Safer]Des=6,// Reserved for DES/SKAes128=7,// Reserved for AES with 128-bit keyAes192=8,// Reserved for AES with 192-bit keyAes256=9,// Reserved for AES with 256-bit keyTwofish=10,// Reserved for Twofish
Here are these lines next to the three versions of the registry:
ID
RFC 2440 §9.2 (1998)
RFC 4880 §9.2 / RFC 9580 §9.3
Comment in this file
5
SAFER-SK128 (13 rounds)
Reserved
"Safer-SK128 (13 rounds)"
6
Reserved for DES/SK
Reserved
"Reserved for DES/SK"
7
Reserved for AES with 128-bit key
AES with 128-bit key
"Reserved for AES with 128-bit key"
8
Reserved for AES with 192-bit key
AES with 192-bit key
"Reserved for AES with 192-bit key"
9
Reserved for AES with 256-bit key
AES with 256-bit key
"Reserved for AES with 256-bit key"
10
(not listed)
Twofish with 256-bit key
"Reserved for Twofish"
So the comments on 5-9 match RFC 2440 word for word. That makes sense: when
2440 was published, AES hadn't been finalised yet. RFC 4880 replaced that table,
moving 7-10 to assigned and 5 to reserved. The comments never caught up. Line 6
is fine under either RFC, so I've left it out.
The code has caught up. In crypto/src/openpgp/PgpUtilities.cs, 7/8/9 map to "AES" and 10 maps to "Twofish" in GetSymmetricCipherName. They have key
sizes in GetKeySize. AES-128 is also the default ECDH KDF cipher in PgpPublicKey, it's hard-coded in PgpSecretKey's S-expression import, and
7/8/9 get key-wrap OIDs in Rfc6637Utilities. Safer is the reverse. GetSymmetricCipherName returns "SAFER" for it, but there's no SAFER engine in the library and no SAFER entry
in CipherUtilities, so a message that uses tag 5 can't actually be decrypted.
Why it matters
These are // comments, not XML docs, so they don't reach IntelliSense or the
generated API docs. This is a source-readability fix, and I'd prioritise it
that way. Still, this file is where you check which symmetric algorithm IDs
the library supports, and right now it calls the mandatory-to-implement cipher
"reserved". Meanwhile the one entry in this block that is actually reserved,
and actually unsupported here, looks like an ordinary algorithm.
Suggested fix
- Safer = 5, // Safer-SK128 (13 rounds) [Safer]+ Safer = 5, // Reserved for SAFER-SK128 (13 rounds)
Des = 6, // Reserved for DES/SK
- Aes128 = 7, // Reserved for AES with 128-bit key- Aes192 = 8, // Reserved for AES with 192-bit key- Aes256 = 9, // Reserved for AES with 256-bit key- Twofish = 10, // Reserved for Twofish+ Aes128 = 7, // AES with 128-bit key+ Aes192 = 8, // AES with 192-bit key+ Aes256 = 9, // AES with 256-bit key+ Twofish = 10, // Twofish with 256-bit key
The Camellia lines just below (11-13) have a different problem: they say "AES".
That's tracked separately in #730, so this diff leaves them alone.
Upstream reference
bc-java had the same comments and corrected them in
bcgit/bc-java@69ab17af222 ("Document SymmetricKeyAlgorithmTags", 2024-05-07).
That commit turned the block into javadoc and linked RFC 4880:
--- a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyAlgorithmTags.java+++ b/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyAlgorithmTags.java- int SAFER = 5; // SAFER-SK128 (13 rounds) [SAFER]- int DES = 6; // Reserved for DES/SK- int AES_128 = 7; // Reserved for AES with 128-bit key- int AES_192 = 8; // Reserved for AES with 192-bit key- int AES_256 = 9; // Reserved for AES with 256-bit key- int TWOFISH = 10; // Reserved for Twofish
...
+ /**+ * Reserved for SAFER-SK128 (13 rounds).+ */+ int SAFER = 5;+ /**+ * Reserved for DES/SK.+ */+ int DES = 6;+ /**+ * AES with 128-bit key.+ */+ int AES_128 = 7;+ /**+ * AES with 192-bit key.+ */+ int AES_192 = 8;+ /**+ * AES with 256-bit key.+ */+ int AES_256 = 9;+ /**+ * Twofish with 256-bit key.+ */+ int TWOFISH = 10;
Current bc-java master has the same wording. A later commit only updated the
class-level @see links to point at RFC 9580:
Summary
In
SymmetricKeyAlgorithmTag, the comments onAes128 = 7,Aes192 = 8,Aes256 = 9andTwofish = 10all start with "Reserved for". RFC 4880 andRFC 9580 both assign these IDs, and bc-csharp implements all four. AES-128 is
the cipher RFC 9580 requires every implementation to support. On the other
hand,
Safer = 5is reserved by both RFCs, and its comment reads like a normalsupported algorithm.
The
PublicKeyAlgorithmTagcomments have the same pattern.Where
crypto/src/bcpg/SymmetricKeyAlgorithmTags.cs:11-16:Here are these lines next to the three versions of the registry:
So the comments on 5-9 match RFC 2440 word for word. That makes sense: when
2440 was published, AES hadn't been finalised yet. RFC 4880 replaced that table,
moving 7-10 to assigned and 5 to reserved. The comments never caught up. Line 6
is fine under either RFC, so I've left it out.
The code has caught up. In
crypto/src/openpgp/PgpUtilities.cs, 7/8/9 map to"AES"and 10 maps to"Twofish"inGetSymmetricCipherName. They have keysizes in
GetKeySize. AES-128 is also the default ECDH KDF cipher inPgpPublicKey, it's hard-coded inPgpSecretKey's S-expression import, and7/8/9 get key-wrap OIDs in
Rfc6637Utilities.Saferis the reverse.GetSymmetricCipherNamereturns"SAFER"for it, but there's no SAFER engine in the library and no SAFER entryin
CipherUtilities, so a message that uses tag 5 can't actually be decrypted.Why it matters
These are
//comments, not XML docs, so they don't reach IntelliSense or thegenerated API docs. This is a source-readability fix, and I'd prioritise it
that way. Still, this file is where you check which symmetric algorithm IDs
the library supports, and right now it calls the mandatory-to-implement cipher
"reserved". Meanwhile the one entry in this block that is actually reserved,
and actually unsupported here, looks like an ordinary algorithm.
Suggested fix
The Camellia lines just below (11-13) have a different problem: they say "AES".
That's tracked separately in #730, so this diff leaves them alone.
Upstream reference
bc-java had the same comments and corrected them in
bcgit/bc-java@
69ab17af222("Document SymmetricKeyAlgorithmTags", 2024-05-07).That commit turned the block into javadoc and linked RFC 4880:
Current bc-java master has the same wording. A later commit only updated the
class-level
@seelinks to point at RFC 9580: