93 vec_for (json_t *vecs,
const char *vecname)
95 json_t *
t = json_object ();
97 json_object_set_new (t,
99 json_string (vecname));
100 json_array_append_new (vecs, t);
124 json = json_string (buf);
128 json_object_set_new (vec, label, json);
144 json_t *json = json_integer (num);
146 json_object_set_new (vec, label, json);
156 const char *s = json_string_value (json_object_get (vec, name));
175 const char *s = json_string_value (json_object_get (vec, name));
181 len = (strlen (s) * 5) / 8;
205 "checking %s\n", operation);
207 if (0 == strcmp (operation,
"hash"))
239 else if (0 == strcmp (operation,
"ecc_ecdh"))
289 else if (0 == strcmp (operation,
"eddsa_key_derivation"))
322 else if (0 == strcmp (operation,
"eddsa_signing"))
380 else if (0 == strcmp (operation,
"kdf"))
402 out_len_comp = out_len;
443 if (0 != memcmp (out, out_comp, out_len))
450 else if (0 == strcmp (operation,
"eddsa_ecdh"))
462 sizeof (priv_ecdhe)))
480 sizeof (priv_eddsa)))
498 sizeof (key_material)))
512 else if (0 == strcmp (operation,
"rsa_blind_signing"))
522 void *blinded_data_comp;
523 size_t blinded_len_comp;
524 void *public_enc_data;
525 size_t public_enc_len;
526 void *secret_enc_data;
527 size_t secret_enc_len;
529 size_t sig_enc_length;
530 void *sig_enc_data_comp;
531 size_t sig_enc_length_comp;
536 sizeof (message_hash)))
543 "blinding_key_secret",
600 if ( (blinded_len != blinded_len_comp) || (0 != memcmp (blinded_data,
616 if ( (sig_enc_length != sig_enc_length_comp) ||
617 (0 != memcmp (sig_enc_data, sig_enc_data_comp, sig_enc_length) ))
626 "unsupported operation '%s'\n", operation);
641 json_t *vecfile = json_loadf (stdin, 0, &err);
642 const char *encoding;
650 encoding = json_string_value (json_object_get (vecfile,
652 if ( (NULL == encoding) || (0 != strcmp (encoding,
"base32crockford")) )
655 json_decref (vecfile);
658 vectors = json_object_get (vecfile,
"vectors");
659 if (!json_is_array (vectors))
662 json_decref (vecfile);
671 json_array_foreach (vectors, index, value) {
672 const char *
op = json_string_value (json_object_get (value,
678 "missing operation\n");
687 (
unsigned int) index);
703 json_t *vecfile = json_object ();
704 json_t *vecs = json_array ();
706 json_object_set_new (vecfile,
708 json_string (
"base32crockford"));
709 json_object_set_new (vecfile,
711 json_string (
"GNUnet " PACKAGE_VERSION
" " VCS_VERSION));
712 json_object_set_new (vecfile,
717 json_t *vec =
vec_for (vecs,
"hash");
719 char *str =
"Hello, GNUnet";
723 d2j (vec,
"input", str, strlen (str));
727 json_t *vec =
vec_for (vecs,
"ecc_ecdh");
761 json_t *vec =
vec_for (vecs,
"eddsa_key_derivation");
779 json_t *vec =
vec_for (vecs,
"eddsa_signing");
818 json_t *vec =
vec_for (vecs,
"kdf");
821 char *ikm =
"I'm the secret input key material";
822 char *
salt =
"I'm very salty";
823 char *
ctx =
"I'm a context chunk, also known as 'info' in the RFC";
850 (
unsigned int) out_len);
857 json_t *vec =
vec_for (vecs,
"eddsa_ecdh");
870 d2j (vec,
"priv_ecdhe",
873 d2j (vec,
"pub_ecdhe",
876 d2j (vec,
"priv_eddsa",
879 d2j (vec,
"pub_eddsa",
882 d2j (vec,
"key_material",
888 json_t *vec =
vec_for (vecs,
"rsa_blind_signing");
898 void *public_enc_data;
899 size_t public_enc_len;
900 void *secret_enc_data;
901 size_t secret_enc_len;
902 void *blinded_sig_enc_data;
903 size_t blinded_sig_enc_length;
905 size_t sig_enc_length;
933 blinded_sig_enc_data);
948 "blinding_key_secret",
957 blinded_sig_enc_data,
958 blinded_sig_enc_length);
973 json_dumpf (vecfile, stdout, JSON_INDENT (2));
974 json_decref (vecfile);
1016 "verify a test vector from stdin"),
1027 "gnunet-crypto-tvg",
1028 "Generate test vectors for cryptographic operations",
struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_decode(const void *buf, size_t buf_size)
Decode the private key from the data-format back to the "normal", internal format.
static int expect_data_dynamic(json_t *vec, const char *name, void **data, size_t *ret_len)
int GNUNET_CRYPTO_rsa_blind(const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, void **buf, size_t *buf_size)
Blinds the given message with the given blinding key.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(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, parse options).
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static char * pkey
Public key of the zone to look in, in ASCII.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_verify(const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaPublicKey *public_key)
Verify whether the given hash corresponds to the given signature and the signature is valid with resp...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
Encode the given signature in a format suitable for storing it into a file.
static GNUNET_NETWORK_STRUCT_END int verify_flag
Should we verify or output test vectors?
Definition of a command line option.
static struct GNUNET_SCHEDULER_Task * t
Main task.
struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_create(unsigned int len)
Create a new private key.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
static int expect_data_fixed(json_t *vec, const char *name, void *data, size_t expect_len)
The public information of an RSA key pair.
static void d2j(json_t *vec, const char *label, const void *data, size_t size)
Add a base32crockford encoded value to a test vector.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
size_t GNUNET_CRYPTO_rsa_private_key_encode(const struct GNUNET_CRYPTO_RsaPrivateKey *key, void **buffer)
Encode the private key in a format suitable for storing it into a file.
static int global_ret
Global exit code.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
static char * value
Value of the record to add/remove.
static void uint2j(json_t *vec, const char *label, unsigned int num)
Add a number to a test vector.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EdDSA public key and a private ECDH key.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode(const char *buf, size_t len)
Decode the public key from the data-format back to the "normal", internal format. ...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
#define GNUNET_SIGNATURE_PURPOSE_TEST
Test signature, not valid for anything other than writing a test.
static json_t * vec_for(json_t *vecs, const char *vecname)
Create a fresh test vector for a given operation label.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a public and a private ECC key.
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_unblind(const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey)
Unblind a blind-signed signature.
Private ECC key encoded for transmission.
int main(int argc, char *const *argv)
The main function of the test vector generation tool.
static unsigned int size
Size of the "table".
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
an ECC signature using EdDSA.
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.
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calcualations.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
Private ECC key encoded for transmission.
static int output_vectors()
Output test vectors.
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_sign_blinded(const struct GNUNET_CRYPTO_RsaPrivateKey *key, const void *msg, size_t msg_len)
Sign a blinded value, which must be a full domain hash of a message.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
#define GNUNET_log(kind,...)
static int checkvec(const char *operation, json_t *vec)
Check a single vector.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
The private information of an RSA key pair.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_private_key_get_public(const struct GNUNET_CRYPTO_RsaPrivateKey *priv)
Extract the public key of the given private key.
Constant-size pre-secret for blinding key generation.
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static struct GNUNET_ARM_Operation * op
Current operation.
static int check_vectors()
Check test vectors from stdin.
uint32_t data
The data value.
void GNUNET_CRYPTO_rsa_private_key_free(struct GNUNET_CRYPTO_RsaPrivateKey *key)
Free memory occupied by the private key.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define gettext_noop(String)
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...