GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
Revocation service

Perform and access key revocations. More...

Data Structures

struct  GNUNET_REVOCATION_PowP
 Struct for a proof of work as part of the revocation. More...
 
struct  GNUNET_REVOCATION_SignaturePurposePS
 The signature object we use for the PoW. More...
 

Macros

#define GNUNET_REVOCATION_VERSION   0x00000001
 Version of the key revocation API. More...
 
#define POW_COUNT   32
 The proof-of-work narrowing factor. More...
 

Typedefs

typedef void(* GNUNET_REVOCATION_Callback) (void *cls, enum GNUNET_GenericReturnValue is_valid)
 Callback to call with the result of a key revocation query. More...
 

Functions

struct GNUNET_REVOCATION_QueryGNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EcdsaPublicKey *key, GNUNET_REVOCATION_Callback func, void *func_cls)
 Check if a key was revoked. More...
 
void GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q)
 Cancel key revocation check. More...
 
struct GNUNET_REVOCATION_HandleGNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_REVOCATION_PowP *pow, GNUNET_REVOCATION_Callback func, void *func_cls)
 Perform key revocation. More...
 
void GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
 Cancel key revocation. More...
 
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, unsigned int matching_bits, struct GNUNET_TIME_Relative epoch_duration)
 Check if the given proof-of-work is valid. More...
 
void GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
 Initializes a fresh PoW computation. More...
 
struct GNUNET_REVOCATION_PowCalculationHandleGNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow, int epochs, unsigned int difficulty)
 Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty. More...
 
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
 Calculate a single round in the key revocation PoW. More...
 
void GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
 Stop a PoW calculation. More...
 

Detailed Description

Perform and access key revocations.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_REVOCATION_VERSION

#define GNUNET_REVOCATION_VERSION   0x00000001

Version of the key revocation API.

Definition at line 51 of file gnunet_revocation_service.h.

◆ POW_COUNT

#define POW_COUNT   32

The proof-of-work narrowing factor.

The number of PoWs that are calculates as part of revocation.

Definition at line 57 of file gnunet_revocation_service.h.

Referenced by calculate_score(), GNUNET_REVOCATION_check_pow(), and GNUNET_REVOCATION_pow_round().

Typedef Documentation

◆ GNUNET_REVOCATION_Callback

typedef void(* GNUNET_REVOCATION_Callback) (void *cls, enum GNUNET_GenericReturnValue is_valid)

Callback to call with the result of a key revocation query.

Parameters
clsclosure
is_validGNUNET_NO of the key is/was revoked, GNUNET_YES if the key is still valid, GNUNET_SYSERR if we had trouble querying the service

Definition at line 137 of file gnunet_revocation_service.h.

Function Documentation

◆ GNUNET_REVOCATION_query()

struct GNUNET_REVOCATION_Query* GNUNET_REVOCATION_query ( const struct GNUNET_CONFIGURATION_Handle cfg,
const struct GNUNET_CRYPTO_EcdsaPublicKey key,
GNUNET_REVOCATION_Callback  func,
void *  func_cls 
)

Check if a key was revoked.

Parameters
cfgthe configuration to use
keykey to check for revocation
funcfuntion to call with the result of the check
func_clsclosure to pass to func
Returns
handle to use in GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback

Definition at line 162 of file revocation_api.c.

References env, GNUNET_REVOCATION_Query::func, GNUNET_REVOCATION_Query::func_cls, GNUNET_CLIENT_connect(), GNUNET_free, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, key, QueryMessage::key, GNUNET_REVOCATION_Query::mq, q, query_mq_error_handler(), and QueryMessage::reserved.

Referenced by recursive_gns_resolution_revocation(), and run().

166 {
167  struct GNUNET_REVOCATION_Query *q
170  GNUNET_MQ_hd_fixed_size (revocation_query_response,
172  struct QueryResponseMessage,
173  q),
175  };
176  struct QueryMessage *qm;
177  struct GNUNET_MQ_Envelope *env;
178 
179  q->mq = GNUNET_CLIENT_connect (cfg,
180  "revocation",
181  handlers,
183  q);
184  if (NULL == q->mq)
185  {
186  GNUNET_free (q);
187  return NULL;
188  }
189  q->func = func;
190  q->func_cls = func_cls;
191  env = GNUNET_MQ_msg (qm,
193  qm->reserved = htonl (0);
194  qm->key = *key;
195  GNUNET_MQ_send (q->mq,
196  env);
197  return q;
198 }
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY
Client to service: was this key revoked?
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1063
struct GNUNET_MQ_Handle * mq
Message queue to the service.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Query key revocation status.
Definition: revocation.h:37
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE
Service to client: answer if key was revoked!
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
Key revocation response.
Definition: revocation.h:59
void * func_cls
Closure for func.
Message handler for a specific message type.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t reserved
For alignment.
Definition: revocation.h:47
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Handle for the key revocation query.
struct GNUNET_CRYPTO_EcdsaPublicKey key
Key to check.
Definition: revocation.h:52
static void query_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
GNUNET_REVOCATION_Callback func
Function to call with the result.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_query_cancel()

void GNUNET_REVOCATION_query_cancel ( struct GNUNET_REVOCATION_Query q)

Cancel key revocation check.

Parameters
qquery to cancel

Definition at line 207 of file revocation_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_REVOCATION_Query::mq.

Referenced by do_shutdown(), GNS_resolver_lookup_cancel(), handle_revocation_query_response(), and query_mq_error_handler().

208 {
209  if (NULL != q->mq)
210  {
211  GNUNET_MQ_destroy (q->mq);
212  q->mq = NULL;
213  }
214  GNUNET_free (q);
215 }
struct GNUNET_MQ_Handle * mq
Message queue to the service.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_revoke()

struct GNUNET_REVOCATION_Handle* GNUNET_REVOCATION_revoke ( const struct GNUNET_CONFIGURATION_Handle cfg,
const struct GNUNET_REVOCATION_PowP pow,
GNUNET_REVOCATION_Callback  func,
void *  func_cls 
)

Perform key revocation.

Parameters
cfgthe configuration to use
powproof of work to use (should have been created by iteratively calling GNUNET_REVOCATION_pow_round)
funcfunction to call with the result of the check (called with is_valid being GNUNET_NO if the revocation worked).
func_clsclosure to pass to func
Returns
handle to use in GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback
Parameters
cfgthe configuration to use
keypublic key of the key to revoke
sigsignature to use on the revocation (should have been created using #GNUNET_REVOCATION_sign_revocation).
tsrevocation timestamp
powproof of work to use (should have been created by iteratively calling GNUNET_REVOCATION_check_pow)
funcfuntion to call with the result of the check (called with is_valid being GNUNET_NO if the revocation worked).
func_clsclosure to pass to func
Returns
handle to use in GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback

Definition at line 301 of file revocation_api.c.

References env, GNUNET_REVOCATION_Query::func, GNUNET_REVOCATION_Handle::func, GNUNET_REVOCATION_Query::func_cls, GNUNET_REVOCATION_Handle::func_cls, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_free, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, GNUNET_OK, GNUNET_REVOCATION_check_pow(), GNUNET_YES, h, matching_bits, GNUNET_REVOCATION_Handle::mq, RevokeMessage::proof_of_work, RevokeMessage::reserved, and revocation_mq_error_handler().

Referenced by perform_revocation().

305 {
309  GNUNET_MQ_hd_fixed_size (revocation_response,
312  h),
314  };
315  unsigned long long matching_bits;
317  struct RevokeMessage *rm;
318  struct GNUNET_MQ_Envelope *env;
319 
320  if ((GNUNET_OK !=
322  "REVOCATION",
323  "WORKBITS",
324  &matching_bits)))
325  {
326  GNUNET_break (0);
327  GNUNET_free (h);
328  return NULL;
329  }
330  if ((GNUNET_OK !=
332  "REVOCATION",
333  "EPOCH_DURATION",
334  &epoch_duration)))
335  {
336  GNUNET_break (0);
337  GNUNET_free (h);
338  return NULL;
339  }
341  (unsigned int) matching_bits,
343  {
344  GNUNET_break (0);
345  GNUNET_free (h);
346  return NULL;
347  }
348 
349 
350  h->mq = GNUNET_CLIENT_connect (cfg,
351  "revocation",
352  handlers,
354  h);
355  if (NULL == h->mq)
356  {
357  GNUNET_free (h);
358  return NULL;
359  }
360  h->func = func;
361  h->func_cls = func_cls;
362  env = GNUNET_MQ_msg (rm,
364  rm->reserved = htonl (0);
365  rm->proof_of_work = *pow;
366  GNUNET_MQ_send (h->mq,
367  env);
368  return h;
369 }
struct GNUNET_REVOCATION_PowP proof_of_work
Number that causes a hash collision with the public_key.
Definition: revocation.h:95
int GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1063
static void revocation_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE
Client to service OR peer-to-peer: revoke this key!
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
void * func_cls
Closure for func.
Revoke key.
Definition: revocation.h:80
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE
Service to client: revocation confirmed.
Message handler for a specific message type.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Key revocation response.
Definition: revocation.h:102
Handle for the key revocation operation.
GNUNET_REVOCATION_Callback func
Function to call once we are done.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
static unsigned long long matching_bits
Number of matching bits required for revocation.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_check_pow(const struct GNUNET_REVOCATION_PowP *pow, unsigned int difficulty, struct GNUNET_TIME_Relative epoch_duration)
Check if the given proof-of-work is valid.
uint32_t reserved
For alignment.
Definition: revocation.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_revoke_cancel()

void GNUNET_REVOCATION_revoke_cancel ( struct GNUNET_REVOCATION_Handle h)

Cancel key revocation.

Parameters
hoperation to cancel

Definition at line 378 of file revocation_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_REVOCATION_Handle::mq.

Referenced by do_shutdown(), handle_revocation_response(), and revocation_mq_error_handler().

379 {
380  if (NULL != h->mq)
381  {
382  GNUNET_MQ_destroy (h->mq);
383  h->mq = NULL;
384  }
385  GNUNET_free (h);
386 }
struct GNUNET_MQ_Handle * mq
Message queue to the service.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_check_pow()

enum GNUNET_GenericReturnValue GNUNET_REVOCATION_check_pow ( const struct GNUNET_REVOCATION_PowP pow,
unsigned int  difficulty,
struct GNUNET_TIME_Relative  epoch_duration 
)

Check if the given proof-of-work is valid.

Parameters
powproof of work
matching_bitshow many bits must match (configuration)
epoch_durationlength of single epoch in configuration
Returns
GNUNET_YES if the pow is acceptable, GNUNET_NO if not

Check if signature valid

First, check if PoW set is strictly monotically increasing

Check expiration

Extend by 10% for unsynchronized clocks

Definition at line 432 of file revocation_api.c.

References buf, count_leading_zeroes(), epochs, GNUNET_CRYPTO_ecdsa_verify_(), GNUNET_CRYPTO_pow_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_ntohll(), GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_REVOCATION, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_multiply(), GNUNET_YES, GNUNET_REVOCATION_PowP::key, GNUNET_REVOCATION_SignaturePurposePS::key, GNUNET_REVOCATION_PowP::pow, POW_COUNT, GNUNET_REVOCATION_SignaturePurposePS::purpose, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_TIME_Relative::rel_value_us, GNUNET_REVOCATION_PowP::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_REVOCATION_SignaturePurposePS::timestamp, and GNUNET_REVOCATION_PowP::timestamp.

Referenced by block_plugin_revocation_evaluate(), ego_callback(), GNUNET_REVOCATION_revoke(), run(), and verify_revoke_message().

435 {
436  char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
437  + sizeof (struct GNUNET_TIME_AbsoluteNBO)
438  + sizeof (uint64_t)] GNUNET_ALIGN;
440  struct GNUNET_HashCode result;
441  struct GNUNET_TIME_Absolute ts;
442  struct GNUNET_TIME_Absolute exp;
443  struct GNUNET_TIME_Relative ttl;
444  struct GNUNET_TIME_Relative buffer;
445  unsigned int score = 0;
446  unsigned int tmp_score = 0;
447  unsigned int epochs;
448  uint64_t pow_val;
449 
453  spurp.key = pow->key;
454  spurp.timestamp = pow->timestamp;
455  spurp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
456  spurp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
457  + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
458  + sizeof (struct GNUNET_TIME_AbsoluteNBO));
459  if (GNUNET_OK !=
461  &spurp.purpose,
462  &pow->signature,
463  &pow->key))
464  {
466  "Proof of work signature invalid!\n");
467  return GNUNET_NO;
468  }
469 
473  for (unsigned int i = 0; i < POW_COUNT - 1; i++)
474  {
475  if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i + 1]))
476  return GNUNET_NO;
477  }
478  GNUNET_memcpy (&buf[sizeof(uint64_t)],
479  &pow->timestamp,
480  sizeof (uint64_t));
481  GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
482  &pow->key,
483  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
484  for (unsigned int i = 0; i < POW_COUNT; i++)
485  {
486  pow_val = GNUNET_ntohll (pow->pow[i]);
487  GNUNET_memcpy (buf, &pow->pow[i], sizeof(uint64_t));
489  buf,
490  sizeof(buf),
491  &result);
492  tmp_score = count_leading_zeroes (&result);
494  "Score %u with %" PRIu64 " (#%u)\n",
495  tmp_score, pow_val, i);
496 
497  score += tmp_score;
498 
499  }
500  score = score / POW_COUNT;
501  if (score < difficulty)
502  return GNUNET_NO;
503  epochs = score - difficulty;
504 
509  ttl = GNUNET_TIME_relative_multiply (epoch_duration,
510  epochs);
514  buffer = GNUNET_TIME_relative_divide (epoch_duration,
515  10);
516  exp = GNUNET_TIME_absolute_add (ts, ttl);
517  exp = GNUNET_TIME_absolute_add (exp,
518  buffer);
519 
521  return GNUNET_NO; /* Not yet valid. */
522  /* Revert to actual start time */
523  ts = GNUNET_TIME_absolute_add (ts,
524  buffer);
525 
526  if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
527  return GNUNET_NO; /* expired */
528  return GNUNET_YES;
529 }
static unsigned int epochs
-e option.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
uint64_t rel_value_us
The actual value.
struct GNUNET_CRYPTO_EcdsaPublicKey key
The revoked public key.
#define POW_COUNT
The proof-of-work narrowing factor.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
The signature object we use for the PoW.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:395
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
static unsigned int count_leading_zeroes(const struct GNUNET_HashCode *hash)
Count the leading zeroes in hash.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
static char buf[2048]
static int result
Global testing status.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442
A 512-bit hashcode.
uint64_t pow[32]
The PoWs.
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature.
void GNUNET_CRYPTO_pow_hash(const struct GNUNET_CRYPTO_PowSalt *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the &#39;proof-of-work&#39; hash (an expensive hash).
Definition: crypto_pow.c:41
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
int GNUNET_CRYPTO_ecdsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:745
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
static struct GNUNET_CRYPTO_PowSalt salt
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:527
Time for absolute times used by GNUnet, in microseconds.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_pow_init()

void GNUNET_REVOCATION_pow_init ( const struct GNUNET_CRYPTO_EcdsaPrivateKey key,
struct GNUNET_REVOCATION_PowP pow 
)

Initializes a fresh PoW computation.

Parameters
keythe key to calculate the PoW for.
powthe pow object to work with in the calculation.
keythe key to calculate the PoW for.
[out]powstarting point for PoW calculation (not yet valid)

Predate the validity period to prevent rejections due to unsynchronized clocks

Definition at line 539 of file revocation_api.c.

References GNUNET_assert, GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_ecdsa_sign_(), GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_REVOCATION, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_absolute_subtract(), GNUNET_TIME_UNIT_WEEKS, GNUNET_REVOCATION_SignaturePurposePS::key, GNUNET_REVOCATION_PowP::key, GNUNET_REVOCATION_SignaturePurposePS::purpose, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_REVOCATION_PowP::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_REVOCATION_SignaturePurposePS::timestamp, and GNUNET_REVOCATION_PowP::timestamp.

Referenced by ego_callback(), and run().

541 {
544 
551 
553  rp.timestamp = pow->timestamp;
554  rp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
555  rp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
556  + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
557  + sizeof (struct GNUNET_TIME_AbsoluteNBO));
559  rp.key = pow->key;
562  &rp.purpose,
563  &pow->signature));
564 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:422
struct GNUNET_CRYPTO_EcdsaPublicKey key
The revoked public key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The signature object we use for the PoW.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature.
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:176
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
int GNUNET_CRYPTO_ecdsa_sign_(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
ECDSA Sign a given block.
Definition: crypto_ecc.c:645
#define GNUNET_TIME_UNIT_WEEKS
One week.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
static char * rp
Relying party.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_pow_start()

struct GNUNET_REVOCATION_PowCalculationHandle* GNUNET_REVOCATION_pow_start ( struct GNUNET_REVOCATION_PowP pow,
int  epochs,
unsigned int  difficulty 
)

Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty.

Parameters
powthe PoW to based calculations on.
epochsthe number of epochs for which the PoW must be valid.
difficultythe base difficulty of the PoW.
Returns
a handle for use in PoW rounds

Definition at line 577 of file revocation_api.c.

References epochs, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_new, GNUNET_TIME_relative_hton(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_YEARS, and pc.

Referenced by ego_callback(), and run().

580 {
582  struct GNUNET_TIME_Relative ttl;
583 
584 
586  pc->pow = pow;
588  epochs);
589  pc->pow->ttl = GNUNET_TIME_relative_hton (ttl);
591  UINT64_MAX);
592  pc->difficulty = difficulty;
593  pc->epochs = epochs;
594  return pc;
595 }
static unsigned int epochs
-e option.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:625
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
The handle to a PoW calculation.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_pow_round()

