aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-tng.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-tng.c')
-rw-r--r--src/transport/gnunet-service-tng.c68
1 files changed, 51 insertions, 17 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index bb1656876..53b9ba0c8 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -33,7 +33,6 @@
33 * transport-to-transport traffic) 33 * transport-to-transport traffic)
34 * 34 *
35 * Implement next: 35 * Implement next:
36 * - backchannel message encryption & decryption
37 * - DV data structures: 36 * - DV data structures:
38 * + using DV routes! 37 * + using DV routes!
39 * - handling of DV-boxed messages that need to be forwarded 38 * - handling of DV-boxed messages that need to be forwarded
@@ -59,7 +58,6 @@
59 * FIXME (without marks in the code!): 58 * FIXME (without marks in the code!):
60 * - proper use/initialization of timestamps in messages exchanged 59 * - proper use/initialization of timestamps in messages exchanged
61 * during DV learning 60 * during DV learning
62 * -
63 * 61 *
64 * Optimizations: 62 * Optimizations:
65 * - use shorthashmap on msg_uuid's when matching reliability/fragment ACKs 63 * - use shorthashmap on msg_uuid's when matching reliability/fragment ACKs
@@ -3238,21 +3236,32 @@ route_message (const struct GNUNET_PeerIdentity *target,
3238 */ 3236 */
3239struct BackchannelKeyState 3237struct BackchannelKeyState
3240{ 3238{
3241 // FIXME: actual data types in this struct are likely still totally wrong
3242 /** 3239 /**
3243 * 3240 * State of our block cipher.
3244 */ 3241 */
3245 char hdr_key[128]; 3242 gcry_cipher_hd_t cipher;
3246 3243
3247 /** 3244 /**
3248 * 3245 * Actual key material.
3249 */ 3246 */
3250 char body_key[128]; 3247 struct {
3251 3248
3252 /** 3249 /**
3253 * 3250 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
3254 */ 3251 */
3255 char hmac_key[128]; 3252 struct GNUNET_CRYPTO_AuthKey hmac_key;
3253
3254 /**
3255 * Symmetric key to use for encryption.
3256 */
3257 char aes_key[256/8];
3258
3259 /**
3260 * Counter value to use during setup.
3261 */
3262 char aes_ctr[128/8];
3263
3264 } material;
3256}; 3265};
3257 3266
3258 3267
@@ -3263,14 +3272,24 @@ bc_setup_key_state_from_km (const struct GNUNET_HashCode *km,
3263{ 3272{
3264 /* must match #dh_key_derive_eph_pub */ 3273 /* must match #dh_key_derive_eph_pub */
3265 GNUNET_assert (GNUNET_YES == 3274 GNUNET_assert (GNUNET_YES ==
3266 GNUNET_CRYPTO_kdf (key, 3275 GNUNET_CRYPTO_kdf (&key->material,
3267 sizeof (*key), 3276 sizeof (key->material),
3268 "transport-backchannel-key", 3277 "transport-backchannel-key",
3269 strlen ("transport-backchannel-key"), 3278 strlen ("transport-backchannel-key"),
3270 &km, 3279 &km,
3271 sizeof (km), 3280 sizeof (km),
3272 iv, 3281 iv,
3273 sizeof (*iv))); 3282 sizeof (*iv)));
3283 gcry_cipher_open (&key->cipher,
3284 GCRY_CIPHER_AES256 /* low level: go for speed */,
3285 GCRY_CIPHER_MODE_CTR,
3286 0 /* flags */);
3287 gcry_cipher_setkey (key->cipher,
3288 &key->material.aes_key,
3289 sizeof (key->material.aes_key));
3290 gcry_cipher_setctr (key->cipher,
3291 &key->material.aes_ctr,
3292 sizeof (key->material.aes_ctr));
3274} 3293}
3275 3294
3276 3295
@@ -3342,7 +3361,10 @@ bc_hmac (const struct BackchannelKeyState *key,
3342 const void *data, 3361 const void *data,
3343 size_t data_size) 3362 size_t data_size)
3344{ 3363{
3345 // FIXME! 3364 GNUNET_CRYPTO_hmac (&key->material.hmac_key,
3365 data,
3366 data_size,
3367 hmac);
3346} 3368}
3347 3369
3348 3370
@@ -3361,7 +3383,12 @@ bc_encrypt (struct BackchannelKeyState *key,
3361 void *dst, 3383 void *dst,
3362 size_t in_size) 3384 size_t in_size)
3363{ 3385{
3364 // FIXME! 3386 GNUNET_assert (0 ==
3387 gcry_cipher_encrypt (key->cipher,
3388 dst,
3389 in_size,
3390 in,
3391 in_size));
3365} 3392}
3366 3393
3367 3394
@@ -3380,7 +3407,12 @@ bc_decrypt (struct BackchannelKeyState *key,
3380 const void *ciph, 3407 const void *ciph,
3381 size_t out_size) 3408 size_t out_size)
3382{ 3409{
3383 // FIXME! 3410 GNUNET_assert (0 ==
3411 gcry_cipher_decrypt (key->cipher,
3412 out,
3413 out_size,
3414 ciph,
3415 out_size));
3384} 3416}
3385 3417
3386 3418
@@ -3392,7 +3424,9 @@ bc_decrypt (struct BackchannelKeyState *key,
3392static void 3424static void
3393bc_key_clean (struct BackchannelKeyState *key) 3425bc_key_clean (struct BackchannelKeyState *key)
3394{ 3426{
3395 // FIXME! 3427 gcry_cipher_close (key->cipher);
3428 GNUNET_CRYPTO_zero_keys (&key->material,
3429 sizeof (key->material));
3396} 3430}
3397 3431
3398 3432