33#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-symmetric", \
46 gcry_randomize (
key->aes_key,
49 gcry_randomize (
key->twofish_key,
71 gcry_cipher_open (
handle, GCRY_CIPHER_AES256,
72 GCRY_CIPHER_MODE_CFB, 0));
73 rc = gcry_cipher_setkey (*
handle,
77 rc = gcry_cipher_setiv (*
handle,
103 gcry_cipher_open (
handle, GCRY_CIPHER_TWOFISH,
104 GCRY_CIPHER_MODE_CFB, 0));
105 rc = gcry_cipher_setkey (*
handle,
108 GNUNET_assert ((0 == rc) || ((
char) rc == GPG_ERR_WEAK_KEY));
109 rc = gcry_cipher_setiv (*
handle,
112 GNUNET_assert ((0 == rc) || ((
char) rc == GPG_ERR_WEAK_KEY));
133 gcry_cipher_close (
handle);
137 gcry_cipher_close (
handle);
138 memset (tmp, 0,
sizeof(tmp));
159 gcry_cipher_close (
handle);
163 gcry_cipher_close (
handle);
164 memset (tmp, 0,
sizeof(tmp));
181 GCRY_CIPHER_MODE_CTR, 0));
182 rc = gcry_cipher_setkey (
handle,
185 GNUNET_assert ((0 == rc) || ((
char) rc == GPG_ERR_WEAK_KEY));
186 rc = gcry_cipher_setctr (
handle,
189 GNUNET_assert ((0 == rc) || ((
char) rc == GPG_ERR_WEAK_KEY));
192 gcry_cipher_close (
handle);
199 const unsigned char in_buf[in_buf_len],
204 ssize_t ctlen = in_buf_len - crypto_secretbox_xsalsa20poly1305_MACBYTES;
207 if (0 != crypto_secretbox_open_detached (
210 + crypto_secretbox_xsalsa20poly1305_MACBYTES,
226 const unsigned char in_buf[in_buf_len],
231 if (in_buf_len > crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX)
233 crypto_secretbox_detached (out_buf
234 + crypto_secretbox_xsalsa20poly1305_MACBYTES,
247 const unsigned char ct[ct_len],
249 const unsigned char aad[aad_len],
255 if (0 != crypto_aead_xchacha20poly1305_ietf_decrypt_detached (
276 const unsigned char pt[pt_len],
278 const unsigned char aad[aad_len],
284 crypto_aead_xchacha20poly1305_ietf_encrypt_detached (ct,
301 crypto_aead_xchacha20poly1305_ietf_keygen (
key->k);
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.
void GNUNET_CRYPTO_aes_ctr(const void *in_buf, size_t in_buf_len, const unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH], const unsigned char iv[GNUNET_CRYPTO_AES_IV_LENGTH], void *out_buf)
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.
struct GNUNET_HashCode key
The key used in the DHT.
static int result
Global testing status.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
void GNUNET_CRYPTO_symmetric_create_session_key(struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Create a new SessionKey (for symmetric encryption).
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt(size_t ct_len, const unsigned char ct[ct_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, const struct GNUNET_CRYPTO_AeadMac *mac, void *pt)
Decrypt the given data using XChaCha20-Poly1305.
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 using a symmetric sessionkey.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt(size_t pt_len, const unsigned char pt[pt_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, void *ct, struct GNUNET_CRYPTO_AeadMac *mac)
Encrypt the given data using XChaCha20-Poly1305.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_decrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_encrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
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 using a symmetric sessionkey.
#define GNUNET_CRYPTO_AES_IV_LENGTH
length of an AES key in bytes
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
#define GNUNET_CRYPTO_AES_KEY_LENGTH
length of the sessionkey in bytes
void GNUNET_CRYPTO_aead_create_key(struct GNUNET_CRYPTO_AeadSecretKey *key)
Create a new AEAD key.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int size
Size of the "table".
unsigned char mac[16]
Initialization vector.
unsigned char npub[24]
Initialization vector.
unsigned char aes_iv[(256/8)/2]
unsigned char twofish_iv[(256/8)/2]
unsigned char twofish_key[(256/8)]
Actual key for TwoFish.
unsigned char aes_key[(256/8)]
Actual key for AES.
unsigned char nonce[24]
Initialization vector.