GNUnet 0.22.2
gnunet-scrypt.c File Reference

tool to manipulate SCRYPT proofs of work. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include <gcrypt.h>
Include dependency graph for gnunet-scrypt.c:

Go to the source code of this file.

Macros

#define ROUND_SIZE   10
 

Functions

static void shutdown_task (void *cls)
 Write our current proof to disk. More...
 
static void find_proof (void *cls)
 Find our proof of work. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 Program to manipulate ECC key files. More...
 

Variables

static struct GNUNET_CRYPTO_PowSalt salt = { "gnunet-nse-proof" }
 Salt for PoW calculations. More...
 
static unsigned long long nse_work_required
 Amount of work required (W-bit collisions) for NSE proofs, in collision-bits. More...
 
static struct GNUNET_TIME_Relative proof_find_delay
 Interval between proof find runs. More...
 
static struct GNUNET_CRYPTO_EddsaPublicKey pub
 
static uint64_t proof
 
static struct GNUNET_SCHEDULER_Taskproof_task
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 
static char * pkfn
 
static char * pwfn
 

Detailed Description

tool to manipulate SCRYPT proofs of work.

Author
Bart Polot

Definition in file gnunet-scrypt.c.

Macro Definition Documentation

◆ ROUND_SIZE

#define ROUND_SIZE   10

Function Documentation

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Write our current proof to disk.

Parameters
clsclosure

Definition at line 66 of file gnunet-scrypt.c.

67{
68 (void) cls;
69 if (GNUNET_OK !=
71 &proof,
72 sizeof(proof),
76 "write",
77 pwfn);
78}
static uint64_t proof
Definition: gnunet-scrypt.c:49
static char * pwfn
Definition: gnunet-scrypt.c:57
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition: disk.c:722
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_OK
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING

References GNUNET_DISK_fn_write(), GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror_file, GNUNET_OK, proof, and pwfn.

Referenced by find_proof(), and run().

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

◆ find_proof()

static void find_proof ( void *  cls)
static

Find our proof of work.

Parameters
clsclosure (unused)

Definition at line 87 of file gnunet-scrypt.c.

88{
89#define ROUND_SIZE 10
90 uint64_t counter;
91 char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
92 + sizeof(uint64_t)] GNUNET_ALIGN;
94 unsigned int i;
96 struct GNUNET_TIME_Relative elapsed;
97
98 (void) cls;
100 "Got Proof of Work %llu\n",
101 (unsigned long long) proof);
102 proof_task = NULL;
103 GNUNET_memcpy (&buf[sizeof(uint64_t)],
104 &pub,
105 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
106 i = 0;
107 counter = proof;
109 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
110 {
111 GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
113 buf,
114 sizeof(buf),
115 &result);
116 if (nse_work_required <=
118 {
119 proof = counter;
120 fprintf (stdout,
121 "Proof of work found: %llu!\n",
122 (unsigned long long) proof);
124 return;
125 }
126 counter++;
127 i++;
128 }
130 elapsed = GNUNET_TIME_relative_divide (elapsed, ROUND_SIZE);
132 "Current: %llu [%s/proof]\n",
133 (unsigned long long) counter,
135 if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
136 {
138 "Testing proofs currently at %llu\n",
139 (unsigned long long) counter);
140 /* remember progress every 100 rounds */
141 proof = counter;
142 shutdown_task (NULL);
143 }
144 else
145 {
146 proof = counter;
147 }
148 proof_task =
151 &find_proof,
152 NULL);
153}
static uint64_t timestamp(void)
Get current timestamp.
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
static struct GNUNET_SCHEDULER_Task * proof_task
Definition: gnunet-scrypt.c:51
static void find_proof(void *cls)
Find our proof of work.
Definition: gnunet-scrypt.c:87
static struct GNUNET_TIME_Relative proof_find_delay
Interval between proof find runs.
Definition: gnunet-scrypt.c:45
static void shutdown_task(void *cls)
Write our current proof to disk.
Definition: gnunet-scrypt.c:66
static unsigned long long nse_work_required
Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
Definition: gnunet-scrypt.c:40
#define ROUND_SIZE
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calculations.
Definition: gnunet-scrypt.c:34
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:174
#define GNUNET_log(kind,...)
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_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1207
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:438
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
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:552
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
A 512-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

