GNUnet  0.10.x
Macros | Functions
crypto_hkdf.c File Reference

Hash-based KDF as defined in RFC 5869. More...

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "benchmark.h"
#include <gcrypt.h>
Include dependency graph for crypto_hkdf.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-crypto-hkdf", __VA_ARGS__)
 
#define GNUNET_BUILD   1
 Set this to 0 if you compile this code outside of GNUnet. More...
 
#define DEBUG_HKDF   0
 Enable debugging. More...
 

Functions

static const void * doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf, size_t buf_len)
 Compute the HMAC. More...
 
static int getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm, size_t skm_len, void *prk)
 Generate pseudo-random key. More...
 
int GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
 Derive key. More...
 
int GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
 Derive key. More...
 

Detailed Description

Hash-based KDF as defined in RFC 5869.

See also
http://www.rfc-editor.org/rfc/rfc5869.txt
Todo:
remove GNUNET references
Author
Nils Durner

The following list of people have reviewed this code and considered it correct on the date given (if you reviewed it, please have your name added to the list):

Definition in file crypto_hkdf.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-crypto-hkdf", __VA_ARGS__)

Definition at line 39 of file crypto_hkdf.c.

◆ GNUNET_BUILD

#define GNUNET_BUILD   1

Set this to 0 if you compile this code outside of GNUnet.

Definition at line 44 of file crypto_hkdf.c.

◆ DEBUG_HKDF

#define DEBUG_HKDF   0

Enable debugging.

Definition at line 49 of file crypto_hkdf.c.

Function Documentation

◆ doHMAC()

static const void* doHMAC ( gcry_md_hd_t  mac,
const void *  key,
size_t  key_len,
const void *  buf,
size_t  buf_len 
)
static

Compute the HMAC.

Todo:
use chunked buffers
Parameters
macgcrypt MAC handle
keyHMAC key
key_lenlength of key
bufmessage to be processed
buf_lenlength of buf
Returns
HMAC, freed by caller via gcry_md_close/_reset

Definition at line 78 of file crypto_hkdf.c.

Referenced by getPRK(), and GNUNET_CRYPTO_hkdf_v().

80 {
81  gcry_md_setkey (mac, key, key_len);
82  gcry_md_write (mac, buf, buf_len);
83 
84  return (const void *) gcry_md_read (mac, 0);
85 }
static char buf[2048]
struct GNUNET_HashCode key
The key used in the DHT.
Here is the caller graph for this function:

◆ getPRK()

static int getPRK ( gcry_md_hd_t  mac,
const void *  xts,
size_t  xts_len,
const void *  skm,
size_t  skm_len,
void *  prk 
)
static

Generate pseudo-random key.

Parameters
macgcrypt HMAC handle
xtssalt
xts_lenlength of the xts salt
skmsource key material
skm_lenlength of skm
prkresult buffer (allocated by caller; at least gcry_md_dlen() bytes)
Returns
GNUNET_YES on success

Definition at line 98 of file crypto_hkdf.c.

References doHMAC(), dump, GNUNET_memcpy, GNUNET_SYSERR, GNUNET_YES, l, p, and ret.

Referenced by GNUNET_CRYPTO_hkdf_v().

100 {
101  const void *ret;
102 
103  ret = doHMAC (mac, xts, xts_len, skm, skm_len);
104  if (ret == NULL)
105  return GNUNET_SYSERR;
106  GNUNET_memcpy (prk, ret, gcry_md_get_algo_dlen (gcry_md_get_algo (mac)));
107 
108  return GNUNET_YES;
109 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
static const void * doHMAC(gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf, size_t buf_len)
Compute the HMAC.
Definition: crypto_hkdf.c:78
Here is the call graph for this function:
Here is the caller graph for this function: