diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-10 10:43:06 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-01-10 10:43:06 +0100 |
commit | 5982cb44ba9b28751b69a818d32afe2d2b99db1c (patch) | |
tree | 31484d4ad1786bced0e446abeae14fde772d90e5 /src/dht | |
parent | 8f8351c2ddb2c3040195548363161a2a177c7cc0 (diff) | |
download | gnunet-5982cb44ba9b28751b69a818d32afe2d2b99db1c.tar.gz gnunet-5982cb44ba9b28751b69a818d32afe2d2b99db1c.zip |
-export routine for path verification (untested)
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/dht_api.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 1ba2f7277..af3c7d685 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_constants.h" | 30 | #include "gnunet_constants.h" |
31 | #include "gnunet_signatures.h" | ||
31 | #include "gnunet_arm_service.h" | 32 | #include "gnunet_arm_service.h" |
32 | #include "gnunet_hello_lib.h" | 33 | #include "gnunet_hello_lib.h" |
33 | #include "gnunet_protocols.h" | 34 | #include "gnunet_protocols.h" |
@@ -1189,7 +1190,43 @@ GNUNET_DHT_pp2s (const struct GNUNET_DHT_PathElement *path, | |||
1189 | (i == path_len - 1) ? "" : "-"); | 1190 | (i == path_len - 1) ? "" : "-"); |
1190 | } | 1191 | } |
1191 | return buf; | 1192 | return buf; |
1193 | } | ||
1194 | |||
1192 | 1195 | ||
1196 | unsigned int | ||
1197 | GNUNET_DHT_verify_path (const struct GNUNET_HashCode *key, | ||
1198 | const void *data, | ||
1199 | size_t data_size, | ||
1200 | struct GNUNET_TIME_Absolute exp_time, | ||
1201 | const struct GNUNET_DHT_PathElement *path, | ||
1202 | unsigned int path_len, | ||
1203 | const struct GNUNET_PeerIdentity *me) | ||
1204 | { | ||
1205 | |||
1206 | struct GNUNET_DHT_HopSignature hs = { | ||
1207 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DHT_HOP), | ||
1208 | .purpose.size = htonl (sizeof (hs)), | ||
1209 | .expiration_time = GNUNET_TIME_absolute_hton (exp_time), | ||
1210 | .key = *key, | ||
1211 | }; | ||
1212 | unsigned int i = path_len - 1; | ||
1213 | |||
1214 | GNUNET_CRYPTO_hash (data, | ||
1215 | data_size, | ||
1216 | &hs.h_data); | ||
1217 | while (i > 0) | ||
1218 | { | ||
1219 | hs.pred = path[i - 1].pred; | ||
1220 | hs.succ = (path_len == i + 1) ? *me : path[i + 1].pred; | ||
1221 | if (GNUNET_OK != | ||
1222 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DHT_HOP, | ||
1223 | &hs, | ||
1224 | &path[i - 1].sig, | ||
1225 | &path[i].pred.public_key)) | ||
1226 | return i; | ||
1227 | i--; | ||
1228 | } | ||
1229 | return i; | ||
1193 | } | 1230 | } |
1194 | 1231 | ||
1195 | 1232 | ||