diff options
author | Nils Durner <durner@gnunet.org> | 2010-10-04 18:06:03 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2010-10-04 18:06:03 +0000 |
commit | 46ec5e283ba163849e70517310383f1a02835dff (patch) | |
tree | e1a3edba98bf3975be4c0c872bdd6e152f292706 /src/core/gnunet-service-core.c | |
parent | 09b6e6bc13f00768e5c8323affb74c6550c4328f (diff) | |
download | gnunet-46ec5e283ba163849e70517310383f1a02835dff.tar.gz gnunet-46ec5e283ba163849e70517310383f1a02835dff.zip |
dynamic IVs
Diffstat (limited to 'src/core/gnunet-service-core.c')
-rw-r--r-- | src/core/gnunet-service-core.c | 137 |
1 files changed, 102 insertions, 35 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index d2a7a45af..96e8af364 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -766,6 +766,49 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | |||
766 | 766 | ||
767 | 767 | ||
768 | /** | 768 | /** |
769 | * Derive an IV from packet information | ||
770 | */ | ||
771 | static void | ||
772 | derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | ||
773 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, | ||
774 | const struct GNUNET_PeerIdentity *identity) | ||
775 | { | ||
776 | static char ctx[] = "initialization vector"; | ||
777 | |||
778 | GNUNET_CRYPTO_aes_derive_iv (iv, | ||
779 | skey, | ||
780 | &seed, | ||
781 | sizeof(seed), | ||
782 | &identity->hashPubKey.bits, | ||
783 | sizeof(identity->hashPubKey.bits), | ||
784 | ctx, | ||
785 | sizeof(ctx), NULL); | ||
786 | } | ||
787 | |||
788 | /** | ||
789 | * Derive an IV from pong packet information | ||
790 | */ | ||
791 | static void | ||
792 | derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | ||
793 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, | ||
794 | uint32_t challenge, const struct GNUNET_PeerIdentity *identity) | ||
795 | { | ||
796 | static char ctx[] = "pong initialization vector"; | ||
797 | |||
798 | GNUNET_CRYPTO_aes_derive_iv (iv, | ||
799 | skey, | ||
800 | &seed, | ||
801 | sizeof(seed), | ||
802 | &identity->hashPubKey.bits, | ||
803 | sizeof(identity->hashPubKey.bits), | ||
804 | &challenge, | ||
805 | sizeof(challenge), | ||
806 | ctx, | ||
807 | sizeof(ctx), NULL); | ||
808 | } | ||
809 | |||
810 | |||
811 | /** | ||
769 | * A preference value for a neighbour was update. Update | 812 | * A preference value for a neighbour was update. Update |
770 | * the preference sum accordingly. | 813 | * the preference sum accordingly. |
771 | * | 814 | * |
@@ -1272,7 +1315,7 @@ static void process_encrypted_neighbour_queue (struct Neighbour *n); | |||
1272 | */ | 1315 | */ |
1273 | static int | 1316 | static int |
1274 | do_encrypt (struct Neighbour *n, | 1317 | do_encrypt (struct Neighbour *n, |
1275 | const GNUNET_HashCode * iv, | 1318 | const struct GNUNET_CRYPTO_AesInitializationVector * iv, |
1276 | const void *in, void *out, size_t size) | 1319 | const void *in, void *out, size_t size) |
1277 | { | 1320 | { |
1278 | if (size != (uint16_t) size) | 1321 | if (size != (uint16_t) size) |
@@ -1284,16 +1327,15 @@ do_encrypt (struct Neighbour *n, | |||
1284 | GNUNET_CRYPTO_aes_encrypt (in, | 1327 | GNUNET_CRYPTO_aes_encrypt (in, |
1285 | (uint16_t) size, | 1328 | (uint16_t) size, |
1286 | &n->encrypt_key, | 1329 | &n->encrypt_key, |
1287 | (const struct | 1330 | iv, out)); |
1288 | GNUNET_CRYPTO_AesInitializationVector | ||
1289 | *) iv, out)); | ||
1290 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, GNUNET_NO); | 1331 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, GNUNET_NO); |
1291 | #if DEBUG_CORE | 1332 | #if DEBUG_CORE |
1292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1293 | "Encrypted %u bytes for `%4s' using key %u\n", | 1334 | "Encrypted %u bytes for `%4s' using key %u, IV %u\n", |
1294 | (unsigned int) size, | 1335 | (unsigned int) size, |
1295 | GNUNET_i2s (&n->peer), | 1336 | GNUNET_i2s (&n->peer), |
1296 | (unsigned int) n->encrypt_key.crc32); | 1337 | (unsigned int) n->encrypt_key.crc32, |
1338 | GNUNET_CRYPTO_crc32_n (iv, sizeof(iv))); | ||
1297 | #endif | 1339 | #endif |
1298 | return GNUNET_OK; | 1340 | return GNUNET_OK; |
1299 | } | 1341 | } |
@@ -1326,6 +1368,7 @@ send_keep_alive (void *cls, | |||
1326 | struct MessageEntry *me; | 1368 | struct MessageEntry *me; |
1327 | struct PingMessage pp; | 1369 | struct PingMessage pp; |
1328 | struct PingMessage *pm; | 1370 | struct PingMessage *pm; |
1371 | struct GNUNET_CRYPTO_AesInitializationVector iv; | ||
1329 | 1372 | ||
1330 | n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; | 1373 | n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; |
1331 | /* send PING */ | 1374 | /* send PING */ |
@@ -1341,18 +1384,23 @@ send_keep_alive (void *cls, | |||
1341 | pm = (struct PingMessage *) &me[1]; | 1384 | pm = (struct PingMessage *) &me[1]; |
1342 | pm->header.size = htons (sizeof (struct PingMessage)); | 1385 | pm->header.size = htons (sizeof (struct PingMessage)); |
1343 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 1386 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
1387 | pm->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | ||
1388 | UINT32_MAX)); | ||
1389 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); | ||
1344 | pp.challenge = htonl (n->ping_challenge); | 1390 | pp.challenge = htonl (n->ping_challenge); |
1345 | pp.target = n->peer; | 1391 | pp.target = n->peer; |
1346 | #if DEBUG_HANDSHAKE | 1392 | #if DEBUG_HANDSHAKE |
1347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1348 | "Encrypting `%s' message with challenge %u for `%4s' using key %u.\n", | 1394 | "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", |
1349 | "PING", | 1395 | "PING", |
1350 | (unsigned int) n->ping_challenge, | 1396 | (unsigned int) n->ping_challenge, |
1351 | GNUNET_i2s (&n->peer), | 1397 | GNUNET_i2s (&n->peer), |
1352 | (unsigned int) n->encrypt_key.crc32); | 1398 | (unsigned int) n->encrypt_key.crc32, |
1399 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | ||
1400 | pm->iv_seed); | ||
1353 | #endif | 1401 | #endif |
1354 | do_encrypt (n, | 1402 | do_encrypt (n, |
1355 | &n->peer.hashPubKey, | 1403 | &iv, |
1356 | &pp.challenge, | 1404 | &pp.challenge, |
1357 | &pm->challenge, | 1405 | &pm->challenge, |
1358 | sizeof (struct PingMessage) - | 1406 | sizeof (struct PingMessage) - |
@@ -1580,7 +1628,7 @@ process_encrypted_neighbour_queue (struct Neighbour *n) | |||
1580 | */ | 1628 | */ |
1581 | static int | 1629 | static int |
1582 | do_decrypt (struct Neighbour *n, | 1630 | do_decrypt (struct Neighbour *n, |
1583 | const GNUNET_HashCode * iv, | 1631 | const struct GNUNET_CRYPTO_AesInitializationVector * iv, |
1584 | const void *in, void *out, size_t size) | 1632 | const void *in, void *out, size_t size) |
1585 | { | 1633 | { |
1586 | if (size != (uint16_t) size) | 1634 | if (size != (uint16_t) size) |
@@ -1598,8 +1646,7 @@ do_decrypt (struct Neighbour *n, | |||
1598 | GNUNET_CRYPTO_aes_decrypt (in, | 1646 | GNUNET_CRYPTO_aes_decrypt (in, |
1599 | (uint16_t) size, | 1647 | (uint16_t) size, |
1600 | &n->decrypt_key, | 1648 | &n->decrypt_key, |
1601 | (const struct | 1649 | iv, |
1602 | GNUNET_CRYPTO_AesInitializationVector *) iv, | ||
1603 | out)) | 1650 | out)) |
1604 | { | 1651 | { |
1605 | GNUNET_break (0); | 1652 | GNUNET_break (0); |
@@ -1608,10 +1655,11 @@ do_decrypt (struct Neighbour *n, | |||
1608 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes decrypted"), size, GNUNET_NO); | 1655 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes decrypted"), size, GNUNET_NO); |
1609 | #if DEBUG_CORE | 1656 | #if DEBUG_CORE |
1610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1657 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1611 | "Decrypted %u bytes from `%4s' using key %u\n", | 1658 | "Decrypted %u bytes from `%4s' using key %u, IV %u\n", |
1612 | (unsigned int) size, | 1659 | (unsigned int) size, |
1613 | GNUNET_i2s (&n->peer), | 1660 | GNUNET_i2s (&n->peer), |
1614 | (unsigned int) n->decrypt_key.crc32); | 1661 | (unsigned int) n->decrypt_key.crc32, |
1662 | GNUNET_CRYPTO_crc32_n (iv, sizeof(*iv))); | ||
1615 | #endif | 1663 | #endif |
1616 | return GNUNET_OK; | 1664 | return GNUNET_OK; |
1617 | } | 1665 | } |
@@ -2048,7 +2096,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2048 | unsigned int priority; | 2096 | unsigned int priority; |
2049 | struct GNUNET_TIME_Absolute deadline; | 2097 | struct GNUNET_TIME_Absolute deadline; |
2050 | struct GNUNET_TIME_Relative retry_time; | 2098 | struct GNUNET_TIME_Relative retry_time; |
2051 | GNUNET_HashCode iv; | 2099 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
2052 | 2100 | ||
2053 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) | 2101 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) |
2054 | { | 2102 | { |
@@ -2160,7 +2208,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2160 | &ph->sequence_number, | 2208 | &ph->sequence_number, |
2161 | esize - sizeof (GNUNET_HashCode), | 2209 | esize - sizeof (GNUNET_HashCode), |
2162 | &ph->hmac); | 2210 | &ph->hmac); |
2163 | GNUNET_CRYPTO_hash (&ph->iv_seed, sizeof (uint32_t), &iv); | 2211 | derive_iv (&iv, &n->encrypt_key, ph->iv_seed, &n->peer); |
2164 | #if DEBUG_HANDSHAKE | 2212 | #if DEBUG_HANDSHAKE |
2165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2166 | "Hashed %u bytes of plaintext (`%s') using IV `%d'\n", | 2214 | "Hashed %u bytes of plaintext (`%s') using IV `%d'\n", |
@@ -2606,6 +2654,7 @@ send_key (struct Neighbour *n) | |||
2606 | struct MessageEntry *me; | 2654 | struct MessageEntry *me; |
2607 | struct PingMessage pp; | 2655 | struct PingMessage pp; |
2608 | struct PingMessage *pm; | 2656 | struct PingMessage *pm; |
2657 | struct GNUNET_CRYPTO_AesInitializationVector iv; | ||
2609 | 2658 | ||
2610 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 2659 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
2611 | { | 2660 | { |
@@ -2751,18 +2800,22 @@ send_key (struct Neighbour *n) | |||
2751 | pm = (struct PingMessage *) &sm[1]; | 2800 | pm = (struct PingMessage *) &sm[1]; |
2752 | pm->header.size = htons (sizeof (struct PingMessage)); | 2801 | pm->header.size = htons (sizeof (struct PingMessage)); |
2753 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 2802 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
2803 | pm->iv_seed = htonl (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | ||
2804 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); | ||
2754 | pp.challenge = htonl (n->ping_challenge); | 2805 | pp.challenge = htonl (n->ping_challenge); |
2755 | pp.target = n->peer; | 2806 | pp.target = n->peer; |
2756 | #if DEBUG_HANDSHAKE | 2807 | #if DEBUG_HANDSHAKE |
2757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2758 | "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u.\n", | 2809 | "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", |
2759 | "SET_KEY", "PING", | 2810 | "SET_KEY", "PING", |
2760 | (unsigned int) n->ping_challenge, | 2811 | (unsigned int) n->ping_challenge, |
2761 | GNUNET_i2s (&n->peer), | 2812 | GNUNET_i2s (&n->peer), |
2762 | (unsigned int) n->encrypt_key.crc32); | 2813 | (unsigned int) n->encrypt_key.crc32, |
2814 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | ||
2815 | pm->iv_seed); | ||
2763 | #endif | 2816 | #endif |
2764 | do_encrypt (n, | 2817 | do_encrypt (n, |
2765 | &n->peer.hashPubKey, | 2818 | &iv, |
2766 | &pp.challenge, | 2819 | &pp.challenge, |
2767 | &pm->challenge, | 2820 | &pm->challenge, |
2768 | sizeof (struct PingMessage) - | 2821 | sizeof (struct PingMessage) - |
@@ -2870,15 +2923,17 @@ handle_ping (struct Neighbour *n, const struct PingMessage *m) | |||
2870 | struct PongMessage tx; | 2923 | struct PongMessage tx; |
2871 | struct PongMessage *tp; | 2924 | struct PongMessage *tp; |
2872 | struct MessageEntry *me; | 2925 | struct MessageEntry *me; |
2926 | struct GNUNET_CRYPTO_AesInitializationVector iv; | ||
2873 | 2927 | ||
2874 | #if DEBUG_CORE | 2928 | #if DEBUG_CORE |
2875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2929 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2876 | "Core service receives `%s' request from `%4s'.\n", | 2930 | "Core service receives `%s' request from `%4s'.\n", |
2877 | "PING", GNUNET_i2s (&n->peer)); | 2931 | "PING", GNUNET_i2s (&n->peer)); |
2878 | #endif | 2932 | #endif |
2933 | derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); | ||
2879 | if (GNUNET_OK != | 2934 | if (GNUNET_OK != |
2880 | do_decrypt (n, | 2935 | do_decrypt (n, |
2881 | &my_identity.hashPubKey, | 2936 | &iv, |
2882 | &m->challenge, | 2937 | &m->challenge, |
2883 | &t.challenge, | 2938 | &t.challenge, |
2884 | sizeof (struct PingMessage) - | 2939 | sizeof (struct PingMessage) - |
@@ -2886,11 +2941,13 @@ handle_ping (struct Neighbour *n, const struct PingMessage *m) | |||
2886 | return; | 2941 | return; |
2887 | #if DEBUG_HANDSHAKE | 2942 | #if DEBUG_HANDSHAKE |
2888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2889 | "Decrypted `%s' to `%4s' with challenge %u decrypted using key %u\n", | 2944 | "Decrypted `%s' to `%4s' with challenge %u decrypted using key %u, IV %u (salt %u)\n", |
2890 | "PING", | 2945 | "PING", |
2891 | GNUNET_i2s (&t.target), | 2946 | GNUNET_i2s (&t.target), |
2892 | (unsigned int) ntohl (t.challenge), | 2947 | (unsigned int) ntohl (t.challenge), |
2893 | (unsigned int) n->decrypt_key.crc32); | 2948 | (unsigned int) n->decrypt_key.crc32, |
2949 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | ||
2950 | m->iv_seed); | ||
2894 | #endif | 2951 | #endif |
2895 | GNUNET_STATISTICS_update (stats, | 2952 | GNUNET_STATISTICS_update (stats, |
2896 | gettext_noop ("# PING messages decrypted"), | 2953 | gettext_noop ("# PING messages decrypted"), |
@@ -2918,8 +2975,10 @@ handle_ping (struct Neighbour *n, const struct PingMessage *m) | |||
2918 | tp = (struct PongMessage *) &me[1]; | 2975 | tp = (struct PongMessage *) &me[1]; |
2919 | tp->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG); | 2976 | tp->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG); |
2920 | tp->header.size = htons (sizeof (struct PongMessage)); | 2977 | tp->header.size = htons (sizeof (struct PongMessage)); |
2978 | tp->iv_seed = htonl (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | ||
2979 | derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer); | ||
2921 | do_encrypt (n, | 2980 | do_encrypt (n, |
2922 | &my_identity.hashPubKey, | 2981 | &iv, |
2923 | &tx.challenge, | 2982 | &tx.challenge, |
2924 | &tp->challenge, | 2983 | &tp->challenge, |
2925 | sizeof (struct PongMessage) - | 2984 | sizeof (struct PongMessage) - |
@@ -2930,10 +2989,12 @@ handle_ping (struct Neighbour *n, const struct PingMessage *m) | |||
2930 | GNUNET_NO); | 2989 | GNUNET_NO); |
2931 | #if DEBUG_HANDSHAKE | 2990 | #if DEBUG_HANDSHAKE |
2932 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2933 | "Encrypting `%s' with challenge %u using key %u\n", | 2992 | "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n", |
2934 | "PONG", | 2993 | "PONG", |
2935 | (unsigned int) ntohl (t.challenge), | 2994 | (unsigned int) ntohl (t.challenge), |
2936 | (unsigned int) n->encrypt_key.crc32); | 2995 | (unsigned int) n->encrypt_key.crc32, |
2996 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | ||
2997 | tp->iv_seed); | ||
2937 | #endif | 2998 | #endif |
2938 | /* trigger queue processing */ | 2999 | /* trigger queue processing */ |
2939 | process_encrypted_neighbour_queue (n); | 3000 | process_encrypted_neighbour_queue (n); |
@@ -2952,6 +3013,7 @@ handle_pong (struct Neighbour *n, | |||
2952 | { | 3013 | { |
2953 | struct PongMessage t; | 3014 | struct PongMessage t; |
2954 | struct ConnectNotifyMessage cnm; | 3015 | struct ConnectNotifyMessage cnm; |
3016 | struct GNUNET_CRYPTO_AesInitializationVector iv; | ||
2955 | 3017 | ||
2956 | #if DEBUG_CORE | 3018 | #if DEBUG_CORE |
2957 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3019 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2960,9 +3022,11 @@ handle_pong (struct Neighbour *n, | |||
2960 | #endif | 3022 | #endif |
2961 | /* mark as garbage, just to be sure */ | 3023 | /* mark as garbage, just to be sure */ |
2962 | memset (&t, 255, sizeof (t)); | 3024 | memset (&t, 255, sizeof (t)); |
3025 | derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, htonl (n->ping_challenge), | ||
3026 | &my_identity); | ||
2963 | if (GNUNET_OK != | 3027 | if (GNUNET_OK != |
2964 | do_decrypt (n, | 3028 | do_decrypt (n, |
2965 | &n->peer.hashPubKey, | 3029 | &iv, |
2966 | &m->challenge, | 3030 | &m->challenge, |
2967 | &t.challenge, | 3031 | &t.challenge, |
2968 | sizeof (struct PongMessage) - | 3032 | sizeof (struct PongMessage) - |
@@ -2975,19 +3039,21 @@ handle_pong (struct Neighbour *n, | |||
2975 | gettext_noop ("# PONG messages decrypted"), | 3039 | gettext_noop ("# PONG messages decrypted"), |
2976 | 1, | 3040 | 1, |
2977 | GNUNET_NO); | 3041 | GNUNET_NO); |
2978 | if (0 != ntohl (t.reserved)) | ||
2979 | { | ||
2980 | GNUNET_break_op (0); | ||
2981 | return; | ||
2982 | } | ||
2983 | #if DEBUG_HANDSHAKE | 3042 | #if DEBUG_HANDSHAKE |
2984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2985 | "Decrypted `%s' from `%4s' with challenge %u using key %u\n", | 3044 | "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n", |
2986 | "PONG", | 3045 | "PONG", |
2987 | GNUNET_i2s (&t.target), | 3046 | GNUNET_i2s (&t.target), |
2988 | (unsigned int) ntohl (t.challenge), | 3047 | (unsigned int) ntohl (t.challenge), |
2989 | (unsigned int) n->decrypt_key.crc32); | 3048 | (unsigned int) n->decrypt_key.crc32, |
3049 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | ||
3050 | m->iv_seed); | ||
2990 | #endif | 3051 | #endif |
3052 | if (0 != ntohl (t.reserved)) | ||
3053 | { | ||
3054 | GNUNET_break_op (0); | ||
3055 | return; | ||
3056 | } | ||
2991 | if ((0 != memcmp (&t.target, | 3057 | if ((0 != memcmp (&t.target, |
2992 | &n->peer, | 3058 | &n->peer, |
2993 | sizeof (struct GNUNET_PeerIdentity))) || | 3059 | sizeof (struct GNUNET_PeerIdentity))) || |
@@ -3178,6 +3244,7 @@ handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m) | |||
3178 | 1, | 3244 | 1, |
3179 | GNUNET_NO); | 3245 | GNUNET_NO); |
3180 | n->decrypt_key = k; | 3246 | n->decrypt_key = k; |
3247 | derive_auth_key(&n->decrypt_auth_key, &n->decrypt_key, t, &my_identity); | ||
3181 | if (n->decrypt_key_created.value != t.value) | 3248 | if (n->decrypt_key_created.value != t.value) |
3182 | { | 3249 | { |
3183 | /* fresh key, reset sequence numbers */ | 3250 | /* fresh key, reset sequence numbers */ |
@@ -3374,14 +3441,14 @@ handle_encrypted_message (struct Neighbour *n, | |||
3374 | GNUNET_HashCode ph; | 3441 | GNUNET_HashCode ph; |
3375 | uint32_t snum; | 3442 | uint32_t snum; |
3376 | struct GNUNET_TIME_Absolute t; | 3443 | struct GNUNET_TIME_Absolute t; |
3377 | GNUNET_HashCode iv; | 3444 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
3378 | 3445 | ||
3379 | #if DEBUG_CORE | 3446 | #if DEBUG_CORE |
3380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3381 | "Core service receives `%s' request from `%4s'.\n", | 3448 | "Core service receives `%s' request from `%4s'.\n", |
3382 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); | 3449 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); |
3383 | #endif | 3450 | #endif |
3384 | GNUNET_CRYPTO_hash (&m->iv_seed, sizeof (uint32_t), &iv); | 3451 | derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); |
3385 | /* decrypt */ | 3452 | /* decrypt */ |
3386 | if (GNUNET_OK != | 3453 | if (GNUNET_OK != |
3387 | do_decrypt (n, | 3454 | do_decrypt (n, |