aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-09-30 13:21:29 +0000
committerChristian Grothoff <christian@grothoff.org>2014-09-30 13:21:29 +0000
commit6b671ee2e7473536db1c9a0215b47f460d0fce88 (patch)
tree6a11a5bc95d0cff8b0aa0c459d739491fe49bd0a /src/core
parent10f4f506dba523b124a9bfe8e54fe8c4ad2ec30a (diff)
downloadgnunet-6b671ee2e7473536db1c9a0215b47f460d0fce88.tar.gz
gnunet-6b671ee2e7473536db1c9a0215b47f460d0fce88.zip
-doxygen, code cleanup
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gnunet-service-core_kx.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 4bf1b7925..31cd14f85 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -82,12 +82,12 @@ struct EphemeralKeyMessage
82 struct GNUNET_MessageHeader header; 82 struct GNUNET_MessageHeader header;
83 83
84 /** 84 /**
85 * Status of the sender (should be in "enum PeerStateMachine"), nbo. 85 * Status of the sender (should be in `enum PeerStateMachine`), nbo.
86 */ 86 */
87 int32_t sender_status GNUNET_PACKED; 87 int32_t sender_status GNUNET_PACKED;
88 88
89 /** 89 /**
90 * An ECC signature of the 'origin' asserting the validity of 90 * An ECC signature of the @e origin_identity asserting the validity of
91 * the given ephemeral key. 91 * the given ephemeral key.
92 */ 92 */
93 struct GNUNET_CRYPTO_EddsaSignature signature; 93 struct GNUNET_CRYPTO_EddsaSignature signature;
@@ -230,7 +230,7 @@ GNUNET_NETWORK_STRUCT_END
230 230
231 231
232/** 232/**
233 * Number of bytes (at the beginning) of "struct EncryptedMessage" 233 * Number of bytes (at the beginning) of `struct EncryptedMessage`
234 * that are NOT encrypted. 234 * that are NOT encrypted.
235 */ 235 */
236#define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number)) 236#define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number))
@@ -385,7 +385,7 @@ static struct GNUNET_SERVER_NotificationContext *nc;
385 * Inform the given monitor about the KX state of 385 * Inform the given monitor about the KX state of
386 * the given peer. 386 * the given peer.
387 * 387 *
388 * @param mc monitor to inform 388 * @param client client to inform
389 * @param kx key exchange state to inform about 389 * @param kx key exchange state to inform about
390 */ 390 */
391static void 391static void
@@ -407,6 +407,22 @@ monitor_notify (struct GNUNET_SERVER_Client *client,
407 407
408 408
409/** 409/**
410 * Calculate seed value we should use for a message.
411 *
412 * @param kx key exchange context
413 */
414static uint32_t
415calculate_seed (struct GSC_KeyExchangeInfo *kx)
416{
417 /* Note: may want to make this non-random and instead
418 derive from key material to avoid having an undetectable
419 side-channel */
420 return htonl (GNUNET_CRYPTO_random_u32
421 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
422}
423
424
425/**
410 * Inform all monitors about the KX state of the given peer. 426 * Inform all monitors about the KX state of the given peer.
411 * 427 *
412 * @param kx key exchange state to inform about 428 * @param kx key exchange state to inform about
@@ -657,8 +673,7 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
657 pm = &kx->ping; 673 pm = &kx->ping;
658 pm->header.size = htons (sizeof (struct PingMessage)); 674 pm->header.size = htons (sizeof (struct PingMessage));
659 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); 675 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
660 pm->iv_seed = 676 pm->iv_seed = calculate_seed (kx);
661 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
662 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer); 677 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer);
663 pp.challenge = kx->ping_challenge; 678 pp.challenge = kx->ping_challenge;
664 pp.target = kx->peer; 679 pp.target = kx->peer;
@@ -1026,8 +1041,7 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
1026 tx.target = t.target; 1041 tx.target = t.target;
1027 tp.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG); 1042 tp.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG);
1028 tp.header.size = htons (sizeof (struct PongMessage)); 1043 tp.header.size = htons (sizeof (struct PongMessage));
1029 tp.iv_seed = 1044 tp.iv_seed = calculate_seed (kx);
1030 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1031 derive_pong_iv (&iv, &kx->encrypt_key, tp.iv_seed, t.challenge, &kx->peer); 1045 derive_pong_iv (&iv, &kx->encrypt_key, tp.iv_seed, t.challenge, &kx->peer);
1032 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge, 1046 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge,
1033 sizeof (struct PongMessage) - ((void *) &tp.challenge - 1047 sizeof (struct PongMessage) - ((void *) &tp.challenge -
@@ -1276,7 +1290,7 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1276 * 1290 *
1277 * @param kx key exchange context 1291 * @param kx key exchange context
1278 * @param payload payload of the message 1292 * @param payload payload of the message
1279 * @param payload_size number of bytes in 'payload' 1293 * @param payload_size number of bytes in @a payload
1280 */ 1294 */
1281void 1295void
1282GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, 1296GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
@@ -1291,10 +1305,8 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1291 struct GNUNET_CRYPTO_AuthKey auth_key; 1305 struct GNUNET_CRYPTO_AuthKey auth_key;
1292 1306
1293 ph = (struct EncryptedMessage *) pbuf; 1307 ph = (struct EncryptedMessage *) pbuf;
1294 ph->iv_seed =
1295 htonl (GNUNET_CRYPTO_random_u32
1296 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
1297 ph->sequence_number = htonl (++kx->last_sequence_number_sent); 1308 ph->sequence_number = htonl (++kx->last_sequence_number_sent);
1309 ph->iv_seed = calculate_seed (kx);
1298 ph->reserved = 0; 1310 ph->reserved = 0;
1299 ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1311 ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1300 memcpy (&ph[1], payload, payload_size); 1312 memcpy (&ph[1], payload, payload_size);