RFC 6637
Elliptic Curve Cryptography (ECC) in OpenPGP
RFC 6637: Elliptic Curve Cryptography (ECC) in OpenPGP π
okay bestie, this is the one where OpenPGP gets elliptic curves π¦ It's an IETF doc, so the quick facts are:
- RFC number: 6637
- Title: Elliptic Curve Cryptography (ECC) in OpenPGP
- Author: A. Jivsov, Symantec Corporation
- Category: Standards Track
- Date: June 2012
- ISSN: 2070-1721
- Obsoletes / Updates: none listed in the title block β¨
Abstract πΈ
okay so this doc adds an Elliptic Curve Cryptography extension to the OpenPGP public key format π It also picks out three elliptic curves that a lot of other standards already support, including ones published by the US National Institute of Standards and Technology. Then it lays out the rules so compliant OpenPGP implementations that use this extension and these curves can actually talk to each other. no cap, it's interoperability iconic π
Status of This Memo π
this is an Internet Standards Track document π
it's a product of the Internet Engineering Task Force (IETF) π It represents the consensus of the IETF community, got public review, and was approved for publication by the Internet Engineering Steering Group (IESG). If you want more on Internet Standards, check Section 2 of RFC 5741.
for the current status, any errata, and how to send feedback, go to http://www.rfc-editor.org/info/rfc6637 π
Copyright Notice Β©οΈ
Copyright (c) 2012 IETF Trust and the persons identified as the document authors. All rights reserved π«Ά
this doc is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as they stand on the publication date. Please actually read these, they're your rights and restrictions for this doc π Code Components pulled out of this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they come without warranty, as the Simplified BSD License describes π
Table of Contents ποΈ
1. Introduction ....................................................3
2. Conventions used in This Document ...............................3
3. Elliptic Curve Cryptography .....................................3
4. Supported ECC Curves ............................................3
5. Supported Public Key Algorithms .................................4
6. Conversion Primitives ...........................................4
7. Key Derivation Function .........................................5
8. EC DH Algorithm (ECDH) ..........................................5
9. Encoding of Public and Private Keys .............................8
10. Message Encoding with Public Keys ..............................9
11. ECC Curve OID .................................................10
12. Compatibility Profiles ........................................10
12.1. OpenPGP ECC Profile ......................................10
12.2. Suite-B Profile ..........................................11
12.2.1. Security Strength at 192 Bits .....................11
12.2.2. Security Strength at 128 Bits .....................11
13. Security Considerations .......................................12
14. IANA Considerations ...........................................14
15. References ....................................................14
15.1. Normative References .....................................14
15.2. Informative References ...................................15
16. Contributors ..................................................15
17. Acknowledgment ................................................15
1. Introduction πΈ
so OpenPGP [RFC4880] already does RSA and DSA (Digital Signature Algorithm) public keys π This doc adds the extension that lets it support public keys based on Elliptic Curve Cryptography (ECC) π¦
2. Conventions Used in This Document π
the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be read as described in [RFC2119] π«Ά Any implementation that follows the format and methods in this doc is called a compliant application β¨ Compliant applications are a subset of the wider set of OpenPGP applications described in [RFC4880]. And any [RFC2119] keyword in this document applies to compliant applications only π
3. Elliptic Curve Cryptography π¦
this doc sets the minimum set of ECC public key parameters and cryptographic methods that will likely work on the widest range of platforms and apps, so everyone can interoperate π It also gives applications a more efficient way to balance their overall security level against any AES algorithm in [RFC4880], compared with just making RSA keys bigger πͺ And it defines a path to expand ECC support later on π§
the National Security Agency (NSA) of the United States specifies ECC for its [SuiteB] set of algorithms π This doc includes algorithms that Suite B requires but that aren't in [RFC4880] β¨
[KOBLITZ] gives a thorough intro to ECC if you want the deep dive π
4. Supported ECC Curves π
this doc references three named prime field curves, defined in [FIPS-186-3] as "Curve P-256", "Curve P-384", and "Curve P-521" π
the named curves are referenced as a sequence of bytes in this doc, called the curve OID throughout π§Ύ Section 11 explains in detail how that byte sequence is formed π
5. Supported Public Key Algorithms π
the supported public key algorithms are the Elliptic Curve Digital Signature Algorithm (ECDSA) [FIPS-186-3] and the Elliptic Curve Diffie-Hellman (ECDH) πΈ A compatible spec of ECDSA is given in [RFC6090] as "KT-I Signatures" and in [SEC1]. ECDH is defined in Section 8 of this doc π
these public key algorithm IDs get added to expand Section 9.1 of [RFC4880], "Public-Key Algorithms" π§Ύ
ID Description of Algorithm
-- --------------------------
18 ECDH public key algorithm
19 ECDSA public key algorithm
Compliant applications MUST support ECDSA and ECDH. no excuses, bestie π
6. Conversion Primitives π§©
this doc only defines the uncompressed point format π«§ The point gets encoded in the Multiprecision Integer (MPI) format [RFC4880]. The content of the MPI is:
B = 04 || x || y
where x and y are the coordinates of the point P = (x, y). Each one is encoded in big-endian format and zero-padded to the adjusted underlying field size π The adjusted underlying field size is the underlying field size rounded up to the nearest 8-bit boundary. the math is giving precision β¨
so the exact size of the MPI payload is 515 bits for "Curve P-256", 771 bits for "Curve P-384", and 1059 bits for "Curve P-521" π
the zero point (also called the point at infinity) can show up as a result of arithmetic on elliptic curve points, but it SHALL NOT appear in data structures defined in this document. don't let it sneak in π
this encoding is compatible with the definition given in [SEC1] π«Ά
if other conversion methods get defined in the future, a compliant application MUST NOT use a new format when in doubt that any recipient can support it π‘οΈ Look, the public key and the per-recipient ECDH data structure (defined in Sections 9 and 10) both contain an encoded point field. But the format change to the field in Section 10 only affects one given recipient of one given message π§
7. Key Derivation Function π
a key derivation function (KDF) is necessary to implement the EC encryption π The Concatenation Key Derivation Function (Approved Alternative 1) [NIST-SP800-56A] with a KDF hash function of SHA2-256 [FIPS-180-3] or stronger is REQUIRED πͺ Check Section 12 for the details on choosing the hash function.
for convenience, the synopsis of the encoding method is below, with significant simplifications because this doc restricts the choice of hash functions. BUT [NIST-SP800-56A] is the normative source of the definition, so that's the one to trust π
// Implements KDF( X, oBits, Param );
// Input: point X = (x,y)
// oBits - the desired size of output
// hBits - the size of output of hash function Hash
// Param - octets representing the parameters
// Assumes that oBits <= hBits
// Convert the point X to the octet string, see section 6:
// ZB' = 04 || x || y
// and extract the x portion from ZB'
ZB = x;
MB = Hash ( 00 || 00 || 00 || 01 || ZB || Param );
return oBits leftmost bits of MB.
note that ZB in the KDF description above is the compact representation of X, defined in Section 4.2 of [RFC6090] π¦
8. EC DH Algorithm (ECDH) β¨
okay so ECDH is basically a combo platter π. You get an ECC Diffie-Hellman method to set up a shared secret, a key derivation method that turns that secret into a derived key, and a key wrapping method that uses the derived key to protect a session key, which then encrypts your message. Three steps, one iconic vibe π
The One-Pass Diffie-Hellman method C(1, 1, ECC CDH) [NIST-SP800-56A] MUST be implemented, with a few restrictions. The ECC CDH primitive gets modified to always assume the cofactor is 1, the KDF from Section 7 is used, and the KDF parameters below are used. No skipping π ββοΈ
The KDF parameters are a concatenation of 5 fields, some variable-length and some fixed-length, and they're built to match the definition of the OtherInfo bitstring [NIST-SP800-56A] π§
- a variable-length field containing a curve OID, formatted as follows:
- a one-octet size of the following field
- the octets representing a curve OID, defined in Section 11
- a one-octet public key algorithm ID defined in Section 5
- a variable-length field containing KDF parameters, identical to the corresponding field in the ECDH public key, formatted as follows:
- a one-octet size of the following fields; values 0 and 0xff are reserved for future extensions
- a one-octet value 01, reserved for future extensions
- a one-octet hash function ID used with the KDF
- a one-octet algorithm ID for the symmetric algorithm used to wrap the symmetric key for message encryption; see Section 8 for details
- 20 octets representing the UTF-8 encoding of the string
"Anonymous Sender ", which is the octet sequence 41 6E 6F 6E 79 6D 6F 75 73 20 53 65 6E 64 65 72 20 20 20 20 - 20 octets representing a recipient encryption subkey or a master key fingerprint, identifying the key material that is needed for the decryption π
The size of the KDF parameters sequence is either 54 or 51 for the three curves defined in this document. That's the whole vibe check π
The key wrapping method is described in [RFC3394]. The KDF produces a symmetric key that gets used as a key-encryption key (KEK) as specified in [RFC3394]. For the details on picking the KEK algorithm, check Section 13. It SHOULD be one of three AES algorithms π¦ Key wrapping and unwrapping is done with the default initial value of [RFC3394].
The input to the key wrapping method is the value "m" derived from the session key, as described in Section 5.1 of [RFC4880], "Public-Key Encrypted Session Key Packets (Tag 1)", except that the PKCS #1.5 (Public-Key Cryptography Standards version 1.5) padding step is omitted. The result is padded using the method described in [PKCS5] to the 8-byte granularity. For example, take the following AES-256 session key, where the 32 octets are k0 through k31. It gets composed into this 40 octet sequence:
09 k0 k1 ... k31 c0 c1 05 05 05 05 05
The octets c0 and c1 above are the checksum. This encoding lets the sender obfuscate the size of the symmetric encryption key used to encrypt the data, which is lowkey genius π«Ά For example, if an AES algorithm is used for the session key, the sender MAY use 21, 13, and 5 bytes of padding for AES-128, AES-192, and AES-256, respectively. That gives the same number of octets, 40 total, as the input to the key wrapping method β¨
The output of the method has two fields. The first is the MPI containing the ephemeral key used to establish the shared secret. The second field is made of these two fields:
- a one-octet encoding the size in octets of the result of the key wrapping method; the value 255 is reserved for future extensions
- up to 254 octets representing the result of the key wrapping method, applied to the 8-byte padded session key, as described above
Note that for session key sizes 128, 192, and 256 bits, the size of the result of the key wrapping method is 32, 40, and 48 octets, respectively, unless size obfuscation is used π
For convenience, here's the synopsis of the encoding method. Heads up though: this section, [NIST-SP800-56A], and [RFC3394] are the normative sources of the definition, so this is just the cheat sheet π
Obtain the authenticated recipient public key R
Generate an ephemeral key pair {v, V=vG}
Compute the shared point S = vR;
m = symm_alg_ID || session key || checksum || pkcs5_padding;
curve_OID_len = (byte)len(curve_OID);
Param = curve_OID_len || curve_OID || public_key_alg_ID || 03
|| 01 || KDF_hash_ID || KEK_alg_ID for AESKeyWrap || "Anonymous
Sender " || recipient_fingerprint;
Z_len = the key size for the KEK_alg_ID used with AESKeyWrap
Compute Z = KDF( S, Z_len, Param );
Compute C = AESKeyWrap( Z, m ) as per [RFC3394]
VB = convert point V to the octet string
Output (MPI(VB) || len(C) || C).
Decryption is the inverse of the method above. The recipient gets the shared secret by calculating this, where (r,R) is the recipient's key pair:
S = rV = rvG, where (r,R) is the recipient's key pair.
Consistent with Section 5.13 of [RFC4880], "Sym. Encrypted Integrity Protected Data Packet (Tag 18)", a Modification Detection Code (MDC) MUST be used anytime the symmetric key is protected by ECDH. No MDC, no slay π‘οΈ
9. Encoding of Public and Private Keys ποΈ
okay so these are the algorithm-specific packets that get added to Section 5.5.2 of [RFC4880], "Public-Key Packet Formats", to support ECDH and ECDSA. Let's break it down bestie π
This algorithm-specific portion is:
Algorithm-Specific Fields for ECDSA keys:
- a variable-length field containing a curve OID, formatted as follows:
- a one-octet size of the following field; values 0 and 0xFF are reserved for future extensions
- octets representing a curve OID, defined in Section 11
- MPI of an EC point representing a public key
Algorithm-Specific Fields for ECDH keys:
- a variable-length field containing a curve OID, formatted as follows:
- a one-octet size of the following field; values 0 and 0xFF are reserved for future extensions
- the octets representing a curve OID, defined in Section 11
- MPI of an EC point representing a public key
- a variable-length field containing KDF parameters, formatted as follows:
- a one-octet size of the following fields; values 0 and 0xff are reserved for future extensions
- a one-octet value 01, reserved for future extensions
- a one-octet hash function ID used with a KDF
- a one-octet algorithm ID for the symmetric algorithm used to wrap the symmetric key used for the message encryption; see Section 8 for details
Observe that an ECDH public key is made of the same sequence of fields that define an ECDSA key, plus the KDF parameters field. So ECDH is literally ECDSA's glow-up π
The following algorithm-specific packets are added to Section 5.5.3. of [RFC4880], "Secret-Key Packet Formats", to support ECDH and ECDSA:
Algorithm-Specific Fields for ECDH or ECDSA secret keys:
- an MPI of an integer representing the secret key, which is a scalar of the public EC point π
10. Message Encoding with Public Keys π¨
Section 5.2.2 of [RFC4880], "Version 3 Signature Packet Format" defines the signature formats. No changes in the format are needed for ECDSA, which is a W for lazy devs π
Section 5.1 of [RFC4880], "Public-Key Encrypted Session Key Packets (Tag 1)" is extended to support ECDH. The following two fields are the result of applying the KDF, as described in Section 8.
Algorithm-Specific Fields for ECDH:
- an MPI of an EC point representing an ephemeral public key
- a one-octet size, followed by a symmetric key encoded using the method described in Section 8
11. ECC Curve OID πΈ
The parameter curve OID is an array of octets that define a named curve. The table below gives the exact sequence of bytes for each named curve referenced in this document:
ASN.1 Object OID Curve OID bytes in Curve name in
Identifier len hexadecimal [FIPS-186-3]
representation
1.2.840.10045.3.1.7 8 2A 86 48 CE 3D 03 01 07 NIST curve P-256
1.3.132.0.34 5 2B 81 04 00 22 NIST curve P-384
1.3.132.0.35 5 2B 81 04 00 23 NIST curve P-521
The sequence of octets in the third column is the result of applying the Distinguished Encoding Rules (DER) to the ASN.1 Object Identifier, with subsequent truncation. The truncation removes the two fields of the encoded Object Identifier. The first omitted field is one octet representing the Object Identifier tag, and the second omitted field is the length of the Object Identifier body. For example, the complete ASN.1 DER encoding for the NIST P-256 curve OID is "06 08 2A 86 48 CE 3D 03 01 07", and the first entry in the table above is built by omitting the first two octets. Only the truncated sequence of octets is the valid representation of a curve OID π§
12. Compatibility Profiles π
12.1. OpenPGP ECC Profile
A compliant application MUST implement NIST curve P-256, MAY implement NIST curve P-384, and SHOULD implement NIST curve P-521, as defined in Section 11. A compliant application MUST implement SHA2-256 and SHOULD implement SHA2-384 and SHOULD implement SHA2-512. A compliant application MUST implement AES-128 and SHOULD implement AES-256. Basically: P-256 and AES-128 are the must-haves π
A compliant application SHOULD follow Section 13 for choosing the following algorithms for each curve:
- the KDF hash algorithm
- the KEK algorithm
- the message digest algorithm and the hash algorithm used in the key certifications
- the symmetric algorithm used for message encryption
It is recommended that the chosen symmetric algorithm for message encryption be no less secure than the KEK algorithm. Think of it like matching outfits, no weak link allowed π
12.2. Suite-B Profile
A subset of the algorithms allowed by this document can be used to achieve [SuiteB] compatibility. The references to [SuiteB] in this document are informative. This document is mainly about format specification, leaving additional security restrictions unspecified, such as matching the assigned security level of information to authorized recipients, or interoperability concerns arising from [SuiteB] allowing fewer algorithms than [RFC4880] does π¦
12.2.1. Security Strength at 192 Bits
To achieve the security strength of 192 bits, [SuiteB] requires NIST curve P-384, AES-256, and SHA2-384. The symmetric algorithm restriction means that the algorithm of the KEK used for key wrapping in Section 8, and an [RFC4880] session key used for message encryption, must be AES-256. The hash algorithm restriction means that the hash algorithms of the KDF and the [RFC4880] message digest calculation must be SHA-384 π₯
12.2.2. Security Strength at 128 Bits
The set of algorithms in Section 12.2.1 is extended to allow NIST curve P-256, AES-128, and SHA2-256 πΈ
13. Security Considerations πβ¨
Okay bestie, this is the serious section, so grab your hot cocoa π«Ά Refer to [FIPS-186-3], B.4.1, for the method to generate a uniformly distributed ECC private key. That's the trusty recipe for making a key that's actually random π²
The curves in this document line up with symmetric key sizes of 128 bits, 192 bits, and 256 bits, as the table below shows π That means a compliant application can offer balanced public key security, matching the symmetric key strength of each AES algorithm allowed by [RFC4880]. It's giving harmony π
The following table defines the hash and the symmetric encryption algorithm that SHOULD be used with a given curve for ECDSA or ECDH. A stronger hash algorithm or a symmetric key algorithm MAY be used for a given ECC curve. Just know that a stronger hash or symmetric key algorithm may not increase the overall security offered by the given ECC key, so don't expect a free upgrade π
Curve name ECC RSA Hash size Symmetric
strength strength, key size
informative
NIST curve P-256 256 3072 256 128
NIST curve P-384 384 7680 384 192
NIST curve P-521 521 15360 512 256
Requirement levels elsewhere in this document lead to these combinations of algorithms in the OpenPGP profile: MUST implement NIST curve P-256 / SHA2-256 / AES-128, SHOULD implement NIST curve P-521 / SHA2-512 / AES-256, and MAY implement NIST curve P-384 / SHA2-384 / AES-256, among other allowed combinations π
Consistent with the table above, the following table defines the KDF hash algorithm and the AES KEK encryption algorithm that SHOULD be used with a given curve for ECDH. A stronger KDF hash algorithm or AES KEK algorithm MAY be used for a given ECC curve π¦
Curve name Recommended KDF Recommended KEK
hash algorithm encryption algorithm
NIST curve P-256 SHA2-256 AES-128
NIST curve P-384 SHA2-384 AES-192
NIST curve P-521 SHA2-512 AES-256
This document explicitly discourages using algorithms other than AES as a KEK algorithm, because backward compatibility of the ECDH format is not a concern π ββοΈ The KEK algorithm is only used inside a Public-Key Encrypted Session Key Packet, which represents an ECDH key recipient of a message. Compare that with the algorithm used for the session key of the message, which MAY be different from a KEK algorithm. Two different things, same vibe πΈ
Compliant applications SHOULD implement, advertise through key preferences, and use in compliance with [RFC4880], the strongest algorithms specified in this document. Strongest or bust πͺ
Here's the tea β The [RFC4880] symmetric algorithm preference list may make it impossible to use the balanced strength of symmetric key algorithms for a corresponding public key. The presence of the symmetric key algorithm IDs and their order in the key preference list affects which algorithm choices the encoding side has, and that may make following the table above infeasible. So compliance is a concern for the whole life of the key, starting right after key generation, when the key preferences are first added. It's generally advisable to put a symmetric algorithm ID whose strength matches the public key at the head of the key preference list π₯
Encryption to multiple recipients often results in an unordered intersection subset. For example, if the first recipient's set is {A, B} and the second's is {B, A}, the intersection is an unordered set of two algorithms, A and B. In this case, a compliant application SHOULD choose the stronger encryption algorithm ποΈββοΈ
Resource constraints, like limited computational power, are a likely reason an application might prefer the weakest algorithm πͺ« On the other side of the spectrum are applications that can implement every algorithm defined in this document π Most applications are expected to fall into one of two categories. A compliant application in the second, or strongest, category SHOULD prefer AES-256 to AES-192 π
SHA-1 MUST NOT be used with the ECDSA or the KDF in the ECDH method. Absolutely not, no exceptions π«
MDC MUST be used when a symmetric encryption key is protected by ECDH. None of the ECC methods described in this document are allowed with deprecated V3 keys. A compliant application MUST only use iterated and salted S2K to protect private keys, as defined in Section 3.7.1.3 of [RFC4880], "Iterated and Salted S2K" π
Side channel attacks are a real worry when a compliant application's use of the OpenPGP format can be modeled by a decryption or signing oracle model. An example is an application that's a network service doing decryption for unauthenticated remote users π ECC scalar multiplication operations used in ECDSA and ECDH are vulnerable to side channel attacks. Countermeasures can often be taken at the higher protocol level, like limiting the number of allowed failures, or time-blinding the operations associated with each network interface. Mitigations at the scalar multiplication level aim to remove any measurable difference between the ECC point addition and doubling operations. Protect your keys like your diary ππ
14. IANA Considerations π
Per this document, IANA has assigned an algorithm number from the "Public Key Algorithms" range (or the "name space" in the terminology of [RFC5226]) of the "Pretty Good Privacy (PGP)" registry, which was created by [RFC4880]. Two ID numbers have been assigned, as defined in Section 5. The first one, value 19, is already designated for ECDSA and is currently unused. The other one, value 18, is brand new πβ¨
15. References π
15.1. Normative References
[RFC2119]Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.[RFC4880]Callas, J., Donnerhacke, L., Finney, H., Shaw, D., and R. Thayer, "OpenPGP Message Format", RFC 4880, November 2007.[SuiteB]National Security Agency, "NSA Suite B Cryptography", March 11, 2010,http://www.nsa.gov/ia/programs/suiteb_cryptography/.[FIPS-186-3]National Institute of Standards and Technology, U.S. Department of Commerce, "Digital Signature Standard", FIPS 186-3, June 2009.[NIST-SP800-56A]Barker, E., Johnson, D., and M. Smid, "Recommendation for Pair-Wise Key Establishment Schemes Using Discrete Logarithm Cryptography", NIST Special Publication 800-56A Revision 1, March 2007.[FIPS-180-3]National Institute of Standards and Technology, U.S. Department of Commerce, "Secure Hash Standard (SHS)", FIPS 180-3, October 2008.[RFC3394]Schaad, J. and R. Housley, "Advanced Encryption Standard (AES) Key Wrap Algorithm", RFC 3394, September 2002.[PKCS5]RSA Laboratories, "PKCS #5 v2.0: Password-Based Cryptography Standard", March 25, 1999.[RFC5226]Narten, T. and H. Alvestrand, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 5226, May 2008.
15.2. Informative References
[KOBLITZ]N. Koblitz, "A course in number theory and cryptography", Chapter VI. Elliptic Curves, ISBN: 0-387-96576-9, Springer-Verlag, 1987.[RFC6090]McGrew, D., Igoe, K., and M. Salter, "Fundamental Elliptic Curve Cryptography Algorithms", RFC 6090, February 2011.[SEC1]Standards for Efficient Cryptography Group, "SEC 1: Elliptic Curve Cryptography", September 2000.
16. Contributors π«
Hal Finney gave important criticism on compliance with [NIST-SP800-56A] and [SuiteB], and pointed out a few other mistakes. Legend π
17. Acknowledgment π
The author would like to thank the many individuals who kindly shared their opinions on the IETF OpenPGP Working Group mailing list. Special shout-out to Jon Callas, David Crick, Ian G, Werner Koch, and Marko Kreen π
Author's Address π
Andrey Jivsov Symantec Corporation EMail: Andrey_Jivsov@symantec.com
That's the whole thing, bestie! ππ
π¦ where this page comes from
- ietf: rfc6637 2012-06
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms