diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-14 17:51:34 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-14 17:51:34 +0100 |
commit | b8672206edfb2047132311b9a3ab3a0138bdc422 (patch) | |
tree | 3c9361a0ba00b5f1d4944fec66cbc9a266d31ca9 /src/include/gnunet_identity_service.h | |
parent | 34587531b0ed15bbc8d73d21123101b7ca482389 (diff) | |
parent | 8e8c3f1e1c8c81a269c57e635153ec22fbfe216e (diff) | |
download | gnunet-b8672206edfb2047132311b9a3ab3a0138bdc422.tar.gz gnunet-b8672206edfb2047132311b9a3ab3a0138bdc422.zip |
Merge branch 'master' of ssh://git.gnunet.org/gnunet
Diffstat (limited to 'src/include/gnunet_identity_service.h')
-rw-r--r-- | src/include/gnunet_identity_service.h | 575 |
1 files changed, 6 insertions, 569 deletions
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index d4192a77f..270f4d26f 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h | |||
@@ -62,20 +62,6 @@ extern "C" { | |||
62 | */ | 62 | */ |
63 | #define GNUNET_IDENTITY_VERSION 0x00000100 | 63 | #define GNUNET_IDENTITY_VERSION 0x00000100 |
64 | 64 | ||
65 | enum GNUNET_IDENTITY_KeyType | ||
66 | { | ||
67 | /** | ||
68 | * The identity type. The value is the same as the | ||
69 | * PKEY record type. | ||
70 | */ | ||
71 | GNUNET_IDENTITY_TYPE_ECDSA = 65536, | ||
72 | |||
73 | /** | ||
74 | * EDDSA identity. The value is the same as the EDKEY | ||
75 | * record type. | ||
76 | */ | ||
77 | GNUNET_IDENTITY_TYPE_EDDSA = 65556 | ||
78 | }; | ||
79 | 65 | ||
80 | /** | 66 | /** |
81 | * Handle to access the identity service. | 67 | * Handle to access the identity service. |
@@ -88,89 +74,6 @@ struct GNUNET_IDENTITY_Handle; | |||
88 | struct GNUNET_IDENTITY_Ego; | 74 | struct GNUNET_IDENTITY_Ego; |
89 | 75 | ||
90 | /** | 76 | /** |
91 | * A private key for an identity as per LSD0001. | ||
92 | * Note that these types are NOT packed and MUST NOT be used in RPC | ||
93 | * messages. Use the respective serialization functions. | ||
94 | */ | ||
95 | struct GNUNET_IDENTITY_PrivateKey | ||
96 | { | ||
97 | /** | ||
98 | * Type of public key. | ||
99 | * Defined by the GNS zone type value. | ||
100 | * In NBO. | ||
101 | */ | ||
102 | uint32_t type; | ||
103 | |||
104 | union | ||
105 | { | ||
106 | /** | ||
107 | * An ECDSA identity key. | ||
108 | */ | ||
109 | struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key; | ||
110 | |||
111 | /** | ||
112 | * AN EdDSA identtiy key | ||
113 | */ | ||
114 | struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key; | ||
115 | }; | ||
116 | }; | ||
117 | |||
118 | |||
119 | /** | ||
120 | * An identity key as per LSD0001. | ||
121 | */ | ||
122 | struct GNUNET_IDENTITY_PublicKey | ||
123 | { | ||
124 | /** | ||
125 | * Type of public key. | ||
126 | * Defined by the GNS zone type value. | ||
127 | * In NBO. | ||
128 | */ | ||
129 | uint32_t type; | ||
130 | |||
131 | union | ||
132 | { | ||
133 | /** | ||
134 | * An ECDSA identity key. | ||
135 | */ | ||
136 | struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key; | ||
137 | |||
138 | /** | ||
139 | * AN EdDSA identtiy key | ||
140 | */ | ||
141 | struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key; | ||
142 | }; | ||
143 | }; | ||
144 | |||
145 | |||
146 | /** | ||
147 | * An identity signature as per LSD0001. | ||
148 | */ | ||
149 | struct GNUNET_IDENTITY_Signature | ||
150 | { | ||
151 | /** | ||
152 | * Type of signature. | ||
153 | * Defined by the GNS zone type value. | ||
154 | * In NBO. | ||
155 | */ | ||
156 | uint32_t type; | ||
157 | |||
158 | union | ||
159 | { | ||
160 | /** | ||
161 | * An ECDSA signature | ||
162 | */ | ||
163 | struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature; | ||
164 | |||
165 | /** | ||
166 | * AN EdDSA signature | ||
167 | */ | ||
168 | struct GNUNET_CRYPTO_EddsaSignature eddsa_signature; | ||
169 | }; | ||
170 | }; | ||
171 | |||
172 | |||
173 | /** | ||
174 | * Handle for an operation with the identity service. | 77 | * Handle for an operation with the identity service. |
175 | */ | 78 | */ |
176 | struct GNUNET_IDENTITY_Operation; | 79 | struct GNUNET_IDENTITY_Operation; |
@@ -182,7 +85,7 @@ struct GNUNET_IDENTITY_Operation; | |||
182 | * @param ego the ego | 85 | * @param ego the ego |
183 | * @return associated ECC key, valid as long as the ego is valid | 86 | * @return associated ECC key, valid as long as the ego is valid |
184 | */ | 87 | */ |
185 | const struct GNUNET_IDENTITY_PrivateKey * | 88 | const struct GNUNET_CRYPTO_PrivateKey * |
186 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); | 89 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); |
187 | 90 | ||
188 | 91 | ||
@@ -203,7 +106,7 @@ GNUNET_IDENTITY_ego_get_anonymous (void); | |||
203 | */ | 106 | */ |
204 | void | 107 | void |
205 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, | 108 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, |
206 | struct GNUNET_IDENTITY_PublicKey *pk); | 109 | struct GNUNET_CRYPTO_PublicKey *pk); |
207 | 110 | ||
208 | 111 | ||
209 | /** | 112 | /** |
@@ -336,7 +239,7 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h); | |||
336 | typedef void | 239 | typedef void |
337 | (*GNUNET_IDENTITY_CreateContinuation) ( | 240 | (*GNUNET_IDENTITY_CreateContinuation) ( |
338 | void *cls, | 241 | void *cls, |
339 | const struct GNUNET_IDENTITY_PrivateKey *pk, | 242 | const struct GNUNET_CRYPTO_PrivateKey *pk, |
340 | enum GNUNET_ErrorCode ec); | 243 | enum GNUNET_ErrorCode ec); |
341 | 244 | ||
342 | 245 | ||
@@ -354,8 +257,8 @@ typedef void | |||
354 | struct GNUNET_IDENTITY_Operation * | 257 | struct GNUNET_IDENTITY_Operation * |
355 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, | 258 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, |
356 | const char *name, | 259 | const char *name, |
357 | const struct GNUNET_IDENTITY_PrivateKey *privkey, | 260 | const struct GNUNET_CRYPTO_PrivateKey *privkey, |
358 | enum GNUNET_IDENTITY_KeyType ktype, | 261 | enum GNUNET_CRYPTO_KeyType ktype, |
359 | GNUNET_IDENTITY_CreateContinuation cont, | 262 | GNUNET_IDENTITY_CreateContinuation cont, |
360 | void *cont_cls); | 263 | void *cont_cls); |
361 | 264 | ||
@@ -406,472 +309,6 @@ void | |||
406 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); | 309 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); |
407 | 310 | ||
408 | 311 | ||
409 | /** | ||
410 | * Get the compacted length of a #GNUNET_IDENTITY_PublicKey. | ||
411 | * Compacted means that it returns the minimum number of bytes this | ||
412 | * key is long, as opposed to the union structure inside | ||
413 | * #GNUNET_IDENTITY_PublicKey. | ||
414 | * Useful for compact serializations. | ||
415 | * | ||
416 | * @param key the key. | ||
417 | * @return -1 on error, else the compacted length of the key. | ||
418 | */ | ||
419 | ssize_t | ||
420 | GNUNET_IDENTITY_public_key_get_length (const struct | ||
421 | GNUNET_IDENTITY_PublicKey *key); | ||
422 | |||
423 | /** | ||
424 | * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer. | ||
425 | * The buffer has to contain at least the compacted length of | ||
426 | * a #GNUNET_IDENTITY_PublicKey in bytes. | ||
427 | * If the buffer is too small, the function returns -1 as error. | ||
428 | * If the buffer does not contain a valid key, it returns -2 as error. | ||
429 | * | ||
430 | * @param buffer the buffer | ||
431 | * @param len the length of buffer | ||
432 | * @param key the key | ||
433 | * @param the amount of bytes read from the buffer | ||
434 | * @return #GNUNET_SYSERR on error | ||
435 | */ | ||
436 | enum GNUNET_GenericReturnValue | ||
437 | GNUNET_IDENTITY_read_public_key_from_buffer ( | ||
438 | const void *buffer, | ||
439 | size_t len, | ||
440 | struct GNUNET_IDENTITY_PublicKey *key, | ||
441 | size_t *read); | ||
442 | |||
443 | /** | ||
444 | * Get the compacted length of a #GNUNET_IDENTITY_PrivateKey. | ||
445 | * Compacted means that it returns the minimum number of bytes this | ||
446 | * key is long, as opposed to the union structure inside | ||
447 | * #GNUNET_IDENTITY_PrivateKey. | ||
448 | * Useful for compact serializations. | ||
449 | * | ||
450 | * @param key the key. | ||
451 | * @return -1 on error, else the compacted length of the key. | ||
452 | */ | ||
453 | ssize_t | ||
454 | GNUNET_IDENTITY_private_key_get_length ( | ||
455 | const struct GNUNET_IDENTITY_PrivateKey *key); | ||
456 | |||
457 | |||
458 | /** | ||
459 | * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer. | ||
460 | * The buffer requires space for at least the compacted length of | ||
461 | * a #GNUNET_IDENTITY_PublicKey in bytes. | ||
462 | * If the buffer is too small, the function returns -1 as error. | ||
463 | * If the key is not valid, it returns -2 as error. | ||
464 | * | ||
465 | * @param key the key | ||
466 | * @param buffer the buffer | ||
467 | * @param len the length of buffer | ||
468 | * @return -1 or -2 on error, else the amount of bytes written to the buffer | ||
469 | */ | ||
470 | ssize_t | ||
471 | GNUNET_IDENTITY_write_public_key_to_buffer (const struct | ||
472 | GNUNET_IDENTITY_PublicKey *key, | ||
473 | void*buffer, | ||
474 | size_t len); | ||
475 | |||
476 | |||
477 | /** | ||
478 | * Reads a #GNUNET_IDENTITY_PrivateKey from a compact buffer. | ||
479 | * The buffer has to contain at least the compacted length of | ||
480 | * a #GNUNET_IDENTITY_PrivateKey in bytes. | ||
481 | * If the buffer is too small, the function returns GNUNET_SYSERR as error. | ||
482 | * | ||
483 | * @param buffer the buffer | ||
484 | * @param len the length of buffer | ||
485 | * @param key the key | ||
486 | * @param the amount of bytes read from the buffer | ||
487 | * @return #GNUNET_SYSERR on error | ||
488 | */ | ||
489 | enum GNUNET_GenericReturnValue | ||
490 | GNUNET_IDENTITY_read_private_key_from_buffer ( | ||
491 | const void*buffer, | ||
492 | size_t len, | ||
493 | struct GNUNET_IDENTITY_PrivateKey *key, | ||
494 | size_t *read); | ||
495 | |||
496 | |||
497 | /** | ||
498 | * Writes a #GNUNET_IDENTITY_PrivateKey to a compact buffer. | ||
499 | * The buffer requires space for at least the compacted length of | ||
500 | * a #GNUNET_IDENTITY_PrivateKey in bytes. | ||
501 | * If the buffer is too small, the function returns -1 as error. | ||
502 | * If the key is not valid, it returns -2 as error. | ||
503 | * | ||
504 | * @param key the key | ||
505 | * @param buffer the buffer | ||
506 | * @param len the length of buffer | ||
507 | * @return -1 or -2 on error, else the amount of bytes written to the buffer | ||
508 | */ | ||
509 | ssize_t | ||
510 | GNUNET_IDENTITY_write_private_key_to_buffer ( | ||
511 | const struct GNUNET_IDENTITY_PrivateKey *key, | ||
512 | void*buffer, | ||
513 | size_t len); | ||
514 | |||
515 | |||
516 | /** | ||
517 | * Get the compacted length of a #GNUNET_IDENTITY_Signature. | ||
518 | * Compacted means that it returns the minimum number of bytes this | ||
519 | * signature is long, as opposed to the union structure inside | ||
520 | * #GNUNET_IDENTITY_Signature. | ||
521 | * Useful for compact serializations. | ||
522 | * | ||
523 | * @param sig the signature. | ||
524 | * @return -1 on error, else the compacted length of the signature. | ||
525 | */ | ||
526 | ssize_t | ||
527 | GNUNET_IDENTITY_signature_get_length ( | ||
528 | const struct GNUNET_IDENTITY_Signature *sig); | ||
529 | |||
530 | |||
531 | /** | ||
532 | * Get the compacted length of a signature by type. | ||
533 | * Compacted means that it returns the minimum number of bytes this | ||
534 | * signature is long, as opposed to the union structure inside | ||
535 | * #GNUNET_IDENTITY_Signature. | ||
536 | * Useful for compact serializations. | ||
537 | * | ||
538 | * @param sig the signature. | ||
539 | * @return -1 on error, else the compacted length of the signature. | ||
540 | */ | ||
541 | ssize_t | ||
542 | GNUNET_IDENTITY_signature_get_raw_length_by_type (uint32_t type); | ||
543 | |||
544 | |||
545 | /** | ||
546 | * Reads a #GNUNET_IDENTITY_Signature from a compact buffer. | ||
547 | * The buffer has to contain at least the compacted length of | ||
548 | * a #GNUNET_IDENTITY_Signature in bytes. | ||
549 | * If the buffer is too small, the function returns -1 as error. | ||
550 | * If the buffer does not contain a valid key, it returns -2 as error. | ||
551 | * | ||
552 | * @param sig the signature | ||
553 | * @param buffer the buffer | ||
554 | * @param len the length of buffer | ||
555 | * @return -1 or -2 on error, else the amount of bytes read from the buffer | ||
556 | */ | ||
557 | ssize_t | ||
558 | GNUNET_IDENTITY_read_signature_from_buffer ( | ||
559 | struct GNUNET_IDENTITY_Signature *sig, | ||
560 | const void*buffer, | ||
561 | size_t len); | ||
562 | |||
563 | |||
564 | /** | ||
565 | * Writes a #GNUNET_IDENTITY_Signature to a compact buffer. | ||
566 | * The buffer requires space for at least the compacted length of | ||
567 | * a #GNUNET_IDENTITY_Signature in bytes. | ||
568 | * If the buffer is too small, the function returns -1 as error. | ||
569 | * If the key is not valid, it returns -2 as error. | ||
570 | * | ||
571 | * @param sig the signature | ||
572 | * @param buffer the buffer | ||
573 | * @param len the length of buffer | ||
574 | * @return -1 or -2 on error, else the amount of bytes written to the buffer | ||
575 | */ | ||
576 | ssize_t | ||
577 | GNUNET_IDENTITY_write_signature_to_buffer ( | ||
578 | const struct GNUNET_IDENTITY_Signature *sig, | ||
579 | void*buffer, | ||
580 | size_t len); | ||
581 | |||
582 | |||
583 | /** | ||
584 | * @brief Sign a given block. | ||
585 | * | ||
586 | * The @a purpose data is the beginning of the data of which the signature is | ||
587 | * to be created. The `size` field in @a purpose must correctly indicate the | ||
588 | * number of bytes of the data structure, including its header. If possible, | ||
589 | * use #GNUNET_IDENTITY_sign() instead of this function. | ||
590 | * | ||
591 | * @param priv private key to use for the signing | ||
592 | * @param purpose what to sign (size, purpose) | ||
593 | * @param[out] sig where to write the signature | ||
594 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
595 | */ | ||
596 | enum GNUNET_GenericReturnValue | ||
597 | GNUNET_IDENTITY_sign_ ( | ||
598 | const struct GNUNET_IDENTITY_PrivateKey *priv, | ||
599 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
600 | struct GNUNET_IDENTITY_Signature *sig); | ||
601 | |||
602 | /** | ||
603 | * @brief Sign a given block. | ||
604 | * | ||
605 | * The @a purpose data is the beginning of the data of which the signature is | ||
606 | * to be created. The `size` field in @a purpose must correctly indicate the | ||
607 | * number of bytes of the data structure, including its header. | ||
608 | * The signature payload and length depends on the key type. | ||
609 | * | ||
610 | * @param priv private key to use for the signing | ||
611 | * @param purpose what to sign (size, purpose) | ||
612 | * @param[out] sig where to write the signature | ||
613 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
614 | */ | ||
615 | enum GNUNET_GenericReturnValue | ||
616 | GNUNET_IDENTITY_sign_raw_ ( | ||
617 | const struct GNUNET_IDENTITY_PrivateKey *priv, | ||
618 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
619 | unsigned char *sig); | ||
620 | |||
621 | |||
622 | /** | ||
623 | * @brief Sign a given block with #GNUNET_IDENTITY_PrivateKey. | ||
624 | * | ||
625 | * The @a ps data must be a fixed-size struct for which the signature is to be | ||
626 | * created. The `size` field in @a ps->purpose must correctly indicate the | ||
627 | * number of bytes of the data structure, including its header. | ||
628 | * | ||
629 | * @param priv private key to use for the signing | ||
630 | * @param ps packed struct with what to sign, MUST begin with a purpose | ||
631 | * @param[out] sig where to write the signature | ||
632 | */ | ||
633 | #define GNUNET_IDENTITY_sign(priv,ps,sig) do { \ | ||
634 | /* check size is set correctly */ \ | ||
635 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | ||
636 | /* check 'ps' begins with the purpose */ \ | ||
637 | GNUNET_static_assert (((void*) (ps)) == \ | ||
638 | ((void*) &(ps)->purpose)); \ | ||
639 | GNUNET_assert (GNUNET_OK == \ | ||
640 | GNUNET_IDENTITY_sign_ (priv, \ | ||
641 | &(ps)->purpose, \ | ||
642 | sig)); \ | ||
643 | } while (0) | ||
644 | |||
645 | |||
646 | /** | ||
647 | * @brief Verify a given signature. | ||
648 | * | ||
649 | * The @a validate data is the beginning of the data of which the signature | ||
650 | * is to be verified. The `size` field in @a validate must correctly indicate | ||
651 | * the number of bytes of the data structure, including its header. If @a | ||
652 | * purpose does not match the purpose given in @a validate (the latter must be | ||
653 | * in big endian), signature verification fails. If possible, | ||
654 | * use #GNUNET_IDENTITY_signature_verify() instead of this function (only if @a validate | ||
655 | * is not fixed-size, you must use this function directly). | ||
656 | * | ||
657 | * @param purpose what is the purpose that the signature should have? | ||
658 | * @param validate block to validate (size, purpose, data) | ||
659 | * @param sig signature that is being validated | ||
660 | * @param pub public key of the signer | ||
661 | * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid | ||
662 | */ | ||
663 | enum GNUNET_GenericReturnValue | ||
664 | GNUNET_IDENTITY_signature_verify_ ( | ||
665 | uint32_t purpose, | ||
666 | const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, | ||
667 | const struct GNUNET_IDENTITY_Signature *sig, | ||
668 | const struct GNUNET_IDENTITY_PublicKey *pub); | ||
669 | |||
670 | /** | ||
671 | * @brief Verify a given signature. | ||
672 | * | ||
673 | * The @a validate data is the beginning of the data of which the signature | ||
674 | * is to be verified. The `size` field in @a validate must correctly indicate | ||
675 | * the number of bytes of the data structure, including its header. If @a | ||
676 | * purpose does not match the purpose given in @a validate (the latter must be | ||
677 | * in big endian), signature verification fails. | ||
678 | * | ||
679 | * @param purpose what is the purpose that the signature should have? | ||
680 | * @param validate block to validate (size, purpose, data) | ||
681 | * @param sig signature that is being validated | ||
682 | * @param pub public key of the signer | ||
683 | * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid | ||
684 | */ | ||
685 | enum GNUNET_GenericReturnValue | ||
686 | GNUNET_IDENTITY_signature_verify_raw_ ( | ||
687 | uint32_t purpose, | ||
688 | const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, | ||
689 | const unsigned char *sig, | ||
690 | const struct GNUNET_IDENTITY_PublicKey *pub); | ||
691 | |||
692 | |||
693 | /** | ||
694 | * @brief Verify a given signature with #GNUNET_IDENTITY_PublicKey. | ||
695 | * | ||
696 | * The @a ps data must be a fixed-size struct for which the signature is to be | ||
697 | * created. The `size` field in @a ps->purpose must correctly indicate the | ||
698 | * number of bytes of the data structure, including its header. | ||
699 | * | ||
700 | * @param purp purpose of the signature, must match 'ps->purpose.purpose' | ||
701 | * (except in host byte order) | ||
702 | * @param ps packed struct with what to sign, MUST begin with a purpose | ||
703 | * @param sig where to read the signature from | ||
704 | * @param pub public key to use for the verifying | ||
705 | */ | ||
706 | #define GNUNET_IDENTITY_signature_verify(purp,ps,sig,pub) ({ \ | ||
707 | /* check size is set correctly */ \ | ||
708 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | ||
709 | /* check 'ps' begins with the purpose */ \ | ||
710 | GNUNET_static_assert (((void*) (ps)) == \ | ||
711 | ((void*) &(ps)->purpose)); \ | ||
712 | GNUNET_IDENTITY_signature_verify_ (purp, \ | ||
713 | &(ps)->purpose, \ | ||
714 | sig, \ | ||
715 | pub); \ | ||
716 | }) | ||
717 | |||
718 | |||
719 | /** | ||
720 | * Encrypt a block with #GNUNET_IDENTITY_PublicKey and derives a | ||
721 | * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption | ||
722 | * using ecdh to derive a symmetric key. | ||
723 | * | ||
724 | * @param block the block to encrypt | ||
725 | * @param size the size of the @a block | ||
726 | * @param pub public key to use for ecdh | ||
727 | * @param ecc where to write the ecc public key | ||
728 | * @param result the output parameter in which to store the encrypted result | ||
729 | * can be the same or overlap with @c block | ||
730 | * @returns the size of the encrypted block, -1 for errors. | ||
731 | * Due to the use of CFB and therefore an effective stream cipher, | ||
732 | * this size should be the same as @c len. | ||
733 | */ | ||
734 | ssize_t | ||
735 | GNUNET_IDENTITY_encrypt_old (const void *block, | ||
736 | size_t size, | ||
737 | const struct GNUNET_IDENTITY_PublicKey *pub, | ||
738 | struct GNUNET_CRYPTO_EcdhePublicKey *ecc, | ||
739 | void *result); | ||
740 | |||
741 | |||
742 | /** | ||
743 | * Decrypt a given block with #GNUNET_IDENTITY_PrivateKey and a given | ||
744 | * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key. | ||
745 | * | ||
746 | * @param block the data to decrypt, encoded as returned by encrypt | ||
747 | * @param size the size of the @a block to decrypt | ||
748 | * @param priv private key to use for ecdh | ||
749 | * @param ecc the ecc public key | ||
750 | * @param result address to store the result at | ||
751 | * can be the same or overlap with @c block | ||
752 | * @return -1 on failure, size of decrypted block on success. | ||
753 | * Due to the use of CFB and therefore an effective stream cipher, | ||
754 | * this size should be the same as @c size. | ||
755 | */ | ||
756 | ssize_t | ||
757 | GNUNET_IDENTITY_decrypt_old ( | ||
758 | const void *block, | ||
759 | size_t size, | ||
760 | const struct GNUNET_IDENTITY_PrivateKey *priv, | ||
761 | const struct GNUNET_CRYPTO_EcdhePublicKey *ecc, | ||
762 | void *result); | ||
763 | |||
764 | #define GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES (crypto_secretbox_MACBYTES \ | ||
765 | + sizeof (struct \ | ||
766 | GNUNET_CRYPTO_FoKemC)) | ||
767 | |||
768 | /** | ||
769 | * Encrypt a block with #GNUNET_IDENTITY_PublicKey and derives a | ||
770 | * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption | ||
771 | * using ecdh to derive a symmetric key. | ||
772 | * | ||
773 | * Note that the result buffer for the ciphertext must be the length of | ||
774 | * the message to encrypt plus #GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES. | ||
775 | * | ||
776 | * @param block the block to encrypt | ||
777 | * @param size the size of the @a block | ||
778 | * @param pub public key to encrypt for | ||
779 | * @param result the output parameter in which to store the encrypted result | ||
780 | * can be the same or overlap with @c block | ||
781 | * @returns GNUNET_OK on success. | ||
782 | */ | ||
783 | enum GNUNET_GenericReturnValue | ||
784 | GNUNET_IDENTITY_encrypt (const void *block, | ||
785 | size_t size, | ||
786 | const struct GNUNET_IDENTITY_PublicKey *pub, | ||
787 | void *result, | ||
788 | size_t result_size); | ||
789 | |||
790 | |||
791 | /** | ||
792 | * Decrypt a given block with #GNUNET_IDENTITY_PrivateKey and a given | ||
793 | * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key. | ||
794 | * | ||
795 | * @param block the data to decrypt, encoded as returned by encrypt | ||
796 | * @param size the size of the @a block to decrypt | ||
797 | * @param priv private key to use for ecdh | ||
798 | * @param result address to store the result at | ||
799 | * can be the same or overlap with @c block | ||
800 | * @returns GNUNET_OK on success. | ||
801 | */ | ||
802 | enum GNUNET_GenericReturnValue | ||
803 | GNUNET_IDENTITY_decrypt (const void *block, | ||
804 | size_t size, | ||
805 | const struct GNUNET_IDENTITY_PrivateKey *priv, | ||
806 | void *result, | ||
807 | size_t result_size); | ||
808 | |||
809 | |||
810 | /** | ||
811 | * Creates a (Base32) string representation of the public key. | ||
812 | * The resulting string encodes a compacted representation of the key. | ||
813 | * See also #GNUNET_IDENTITY_key_get_length. | ||
814 | * | ||
815 | * @param key the key. | ||
816 | * @return the string representation of the key, or NULL on error. | ||
817 | */ | ||
818 | char * | ||
819 | GNUNET_IDENTITY_public_key_to_string ( | ||
820 | const struct GNUNET_IDENTITY_PublicKey *key); | ||
821 | |||
822 | |||
823 | /** | ||
824 | * Creates a (Base32) string representation of the private key. | ||
825 | * The resulting string encodes a compacted representation of the key. | ||
826 | * See also #GNUNET_IDENTITY_key_get_length. | ||
827 | * | ||
828 | * @param key the key. | ||
829 | * @return the string representation of the key, or NULL on error. | ||
830 | */ | ||
831 | char * | ||
832 | GNUNET_IDENTITY_private_key_to_string ( | ||
833 | const struct GNUNET_IDENTITY_PrivateKey *key); | ||
834 | |||
835 | |||
836 | /** | ||
837 | * Parses a (Base32) string representation of the public key. | ||
838 | * See also #GNUNET_IDENTITY_public_key_to_string. | ||
839 | * | ||
840 | * @param str the encoded key. | ||
841 | * @param key where to write the key. | ||
842 | * @return GNUNET_SYSERR on error. | ||
843 | */ | ||
844 | enum GNUNET_GenericReturnValue | ||
845 | GNUNET_IDENTITY_public_key_from_string (const char*str, | ||
846 | struct GNUNET_IDENTITY_PublicKey *key); | ||
847 | |||
848 | |||
849 | /** | ||
850 | * Parses a (Base32) string representation of the private key. | ||
851 | * See also #GNUNET_IDENTITY_private_key_to_string. | ||
852 | * | ||
853 | * @param str the encoded key. | ||
854 | * @param key where to write the key. | ||
855 | * @return GNUNET_SYSERR on error. | ||
856 | */ | ||
857 | enum GNUNET_GenericReturnValue | ||
858 | GNUNET_IDENTITY_private_key_from_string (const char*str, | ||
859 | struct GNUNET_IDENTITY_PrivateKey *key); | ||
860 | |||
861 | |||
862 | /** | ||
863 | * Retrieves the public key representation of a private key. | ||
864 | * | ||
865 | * @param privkey the private key. | ||
866 | * @param key the public key result. | ||
867 | * @return GNUNET_SYSERR on error. | ||
868 | */ | ||
869 | enum GNUNET_GenericReturnValue | ||
870 | GNUNET_IDENTITY_key_get_public (const struct | ||
871 | GNUNET_IDENTITY_PrivateKey *privkey, | ||
872 | struct GNUNET_IDENTITY_PublicKey *key); | ||
873 | |||
874 | |||
875 | /* ************* convenience API to lookup an ego ***************** */ | 312 | /* ************* convenience API to lookup an ego ***************** */ |
876 | 313 | ||
877 | /** | 314 | /** |
@@ -924,7 +361,7 @@ GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el); | |||
924 | typedef void | 361 | typedef void |
925 | (*GNUNET_IDENTITY_EgoSuffixCallback) ( | 362 | (*GNUNET_IDENTITY_EgoSuffixCallback) ( |
926 | void *cls, | 363 | void *cls, |
927 | const struct GNUNET_IDENTITY_PrivateKey *priv, | 364 | const struct GNUNET_CRYPTO_PrivateKey *priv, |
928 | const char *ego_name); | 365 | const char *ego_name); |
929 | 366 | ||
930 | 367 | ||