wickr-crypto-c

eckey.h
1 /*
2 * Copyright © 2012-2020 Wickr Inc. All rights reserved.
3 *
4 * This code is being released for EDUCATIONAL, ACADEMIC, AND CODE REVIEW PURPOSES
5 * ONLY. COMMERCIAL USE OF THE CODE IS EXPRESSLY PROHIBITED. For additional details,
6 * please see LICENSE
7 *
8 * THE CODE IS MADE AVAILABLE "AS-IS" AND WITHOUT ANY EXPRESS OR
9 * IMPLIED GUARANTEES AS TO FITNESS, MERCHANTABILITY, NON-
10 * INFRINGEMENT OR OTHERWISE. IT IS NOT BEING PROVIDED IN TRADE BUT ON
11 * A VOLUNTARY BASIS ON BEHALF OF THE AUTHOR’S PART FOR THE BENEFIT
12 * OF THE LICENSEE AND IS NOT MADE AVAILABLE FOR CONSUMER USE OR ANY
13 * OTHER USE OUTSIDE THE TERMS OF THIS LICENSE. ANYONE ACCESSING THE
14 * CODE SHOULD HAVE THE REQUISITE EXPERTISE TO SECURE THEIR SYSTEM
15 * AND DEVICES AND TO ACCESS AND USE THE CODE FOR REVIEW PURPOSES
16 * ONLY. LICENSEE BEARS THE RISK OF ACCESSING AND USING THE CODE. IN
17 * PARTICULAR, AUTHOR BEARS NO LIABILITY FOR ANY INTERFERENCE WITH OR
18 * ADVERSE EFFECT THAT MAY OCCUR AS A RESULT OF THE LICENSEE
19 * ACCESSING AND/OR USING THE CODE ON LICENSEE’S SYSTEM.
20 */
21
22 #ifndef eckey_h
23 #define eckey_h
24
25 #include <stdlib.h>
26 #include "buffer.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
38 #define P521_SIGNATURE_MAX_SIZE 143
39
44 #define P521_PUB_KEY_MAX_SIZE 134
45
46 typedef enum { EC_CURVE_ID_NIST_P521 } wickr_ec_curve_id;
47
67 struct wickr_ec_curve {
68 wickr_ec_curve_id identifier;
69 uint8_t signature_size;
70 uint8_t max_pub_size;
71 };
72
73 typedef struct wickr_ec_curve wickr_ec_curve_t;
74
75 static const wickr_ec_curve_t EC_CURVE_NIST_P521 = { EC_CURVE_ID_NIST_P521, P521_SIGNATURE_MAX_SIZE, P521_PUB_KEY_MAX_SIZE };
76
92 struct wickr_ec_key {
93 wickr_ec_curve_t curve;
94 wickr_buffer_t *pub_data;
95 wickr_buffer_t *pri_data;
96 };
97
98 typedef struct wickr_ec_key wickr_ec_key_t;
99
113 wickr_ec_key_t *wickr_ec_key_create(wickr_ec_curve_t curve, wickr_buffer_t *pub_data, wickr_buffer_t *pri_data);
114
124 wickr_ec_key_t *wickr_ec_key_copy(const wickr_ec_key_t *source);
125
134 void wickr_ec_key_destroy(wickr_ec_key_t **key);
135
146 wickr_buffer_t *wickr_ec_key_get_pubdata_fixed_len(const wickr_ec_key_t *key);
147
157 const wickr_ec_curve_t *wickr_ec_curve_find(uint8_t identifier);
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif /* eckey_h */
wickr_ec_curve_find
const wickr_ec_curve_t * wickr_ec_curve_find(uint8_t identifier)
wickr_ec_key_create
wickr_ec_key_t * wickr_ec_key_create(wickr_ec_curve_t curve, wickr_buffer_t *pub_data, wickr_buffer_t *pri_data)
wickr_ec_key_destroy
void wickr_ec_key_destroy(wickr_ec_key_t **key)
wickr_ec_key_copy
wickr_ec_key_t * wickr_ec_key_copy(const wickr_ec_key_t *source)
wickr_buffer
Represents an array of bytes and the length of the allocation associated with those bytes.
Definition: buffer.h:51
wickr_ec_curve
Metadata about curve types to help with key generation, and signatures.
Definition: eckey.h:67
wickr_ec_curve::max_pub_size
uint8_t max_pub_size
Definition: eckey.h:70
wickr_ec_curve::identifier
wickr_ec_curve_id identifier
Definition: eckey.h:68
wickr_ec_curve::signature_size
uint8_t signature_size
Definition: eckey.h:69
wickr_ec_key
Representation of public and private Elliptic Curve Keypair information as buffers.
Definition: eckey.h:92
wickr_ec_key::curve
wickr_ec_curve_t curve
Definition: eckey.h:93
wickr_ec_key::pri_data
wickr_buffer_t * pri_data
Definition: eckey.h:95
wickr_ec_key::pub_data
wickr_buffer_t * pub_data
Definition: eckey.h:94