1 /*
2 * This file Copyright (C) 2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 */
8
9 /* This file is designed specifically to be included by other source files to
10 implement missing (or duplicate) functionality without exposing internal
11 details in header files. */
12
13 #include "transmission.h"
14 #include "crypto-utils.h"
15 #include "tr-assert.h"
16 #include "utils.h"
17
18 /***
19 ****
20 ***/
21
22 #ifdef TR_CRYPTO_DH_SECRET_FALLBACK
23
24 /* Most Diffie-Hellman backends handle secret key in the very same way: by
25 manually allocating memory for it and storing the value in plain form. */
26
27 struct tr_dh_secret
28 {
29 size_t key_length;
30 uint8_t key[];
31 };
32
tr_dh_secret_new(size_t key_length)33 static struct tr_dh_secret* tr_dh_secret_new(size_t key_length)
34 {
35 struct tr_dh_secret* handle = tr_malloc(sizeof(struct tr_dh_secret) + key_length);
36 handle->key_length = key_length;
37 return handle;
38 }
39
tr_dh_secret_align(struct tr_dh_secret * handle,size_t current_key_length)40 static void tr_dh_secret_align(struct tr_dh_secret* handle, size_t current_key_length)
41 {
42 tr_dh_align_key(handle->key, current_key_length, handle->key_length);
43 }
44
tr_dh_secret_derive(tr_dh_secret_t raw_handle,void const * prepend_data,size_t prepend_data_size,void const * append_data,size_t append_data_size,uint8_t * hash)45 bool tr_dh_secret_derive(tr_dh_secret_t raw_handle, void const* prepend_data, size_t prepend_data_size, void const* append_data,
46 size_t append_data_size, uint8_t* hash)
47 {
48 TR_ASSERT(raw_handle != NULL);
49 TR_ASSERT(hash != NULL);
50
51 struct tr_dh_secret* handle = raw_handle;
52
53 return tr_sha1(hash, prepend_data == NULL ? "" : prepend_data, prepend_data == NULL ? 0 : (int)prepend_data_size,
54 handle->key, (int)handle->key_length, append_data, append_data == NULL ? 0 : (int)append_data_size, NULL);
55 }
56
tr_dh_secret_free(tr_dh_secret_t handle)57 void tr_dh_secret_free(tr_dh_secret_t handle)
58 {
59 tr_free(handle);
60 }
61
62 #endif /* TR_CRYPTO_DH_SECRET_FALLBACK */
63
64 #ifdef TR_CRYPTO_X509_FALLBACK
65
tr_ssl_get_x509_store(tr_ssl_ctx_t handle)66 tr_x509_store_t tr_ssl_get_x509_store(tr_ssl_ctx_t handle)
67 {
68 (void)handle;
69
70 return NULL;
71 }
72
tr_x509_store_add(tr_x509_store_t handle,tr_x509_cert_t cert)73 bool tr_x509_store_add(tr_x509_store_t handle, tr_x509_cert_t cert)
74 {
75 (void)handle;
76 (void)cert;
77
78 return false;
79 }
80
tr_x509_cert_new(void const * der,size_t der_length)81 tr_x509_cert_t tr_x509_cert_new(void const* der, size_t der_length)
82 {
83 (void)der;
84 (void)der_length;
85
86 return NULL;
87 }
88
tr_x509_cert_free(tr_x509_cert_t handle)89 void tr_x509_cert_free(tr_x509_cert_t handle)
90 {
91 (void)handle;
92 }
93
94 #endif /* TR_CRYPTO_X509_FALLBACK */
95