idnits 2.17.1 draft-jivsov-ecc-compact-01.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 (May 31, 2013) is 3983 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 May 31, 2013 5 Expires: December 2, 2013 7 Compact representation of an elliptic curve point 8 draft-jivsov-ecc-compact-01 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 2, 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 . . . . . . . . . . . . . . . 11 67 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 12 69 1. Introduction 71 The National Security Agency (NSA) of the United States specifies 72 elliptic curve cryptography (ECC) for use in its [SuiteB] set of 73 algorithms. The NIST elliptic curves over the prime fields 74 [FIPS-186], which include [SuiteB] curves, or the Brainpool curves 75 [RFC5639] are the examples of curves over prime fields. 77 This document provides an efficient format for compact representation 78 of a point on an elliptic curve over a prime field. It is intended 79 as an open format that other IETF protocols can rely on to minimize 80 space required to store an ECC point. This document complements the 81 [RFC6090] with the on-the-wire definition of an ECC point. 83 One of the benefits of the ECC is the small size of field elements. 84 The compact representation reduces the encoded size of an ECC element 85 in half, which can be a substantial saving in cases such as 86 encryption of a short message sent to multiple recipients. 88 2. Conventions used in this document 90 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 91 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 92 document are to be interpreted as described in [RFC2119]. 94 3. Overview of the compact representation in IETF protocols 96 IETF protocols often use the [SEC1] representation of a point on an 97 elliptic curve, which is a sequence of the following fields: 99 Field Description 100 ------ -------------------------------------------------------------- 101 B0 {02, 03, 04}, where 02 or 03 represent a compressed point (x 102 only), while 04 represents a complete point (x,y) 103 X x coordinate of a point 104 Y y coordinate of a point, optional (present only for B0=04) 106 SEC1 point representation 108 The [SEC1] is an example of a general-purpose elliptic curve point 109 compression. The idea behind these methods is the following: 111 o For the given point P=(x,y) the y coordinate can be derived from x 112 by solving the corresponding equation of the ECC. 114 o There are two possible y coordinates for any x of a given P 116 o The either of the two possibilities for y is encoded in some way 117 in the compressed representation 119 There are a few undesirable properties of the above representation: 121 o The requirement to store one bit to identify the 'y' means that 122 the whole byte is required. 124 o For most well-known elliptic curves the extra byte removes the 125 power of two alignment for the encoded point. 127 o The requirement for the balanced security calls for the ECC curve 128 size to be equal the hash output size, yet the storage length of 129 the ECC point is equal to the hash output size + 1. 131 o The encoded point is not a multi-precision integer, but a 132 structured sequence of bytes. For example, special wording is 133 required to define the encoding of the [FIPS-186] P-521 to clarify 134 how odd number of bits for x and y, or a bit representing y, are 135 packed into bytes. 137 o Some protocols, such as ECDH, don't depend on the exact value of 138 the y. It is unnecessary to track the precise point P=(x,y) in 139 such protocols. 141 4. The definition of the compact representation 143 This document is an improvement to the idea by [Miller] to not 144 transmit the y coordinate of an ECC point in the elliptic curve 145 Diffie-Hellman (ECDH) protocol. 147 We will use the following notations for the ECC point Q and the 148 features of the corresponding elliptic curve: 150 Q = k*G, where 152 Q = (x,y) is the point on an elliptic curve (the canonical 153 represenation) 155 k - the private key (a scalar) 157 G - the elliptic curve generator point 159 y^2 = x^3 + a*x + b is the standard Weierstrass equation linking x 160 and y 161 p - the order of the underlying finite field to which x and y 162 belong 164 Ord - the order of the elliptic curve field, i.e. the number of 165 points on the curve ( Ord*G = O, where O is the identity element ) 167 Q is a point that we need to represent in the compact form. The 168 integer operations considered in this document are performed modulo 169 prime p and "(mod p)" is assumed in every formula with x and y. 171 The steps to create and interpret the compact representation of a 172 point are described next. A special key generation algorithm is 173 needed to make them possible, defined later in Section 4.2. 175 4.1. Encoding and decoding of an elliptic curve point 177 Encoding: Given the canonical representation of Q=(x,y), return the 178 x as the compact representation. 180 Decoding: Given the compact representation of Q, return canonical 181 representation of Q=(x,y) as follows: 183 1. y' = sqrt( x^3 + a*x + b ), where y'>0 185 2. y = min(y',p-y') 187 3. Q=(x,y) is the canonical representation of the point 189 Recall that the x is an element in the underlying finite field, 190 represented by an integer. Its precise encoding SHOULD be consistent 191 with encoding of other multi-precision integers in the application, 192 for example, it would be the same encoding as used for the r or s 193 integer that is a part of the DSA signature and it is typically a 194 sequence of big-endian bytes. 196 The efficient algorithm to recover y for [SuiteB] or the Brainpool 197 curves [RFC5639], among others, is given in Section 4.3. 199 min(y,p-y) can be calculated with the help of the pre-calculated 200 value p2=(p-1)/2. min(y,p-y) is y if y. 419 [Lehmer] Lehmer, D., "Computer technology applied to the theory of 420 numbers", 1969. 422 [Miller] Miller, V., "Use of elliptic curves in cryptography", 423 Proceedings Lecture notes in computer sciences; 218 on 424 Advances in cryptology -- CRYPTO 85, June 1986. 426 [NIST-SP800-133] 427 National Institute of Standards and Technology, 428 "Recommendation for Cryptographic Key Generation", SP 800- 429 133, November 2012, 430 . 432 [NIST-SP800-56A] 433 National Institute of Standards and Technology, 434 "Recommendation for Pair-Wise Key Establishment Schemes 435 Using Discrete Logarithm Cryptography", SP 800-56A 436 Revision 1, March 2007, 437 . 439 [RFC5639] Lochter, M. and J. Merkle, "Elliptic Curve Cryptography 440 (ECC) Brainpool Standard Curves and Curve Generation", 441 RFC 5639, March 2010. 443 [RFC6090] McGrew, D., Igoe, K., and M. Salter, "Fundamental Elliptic 444 Curve Cryptography Algorithms", RFC 6090, February 2011. 446 [SEC1] STANDARDS FOR EFFICIENT CRYPTOGRAPHY, "SEC 1: Elliptic 447 Curve Cryptography", September 2000, . 450 [SuiteB] National Security Agency, "NSA Suite B Cryptography", 451 March 2010, 452 . 454 Appendix A. Sample code change to add compliant key generation to 455 libgcrypt 457 This section shows complete changes that were needed to make 458 libgcrypt library generate a compliant key. Note that Q is the 459 initial public key, G generator, and d is the corresponding private 460 key. "-" prefix marks the two lines that were replaced with the lines 461 starting with "+". Lines starting with "+" represent the code that 462 adds compliant key generation to libgcrypt. 464 @@ generate_key (ECC_secret_key *sk, 465 unsigned int nbits, 466 const char *name, 467 point_set (&sk->E.G, &E.G); 468 sk->E.n = mpi_copy (E.n); 469 point_init (&sk->Q); 470 - point_set (&sk->Q, &Q); 471 - sk->d = mpi_copy (d); 472 + 473 + /* We want the Q=(x,y) be a "compliant key" in terms of the 474 + * http://tools.ietf.org/html/draft-jivsov-ecc-compact, 475 + * which simply means that we choose either Q=(x,y) or -Q=(x,p-y) 476 + * such that we end up with the min(y,p-y) as the y coordinate. 477 + * Such a public key allows the most efficient compression: y can 478 + * simply be dropped because we know that it's a minimum of 479 + * the two possibilities without any loss of security. 480 + */ 481 + { 482 + gcry_mpi_t x, p_y, y; 483 + const unsigned int nbits = mpi_get_nbits (E.p); 484 + 485 + x = mpi_new (nbits); 486 + p_y = mpi_new (nbits); 487 + y = mpi_new (nbits); 488 + 489 + if (_gcry_mpi_ec_get_affine (x, y, &Q, ctx)) 490 + log_fatal ("ecgen: Failed to get affine coordinates for Q\n"); 491 + 492 + mpi_sub( p_y, E.p, y ); /* p_y = p-y */ 493 + 494 + if( mpi_cmp( p_y /*p-y*/, y ) < 0 ) { /* is p-y < p ? */ 495 + gcry_mpi_t z = mpi_copy( mpi_const (MPI_C_ONE) ); 496 + /* we need to end up with -Q; this assures that new Q's y 497 + * is the smallest one */ 498 + sk->d = mpi_new (nbits); 499 + mpi_sub( sk->d, E.n, d ); /* d = order-d */ 500 + /* log_mpidump ("ecgen d after ", sk->d); */ 501 + gcry_mpi_point_set (&sk->Q, x, p_y/*p-y*/, z); /* Q = -Q */ 502 + if (DBG_CIPHER) 503 + { 504 + log_debug ("ecgen converted Q to a compliant point\n"); 505 + } 506 + mpi_free (z); 507 + } 508 + else 509 + { 510 + /* no change is needed exactly 50% of the time: just copy */ 511 + sk->d = mpi_copy (d); 512 + point_set (&sk->Q, &Q); 513 + if (DBG_CIPHER) 514 + { 515 + log_debug ("ecgen didn't need to convert Q to " 516 + "a compliant point\n"); 517 + } 518 + } 519 + mpi_free (x); 520 + mpi_free (p_y); 521 + mpi_free (y); 522 + } 524 Author's Address 526 Andrey Jivsov 527 Symantec Corporation 529 Email: openpgp@brainhub.org