enum GNUNET_GenericReturnValue GNUNET_REVOCATION_pow_round ( struct GNUNET_REVOCATION_PowCalculationHandle pc)

Calculate a single round in the key revocation PoW.

Parameters
pchandle to the PoW, initially called with NULL.
Returns
GNUNET_YES if the pow is acceptable, GNUNET_NO if not

Calculate a single round in the key revocation PoW.

Parameters
pchandle to the PoW, initially called with NULL.
epochsnumber of epochs for which the revocation must be valid.
powcurrent pow value to try
difficultycurrent base difficulty to achieve
Returns
GNUNET_YES if the pow is acceptable, GNUNET_NO if not

Do not try duplicates

Definition at line 623 of file revocation_api.c.

References GNUNET_REVOCATION_PowCalculationHandle::best, BestPow::bits, buf, calculate_score(), cmp_pow_value(), count_leading_zeroes(), GNUNET_REVOCATION_PowCalculationHandle::current_pow, GNUNET_REVOCATION_PowCalculationHandle::difficulty, GNUNET_REVOCATION_PowCalculationHandle::epochs, GNUNET_CRYPTO_pow_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_htonll(), GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_YES, GNUNET_REVOCATION_PowP::key, BestPow::pow, GNUNET_REVOCATION_PowP::pow, GNUNET_REVOCATION_PowCalculationHandle::pow, POW_COUNT, ret, and GNUNET_REVOCATION_PowP::timestamp.

