GNUnet  0.20.0
Revocation service

Perform and access key revocations. More...

Collaboration diagram for Revocation service:

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 GNUNET_REVOCATION_MAX_PROOF_SIZE
 Maximum length of a revocation. 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_IDENTITY_PublicKey *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_IDENTITY_PrivateKey *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...
 
size_t GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow)
 

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 57 of file gnunet_revocation_service.h.

◆ GNUNET_REVOCATION_MAX_PROOF_SIZE

#define GNUNET_REVOCATION_MAX_PROOF_SIZE
Value:
sizeof(struct GNUNET_REVOCATION_PowP) +\
sizeof(struct GNUNET_IDENTITY_PublicKey) +\
1024
An identity key as per LSD0001.
Struct for a proof of work as part of the revocation.

Maximum length of a revocation.

Definition at line 62 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 70 of file gnunet_revocation_service.h.

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 139 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_IDENTITY_PublicKey key,
GNUNET_REVOCATION_Callback  func,
void *  func_cls 
)

Check if a key was revoked.

Parameters
cfgthe configuration to use
keykey to check for revocation
funcfunction 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.

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  size_t key_len;
179 
181  "revocation",
182  handlers,
184  q);
185  if (NULL == q->mq)
186  {
187  GNUNET_free (q);
188  return NULL;
189  }
190  q->func = func;
191  q->func_cls = func_cls;
193  env = GNUNET_MQ_msg_extra (qm, key_len,
196  qm->key_len = htonl (key_len);
197  GNUNET_MQ_send (q->mq,
198  env);
199  return q;
200 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
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:1057
ssize_t GNUNET_IDENTITY_write_public_key_to_buffer(const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PublicKey to a compact buffer.
Definition: identity_api.c:890
ssize_t GNUNET_IDENTITY_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:830
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY
Client to service: was this key revoked?
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE
Service to client: answer if key was revoked!
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...
Message handler for a specific message type.
Handle for the key revocation query.
void * func_cls
Closure for func.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
GNUNET_REVOCATION_Callback func
Function to call with the result.
Query key revocation status.
Definition: revocation.h:38
uint32_t key_len
Key length.
Definition: revocation.h:47
Key revocation response.
Definition: revocation.h:59

References cfg, env, GNUNET_REVOCATION_Query::func, GNUNET_REVOCATION_Query::func_cls, GNUNET_CLIENT_connect(), GNUNET_free, GNUNET_IDENTITY_public_key_get_length(), GNUNET_IDENTITY_write_public_key_to_buffer(), GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, handlers, key, QueryMessage::key_len, GNUNET_REVOCATION_Query::mq, q, and query_mq_error_handler().

Referenced by recursive_gns_resolution_revocation(), and run().

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 209 of file revocation_api.c.

210 {
211  if (NULL != q->mq)
212  {
214  q->mq = NULL;
215  }
216  GNUNET_free (q);
217 }
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683

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

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

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)
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

Definition at line 303 of file revocation_api.c.

307 {
311  GNUNET_MQ_hd_fixed_size (revocation_response,
314  h),
316  };
317  unsigned long long matching_bits;
319  struct RevokeMessage *rm;
320  struct GNUNET_MQ_Envelope *env;
321 
322  if ((GNUNET_OK !=
324  "REVOCATION",
325  "WORKBITS",
326  &matching_bits)))
327  {
328  GNUNET_break (0);
329  GNUNET_free (h);
330  return NULL;
331  }
332  if ((GNUNET_OK !=
334  "REVOCATION",
335  "EPOCH_DURATION",
336  &epoch_duration)))
337  {
338  GNUNET_break (0);
339  GNUNET_free (h);
340  return NULL;
341  }
343  (unsigned int) matching_bits,
345  {
346  GNUNET_break (0);
347  GNUNET_free (h);
348  return NULL;
349  }
350 
351 
353  "revocation",
354  handlers,
356  h);
357  if (NULL == h->mq)
358  {
359  GNUNET_free (h);
360  return NULL;
361  }
362  h->func = func;
363  h->func_cls = func_cls;
364  size_t extra_len = GNUNET_REVOCATION_proof_get_size (pow);
365  env = GNUNET_MQ_msg_extra (rm,
366  extra_len,
368  rm->pow_size = htonl (extra_len);
369  memcpy (&rm[1], pow, extra_len);
370  GNUNET_MQ_send (h->mq,
371  env);
372  return h;
373 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
static unsigned long long matching_bits
Number of matching bits required for revocation.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue 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.
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE
Client to service OR peer-to-peer: revoke this key!
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE
Service to client: revocation confirmed.
size_t GNUNET_REVOCATION_proof_get_size(const struct GNUNET_REVOCATION_PowP *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.
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...
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
Handle for the key revocation operation.
Time for relative time used by GNUnet, in microseconds.
Key revocation response.
Definition: revocation.h:99
Revoke key.
Definition: revocation.h:80
uint32_t pow_size
Length of PoW with signature.
Definition: revocation.h:89

References cfg, env, epoch_duration, 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_extra, GNUNET_MQ_send(), GNUNET_new, GNUNET_OK, GNUNET_REVOCATION_check_pow(), GNUNET_REVOCATION_proof_get_size(), GNUNET_YES, h, handlers, matching_bits, GNUNET_ARM_Handle::mq, RevokeMessage::pow_size, and revocation_mq_error_handler().

Referenced by perform_revocation().

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 377 of file revocation_api.c.

378 {
379  if (NULL != h->mq)
380  {
382  h->mq = NULL;
383  }
384  GNUNET_free (h);
385 }

References GNUNET_free, GNUNET_MQ_destroy(), h, and GNUNET_ARM_Handle::mq.

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

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
Parameters
powproof of work
difficultyhow many bits must match (configuration) LSD0001: D
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 406 of file revocation_api.c.

470 {
471  char buf[sizeof(struct GNUNET_IDENTITY_PublicKey)
472  + sizeof (struct GNUNET_TIME_AbsoluteNBO)
473  + sizeof (uint64_t)] GNUNET_ALIGN;
474  struct GNUNET_HashCode result;
475  struct GNUNET_TIME_Absolute ts;
476  struct GNUNET_TIME_Absolute exp;
477  struct GNUNET_TIME_Relative ttl;
478  struct GNUNET_TIME_Relative buffer;
479  /* LSD0001: D' */
480  unsigned int score = 0;
481  unsigned int tmp_score = 0;
482  unsigned int epochs;
483  uint64_t pow_val;
484  ssize_t pklen;
485  const struct GNUNET_IDENTITY_PublicKey *pk;
486 
487  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
488 
492  if (GNUNET_OK != check_signature (pow))
493  {
495  "Proof of work signature invalid!\n");
496  return GNUNET_SYSERR;
497  }
498 
502  for (unsigned int i = 0; i < POW_COUNT - 1; i++)
503  {
504  if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i + 1]))
505  return GNUNET_NO;
506  }
507  GNUNET_memcpy (&buf[sizeof(uint64_t)],
508  &pow->timestamp,
509  sizeof (uint64_t));
511  if (0 > pklen)
512  {
513  GNUNET_break (0);
514  return GNUNET_NO;
515  }
516  GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
517  pk,
518  pklen);
519  for (unsigned int i = 0; i < POW_COUNT; i++)
520  {
521  pow_val = GNUNET_ntohll (pow->pow[i]);
522  GNUNET_memcpy (buf, &pow->pow[i], sizeof(uint64_t));
524  buf,
525  sizeof(buf),
526  &result);
529  "Score %u with %" PRIu64 " (#%u)\n",
530  tmp_score, pow_val, i);
531 
532  score += tmp_score;
533 
534  }
535  score = score / POW_COUNT;
536  if (score < difficulty)
537  return GNUNET_NO;
538  /* LSD0001: (D'-D+1) */
539  epochs = score - difficulty + 1;
540 
546  epochs);
551  10);
552  exp = GNUNET_TIME_absolute_add (ts, ttl);
553  exp = GNUNET_TIME_absolute_add (exp,
554  buffer);
555 
556  if (0 != GNUNET_TIME_absolute_get_remaining (ts).rel_value_us)
557  return GNUNET_NO; /* Not yet valid. */
558  /* Revert to actual start time */
559  ts = GNUNET_TIME_absolute_add (ts,
560  buffer);
561 
562  if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
563  return GNUNET_NO; /* expired */
564  return GNUNET_YES;
565 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
static int result
Global testing status.
static unsigned int epochs
-e option.
static char buf[2048]
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
Definition: crypto_hash.c:177
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
void GNUNET_CRYPTO_pow_hash(const struct GNUNET_CRYPTO_PowSalt *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the 'proof-of-work' hash (an expensive hash).
Definition: crypto_pow.c:42
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define POW_COUNT
The proof-of-work narrowing factor.
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:405
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
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:484
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:450
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:550
static struct GNUNET_CRYPTO_PowSalt salt
enum GNUNET_GenericReturnValue check_signature(const struct GNUNET_REVOCATION_PowP *pow)
A 512-bit hashcode.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.

Referenced by ego_callback(), GNUNET_REVOCATION_revoke(), run(), and run_with_key().

Here is the caller graph for this function:

◆ GNUNET_REVOCATION_pow_init()

void GNUNET_REVOCATION_pow_init ( const struct GNUNET_IDENTITY_PrivateKey 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)

Definition at line 619 of file revocation_api.c.

621 {
622  GNUNET_assert (GNUNET_OK == sign_pow (key, pow));
623 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue sign_pow(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)

References GNUNET_assert, GNUNET_OK, key, and sign_pow().

Referenced by ego_callback(), and run_with_key().

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 627 of file revocation_api.c.

630 {
632  struct GNUNET_TIME_Relative ttl;
633 
634 
636  pc->pow = pow;
638  epochs);
639  pc->pow->ttl = GNUNET_TIME_relative_hton (ttl);
641  UINT64_MAX);
642  pc->difficulty = difficulty;
643  pc->epochs = epochs;
644  return pc;
645 }
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:618
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
The handle to a PoW calculation.

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

