GNUnet 0.28.0-dev.5-39-g27eb33d95
 
Loading...
Searching...
No Matches
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
27#include "platform.h"
28#include "gnunet_common.h"
29#include <gcrypt.h>
30#include <sodium.h>
31#include <sodium/crypto_sign_ed25519.h>
32#include "gnunet_util_lib.h"
33#include "benchmark.h"
34#include "sodium/crypto_scalarmult.h"
35#include "sodium/crypto_scalarmult_curve25519.h"
36#include "sodium/utils.h"
37
38#define EXTRA_CHECKS 0
39
63#define CURVE "Ed25519"
64
65#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
66
67#define LOG_STRERROR(kind, syscall) \
68 GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
69
70#define LOG_STRERROR_FILE(kind, syscall, filename) \
71 GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, \
72 filename)
73
79#define LOG_GCRY(level, cmd, rc) \
80 do \
81 { \
82 LOG (level, \
83 _ ("`%s' failed at %s:%d with error: %s\n"), \
84 cmd, \
85 __FILE__, \
86 __LINE__, \
87 gcry_strerror (rc)); \
88 } while (0)
89
90
100static int
101key_from_sexp (gcry_mpi_t *array,
102 gcry_sexp_t sexp,
103 const char *topname,
104 const char *elems)
105{
106 gcry_sexp_t list;
107 gcry_sexp_t l2;
108 unsigned int idx;
109
110 list = gcry_sexp_find_token (sexp, topname, 0);
111 if (! list)
112 return 1;
113 l2 = gcry_sexp_cadr (list);
114 gcry_sexp_release (list);
115 list = l2;
116 if (! list)
117 return 2;
118
119 idx = 0;
120 for (const char *s = elems; *s; s++, idx++)
121 {
122 l2 = gcry_sexp_find_token (list, s, 1);
123 if (! l2)
124 {
125 for (unsigned int i = 0; i < idx; i++)
126 {
127 gcry_free (array[i]);
128 array[i] = NULL;
129 }
130 gcry_sexp_release (list);
131 return 3; /* required parameter not found */
132 }
133 array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
134 gcry_sexp_release (l2);
135 if (! array[idx])
136 {
137 for (unsigned int i = 0; i < idx; i++)
138 {
139 gcry_free (array[i]);
140 array[i] = NULL;
141 }
142 gcry_sexp_release (list);
143 return 4; /* required parameter is invalid */
144 }
145 }
146 gcry_sexp_release (list);
147 return 0;
148}
149
150
158static gcry_sexp_t
160{
161 gcry_sexp_t result;
162 int rc;
163 uint8_t d[32];
164
165 for (size_t i = 0; i<32; i++)
166 d[i] = priv->d[31 - i];
167
168 rc = gcry_sexp_build (&result,
169 NULL,
170 "(private-key(ecc(curve \"" CURVE "\")"
171 "(d %b)))",
172 32,
173 d);
174 if (0 != rc)
175 {
176 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
177 GNUNET_assert (0);
178 }
179#if EXTRA_CHECKS
180 if (0 != (rc = gcry_pk_testkey (result)))
181 {
182 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
183 GNUNET_assert (0);
184 }
185#endif
186 return result;
187}
188
189
190void
192 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
194{
195 BENCHMARK_START (ecdsa_key_get_public);
196 crypto_scalarmult_ed25519_base_noclamp (pub->q_y, priv->d);
197 BENCHMARK_END (ecdsa_key_get_public);
198}
199
200
201void
203 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
205{
206 unsigned char pk[crypto_sign_PUBLICKEYBYTES];
207 unsigned char sk[crypto_sign_SECRETKEYBYTES];
208
209 BENCHMARK_START (eddsa_key_get_public);
210 GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
211 GNUNET_memcpy (pub->q_y, pk, crypto_sign_PUBLICKEYBYTES);
212 sodium_memzero (sk, crypto_sign_SECRETKEYBYTES);
213 BENCHMARK_END (eddsa_key_get_public);
214}
215
216
217void
219 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
221{
222 BENCHMARK_START (ecdhe_key_get_public);
223 GNUNET_assert (0 == crypto_scalarmult_base (pub->q_y, priv->d));
224 BENCHMARK_END (ecdhe_key_get_public);
225}
226
227
228char *
230 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
231{
232 char *pubkeybuf;
233 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
234 char *end;
235
236 if (keylen % 5 > 0)
237 keylen += 5 - keylen % 5;
238 keylen /= 5;
239 pubkeybuf = GNUNET_malloc (keylen + 1);
240 end =
241 GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
242 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
243 pubkeybuf,
244 keylen);
245 if (NULL == end)
246 {
247 GNUNET_free (pubkeybuf);
248 return NULL;
249 }
250 *end = '\0';
251 return pubkeybuf;
252}
253
254
255char *
257 const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
258{
259 char *pubkeybuf;
260 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
261 char *end;
262
263 if (keylen % 5 > 0)
264 keylen += 5 - keylen % 5;
265 keylen /= 5;
266 pubkeybuf = GNUNET_malloc (keylen + 1);
267 end =
268 GNUNET_STRINGS_data_to_string ((unsigned char *) pub,
269 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
270 pubkeybuf,
271 keylen);
272 if (NULL == end)
273 {
274 GNUNET_free (pubkeybuf);
275 return NULL;
276 }
277 *end = '\0';
278 return pubkeybuf;
279}
280
281
282char *
284 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
285{
286 char *privkeybuf;
287 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
288 char *end;
289
290 if (keylen % 5 > 0)
291 keylen += 5 - keylen % 5;
292 keylen /= 5;
293 privkeybuf = GNUNET_malloc (keylen + 1);
294 end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
295 sizeof(
297 privkeybuf,
298 keylen);
299 if (NULL == end)
300 {
301 GNUNET_free (privkeybuf);
302 return NULL;
303 }
304 *end = '\0';
305 return privkeybuf;
306}
307
308
309char *
311 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
312{
313 char *privkeybuf;
314 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)) * 8;
315 char *end;
316
317 if (keylen % 5 > 0)
318 keylen += 5 - keylen % 5;
319 keylen /= 5;
320 privkeybuf = GNUNET_malloc (keylen + 1);
321 end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
322 sizeof(
324 privkeybuf,
325 keylen);
326 if (NULL == end)
327 {
328 GNUNET_free (privkeybuf);
329 return NULL;
330 }
331 *end = '\0';
332 return privkeybuf;
333}
334
335
338 const char *enc,
339 size_t enclen,
341{
342 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
343
344 if (keylen % 5 > 0)
345 keylen += 5 - keylen % 5;
346 keylen /= 5;
347 if (enclen != keylen)
348 return GNUNET_SYSERR;
349
350 if (GNUNET_OK !=
352 enclen,
353 pub,
354 sizeof(
356 return GNUNET_SYSERR;
357 return GNUNET_OK;
358}
359
360
363 const char *enc,
364 size_t enclen,
366{
367 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) * 8;
368
369 if (keylen % 5 > 0)
370 keylen += 5 - keylen % 5;
371 keylen /= 5;
372 if (enclen != keylen)
373 return GNUNET_SYSERR;
374
375 if (GNUNET_OK !=
377 enclen,
378 pub,
379 sizeof(
381 return GNUNET_SYSERR;
382 return GNUNET_OK;
383}
384
385
388 const char *enc,
389 size_t enclen,
391{
392 size_t keylen = (sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
393
394 if (keylen % 5 > 0)
395 keylen += 5 - keylen % 5;
396 keylen /= 5;
397 if (enclen != keylen)
398 return GNUNET_SYSERR;
399
400 if (GNUNET_OK !=
402 enclen,
403 priv,
404 sizeof(
406 return GNUNET_SYSERR;
407#if CRYPTO_BUG
408 if (GNUNET_OK != check_eddsa_key (priv))
409 {
410 GNUNET_break (0);
411 return GNUNET_OK;
412 }
413#endif
414 return GNUNET_OK;
415}
416
417
418static void
419buffer_clear (void *buf, size_t len)
420{
421#if HAVE_MEMSET_S
422 memset_s (buf, len, 0, len);
423#elif HAVE_EXPLICIT_BZERO
424 explicit_bzero (buf, len);
425#else
426 volatile unsigned char *p = buf;
427 while (len--)
428 *p++ = 0;
429#endif
430}
431
432
433void
438
439
440void
445
446
447void
452
453
454void
456{
457 BENCHMARK_START (ecdhe_key_create);
459 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
460 BENCHMARK_END (ecdhe_key_create);
461}
462
463
464void
466{
467 BENCHMARK_START (ecdsa_key_create);
469 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
470 pk->d[0] &= 248;
471 pk->d[31] &= 127;
472 pk->d[31] |= 64;
473
474 BENCHMARK_END (ecdsa_key_create);
475}
476
477
478void
480{
481 BENCHMARK_START (eddsa_key_create);
482 /*
483 * We do not clamp for EdDSA, since all functions that use the private key do
484 * their own clamping (just like in libsodium). What we call "private key"
485 * here, actually corresponds to the seed in libsodium.
486 *
487 * (Contrast this to ECDSA, where functions using the private key can't clamp
488 * due to properties needed for GNS. That is a worse/unsafter API, but
489 * required for the GNS constructions to work.)
490 */
492 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
493 BENCHMARK_END (eddsa_key_create);
494}
495
496
499{
504 static struct GNUNET_CRYPTO_EcdsaPrivateKey anonymous;
505 static int once;
506
507 if (once)
508 return &anonymous;
510 sizeof(anonymous.d),
511 GCRYMPI_CONST_ONE);
512 anonymous.d[0] &= 248;
513 anonymous.d[31] &= 127;
514 anonymous.d[31] |= 64;
515
516 once = 1;
517 return &anonymous;
518}
519
520
523{
528 static struct GNUNET_CRYPTO_EddsaPrivateKey anonymous;
529 static int once;
530
531 if (once)
532 return &anonymous;
533
534 memset (anonymous.d, 0, sizeof(anonymous.d));
535
536 // Set the first byte to 1 (Little-Endian representation of 1)
537 anonymous.d[0] = 1;
538
539 once = 1;
540 return &anonymous;
541}
542
543
551static gcry_sexp_t
553{
554 gcry_sexp_t data;
555 int rc;
556 /* Unlike EdDSA, libgcrypt expects a hash for ECDSA. */
557 struct GNUNET_HashCode hc;
558
559 GNUNET_CRYPTO_hash (purpose, ntohl (purpose->size), &hc);
560 if (0 != (rc = gcry_sexp_build (&data,
561 NULL,
562 "(data(flags rfc6979)(hash %s %b))",
563 "sha512",
564 (int) sizeof(hc),
565 &hc)))
566 {
567 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
568 return NULL;
569 }
570 return data;
571}
572
573
576 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
577 const struct GNUNET_CRYPTO_SignaturePurpose *purpose,
579{
580 gcry_sexp_t priv_sexp;
581 gcry_sexp_t sig_sexp;
582 gcry_sexp_t data;
583 int rc;
584 gcry_mpi_t rs[2];
585
586 BENCHMARK_START (ecdsa_sign);
587
588 priv_sexp = decode_private_ecdsa_key (priv);
589 data = data_to_ecdsa_value (purpose);
590 if (0 != (rc = gcry_pk_sign (&sig_sexp, data, priv_sexp)))
591 {
593 _ ("ECC signing failed at %s:%d: %s\n"),
594 __FILE__,
595 __LINE__,
596 gcry_strerror (rc));
597 gcry_sexp_release (data);
598 gcry_sexp_release (priv_sexp);
599 return GNUNET_SYSERR;
600 }
601 gcry_sexp_release (priv_sexp);
602 gcry_sexp_release (data);
603
604 /* extract 'r' and 's' values from sexpression 'sig_sexp' and store in
605 'signature' */
606 if (0 != (rc = key_from_sexp (rs, sig_sexp, "sig-val", "rs")))
607 {
608 GNUNET_break (0);
609 gcry_sexp_release (sig_sexp);
610 return GNUNET_SYSERR;
611 }
612 gcry_sexp_release (sig_sexp);
613 GNUNET_CRYPTO_mpi_print_unsigned (sig->r, sizeof(sig->r), rs[0]);
614 GNUNET_CRYPTO_mpi_print_unsigned (sig->s, sizeof(sig->s), rs[1]);
615 gcry_mpi_release (rs[0]);
616 gcry_mpi_release (rs[1]);
617
618 BENCHMARK_END (ecdsa_sign);
619
620 return GNUNET_OK;
621}
622
623
626 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
627 void *data,
628 size_t size,
630{
631 unsigned char sk[crypto_sign_SECRETKEYBYTES];
632 unsigned char pk[crypto_sign_PUBLICKEYBYTES];
633 int res;
634
635 GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
636 res = crypto_sign_detached ((uint8_t *) sig,
637 NULL,
638 (uint8_t *) data,
639 size,
640 sk);
641 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
642}
643
644
647 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
648 const struct GNUNET_CRYPTO_SignaturePurpose *purpose,
650{
651
652 size_t mlen = ntohl (purpose->size);
653 unsigned char sk[crypto_sign_SECRETKEYBYTES];
654 unsigned char pk[crypto_sign_PUBLICKEYBYTES];
655 int res;
656
657 BENCHMARK_START (eddsa_sign);
658 GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d));
659 res = crypto_sign_detached ((uint8_t *) sig,
660 NULL,
661 (uint8_t *) purpose,
662 mlen,
663 sk);
664 BENCHMARK_END (eddsa_sign);
665 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
666}
667
668
671 uint32_t purpose,
672 const struct GNUNET_CRYPTO_SignaturePurpose *validate,
673 const struct GNUNET_CRYPTO_EcdsaSignature *sig,
674 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
675{
676 gcry_sexp_t data;
677 gcry_sexp_t sig_sexpr;
678 gcry_sexp_t pub_sexpr;
679 int rc;
680
681 BENCHMARK_START (ecdsa_verify);
682
683 if (purpose != ntohl (validate->purpose))
684 return GNUNET_SYSERR; /* purpose mismatch */
685
686 /* build s-expression for signature */
687 if (0 != (rc = gcry_sexp_build (&sig_sexpr,
688 NULL,
689 "(sig-val(ecdsa(r %b)(s %b)))",
690 (int) sizeof(sig->r),
691 sig->r,
692 (int) sizeof(sig->s),
693 sig->s)))
694 {
695 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
696 return GNUNET_SYSERR;
697 }
698 data = data_to_ecdsa_value (validate);
699 if (0 != (rc = gcry_sexp_build (&pub_sexpr,
700 NULL,
701 "(public-key(ecc(curve " CURVE ")(q %b)))",
702 (int) sizeof(pub->q_y),
703 pub->q_y)))
704 {
705 gcry_sexp_release (data);
706 gcry_sexp_release (sig_sexpr);
707 return GNUNET_SYSERR;
708 }
709 rc = gcry_pk_verify (sig_sexpr, data, pub_sexpr);
710 gcry_sexp_release (pub_sexpr);
711 gcry_sexp_release (data);
712 gcry_sexp_release (sig_sexpr);
713 if (0 != rc)
714 {
716 _ ("ECDSA signature verification failed at %s:%d: %s\n"),
717 __FILE__,
718 __LINE__,
719 gcry_strerror (rc));
720 BENCHMARK_END (ecdsa_verify);
721 return GNUNET_SYSERR;
722 }
723 BENCHMARK_END (ecdsa_verify);
724 return GNUNET_OK;
725}
726
727
730 uint32_t purpose,
731 const struct GNUNET_CRYPTO_SignaturePurpose *validate,
732 const struct GNUNET_CRYPTO_EddsaSignature *sig,
733 const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
734{
735 const unsigned char *m = (const void *) validate;
736 size_t mlen = ntohl (validate->size);
737 const unsigned char *s = (const void *) sig;
738
739 int res;
740
741 if (purpose != ntohl (validate->purpose))
742 return GNUNET_SYSERR; /* purpose mismatch */
743
744 BENCHMARK_START (eddsa_verify);
745
746 res = crypto_sign_verify_detached (s, m, mlen, pub->q_y);
747 BENCHMARK_END (eddsa_verify);
748 return (res == 0) ? GNUNET_OK : GNUNET_SYSERR;
749}
750
751
754 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
755 struct GNUNET_HashCode *key_material)
756{
757 uint8_t p[crypto_scalarmult_BYTES];
758 if (0 != crypto_scalarmult (p, priv->d, pub->q_y))
759 return GNUNET_SYSERR;
760 GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
761 return GNUNET_OK;
762}
763
764
767 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
768 struct GNUNET_HashCode *key_material)
769{
770 struct GNUNET_HashCode hc;
771 uint8_t a[crypto_scalarmult_SCALARBYTES];
772 uint8_t p[crypto_scalarmult_BYTES];
773
774 GNUNET_CRYPTO_hash (priv,
775 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
776 &hc);
777 memcpy (a, &hc, sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
778 if (0 != crypto_scalarmult (p, a, pub->q_y))
779 return GNUNET_SYSERR;
781 crypto_scalarmult_BYTES,
782 key_material);
783 return GNUNET_OK;
784}
785
786
789 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
791{
792 uint64_t checkbyte = 0;
793 size_t num_words = sizeof *dh / sizeof (uint64_t);
794 if (0 != crypto_scalarmult_curve25519 (dh->q_y, sk->d, pub->q_y))
795 return GNUNET_SYSERR;
796 // We need to check if this is the all-zero value
797 for (int i = 0; i < num_words; i++)
798 checkbyte |= ((uint64_t*) dh)[i];
799 return (0 == checkbyte) ? GNUNET_SYSERR : GNUNET_OK;
800}
801
802
805 const struct GNUNET_CRYPTO_EcdhePublicKey *pk,
807{
808 uint64_t checkbyte = 0;
809 size_t num_words = sizeof *dh / sizeof (uint64_t);
810 if (0 != crypto_scalarmult_curve25519 (dh->q_y, sk->d, pk->q_y))
811 return GNUNET_SYSERR;
812 // We need to check if this is the all-zero value
813 for (int i = 0; i < num_words; i++)
814 checkbyte |= ((uint64_t*) dh)[i];
815 if (0 == checkbyte)
816 {
818 "HPKE ECDH: X25519 all zero value!\n");
819 return GNUNET_SYSERR;
820 }
821 return GNUNET_OK;
822}
823
824
827 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
828 struct GNUNET_HashCode *key_material)
829{
830 uint8_t p[crypto_scalarmult_BYTES];
831
832 BENCHMARK_START (ecdsa_ecdh);
833 if (0 != crypto_scalarmult (p, priv->d, pub->q_y))
834 return GNUNET_SYSERR;
836 crypto_scalarmult_BYTES,
837 key_material);
838 BENCHMARK_END (ecdsa_ecdh);
839 return GNUNET_OK;
840}
841
842
845 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
846 struct GNUNET_HashCode *key_material)
847{
848 uint8_t p[crypto_scalarmult_BYTES];
849 uint8_t curve25510_pk[crypto_scalarmult_BYTES];
850
851 if (0 != crypto_sign_ed25519_pk_to_curve25519 (curve25510_pk, pub->q_y))
852 return GNUNET_SYSERR;
853 if (0 != crypto_scalarmult (p, priv->d, curve25510_pk))
854 return GNUNET_SYSERR;
855 GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
856 return GNUNET_OK;
857}
858
859
862 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
863 struct GNUNET_HashCode *key_material)
864{
865 uint8_t p[crypto_scalarmult_BYTES];
866 uint8_t curve25510_pk[crypto_scalarmult_BYTES];
867
868 if (0 != crypto_sign_ed25519_pk_to_curve25519 (curve25510_pk, pub->q_y))
869 return GNUNET_SYSERR;
870 if (0 != crypto_scalarmult (p, priv->d, curve25510_pk))
871 return GNUNET_SYSERR;
872 GNUNET_CRYPTO_hash (p, crypto_scalarmult_BYTES, key_material);
873 return GNUNET_OK;
874}
875
876
877/* 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:101
#define CURVE
IMPLEMENTATION NOTICE:
Definition crypto_ecc.c:63
static void buffer_clear(void *buf, size_t len)
Definition crypto_ecc.c:419
#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:79
static gcry_sexp_t data_to_ecdsa_value(const struct GNUNET_CRYPTO_SignaturePurpose *purpose)
Convert the data specified in the given purpose argument to an S-expression suitable for signature op...
Definition crypto_ecc.c:552
#define LOG(kind,...)
Definition crypto_ecc.c:65
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:159
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition gnunet-arm.c:103
static int list
Set if we should print a list of currently running services.
Definition gnunet-arm.c:68
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
static char * data
The data to insert into the dht.
static OpusEncoder * enc
OPUS encoder.
struct GNUNET_CRYPTO_BlindablePrivateKey pk
Private key from command line option, or NULL.
static char * res
Currently read line or NULL on EOF.
static int once
Option -i.
Definition gnunet-pils.c:39
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
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:753
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition crypto_ecc.c:455
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition crypto_ecc.c:729
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_x25519_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *sk, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *dh)
Derive key material from a ECDH public key and a private X25519 key.
Definition crypto_ecc.c:788
const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_get_anonymous()
Get the shared private key we use for anonymous users.
Definition crypto_ecc.c:522
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:202
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_ecdh(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
HPKE END.
Definition crypto_ecc.c:826
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:448
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition crypto_ecc.c:646
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:766
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:861
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
Definition crypto_ecc.c:479
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:844
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
ECDSA Sign a given block.
Definition crypto_ecc.c:575
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition crypto_ecc.c:465
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:441
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:498
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive key.
Definition crypto_ecc.c:191
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_x25519(const struct GNUNET_CRYPTO_EcdhePrivateKey *sk, const struct GNUNET_CRYPTO_EcdhePublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *dh)
Derive key material from a EdDSA public key and a private ECDH key.
Definition crypto_ecc.c:804
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:434
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:218
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition crypto_ecc.c:670
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
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:283
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:625
#define GNUNET_log(kind,...)
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:337
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:256
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:362
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
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:229
#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:387
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:310
GNUNET_GenericReturnValue
Named constants for return values.
@ 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:763
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:843
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
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...
unsigned char q_y[256/8]
Q consists of an x- and a y-value, each mod p (256 bits), given here in affine coordinates and Ed2551...
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.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
A 512-bit hashcode.