wickr-crypto-c

key_exchange.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 key_exchange_h
23 #define key_exchange_h
24
25 #include "buffer.h"
26 #include "eckey.h"
27 #include "crypto_engine.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
53 struct wickr_key_exchange {
54 wickr_buffer_t *exchange_id;
55 uint64_t key_id;
56 wickr_cipher_result_t *exchange_ciphertext;
57 };
58
59 typedef struct wickr_key_exchange wickr_key_exchange_t;
60
72 wickr_key_exchange_t *wickr_key_exchange_create(wickr_buffer_t *exchange_id,
73 uint64_t key_id,
74 wickr_cipher_result_t *exchange_ciphertext);
75
76
86 wickr_key_exchange_t *wickr_key_exchange_copy(const wickr_key_exchange_t *source);
87
96 void wickr_key_exchange_destroy(wickr_key_exchange_t **exchange);
97
98 typedef wickr_array_t wickr_exchange_array_t;
99
109 wickr_exchange_array_t *wickr_exchange_array_new(uint32_t exchange_count);
110
123 bool wickr_exchange_array_set_item(wickr_exchange_array_t *array, uint32_t index, wickr_key_exchange_t *exchange);
124
136 wickr_key_exchange_t *wickr_exchange_array_fetch_item(wickr_exchange_array_t *array, uint32_t index);
137
144 wickr_array_t *wickr_exchange_array_copy(wickr_exchange_array_t *array);
145
151 void wickr_exchange_array_destroy(wickr_exchange_array_t **array);
152
169 struct wickr_key_exchange_set {
170 wickr_ec_key_t *sender_pub;
171 wickr_exchange_array_t *exchanges;
172 };
173
174 typedef struct wickr_key_exchange_set wickr_key_exchange_set_t;
175
185 wickr_key_exchange_set_t *wickr_key_exchange_set_create(wickr_ec_key_t *sender_pub, wickr_exchange_array_t *exchanges);
186
196 wickr_key_exchange_t *wickr_key_exchange_set_find(const wickr_key_exchange_set_t *exchange_set,
197 const wickr_buffer_t *identifier);
198
208 wickr_key_exchange_set_t *wickr_key_exchange_set_copy(const wickr_key_exchange_set_t *source);
209
219 void wickr_key_exchange_set_destroy(wickr_key_exchange_set_t **exchange_set);
220
230 wickr_buffer_t *wickr_key_exchange_set_serialize(const wickr_key_exchange_set_t *exchange_set);
231
242 wickr_key_exchange_set_t *wickr_key_exchange_set_create_from_buffer(const wickr_crypto_engine_t *engine,
243 const wickr_buffer_t *buffer);
244
260 wickr_cipher_result_t *wickr_key_exchange_set_encrypt(const wickr_key_exchange_set_t *exchange_set,
261 const wickr_crypto_engine_t *engine,
262 const wickr_cipher_key_t *header_key);
263
276 wickr_key_exchange_set_t *wickr_key_exchange_set_create_from_cipher(const wickr_crypto_engine_t *engine,
277 const wickr_cipher_result_t *cipher_result,
278 const wickr_cipher_key_t *header_key);
279
280 #ifdef __cplusplus
281 }
282 #endif
283
284 #endif /* key_exchange_h */
wickr_key_exchange_set_copy
wickr_key_exchange_set_t * wickr_key_exchange_set_copy(const wickr_key_exchange_set_t *source)
wickr_key_exchange_set_create_from_cipher
wickr_key_exchange_set_t * wickr_key_exchange_set_create_from_cipher(const wickr_crypto_engine_t *engine, const wickr_cipher_result_t *cipher_result, const wickr_cipher_key_t *header_key)
wickr_key_exchange_set_create
wickr_key_exchange_set_t * wickr_key_exchange_set_create(wickr_ec_key_t *sender_pub, wickr_exchange_array_t *exchanges)
wickr_key_exchange_set_destroy
void wickr_key_exchange_set_destroy(wickr_key_exchange_set_t **exchange_set)
wickr_key_exchange_set_find
wickr_key_exchange_t * wickr_key_exchange_set_find(const wickr_key_exchange_set_t *exchange_set, const wickr_buffer_t *identifier)
wickr_key_exchange_set_encrypt
wickr_cipher_result_t * wickr_key_exchange_set_encrypt(const wickr_key_exchange_set_t *exchange_set, const wickr_crypto_engine_t *engine, const wickr_cipher_key_t *header_key)
wickr_key_exchange_set_create_from_buffer
wickr_key_exchange_set_t * wickr_key_exchange_set_create_from_buffer(const wickr_crypto_engine_t *engine, const wickr_buffer_t *buffer)
wickr_key_exchange_set_serialize
wickr_buffer_t * wickr_key_exchange_set_serialize(const wickr_key_exchange_set_t *exchange_set)
wickr_key_exchange_create
wickr_key_exchange_t * wickr_key_exchange_create(wickr_buffer_t *exchange_id, uint64_t key_id, wickr_cipher_result_t *exchange_ciphertext)
wickr_key_exchange_copy
wickr_key_exchange_t * wickr_key_exchange_copy(const wickr_key_exchange_t *source)
wickr_exchange_array_fetch_item
wickr_key_exchange_t * wickr_exchange_array_fetch_item(wickr_exchange_array_t *array, uint32_t index)
wickr_key_exchange_destroy
void wickr_key_exchange_destroy(wickr_key_exchange_t **exchange)
wickr_exchange_array_new
wickr_exchange_array_t * wickr_exchange_array_new(uint32_t exchange_count)
wickr_exchange_array_copy
wickr_array_t * wickr_exchange_array_copy(wickr_exchange_array_t *array)
wickr_exchange_array_set_item
bool wickr_exchange_array_set_item(wickr_exchange_array_t *array, uint32_t index, wickr_key_exchange_t *exchange)
wickr_exchange_array_destroy
void wickr_exchange_array_destroy(wickr_exchange_array_t **array)
wickr_buffer
Represents an array of bytes and the length of the allocation associated with those bytes.
Definition: buffer.h:51
wickr_cipher_key
Definition: cipher.h:189
wickr_cipher_result
Definition: cipher.h:97
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_key_exchange_set
A collection of key exchanges for a set of recipients. The data protected inside 'exchange_ciphertext...
Definition: key_exchange.h:169
wickr_key_exchange_set::exchanges
wickr_exchange_array_t * exchanges
Definition: key_exchange.h:171
wickr_key_exchange_set::sender_pub
wickr_ec_key_t * sender_pub
Definition: key_exchange.h:170
wickr_key_exchange
Public key exchange protected data. After a shared secret is generated using a public key with identi...
Definition: key_exchange.h:53
wickr_key_exchange::exchange_id
wickr_buffer_t * exchange_id
Definition: key_exchange.h:54
wickr_key_exchange::exchange_ciphertext
wickr_cipher_result_t * exchange_ciphertext
Definition: key_exchange.h:56
wickr_key_exchange::key_id
uint64_t key_id
Definition: key_exchange.h:55