Referenced by calculate_pow(), and run().

624 {
625  char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
626  + sizeof (uint64_t)
627  + sizeof (uint64_t)] GNUNET_ALIGN;
628  struct GNUNET_HashCode result;
629  unsigned int zeros;
630  int ret;
631  uint64_t pow_nbo;
632 
633  pc->current_pow++;
634 
638  for (unsigned int i = 0; i < POW_COUNT; i++)
639  if (pc->current_pow == pc->best[i].pow)
640  return GNUNET_NO;
641  pow_nbo = GNUNET_htonll (pc->current_pow);
642  GNUNET_memcpy (buf, &pow_nbo, sizeof(uint64_t));
643  GNUNET_memcpy (&buf[sizeof(uint64_t)],
644  &pc->pow->timestamp,
645  sizeof (uint64_t));
646  GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
647  &pc->pow->key,
648  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
650  buf,
651  sizeof(buf),
652  &result);
653  zeros = count_leading_zeroes (&result);
654  for (unsigned int i = 0; i < POW_COUNT; i++)
655  {
656  if (pc->best[i].bits < zeros)
657  {
658  pc->best[i].bits = zeros;
659  pc->best[i].pow = pc->current_pow;
660  pc->pow->pow[i] = pow_nbo;
662  "New best score %u with %" PRIu64 " (#%u)\n",
663  zeros, pc->current_pow, i);
664 
665  break;
666  }
667  }
668  ret = calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
669  GNUNET_NO;
670  if (GNUNET_YES == ret)
671  {
672  /* Sort POWs) */
673  qsort (pc->pow->pow, POW_COUNT, sizeof (uint64_t), &cmp_pow_value);
674  }
675  return ret;
676 }
static unsigned int calculate_score(const struct GNUNET_REVOCATION_PowCalculationHandle *ph)
Calculate the average zeros in the pows.
struct GNUNET_CRYPTO_EcdsaPublicKey key
The revoked public key.
uint64_t current_pow
The current nonce to try.
#define POW_COUNT
The proof-of-work narrowing factor.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct BestPow best[POW_COUNT]
Current set of found PoWs.
uint64_t pow
PoW nonce.
static unsigned int count_leading_zeroes(const struct GNUNET_HashCode *hash)
Count the leading zeroes in hash.
static int cmp_pow_value(const void *a, const void *b)
Comparison function for quicksort.
unsigned int difficulty
The difficulty (leading zeros) to achieve.
static char buf[2048]
struct GNUNET_REVOCATION_PowP * pow
The final PoW result data structure.
static int result
Global testing status.
A 512-bit hashcode.
uint64_t pow[32]
The PoWs.
void GNUNET_CRYPTO_pow_hash(const struct GNUNET_CRYPTO_PowSalt *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the &#39;proof-of-work&#39; hash (an expensive hash).
Definition: crypto_pow.c:41
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
unsigned int bits
Corresponding zero bits in hash.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
static struct GNUNET_CRYPTO_PowSalt salt
unsigned int epochs
Epochs how long the PoW should be valid.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REVOCATION_pow_stop()

void GNUNET_REVOCATION_pow_stop ( struct GNUNET_REVOCATION_PowCalculationHandle pc)

Stop a PoW calculation.

Parameters
pcthe calculation to clean up
Returns
GNUNET_YES if pow valid, GNUNET_NO if pow was set but is not valid

Definition at line 687 of file revocation_api.c.

References GNUNET_free.

Referenced by calculate_pow_shutdown().

688 {
689  GNUNET_free (pc);
690 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: