GNUnet 0.28.0-dev.2-27-gc87478450
 
Loading...
Searching...
No Matches
gnsrecord_crypto.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2018 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 "gnsrecord_crypto.h"
30
31#define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__)
32
38#pragma GCC diagnostic push
39#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
40void
41GNR_derive_block_aes_key (unsigned char *ctr,
42 unsigned char *key,
43 const char *label,
44 uint64_t exp,
46{
47 static const char ctx_key[] = "gns-aes-ctx-key";
48 static const char ctx_iv[] = "gns-aes-ctx-iv";
49
51 ctx_key, strlen (ctx_key),
52 pub, sizeof(struct
55 memset (ctr, 0, GNUNET_CRYPTO_AES_KEY_LENGTH / 2);
58 ctx_iv, strlen (ctx_iv),
59 pub, sizeof(struct
63 memcpy (ctr + 4, &exp, sizeof (exp));
65 ctr[15] |= 0x01;
66}
67
68
69void
72 const char *label,
73 uint64_t exp,
75{
76 static const char ctx_key[] = "gns-xsalsa-ctx-key";
77 static const char ctx_iv[] = "gns-xsalsa-ctx-iv";
78
80 key, crypto_secretbox_KEYBYTES,
81 ctx_key, strlen (ctx_key),
82 pub, sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
84 memset (nonce, 0, crypto_secretbox_NONCEBYTES);
87 nonce, (crypto_secretbox_NONCEBYTES - sizeof (exp)),
88 ctx_iv, strlen (ctx_iv),
89 pub, sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
92 memcpy (&nonce->nonce[crypto_secretbox_NONCEBYTES - sizeof (exp)],
93 &exp,
94 sizeof (exp));
95}
96
97
99block_sign_ecdsa (const struct
101 const struct
103 const char *label,
104 struct GNUNET_GNSRECORD_Block *block)
105{
106 struct GNRBlockPS *gnr_block;
107 struct GNUNET_GNSRECORD_EcdsaBlock *ecblock;
108 size_t size = ntohl (block->size) - sizeof (*block) + sizeof (*gnr_block);
109
110 gnr_block = GNUNET_malloc (size);
111 ecblock = &(block)->ecdsa_block;
112 gnr_block->purpose.size = htonl (size);
113 gnr_block->purpose.purpose =
115 gnr_block->expiration_time = ecblock->expiration_time;
116 /* encrypt and sign */
117 GNUNET_memcpy (&gnr_block[1], &ecblock[1],
118 size - sizeof (*gnr_block));
120 label,
121 "gns",
122 &ecblock->derived_key);
123 if (GNUNET_OK !=
125 label,
126 "gns",
127 &gnr_block->purpose,
128 &ecblock->signature))
129 {
130 GNUNET_break (0);
131 GNUNET_free (gnr_block);
132 return GNUNET_SYSERR;
133 }
134 GNUNET_free (gnr_block);
135 return GNUNET_OK;
136}
137
138
140block_sign_eddsa (const struct
142 const struct
144 const char *label,
145 struct GNUNET_GNSRECORD_Block *block)
146{
147 struct GNRBlockPS *gnr_block;
148 struct GNUNET_GNSRECORD_EddsaBlock *edblock;
149 size_t size = ntohl (block->size) - sizeof (*block) + sizeof (*gnr_block);
150 gnr_block = GNUNET_malloc (size);
151 edblock = &(block)->eddsa_block;
152 gnr_block->purpose.size = htonl (size);
153 gnr_block->purpose.purpose =
155 gnr_block->expiration_time = edblock->expiration_time;
156 GNUNET_memcpy (&gnr_block[1], &edblock[1],
157 size - sizeof (*gnr_block));
158 /* encrypt and sign */
160 label,
161 "gns",
162 &edblock->derived_key);
164 label,
165 "gns",
166 &gnr_block->purpose,
167 &edblock->signature);
168 GNUNET_free (gnr_block);
169 return GNUNET_OK;
170}
171
172
176 const char *label,
177 struct GNUNET_GNSRECORD_Block *block)
178{
181 char *norm_label;
182
184 &pkey);
185 norm_label = GNUNET_GNSRECORD_string_normalize (label);
186
187 switch (ntohl (key->type))
188 {
190 res = block_sign_ecdsa (&key->ecdsa_key,
191 &pkey.ecdsa_key,
192 norm_label,
193 block);
194 break;
196 res = block_sign_eddsa (&key->eddsa_key,
197 &pkey.eddsa_key,
198 norm_label,
199 block);
200 break;
201 default:
202 GNUNET_assert (0);
203 }
204 GNUNET_free (norm_label);
205 return res;
206}
207
208
226 const char *label,
227 const unsigned char *rdata,
228 size_t rdata_len,
229 struct GNUNET_GNSRECORD_Block **block,
230 int sign)
231{
232 struct GNUNET_GNSRECORD_EcdsaBlock *ecblock;
233 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
234 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH];
235
236 if (rdata_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
237 {
238 GNUNET_break (0);
239 return GNUNET_SYSERR;
240 }
241 /* serialize */
242 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + rdata_len);
243 (*block)->size = htonl (sizeof (struct GNUNET_GNSRECORD_Block) + rdata_len);
244 {
245 ecblock = &(*block)->ecdsa_block;
246 (*block)->type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
249 skey,
250 label,
252 pkey);
254 rdata_len,
255 skey,
256 ctr,
257 &ecblock[1]);
258 }
259 if (GNUNET_YES != sign)
260 return GNUNET_OK;
261 if (GNUNET_OK !=
262 block_sign_ecdsa (key, pkey, label, *block))
263 {
264 GNUNET_break (0);
265 GNUNET_free (*block);
266 return GNUNET_SYSERR;
267 }
268 return GNUNET_OK;
269}
270
271
289 const char *label,
290 const unsigned char *rdata,
291 size_t rdata_len,
292 struct GNUNET_GNSRECORD_Block **block,
293 int sign)
294{
295 struct GNUNET_GNSRECORD_EddsaBlock *edblock;
298
299 if (rdata_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
300 {
301 GNUNET_break (0);
302 return GNUNET_SYSERR;
303 }
304 /* serialize */
305 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block)
306 + rdata_len + crypto_secretbox_MACBYTES);
307 (*block)->size = htonl (sizeof (struct GNUNET_GNSRECORD_Block)
308 + rdata_len + crypto_secretbox_MACBYTES);
309 {
310 edblock = &(*block)->eddsa_block;
311 (*block)->type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY);
314 &skey,
315 label,
317 pkey);
320 rdata_len,
321 (unsigned char*) rdata,
322 &skey,
323 &nonce,
324 &edblock[1]));
325 if (GNUNET_YES != sign)
326 return GNUNET_OK;
327 block_sign_eddsa (key, pkey, label, *block);
328 }
329 return GNUNET_OK;
330}
331
332
348
352 const char *label,
353 const unsigned char *rdata,
354 size_t rdata_len,
356 int sign)
357{
359 struct GNUNET_CRYPTO_EddsaPublicKey edpubkey;
361 char *norm_label;
362#define CSIZE 64
363 static struct KeyCacheLine cache[CSIZE];
364 struct KeyCacheLine *line;
365
366 norm_label = GNUNET_GNSRECORD_string_normalize (label);
367
368 if (GNUNET_PUBLIC_KEY_TYPE_ECDSA == ntohl (pkey->type))
369 {
370 key = &pkey->ecdsa_key;
371
372 line = &cache[(*(unsigned int *) key) % CSIZE];
373 if (0 != memcmp (&line->key,
374 key,
375 sizeof(*key)))
376 {
377 /* cache miss, recompute */
378 line->key = *key;
380 &line->pkey);
381 }
383 &line->pkey,
384 expire,
385 norm_label,
386 rdata,
387 rdata_len,
388 result,
389 sign);
390 }
391 else if (GNUNET_PUBLIC_KEY_TYPE_EDDSA == ntohl (pkey->type))
392 {
394 &edpubkey);
395 res = block_create_eddsa (&pkey->eddsa_key,
396 &edpubkey,
397 expire,
398 norm_label,
399 rdata,
400 rdata_len,
401 result,
402 sign);
403 }
404#undef CSIZE
405 GNUNET_free (norm_label);
406 return res;
407}
408
409
419{
420 struct GNRBlockPS *purp;
421 size_t payload_len = ntohl (block->size)
422 - sizeof (struct GNUNET_GNSRECORD_Block);
424
425 if (ntohl (block->size) <
426 sizeof (struct GNUNET_GNSRECORD_Block))
427 {
428 GNUNET_break_op (0);
429 return GNUNET_SYSERR;
430 }
431 GNUNET_assert (payload_len <= UINT16_MAX);
432 purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len);
433 purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len);
435 GNUNET_memcpy (&purp[1],
436 &block[1],
437 payload_len);
438 switch (ntohl (block->type))
439 {
444 &purp->purpose,
445 &block->ecdsa_block.signature,
446 &block->ecdsa_block.derived_key);
447 break;
452 &purp->purpose,
453 &block->eddsa_block.signature,
454 &block->eddsa_block.derived_key);
455 break;
456 default:
457 res = GNUNET_NO;
458 }
459 GNUNET_free (purp);
460 return res;
461}
462
463
466 const struct GNUNET_GNSRECORD_Block *block,
467 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key,
468 const char *label,
470 void *proc_cls)
471{
472 size_t payload_len = ntohl (block->size)
473 - sizeof (struct GNUNET_GNSRECORD_Block);
474 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
475 unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH];
476
477 if (ntohl (block->size) <
478 sizeof (struct GNUNET_GNSRECORD_Block))
479 {
480 GNUNET_break_op (0);
481 return GNUNET_SYSERR;
482 }
483 GNUNET_assert (payload_len <= UINT16_MAX);
485 key,
486 label,
488 zone_key);
489 {
490 char payload[payload_len];
491 unsigned int rd_count;
492
493 GNUNET_CRYPTO_aes_ctr (&block[1],
494 payload_len,
495 key,
496 ctr,
497 payload);
499 payload);
500 if (rd_count > 2048)
501 {
502 /* limit to sane value */
503 GNUNET_break_op (0);
504 return GNUNET_SYSERR;
505 }
506 {
508 unsigned int j;
509 struct GNUNET_TIME_Absolute now;
510
511 if (GNUNET_OK !=
513 payload,
514 rd_count,
515 rd))
516 {
517 GNUNET_break_op (0);
518 return GNUNET_SYSERR;
519 }
520 /* hide expired records */
522 j = 0;
523 for (unsigned int i = 0; i < rd_count; i++)
524 {
525 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
526 {
527 /* encrypted blocks must never have relative expiration times, skip! */
528 GNUNET_break_op (0);
529 continue;
530 }
531
532 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
533 {
534 int include_record = GNUNET_YES;
535 /* Shadow record, figure out if we have a not expired active record */
536 for (unsigned int k = 0; k < rd_count; k++)
537 {
538 if (k == i)
539 continue;
540 if (rd[i].expiration_time < now.abs_value_us)
541 include_record = GNUNET_NO; /* Shadow record is expired */
542 if ((rd[k].record_type == rd[i].record_type) &&
543 (rd[k].expiration_time >= now.abs_value_us) &&
544 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
545 {
546 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
548 "Ignoring shadow record\n");
549 break;
550 }
551 }
552 if (GNUNET_YES == include_record)
553 {
554 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
555 if (j != i)
556 rd[j] = rd[i];
557 j++;
558 }
559 }
560 else if (rd[i].expiration_time >= now.abs_value_us)
561 {
562 /* Include this record */
563 if (j != i)
564 rd[j] = rd[i];
565 j++;
566 }
567 else
568 {
569 struct GNUNET_TIME_Absolute at;
570
573 "Excluding record that expired %s (%llu ago)\n",
575 (unsigned long long) rd[i].expiration_time
576 - now.abs_value_us);
577 }
578 }
579 rd_count = j;
580 if (NULL != proc)
581 proc (proc_cls,
582 rd_count,
583 (0 != rd_count) ? rd : NULL);
584 }
585 }
586 return GNUNET_OK;
587}
588
589
592 const struct
594 const char *label,
596 void *proc_cls)
597{
598 size_t payload_len = ntohl (block->size)
599 - sizeof (struct GNUNET_GNSRECORD_Block);
602
603
604 if (ntohl (block->size) <
605 sizeof(struct GNUNET_GNSRECORD_Block))
606 {
607 GNUNET_break_op (0);
608 return GNUNET_SYSERR;
609 }
611 &skey,
612 label,
614 ,
615 zone_key);
616 {
617 char payload[payload_len];
618 unsigned int rd_count;
619
622 payload_len,
623 (unsigned char*) &block[1],
624 &skey,
625 &nonce,
626 payload));
627 payload_len -= crypto_secretbox_MACBYTES;
629 payload);
630 if (rd_count > 2048)
631 {
632 /* limit to sane value */
633 GNUNET_break_op (0);
634 return GNUNET_SYSERR;
635 }
636 {
638 unsigned int j;
639 struct GNUNET_TIME_Absolute now;
640
641 if (GNUNET_OK !=
643 payload,
644 rd_count,
645 rd))
646 {
647 GNUNET_break_op (0);
648 return GNUNET_SYSERR;
649 }
650 /* hide expired records */
652 j = 0;
653 for (unsigned int i = 0; i < rd_count; i++)
654 {
655 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
656 {
657 /* encrypted blocks must never have relative expiration times, skip! */
658 GNUNET_break_op (0);
659 continue;
660 }
661
662 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
663 {
664 int include_record = GNUNET_YES;
665 /* Shadow record, figure out if we have a not expired active record */
666 for (unsigned int k = 0; k < rd_count; k++)
667 {
668 if (k == i)
669 continue;
670 if (rd[i].expiration_time < now.abs_value_us)
671 include_record = GNUNET_NO; /* Shadow record is expired */
672 if ((rd[k].record_type == rd[i].record_type) &&
673 (rd[k].expiration_time >= now.abs_value_us) &&
674 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
675 {
676 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
678 "Ignoring shadow record\n");
679 break;
680 }
681 }
682 if (GNUNET_YES == include_record)
683 {
684 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
685 if (j != i)
686 rd[j] = rd[i];
687 j++;
688 }
689 }
690 else if (rd[i].expiration_time >= now.abs_value_us)
691 {
692 /* Include this record */
693 if (j != i)
694 rd[j] = rd[i];
695 j++;
696 }
697 else
698 {
699 struct GNUNET_TIME_Absolute at;
700
703 "Excluding record that expired %s (%llu ago)\n",
705 (unsigned long long) rd[i].expiration_time
706 - now.abs_value_us);
707 }
708 }
709 rd_count = j;
710 if (NULL != proc)
711 proc (proc_cls,
712 rd_count,
713 (0 != rd_count) ? rd : NULL);
714 }
715 }
716 return GNUNET_OK;
717}
718
719
720#pragma GCC diagnostic pop
721
729void
732 ,
733 const char *label,
734 struct GNUNET_HashCode *query)
735{
736 char *norm_label;
738
739 norm_label = GNUNET_GNSRECORD_string_normalize (label);
740 switch (ntohl (zone->type))
741 {
744
746 &pub);
748 norm_label,
749 query);
750 break;
751 default:
752 GNUNET_assert (0);
753 }
754 GNUNET_free (norm_label);
755}
756
757
758#pragma GCC diagnostic push
759#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
760void
763 const char *label,
764 struct GNUNET_HashCode *query)
765{
766 char *norm_label;
768
769 norm_label = GNUNET_GNSRECORD_string_normalize (label);
770
771 switch (ntohl (pub->type))
772 {
774 pd.type = pub->type;
776 norm_label,
777 "gns",
778 &pd.ecdsa_key);
780 sizeof (pd.ecdsa_key),
781 query);
782 break;
784 pd.type = pub->type;
786 norm_label,
787 "gns",
788 &(pd.eddsa_key));
790 sizeof (pd.eddsa_key),
791 query);
792 break;
793 default:
794 GNUNET_assert (0);
795 }
796 GNUNET_free (norm_label);
797}
798
799
800#pragma GCC diagnostic pop
801
808
811 const char *label,
812 const struct GNUNET_GNSRECORD_Block *block,
814 void *proc_cls)
815{
816 struct EncryptionContextData *ecd = cls;
818 char *norm_label;
819
820 norm_label = GNUNET_GNSRECORD_string_normalize (label);
821 return block_decrypt_ecdsa (block,
822 &ecd->zkey.ecdsa_key,
823 norm_label, proc,
824 proc_cls);
825 GNUNET_free (norm_label);
826 return res;
827
828}
829
830
833 const char *label,
834 const struct GNUNET_GNSRECORD_Block *block,
836 void *proc_cls)
837{
838 struct EncryptionContextData *ecd = cls;
840 char *norm_label;
841
842 norm_label = GNUNET_GNSRECORD_string_normalize (label);
843 res = block_decrypt_eddsa (block,
844 &ecd->zkey.eddsa_key,
845 norm_label, proc,
846 proc_cls);
847 GNUNET_free (norm_label);
848 return res;
849}
850
851
854 const char *label,
856 unsigned char *rdata,
857 size_t rdata_len,
859{
860 GNUNET_break (0);
861 return GNUNET_SYSERR;
862}
863
864
866block_seal (void *cls,
867 const char *label,
869 unsigned char *rdata,
870 size_t rdata_len,
872{
873 struct EncryptionContextData *ecd = cls;
874
875 return block_create2 (ecd->sk,
876 expire,
877 label,
878 rdata,
879 rdata_len,
880 result,
881 GNUNET_YES);
882}
883
884
887 const struct GNUNET_CRYPTO_BlindablePrivateKey *sk)
888{
890 struct EncryptionContextData *ecd;
891 size_t sk_len;
892
893 ec = GNUNET_malloc (sizeof(*ec) + sizeof(struct EncryptionContextData));
894 ec->cls = &ec[1];
895 ecd = ec->cls;
897 ecd->sk = GNUNET_malloc (sk_len);
898 GNUNET_memcpy (ecd->sk,
899 sk,
900 sk_len);
902 switch (ntohl (sk->type))
903 {
906 ec->seal = block_seal;
907 break;
910 ec->seal = block_seal;
911 break;
912 default:
913 GNUNET_assert (0);
914 }
915 return ec;
916}
917
918
921 const struct GNUNET_CRYPTO_BlindablePublicKey *zkey)
922{
924 struct EncryptionContextData *ecd;
925 size_t pk_len;
926
927 ec = GNUNET_malloc (sizeof (*ec) + sizeof (*ecd));
928 ec->cls = &ec[1];
929 ecd = ec->cls;
931 GNUNET_memcpy (&ecd->zkey,
932 zkey,
933 pk_len);
934 switch (ntohl (zkey->type))
935 {
939 break;
943 break;
944 default:
945 GNUNET_assert (0);
946 }
947 return ec;
948}
949
950
951void
954 *ec)
955{
956 struct EncryptionContextData *ecd = ec->cls;
957
958 GNUNET_free (ecd->sk);
959 GNUNET_free (ec);
960
961}
962
963
966 const struct
968 const char *label,
970 void *proc_cls)
971{
974
976 ret = ec->open (ec->cls,
977 label,
978 block,
979 proc,
980 proc_cls);
982 return ret;
983}
984
985
986/* end of gnsrecord_crypto.c */
static enum GNUNET_GenericReturnValue block_sign_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
static enum GNUNET_GenericReturnValue block_open_eddsa(void *cls, const char *label, const struct GNUNET_GNSRECORD_Block *block, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
static enum GNUNET_GenericReturnValue block_seal_not_implemented(void *cls, const char *label, struct GNUNET_TIME_Absolute expire, unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result)
static enum GNUNET_GenericReturnValue block_create_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records.
static enum GNUNET_GenericReturnValue block_seal(void *cls, const char *label, struct GNUNET_TIME_Absolute expire, unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result)
static enum GNUNET_GenericReturnValue block_open_ecdsa(void *cls, const char *label, const struct GNUNET_GNSRECORD_Block *block, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
static enum GNUNET_GenericReturnValue block_create2(const struct GNUNET_CRYPTO_BlindablePrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result, int sign)
void GNR_derive_block_aes_key(unsigned char *ctr, unsigned char *key, const char *label, uint64_t exp, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
We disable deprecation warnings because we implement RFC9408/LSD0001 record types here.
static enum GNUNET_GenericReturnValue block_sign_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
static enum GNUNET_GenericReturnValue block_decrypt_eddsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EddsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
#define CSIZE
void GNR_derive_block_xsalsa_key(struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const char *label, uint64_t exp, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Derive session key and iv from label and public key.
static enum GNUNET_GenericReturnValue block_decrypt_ecdsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
static enum GNUNET_GenericReturnValue block_create_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records (EDDSA version)
API for GNS record-related crypto.
#define GNUNET_GNSRECORD_TYPE_PKEY
WARNING: This header is generated! In order to add GNS record types, you must register them in GANA,...
#define GNUNET_GNSRECORD_TYPE_EDKEY
GNS zone delegation (EDKEY)
static int ret
Final status code.
Definition gnunet-arm.c:93
static char * line
Desired phone line (string to be converted to a hash).
struct GNUNET_HashCode key
The key used in the DHT.
static char * expire
DID Document expiration Date Attribute String.
Definition gnunet-did.c:98
static char * pkey
Public key of the zone to look in, in ASCII.
static unsigned int rd_count
Number of records for currently parsed set.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
static unsigned long long payload
How much data are we currently storing in the database?
#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN
GNS record set signature (GNS)
void GNUNET_CRYPTO_ecdsa_public_key_derive(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EcdsaPublicKey *result)
Derive a public key from a given public key and a label.
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:728
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
void GNUNET_CRYPTO_eddsa_public_key_derive(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPublicKey *result)
Derive a public key from a given public key and a label.
void GNUNET_CRYPTO_aes_ctr(const void *in_buf, size_t in_buf_len, const unsigned char key[(256/8)], const unsigned char iv[(128/8)], void *out_buf)
Decrypt or encrypt a given block using a symmetric key using AES in counter mode.
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive key.
Definition crypto_ecc.c:190
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_decrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_encrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
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:669
void GNUNET_GNSRECORD_query_from_private_key(const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE
Maximum size of a value that can be stored in a GNS block.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
void GNUNET_GNSRECORD_encryption_context_destroy(struct GNUNET_GNSRECORD_EncryptionContext *ec)
Cleanup and free the encryption context.
struct GNUNET_GNSRECORD_EncryptionContext * GNUNET_GNSRECORD_encryption_context_setup_resolver(const struct GNUNET_CRYPTO_BlindablePublicKey *zkey)
Create a new encryption context for a resolver.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_verify(const struct GNUNET_GNSRECORD_Block *block)
Check if a signature is valid.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_BlindablePublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
Decrypt block.
unsigned int GNUNET_GNSRECORD_records_deserialize_get_size(size_t len, const char *src)
void(* GNUNET_GNSRECORD_RecordCallback)(void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Process a records that were decrypted from a block.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_sign(const struct GNUNET_CRYPTO_BlindablePrivateKey *key, const char *label, struct GNUNET_GNSRECORD_Block *block)
Sign a block create with GNUNET_GNSRECORD_block_create_unsigned.
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_CRYPTO_BlindablePublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
struct GNUNET_GNSRECORD_EncryptionContext * GNUNET_GNSRECORD_encryption_context_setup_owner(const struct GNUNET_CRYPTO_BlindablePrivateKey *sk)
Create a new encryption context for the zone owner.
char * GNUNET_GNSRECORD_string_normalize(const char *src)
Normalize a UTF-8 string to a GNS name.
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
@ GNUNET_GNSRECORD_RF_SHADOW
This record should not be used unless all (other) records in the set with an absolute expiration time...
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
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blindable_key_get_public(const struct GNUNET_CRYPTO_BlindablePrivateKey *privkey, struct GNUNET_CRYPTO_BlindablePublicKey *key)
Retrieves the public key representation of a private key.
#define GNUNET_log(kind,...)
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
#define GNUNET_CRYPTO_kdf_arg_string(d)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_derived(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
This is a signature function for ECDSA which takes a private key, derives/blinds it and signs the mes...
#define GNUNET_CRYPTO_AES_KEY_LENGTH
length of the sessionkey in bytes
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_derived(const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
This is a signature function for EdDSA which takes a private key and derives it using the label and c...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
ssize_t GNUNET_CRYPTO_blindable_sk_get_length(const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_BlindablePrivateKey.
Definition crypto_pkey.c:66
GNUNET_GenericReturnValue
Named constants for return values.
ssize_t GNUNET_CRYPTO_blindable_pk_get_length(const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_BlindablePublicKey.
Definition crypto_pkey.c:87
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#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_INFO
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:671
static unsigned int size
Size of the "table".
Definition peer.c:68
struct GNUNET_CRYPTO_BlindablePrivateKey * sk
struct GNUNET_CRYPTO_BlindablePublicKey zkey
Information we have in an encrypted block with record data (i.e.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_SignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow.
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
An identity key as per LSD0001.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key
An ECDSA identity key.
struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key
AN EdDSA identtiy key.
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
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 (!...
unsigned char nonce[24]
Initialization vector.
uint32_t type
The zone type (GNUNET_GNSRECORD_TYPE_PKEY)
struct GNUNET_GNSRECORD_EcdsaBlock ecdsa_block
struct GNUNET_GNSRECORD_EddsaBlock eddsa_block
uint32_t size
Size of the block.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Information we have in an encrypted block with record data (i.e.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
Information we have in an encrypted block with record data (i.e.
struct GNUNET_CRYPTO_EddsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EddsaSignature signature
Signature of the block.
The GNSRECORD encryption context.
enum GNUNET_GenericReturnValue(* open)(void *cls, const char *label, const struct GNUNET_GNSRECORD_Block *block, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
Open a record set.
void * cls
Private data of the context.
enum GNUNET_GenericReturnValue(* seal)(void *cls, const char *label, struct GNUNET_TIME_Absolute expire, unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result)
Seal a record set.
A 512-bit hashcode.
uint64_t abs_value_us__
The actual value (in network byte order).
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Line in cache mapping private keys to public keys.
struct GNUNET_CRYPTO_EcdsaPublicKey pkey
Associated public key.
struct GNUNET_CRYPTO_EcdsaPrivateKey key
A private key.