Referenced by ego_callback(), run(), and run_with_key().

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 656 of file revocation_api.c.

674 {
675  char buf[sizeof(struct GNUNET_IDENTITY_PublicKey)
676  + sizeof (uint64_t)
677  + sizeof (uint64_t)] GNUNET_ALIGN;
678  struct GNUNET_HashCode result;
679  const struct GNUNET_IDENTITY_PublicKey *pk;
680  unsigned int zeros;
681  int ret;
682  uint64_t pow_nbo;
683  ssize_t ksize;
684 
685  pc->current_pow++;
686  pk = (const struct GNUNET_IDENTITY_PublicKey *) &(pc->pow[1]);
687 
691  for (unsigned int i = 0; i < POW_COUNT; i++)
692  if (pc->current_pow == pc->best[i].pow)
693  return GNUNET_NO;
694  pow_nbo = GNUNET_htonll (pc->current_pow);
695  GNUNET_memcpy (buf, &pow_nbo, sizeof(uint64_t));
696  GNUNET_memcpy (&buf[sizeof(uint64_t)],
697  &pc->pow->timestamp,
698  sizeof (uint64_t));
700  GNUNET_assert (0 < ksize);
701  GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
702  pk,
703  ksize);
705  buf,
706  sizeof(buf),
707  &result);
709  for (unsigned int i = 0; i < POW_COUNT; i++)
710  {
711  if (pc->best[i].bits < zeros)
712  {
713  pc->best[i].bits = zeros;
714  pc->best[i].pow = pc->current_pow;
715  pc->pow->pow[i] = pow_nbo;
717  "New best score %u with %" PRIu64 " (#%u)\n",
718  zeros, pc->current_pow, i);
719 
720  break;
721  }
722  }
723  ret = calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
724  GNUNET_NO;
725  if (GNUNET_YES == ret)
726  {
727  /* Sort POWs) */
728  qsort (pc->pow->pow, POW_COUNT, sizeof (uint64_t), &cmp_pow_value);
729  }
730  return ret;
731 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
static unsigned int calculate_score(const struct GNUNET_REVOCATION_PowCalculationHandle *ph)
Calculate the average zeros in the pows.
static int cmp_pow_value(const void *a, const void *b)
Comparison function for quicksort.

