OlinCoin
Test
crypto.h
1#pragma once
2
3#include "mbedtls/entropy.h"
4#include "mbedtls/ctr_drbg.h"
5#include "mbedtls/ecdsa.h"
6
7#define CURVE MBEDTLS_ECP_DP_SECP256K1
8
9/* KEY GENERATION */
10
16void init_entropy();
17
23void free_entropy();
24
33mbedtls_ecdsa_context *gen_keys();
34
35/* SIGNATURE HANDLING */
36
49size_t write_sig(
50 unsigned char *dest, size_t dest_len,
51 unsigned char *hash, size_t hash_len,
52 mbedtls_ecdsa_context *keys
53);
54
67int validate_sig(
68 unsigned char *sig, size_t sig_len,
69 unsigned char *hash, size_t hash_len,
70 mbedtls_ecdsa_context *key_pair
71);
72
80void build_ctx_from_public(mbedtls_ecdsa_context *ctx, mbedtls_ecp_point *pub_key);
81
82/* HASHING */
83
92int hash_sha256(unsigned char *output_hash, unsigned char *input_data, size_t input_sz);
93
100void hash_pub_key(unsigned char *dest, mbedtls_ecdsa_context *key_pair);
101
102
103/* MISC */
104
119void dump_buf(char *prefix, const char *title, const unsigned char *buf, size_t len);
120
121/* GLOBALS */
122
123extern char *seed;
124extern mbedtls_entropy_context *entropy;
125extern mbedtls_ctr_drbg_context *ctr_drbg;