A simple and secure ECDH and ECDSA library.
I recommend just copying (or symlink) ecc.h and ecc.c into your project. Then just #include "ecc.h"
to use the easy-ecc functions.
int ecc_make_key(
uint8_t p_publicKey[ECC_BYTES+1],
uint8_t p_privateKey[ECC_BYTES]
);
Create a public/private key pair.
Outputs:
p_publicKey
- Will be filled in with the public key.p_privateKey
- Will be filled in with the private key.Returns 1 if the key pair was generated successfully, 0 if an error occurred.
int ecdh_shared_secret(
const uint8_t p_publicKey[ECC_BYTES+1],
const uint8_t p_privateKey[ECC_BYTES],
uint8_t p_secret[ECC_BYTES]
);
Compute a shared secret given your secret key and someone else's public key.
Note: It is recommended that you hash the result of ecdh_shared_secret
before using it for symmetric encryption or HMAC.
Inputs:
p_publicKey
- The public key of the remote party.p_privateKey
- Your private key.Outputs:
p_secret
- Will be filled in with the shared secret value.Returns 1 if the shared secret was generated successfully, 0 if an error occurred.
int ecdsa_sign(
const uint8_t p_privateKey[ECC_BYTES],
const uint8_t p_hash[ECC_BYTES],
uint8_t p_signature[ECC_BYTES*2]
);
Generate an ECDSA signature for a given hash value.
Usage: Compute a hash of the data you wish to sign (SHA-2 is recommended) and pass it in to this function along with your private key.
Inputs:
p_privateKey
- Your private key.p_hash
- The message hash to sign.Outputs:
p_signature
- Will be filled in with the signature value.Returns 1 if the signature generated successfully, 0 if an error occurred.
int ecdsa_verify(
const uint8_t p_publicKey[ECC_BYTES+1],
const uint8_t p_hash[ECC_BYTES],
const uint8_t p_signature[ECC_BYTES*2]
);
Verify an ECDSA signature.
Usage: Compute the hash of the signed data using the same hash as the signer and pass it to this function along with the signer's public key and the signature values (r and s).
Inputs:
p_publicKey
- The signer's public key
p_hash
- The hash of the signed data.
p_signature
- The signature value.
Returns 1 if the signature is valid, 0 if it is invalid.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。