References find_proof(), GNUNET_ALIGN, GNUNET_CRYPTO_hash_count_leading_zeros(), GNUNET_CRYPTO_pow_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_memcpy, GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_SCHEDULER_shutdown(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_relative_divide(), nse_work_required, proof, proof_find_delay, proof_task, pub, result, ROUND_SIZE, salt, shutdown_task(), and timestamp().

Referenced by find_proof(), and run().

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

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle config 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 165 of file gnunet-scrypt.c.

169{
171 char *pids;
172
173 (void) cls;
174 (void) args;
175 (void) cfgfile;
176 cfg = config;
177 /* load proof of work */
178 if (NULL == pwfn)
179 {
181 "NSE",
182 "PROOFFILE",
183 &pwfn))
184 {
187 return;
188 }
189 }
190 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Proof of Work file: %s\n", pwfn);
192 (sizeof(proof) != GNUNET_DISK_fn_read (pwfn, &proof, sizeof(proof))))
193 proof = 0;
194
195 /* load private key */
196 if (NULL == pkfn)
197 {
199 "PEER",
200 "PRIVATE_KEY",
201 &pkfn))
202 {
204 "PEER",
205 "PRIVATE_KEY");
206 return;
207 }
208 }
209 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
210 if (GNUNET_SYSERR ==
213 &pk))
214 {
215 fprintf (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
217 return;
218 }
221 &pub);
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids);
224 GNUNET_free (pids);
225
226 /* get target bit amount */
227 if (0 == nse_work_required)
228 {
230 "NSE",
231 "WORKBITS",
233 {
236 return;
237 }
238 if (nse_work_required >= sizeof(struct GNUNET_HashCode) * 8)
239 {
241 "NSE",
242 "WORKBITS",
243 _ ("Value is too large.\n"));
245 return;
246 }
247 else if (0 == nse_work_required)
248 {
250 return;
251 }
252 }
254
256 "Delay between tries: %s\n",
258 proof_task =
260 &find_proof,
261 NULL);
263}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
const struct GNUNET_CONFIGURATION_Handle * config
static const struct GNUNET_CONFIGURATION_Handle * cfg
Definition: gnunet-scrypt.c:53
static char * pkfn
Definition: gnunet-scrypt.c:55
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
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_CRYPTO_eddsa_key_from_file(const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
Create a new private key by reading it from a file.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:201
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:506
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:660
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:255
@ GNUNET_YES
@ GNUNET_SYSERR
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1339
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1231
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Private ECC key encoded for transmission.

References _, consensus-simulation::args, cfg, config, find_proof(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_DISK_file_test(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_log_config_invalid(), GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_SCHEDULER_shutdown(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_YES, nse_work_required, pk, pkfn, proof, proof_find_delay, proof_task, pub, pwfn, and shutdown_task().

Referenced by main().

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

◆ main()

int main ( int  argc,
char *const *  argv 
)

Program to manipulate ECC key files.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 274 of file gnunet-scrypt.c.

275{
278 'b',
279 "bits",
280 "BITS",
281 gettext_noop ("number of bits to require for the proof of work"),
284 'k',
285 "keyfile",
286 "FILE",
287 gettext_noop ("file with private key, otherwise default is used"),
288 &pkfn),
290 'o',
291 "outfile",
292 "FILE",
293 gettext_noop ("file with proof of work, otherwise default is used"),
294 &pwfn),
296 "timeout",
297 "TIME",
299 "time to wait between calculations"),
302 };
303 int ret;
304
305 ret =
306 (GNUNET_OK ==
308 argc,
309 argv,
310 "gnunet-scrypt [OPTIONS] prooffile",
311 gettext_noop ("Manipulate GNUnet proof of work files"),
312 options,
313 &run,
314 NULL))
315 ? 0
316 : 1;
318 return ret;
319}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
static int ret
Final status code.
Definition: gnunet-arm.c:93
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main function that will be run by the scheduler.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_filename(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a filename (automatically path expanded).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_ulong(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned long long *val)
Allow user to specify an unsigned long long.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:407
Definition of a command line option.

References gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_filename(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_ulong(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), nse_work_required, options, pkfn, proof_find_delay, pwfn, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ salt

◆ nse_work_required

unsigned long long nse_work_required
static

Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.

Definition at line 40 of file gnunet-scrypt.c.

Referenced by find_proof(), main(), and run().

◆ proof_find_delay

struct GNUNET_TIME_Relative proof_find_delay
static

Interval between proof find runs.

Definition at line 45 of file gnunet-scrypt.c.

Referenced by find_proof(), main(), and run().

◆ pub

struct GNUNET_CRYPTO_EddsaPublicKey pub
static

Definition at line 47 of file gnunet-scrypt.c.

Referenced by calc_r_dash(), checkvec(), clean_blind_sign_pub(), create_finished(), cs_full_domain_hash(), derive_h(), derive_ublock_encryption_key(), elligator_generate_public_key(), find_proof(), get_nick_record(), get_update_information_directory(), GNR_derive_block_aes_key(), GNR_derive_block_xsalsa_key(), GNUNET_CRYPTO_blind_sign_keys_create_va(), GNUNET_CRYPTO_cs_calc_blinded_c(), GNUNET_CRYPTO_cs_private_key_get_public(), GNUNET_CRYPTO_cs_verify(), GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdh_ecdsa(), GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_ecdhe_elligator_encoding(), GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_ecdsa_ecdh(), GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_CRYPTO_ecdsa_verify_(), GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_CRYPTO_eddsa_kem_encaps(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_CRYPTO_eddsa_public_key_derive(), GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_CRYPTO_eddsa_verify_(), GNUNET_CRYPTO_edx25519_key_get_public(), GNUNET_CRYPTO_edx25519_private_key_derive(), GNUNET_CRYPTO_edx25519_public_key_derive(), GNUNET_CRYPTO_edx25519_verify_(), GNUNET_CRYPTO_hpke_kem_encaps(), GNUNET_CRYPTO_rsa_private_key_get_public(), GNUNET_CRYPTO_signature_verify_(), GNUNET_CRYPTO_signature_verify_raw_(), GNUNET_CRYPTO_x25519_ecdh(), GNUNET_FS_publish_ublock_(), GNUNET_GNSRECORD_query_from_private_key(), GNUNET_GNSRECORD_query_from_public_key(), GNUNET_PQ_query_param_blind_sign_pub(), GNUNET_PQ_result_spec_blind_sign_pub(), issue_ticket(), output_vectors(), and run().

◆ proof

◆ proof_task

struct GNUNET_SCHEDULER_Task* proof_task
static

Definition at line 51 of file gnunet-scrypt.c.

Referenced by find_proof(), and run().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Definition at line 53 of file gnunet-scrypt.c.

Referenced by run().

◆ pkfn

char* pkfn
static

Definition at line 55 of file gnunet-scrypt.c.

Referenced by main(), and run().

◆ pwfn

char* pwfn
static

Definition at line 57 of file gnunet-scrypt.c.

Referenced by main(), run(), and shutdown_task().