Referenced by calculate_pow(), and run_with_key().

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 742 of file revocation_api.c.

743 {
744  GNUNET_free (pc);
745 }

References GNUNET_free, and pc.

Referenced by calculate_pow_shutdown().

Here is the caller graph for this function:

◆ GNUNET_REVOCATION_proof_get_size()

size_t GNUNET_REVOCATION_proof_get_size ( const struct GNUNET_REVOCATION_PowP pow)

Definition at line 749 of file revocation_api.c.

750 {
751  size_t size;
752  size_t ksize;
753  const struct GNUNET_IDENTITY_PublicKey *pk;
754 
755  size = sizeof (struct GNUNET_REVOCATION_PowP);
756  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
758  size += ksize;
760  return size;
761 }
ssize_t GNUNET_IDENTITY_signature_get_raw_length_by_type(uint32_t type)
Get the compacted length of a signature by type.
Definition: identity_api.c:970
static unsigned int size
Size of the "table".
Definition: peer.c:68
uint32_t type
Type of public key.

References GNUNET_IDENTITY_public_key_get_length(), GNUNET_IDENTITY_signature_get_raw_length_by_type(), pk, size, and GNUNET_IDENTITY_PrivateKey::type.

Referenced by calculate_pow(), GNUNET_REVOCATION_revoke(), run(), run_with_key(), and sync_pow().

Here is the call graph for this function:
Here is the caller graph for this function: