wickr-crypto-c

crypto_engine.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 crypto_engine_h
23 #define crypto_engine_h
24
25 #include "buffer.h"
26 #include "cipher.h"
27 #include "digest.h"
28 #include "eckey.h"
29 #include "ecdsa.h"
30 #include "kdf.h"
31
32 #include <stdlib.h>
33 #include <stdio.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
53 struct wickr_crypto_engine {
54
55 wickr_ec_curve_t default_curve;
56 wickr_cipher_t default_cipher;
57
66 wickr_buffer_t *(*wickr_crypto_engine_crypto_random)(size_t len);
67
76 wickr_cipher_key_t *(*wickr_crypto_engine_cipher_key_random)(wickr_cipher_t cipher);
77
91 wickr_cipher_result_t *(*wickr_crypto_engine_cipher_encrypt)(const wickr_buffer_t *plaintext,
92 const wickr_buffer_t *aad,
93 const wickr_cipher_key_t *key,
94 const wickr_buffer_t *iv);
95
107 wickr_buffer_t *(*wickr_crypto_engine_cipher_decrypt)(const wickr_cipher_result_t *cipher_result,
108 const wickr_buffer_t *aad,
109 const wickr_cipher_key_t *key,
110 bool only_auth_ciphers);
111
122 bool (*wickr_crypto_engine_encrypt_file)(const wickr_cipher_key_t *key,
123 const char *sourceFilePath,
124 const char *destinationFilePath);
125
138 bool (*wickr_crypto_engine_decrypt_file)(const wickr_cipher_key_t *key,
139 const char *sourceFilePath,
140 const char *destinationFilePath,
141 bool only_auth_ciphers);
142
155 bool (*wickr_crypto_engine_encrypt_ofile)(FILE *fin,
156 const wickr_cipher_key_t *key,
157 FILE *fout);
158
171 bool (*wickr_crypto_engine_decrypt_ofile)(FILE *fin,
172 const wickr_cipher_key_t *key,
173 FILE *fout,
174 bool only_auth_ciphers);
175
187 wickr_buffer_t *(*wickr_crypto_engine_digest)(const wickr_buffer_t *buffer,
188 const wickr_buffer_t *salt,
189 wickr_digest_t digest_mode);
190
200 wickr_buffer_t *(*wickr_crypto_engine_digest_file)(FILE *in_file,
201 const wickr_digest_t mode);
202
211 wickr_ec_key_t *(*wickr_crypto_engine_ec_rand_key)(wickr_ec_curve_t curve);
212
222 wickr_ec_key_t *(*wickr_crypto_engine_ec_key_import)(const wickr_buffer_t *buffer,
223 bool is_private);
224
236 wickr_ecdsa_result_t *(*wickr_crypto_engine_ec_sign)(const wickr_ec_key_t *ec_signing_key,
237 const wickr_buffer_t *data_to_sign,
238 const wickr_digest_t digest_mode);
239
250 bool (*wickr_crypto_engine_ec_verify)(const wickr_ecdsa_result_t *signature,
251 const wickr_ec_key_t *ec_public_key,
252 const wickr_buffer_t *data_to_verify);
253
263 wickr_buffer_t *(*wickr_crypto_engine_gen_shared_secret)(const wickr_ec_key_t *local, const wickr_ec_key_t *peer);
264
275 wickr_buffer_t *(*wickr_crypto_engine_hmac_create)(const wickr_buffer_t *data,
276 const wickr_buffer_t *hmac_key,
277 wickr_digest_t digest_mode);
278
290 bool (*wickr_crypto_engine_hmac_verify)(const wickr_buffer_t *data,
291 const wickr_buffer_t *hmac_key,
292 const wickr_digest_t mode,
293 const wickr_buffer_t *expected);
294
305 wickr_kdf_result_t *(*wickr_crypto_kdf_gen)(wickr_kdf_algo_t algo,
306 const wickr_buffer_t *passphrase);
307
318 wickr_kdf_result_t *(*wickr_crypto_kdf_meta)(const wickr_kdf_meta_t *existing_meta,
319 const wickr_buffer_t *passphrase);
320 };
321
322 typedef struct wickr_crypto_engine wickr_crypto_engine_t;
323
331 const wickr_crypto_engine_t wickr_crypto_engine_get_default(void);
332
352 wickr_buffer_t *wickr_crypto_engine_kdf_cipher(const wickr_crypto_engine_t *engine,
353 wickr_kdf_algo_t algo,
354 wickr_cipher_t cipher,
355 const wickr_buffer_t *value,
356 const wickr_buffer_t *passphrase);
357
366 wickr_buffer_t *wickr_crypto_engine_kdf_decipher(const wickr_crypto_engine_t *engine,
367 const wickr_buffer_t *input_buffer,
368 const wickr_buffer_t *passphrase);
369
383 wickr_digest_t wickr_digest_matching_cipher(wickr_cipher_t cipher);
384
393 wickr_digest_t wickr_digest_matching_curve(wickr_ec_curve_t curve);
394
408 wickr_cipher_t wickr_exchange_cipher_matching_cipher(wickr_cipher_t cipher);
409
410 #ifdef __cplusplus
411 }
412 #endif
413
414 #endif /* crypto_engine_h */
wickr_crypto_engine::wickr_crypto_engine_hmac_verify
bool(* wickr_crypto_engine_hmac_verify)(const wickr_buffer_t *data, const wickr_buffer_t *hmac_key, const wickr_digest_t mode, const wickr_buffer_t *expected)
Definition: crypto_engine.h:290
wickr_digest_matching_curve
wickr_digest_t wickr_digest_matching_curve(wickr_ec_curve_t curve)
wickr_digest_matching_cipher
wickr_digest_t wickr_digest_matching_cipher(wickr_cipher_t cipher)
wickr_crypto_engine::wickr_crypto_engine_decrypt_file
bool(* wickr_crypto_engine_decrypt_file)(const wickr_cipher_key_t *key, const char *sourceFilePath, const char *destinationFilePath, bool only_auth_ciphers)
Definition: crypto_engine.h:138
wickr_crypto_engine_get_default
const wickr_crypto_engine_t wickr_crypto_engine_get_default(void)
wickr_crypto_engine::wickr_crypto_engine_encrypt_ofile
bool(* wickr_crypto_engine_encrypt_ofile)(FILE *fin, const wickr_cipher_key_t *key, FILE *fout)
Definition: crypto_engine.h:155
wickr_crypto_engine_kdf_cipher
wickr_buffer_t * wickr_crypto_engine_kdf_cipher(const wickr_crypto_engine_t *engine, wickr_kdf_algo_t algo, wickr_cipher_t cipher, const wickr_buffer_t *value, const wickr_buffer_t *passphrase)
wickr_crypto_engine::wickr_crypto_engine_encrypt_file
bool(* wickr_crypto_engine_encrypt_file)(const wickr_cipher_key_t *key, const char *sourceFilePath, const char *destinationFilePath)
Definition: crypto_engine.h:122
wickr_crypto_engine_kdf_decipher
wickr_buffer_t * wickr_crypto_engine_kdf_decipher(const wickr_crypto_engine_t *engine, const wickr_buffer_t *input_buffer, const wickr_buffer_t *passphrase)
wickr_crypto_engine::wickr_crypto_engine_ec_verify
bool(* wickr_crypto_engine_ec_verify)(const wickr_ecdsa_result_t *signature, const wickr_ec_key_t *ec_public_key, const wickr_buffer_t *data_to_verify)
Definition: crypto_engine.h:250
wickr_crypto_engine::wickr_crypto_engine_decrypt_ofile
bool(* wickr_crypto_engine_decrypt_ofile)(FILE *fin, const wickr_cipher_key_t *key, FILE *fout, bool only_auth_ciphers)
Definition: crypto_engine.h:171
wickr_exchange_cipher_matching_cipher
wickr_cipher_t wickr_exchange_cipher_matching_cipher(wickr_cipher_t cipher)
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_cipher
Represents a cipher that can be used in the crypto_engine. This meta object holds parameters for the ...
Definition: cipher.h:56
wickr_crypto_engine
Interface to a set of cryptographic operations used throughout the library. Currently the default imp...
Definition: crypto_engine.h:53
wickr_crypto_engine::default_curve
wickr_ec_curve_t default_curve
Definition: crypto_engine.h:55
wickr_crypto_engine::default_cipher
wickr_cipher_t default_cipher
Definition: crypto_engine.h:56
wickr_digest
Digest function parameters.
Definition: digest.h:54
wickr_ec_curve
Metadata about curve types to help with key generation, and signatures.
Definition: eckey.h:67
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_kdf_algo
Metadata associated with a particular KDF function.
Definition: kdf.h:71
wickr_kdf_meta
Represents the information the KDF function will need along with it's input to derive a particular ou...
Definition: kdf.h:135
wickr_kdf_result
Represents the result of a KDF function execution.
Definition: kdf.h:155