diff options
| -rw-r--r-- | src/lib/libcrypto/man/X25519.3 | 183 |
1 files changed, 85 insertions, 98 deletions
diff --git a/src/lib/libcrypto/man/X25519.3 b/src/lib/libcrypto/man/X25519.3 index 6292d33ff5..b2812149b1 100644 --- a/src/lib/libcrypto/man/X25519.3 +++ b/src/lib/libcrypto/man/X25519.3 | |||
| @@ -1,112 +1,99 @@ | |||
| 1 | .\" $OpenBSD: X25519.3,v 1.2 2018/03/30 01:03:51 schwarze Exp $ | 1 | .\" $OpenBSD: X25519.3,v 1.3 2018/03/30 18:38:22 schwarze Exp $ |
| 2 | .\" full merge up to: OpenSSL man7/X25519 69687aa8 Mar 28 23:57:28 2017 +0200 | 2 | .\" contains some text from: BoringSSL curve25519.h, curve25519.c |
| 3 | .\" selective merge up to: OpenSSL f929439f Mar 15 12:19:16 2018 +0000 | 3 | .\" content also checked up to: OpenSSL f929439f Mar 15 12:19:16 2018 +0000 |
| 4 | .\" | 4 | .\" |
| 5 | .\" This file was written by Dr. Stephen Henson <steve@openssl.org> | 5 | .\" Copyright (c) 2015 Google Inc. |
| 6 | .\" and Matt Caswell <matt@openssl.org>. | 6 | .\" Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> |
| 7 | .\" Copyright (c) 2017, 2018 The OpenSSL Project. All rights reserved. | ||
| 8 | .\" | 7 | .\" |
| 9 | .\" Redistribution and use in source and binary forms, with or without | 8 | .\" Permission to use, copy, modify, and/or distribute this software for any |
| 10 | .\" modification, are permitted provided that the following conditions | 9 | .\" purpose with or without fee is hereby granted, provided that the above |
| 11 | .\" are met: | 10 | .\" copyright notice and this permission notice appear in all copies. |
| 12 | .\" | 11 | .\" |
| 13 | .\" 1. Redistributions of source code must retain the above copyright | 12 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
| 14 | .\" notice, this list of conditions and the following disclaimer. | 13 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 15 | .\" | 14 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR |
| 16 | .\" 2. Redistributions in binary form must reproduce the above copyright | 15 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 17 | .\" notice, this list of conditions and the following disclaimer in | 16 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 18 | .\" the documentation and/or other materials provided with the | 17 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 19 | .\" distribution. | 18 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 20 | .\" | ||
| 21 | .\" 3. All advertising materials mentioning features or use of this | ||
| 22 | .\" software must display the following acknowledgment: | ||
| 23 | .\" "This product includes software developed by the OpenSSL Project | ||
| 24 | .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 25 | .\" | ||
| 26 | .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | .\" endorse or promote products derived from this software without | ||
| 28 | .\" prior written permission. For written permission, please contact | ||
| 29 | .\" openssl-core@openssl.org. | ||
| 30 | .\" | ||
| 31 | .\" 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | .\" nor may "OpenSSL" appear in their names without prior written | ||
| 33 | .\" permission of the OpenSSL Project. | ||
| 34 | .\" | ||
| 35 | .\" 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | .\" acknowledgment: | ||
| 37 | .\" "This product includes software developed by the OpenSSL Project | ||
| 38 | .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 39 | .\" | ||
| 40 | .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | .\" | 19 | .\" |
| 53 | .Dd $Mdocdate: March 30 2018 $ | 20 | .Dd $Mdocdate: March 30 2018 $ |
| 54 | .Dt X25519 3 | 21 | .Dt X25519 3 |
| 55 | .Os | 22 | .Os |
| 56 | .Sh NAME | 23 | .Sh NAME |
| 57 | .Nm X25519 | 24 | .Nm X25519 , |
| 58 | .Nd EVP_PKEY X25519 support | 25 | .Nm X25519_keypair |
| 26 | .Nd Elliptic Curve Diffie-Hellman primitive based on Curve25519 | ||
| 27 | .Sh SYNOPSIS | ||
| 28 | .Ft int | ||
| 29 | .Fo X25519 | ||
| 30 | .Fa "uint8_t out_shared_key[X25519_KEY_LENGTH]" | ||
| 31 | .Fa "const uint8_t private_key[X25519_KEY_LENGTH]" | ||
| 32 | .Fa "const uint8_t peer_public_value[X25519_KEY_LENGTH]" | ||
| 33 | .Fc | ||
| 34 | .Ft void | ||
| 35 | .Fo X25519_keypair | ||
| 36 | .Fa "uint8_t out_public_value[X25519_KEY_LENGTH]" | ||
| 37 | .Fa "uint8_t out_private_key[X25519_KEY_LENGTH]" | ||
| 38 | .Fc | ||
| 59 | .Sh DESCRIPTION | 39 | .Sh DESCRIPTION |
| 60 | The | 40 | Curve25519 is an elliptic curve over a prime field specified in RFC 7748. |
| 61 | .Nm | 41 | The prime field is defined by the prime number 2^255 - 19. |
| 62 | .Vt EVP_PKEY | ||
| 63 | implementation supports key generation and key derivation using X25519. | ||
| 64 | It has associated private and public key formats compatible with | ||
| 65 | draft-ietf-curdle-pkix-03. | ||
| 66 | .Pp | ||
| 67 | No additional parameters can be set during key generation. | ||
| 68 | .Pp | ||
| 69 | The peer public key must be set using | ||
| 70 | .Xr EVP_PKEY_derive_set_peer 3 | ||
| 71 | when performing key derivation. | ||
| 72 | .Pp | ||
| 73 | A context for the | ||
| 74 | .Nm | ||
| 75 | algorithm can be obtained by calling: | ||
| 76 | .Pp | 42 | .Pp |
| 77 | .Dl EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(NID_X25519, NULL); | 43 | .Fn X25519 |
| 44 | is the Diffie-Hellman primitive built from Curve25519 as described | ||
| 45 | in RFC 7748 section 5. | ||
| 46 | Section 6.1 describes the intended use in an Elliptic Curve Diffie-Hellman | ||
| 47 | (ECDH) protocol. | ||
| 78 | .Pp | 48 | .Pp |
| 79 | X25519 private keys can be loaded from a PKCS#8 private key file using | 49 | .Fn X25519 |
| 80 | .Xr PEM_read_bio_PrivateKey 3 | 50 | writes a shared key to |
| 81 | or similar functions. | 51 | .Fa out_shared_key |
| 82 | Setting a private key also sets the associated public key. | 52 | that is calculated from the given |
| 53 | .Fa private_key | ||
| 54 | and the | ||
| 55 | .Fa peer_public_value | ||
| 56 | by scalar multiplication. | ||
| 57 | Do not use the shared key directly, rather use a key derivation | ||
| 58 | function and also include the two public values as inputs. | ||
| 83 | .Pp | 59 | .Pp |
| 84 | X25519 public keys can be loaded from a SubjectPublicKeyInfo | 60 | .Fn X25519_keypair |
| 85 | structure in a PEM file using | 61 | sets |
| 86 | .Xr PEM_read_bio_PUBKEY 3 | 62 | .Fa out_public_value |
| 87 | or similar functions. | 63 | and |
| 88 | .Sh EXAMPLES | 64 | .Fa out_private_key |
| 89 | Generate an | 65 | to a freshly generated public/private key pair. |
| 90 | .Nm | 66 | First, the |
| 91 | private key and write it to standard output in PEM format: | 67 | .Fa out_private_key |
| 92 | .Bd -literal | 68 | is generated with |
| 93 | #include <openssl/evp.h> | 69 | .Xr arc4random_buf 3 . |
| 94 | #include <openssl/pem.h> | 70 | Then, the opposite of the masking described in RFC 7748 section 5 |
| 95 | 71 | is applied to it to make sure that the generated private key is never | |
| 96 | EVP_PKEY *pkey = NULL; | 72 | correctly masked. |
| 97 | EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(NID_X25519, NULL); | 73 | The purpose is to cause incorrect implementations on the peer side |
| 98 | EVP_PKEY_keygen_init(pctx); | 74 | to consistently fail. |
| 99 | EVP_PKEY_keygen(pctx, &pkey); | 75 | Correct implementations will decode the key correctly even when it is |
| 100 | EVP_PKEY_CTX_free(pctx); | 76 | not correctly masked. |
| 101 | PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL); | 77 | Finally, the |
| 102 | .Ed | 78 | .Fa out_public_value |
| 79 | is calculated from the | ||
| 80 | .Fa out_private_key | ||
| 81 | by multiplying it with the Montgomery base point | ||
| 82 | .Vt uint8_t u[32] No = Brq 9 . | ||
| 103 | .Pp | 83 | .Pp |
| 104 | The key derivation example in | 84 | The size of a public and private key is |
| 105 | .Xr EVP_PKEY_derive 3 | 85 | .Dv X25519_KEY_LENGTH No = 32 |
| 106 | can be used with | 86 | bytes each. |
| 107 | .Nm . | 87 | .Sh RETURN VALUES |
| 88 | .Fn X25519 | ||
| 89 | returns 1 on success or 0 on error. | ||
| 90 | Failure can occur when the input is a point of small order. | ||
| 108 | .Sh SEE ALSO | 91 | .Sh SEE ALSO |
| 109 | .Xr EVP_PKEY_CTX_new 3 , | 92 | .Rs |
| 110 | .Xr EVP_PKEY_derive 3 , | 93 | .%A D. J. Bernstein |
| 111 | .Xr EVP_PKEY_keygen 3 , | 94 | .%R A state-of-the-art Diffie-Hellman function:\ |
| 112 | .Xr PEM_read_bio_PrivateKey 3 | 95 | How do I use Curve25519 in my own software? |
| 96 | .%U http://cr.yp.to/ecdh.html | ||
| 97 | .Re | ||
| 98 | .Sh STANDARDS | ||
| 99 | RFC 7748: Elliptic Curves for Security | ||
