wickr-crypto-c

identity.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 identity_h
23 #define identity_h
24
25 #include <stdlib.h>
26 #include "buffer.h"
27 #include "eckey.h"
28 #include "ecdsa.h"
29 #include "crypto_engine.h"
30 #include "root_keys.h"
31 #include "fingerprint.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
44 #define IDENTIFIER_LEN 32
45
49 #define MAX_IDENTIFIER_LEN 128
50
51
52 /* Define ROOT and NODE identity types */
53 typedef enum { IDENTITY_TYPE_ROOT, IDENTITY_TYPE_NODE } wickr_identity_type;
54
66 typedef enum { IDENTITY_CHAIN_STATUS_UNKNOWN, IDENTITY_CHAIN_STATUS_VALID, IDENTITY_CHAIN_STATUS_INVALID } wickr_identity_chain_status;
67
90 struct wickr_identity {
91 wickr_identity_type type;
92 wickr_buffer_t *identifier;
93 wickr_ec_key_t *sig_key;
94 wickr_ecdsa_result_t *signature;
95 };
96
97 typedef struct wickr_identity wickr_identity_t;
98
116 struct wickr_identity_chain {
117 wickr_identity_chain_status status;
118 wickr_identity_t *root;
119 wickr_identity_t *node;
120 wickr_buffer_t *_status_cache;
121 };
122
123 typedef struct wickr_identity_chain wickr_identity_chain_t;
124
137 wickr_identity_t *wickr_identity_create(wickr_identity_type type, wickr_buffer_t *identifier, wickr_ec_key_t *sig_key, wickr_ecdsa_result_t *signature);
138
150 wickr_ecdsa_result_t *wickr_identity_sign(const wickr_identity_t *identity, const wickr_crypto_engine_t *engine, const wickr_buffer_t *data);
151
163 wickr_identity_t *wickr_node_identity_gen(const wickr_crypto_engine_t *engine, const wickr_identity_t *root_identity, const wickr_buffer_t *identifier);
164
174 wickr_identity_t *wickr_identity_copy(const wickr_identity_t *source);
175
184 void wickr_identity_destroy(wickr_identity_t **identity);
185
195 wickr_buffer_t *wickr_identity_serialize(const wickr_identity_t *identity);
196
197
198
209 wickr_identity_t *wickr_identity_create_from_buffer(const wickr_buffer_t *buffer, const wickr_crypto_engine_t *engine);
210
221 wickr_fingerprint_t *wickr_identity_get_fingerprint(const wickr_identity_t *identity,
222 wickr_crypto_engine_t engine);
223
224
238 wickr_fingerprint_t *wickr_identity_get_bilateral_fingerprint(const wickr_identity_t *identity,
239 const wickr_identity_t *remote_identity,
240 wickr_crypto_engine_t engine);
241
251 wickr_buffer_t *wickr_identity_chain_serialize(const wickr_identity_chain_t *identity_chain);
252
263 wickr_buffer_t *wickr_identity_chain_serialize_private(const wickr_identity_chain_t *identity_chain);
264
275 wickr_identity_chain_t *wickr_identity_chain_create_from_buffer(const wickr_buffer_t *buffer, const wickr_crypto_engine_t *engine);
276
287 wickr_identity_chain_t *wickr_identity_chain_create(wickr_identity_t *root, wickr_identity_t *node);
288
298 wickr_identity_chain_t *wickr_identity_chain_copy(const wickr_identity_chain_t *source);
299
310 bool wickr_identity_chain_validate(wickr_identity_chain_t *chain, const wickr_crypto_engine_t *engine);
311
320 void wickr_identity_chain_destroy(wickr_identity_chain_t **chain);
321
322 #ifdef __cplusplus
323 }
324 #endif
325
326 #endif /* identity_h */
wickr_identity_copy
wickr_identity_t * wickr_identity_copy(const wickr_identity_t *source)
wickr_identity_sign
wickr_ecdsa_result_t * wickr_identity_sign(const wickr_identity_t *identity, const wickr_crypto_engine_t *engine, const wickr_buffer_t *data)
wickr_identity_create_from_buffer
wickr_identity_t * wickr_identity_create_from_buffer(const wickr_buffer_t *buffer, const wickr_crypto_engine_t *engine)
wickr_identity_chain_validate
bool wickr_identity_chain_validate(wickr_identity_chain_t *chain, const wickr_crypto_engine_t *engine)
wickr_identity_get_fingerprint
wickr_fingerprint_t * wickr_identity_get_fingerprint(const wickr_identity_t *identity, wickr_crypto_engine_t engine)
wickr_identity_create
wickr_identity_t * wickr_identity_create(wickr_identity_type type, wickr_buffer_t *identifier, wickr_ec_key_t *sig_key, wickr_ecdsa_result_t *signature)
wickr_identity_chain_status
wickr_identity_chain_status
Definition: identity.h:66
wickr_identity_chain_create
wickr_identity_chain_t * wickr_identity_chain_create(wickr_identity_t *root, wickr_identity_t *node)
wickr_identity_serialize
wickr_buffer_t * wickr_identity_serialize(const wickr_identity_t *identity)
wickr_identity_get_bilateral_fingerprint
wickr_fingerprint_t * wickr_identity_get_bilateral_fingerprint(const wickr_identity_t *identity, const wickr_identity_t *remote_identity, wickr_crypto_engine_t engine)
wickr_identity_destroy
void wickr_identity_destroy(wickr_identity_t **identity)
wickr_node_identity_gen
wickr_identity_t * wickr_node_identity_gen(const wickr_crypto_engine_t *engine, const wickr_identity_t *root_identity, const wickr_buffer_t *identifier)
wickr_identity_chain_copy
wickr_identity_chain_t * wickr_identity_chain_copy(const wickr_identity_chain_t *source)
wickr_identity_chain_destroy
void wickr_identity_chain_destroy(wickr_identity_chain_t **chain)
wickr_buffer
Represents an array of bytes and the length of the allocation associated with those bytes.
Definition: buffer.h:51
wickr_crypto_engine
Interface to a set of cryptographic operations used throughout the library. Currently the default imp...
Definition: crypto_engine.h:53
wickr_ec_key
Representation of public and private Elliptic Curve Keypair information as buffers.
Definition: eckey.h:92
wickr_ecdsa_result
Elliptic Curve Digital Signature Algorithm Result.
Definition: ecdsa.h:54
wickr_fingerprint
A fingerprint representation of a combination of signature keys / identifiers.
Definition: fingerprint.h:75
wickr_identity_chain
Represents a root -> node relationship as well as it's signature status.
Definition: identity.h:116
wickr_identity_chain::root
wickr_identity_t * root
Definition: identity.h:118
wickr_identity_chain::node
wickr_identity_t * node
Definition: identity.h:119
wickr_identity_chain::_status_cache
wickr_buffer_t * _status_cache
Definition: identity.h:120
wickr_identity_chain::status
wickr_identity_chain_status status
Definition: identity.h:117
wickr_identity
A signing identity on the Wickr system.
Definition: identity.h:90
wickr_identity::type
wickr_identity_type type
Definition: identity.h:91
wickr_identity::sig_key
wickr_ec_key_t * sig_key
Definition: identity.h:93
wickr_identity::identifier
wickr_buffer_t * identifier
Definition: identity.h:92
wickr_identity::signature
wickr_ecdsa_result_t * signature
Definition: identity.h:94