libbtc
bitcoinclibrary
ecc_key.h
Go to the documentation of this file.
1 /*
2 
3  The MIT License (MIT)
4 
5  Copyright (c) 2015 Jonas Schnelli
6 
7  Permission is hereby granted, free of charge, to any person obtaining
8  a copy of this software and associated documentation files (the "Software"),
9  to deal in the Software without restriction, including without limitation
10  the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  and/or sell copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following conditions:
13 
14  The above copyright notice and this permission notice shall be included
15  in all copies or substantial portions of the Software.
16 
17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  OTHER DEALINGS IN THE SOFTWARE.
24 
25 */
26 
27 #ifndef __LIBBTC_ECC_KEY_H__
28 #define __LIBBTC_ECC_KEY_H__
29 
30 #include "btc.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdio.h>
37 #include <stdint.h>
38 
39 typedef struct btc_key_
40 {
42 } btc_key;
43 
44 typedef struct btc_pubkey_
45 {
48 } btc_pubkey;
49 
50 LIBBTC_API void btc_privkey_init(btc_key* privkey);
53 LIBBTC_API void btc_privkey_gen(btc_key* privkey);
55 
59 LIBBTC_API void btc_pubkey_from_key(btc_key* privkey, btc_pubkey* pubkey_inout);
60 LIBBTC_API void btc_pubkey_get_hash160(const btc_pubkey* pubkey, uint8_t *hash160);
61 
62 //sign a 32byte message/hash and returns a DER encoded signature (through *sigout)
63 LIBBTC_API btc_bool btc_key_sign_hash(const btc_key* privkey, const uint8_t* hash, unsigned char* sigout, size_t* outlen);
64 
65 //verifies a DER encoded signature with given pubkey and return true if valid
66 LIBBTC_API btc_bool btc_pubkey_verify_sig(const btc_pubkey* pubkey, const uint8_t* hash, unsigned char* sigder, int len);
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 #endif //__LIBBTC_ECC_KEY_H__
uint8_t btc_bool
Definition: btc.h:34
#define LIBBTC_API
Definition: btc.h:59
struct btc_pubkey_ btc_pubkey
#define BTC_ECKEY_PKEY_LENGTH
Definition: btc.h:70
LIBBTC_API void btc_pubkey_get_hash160(const btc_pubkey *pubkey, uint8_t *hash160)
Definition: ecc_key.c:112
LIBBTC_API void btc_pubkey_init(btc_pubkey *pubkey)
Definition: ecc_key.c:87
LIBBTC_API void btc_pubkey_cleanse(btc_pubkey *pubkey)
Definition: ecc_key.c:103
LIBBTC_API btc_bool btc_pubkey_verify_sig(const btc_pubkey *pubkey, const uint8_t *hash, unsigned char *sigder, int len)
Definition: ecc_key.c:136
LIBBTC_API void btc_pubkey_from_key(btc_key *privkey, btc_pubkey *pubkey_inout)
Definition: ecc_key.c:118
#define BTC_ECKEY_UNCOMPRESSED_LENGTH
Definition: btc.h:67
LIBBTC_API btc_bool btc_privkey_is_valid(btc_key *privkey)
Definition: ecc_key.c:48
LIBBTC_API void btc_privkey_cleanse(btc_key *privkey)
Definition: ecc_key.c:54
LIBBTC_API void btc_privkey_init(btc_key *privkey)
Definition: ecc_key.c:42
LIBBTC_API btc_bool btc_key_sign_hash(const btc_key *privkey, const uint8_t *hash, unsigned char *sigout, size_t *outlen)
Definition: ecc_key.c:130
struct btc_key_ btc_key
LIBBTC_API btc_bool btc_pubkey_is_valid(btc_pubkey *pubkey)
Definition: ecc_key.c:97
LIBBTC_API void btc_privkey_gen(btc_key *privkey)
Definition: ecc_key.c:60
LIBBTC_API btc_bool btc_privkey_verify_pubkey(btc_key *privkey, btc_pubkey *pubkey)
Definition: ecc_key.c:71
btc_bool compressed
Definition: ecc_key.h:46
uint8_t pubkey[BTC_ECKEY_UNCOMPRESSED_LENGTH]
Definition: ecc_key.h:47
uint8_t privkey[BTC_ECKEY_PKEY_LENGTH]
Definition: ecc_key.h:41