diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 13:37:38 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 13:37:38 +0200 |
commit | 9ef4abad615bea12d13be542b8ae5fbeb2dfee32 (patch) | |
tree | 8875a687e004d331c9ea6a1d511a328c72b88113 /src/messenger/messenger_api_message.c | |
parent | e95236b3ed78cd597c15f34b89385295702b627f (diff) | |
download | gnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.tar.gz gnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.zip |
NEWS: Refactoring components under src/ into lib/, plugin/, cli/ and service/
This also includes a necessary API refactoring of crypto from IDENTITY
to UTIL.
Diffstat (limited to 'src/messenger/messenger_api_message.c')
-rw-r--r-- | src/messenger/messenger_api_message.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c index 31d0c94b8..1f7e8dbf2 100644 --- a/src/messenger/messenger_api_message.c +++ b/src/messenger/messenger_api_message.c | |||
@@ -276,16 +276,16 @@ get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, | |||
276 | switch (kind) | 276 | switch (kind) |
277 | { | 277 | { |
278 | case GNUNET_MESSENGER_KIND_INFO: | 278 | case GNUNET_MESSENGER_KIND_INFO: |
279 | length += GNUNET_IDENTITY_public_key_get_length (&(body->info.host_key)); | 279 | length += GNUNET_CRYPTO_public_key_get_length (&(body->info.host_key)); |
280 | break; | 280 | break; |
281 | case GNUNET_MESSENGER_KIND_JOIN: | 281 | case GNUNET_MESSENGER_KIND_JOIN: |
282 | length += GNUNET_IDENTITY_public_key_get_length (&(body->join.key)); | 282 | length += GNUNET_CRYPTO_public_key_get_length (&(body->join.key)); |
283 | break; | 283 | break; |
284 | case GNUNET_MESSENGER_KIND_NAME: | 284 | case GNUNET_MESSENGER_KIND_NAME: |
285 | length += (body->name.name ? strlen (body->name.name) : 0); | 285 | length += (body->name.name ? strlen (body->name.name) : 0); |
286 | break; | 286 | break; |
287 | case GNUNET_MESSENGER_KIND_KEY: | 287 | case GNUNET_MESSENGER_KIND_KEY: |
288 | length += GNUNET_IDENTITY_public_key_get_length (&(body->key.key)); | 288 | length += GNUNET_CRYPTO_public_key_get_length (&(body->key.key)); |
289 | break; | 289 | break; |
290 | case GNUNET_MESSENGER_KIND_TEXT: | 290 | case GNUNET_MESSENGER_KIND_TEXT: |
291 | length += strlen (body->text.text); | 291 | length += strlen (body->text.text); |
@@ -313,7 +313,7 @@ get_message_size (const struct GNUNET_MESSENGER_Message *message, | |||
313 | uint16_t length = 0; | 313 | uint16_t length = 0; |
314 | 314 | ||
315 | if (GNUNET_YES == include_header) | 315 | if (GNUNET_YES == include_header) |
316 | length += GNUNET_IDENTITY_signature_get_length ( | 316 | length += GNUNET_CRYPTO_signature_get_length ( |
317 | &(message->header.signature)); | 317 | &(message->header.signature)); |
318 | 318 | ||
319 | length += get_message_kind_size (message->header.kind, include_header); | 319 | length += get_message_kind_size (message->header.kind, include_header); |
@@ -399,7 +399,7 @@ calc_padded_length (uint16_t length) | |||
399 | } while (0) | 399 | } while (0) |
400 | 400 | ||
401 | #define encode_step_key(dst, offset, src, length) do { \ | 401 | #define encode_step_key(dst, offset, src, length) do { \ |
402 | ssize_t result = GNUNET_IDENTITY_write_public_key_to_buffer ( \ | 402 | ssize_t result = GNUNET_CRYPTO_write_public_key_to_buffer ( \ |
403 | src, dst + offset, length - offset \ | 403 | src, dst + offset, length - offset \ |
404 | ); \ | 404 | ); \ |
405 | if (result < 0) \ | 405 | if (result < 0) \ |
@@ -409,7 +409,7 @@ calc_padded_length (uint16_t length) | |||
409 | } while (0) | 409 | } while (0) |
410 | 410 | ||
411 | #define encode_step_signature(dst, offset, src, length) do { \ | 411 | #define encode_step_signature(dst, offset, src, length) do { \ |
412 | ssize_t result = GNUNET_IDENTITY_write_signature_to_buffer ( \ | 412 | ssize_t result = GNUNET_CRYPTO_write_signature_to_buffer ( \ |
413 | src, dst + offset, length - offset \ | 413 | src, dst + offset, length - offset \ |
414 | ); \ | 414 | ); \ |
415 | if (result < 0) \ | 415 | if (result < 0) \ |
@@ -581,7 +581,7 @@ encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, | |||
581 | #define decode_step_key(src, offset, dst, length) do { \ | 581 | #define decode_step_key(src, offset, dst, length) do { \ |
582 | enum GNUNET_GenericReturnValue result; \ | 582 | enum GNUNET_GenericReturnValue result; \ |
583 | size_t read; \ | 583 | size_t read; \ |
584 | result = GNUNET_IDENTITY_read_public_key_from_buffer ( \ | 584 | result = GNUNET_CRYPTO_read_public_key_from_buffer ( \ |
585 | src + offset, length - offset, dst, &read \ | 585 | src + offset, length - offset, dst, &read \ |
586 | ); \ | 586 | ); \ |
587 | if (GNUNET_SYSERR == result) \ | 587 | if (GNUNET_SYSERR == result) \ |
@@ -695,7 +695,7 @@ decode_message (struct GNUNET_MESSENGER_Message *message, | |||
695 | 695 | ||
696 | if (GNUNET_YES == include_header) | 696 | if (GNUNET_YES == include_header) |
697 | { | 697 | { |
698 | ssize_t result = GNUNET_IDENTITY_read_signature_from_buffer ( | 698 | ssize_t result = GNUNET_CRYPTO_read_signature_from_buffer ( |
699 | &(message->header.signature), buffer, length - offset | 699 | &(message->header.signature), buffer, length - offset |
700 | ); | 700 | ); |
701 | 701 | ||
@@ -788,7 +788,7 @@ hash_message (const struct GNUNET_MESSENGER_Message *message, | |||
788 | { | 788 | { |
789 | GNUNET_assert ((message) && (buffer) && (hash)); | 789 | GNUNET_assert ((message) && (buffer) && (hash)); |
790 | 790 | ||
791 | const ssize_t offset = GNUNET_IDENTITY_signature_get_length ( | 791 | const ssize_t offset = GNUNET_CRYPTO_signature_get_length ( |
792 | &(message->header.signature) | 792 | &(message->header.signature) |
793 | ); | 793 | ); |
794 | 794 | ||
@@ -811,7 +811,7 @@ sign_message (struct GNUNET_MESSENGER_Message *message, | |||
811 | signature.purpose.size = htonl (sizeof(signature)); | 811 | signature.purpose.size = htonl (sizeof(signature)); |
812 | 812 | ||
813 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | 813 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); |
814 | GNUNET_IDENTITY_sign (&(ego->priv), &signature, &(message->header.signature)); | 814 | GNUNET_CRYPTO_sign (&(ego->priv), &signature, &(message->header.signature)); |
815 | 815 | ||
816 | uint16_t offset = 0; | 816 | uint16_t offset = 0; |
817 | encode_step_signature (buffer, offset, &(message->header.signature), length); | 817 | encode_step_signature (buffer, offset, &(message->header.signature), length); |
@@ -821,7 +821,7 @@ sign_message (struct GNUNET_MESSENGER_Message *message, | |||
821 | int | 821 | int |
822 | verify_message (const struct GNUNET_MESSENGER_Message *message, | 822 | verify_message (const struct GNUNET_MESSENGER_Message *message, |
823 | const struct GNUNET_HashCode *hash, | 823 | const struct GNUNET_HashCode *hash, |
824 | const struct GNUNET_IDENTITY_PublicKey *key) | 824 | const struct GNUNET_CRYPTO_PublicKey *key) |
825 | { | 825 | { |
826 | GNUNET_assert ((message) && (hash) && (key)); | 826 | GNUNET_assert ((message) && (hash) && (key)); |
827 | 827 | ||
@@ -835,7 +835,7 @@ verify_message (const struct GNUNET_MESSENGER_Message *message, | |||
835 | 835 | ||
836 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | 836 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); |
837 | 837 | ||
838 | return GNUNET_IDENTITY_signature_verify ( | 838 | return GNUNET_CRYPTO_signature_verify ( |
839 | GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature, | 839 | GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature, |
840 | &(message->header.signature), key); | 840 | &(message->header.signature), key); |
841 | } | 841 | } |
@@ -843,7 +843,7 @@ verify_message (const struct GNUNET_MESSENGER_Message *message, | |||
843 | 843 | ||
844 | int | 844 | int |
845 | encrypt_message (struct GNUNET_MESSENGER_Message *message, | 845 | encrypt_message (struct GNUNET_MESSENGER_Message *message, |
846 | const struct GNUNET_IDENTITY_PublicKey *key) | 846 | const struct GNUNET_CRYPTO_PublicKey *key) |
847 | { | 847 | { |
848 | GNUNET_assert ((message) && (key)); | 848 | GNUNET_assert ((message) && (key)); |
849 | 849 | ||
@@ -853,7 +853,7 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
853 | 853 | ||
854 | const uint16_t length = get_short_message_size (&shortened, GNUNET_YES); | 854 | const uint16_t length = get_short_message_size (&shortened, GNUNET_YES); |
855 | const uint16_t padded_length = calc_padded_length ( | 855 | const uint16_t padded_length = calc_padded_length ( |
856 | length + GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES | 856 | length + GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES |
857 | ); | 857 | ); |
858 | 858 | ||
859 | message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE; | 859 | message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE; |
@@ -861,12 +861,12 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
861 | message->body.privacy.length = padded_length; | 861 | message->body.privacy.length = padded_length; |
862 | 862 | ||
863 | const uint16_t encoded_length = ( | 863 | const uint16_t encoded_length = ( |
864 | padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES | 864 | padded_length - GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES |
865 | ); | 865 | ); |
866 | 866 | ||
867 | encode_short_message (&shortened, encoded_length, message->body.privacy.data); | 867 | encode_short_message (&shortened, encoded_length, message->body.privacy.data); |
868 | 868 | ||
869 | if (GNUNET_OK != GNUNET_IDENTITY_encrypt (message->body.privacy.data, | 869 | if (GNUNET_OK != GNUNET_CRYPTO_encrypt (message->body.privacy.data, |
870 | encoded_length, | 870 | encoded_length, |
871 | key, | 871 | key, |
872 | message->body.privacy.data, | 872 | message->body.privacy.data, |
@@ -885,13 +885,13 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
885 | 885 | ||
886 | int | 886 | int |
887 | decrypt_message (struct GNUNET_MESSENGER_Message *message, | 887 | decrypt_message (struct GNUNET_MESSENGER_Message *message, |
888 | const struct GNUNET_IDENTITY_PrivateKey *key) | 888 | const struct GNUNET_CRYPTO_PrivateKey *key) |
889 | { | 889 | { |
890 | GNUNET_assert ((message) && (key)); | 890 | GNUNET_assert ((message) && (key)); |
891 | 891 | ||
892 | const uint16_t padded_length = message->body.privacy.length; | 892 | const uint16_t padded_length = message->body.privacy.length; |
893 | 893 | ||
894 | if (padded_length < GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES) | 894 | if (padded_length < GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES) |
895 | { | 895 | { |
896 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 896 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
897 | "Message length too short to decrypt!\n"); | 897 | "Message length too short to decrypt!\n"); |
@@ -900,10 +900,10 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
900 | } | 900 | } |
901 | 901 | ||
902 | const uint16_t encoded_length = ( | 902 | const uint16_t encoded_length = ( |
903 | padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES | 903 | padded_length - GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES |
904 | ); | 904 | ); |
905 | 905 | ||
906 | if (GNUNET_OK != GNUNET_IDENTITY_decrypt (message->body.privacy.data, | 906 | if (GNUNET_OK != GNUNET_CRYPTO_decrypt (message->body.privacy.data, |
907 | padded_length, | 907 | padded_length, |
908 | key, | 908 | key, |
909 | message->body.privacy.data, | 909 | message->body.privacy.data, |