GNUnet 0.26.2-106-g126384b46
 
Loading...
Searching...
No Matches
crypto_kdf.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
28#include "platform.h"
29#include <gcrypt.h>
30
31
32#include "gnunet_util_lib.h"
33
34#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-kdf", __VA_ARGS__)
35
36
37void
39 gcry_mpi_t n,
40 const void *xts, size_t xts_len,
41 const void *skm, size_t skm_len,
42 const char *ctx)
43{
44 gcry_error_t rc;
45 unsigned int nbits;
46 size_t rsize;
47 uint16_t ctr;
48
49 nbits = gcry_mpi_get_nbits (n);
50 /* GNUNET_assert (nbits > 512); */
51 ctr = 0;
52 while (1)
53 {
54 /* Ain't clear if n is always divisible by 8 */
55 size_t bsize = (nbits - 1) / 8 + 1;
56 uint8_t buf[bsize];
57 uint16_t ctr_nbo = htons (ctr);
58
60 bsize,
61 xts, xts_len,
62 skm, skm_len,
65 ;
67 rc = gcry_mpi_scan (r,
68 GCRYMPI_FMT_USG,
69 (const unsigned char *) buf,
70 bsize,
71 &rsize);
72 GNUNET_assert (GPG_ERR_NO_ERROR == rc); /* Allocation error? */
73 GNUNET_assert (rsize == bsize);
74 gcry_mpi_clear_highbit (*r,
75 nbits);
76 GNUNET_assert (0 ==
77 gcry_mpi_test_bit (*r,
78 nbits));
79 ++ctr;
80 /* We reject this FDH if either *r > n and retry with another ctr */
81 if (0 > gcry_mpi_cmp (*r, n))
82 break;
83 gcry_mpi_release (*r);
84 }
85}
86
87
88/* end of crypto_kdf.c */
static struct GNUNET_FS_Handle * ctx
static unsigned int bsize
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
void GNUNET_CRYPTO_kdf_mod_mpi(gcry_mpi_t *r, gcry_mpi_t n, const void *xts, size_t xts_len, const void *skm, size_t skm_len, const char *ctx)
Deterministically generate a pseudo-random number uniformly from the integers modulo a libgcrypt mpi.
Definition crypto_kdf.c:38
#define GNUNET_CRYPTO_kdf_arg_string(d)
#define GNUNET_CRYPTO_kdf_arg_auto(d)
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.