source: trunk/libtransmission/crypto-utils-fallback.c

Last change on this file was 14370, checked in by mikedld, 6 years ago

Fix a couple of ordinary and pedantic warnings

Add previously missing -Wall to warning flags in CMake. Remove -Wformat
and -Wvariadic-macros (enabled by default; latter is not meaningful in
C99 mode we use), -Wdeclaration-after-statement (again, not needed as
we use C99). Move -Wmissing-declarations to C-only flags (GCC man says
so).

Add copyrights year to crypto-utils-fallback.c.

  • Property svn:keywords set to Date Rev Author Id
File size: 1.9 KB
Line 
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 * $Id: crypto-utils-fallback.c 14370 2014-12-11 05:11:02Z mikedld $
8 */
9
10/* This file is designed specifically to be included by other source files to
11   implement missing (or duplicate) functionality without exposing internal
12   details in header files. */
13
14#include <assert.h>
15
16#include "transmission.h"
17#include "crypto-utils.h"
18#include "utils.h"
19
20/***
21****
22***/
23
24#ifdef TR_CRYPTO_DH_SECRET_FALLBACK
25
26/* Most Diffie-Hellman backends handle secret key in the very same way: by
27   manually allocating memory for it and storing the value in plain form. */
28
29struct tr_dh_secret
30{
31  size_t  key_length;
32  uint8_t key[];
33};
34
35static struct tr_dh_secret *
36tr_dh_secret_new (size_t key_length)
37{
38  struct tr_dh_secret * handle = tr_malloc (sizeof (struct tr_dh_secret) + key_length);
39  handle->key_length = key_length;
40  return handle;
41}
42
43static void
44tr_dh_secret_align (struct tr_dh_secret * handle,
45                    size_t                current_key_length)
46{
47  tr_dh_align_key (handle->key, current_key_length, handle->key_length);
48}
49
50bool
51tr_dh_secret_derive (tr_dh_secret_t   raw_handle,
52                     const void     * prepend_data,
53                     size_t           prepend_data_size,
54                     const void     * append_data,
55                     size_t           append_data_size,
56                     uint8_t        * hash)
57{
58  struct tr_dh_secret * handle = raw_handle;
59
60  assert (handle != NULL);
61  assert (hash != NULL);
62
63  return tr_sha1 (hash,
64                  prepend_data == NULL ? "" : prepend_data,
65                  prepend_data == NULL ? 0 : (int) prepend_data_size,
66                  handle->key, (int) handle->key_length,
67                  append_data, append_data == NULL ? 0 : (int) append_data_size,
68                  NULL);
69}
70
71void
72tr_dh_secret_free (tr_dh_secret_t handle)
73{
74  tr_free (handle);
75}
76
77#endif /* TR_CRYPTO_DH_SECRET_FALLBACK */
Note: See TracBrowser for help on using the repository browser.