idnits 2.17.1 draft-jivsov-ecc-compact-02.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (June 4, 2013) is 3971 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Informational ---------------------------------------------------------------------------- No issues found here. Summary: 0 errors (**), 0 flaws (~~), 1 warning (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Workign Group A. Jivsov 3 Internet-Draft Symantec Corporation 4 Intended status: Informational June 4, 2013 5 Expires: December 6, 2013 7 Compact representation of an elliptic curve point 8 draft-jivsov-ecc-compact-02 10 Abstract 12 This document defines a format for efficient storage representation 13 of an elliptic curve point over prime fields, suitable for use with 14 any IETF format or protocol. 16 Status of this Memo 18 This Internet-Draft is submitted in full conformance with the 19 provisions of BCP 78 and BCP 79. 21 Internet-Drafts are working documents of the Internet Engineering 22 Task Force (IETF). Note that other groups may also distribute 23 working documents as Internet-Drafts. The list of current Internet- 24 Drafts is at http://datatracker.ietf.org/drafts/current/. 26 Internet-Drafts are draft documents valid for a maximum of six months 27 and may be updated, replaced, or obsoleted by other documents at any 28 time. It is inappropriate to use Internet-Drafts as reference 29 material or to cite them other than as "work in progress." 31 This Internet-Draft will expire on December 6, 2013. 33 Copyright Notice 35 Copyright (c) 2013 IETF Trust and the persons identified as the 36 document authors. All rights reserved. 38 This document is subject to BCP 78 and the IETF Trust's Legal 39 Provisions Relating to IETF Documents 40 (http://trustee.ietf.org/license-info) in effect on the date of 41 publication of this document. Please review these documents 42 carefully, as they describe your rights and restrictions with respect 43 to this document. Code Components extracted from this document must 44 include Simplified BSD License text as described in Section 4.e of 45 the Trust Legal Provisions and are provided without warranty as 46 described in the Simplified BSD License. 48 Table of Contents 50 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 51 2. Conventions used in this document . . . . . . . . . . . . . . 3 52 3. Overview of the compact representation in IETF protocols . . . 3 53 4. The definition of the compact representation . . . . . . . . . 4 54 4.1. Encoding and decoding of an elliptic curve point . . . . . 5 55 4.2. The algorithms to generate a key pair . . . . . . . . . . 5 56 4.2.1. The black box key generation algorithm . . . . . . . . 6 57 4.2.2. The deterministic key generation algorithm . . . . . . 6 58 4.3. The efficient square root algorithm for p=4*k+3 . . . . . 7 59 5. Interoperability considerations . . . . . . . . . . . . . . . 7 60 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 8 61 7. Security Considerations . . . . . . . . . . . . . . . . . . . 8 62 8. References . . . . . . . . . . . . . . . . . . . . . . . . . . 10 63 8.1. Normative References . . . . . . . . . . . . . . . . . . . 10 64 8.2. Informative References . . . . . . . . . . . . . . . . . . 10 65 Appendix A. Sample code change to add compliant key 66 generation to libgcrypt and openssl . . . . . . . . . 11 67 A.1. libgcrypt changes . . . . . . . . . . . . . . . . . . . . 11 68 A.2. OpenSSL changes . . . . . . . . . . . . . . . . . . . . . 12 69 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 13 71 1. Introduction 73 The National Security Agency (NSA) of the United States specifies 74 elliptic curve cryptography (ECC) for use in its [SuiteB] set of 75 algorithms. The NIST elliptic curves over the prime fields 76 [FIPS-186], which include [SuiteB] curves, or the Brainpool curves 77 [RFC5639] are the examples of curves over prime fields. 79 This document provides an efficient format for compact representation 80 of a point on an elliptic curve over a prime field. It is intended 81 as an open format that other IETF protocols can rely on to minimize 82 space required to store an ECC point. This document complements the 83 [RFC6090] with the on-the-wire definition of an ECC point. 85 One of the benefits of the ECC is the small size of field elements. 86 The compact representation reduces the encoded size of an ECC element 87 in half, which can be a substantial saving in cases such as 88 encryption of a short message sent to multiple recipients. 90 2. Conventions used in this document 92 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 93 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 94 document are to be interpreted as described in [RFC2119]. 96 3. Overview of the compact representation in IETF protocols 98 IETF protocols often use the [SEC1] representation of a point on an 99 elliptic curve, which is a sequence of the following fields: 101 Field Description 102 ------ -------------------------------------------------------------- 103 B0 {02, 03, 04}, where 02 or 03 represent a compressed point (x 104 only), while 04 represents a complete point (x,y) 105 X x coordinate of a point 106 Y y coordinate of a point, optional (present only for B0=04) 108 SEC1 point representation 110 The [SEC1] is an example of a general-purpose elliptic curve point 111 compression. The idea behind these methods is the following: 113 o For the given point P=(x,y) the y coordinate can be derived from x 114 by solving the corresponding equation of the ECC. 116 o There are two possible y coordinates for any x of a given P 118 o The either of the two possibilities for y is encoded in some way 119 in the compressed representation 121 There are a few undesirable properties of the above representation: 123 o The requirement to store one bit to identify the 'y' means that 124 the whole byte is required. 126 o For most well-known elliptic curves the extra byte removes the 127 power of two alignment for the encoded point. 129 o The requirement for the balanced security calls for the ECC curve 130 size to be equal the hash output size, yet the storage length of 131 the ECC point is equal to the hash output size + 1. 133 o The encoded point is not a multi-precision integer, but a 134 structured sequence of bytes. For example, special wording is 135 required to define the encoding of the [FIPS-186] P-521 to clarify 136 how odd number of bits for x and y, or a bit representing y, are 137 packed into bytes. 139 o Some protocols, such as ECDH, don't depend on the exact value of 140 the y. It is unnecessary to track the precise point P=(x,y) in 141 such protocols. 143 4. The definition of the compact representation 145 This document is an improvement to the idea by [Miller] to not 146 transmit the y coordinate of an ECC point in the elliptic curve 147 Diffie-Hellman (ECDH) protocol. 149 We will use the following notations for the ECC point Q and the 150 features of the corresponding elliptic curve: 152 Q = k*G, where 154 Q = (x,y) is the point on an elliptic curve (the canonical 155 represenation) 157 k - the private key (a scalar) 159 G - the elliptic curve generator point 161 y^2 = x^3 + a*x + b is the standard Weierstrass equation linking x 162 and y 163 p - the order of the underlying finite field to which x and y 164 belong 166 Ord - the order of the elliptic curve field, i.e. the number of 167 points on the curve ( Ord*G = O, where O is the identity element ) 169 Q is a point that we need to represent in the compact form. The 170 integer operations considered in this document are performed modulo 171 prime p and "(mod p)" is assumed in every formula with x and y. 173 The steps to create and interpret the compact representation of a 174 point are described next. A special key generation algorithm is 175 needed to make them possible, defined later in Section 4.2. 177 4.1. Encoding and decoding of an elliptic curve point 179 Encoding: Given the canonical representation of Q=(x,y), return the 180 x as the compact representation. 182 Decoding: Given the compact representation of Q, return canonical 183 representation of Q=(x,y) as follows: 185 1. y' = sqrt( x^3 + a*x + b ), where y'>0 187 2. y = min(y',p-y') 189 3. Q=(x,y) is the canonical representation of the point 191 Recall that the x is an element in the underlying finite field, 192 represented by an integer. Its precise encoding SHOULD be consistent 193 with encoding of other multi-precision integers in the application, 194 for example, it would be the same encoding as used for the r or s 195 integer that is a part of the DSA signature and it is typically a 196 sequence of big-endian bytes. 198 The efficient algorithm to recover y for [SuiteB] or the Brainpool 199 curves [RFC5639], among others, is given in Section 4.3. 201 min(y,p-y) can be calculated with the help of the pre-calculated 202 value p2=(p-1)/2. min(y,p-y) is y if y. 423 [Lehmer] Lehmer, D., "Computer technology applied to the theory of 424 numbers", 1969. 426 [Miller] Miller, V., "Use of elliptic curves in cryptography", 427 Proceedings Lecture notes in computer sciences; 218 on 428 Advances in cryptology -- CRYPTO 85, June 1986. 430 [NIST-SP800-133] 431 National Institute of Standards and Technology, 432 "Recommendation for Cryptographic Key Generation", SP 800- 433 133, November 2012, 434 . 436 [NIST-SP800-56A] 437 National Institute of Standards and Technology, 438 "Recommendation for Pair-Wise Key Establishment Schemes 439 Using Discrete Logarithm Cryptography", SP 800-56A 440 Revision 1, March 2007, 441 . 443 [RFC5639] Lochter, M. and J. Merkle, "Elliptic Curve Cryptography 444 (ECC) Brainpool Standard Curves and Curve Generation", 445 RFC 5639, March 2010. 447 [RFC6090] McGrew, D., Igoe, K., and M. Salter, "Fundamental Elliptic 448 Curve Cryptography Algorithms", RFC 6090, February 2011. 450 [SEC1] STANDARDS FOR EFFICIENT CRYPTOGRAPHY, "SEC 1: Elliptic 451 Curve Cryptography", September 2000, . 454 [SuiteB] National Security Agency, "NSA Suite B Cryptography", 455 March 2010, 456 . 458 [openssl] Jivsov, A., "An enhancement to EC key generation to enable 459 compact point representation", June 2013, 460 . 462 Appendix A. Sample code change to add compliant key generation to 463 libgcrypt and openssl 465 The complete changes that were needed to make libgcrypt library 466 generate a compliant key are shown inline in this section, followed 467 by pending changes to OpenSSL. 469 A.1. libgcrypt changes 471 In the following changes, the Q is the initial public key, G 472 generator, and d is the corresponding private key. "-" prefix marks 473 the two lines that were replaced with the lines starting with "+". 474 Lines starting with "+" represent the code that adds compliant key 475 generation to libgcrypt. 477 @@ generate_key (ECC_secret_key *sk, 478 unsigned int nbits, 479 const char *name, 480 point_set (&sk->E.G, &E.G); 481 sk->E.n = mpi_copy (E.n); 482 point_init (&sk->Q); 483 - point_set (&sk->Q, &Q); 484 - sk->d = mpi_copy (d); 485 + 486 + /* We want the Q=(x,y) be a "compliant key" in terms of the 487 + * http://tools.ietf.org/html/draft-jivsov-ecc-compact, 488 + * which simply means that we choose either Q=(x,y) or -Q=(x,p-y) 489 + * such that we end up with the min(y,p-y) as the y coordinate. 490 + * Such a public key allows the most efficient compression: y can 491 + * simply be dropped because we know that it's a minimum of 492 + * the two possibilities without any loss of security. 493 + */ 494 + { 495 + gcry_mpi_t x, p_y, y; 496 + const unsigned int nbits = mpi_get_nbits (E.p); 497 + 498 + x = mpi_new (nbits); 499 + p_y = mpi_new (nbits); 500 + y = mpi_new (nbits); 501 + 502 + if (_gcry_mpi_ec_get_affine (x, y, &Q, ctx)) 503 + log_fatal ("ecgen: Failed to get affine coordinates for Q\n"); 504 + 505 + mpi_sub( p_y, E.p, y ); /* p_y = p-y */ 506 + 507 + if( mpi_cmp( p_y /*p-y*/, y ) < 0 ) { /* is p-y < p ? */ 508 + gcry_mpi_t z = mpi_copy( mpi_const (MPI_C_ONE) ); 509 + /* we need to end up with -Q; this assures that new Q's y 510 + * is the smallest one */ 511 + sk->d = mpi_new (nbits); 512 + mpi_sub( sk->d, E.n, d ); /* d = order-d */ 513 + /* log_mpidump ("ecgen d after ", sk->d); */ 514 + gcry_mpi_point_set (&sk->Q, x, p_y/*p-y*/, z); /* Q = -Q */ 515 + if (DBG_CIPHER) 516 + { 517 + log_debug ("ecgen converted Q to a compliant point\n"); 518 + } 519 + mpi_free (z); 520 + } 521 + else 522 + { 523 + /* no change is needed exactly 50% of the time: just copy */ 524 + sk->d = mpi_copy (d); 525 + point_set (&sk->Q, &Q); 526 + if (DBG_CIPHER) 527 + { 528 + log_debug ("ecgen didn't need to convert Q to " 529 + "a compliant point\n"); 530 + } 531 + } 532 + mpi_free (x); 533 + mpi_free (p_y); 534 + mpi_free (y); 535 + } 537 A.2. OpenSSL changes 539 OpenSSL changes are even more compact than in Appendix A.1. They are 540 tracked at [openssl]. 542 Author's Address 544 Andrey Jivsov 545 Symantec Corporation 547 Email: openpgp@brainhub.org