GNUnet  0.19.4
crypto_ecc.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012, 2013, 2015 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
28 #include "platform.h"
29 #include <gcrypt.h>
30 #include <sodium.h>
31 #include "gnunet_util_lib.h"
32 #include "benchmark.h"
33 
34 #define EXTRA_CHECKS 0
35 
59 #define CURVE "Ed25519"
60 
61 #define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
62 
63 #define LOG_STRERROR(kind, syscall) \
64  GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
65 
66 #define LOG_STRERROR_FILE(kind, syscall, filename) \
67  GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
68 
74 #define LOG_GCRY(level, cmd, rc) \
75  do \
76  { \
77  LOG (level, \
78  _ ("`%s' failed at %s:%d with error: %s\n"), \
79  cmd, \
80  __FILE__, \
81  __LINE__, \
82  gcry_strerror (rc)); \
83  } while (0)
84 
85 
95 static int
96 key_from_sexp (gcry_mpi_t *array,
97  gcry_sexp_t sexp,
98  const char *topname,
99  const char *elems)
100 {
101  gcry_sexp_t list;
102  gcry_sexp_t l2;
103  unsigned int idx;
104 
105  list = gcry_sexp_find_token (sexp, topname, 0);
106  if (! list)
107  return 1;
108  l2 = gcry_sexp_cadr (list);
109  gcry_sexp_release (list);
110  list = l2;
111  if (! list)
112  return 2;
113 
114  idx = 0;
115  for (const char *s = elems; *s; s++, idx++)
116  {
117  l2 = gcry_sexp_find_token (list, s, 1);
118  if (! l2)
119  {
120  for (unsigned int i = 0; i < idx; i++)
121  {
122  gcry_free (array[i]);
123  array[i] = NULL;
124  }
125  gcry_sexp_release (list);
126  return 3; /* required parameter not found */
127  }
128  array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
129  gcry_sexp_release (l2);
130  if (! array[idx])
131  {
132  for (unsigned int i = 0; i < idx; i++)
133  {
134  gcry_free (array[i]);
135  array[i] = NULL;
136  }
137  gcry_sexp_release (list);
138  return 4; /* required parameter is invalid */
139  }
140  }
141  gcry_sexp_release (list);
142  return 0;
143 }
144 
145 
153 static gcry_sexp_t
155 {
156  gcry_sexp_t result;
157  int rc;
158  uint8_t d[32];
159 
160  for (size_t i = 0; i<32; i++)
161  d[i] = priv->d[31 - i];
162 
163  rc = gcry_sexp_build (&result,
164  NULL,
165  "(private-key(ecc(curve \"" CURVE "\")"
166  "(d %b)))",
167  32,
168  d);
169  if (0 != rc)
170  {
171  LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
172  GNUNET_assert (0);
173  }
174 #if EXTRA_CHECKS
175  if (0 != (rc = gcry_pk_testkey (result)))
176  {
177  LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
178  GNUNET_assert (0);
179  }
180 #endif
181  return result;
182 }
183 
184 
185 void
187  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
189 {
190  BENCHMARK_START (ecdsa_key_get_public);
191  crypto_scalarmult_ed25519_base_noclamp (pub->q_y, priv->d);
192  BENCHMARK_END (ecdsa_key_get_public);
193 }
194 
195 
196 void
198  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
200 {
201  unsigned char pk[crypto_sign_PUBLICKEYBYTES];
202  unsigned char sk[crypto_sign_SECRETKEYBYTES];
203 
204  BENCHMARK_START (eddsa_key_get_public);
205  GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
206  GNUNET_memcpy (pub->q_y, pk, crypto_sign_PUBLICKEYBYTES);
207  sodium_memzero (sk, crypto_sign_SECRETKEYBYTES);
208  BENCHMARK_END (eddsa_key_get_public);
209 }
210 
211 
212 void
214  const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
216 {
217  BENCHMARK_START (ecdhe_key_get_public);
218  GNUNET_assert (0 == crypto_scalarmult_base (pub->q_y, priv->d));
219  BENCHMARK_END (ecdhe_key_get_public);
220 }
221 
222 
223 char *
225  const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
226 {
227  char *pubkeybuf;
228  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
229  char *end;
230 
231  if (keylen % 5 > 0)
232  keylen += 5 - keylen % 5;
233  keylen /= 5;
234  pubkeybuf = GNUNET_malloc (keylen + 1);
235  end =
236  GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
237  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
238  pubkeybuf,
239  keylen);
240  if (NULL == end)
241  {
242  GNUNET_free (pubkeybuf);
243  return NULL;
244  }
245  *end = '\0';
246  return pubkeybuf;
247 }
248 
249 
250 char *
252  const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
253 {
254  char *pubkeybuf;
255  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
256  char *end;
257 
258  if (keylen % 5 > 0)
259  keylen += 5 - keylen % 5;
260  keylen /= 5;
261  pubkeybuf = GNUNET_malloc (keylen + 1);
262  end =
263  GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
264  sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
265  pubkeybuf,
266  keylen);
267  if (NULL == end)
268  {
269  GNUNET_free (pubkeybuf);
270  return NULL;
271  }
272  *end = '\0';
273  return pubkeybuf;
274 }
275 
276 
277 char *
279  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
280 {
281  char *privkeybuf;
282  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
283  char *end;
284 
285  if (keylen % 5 > 0)
286  keylen += 5 - keylen % 5;
287  keylen /= 5;
288  privkeybuf = GNUNET_malloc (keylen + 1);
289  end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
290  sizeof(
292  privkeybuf,
293  keylen);
294  if (NULL == end)
295  {
296  GNUNET_free (privkeybuf);
297  return NULL;
298  }
299  *end = '\0';
300  return privkeybuf;
301 }
302 
303 
304 char *
306  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
307 {
308  char *privkeybuf;
309  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)) * 8;
310  char *end;
311 
312  if (keylen % 5 > 0)
313  keylen += 5 - keylen % 5;
314  keylen /= 5;
315  privkeybuf = GNUNET_malloc (keylen + 1);
316  end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
317  sizeof(
319  privkeybuf,
320  keylen);
321  if (NULL == end)
322  {
323  GNUNET_free (privkeybuf);
324  return NULL;
325  }
326  *end = '\0';
327  return privkeybuf;
328 }
329 
330 
333  const char *enc,
334  size_t enclen,
336 {
337  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
338 
339  if (keylen % 5 > 0)
340  keylen += 5 - keylen % 5;
341  keylen /= 5;
342  if (enclen != keylen)
343  return GNUNET_SYSERR;
344 
345  if (GNUNET_OK !=
347  enclen,
348  pub,
349  sizeof(
351  return GNUNET_SYSERR;
352  return GNUNET_OK;
353 }
354 
355 
358  const char *enc,
359  size_t enclen,
361 {
362  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
363 
364  if (keylen % 5 > 0)
365  keylen += 5 - keylen % 5;
366  keylen /= 5;
367  if (enclen != keylen)
368  return GNUNET_SYSERR;
369 
370  if (GNUNET_OK !=
372  enclen,
373  pub,
374  sizeof(
376  return GNUNET_SYSERR;
377  return GNUNET_OK;
378 }
379 
380 
383  const char *enc,
384  size_t enclen,
385  struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
386 {
387  size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
388 
389  if (keylen % 5 > 0)
390  keylen += 5 - keylen % 5;
391  keylen /= 5;
392  if (enclen != keylen)
393  return GNUNET_SYSERR;
394 
395  if (GNUNET_OK !=
397  enclen,
398  priv,
399  sizeof(
401  return GNUNET_SYSERR;
402 #if CRYPTO_BUG
403  if (GNUNET_OK != check_eddsa_key (priv))
404  {
405  GNUNET_break (0);
406  return GNUNET_OK;
407  }
408 #endif
409  return GNUNET_OK;
410 }
411 
412 
413 void
415 {
416  memset (pk, 0, sizeof(struct GNUNET_CRYPTO_EcdhePrivateKey));
417 }
418 
419 
420 void
422 {
423  memset (pk, 0, sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey));
424 }
425 
426 
427 void
429 {
430  memset (pk, 0, sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey));
431 }
432 
433 
434 void
436 {
437  BENCHMARK_START (ecdhe_key_create);
439  pk,
440  sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
441  BENCHMARK_END (ecdhe_key_create);
442 }
443 
444 
445 void
447 {
448  BENCHMARK_START (ecdsa_key_create);
450  pk,
451  sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
452  pk->d[0] &= 248;
453  pk->d[31] &= 127;
454  pk->d[31] |= 64;
455 
456  BENCHMARK_END (ecdsa_key_create);
457 }
458 
459 
460 void
462 {
463  BENCHMARK_START (eddsa_key_create);
464  /*
465  * We do not clamp for EdDSA, since all functions that use the private key do
466  * their own clamping (just like in libsodium). What we call "private key"
467  * here, actually corresponds to the seed in libsodium.
468  *
469  * (Contrast this to ECDSA, where functions using the private key can't clamp
470  * due to properties needed for GNS. That is a worse/unsafer API, but
471  * required for the GNS constructions to work.)
472  */
474  pk,
475  sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
476  BENCHMARK_END (eddsa_key_create);
477 }
478 
479 
480 const struct GNUNET_CRYPTO_EcdsaPrivateKey *
482 {
487  static struct GNUNET_CRYPTO_EcdsaPrivateKey anonymous;
488  static int once;
489 
490  if (once)
491  return &anonymous;
493  sizeof(anonymous.d),
494  GCRYMPI_CONST_ONE);
495  anonymous.d[0] &= 248;
496  anonymous.d[31] &= 127;
497  anonymous.d[31] |= 64;
498 
499  once = 1;
500  return &anonymous;
501 }
502 
503 
511 static gcry_sexp_t
513 {
514  gcry_sexp_t data;
515  int rc;
516 
517 /* See #5398 */
518 #if 1
519  struct GNUNET_HashCode hc;
520 
521  GNUNET_CRYPTO_hash (purpose, ntohl (purpose->size), &hc);
522  if (0 != (rc = gcry_sexp_build (&data,
523  NULL,
524  "(data(flags rfc6979)(hash %s %b))",
525  "sha512",
526  (int) sizeof(hc),
527  &hc)))
528  {
529  LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
530  return NULL;
531  }
532 #else
533  if (0 != (rc = gcry_sexp_build (&data,
534  NULL,
535  "(data(flags rfc6979)(hash %s %b))",
536  "sha512",
537  ntohl (purpose->size),
538  purpose)))
539  {
540  LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
541  return NULL;
542  }
543 #endif
544  return data;
545 }
546 
547 
550  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
551  const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
552  struct GNUNET_CRYPTO_EcdsaSignature *sig)
553 {
554  gcry_sexp_t priv_sexp;
555  gcry_sexp_t sig_sexp;
556  gcry_sexp_t data;
557  int rc;
558  gcry_mpi_t rs[2];
559 
560  BENCHMARK_START (ecdsa_sign);
561 
562  priv_sexp = decode_private_ecdsa_key (priv);
563  data = data_to_ecdsa_value (purpose);
564  if (0 != (rc = gcry_pk_sign (&sig_sexp, data, priv_sexp)))
565  {
567  _ ("ECC signing failed at %s:%d: %s\n"),
568  __FILE__,
569  __LINE__,
570  gcry_strerror (rc));
571  gcry_sexp_release (data);
572  gcry_sexp_release (priv_sexp);
573  return GNUNET_SYSERR;
574  }
575  gcry_sexp_release (priv_sexp);
576  gcry_sexp_release (data);
577 
578  /* extract 'r' and 's' values from sexpression 'sig_sexp' and store in
579  'signature' */
580  if (0 != (rc = key_from_sexp (rs, sig_sexp, "sig-val", "rs")))
581  {
582  GNUNET_break (0);
583  gcry_sexp_release (sig_sexp);
584  return GNUNET_SYSERR;
585  }
586  gcry_sexp_release (sig_sexp);
587  GNUNET_CRYPTO_mpi_print_unsigned (sig->r, sizeof(sig->r), rs[0]);
588  GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof(sig->s), rs[1]);
589  gcry_mpi_release (rs[0]);
590  gcry_mpi_release (rs[1]);
591 
592  BENCHMARK_END (ecdsa_sign);
593 
594  return GNUNET_OK;
595 }
596 
599  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
600  void *data,
601  size_t size,
602  struct GNUNET_CRYPTO_EddsaSignature *sig)
603 {
604  unsigned char sk[crypto_sign_SECRETKEYBYTES];
605  unsigned char pk[crypto_sign_PUBLICKEYBYTES];
606  int res;
607 
608  GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
609  res = crypto_sign_detached ((uint8_t *) sig,
610  NULL,
611  (uint8_t *) data,
612  size,
613  sk);
614  return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
615 }
616 
617 
620  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
621  const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
622  struct GNUNET_CRYPTO_EddsaSignature *sig)
623 {
624 
625  size_t mlen = ntohl (purpose->size);
626  unsigned char sk[crypto_sign_SECRETKEYBYTES];
627  unsigned char pk[crypto_sign_PUBLICKEYBYTES];
628  int res;
629 
630  BENCHMARK_START (eddsa_sign);
631  GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
632  res = crypto_sign_detached ((uint8_t *) sig,
633  NULL,
634  (uint8_t *) purpose,
635  mlen,
636  sk);
637  BENCHMARK_END (eddsa_sign);
638  return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
639 }
640 
641 
644  uint32_t purpose,
645  const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
646  const struct GNUNET_CRYPTO_EcdsaSignature *sig,
647  const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
648 {
649  gcry_sexp_t data;
650  gcry_sexp_t sig_sexpr;
651  gcry_sexp_t pub_sexpr;
652  int rc;
653 
654  BENCHMARK_START (ecdsa_verify);
655 
656  if (purpose != ntohl (validate->purpose))
657  return GNUNET_SYSERR; /* purpose mismatch */
658 
659  /* build s-expression for signature */
660  if (0 != (rc = gcry_sexp_build (&sig_sexpr,
661  NULL,
662  "(sig-val(ecdsa(r %b)(s %b)))",
663  (int) sizeof(sig->r),
664  sig->r,
665  (int) sizeof(sig->s),
666  sig->s)))
667  {
668  LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
669  return GNUNET_SYSERR;
670  }
671  data = data_to_ecdsa_value (validate);
672  if (0 != (rc = gcry_sexp_build (&pub_sexpr,
673  NULL,
674  "(public-key(ecc(curve " CURVE ")(q %b)))",
675  (int) sizeof(pub->q_y),
676  pub->q_y)))
677  {
678  gcry_sexp_release (data);
679  gcry_sexp_release (sig_sexpr);
680  return GNUNET_SYSERR;
681  }
682  rc = gcry_pk_verify (sig_sexpr, data, pub_sexpr);
683  gcry_sexp_release (pub_sexpr);
684  gcry_sexp_release (data);
685  gcry_sexp_release (sig_sexpr);
686  if (0 != rc)
687  {
689  _ ("ECDSA signature verification failed at %s:%d: %s\n"),
690  __FILE__,
691  __LINE__,
692  gcry_strerror (rc));
693  BENCHMARK_END (ecdsa_verify);
694  return GNUNET_SYSERR;
695  }
696  BENCHMARK_END (ecdsa_verify);
697  return GNUNET_OK;
698 }
699 
700 
703  uint32_t purpose,
704  const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
705  const struct GNUNET_CRYPTO_EddsaSignature *sig,
706  const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
707 {
708  const unsigned char *m = (const void *) validate;
709  size_t mlen = ntohl (validate->size);
710  const unsigned char *s = (const void *) sig;
711 
712  int res;
713 
714  if (purpose != ntohl (validate->purpose))
715  return GNUNET_SYSERR; /* purpose mismatch */
716 
717  BENCHMARK_START (eddsa_verify);
718 
719  res = crypto_sign_verify_detached (s, m, mlen, pub->q_y);
720  BENCHMARK_END (eddsa_verify);
721  return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
722 }
723 
724 
727  const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
728  struct GNUNET_HashCode *key_material)
729 {
730  uint8_t p[crypto_scalarmult_BYTES];
731  if (0 != crypto_scalarmult (p, priv->d, pub->q_y))
732  return GNUNET_SYSERR;
733  GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
734  return GNUNET_OK;
735 }
736 
737 
740  const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
741  struct GNUNET_HashCode *key_material)
742 {
743  struct GNUNET_HashCode hc;
744  uint8_t a[crypto_scalarmult_SCALARBYTES];
745  uint8_t p[crypto_scalarmult_BYTES];
746 
747  GNUNET_CRYPTO_hash (priv,
748  sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
749  &hc);
750  memcpy (a, &hc, sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
751  if (0 != crypto_scalarmult (p, a, pub->q_y))
752  return GNUNET_SYSERR;
754  crypto_scalarmult_BYTES,
755  key_material);
756  return GNUNET_OK;
757 }
758 
759 
762  const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
763  struct GNUNET_HashCode *key_material)
764 {
765  uint8_t p[crypto_scalarmult_BYTES];
766 
767  BENCHMARK_START (ecdsa_ecdh);
768  if (0 != crypto_scalarmult (p, priv->d, pub->q_y))
769  return GNUNET_SYSERR;
771  crypto_scalarmult_BYTES,
772  key_material);
773  BENCHMARK_END (ecdsa_ecdh);
774  return GNUNET_OK;
775 }
776 
777 
780  const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
781  struct GNUNET_HashCode *key_material)
782 {
783  uint8_t p[crypto_scalarmult_BYTES];
784  uint8_t curve25510_pk[crypto_scalarmult_BYTES];
785 
786  if (0 != crypto_sign_ed25519_pk_to_curve25519 (curve25510_pk, pub->q_y))
787  return GNUNET_SYSERR;
788  if (0 != crypto_scalarmult (p, priv->d, curve25510_pk))
789  return GNUNET_SYSERR;
790  GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
791  return GNUNET_OK;
792 }
793 
794 
797  const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
798  struct GNUNET_HashCode *key_material)
799 {
800  uint8_t p[crypto_scalarmult_BYTES];
801  uint8_t curve25510_pk[crypto_scalarmult_BYTES];
802 
803  if (0 != crypto_sign_ed25519_pk_to_curve25519 (curve25510_pk, pub->q_y))
804  return GNUNET_SYSERR;
805  if (0 != crypto_scalarmult (p, priv->d, curve25510_pk))
806  return GNUNET_SYSERR;
807  GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
808  return GNUNET_OK;
809 }
810 
811 
812 /* end of crypto_ecc.c */
benchmarking for various operations
#define BENCHMARK_START(opname)
Definition: benchmark.h:57
#define BENCHMARK_END(opname)
Definition: benchmark.h:58
static int key_from_sexp(gcry_mpi_t *array, gcry_sexp_t sexp, const char *topname, const char *elems)
Extract values from an S-expression.
Definition: crypto_ecc.c:96
static gcry_sexp_t data_to_ecdsa_value(const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
Convert the data specified in the given purpose argument to an S-expression suitable for signature op...
Definition: crypto_ecc.c:512
#define CURVE
IMPLEMENTATION NOTICE:
Definition: crypto_ecc.c:59
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Definition: crypto_ecc.c:74
#define LOG(kind,...)
Definition: crypto_ecc.c:61
static gcry_sexp_t decode_private_ecdsa_key(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
Convert the given private key from the network format to the S-expression that can be used by libgcry...
Definition: crypto_ecc.c:154
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:67
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static int res
static OpusEncoder * enc
OPUS encoder.
uint32_t data
The data value.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
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.
Definition: crypto_ecc.c:726
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:435
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
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:197
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_ecdh(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private ECDSA key.
Definition: crypto_ecc.c:761
void GNUNET_CRYPTO_eddsa_key_clear(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:428
enum GNUNET_GenericReturnValue 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:549
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private EdDSA key.
Definition: crypto_ecc.c:739
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_key_get_anonymous()
Get the shared private key we use for anonymous users.
Definition: crypto_ecc.c:481
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_ecdsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EcDSA public key and a private ECDH key.
Definition: crypto_ecc.c:796
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:461
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.
Definition: crypto_ecc.c:779
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:446
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:619
void GNUNET_CRYPTO_ecdsa_key_clear(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:421
enum GNUNET_GenericReturnValue 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:643
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:186
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:702
void GNUNET_CRYPTO_ecdhe_key_clear(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:414
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.
Definition: crypto_ecc.c:213
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_raw(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *data, size_t size, struct GNUNET_CRYPTO_EddsaSignature *sig)
Definition: crypto_ecc.c:598
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:224
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:332
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:251
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:357
void GNUNET_CRYPTO_mpi_print_unsigned(void *buf, size_t size, gcry_mpi_t val)
Output the given MPI value to the given buffer in network byte order.
Definition: crypto_mpi.c:79
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_private_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Convert a string representing a private key to a private key.
Definition: crypto_ecc.c:382
GNUNET_GenericReturnValue
Named constants for return values.
char * GNUNET_CRYPTO_ecdsa_private_key_to_string(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
Convert a private key to a string.
Definition: crypto_ecc.c:305
char * GNUNET_CRYPTO_eddsa_private_key_to_string(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Convert a private key to a string.
Definition: crypto_ecc.c:278
@ GNUNET_OK
@ GNUNET_SYSERR
#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_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:708
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:788
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
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...
Private ECC key encoded for transmission.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
an ECC signature using ECDSA
unsigned char s[256/8]
S value.
unsigned char r[256/8]
R value.
Private ECC key encoded for transmission.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
unsigned char q_y[256/8]
Point Q consists of a y-value mod p (256 bits); the x-value is always positive.
an ECC signature using EdDSA.
A 512-bit hashcode.