GNUnet  0.11.x
Macros | Functions
crypto_symmetric.c File Reference

Symmetric encryption services; combined cipher AES+TWOFISH (256-bit each) More...

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

Go to the source code of this file.

Macros

#define LOG(kind, ...)
 

Functions

void GNUNET_CRYPTO_symmetric_create_session_key (struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Create a new SessionKey (for symmetric encryption). More...
 
static int setup_cipher_aes (gcry_cipher_hd_t *handle, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
 Initialize AES cipher. More...
 
static int setup_cipher_twofish (gcry_cipher_hd_t *handle, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
 Initialize TWOFISH cipher. More...
 
ssize_t GNUNET_CRYPTO_symmetric_encrypt (const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
 Encrypt a block with a symmetric session key. More...
 
ssize_t GNUNET_CRYPTO_symmetric_decrypt (const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
 Decrypt a given block with the session key. More...
 
void GNUNET_CRYPTO_symmetric_derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
 Derive an IV. More...
 
void GNUNET_CRYPTO_symmetric_derive_iv_v (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len, va_list argp)
 Derive an IV. More...
 

Detailed Description

Symmetric encryption services; combined cipher AES+TWOFISH (256-bit each)

Author
Christian Grothoff
Ioana Patrascu

Definition in file crypto_symmetric.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)
Value:
GNUNET_log_from (kind, "util-crypto-symmetric", \
__VA_ARGS__)
#define GNUNET_log_from(kind, comp,...)

Definition at line 32 of file crypto_symmetric.c.

Function Documentation

◆ setup_cipher_aes()

static int setup_cipher_aes ( gcry_cipher_hd_t *  handle,
const struct GNUNET_CRYPTO_SymmetricSessionKey sessionkey,
const struct GNUNET_CRYPTO_SymmetricInitializationVector iv 
)
static

Initialize AES cipher.

Parameters
handlehandle to initialize
sessionkeysession key to use
ivinitialization vector to use
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 63 of file crypto_symmetric.c.

References GNUNET_CRYPTO_SymmetricInitializationVector::aes_iv, GNUNET_CRYPTO_SymmetricSessionKey::aes_key, GNUNET_assert, and GNUNET_OK.

Referenced by GNUNET_CRYPTO_symmetric_decrypt(), and GNUNET_CRYPTO_symmetric_encrypt().

66 {
67  int rc;
68 
69  GNUNET_assert (0 ==
70  gcry_cipher_open (handle, GCRY_CIPHER_AES256,
71  GCRY_CIPHER_MODE_CFB, 0));
72  rc = gcry_cipher_setkey (*handle,
73  sessionkey->aes_key,
74  sizeof(sessionkey->aes_key));
75  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
76  rc = gcry_cipher_setiv (*handle,
77  iv->aes_iv,
78  sizeof(iv->aes_iv));
79  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
80  return GNUNET_OK;
81 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
unsigned char aes_key[(256/8)]
Actual key for AES.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Here is the caller graph for this function:

◆ setup_cipher_twofish()

static int setup_cipher_twofish ( gcry_cipher_hd_t *  handle,
const struct GNUNET_CRYPTO_SymmetricSessionKey sessionkey,
const struct GNUNET_CRYPTO_SymmetricInitializationVector iv 
)
static

Initialize TWOFISH cipher.

Parameters
handlehandle to initialize
sessionkeysession key to use
ivinitialization vector to use
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 93 of file crypto_symmetric.c.

References GNUNET_assert, GNUNET_OK, GNUNET_CRYPTO_SymmetricInitializationVector::twofish_iv, and GNUNET_CRYPTO_SymmetricSessionKey::twofish_key.

Referenced by GNUNET_CRYPTO_symmetric_decrypt(), and GNUNET_CRYPTO_symmetric_encrypt().

98 {
99  int rc;
100 
101  GNUNET_assert (0 ==
102  gcry_cipher_open (handle, GCRY_CIPHER_TWOFISH,
103  GCRY_CIPHER_MODE_CFB, 0));
104  rc = gcry_cipher_setkey (*handle,
105  sessionkey->twofish_key,
106  sizeof(sessionkey->twofish_key));
107  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
108  rc = gcry_cipher_setiv (*handle,
109  iv->twofish_iv,
110  sizeof(iv->twofish_iv));
111  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
112  return GNUNET_OK;
113 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
unsigned char twofish_key[(256/8)]
Actual key for TwoFish.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Here is the caller graph for this function:

◆ GNUNET_CRYPTO_symmetric_derive_iv_v()

void GNUNET_CRYPTO_symmetric_derive_iv_v ( struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
const struct GNUNET_CRYPTO_SymmetricSessionKey skey,
const void *  salt,
size_t  salt_len,
va_list  argp 
)

Derive an IV.

Parameters
ivinitialization vector
skeysession key
saltsalt for the derivation
salt_lensize of the salt
argppairs of void * & size_t for context chunks, terminated by NULL

Definition at line 229 of file crypto_symmetric.c.

References GNUNET_CRYPTO_SymmetricInitializationVector::aes_iv, GNUNET_CRYPTO_SymmetricSessionKey::aes_key, GNUNET_CRYPTO_kdf_v(), GNUNET_memcpy, GNUNET_CRYPTO_SymmetricInitializationVector::twofish_iv, and GNUNET_CRYPTO_SymmetricSessionKey::twofish_key.

Referenced by GNUNET_CRYPTO_symmetric_derive_iv().

237 {
238  char aes_salt[salt_len + 4];
239  char twofish_salt[salt_len + 4];
240 
241  GNUNET_memcpy (aes_salt, salt, salt_len);
242  GNUNET_memcpy (&aes_salt[salt_len], "AES!", 4);
243  GNUNET_memcpy (twofish_salt, salt, salt_len);
244  GNUNET_memcpy (&twofish_salt[salt_len], "FISH", 4);
246  sizeof(iv->aes_iv),
247  aes_salt,
248  salt_len + 4,
249  skey->aes_key,
250  sizeof(skey->aes_key),
251  argp);
253  sizeof(iv->twofish_iv),
254  twofish_salt,
255  salt_len + 4,
256  skey->twofish_key,
257  sizeof(skey->twofish_key),
258  argp);
259 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
unsigned char aes_key[(256/8)]
Actual key for AES.
unsigned char twofish_key[(256/8)]
Actual key for TwoFish.
int GNUNET_CRYPTO_kdf_v(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
Derive key.
Definition: crypto_kdf.c:47
Here is the call graph for this function:
Here is the caller graph for this function: