GNUnet 0.28.0
 
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 if (payload_len > UINT16_MAX)
484 {
485 GNUNET_break_op (0);
486 return GNUNET_SYSERR;
487 }
489 key,
490 label,
492 zone_key);
493 {
494 char payload[payload_len];
495 unsigned int rd_count;
496
497 GNUNET_CRYPTO_aes_ctr (&block[1],
498 payload_len,
499 key,
500 ctr,
501 payload);
503 payload);
504 if (rd_count > 2048)
505 {
506 /* limit to sane value */
507 GNUNET_break_op (0);
508 return GNUNET_SYSERR;
509 }
510 {
512 unsigned int j;
513 struct GNUNET_TIME_Absolute now;
514
515 if (GNUNET_OK !=
517 payload,
518 rd_count,
519 rd))
520 {
521 GNUNET_break_op (0);
522 return GNUNET_SYSERR;
523 }
524 /* hide expired records */
526 j = 0;
527 for (unsigned int i = 0; i < rd_count; i++)
528 {
529 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
530 {
531 /* encrypted blocks must never have relative expiration times, skip! */
532 GNUNET_break_op (0);
533 continue;
534 }
535
536 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
537 {
538 int include_record = GNUNET_YES;
539 /* Shadow record, figure out if we have a not expired active record */
540 for (unsigned int k = 0; k < rd_count; k++)
541 {
542 if (k == i)
543 continue;
544 if (rd[i].expiration_time < now.abs_value_us)
545 include_record = GNUNET_NO; /* Shadow record is expired */
546 if ((rd[k].record_type == rd[i].record_type) &&
547 (rd[k].expiration_time >= now.abs_value_us) &&
548 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
549 {
550 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
552 "Ignoring shadow record\n");
553 break;
554 }
555 }
556 if (GNUNET_YES == include_record)
557 {
558 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
559 if (j != i)
560 rd[j] = rd[i];
561 j++;
562 }
563 }
564 else if (rd[i].expiration_time >= now.abs_value_us)
565 {
566 /* Include this record */
567 if (j != i)
568 rd[j] = rd[i];
569 j++;
570 }
571 else
572 {
573 struct GNUNET_TIME_Absolute at;
574
577 "Excluding record that expired %s (%llu ago)\n",
579 (unsigned long long) rd[i].expiration_time
580 - now.abs_value_us);
581 }
582 }
583 rd_count = j;
584 if (NULL != proc)
585 proc (proc_cls,
586 rd_count,
587 (0 != rd_count) ? rd : NULL);
588 }
589 }
590 return GNUNET_OK;
591}
592
593
596 const struct
598 const char *label,
600 void *proc_cls)
601{
602 size_t payload_len = ntohl (block->size)
603 - sizeof (struct GNUNET_GNSRECORD_Block);
606
607
608 if (ntohl (block->size) <
609 sizeof(struct GNUNET_GNSRECORD_Block))
610 {
611 GNUNET_break_op (0);
612 return GNUNET_SYSERR;
613 }
614 if (payload_len > UINT16_MAX)
615 {
616 GNUNET_break_op (0);
617 return GNUNET_SYSERR;
618 }
620 &skey,
621 label,
623 ,
624 zone_key);
625 {
626 char payload[payload_len];
627 unsigned int rd_count;
628
629 if (GNUNET_OK !=
631 payload_len,
632 (unsigned char*) &block[1],
633 &skey,
634 &nonce,
635 payload))
636 {
637 GNUNET_break_op (0);
638 return GNUNET_SYSERR;
639 }
640 payload_len -= crypto_secretbox_MACBYTES;
642 payload);
643 if (rd_count > 2048)
644 {
645 /* limit to sane value */
646 GNUNET_break_op (0);
647 return GNUNET_SYSERR;
648 }
649 {
651 unsigned int j;
652 struct GNUNET_TIME_Absolute now;
653
654 if (GNUNET_OK !=
656 payload,
657 rd_count,
658 rd))
659 {
660 GNUNET_break_op (0);
661 return GNUNET_SYSERR;
662 }
663 /* hide expired records */
665 j = 0;
666 for (unsigned int i = 0; i < rd_count; i++)
667 {
668 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
669 {
670 /* encrypted blocks must never have relative expiration times, skip! */
671 GNUNET_break_op (0);
672 continue;
673 }
674
675 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
676 {
677 int include_record = GNUNET_YES;
678 /* Shadow record, figure out if we have a not expired active record */
679 for (unsigned int k = 0; k < rd_count; k++)
680 {
681 if (k == i)
682 continue;
683 if (rd[i].expiration_time < now.abs_value_us)
684 include_record = GNUNET_NO; /* Shadow record is expired */
685 if ((rd[k].record_type == rd[i].record_type) &&
686 (rd[k].expiration_time >= now.abs_value_us) &&
687 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
688 {
689 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
691 "Ignoring shadow record\n");
692 break;
693 }
694 }
695 if (GNUNET_YES == include_record)
696 {
697 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
698 if (j != i)
699 rd[j] = rd[i];
700 j++;
701 }
702 }
703 else if (rd[i].expiration_time >= now.abs_value_us)
704 {
705 /* Include this record */
706 if (j != i)
707 rd[j] = rd[i];
708 j++;
709 }
710 else
711 {
712 struct GNUNET_TIME_Absolute at;
713
716 "Excluding record that expired %s (%llu ago)\n",
718 (unsigned long long) rd[i].expiration_time
719 - now.abs_value_us);
720 }
721 }
722 rd_count = j;
723 if (NULL != proc)
724 proc (proc_cls,
725 rd_count,
726 (0 != rd_count) ? rd : NULL);
727 }
728 }
729 return GNUNET_OK;
730}
731
732
733#pragma GCC diagnostic pop
734
742void
745 ,
746 const char *label,
747 struct GNUNET_HashCode *query)
748{
749 char *norm_label;
751
752 norm_label = GNUNET_GNSRECORD_string_normalize (label);
753 switch (ntohl (zone->type))
754 {
757
759 &pub);
761 norm_label,
762 query);
763 break;
764 default:
765 GNUNET_assert (0);
766 }
767 GNUNET_free (norm_label);
768}
769
770
771#pragma GCC diagnostic push
772#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
773void
776 const char *label,
777 struct GNUNET_HashCode *query)
778{
779 char *norm_label;
781
782 norm_label = GNUNET_GNSRECORD_string_normalize (label);
783
784 switch (ntohl (pub->type))
785 {
787 pd.type = pub->type;
789 norm_label,
790 "gns",
791 &pd.ecdsa_key);
793 sizeof (pd.ecdsa_key),
794 query);
795 break;
797 pd.type = pub->type;
799 norm_label,
800 "gns",
801 &(pd.eddsa_key));
803 sizeof (pd.eddsa_key),
804 query);
805 break;
806 default:
807 GNUNET_assert (0);
808 }
809 GNUNET_free (norm_label);
810}
811
812
813#pragma GCC diagnostic pop
814
821
824 const char *label,
825 const struct GNUNET_GNSRECORD_Block *block,
827 void *proc_cls)
828{
829 struct EncryptionContextData *ecd = cls;
831 char *norm_label;
832
833 norm_label = GNUNET_GNSRECORD_string_normalize (label);
834 return block_decrypt_ecdsa (block,
835 &ecd->zkey.ecdsa_key,
836 norm_label, proc,
837 proc_cls);
838 GNUNET_free (norm_label);
839 return res;
840
841}
842
843
846 const char *label,
847 const struct GNUNET_GNSRECORD_Block *block,
849 void *proc_cls)
850{
851 struct EncryptionContextData *ecd = cls;
853 char *norm_label;
854
855 norm_label = GNUNET_GNSRECORD_string_normalize (label);
856 res = block_decrypt_eddsa (block,
857 &ecd->zkey.eddsa_key,
858 norm_label, proc,
859 proc_cls);
860 GNUNET_free (norm_label);
861 return res;
862}
863
864
867 const char *label,
869 unsigned char *rdata,
870 size_t rdata_len,
872{
873 GNUNET_break (0);
874 return GNUNET_SYSERR;
875}
876
877
879block_seal (void *cls,
880 const char *label,
882 unsigned char *rdata,
883 size_t rdata_len,
885{
886 struct EncryptionContextData *ecd = cls;
887
888 return block_create2 (ecd->sk,
889 expire,
890 label,
891 rdata,
892 rdata_len,
893 result,
894 GNUNET_YES);
895}
896
897
900 const struct GNUNET_CRYPTO_BlindablePrivateKey *sk)
901{
903 struct EncryptionContextData *ecd;
904 size_t sk_len;
905
906 ec = GNUNET_malloc (sizeof(*ec) + sizeof(struct EncryptionContextData));
907 ec->cls = &ec[1];
908 ecd = ec->cls;
910 ecd->sk = GNUNET_malloc (sk_len);
911 GNUNET_memcpy (ecd->sk,
912 sk,
913 sk_len);
915 switch (ntohl (sk->type))
916 {
919 ec->seal = block_seal;
920 break;
923 ec->seal = block_seal;
924 break;
925 default:
926 GNUNET_assert (0);
927 }
928 return ec;
929}
930
931
934 const struct GNUNET_CRYPTO_BlindablePublicKey *zkey)
935{
937 struct EncryptionContextData *ecd;
938 size_t pk_len;
939
940 ec = GNUNET_malloc (sizeof (*ec) + sizeof (*ecd));
941 ec->cls = &ec[1];
942 ecd = ec->cls;
944 GNUNET_memcpy (&ecd->zkey,
945 zkey,
946 pk_len);
947 switch (ntohl (zkey->type))
948 {
952 break;
956 break;
957 default:
958 GNUNET_assert (0);
959 }
960 return ec;
961}
962
963
964void
967 *ec)
968{
969 struct EncryptionContextData *ecd = ec->cls;
970
971 GNUNET_free (ecd->sk);
972 GNUNET_free (ec);
973
974}
975
976
979 const struct
981 const char *label,
983 void *proc_cls)
984{
987
989 ret = ec->open (ec->cls,
990 label,
991 block,
992 proc,
993 proc_cls);
995 return ret;
996}
997
998
999/* 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:729
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
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:191
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:670
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.