GNUnet 0.27.0-17-g14611e095
 
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
33void
34GNR_derive_block_aes_key (unsigned char *ctr,
35 unsigned char *key,
36 const char *label,
37 uint64_t exp,
39{
40 static const char ctx_key[] = "gns-aes-ctx-key";
41 static const char ctx_iv[] = "gns-aes-ctx-iv";
42
44 ctx_key, strlen (ctx_key),
45 pub, sizeof(struct
48 memset (ctr, 0, GNUNET_CRYPTO_AES_KEY_LENGTH / 2);
51 ctx_iv, strlen (ctx_iv),
52 pub, sizeof(struct
56 memcpy (ctr + 4, &exp, sizeof (exp));
58 ctr[15] |= 0x01;
59}
60
61
62void
63GNR_derive_block_xsalsa_key (unsigned char *nonce,
64 unsigned char *key,
65 const char *label,
66 uint64_t exp,
68{
69 static const char ctx_key[] = "gns-xsalsa-ctx-key";
70 static const char ctx_iv[] = "gns-xsalsa-ctx-iv";
71
73 key, crypto_secretbox_KEYBYTES,
74 ctx_key, strlen (ctx_key),
75 pub, sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
77 memset (nonce, 0, crypto_secretbox_NONCEBYTES);
80 nonce, (crypto_secretbox_NONCEBYTES - sizeof (exp)),
81 ctx_iv, strlen (ctx_iv),
82 pub, sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
85 memcpy (nonce + (crypto_secretbox_NONCEBYTES - sizeof (exp)),
86 &exp, sizeof (exp));
87}
88
89
91block_sign_ecdsa (const struct
93 const struct
95 const char *label,
96 struct GNUNET_GNSRECORD_Block *block)
97{
98 struct GNRBlockPS *gnr_block;
99 struct GNUNET_GNSRECORD_EcdsaBlock *ecblock;
100 size_t size = ntohl (block->size) - sizeof (*block) + sizeof (*gnr_block);
101
102 gnr_block = GNUNET_malloc (size);
103 ecblock = &(block)->ecdsa_block;
104 gnr_block->purpose.size = htonl (size);
105 gnr_block->purpose.purpose =
107 gnr_block->expiration_time = ecblock->expiration_time;
108 /* encrypt and sign */
109 GNUNET_memcpy (&gnr_block[1], &ecblock[1],
110 size - sizeof (*gnr_block));
112 label,
113 "gns",
114 &ecblock->derived_key);
115 if (GNUNET_OK !=
117 label,
118 "gns",
119 &gnr_block->purpose,
120 &ecblock->signature))
121 {
122 GNUNET_break (0);
123 GNUNET_free (gnr_block);
124 return GNUNET_SYSERR;
125 }
126 GNUNET_free (gnr_block);
127 return GNUNET_OK;
128}
129
130
132block_sign_eddsa (const struct
134 const struct
136 const char *label,
137 struct GNUNET_GNSRECORD_Block *block)
138{
139 struct GNRBlockPS *gnr_block;
140 struct GNUNET_GNSRECORD_EddsaBlock *edblock;
141 size_t size = ntohl (block->size) - sizeof (*block) + sizeof (*gnr_block);
142 gnr_block = GNUNET_malloc (size);
143 edblock = &(block)->eddsa_block;
144 gnr_block->purpose.size = htonl (size);
145 gnr_block->purpose.purpose =
147 gnr_block->expiration_time = edblock->expiration_time;
148 GNUNET_memcpy (&gnr_block[1], &edblock[1],
149 size - sizeof (*gnr_block));
150 /* encrypt and sign */
152 label,
153 "gns",
154 &edblock->derived_key);
156 label,
157 "gns",
158 &gnr_block->purpose,
159 &edblock->signature);
160 GNUNET_free (gnr_block);
161 return GNUNET_OK;
162}
163
164
168 const char *label,
169 struct GNUNET_GNSRECORD_Block *block)
170{
173 char *norm_label;
174
176 &pkey);
177 norm_label = GNUNET_GNSRECORD_string_normalize (label);
178
179 switch (ntohl (key->type))
180 {
182 res = block_sign_ecdsa (&key->ecdsa_key,
183 &pkey.ecdsa_key,
184 norm_label,
185 block);
186 break;
188 res = block_sign_eddsa (&key->eddsa_key,
189 &pkey.eddsa_key,
190 norm_label,
191 block);
192 break;
193 default:
194 GNUNET_assert (0);
195 }
196 GNUNET_free (norm_label);
197 return res;
198}
199
200
218 const char *label,
219 const struct GNUNET_GNSRECORD_Data *rd,
220 unsigned int rd_count,
221 struct GNUNET_GNSRECORD_Block **block,
222 int sign)
223{
224 ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count,
225 rd);
226 struct GNUNET_GNSRECORD_EcdsaBlock *ecblock;
227 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
228 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH];
230 struct GNUNET_TIME_Absolute now;
231
232 if (payload_len < 0)
233 {
234 GNUNET_break (0);
235 return GNUNET_SYSERR;
236 }
237 if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
238 {
239 GNUNET_break (0);
240 return GNUNET_SYSERR;
241 }
242 /* convert relative to absolute times */
244 for (unsigned int i = 0; i < rd_count; i++)
245 {
246 rdc[i] = rd[i];
247 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
248 {
249 struct GNUNET_TIME_Relative t;
250
251 /* encrypted blocks must never have relative expiration times, convert! */
252 rdc[i].flags &= ~GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
253 t.rel_value_us = rdc[i].expiration_time;
255 }
256 }
257 /* serialize */
258 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + payload_len);
259 (*block)->size = htonl (sizeof (struct GNUNET_GNSRECORD_Block) + payload_len);
260 {
261 char payload[payload_len];
262
263 GNUNET_assert (payload_len ==
265 rdc,
266 payload_len,
267 payload));
268 ecblock = &(*block)->ecdsa_block;
269 (*block)->type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
272 skey,
273 label,
275 pkey);
277 payload_len,
278 skey,
279 ctr,
280 &ecblock[1]);
281 }
282 if (GNUNET_YES != sign)
283 return GNUNET_OK;
284 if (GNUNET_OK !=
285 block_sign_ecdsa (key, pkey, label, *block))
286 {
287 GNUNET_break (0);
288 GNUNET_free (*block);
289 return GNUNET_SYSERR;
290 }
291 return GNUNET_OK;
292}
293
294
312 const char *label,
313 const struct GNUNET_GNSRECORD_Data *rd,
314 unsigned int rd_count,
315 struct GNUNET_GNSRECORD_Block **block,
316 int sign)
317{
318 ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count,
319 rd);
320 struct GNUNET_GNSRECORD_EddsaBlock *edblock;
321 unsigned char nonce[crypto_secretbox_NONCEBYTES];
322 unsigned char skey[crypto_secretbox_KEYBYTES];
324 struct GNUNET_TIME_Absolute now;
325
326 if (payload_len < 0)
327 {
328 GNUNET_break (0);
329 return GNUNET_SYSERR;
330 }
331 if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
332 {
333 GNUNET_break (0);
334 return GNUNET_SYSERR;
335 }
336 /* convert relative to absolute times */
338 for (unsigned int i = 0; i < rd_count; i++)
339 {
340 rdc[i] = rd[i];
341 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
342 {
343 struct GNUNET_TIME_Relative t;
344
345 /* encrypted blocks must never have relative expiration times, convert! */
346 rdc[i].flags &= ~GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
347 t.rel_value_us = rdc[i].expiration_time;
349 }
350 }
351 /* serialize */
352 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block)
353 + payload_len + crypto_secretbox_MACBYTES);
354 (*block)->size = htonl (sizeof (struct GNUNET_GNSRECORD_Block)
355 + payload_len + crypto_secretbox_MACBYTES);
356 {
357 char payload[payload_len];
358
359 GNUNET_assert (payload_len ==
361 rdc,
362 payload_len,
363 payload));
364 edblock = &(*block)->eddsa_block;
365 (*block)->type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY);
368 skey,
369 label,
371 pkey);
374 payload_len,
375 (unsigned char*) payload,
376 skey,
377 nonce,
378 &edblock[1]));
379 if (GNUNET_YES != sign)
380 return GNUNET_OK;
381 block_sign_eddsa (key, pkey, label, *block);
382 }
383 return GNUNET_OK;
384}
385
386
389 key,
391 const char *label,
392 const struct GNUNET_GNSRECORD_Data *rd,
393 unsigned int rd_count,
395{
398 char *norm_label;
399
401 &pkey);
402 norm_label = GNUNET_GNSRECORD_string_normalize (label);
403
404 switch (ntohl (key->type))
405 {
407 res = block_create_ecdsa (&key->ecdsa_key,
408 &pkey.ecdsa_key,
409 expire,
410 norm_label,
411 rd,
412 rd_count,
413 result,
414 GNUNET_YES);
415 break;
417 res = block_create_eddsa (&key->eddsa_key,
418 &pkey.eddsa_key,
419 expire,
420 norm_label,
421 rd,
422 rd_count,
423 result,
424 GNUNET_YES);
425 break;
426 default:
427 GNUNET_assert (0);
428 }
429 GNUNET_free (norm_label);
430 return res;
431}
432
433
449
450
454 const char *label,
455 const struct GNUNET_GNSRECORD_Data *rd,
456 unsigned int rd_count,
458 int sign)
459{
461 struct GNUNET_CRYPTO_EddsaPublicKey edpubkey;
463 char *norm_label;
464#define CSIZE 64
465 static struct KeyCacheLine cache[CSIZE];
466 struct KeyCacheLine *line;
467
468 norm_label = GNUNET_GNSRECORD_string_normalize (label);
469
470 if (GNUNET_PUBLIC_KEY_TYPE_ECDSA == ntohl (pkey->type))
471 {
472 key = &pkey->ecdsa_key;
473
474 line = &cache[(*(unsigned int *) key) % CSIZE];
475 if (0 != memcmp (&line->key,
476 key,
477 sizeof(*key)))
478 {
479 /* cache miss, recompute */
480 line->key = *key;
482 &line->pkey);
483 }
485 &line->pkey,
486 expire,
487 norm_label,
488 rd,
489 rd_count,
490 result,
491 sign);
492 }
493 else if (GNUNET_PUBLIC_KEY_TYPE_EDDSA == ntohl (pkey->type))
494 {
496 &edpubkey);
497 res = block_create_eddsa (&pkey->eddsa_key,
498 &edpubkey,
499 expire,
500 norm_label,
501 rd,
502 rd_count,
503 result,
504 sign);
505 }
506#undef CSIZE
507 GNUNET_free (norm_label);
508 return res;
509}
510
511
516 const char *label,
517 const struct GNUNET_GNSRECORD_Data *rd,
518 unsigned int rd_count,
520{
521 return block_create2 (pkey,
522 expire,
523 label,
524 rd,
525 rd_count,
526 result,
527 GNUNET_NO);
528}
529
530
535 const char *label,
536 const struct GNUNET_GNSRECORD_Data *rd,
537 unsigned int rd_count,
539{
540 return block_create2 (pkey,
541 expire,
542 label,
543 rd,
544 rd_count,
545 result,
546 GNUNET_YES);
547}
548
549
559{
560 struct GNRBlockPS *purp;
561 size_t payload_len = ntohl (block->size)
562 - sizeof (struct GNUNET_GNSRECORD_Block);
564
565 if (ntohl (block->size) <
566 sizeof (struct GNUNET_GNSRECORD_Block))
567 {
568 GNUNET_break_op (0);
569 return GNUNET_SYSERR;
570 }
571 GNUNET_assert (payload_len <= UINT16_MAX);
572 purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len);
573 purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len);
575 GNUNET_memcpy (&purp[1],
576 &block[1],
577 payload_len);
578 switch (ntohl (block->type))
579 {
584 &purp->purpose,
585 &block->ecdsa_block.signature,
586 &block->ecdsa_block.derived_key);
587 break;
592 &purp->purpose,
593 &block->eddsa_block.signature,
594 &block->eddsa_block.derived_key);
595 break;
596 default:
597 res = GNUNET_NO;
598 }
599 GNUNET_free (purp);
600 return res;
601}
602
603
606 const struct GNUNET_GNSRECORD_Block *block,
607 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key,
608 const char *label,
610 void *proc_cls)
611{
612 size_t payload_len = ntohl (block->size)
613 - sizeof (struct GNUNET_GNSRECORD_Block);
614 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
615 unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH];
616
617 if (ntohl (block->size) <
618 sizeof (struct GNUNET_GNSRECORD_Block))
619 {
620 GNUNET_break_op (0);
621 return GNUNET_SYSERR;
622 }
623 GNUNET_assert (payload_len <= UINT16_MAX);
625 key,
626 label,
628 zone_key);
629 {
630 char payload[payload_len];
631 unsigned int rd_count;
632
633 GNUNET_CRYPTO_aes_ctr (&block[1],
634 payload_len,
635 key,
636 ctr,
637 payload);
639 payload);
640 if (rd_count > 2048)
641 {
642 /* limit to sane value */
643 GNUNET_break_op (0);
644 return GNUNET_SYSERR;
645 }
646 {
648 unsigned int j;
649 struct GNUNET_TIME_Absolute now;
650
651 if (GNUNET_OK !=
653 payload,
654 rd_count,
655 rd))
656 {
657 GNUNET_break_op (0);
658 return GNUNET_SYSERR;
659 }
660 /* hide expired records */
662 j = 0;
663 for (unsigned int i = 0; i < rd_count; i++)
664 {
665 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
666 {
667 /* encrypted blocks must never have relative expiration times, skip! */
668 GNUNET_break_op (0);
669 continue;
670 }
671
672 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
673 {
674 int include_record = GNUNET_YES;
675 /* Shadow record, figure out if we have a not expired active record */
676 for (unsigned int k = 0; k < rd_count; k++)
677 {
678 if (k == i)
679 continue;
680 if (rd[i].expiration_time < now.abs_value_us)
681 include_record = GNUNET_NO; /* Shadow record is expired */
682 if ((rd[k].record_type == rd[i].record_type) &&
683 (rd[k].expiration_time >= now.abs_value_us) &&
684 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
685 {
686 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
688 "Ignoring shadow record\n");
689 break;
690 }
691 }
692 if (GNUNET_YES == include_record)
693 {
694 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
695 if (j != i)
696 rd[j] = rd[i];
697 j++;
698 }
699 }
700 else if (rd[i].expiration_time >= now.abs_value_us)
701 {
702 /* Include this record */
703 if (j != i)
704 rd[j] = rd[i];
705 j++;
706 }
707 else
708 {
709 struct GNUNET_TIME_Absolute at;
710
713 "Excluding record that expired %s (%llu ago)\n",
715 (unsigned long long) rd[i].expiration_time
716 - now.abs_value_us);
717 }
718 }
719 rd_count = j;
720 if (NULL != proc)
721 proc (proc_cls,
722 rd_count,
723 (0 != rd_count) ? rd : NULL);
724 }
725 }
726 return GNUNET_OK;
727}
728
729
732 const struct
734 const char *label,
736 void *proc_cls)
737{
738 size_t payload_len = ntohl (block->size)
739 - sizeof (struct GNUNET_GNSRECORD_Block);
740 unsigned char nonce[crypto_secretbox_NONCEBYTES];
741 unsigned char key[crypto_secretbox_KEYBYTES];
742
743 if (ntohl (block->size) <
744 sizeof(struct GNUNET_GNSRECORD_Block))
745 {
746 GNUNET_break_op (0);
747 return GNUNET_SYSERR;
748 }
750 key,
751 label,
753 ,
754 zone_key);
755 {
756 char payload[payload_len];
757 unsigned int rd_count;
758
761 payload_len,
762 (unsigned char*) &block[1],
763 key,
764 nonce,
765 payload));
766 payload_len -= crypto_secretbox_MACBYTES;
768 payload);
769 if (rd_count > 2048)
770 {
771 /* limit to sane value */
772 GNUNET_break_op (0);
773 return GNUNET_SYSERR;
774 }
775 {
777 unsigned int j;
778 struct GNUNET_TIME_Absolute now;
779
780 if (GNUNET_OK !=
782 payload,
783 rd_count,
784 rd))
785 {
786 GNUNET_break_op (0);
787 return GNUNET_SYSERR;
788 }
789 /* hide expired records */
791 j = 0;
792 for (unsigned int i = 0; i < rd_count; i++)
793 {
794 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
795 {
796 /* encrypted blocks must never have relative expiration times, skip! */
797 GNUNET_break_op (0);
798 continue;
799 }
800
801 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
802 {
803 int include_record = GNUNET_YES;
804 /* Shadow record, figure out if we have a not expired active record */
805 for (unsigned int k = 0; k < rd_count; k++)
806 {
807 if (k == i)
808 continue;
809 if (rd[i].expiration_time < now.abs_value_us)
810 include_record = GNUNET_NO; /* Shadow record is expired */
811 if ((rd[k].record_type == rd[i].record_type) &&
812 (rd[k].expiration_time >= now.abs_value_us) &&
813 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
814 {
815 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
817 "Ignoring shadow record\n");
818 break;
819 }
820 }
821 if (GNUNET_YES == include_record)
822 {
823 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
824 if (j != i)
825 rd[j] = rd[i];
826 j++;
827 }
828 }
829 else if (rd[i].expiration_time >= now.abs_value_us)
830 {
831 /* Include this record */
832 if (j != i)
833 rd[j] = rd[i];
834 j++;
835 }
836 else
837 {
838 struct GNUNET_TIME_Absolute at;
839
842 "Excluding record that expired %s (%llu ago)\n",
844 (unsigned long long) rd[i].expiration_time
845 - now.abs_value_us);
846 }
847 }
848 rd_count = j;
849 if (NULL != proc)
850 proc (proc_cls,
851 rd_count,
852 (0 != rd_count) ? rd : NULL);
853 }
854 }
855 return GNUNET_OK;
856}
857
858
866void
869 ,
870 const char *label,
871 struct GNUNET_HashCode *query)
872{
873 char *norm_label;
875
876 norm_label = GNUNET_GNSRECORD_string_normalize (label);
877 switch (ntohl (zone->type))
878 {
881
883 &pub);
885 norm_label,
886 query);
887 break;
888 default:
889 GNUNET_assert (0);
890 }
891 GNUNET_free (norm_label);
892}
893
894
895void
898 const char *label,
899 struct GNUNET_HashCode *query)
900{
901 char *norm_label;
903
904 norm_label = GNUNET_GNSRECORD_string_normalize (label);
905
906 switch (ntohl (pub->type))
907 {
909 pd.type = pub->type;
911 norm_label,
912 "gns",
913 &pd.ecdsa_key);
915 sizeof (pd.ecdsa_key),
916 query);
917 break;
919 pd.type = pub->type;
921 norm_label,
922 "gns",
923 &(pd.eddsa_key));
925 sizeof (pd.eddsa_key),
926 query);
927 break;
928 default:
929 GNUNET_assert (0);
930 }
931 GNUNET_free (norm_label);
932}
933
934
941
944 const char *label,
945 const struct GNUNET_GNSRECORD_Block *block,
947 void *proc_cls)
948{
949 struct EncryptionContextData *ecd = cls;
951 char *norm_label;
952
953 norm_label = GNUNET_GNSRECORD_string_normalize (label);
954 return block_decrypt_ecdsa (block,
955 &ecd->zkey.ecdsa_key,
956 norm_label, proc,
957 proc_cls);
958 GNUNET_free (norm_label);
959 return res;
960
961}
962
963
966 const char *label,
967 const struct GNUNET_GNSRECORD_Block *block,
969 void *proc_cls)
970{
971 struct EncryptionContextData *ecd = cls;
973 char *norm_label;
974
975 norm_label = GNUNET_GNSRECORD_string_normalize (label);
976 res = block_decrypt_eddsa (block,
977 &ecd->zkey.eddsa_key,
978 norm_label, proc,
979 proc_cls);
980 GNUNET_free (norm_label);
981 return res;
982}
983
984
987 const char *label,
989 unsigned int rd_count,
990 const struct GNUNET_GNSRECORD_Data rd[rd_count],
992{
993 GNUNET_break (0);
994 return GNUNET_SYSERR;
995}
996
997
999block_seal (void *cls,
1000 const char *label,
1002 unsigned int rd_count,
1003 const struct GNUNET_GNSRECORD_Data rd[rd_count],
1005{
1006 struct EncryptionContextData *ecd = cls;
1007
1008 return block_create2 (ecd->sk,
1009 expire,
1010 label,
1011 rd,
1012 rd_count,
1013 result,
1014 GNUNET_YES);
1015}
1016
1017
1020 const struct GNUNET_CRYPTO_BlindablePrivateKey *sk)
1021{
1023 struct EncryptionContextData *ecd;
1024 size_t sk_len;
1025
1026 ec = GNUNET_malloc (sizeof(*ec) + sizeof(struct EncryptionContextData));
1027 ec->cls = &ec[1];
1028 ecd = ec->cls;
1030 ecd->sk = GNUNET_malloc (sk_len);
1031 GNUNET_memcpy (ecd->sk,
1032 sk,
1033 sk_len);
1035 switch (ntohl (sk->type))
1036 {
1038 ec->open = block_open_ecdsa;
1039 ec->seal = block_seal;
1040 break;
1042 ec->open = block_open_eddsa;
1043 ec->seal = block_seal;
1044 break;
1045 default:
1046 GNUNET_assert (0);
1047 }
1048 return ec;
1049}
1050
1051
1054 const struct GNUNET_CRYPTO_BlindablePublicKey *zkey)
1055{
1057 struct EncryptionContextData *ecd;
1058 size_t pk_len;
1059
1060 ec = GNUNET_malloc (sizeof (*ec) + sizeof (*ecd));
1061 ec->cls = &ec[1];
1062 ecd = ec->cls;
1064 GNUNET_memcpy (&ecd->zkey,
1065 zkey,
1066 pk_len);
1067 switch (ntohl (zkey->type))
1068 {
1070 ec->open = block_open_ecdsa;
1072 break;
1074 ec->open = block_open_eddsa;
1076 break;
1077 default:
1078 GNUNET_assert (0);
1079 }
1080 return ec;
1081}
1082
1083
1084void
1087 *ec)
1088{
1089 struct EncryptionContextData *ecd = ec->cls;
1090
1091 GNUNET_free (ecd->sk);
1092 GNUNET_free (ec);
1093
1094}
1095
1096
1099 const struct
1101 const char *label,
1103 void *proc_cls)
1104{
1107
1109 ret = ec->open (ec->cls,
1110 label,
1111 block,
1112 proc,
1113 proc_cls);
1115 return ret;
1116}
1117
1118
1119/* end of gnsrecord_crypto.c */
static enum GNUNET_GenericReturnValue block_seal_not_implemented(void *cls, const char *label, struct GNUNET_TIME_Absolute expire, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data rd[rd_count], struct GNUNET_GNSRECORD_Block **result)
static enum GNUNET_GenericReturnValue block_seal(void *cls, const char *label, struct GNUNET_TIME_Absolute expire, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data rd[rd_count], struct GNUNET_GNSRECORD_Block **result)
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_create2(const struct GNUNET_CRYPTO_BlindablePrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result, int sign)
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)
void GNR_derive_block_xsalsa_key(unsigned char *nonce, unsigned char *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_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_create_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records.
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 struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records (EDDSA version)
void GNR_derive_block_aes_key(unsigned char *ctr, unsigned char *key, const char *label, uint64_t exp, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive session key and iv from label and public key.
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
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)
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 struct GNUNET_SCHEDULER_Task * t
Main task.
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:708
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition crypto_ecc.c:201
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_encrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const unsigned char key[crypto_secretbox_xsalsa20poly1305_KEYBYTES], const unsigned char nonce[crypto_secretbox_xsalsa20poly1305_NONCEBYTES], void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_decrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const unsigned char key[crypto_secretbox_xsalsa20poly1305_KEYBYTES], const unsigned char nonce[crypto_secretbox_xsalsa20poly1305_NONCEBYTES], void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
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_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:649
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.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create2(const struct GNUNET_CRYPTO_BlindablePrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result)
Sign name and records, cache derived public key (also keeps the private key in static memory,...
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.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create(const struct GNUNET_CRYPTO_BlindablePrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result)
Sign name and records.
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.
ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
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.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create_unsigned(const struct GNUNET_CRYPTO_BlindablePrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result)
Create name and records but do not sign! Sign later with GNUNET_GNSRECORD_block_sign().
@ 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:41
#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:64
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:85
@ 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_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition time.c:452
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 (!...
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 int rd_count, const struct GNUNET_GNSRECORD_Data rd[rd_count], 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.
Time for relative time used by GNUnet, in microseconds.
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.