96 for (
unsigned int j = 0; j<
POW_COUNT; j++)
114 spurp->
purpose.
size = htonl (
sizeof(*spurp) + ksize);
133 sig = ((
unsigned char*) &pow[1] + ksize);
165 unsigned int difficulty,
177 unsigned int score = 0;
178 unsigned int tmp_score = 0;
192 "Proof of work signature invalid!\n");
199 for (
unsigned int i = 0; i <
POW_COUNT - 1; i++)
216 for (
unsigned int i = 0; i <
POW_COUNT; i++)
226 "Score %u with %" PRIu64
" (#%u)\n",
227 tmp_score, pow_val, i);
233 if (score < difficulty)
236 epochs = score - difficulty + 1;
286 sig = ((
char*) &pow[1]) + ksize;
340 pc->difficulty = difficulty;
389 for (
unsigned int i = 0; i <
POW_COUNT; i++)
390 if (
pc->current_pow ==
pc->best[i].pow)
407 for (
unsigned int i = 0; i <
POW_COUNT; i++)
409 if (
pc->best[i].bits < zeros)
411 pc->best[i].bits = zeros;
412 pc->best[i].pow =
pc->current_pow;
413 pc->pow->pow[i] = pow_nbo;
415 "New best score %u with %" PRIu64
" (#%u)\n",
416 zeros,
pc->current_pow, i);
API for GNS record-related crypto.
static unsigned int calculate_score(const struct GNUNET_GNSRECORD_PowCalculationHandle *ph)
Calculate the average zeros in the pows.
static enum GNUNET_GenericReturnValue sign_pow_identity(const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_GNSRECORD_PowP *pow)
static enum GNUNET_GenericReturnValue check_signature(const struct GNUNET_GNSRECORD_PowP *pow)
struct GNUNET_GNSRECORD_SignaturePurposePS * GNR_create_signature_message(const struct GNUNET_GNSRECORD_PowP *pow)
Create the revocation metadata to sign for a revocation message.
static int cmp_pow_value(const void *a, const void *b)
Comparison function for quicksort.
static struct GNUNET_CRYPTO_PowSalt salt
static enum GNUNET_GenericReturnValue sign_pow(const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_GNSRECORD_PowP *pow)
static enum GNUNET_GenericReturnValue check_signature_identity(const struct GNUNET_GNSRECORD_PowP *pow, const struct GNUNET_CRYPTO_PublicKey *key)
static int ret
Final status code.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static char * rp
Relying party.
static int result
Global testing status.
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
static unsigned int epochs
-e option.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
API that can be used to manipulate GNS record data.
#define GNUNET_SIGNATURE_PURPOSE_GNS_REVOCATION
GNS zone key revocation (GNS)
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).
size_t GNUNET_GNSRECORD_proof_get_size(const struct GNUNET_GNSRECORD_PowP *pow)
#define POW_COUNT
The proof-of-work narrowing factor.
void GNUNET_GNSRECORD_pow_stop(struct GNUNET_GNSRECORD_PowCalculationHandle *pc)
Stop a PoW calculation.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_pow_round(struct GNUNET_GNSRECORD_PowCalculationHandle *pc)
Calculate a key revocation valid for broadcasting for a number of epochs.
void GNUNET_GNSRECORD_pow_init(const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_GNSRECORD_PowP *pow)
Initializes a fresh PoW computation.
struct GNUNET_GNSRECORD_PowCalculationHandle * GNUNET_GNSRECORD_pow_start(struct GNUNET_GNSRECORD_PowP *pow, int epochs, unsigned int difficulty)
Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_check_pow(const struct GNUNET_GNSRECORD_PowP *pow, unsigned int difficulty, struct GNUNET_TIME_Relative epoch_duration)
Check if the given proof-of-work is valid.
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_raw_(const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, unsigned char *sig)
Sign a given block.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_signature_verify_raw_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const unsigned char *sig, const struct GNUNET_CRYPTO_PublicKey *pub)
Verify a given signature.
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
#define GNUNET_log(kind,...)
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer(const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
ssize_t GNUNET_CRYPTO_signature_get_raw_length_by_type(uint32_t type)
Get the compacted length of a signature by type.
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).
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#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_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
#define GNUNET_TIME_UNIT_WEEKS
One week.
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.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
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.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
static unsigned int size
Size of the "table".
unsigned int bits
Corresponding zero bits in hash.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Value for a salt for GNUNET_CRYPTO_pow_hash().
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
An identity key as per LSD0001.
The handle to a PoW calculation.
unsigned int difficulty
The difficulty (leading zeros) to achieve.
unsigned int epochs
Epochs how long the PoW should be valid.
struct BestPow best[POW_COUNT]
Current set of found PoWs.
struct GNUNET_GNSRECORD_PowP * pow
The final PoW result data structure.
uint64_t current_pow
The current nonce to try.
Struct for a proof of work as part of the revocation.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
uint64_t pow[32]
The PoWs.
The signature object we use for the PoW.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
The signature purpose.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.