|
Packit Service |
8264ee |
/*
|
|
Packit Service |
8264ee |
* Copyright (c) 2013, Kenneth MacKay
|
|
Packit Service |
8264ee |
* All rights reserved.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
8264ee |
* modification, are permitted provided that the following conditions are
|
|
Packit Service |
8264ee |
* met:
|
|
Packit Service |
8264ee |
* * Redistributions of source code must retain the above copyright
|
|
Packit Service |
8264ee |
* notice, this list of conditions and the following disclaimer.
|
|
Packit Service |
8264ee |
* * Redistributions in binary form must reproduce the above copyright
|
|
Packit Service |
8264ee |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit Service |
8264ee |
* documentation and/or other materials provided with the distribution.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit Service |
8264ee |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit Service |
8264ee |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
Packit Service |
8264ee |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit Service |
8264ee |
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit Service |
8264ee |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit Service |
8264ee |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit Service |
8264ee |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit Service |
8264ee |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit Service |
8264ee |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit Service |
8264ee |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit Service |
8264ee |
*/
|
|
Packit Service |
8264ee |
|
|
Packit Service |
8264ee |
#include <stdbool.h>
|
|
Packit Service |
8264ee |
#include <stdint.h>
|
|
Packit Service |
8264ee |
|
|
Packit Service |
8264ee |
/* Create a public key from a private key.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Inputs:
|
|
Packit Service |
8264ee |
* private_key - Your private key.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Outputs:
|
|
Packit Service |
8264ee |
* public_key - Will be filled in with the public key.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Returns true if the public key was generated successfully, false
|
|
Packit Service |
8264ee |
* if an error occurred. The keys are with the LSB first.
|
|
Packit Service |
8264ee |
*/
|
|
Packit Service |
8264ee |
bool ecc_make_public_key(const uint8_t private_key[32], uint8_t public_key[64]);
|
|
Packit Service |
8264ee |
|
|
Packit Service |
8264ee |
/* Create a public/private key pair.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Outputs:
|
|
Packit Service |
8264ee |
* public_key - Will be filled in with the public key.
|
|
Packit Service |
8264ee |
* private_key - Will be filled in with the private key.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Returns true if the key pair was generated successfully, false
|
|
Packit Service |
8264ee |
* if an error occurred. The keys are with the LSB first.
|
|
Packit Service |
8264ee |
*/
|
|
Packit Service |
8264ee |
bool ecc_make_key(uint8_t public_key[64], uint8_t private_key[32]);
|
|
Packit Service |
8264ee |
|
|
Packit Service |
8264ee |
/* Check to see if a public key is valid.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Inputs:
|
|
Packit Service |
8264ee |
* public_key - The public key to check.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Returns true if the public key is valid, false if it is invalid.
|
|
Packit Service |
8264ee |
*/
|
|
Packit Service |
8264ee |
bool ecc_valid_public_key(const uint8_t public_key[64]);
|
|
Packit Service |
8264ee |
|
|
Packit Service |
8264ee |
/* Compute a shared secret given your secret key and someone else's
|
|
Packit Service |
8264ee |
* public key.
|
|
Packit Service |
8264ee |
* Note: It is recommended that you hash the result of ecdh_shared_secret
|
|
Packit Service |
8264ee |
* before using it for symmetric encryption or HMAC.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Inputs:
|
|
Packit Service |
8264ee |
* public_key - The public key of the remote party.
|
|
Packit Service |
8264ee |
* private_key - Your private key.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Outputs:
|
|
Packit Service |
8264ee |
* secret - Will be filled in with the shared secret value.
|
|
Packit Service |
8264ee |
*
|
|
Packit Service |
8264ee |
* Returns true if the shared secret was generated successfully, false
|
|
Packit Service |
8264ee |
* if an error occurred. Both input and output parameters are with the
|
|
Packit Service |
8264ee |
* LSB first.
|
|
Packit Service |
8264ee |
*/
|
|
Packit Service |
8264ee |
bool ecdh_shared_secret(const uint8_t public_key[64],
|
|
Packit Service |
8264ee |
const uint8_t private_key[32],
|
|
Packit Service |
8264ee |
uint8_t secret[32]);
|