aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_common.h63
-rw-r--r--src/include/gnunet_json_lib.h11
-rw-r--r--src/include/gnunet_revocation_service.h142
3 files changed, 181 insertions, 35 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 78aeb3de7..033a68894 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -1209,7 +1209,10 @@ GNUNET_is_zero_ (const void *a,
1209 * @param n number of elements in the array 1209 * @param n number of elements in the array
1210 * @param type name of the struct or union, i.e. pass 'struct Foo'. 1210 * @param type name of the struct or union, i.e. pass 'struct Foo'.
1211 */ 1211 */
1212#define GNUNET_new_array(n, type) (type *) GNUNET_malloc ((n) * sizeof(type)) 1212#define GNUNET_new_array(n, type) ({ \
1213 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1214 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1215 })
1213 1216
1214/** 1217/**
1215 * @ingroup memory 1218 * @ingroup memory
@@ -1284,23 +1287,23 @@ GNUNET_is_zero_ (const void *a,
1284 * @ingroup memory 1287 * @ingroup memory
1285 * Wrapper around free. Frees the memory referred to by ptr. 1288 * Wrapper around free. Frees the memory referred to by ptr.
1286 * Note that it is generally better to free memory that was 1289 * Note that it is generally better to free memory that was
1287 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free. 1290 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free_nz.
1288 * 1291 *
1289 * @param ptr location where to free the memory. ptr must have 1292 * @param ptr location where to free the memory. ptr must have
1290 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. 1293 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier.
1291 */ 1294 */
1292#define GNUNET_free(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__) 1295#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1293 1296
1294/** 1297/**
1295 * @ingroup memory 1298 * @ingroup memory
1296 * Wrapper around free. Frees the memory referred to by ptr and sets ptr to NULL. 1299 * Wrapper around free. Frees the memory referred to by ptr and sets ptr to NULL.
1297 * Note that it is generally better to free memory that was 1300 * Note that it is generally better to free memory that was
1298 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_freez. 1301 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free.
1299 * 1302 *
1300 * @param ptr location where to free the memory. ptr must have 1303 * @param ptr location where to free the memory. ptr must have
1301 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. 1304 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier.
1302 */ 1305 */
1303#define GNUNET_freez(ptr) do { \ 1306#define GNUNET_free(ptr) do { \
1304 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ 1307 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1305 ptr = NULL; \ 1308 ptr = NULL; \
1306} while (0) 1309} while (0)
@@ -1389,22 +1392,58 @@ GNUNET_is_zero_ (const void *a,
1389 1392
1390/** 1393/**
1391 * @ingroup memory 1394 * @ingroup memory
1392 * Append an element to a list (growing the list by one). 1395 * Append an element to an array (growing the array by one).
1393 * 1396 *
1394 * @param arr base-pointer of the vector, may be NULL if size is 0; 1397 * @param arr base-pointer of the vector, may be NULL if @a len is 0;
1395 * will be updated to reflect the new address. The TYPE of 1398 * will be updated to reflect the new address. The TYPE of
1396 * arr is important since size is the number of elements and 1399 * arr is important since size is the number of elements and
1397 * not the size in bytes 1400 * not the size in bytes
1398 * @param size the number of elements in the existing vector (number 1401 * @param len the number of elements in the existing vector (number
1399 * of elements to copy over), will be updated with the new 1402 * of elements to copy over), will be updated with the new
1400 * array size 1403 * array length
1401 * @param element the element that will be appended to the array 1404 * @param element the element that will be appended to the array
1402 */ 1405 */
1403#define GNUNET_array_append(arr, size, element) \ 1406#define GNUNET_array_append(arr, len, element) \
1407 do \
1408 { \
1409 GNUNET_assert ((len) + 1 > (len)); \
1410 GNUNET_array_grow (arr, len, len + 1); \
1411 (arr) [len - 1] = element; \
1412 } while (0)
1413
1414
1415/**
1416 * @ingroup memory
1417 * Append @a arr2 to @a arr1 (growing @a arr1
1418 * as needed). The @a arr2 array is left unchanged. Naturally
1419 * this function performs a shallow copy. Both arrays must have
1420 * the same type for their elements.
1421 *
1422 * @param arr1 base-pointer of the vector, may be NULL if @a len is 0;
1423 * will be updated to reflect the new address. The TYPE of
1424 * arr is important since size is the number of elements and
1425 * not the size in bytes
1426 * @param len1 the number of elements in the existing vector (number
1427 * of elements to copy over), will be updated with the new
1428 * array size
1429 * @param arr2 base-pointer a second array to concatenate, may be NULL if @a len2 is 0;
1430 * will be updated to reflect the new address. The TYPE of
1431 * arr is important since size is the number of elements and
1432 * not the size in bytes
1433 * @param len the number of elements in the existing vector (number
1434 * of elements to copy over), will be updated with the new
1435 * array size
1436
1437 */
1438#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1404 do \ 1439 do \
1405 { \ 1440 { \
1406 GNUNET_array_grow (arr, size, size + 1); \ 1441 const typeof (*arr2) * _a1 = (arr1); \
1407 (arr) [size - 1] = element; \ 1442 const typeof (*arr1) * _a2 = (arr2); \
1443 GNUNET_assert ((len1) + (len2) >= (len1)); \
1444 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1445 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1446 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1408 } while (0) 1447 } while (0)
1409 1448
1410/** 1449/**
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index f6cabd589..27996f18d 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -219,6 +219,17 @@ GNUNET_JSON_spec_json (const char *name, json_t **jsonp);
219 219
220 220
221/** 221/**
222 * boolean.
223 *
224 * @param name name of the JSON field
225 * @param[out] b where to store the boolean found under @a name
226 */
227struct GNUNET_JSON_Specification
228GNUNET_JSON_spec_bool (const char *name,
229 bool *b);
230
231
232/**
222 * 8-bit integer. 233 * 8-bit integer.
223 * 234 *
224 * @param name name of the JSON field 235 * @param name name of the JSON field
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h
index 7222cedc1..9a8918b43 100644
--- a/src/include/gnunet_revocation_service.h
+++ b/src/include/gnunet_revocation_service.h
@@ -51,6 +51,73 @@ extern "C"
51#define GNUNET_REVOCATION_VERSION 0x00000000 51#define GNUNET_REVOCATION_VERSION 0x00000000
52 52
53/** 53/**
54 * The proof-of-work narrowing factor.
55 * The number of PoWs that are calculates as part of revocation.
56 */
57#define POW_COUNT 32
58
59
60GNUNET_NETWORK_STRUCT_BEGIN
61
62struct GNUNET_REVOCATION_Pow
63{
64 /**
65 * The timestamp of the revocation
66 */
67 struct GNUNET_TIME_AbsoluteNBO timestamp;
68
69 /**
70 * The TTL of this revocation (purely informational)
71 */
72 struct GNUNET_TIME_RelativeNBO ttl;
73
74 /**
75 * The PoWs
76 */
77 uint64_t pow[POW_COUNT] GNUNET_PACKED;
78
79 /**
80 * The signature
81 */
82 struct GNUNET_CRYPTO_EcdsaSignature signature;
83
84 /**
85 * The revoked public key
86 */
87 struct GNUNET_CRYPTO_EcdsaPublicKey key;
88};
89
90
91/**
92 * The signature object we use for the PoW
93 */
94struct GNUNET_REVOCATION_SignaturePurpose
95{
96 /**
97 * The signature purpose
98 */
99 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
100
101 /**
102 * The revoked public key
103 */
104 struct GNUNET_CRYPTO_EcdsaPublicKey key;
105
106 /**
107 * The timestamp of the revocation
108 */
109 struct GNUNET_TIME_AbsoluteNBO timestamp;
110};
111
112GNUNET_NETWORK_STRUCT_END
113
114
115/**
116 * Handle to a running proof-of-work calculation.
117 */
118struct GNUNET_REVOCATION_PowCalculationHandle;
119
120/**
54 * Handle for the key revocation query. 121 * Handle for the key revocation query.
55 */ 122 */
56struct GNUNET_REVOCATION_Query; 123struct GNUNET_REVOCATION_Query;
@@ -65,7 +132,8 @@ struct GNUNET_REVOCATION_Query;
65 * 132 *
66 */ 133 */
67typedef void (*GNUNET_REVOCATION_Callback) (void *cls, 134typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
68 int is_valid); 135 enum GNUNET_GenericReturnValue
136 is_valid);
69 137
70 138
71/** 139/**
@@ -102,12 +170,9 @@ struct GNUNET_REVOCATION_Handle;
102 * Perform key revocation. 170 * Perform key revocation.
103 * 171 *
104 * @param cfg the configuration to use 172 * @param cfg the configuration to use
105 * @param key public key of the key to revoke
106 * @param sig signature to use on the revocation (should have been
107 * created using #GNUNET_REVOCATION_sign_revocation).
108 * @param pow proof of work to use (should have been created by 173 * @param pow proof of work to use (should have been created by
109 * iteratively calling #GNUNET_REVOCATION_check_pow) 174 * iteratively calling #GNUNET_REVOCATION_pow_round)
110 * @param func funtion to call with the result of the check 175 * @param func function to call with the result of the check
111 * (called with `is_valid` being #GNUNET_NO if 176 * (called with `is_valid` being #GNUNET_NO if
112 * the revocation worked). 177 * the revocation worked).
113 * @param func_cls closure to pass to @a func 178 * @param func_cls closure to pass to @a func
@@ -115,9 +180,7 @@ struct GNUNET_REVOCATION_Handle;
115 */ 180 */
116struct GNUNET_REVOCATION_Handle * 181struct GNUNET_REVOCATION_Handle *
117GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, 182GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
118 const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 183 const struct GNUNET_REVOCATION_Pow *pow,
119 const struct GNUNET_CRYPTO_EcdsaSignature *sig,
120 uint64_t pow,
121 GNUNET_REVOCATION_Callback func, void *func_cls); 184 GNUNET_REVOCATION_Callback func, void *func_cls);
122 185
123 186
@@ -131,31 +194,64 @@ GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h);
131 194
132 195
133/** 196/**
134 * Check if the given proof-of-work value 197 * Check if the given proof-of-work is valid.
135 * would be acceptable for revoking the given key.
136 * 198 *
137 * @param key key to check for 199 * @param pow proof of work
138 * @param pow proof of work value
139 * @param matching_bits how many bits must match (configuration) 200 * @param matching_bits how many bits must match (configuration)
201 * @param epoch_duration length of single epoch in configuration
140 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not 202 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
141 */ 203 */
142int 204enum GNUNET_GenericReturnValue
143GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 205GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
144 uint64_t pow, 206 unsigned int matching_bits,
145 unsigned int matching_bits); 207 struct GNUNET_TIME_Relative epoch_duration);
146 208
147 209
148/** 210/**
149 * Create a revocation signature. 211 * Initializes a fresh PoW computation.
150 * 212 *
151 * @param key private key of the key to revoke 213 * @param key the key to calculate the PoW for.
152 * @param sig where to write the revocation signature 214 * @param pow the pow object to work with in the calculation.
153 */ 215 */
154void 216void
155GNUNET_REVOCATION_sign_revocation (const struct 217GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
156 GNUNET_CRYPTO_EcdsaPrivateKey *key, 218 struct GNUNET_REVOCATION_Pow *pow);
157 struct GNUNET_CRYPTO_EcdsaSignature *sig); 219
220
221/**
222 * Starts a proof-of-work calculation given the pow object as well as
223 * target epochs and difficulty.
224 *
225 * @param pow the PoW to based calculations on.
226 * @param epochs the number of epochs for which the PoW must be valid.
227 * @param difficulty the base difficulty of the PoW.
228 * @return a handle for use in PoW rounds
229 */
230struct GNUNET_REVOCATION_PowCalculationHandle*
231GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_Pow *pow,
232 int epochs,
233 unsigned int difficulty);
234
158 235
236/**
237 * Calculate a single round in the key revocation PoW.
238 *
239 * @param pc handle to the PoW, initially called with NULL.
240 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
241 */
242enum GNUNET_GenericReturnValue
243GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
244
245
246/**
247 * Stop a PoW calculation
248 *
249 * @param pc the calculation to clean up
250 * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not
251 * valid
252 */
253void
254GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
159 255
160#if 0 /* keep Emacsens' auto-indent happy */ 256#if 0 /* keep Emacsens' auto-indent happy */
161{ 257{