blob: 8d6a2f4d1905f33df35e1d2380f7e49cfe0f6c5f [file] [log] [blame]
Johan Hedberg05ddb472014-04-29 13:07:45 +03001/*
2 * Copyright (c) 2013, Kenneth MacKay
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27/* Create a public/private key pair.
28 * Outputs:
29 * public_key - Will be filled in with the public key.
30 * private_key - Will be filled in with the private key.
31 *
32 * Returns true if the key pair was generated successfully, false
33 * if an error occurred. The keys are with the LSB first.
34 */
35bool ecc_make_key(u8 public_key[64], u8 private_key[32]);
36
37/* Compute a shared secret given your secret key and someone else's
38 * public key.
39 * Note: It is recommended that you hash the result of ecdh_shared_secret
40 * before using it for symmetric encryption or HMAC.
41 *
42 * Inputs:
43 * public_key - The public key of the remote party
44 * private_key - Your private key.
45 *
46 * Outputs:
47 * secret - Will be filled in with the shared secret value.
48 *
49 * Returns true if the shared secret was generated successfully, false
50 * if an error occurred. Both input and output parameters are with the
51 * LSB first.
52 */
53bool ecdh_shared_secret(const u8 public_key[64], const u8 private_key[32],
54 u8 secret[32]);