GNUnet 0.28.0-dev.2-27-gc87478450
 
Loading...
Searching...
No Matches
messenger_api_message.c File Reference
#include "messenger_api_message.h"
#include "gnunet_common.h"
#include "gnunet_messenger_service.h"
#include "gnunet_pils_service.h"
#include "gnunet_signatures.h"
#include "gnunet_util_lib.h"
#include <unistd.h>
Include dependency graph for messenger_api_message.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MessageSignature
 
struct  GNUNET_MESSENGER_ShortMessage
 

Macros

#define member_size(type, member)   sizeof(((type*) NULL)->member)
 
#define max(x, y)   (x > y? x : y)
 
#define min(x, y)   (x < y? x : y)
 
#define encode_step_ext(dst, offset, src, size)
 
#define encode_step(dst, offset, src)
 
#define encode_step_key(dst, offset, src, length)
 
#define encode_step_hpke_key(dst, offset, src, length)
 
#define encode_step_signature(dst, offset, src, length)
 
#define decode_step_ext(src, offset, dst, size)
 
#define decode_step(src, offset, dst)
 
#define decode_step_malloc(src, offset, dst, size, zero)
 
#define decode_step_key(src, offset, dst, length)
 
#define decode_step_hpke_key(src, offset, dst, length)
 

Typedefs

typedef uint32_t kind_t
 

Functions

struct GNUNET_MESSENGER_Messagecreate_message (enum GNUNET_MESSENGER_MessageKind kind)
 Creates and allocates a new message with a specific kind.
 
struct GNUNET_MESSENGER_Messagecopy_message (const struct GNUNET_MESSENGER_Message *message)
 Creates and allocates a copy of a given message.
 
void copy_message_header (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_MessageHeader *header)
 Copy message header details from another message to a given message.
 
static void destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
 
void cleanup_message (struct GNUNET_MESSENGER_Message *message)
 Frees the messages body memory.
 
void destroy_message (struct GNUNET_MESSENGER_Message *message)
 Destroys a message and frees its memory fully.
 
enum GNUNET_GenericReturnValue is_message_session_bound (const struct GNUNET_MESSENGER_Message *message)
 Returns if the message should be bound to a member session.
 
static void fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
 
static void unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
 
static uint16_t get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind)
 
uint16_t get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
 Returns the minimal size in bytes to encode a message of a specific kind.
 
static uint16_t get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
 
uint16_t get_message_size (const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
 Returns the exact size in bytes to encode a given message.
 
static uint16_t get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)
 
static uint16_t calc_usual_padding ()
 
static uint16_t calc_padded_length (uint16_t length)
 
static void encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
 
void encode_message_signature (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
 Encodes the signature of a given message into a buffer of a maximum length in bytes.
 
void encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
 Encodes a given message into a buffer of a maximum length in bytes.
 
static void encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
 
static uint16_t decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)
 
enum GNUNET_GenericReturnValue decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
 Decodes a message from a given buffer of a maximum length in bytes.
 
static enum GNUNET_GenericReturnValue decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
 
void hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
 Calculates a hash of a given buffer with a length in bytes from a message.
 
void sign_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
 Signs the hash of a message with a given private key.
 
struct GNUNET_PILS_Operationsign_message_by_peer (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, struct GNUNET_PILS_Handle *pils, const GNUNET_PILS_SignResultCallback sign_cb, void *cls)
 Signs the hash of a message with the peer identity of a given pils service going into a callback with a custom closure on success.
 
static enum GNUNET_GenericReturnValue calc_message_hmac (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key, struct GNUNET_HashCode *hmac)
 
enum GNUNET_GenericReturnValue sign_message_by_key (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key)
 Signs the message body via it's own hmac with a specific shared key.
 
enum GNUNET_GenericReturnValue verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
 Verifies the signature of a given message and its hash with a specific public key.
 
enum GNUNET_GenericReturnValue verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_PeerIdentity *identity)
 Verifies the signature of a given message and its hash with a specific peer's identity.
 
enum GNUNET_GenericReturnValue verify_message_by_key (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key)
 Verifies the hmac of a given message body with a specific shared key.
 
enum GNUNET_GenericReturnValue encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
 Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message.
 
enum GNUNET_GenericReturnValue decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
 Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message.
 
struct GNUNET_MESSENGER_Messagetranscribe_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
 Transcribes a message as a new transcript message using a given public key from the recipient of the encrypted message content.
 
enum GNUNET_GenericReturnValue encrypt_secret_message (struct GNUNET_MESSENGER_Message *message, const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_AeadSecretKey *key)
 Encrypts a message using a given shared key from an announcement of an epoch and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue decrypt_secret_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key)
 Decrypts a secret message using a given shared key and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue read_transcript_message (struct GNUNET_MESSENGER_Message *message)
 Read the original message from a transcript message and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue extract_access_message_key (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *key, struct GNUNET_CRYPTO_AeadSecretKey *shared_key)
 Extracts the shared epoch or group key from an access message using the private ephemeral key from an epoch and verifies it via the HMAC from the message body.
 
enum GNUNET_GenericReturnValue extract_authorization_message_key (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key, struct GNUNET_CRYPTO_AeadSecretKey *shared_key)
 Extracts the shared epoch or group key from an authorization message using a previously exchanged shared key and verifies it via the HMAC from the message body.
 
struct GNUNET_TIME_Relative get_message_timeout (const struct GNUNET_MESSENGER_Message *message)
 Return the relative timeout of the content from a given message that controls when a delayed handling action of this message needs to be processed at least.
 
struct GNUNET_MQ_Envelopepack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_PackMode mode)
 Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE.
 
enum GNUNET_GenericReturnValue is_peer_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message can be sent by the service without usage of a clients private key.
 
enum GNUNET_GenericReturnValue is_service_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message contains service critical information.
 
enum GNUNET_GenericReturnValue is_epoch_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a certain kind of message from storage contains some specific details that might be required for the overall message graph to function as intended.
 
enum GNUNET_GenericReturnValue filter_message_sending (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message should be sent by a client.
 
const struct GNUNET_ShortHashCodeget_message_discourse (const struct GNUNET_MESSENGER_Message *message)
 Returns the discourse hash of a message depending on its kind.
 

Variables

const uint16_t encryption_overhead
 

Macro Definition Documentation

◆ member_size

#define member_size (   type,
  member 
)    sizeof(((type*) NULL)->member)

Definition at line 304 of file messenger_api_message.c.

◆ max

#define max (   x,
 
)    (x > y? x : y)

Definition at line 593 of file messenger_api_message.c.

◆ min

#define min (   x,
 
)    (x < y? x : y)

Definition at line 622 of file messenger_api_message.c.

◆ encode_step_ext

#define encode_step_ext (   dst,
  offset,
  src,
  size 
)
Value:
do { \
GNUNET_memcpy (dst + offset, src, size); \
offset += size; \
} while (0)
static unsigned int size
Size of the "table".
Definition peer.c:68

Definition at line 624 of file messenger_api_message.c.

624 { \
625 GNUNET_memcpy (dst + offset, src, size); \
626 offset += size; \
627} while (0)

◆ encode_step

#define encode_step (   dst,
  offset,
  src 
)
Value:
do { \
encode_step_ext (dst, offset, src, sizeof(*src)); \
} while (0)

Definition at line 629 of file messenger_api_message.c.

629 { \
630 encode_step_ext (dst, offset, src, sizeof(*src)); \
631} while (0)

◆ encode_step_key

#define encode_step_key (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
static int result
Global testing status.
ssize_t GNUNET_CRYPTO_write_blindable_pk_to_buffer(const struct GNUNET_CRYPTO_BlindablePublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_BlindablePublicKey to a compact buffer.

Definition at line 633 of file messenger_api_message.c.

633 { \
635 src, dst + offset, length - offset); \
636 if (result < 0) \
637 GNUNET_break (0); \
638 else \
639 offset += result; \
640} while (0)

◆ encode_step_hpke_key

#define encode_step_hpke_key (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
ssize_t GNUNET_CRYPTO_write_hpke_pk_to_buffer(const struct GNUNET_CRYPTO_HpkePublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_HpkePublicKey to a compact buffer.

Definition at line 642 of file messenger_api_message.c.

642 { \
644 src, dst + offset, length - offset); \
645 if (result < 0) \
646 GNUNET_break (0); \
647 else \
648 offset += result; \
649} while (0)

◆ encode_step_signature

#define encode_step_signature (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
ssize_t GNUNET_CRYPTO_write_blinded_key_signature_to_buffer(const struct GNUNET_CRYPTO_BlindableKeySignature *sig, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_BlindableKeySignature to a compact buffer.

Definition at line 651 of file messenger_api_message.c.

651 { \
653 src, dst + offset, length - offset); \
654 if (result < 0) \
655 GNUNET_break (0); \
656 else \
657 offset += result; \
658} while (0)

◆ decode_step_ext

#define decode_step_ext (   src,
  offset,
  dst,
  size 
)
Value:
do { \
GNUNET_memcpy (dst, src + offset, size); \
offset += size; \
} while (0)

Definition at line 936 of file messenger_api_message.c.

936 { \
937 GNUNET_memcpy (dst, src + offset, size); \
938 offset += size; \
939} while (0)

◆ decode_step

#define decode_step (   src,
  offset,
  dst 
)
Value:
do { \
decode_step_ext (src, offset, dst, sizeof(*dst)); \
} while (0)

Definition at line 941 of file messenger_api_message.c.

941 { \
942 decode_step_ext (src, offset, dst, sizeof(*dst)); \
943} while (0)

◆ decode_step_malloc

#define decode_step_malloc (   src,
  offset,
  dst,
  size,
  zero 
)
Value:
do { \
dst = GNUNET_malloc (size + zero); \
if (zero) dst[size] = 0; \
decode_step_ext (src, offset, dst, size); \
} while (0)
static const struct GNUNET_CRYPTO_BlindablePrivateKey zero
Public key of all zeros.
#define GNUNET_malloc(size)
Wrapper around malloc.

Definition at line 945 of file messenger_api_message.c.

945 { \
946 dst = GNUNET_malloc (size + zero); \
947 if (zero) dst[size] = 0; \
948 decode_step_ext (src, offset, dst, size); \
949} while (0)

◆ decode_step_key

#define decode_step_key (   src,
  offset,
  dst,
  length 
)
Value:
do { \
size_t read; \
src + offset, length - offset, dst, &read); \
GNUNET_break (0); \
else \
offset += read; \
} while (0)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_blindable_pk_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_BlindablePublicKey *key, size_t *read)
Reads a GNUNET_CRYPTO_BlindablePublicKey from a compact buffer.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR

Definition at line 951 of file messenger_api_message.c.

951 { \
953 size_t read; \
955 src + offset, length - offset, dst, &read); \
956 if (GNUNET_SYSERR == result) \
957 GNUNET_break (0); \
958 else \
959 offset += read; \
960} while (0)

◆ decode_step_hpke_key

#define decode_step_hpke_key (   src,
  offset,
  dst,
  length 
)
Value:
do { \
size_t read; \
src + offset, length - offset, dst, &read); \
GNUNET_break (0); \
else \
offset += read; \
} while (0)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_hpke_pk_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_HpkePublicKey *key, size_t *read)
Reads a GNUNET_CRYPTO_HpkePublicKey from a compact buffer.

Definition at line 962 of file messenger_api_message.c.

962 { \
964 size_t read; \
966 src + offset, length - offset, dst, &read); \
967 if (GNUNET_SYSERR == result) \
968 GNUNET_break (0); \
969 else \
970 offset += read; \
971} while (0)

Typedef Documentation

◆ kind_t

typedef uint32_t kind_t

Definition at line 457 of file messenger_api_message.c.

Function Documentation

◆ create_message()

struct GNUNET_MESSENGER_Message * create_message ( enum GNUNET_MESSENGER_MessageKind  kind)

Creates and allocates a new message with a specific kind.

Parameters
[in]kindKind of message
Returns
New message

Definition at line 52 of file messenger_api_message.c.

53{
54 struct GNUNET_MESSENGER_Message *message;
55
56 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
57 message->header.kind = kind;
58
59 switch (message->header.kind)
60 {
62 message->body.name.name = NULL;
63 break;
65 message->body.text.text = NULL;
66 break;
68 message->body.file.uri = NULL;
69 break;
71 message->body.privacy.length = 0;
72 message->body.privacy.data = NULL;
73 break;
75 message->body.ticket.identifier = NULL;
76 break;
78 message->body.transcript.length = 0;
79 message->body.transcript.data = NULL;
80 break;
82 message->body.tag.tag = NULL;
83 break;
85 message->body.talk.length = 0;
86 message->body.talk.data = NULL;
87 break;
89 message->body.secret.length = 0;
90 message->body.secret.data = NULL;
91 break;
92 default:
93 break;
94 }
95
96 return message;
97}
#define GNUNET_new(type)
Allocate a struct or union of the given type.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_TAG
The tag kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_TRANSCRIPT
The transcript kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_SECRET
The secret kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
struct GNUNET_MESSENGER_MessageSecret secret
struct GNUNET_MESSENGER_MessagePrivate privacy
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_MESSENGER_MessageTalk talk
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageTag tag
struct GNUNET_MESSENGER_MessageTicket ticket
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
char * name
The new name which replaces the current senders name.
uint16_t length
The length of the encrypted message.
char * data
The data of the encrypted message.
char * data
The data of the encrypted message.
uint16_t length
The length of the encrypted message.
uint16_t length
The length of the talk message data.
char * data
The data of the talk message.
char * identifier
The identifier of a ticket.
uint16_t length
The length of the transcribed message.
char * data
The data of the transcribed message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by create_message_access(), create_message_announcement(), create_message_appeal(), create_message_authorization(), create_message_connection(), create_message_deletion(), create_message_group(), create_message_id(), create_message_info(), create_message_join(), create_message_key(), create_message_leave(), create_message_merge(), create_message_miss(), create_message_name(), create_message_peer(), create_message_request(), create_message_revolution(), create_message_subscription(), get_store_message(), and transcribe_message().

Here is the caller graph for this function:

◆ copy_message()

struct GNUNET_MESSENGER_Message * copy_message ( const struct GNUNET_MESSENGER_Message message)

Creates and allocates a copy of a given message.

Parameters
[in]messageMessage
Returns
New message

Definition at line 101 of file messenger_api_message.c.

102{
103 struct GNUNET_MESSENGER_Message *copy;
104
105 GNUNET_assert (message);
106
107 copy = GNUNET_new (struct GNUNET_MESSENGER_Message);
108 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
109
110 switch (message->header.kind)
111 {
113 copy->body.name.name = message->body.name.name? GNUNET_strdup (
114 message->body.name.name) : NULL;
115 break;
117 copy->body.text.text = message->body.text.text? GNUNET_strdup (
118 message->body.text.text) : NULL;
119 break;
121 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
122 message->body.file.uri) : NULL;
123 break;
126 copy->body.privacy.length) : NULL;
127
128 if (copy->body.privacy.data)
129 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
130 copy->body.privacy.length);
131
132 break;
134 copy->body.ticket.identifier = message->body.ticket.identifier?
136 message->body.ticket.identifier) : NULL;
137 break;
140 copy->body.transcript.length) : NULL;
141
142 if (copy->body.transcript.data)
144 copy->body.transcript.length);
145
146 break;
148 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
149 message->body.tag.tag) : NULL;
150 break;
152 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
153 copy->body.talk.length) : NULL;
154
155 if (copy->body.talk.data)
156 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
157 copy->body.talk.length);
158
159 break;
161 copy->body.secret.data = copy->body.secret.length ? GNUNET_malloc (
162 copy->body.secret.length) : NULL;
163
164 if (copy->body.secret.data)
165 GNUNET_memcpy (copy->body.secret.data, message->body.secret.data,
166 copy->body.secret.length);
167
168 break;
169 default:
170 break;
171 }
172
173 return copy;
174}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_assert, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_strdup, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by enqueue_message_control(), forward_tunnel_message(), GNUNET_MESSENGER_send_message(), handle_private_message(), handle_room_message(), handle_transcript_message(), handle_tunnel_message(), send_srv_handle_message(), and update_room_secret_message().

Here is the caller graph for this function:

◆ copy_message_header()

void copy_message_header ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_MESSENGER_MessageHeader header 
)

Copy message header details from another message to a given message.

Parameters
[in,out]messageMessage
[in]headerMessage header

Definition at line 178 of file messenger_api_message.c.

180{
182
183 GNUNET_assert ((message) && (header));
184
185 kind = message->header.kind;
186
187 GNUNET_memcpy (&(message->header), header,
188 sizeof(struct GNUNET_MESSENGER_MessageHeader));
189
190 message->header.kind = kind;
191}
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
The header of a GNUNET_MESSENGER_Message.

References GNUNET_assert, GNUNET_memcpy, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by handle_room_message(), and handle_transcript_message().

Here is the caller graph for this function:

◆ destroy_message_body()

static void destroy_message_body ( enum GNUNET_MESSENGER_MessageKind  kind,
struct GNUNET_MESSENGER_MessageBody body 
)
static

Definition at line 195 of file messenger_api_message.c.

197{
198 GNUNET_assert (body);
199
200 switch (kind)
201 {
203 if (body->name.name)
204 GNUNET_free (body->name.name);
205 break;
207 if (body->text.text)
208 GNUNET_free (body->text.text);
209 break;
211 if (body->file.uri)
212 GNUNET_free (body->file.uri);
213 break;
215 if (body->privacy.data)
216 GNUNET_free (body->privacy.data);
217 break;
219 if (body->ticket.identifier)
221 break;
223 if (body->transcript.data)
225 break;
227 if (body->tag.tag)
228 GNUNET_free (body->tag.tag);
229 break;
231 if (body->talk.data)
232 GNUNET_free (body->talk.data);
233 break;
235 if (body->secret.data)
236 GNUNET_free (body->secret.data);
237 break;
238 default:
239 break;
240 }
241}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_assert, GNUNET_free, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by cleanup_message(), destroy_message(), encrypt_message(), encrypt_secret_message(), and unfold_short_message().

Here is the caller graph for this function:

◆ cleanup_message()

void cleanup_message ( struct GNUNET_MESSENGER_Message message)

Frees the messages body memory.

Parameters
[in,out]messageMessage

Definition at line 245 of file messenger_api_message.c.

246{
247 GNUNET_assert (message);
248
249 destroy_message_body (message->header.kind, &(message->body));
250}
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)

References GNUNET_MESSENGER_Message::body, destroy_message_body(), GNUNET_assert, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by check_recv_message(), check_send_message(), handle_recv_message(), handle_send_message(), and handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_message()

void destroy_message ( struct GNUNET_MESSENGER_Message message)

Destroys a message and frees its memory fully.

Parameters
[in,out]messageMessage

Definition at line 254 of file messenger_api_message.c.

255{
256 GNUNET_assert (message);
257
258 destroy_message_body (message->header.kind, &(message->body));
259
260 GNUNET_free (message);
261}

References GNUNET_MESSENGER_Message::body, destroy_message_body(), GNUNET_assert, GNUNET_free, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by callback_tunnel_message_signed(), clear_queue_messages(), create_message_access(), create_message_announcement(), create_message_authorization(), create_message_peer(), create_message_revolution(), dequeue_from_messages(), dequeue_message_from_room(), destroy_message_control(), enqueue_to_messages(), forward_tunnel_message(), get_store_message(), handle_discourse_subscription(), handle_private_message(), handle_room_delayed_deletion(), handle_transcript_message(), iterate_cancel_signature(), iterate_destroy_message(), iterate_destroy_messages(), iterate_destroy_subscription(), iterate_flag_for_cleanup_discourse_message(), keep_subscription_alive(), send_message_to_room_with_key(), sign_srv_room_message(), task_message_control(), update_room_message(), and update_room_secret_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_message_session_bound()

enum GNUNET_GenericReturnValue is_message_session_bound ( const struct GNUNET_MESSENGER_Message message)

Returns if the message should be bound to a member session.

Parameters
[in]messageMessage
Returns
GNUNET_YES or GNUNET_NO

Definition at line 265 of file messenger_api_message.c.

266{
267 GNUNET_assert (message);
268
269 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
271 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
272 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
274 return GNUNET_YES;
275 else
276 return GNUNET_NO;
277}
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.

References GNUNET_assert, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_NAME, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by enqueue_message_to_room(), and update_member_session_history().

Here is the caller graph for this function:

◆ fold_short_message()

static void fold_short_message ( const struct GNUNET_MESSENGER_Message message,
struct GNUNET_MESSENGER_ShortMessage shortened 
)
static

Definition at line 281 of file messenger_api_message.c.

283{
284 shortened->kind = message->header.kind;
285
286 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
288}
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageBody body
enum GNUNET_MESSENGER_MessageKind kind

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, GNUNET_memcpy, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by encrypt_message(), encrypt_secret_message(), and transcribe_message().

Here is the caller graph for this function:

◆ unfold_short_message()

static void unfold_short_message ( struct GNUNET_MESSENGER_ShortMessage shortened,
struct GNUNET_MESSENGER_Message message 
)
static

Definition at line 292 of file messenger_api_message.c.

294{
295 destroy_message_body (message->header.kind, &(message->body));
296
297 message->header.kind = shortened->kind;
298
299 GNUNET_memcpy (&(message->body), &(shortened->body),
300 sizeof(struct GNUNET_MESSENGER_MessageBody));
301}

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, destroy_message_body(), GNUNET_memcpy, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decrypt_message(), decrypt_secret_message(), encrypt_message(), encrypt_secret_message(), and read_transcript_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_body_kind_size()

static uint16_t get_message_body_kind_size ( enum GNUNET_MESSENGER_MessageKind  kind)
static

Definition at line 307 of file messenger_api_message.c.

308{
309 uint16_t length;
310
311 length = 0;
312
313 switch (kind)
314 {
316 length += member_size (struct GNUNET_MESSENGER_Message,
317 body.info.messenger_version);
318 break;
320 length += member_size (struct GNUNET_MESSENGER_Message,
321 body.join.epoch);
322 break;
324 length += member_size (struct GNUNET_MESSENGER_Message,
325 body.leave.epoch);
326 break;
328 length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer);
329 break;
331 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
332 break;
334 length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer);
335 break;
337 length += member_size (struct GNUNET_MESSENGER_Message,
338 body.merge.epochs[0]);
339 length += member_size (struct GNUNET_MESSENGER_Message,
340 body.merge.epochs[1]);
341 length += member_size (struct GNUNET_MESSENGER_Message,
342 body.merge.previous);
343 break;
345 length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash);
346 break;
348 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door);
349 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key);
350 break;
352 length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash);
353 length += member_size (struct GNUNET_MESSENGER_Message, body.file.name);
354 break;
356 length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash);
357 length += member_size (struct GNUNET_MESSENGER_Message,
358 body.deletion.delay);
359 break;
361 length += member_size (struct GNUNET_MESSENGER_Message,
362 body.connection.amount);
363 length += member_size (struct GNUNET_MESSENGER_Message,
364 body.connection.flags);
365 break;
367 length += member_size (struct GNUNET_MESSENGER_Message,
368 body.transcript.hash);
369 break;
371 length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash);
372 break;
374 length += member_size (struct GNUNET_MESSENGER_Message,
375 body.subscription.discourse);
376 length += member_size (struct GNUNET_MESSENGER_Message,
377 body.subscription.time);
378 length += member_size (struct GNUNET_MESSENGER_Message,
379 body.subscription.flags);
380 break;
382 length += member_size (struct GNUNET_MESSENGER_Message,
383 body.talk.discourse);
384 break;
386 length += member_size (struct GNUNET_MESSENGER_Message,
387 body.announcement.identifier);
388 length += member_size (struct GNUNET_MESSENGER_Message,
389 body.announcement.key);
390 length += member_size (struct GNUNET_MESSENGER_Message,
391 body.announcement.nonce);
392 length += member_size (struct GNUNET_MESSENGER_Message,
393 body.announcement.timeout);
394 length += member_size (struct GNUNET_MESSENGER_Message,
395 body.announcement.hmac);
396 break;
398 length += member_size (struct GNUNET_MESSENGER_Message,
399 body.secret.identifier);
400 length += member_size (struct GNUNET_MESSENGER_Message,
401 body.secret.iv);
402 length += member_size (struct GNUNET_MESSENGER_Message,
403 body.secret.mac);
404 break;
406 length += member_size (struct GNUNET_MESSENGER_Message,
407 body.appeal.event);
408 length += member_size (struct GNUNET_MESSENGER_Message,
409 body.appeal.key);
410 length += member_size (struct GNUNET_MESSENGER_Message,
411 body.appeal.timeout);
412 break;
414 length += member_size (struct GNUNET_MESSENGER_Message,
415 body.access.event);
416 length += member_size (struct GNUNET_MESSENGER_Message,
417 body.access.key);
418 length += member_size (struct GNUNET_MESSENGER_Message,
419 body.access.hmac);
420 break;
422 length += member_size (struct GNUNET_MESSENGER_Message,
423 body.revolution.identifier);
424 length += member_size (struct GNUNET_MESSENGER_Message,
425 body.revolution.nonce);
426 length += member_size (struct GNUNET_MESSENGER_Message,
427 body.revolution.hmac);
428 break;
430 length += member_size (struct GNUNET_MESSENGER_Message,
431 body.group.identifier);
432 length += member_size (struct GNUNET_MESSENGER_Message,
433 body.group.initiator);
434 length += member_size (struct GNUNET_MESSENGER_Message,
435 body.group.partner);
436 length += member_size (struct GNUNET_MESSENGER_Message,
437 body.group.timeout);
438 break;
440 length += member_size (struct GNUNET_MESSENGER_Message,
441 body.authorization.identifier);
442 length += member_size (struct GNUNET_MESSENGER_Message,
443 body.authorization.event);
444 length += member_size (struct GNUNET_MESSENGER_Message,
445 body.authorization.key);
446 length += member_size (struct GNUNET_MESSENGER_Message,
447 body.authorization.hmac);
448 break;
449 default:
450 break;
451 }
452
453 return length;
454}
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_AUTHORIZATION
The authorization kind.
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
@ GNUNET_MESSENGER_KIND_APPEAL
The appeal kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_ACCESS
The access kind.
@ GNUNET_MESSENGER_KIND_REVOLUTION
The revolution kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_GROUP
The group kind.
#define member_size(type, member)

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::appeal, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessageDeletion::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageJoin::epoch, GNUNET_MESSENGER_MessageLeave::epoch, GNUNET_MESSENGER_MessageMerge::epochs, GNUNET_MESSENGER_MessageAppeal::event, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribtion::flags, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageBody::group, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDeletion::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageGroup::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageGroup::initiator, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageSecret::iv, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageAnnouncement::key, GNUNET_MESSENGER_MessageAppeal::key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageBody::leave, GNUNET_MESSENGER_MessageSecret::mac, member_size, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, GNUNET_MESSENGER_MessageGroup::partner, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::revolution, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageBody::subscription, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageSubscribtion::time, GNUNET_MESSENGER_MessageAnnouncement::timeout, GNUNET_MESSENGER_MessageAppeal::timeout, GNUNET_MESSENGER_MessageGroup::timeout, and GNUNET_MESSENGER_MessageBody::transcript.

Referenced by get_message_kind_size(), and get_short_message_size().

Here is the caller graph for this function:

◆ get_message_kind_size()

uint16_t get_message_kind_size ( enum GNUNET_MESSENGER_MessageKind  kind,
enum GNUNET_GenericReturnValue  include_header 
)

Returns the minimal size in bytes to encode a message of a specific kind.

Parameters
[in]kindKind of message
[in]include_headerFlag to include header
Returns
Minimal size to encode

Definition at line 460 of file messenger_api_message.c.

462{
463 uint16_t length;
464
465 length = 0;
466
467 if (GNUNET_YES == include_header)
468 {
469 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
470 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
471 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
472 }
473
474 length += sizeof(kind_t);
475
476 return length + get_message_body_kind_size (kind);
477}
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
uint32_t kind_t

References get_message_body_kind_size(), GNUNET_YES, GNUNET_MESSENGER_Message::header, member_size, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by calc_usual_padding(), check_recv_message(), check_send_message(), check_tunnel_message(), decode_message(), get_message_size(), and get_store_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_body_size()

static uint16_t get_message_body_size ( enum GNUNET_MESSENGER_MessageKind  kind,
const struct GNUNET_MESSENGER_MessageBody body 
)
static

Definition at line 481 of file messenger_api_message.c.

483{
484 uint16_t length;
485
486 length = 0;
487
488 switch (kind)
489 {
493 break;
495 length += (body->name.name ? strlen (body->name.name) : 0);
496 break;
498 length += GNUNET_CRYPTO_blindable_pk_get_length (&(body->key.key));
499 length += GNUNET_CRYPTO_hpke_pk_get_length (&(body->key.hpke_key));
500 break;
502 length += (body->text.text ? strlen (body->text.text) : 0);
503 break;
505 length += (body->file.uri ? strlen (body->file.uri) : 0);
506 break;
508 length += body->privacy.length;
509 break;
511 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
512 break;
515 length += body->transcript.length;
516 break;
518 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
519 break;
521 length += body->talk.length;
522 break;
524 length += body->secret.length;
525 break;
526 default:
527 break;
528 }
529
530 return length;
531}
ssize_t GNUNET_CRYPTO_hpke_pk_get_length(const struct GNUNET_CRYPTO_HpkePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_HpkePublicKey.
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
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_CRYPTO_BlindablePublicKey key
The senders blindable public key to verify its signatures.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The senders HPKE public key to encrypt private messages with.
struct GNUNET_CRYPTO_BlindablePublicKey key
The new blindable public key which replaces the current senders public key.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The new HPKE public key which replaces the current senders HPKE public key.
struct GNUNET_CRYPTO_BlindablePublicKey key
The key from the recipient of the original message.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageBody::file, GNUNET_CRYPTO_blindable_pk_get_length(), GNUNET_CRYPTO_hpke_pk_get_length(), GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageJoin::hpke_key, GNUNET_MESSENGER_MessageKey::hpke_key, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by get_message_size(), and get_short_message_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_size()

uint16_t get_message_size ( const struct GNUNET_MESSENGER_Message message,
enum GNUNET_GenericReturnValue  include_header 
)

Returns the exact size in bytes to encode a given message.

Parameters
[in]messageMessage
[in]include_headerFlag to include header
Returns
Size to encode

Definition at line 535 of file messenger_api_message.c.

537{
538 uint16_t length;
539
540 GNUNET_assert (message);
541
542 length = 0;
543
544 if (GNUNET_YES == include_header)
546 &(message->header.signature));
547
548 length += get_message_kind_size (message->header.kind, include_header);
549 length += get_message_body_size (message->header.kind, &(message->body));
550
551 return length;
552}
ssize_t GNUNET_CRYPTO_blinded_key_signature_get_length(const struct GNUNET_CRYPTO_BlindableKeySignature *sig)
Get the compacted length of a #GNUNET_CRYPTO_Signature.
static uint16_t get_message_body_size(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
struct GNUNET_CRYPTO_BlindableKeySignature signature
The signature of the senders private key.

References GNUNET_MESSENGER_Message::body, get_message_body_size(), get_message_kind_size(), GNUNET_assert, GNUNET_CRYPTO_blinded_key_signature_get_length(), GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_MessageHeader::signature.

Referenced by iterate_save_messages(), notify_srv_handle_message(), pack_message(), and send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_short_message_size()

static uint16_t get_short_message_size ( const struct GNUNET_MESSENGER_ShortMessage message,
enum GNUNET_GenericReturnValue  include_body 
)
static

Definition at line 556 of file messenger_api_message.c.

558{
559 uint16_t minimum_size;
560
561 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
562
563 if (message)
564 return minimum_size + get_message_body_kind_size (message->kind)
565 + (include_body == GNUNET_YES?
566 get_message_body_size (message->kind, &(message->body)) : 0);
567 else
568 return minimum_size;
569}
A 512-bit hashcode.

References GNUNET_MESSENGER_ShortMessage::body, get_message_body_kind_size(), get_message_body_size(), GNUNET_YES, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decode_short_message(), encrypt_message(), encrypt_secret_message(), and transcribe_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_usual_padding()

static uint16_t calc_usual_padding ( )
static

Definition at line 573 of file messenger_api_message.c.

574{
575 uint16_t padding;
576 uint16_t kind_size;
577
578 padding = 0;
579
580 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
581 {
583 GNUNET_YES);
584
585 if (kind_size > padding)
586 padding = kind_size;
587 }
588
589 return padding + GNUNET_MESSENGER_PADDING_MIN;
590}
#define GNUNET_MESSENGER_KIND_MAX
#define GNUNET_MESSENGER_PADDING_MIN

References get_message_kind_size(), GNUNET_MESSENGER_KIND_MAX, GNUNET_MESSENGER_PADDING_MIN, and GNUNET_YES.

Referenced by calc_padded_length().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_padded_length()

static uint16_t calc_padded_length ( uint16_t  length)
static

Definition at line 596 of file messenger_api_message.c.

597{
598 static uint16_t usual_padding = 0;
599 uint16_t padded_length;
600
601 if (! usual_padding)
602 usual_padding = calc_usual_padding ();
603
604 padded_length = max (
606 usual_padding);
607
608 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
610
611 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
613
614 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
616
618
619}
static uint16_t calc_usual_padding()
#define max(x, y)
#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE
#define GNUNET_MESSENGER_PADDING_LEVEL0
#define GNUNET_MESSENGER_PADDING_LEVEL2
#define GNUNET_MESSENGER_PADDING_LEVEL1

References calc_usual_padding(), GNUNET_MESSENGER_MAX_MESSAGE_SIZE, GNUNET_MESSENGER_PADDING_LEVEL0, GNUNET_MESSENGER_PADDING_LEVEL1, GNUNET_MESSENGER_PADDING_LEVEL2, GNUNET_MESSENGER_PADDING_MIN, and max.

Referenced by encrypt_message(), encrypt_secret_message(), and pack_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_message_body()

static void encode_message_body ( enum GNUNET_MESSENGER_MessageKind  kind,
const struct GNUNET_MESSENGER_MessageBody body,
uint16_t  length,
char *  buffer,
uint16_t  offset 
)
static

Definition at line 661 of file messenger_api_message.c.

666{
667 uint32_t value0, value1;
668
669 GNUNET_assert ((body) && (buffer));
670
671 switch (kind)
672 {
674 value0 = GNUNET_htobe32 (body->info.messenger_version);
675
676 encode_step (buffer, offset, &value0);
677 break;
679 encode_step (buffer, offset, &(body->join.epoch));
680 encode_step_key (buffer, offset, &(body->join.key), length);
681 encode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
682 break;
684 encode_step (buffer, offset, &(body->leave.epoch));
685 break;
687 if (body->name.name)
689 buffer,
690 offset,
691 body->name.name,
692 min (length - offset, strlen (body->name.name)));
693 break;
695 encode_step_key (buffer, offset, &(body->key.key), length);
696 encode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
697 break;
699 encode_step (buffer, offset, &(body->peer.peer));
700 break;
702 encode_step (buffer, offset, &(body->id.id));
703 break;
705 encode_step (buffer, offset, &(body->miss.peer));
706 break;
708 encode_step (buffer, offset, &(body->merge.epochs[0]));
709 encode_step (buffer, offset, &(body->merge.epochs[1]));
710 encode_step (buffer, offset, &(body->merge.previous));
711 break;
713 encode_step (buffer, offset, &(body->request.hash));
714 break;
716 encode_step (buffer, offset, &(body->invite.door));
717 encode_step (buffer, offset, &(body->invite.key));
718 break;
720 if (body->text.text)
722 buffer,
723 offset,
724 body->text.text,
725 min (length - offset, strlen (body->text.text)));
726 break;
728 encode_step (buffer, offset, &(body->file.hash));
729 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
730 if (body->file.uri)
731 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
732 strlen (
733 body->file.uri)));
734 break;
736 if (body->privacy.data)
737 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
738 body->privacy.
739 length));
740 break;
742 encode_step (buffer, offset, &(body->deletion.hash));
743 encode_step (buffer, offset, &(body->deletion.delay));
744 break;
746 value0 = GNUNET_htobe32 (body->connection.amount);
747 value1 = GNUNET_htobe32 (body->connection.flags);
748
749 encode_step (buffer, offset, &value0);
750 encode_step (buffer, offset, &value1);
751 break;
753 encode_step_ext (buffer, offset, body->ticket.identifier,
754 min (length - offset, strlen (body->ticket.identifier)));
755 break;
757 encode_step (buffer, offset, &(body->transcript.hash));
758 encode_step_key (buffer, offset, &(body->transcript.key), length);
759
760 if (body->transcript.data)
761 encode_step_ext (buffer, offset, body->transcript.data, min (length
762 - offset,
763 body->
764 transcript.
765 length));
766 break;
768 encode_step (buffer, offset, &(body->tag.hash));
769
770 if (body->tag.tag)
771 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
772 strlen (
773 body->tag.tag)));
774 break;
776 value0 = GNUNET_htobe32 (body->subscription.flags);
777
778 encode_step (buffer, offset, &(body->subscription.discourse));
779 encode_step (buffer, offset, &(body->subscription.time));
780 encode_step (buffer, offset, &value0);
781 break;
783 encode_step (buffer, offset, &(body->talk.discourse));
784
785 if (body->talk.data)
786 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
787 body->talk.
788 length));
789 break;
791 encode_step (buffer, offset, &(body->announcement.identifier));
792 encode_step (buffer, offset, &(body->announcement.key));
793 encode_step (buffer, offset, &(body->announcement.nonce));
794 encode_step (buffer, offset, &(body->announcement.timeout));
795 encode_step (buffer, offset, &(body->announcement.hmac));
796 break;
798 encode_step (buffer, offset, &(body->secret.identifier));
799 encode_step (buffer, offset, &(body->secret.iv));
800 encode_step (buffer, offset, &(body->secret.mac));
801
802 if (body->secret.data)
803 encode_step_ext (buffer, offset, body->secret.data, min (length - offset,
804 body->secret.
805 length));
806 break;
808 encode_step (buffer, offset, &(body->appeal.event));
809 encode_step (buffer, offset, &(body->appeal.key));
810 encode_step (buffer, offset, &(body->appeal.timeout));
811 break;
813 encode_step (buffer, offset, &(body->access.event));
814 encode_step (buffer, offset, &(body->access.key));
815 encode_step (buffer, offset, &(body->access.hmac));
816 break;
818 encode_step (buffer, offset, &(body->revolution.identifier));
819 encode_step (buffer, offset, &(body->revolution.nonce));
820 encode_step (buffer, offset, &(body->revolution.hmac));
821 break;
823 encode_step (buffer, offset, &(body->group.identifier));
824 encode_step (buffer, offset, &(body->group.initiator));
825 encode_step (buffer, offset, &(body->group.partner));
826 encode_step (buffer, offset, &(body->group.timeout));
827 break;
829 encode_step (buffer, offset, &(body->authorization.identifier));
830 encode_step (buffer, offset, &(body->authorization.event));
831 encode_step (buffer, offset, &(body->authorization.key));
832 encode_step (buffer, offset, &(body->authorization.hmac));
833 break;
834 default:
835 break;
836 }
837
838 if (offset >= length)
839 return;
840
841 {
842 uint16_t padding;
843 uint16_t used_padding;
844
845 padding = length - offset;
846 used_padding = sizeof(padding) + sizeof(char);
847
848 GNUNET_assert (padding >= used_padding);
849
850 buffer[offset++] = '\0';
851
852 if (padding > used_padding)
853 GNUNET_CRYPTO_random_block (buffer + offset,
854 padding - used_padding);
855
856 GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
857 sizeof(padding));
858 }
859}
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
#define GNUNET_htobe32(x)
#define encode_step_ext(dst, offset, src, size)
#define encode_step(dst, offset, src)
#define encode_step_hpke_key(dst, offset, src, length)
#define min(x, y)
#define encode_step_key(dst, offset, src, length)
struct GNUNET_HashCode hmac
The hmac of the access.
uint8_t key[sizeof(struct GNUNET_CRYPTO_AeadSecretKey)+16+sizeof(struct GNUNET_CRYPTO_HpkeEncapsulation)]
The encrypted group or epoch key.
struct GNUNET_HashCode event
The hash of the linked announcement or group message event.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the announcement.
struct GNUNET_HashCode hmac
The hmac of the announcement.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to appeal access.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to receive access.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the appeal.
struct GNUNET_HashCode event
The hash of the linked announcement message event.
struct GNUNET_HashCode event
The hash of the linked group message event.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode hmac
The hmac of the authorization.
uint8_t key[sizeof(struct GNUNET_CRYPTO_AeadSecretKey)]
The encrypted group or epoch key.
struct GNUNET_MESSENGER_MessageAnnouncement announcement
struct GNUNET_MESSENGER_MessageGroup group
struct GNUNET_MESSENGER_MessageDeletion deletion
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageLeave leave
struct GNUNET_MESSENGER_MessageRevolution revolution
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageAccess access
struct GNUNET_MESSENGER_MessageSubscribtion subscription
struct GNUNET_MESSENGER_MessageAuthorization authorization
struct GNUNET_MESSENGER_MessageAppeal appeal
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageInfo info
uint32_t amount
The amount of connections of a peer.
uint32_t flags
The flags about the connections of a peer.
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
struct GNUNET_HashCode hash
The hash of the original file.
char name[NAME_MAX]
The name of the file.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the group formation.
struct GNUNET_HashCode initiator
The hash of the initiator group announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode partner
The hash of the partner group announcement.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
uint32_t messenger_version
The version of GNUnet Messenger API.
union GNUNET_MESSENGER_RoomKey key
The hash identifying the port of the room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_HashCode epochs[2]
The previous epochs the message was sent from.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_HashCode hash
The hash of the requested message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the revolution.
struct GNUNET_HashCode hmac
The hmac of the revolution.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_CRYPTO_AeadMac mac
The mac of the encrypted message.
struct GNUNET_CRYPTO_AeadNonce iv
The IV of the secret message.
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscription.
struct GNUNET_HashCode hash
The hash of the message to tag.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.
struct GNUNET_HashCode hash
The hash of the original message.

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::appeal, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, GNUNET_MESSENGER_MessageDeletion::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, encode_step, encode_step_ext, encode_step_hpke_key, encode_step_key, GNUNET_MESSENGER_MessageJoin::epoch, GNUNET_MESSENGER_MessageLeave::epoch, GNUNET_MESSENGER_MessageMerge::epochs, GNUNET_MESSENGER_MessageAppeal::event, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribtion::flags, GNUNET_assert, GNUNET_CRYPTO_random_block(), GNUNET_htobe32, GNUNET_memcpy, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageBody::group, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDeletion::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, GNUNET_MESSENGER_MessageJoin::hpke_key, GNUNET_MESSENGER_MessageKey::hpke_key, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageGroup::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageGroup::initiator, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageSecret::iv, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageAnnouncement::key, GNUNET_MESSENGER_MessageAppeal::key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageBody::leave, GNUNET_MESSENGER_MessageSecret::mac, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, min, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, GNUNET_MESSENGER_MessageGroup::partner, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::revolution, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageBody::subscription, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageSubscribtion::time, GNUNET_MESSENGER_MessageAnnouncement::timeout, GNUNET_MESSENGER_MessageAppeal::timeout, GNUNET_MESSENGER_MessageGroup::timeout, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by encode_message(), and encode_short_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_message_signature()

void encode_message_signature ( const struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer 
)

Encodes the signature of a given message into a buffer of a maximum length in bytes.

Parameters
[in]messageMessage
[in]lengthMaximal length to encode
[out]bufferBuffer

Definition at line 863 of file messenger_api_message.c.

866{
867 uint16_t offset = 0;
868
869 GNUNET_assert ((message) && (buffer));
870
871 encode_step_signature (buffer, offset, &(message->header.signature),
872 length);
873}
#define encode_step_signature(dst, offset, src, length)

References encode_step_signature, GNUNET_assert, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::signature.

Referenced by callback_srv_room_sign_result(), and send_message_to_room().

Here is the caller graph for this function:

◆ encode_message()

void encode_message ( const struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer,
enum GNUNET_GenericReturnValue  include_header 
)

Encodes a given message into a buffer of a maximum length in bytes.

Parameters
[in]messageMessage
[in]lengthMaximal length to encode
[out]bufferBuffer
[in]include_headerFlag to include header

Definition at line 877 of file messenger_api_message.c.

881{
882 uint16_t offset;
883 kind_t kind;
884
885 GNUNET_assert ((message) && (buffer));
886
887 offset = 0;
888
889 if (GNUNET_YES == include_header)
890 encode_step_signature (buffer, offset, &(message->header.signature),
891 length);
892
893 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
894
895 if (GNUNET_YES == include_header)
896 {
897 encode_step (buffer, offset, &(message->header.timestamp));
898 encode_step (buffer, offset, &(message->header.sender_id));
899 encode_step (buffer, offset, &(message->header.previous));
900 }
901
902 encode_step (buffer, offset, &kind);
903
904 encode_message_body (message->header.kind, &(message->body),
905 length, buffer, offset);
906}
static void encode_message_body(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.

References GNUNET_MESSENGER_Message::body, encode_message_body(), encode_step, encode_step_signature, GNUNET_assert, GNUNET_htobe32, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_MessageHeader::signature, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by iterate_save_messages(), notify_srv_handle_message(), pack_message(), and send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_short_message()

static void encode_short_message ( const struct GNUNET_MESSENGER_ShortMessage message,
uint16_t  length,
char *  buffer 
)
static

Definition at line 910 of file messenger_api_message.c.

913{
914 struct GNUNET_HashCode hash;
915 uint16_t offset;
916 kind_t kind;
917
918 GNUNET_assert ((message) && (buffer));
919
920 offset = sizeof(hash);
921 kind = GNUNET_htobe32 ((kind_t) message->kind);
922
923 encode_step (buffer, offset, &kind);
924
925 encode_message_body (message->kind, &(message->body), length, buffer, offset);
926
928 buffer + sizeof(hash),
929 length - sizeof(hash),
930 &hash);
931
932 GNUNET_memcpy (buffer, &hash, sizeof(hash));
933}
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

References GNUNET_MESSENGER_ShortMessage::body, encode_message_body(), encode_step, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_htobe32, GNUNET_memcpy, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by encrypt_message(), encrypt_secret_message(), and transcribe_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_message_body()

static uint16_t decode_message_body ( enum GNUNET_MESSENGER_MessageKind kind,
struct GNUNET_MESSENGER_MessageBody body,
uint16_t  length,
const char *  buffer,
uint16_t  offset 
)
static

Definition at line 974 of file messenger_api_message.c.

979{
980 uint16_t padding;
981 uint32_t value0, value1;
982
983 GNUNET_assert ((kind) && (body) && (buffer));
984
985 padding = 0;
986
987 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
988
989 if (padding > length - offset)
990 padding = 0;
991
992 {
993 uint16_t end_zero;
994 end_zero = length - padding;
995
996 if ((padding) && (buffer[end_zero] != '\0'))
997 padding = 0;
998 }
999
1000 length -= padding;
1001
1002 switch (*kind)
1003 {
1005 decode_step (buffer, offset, &value0);
1006
1007 body->info.messenger_version = GNUNET_be32toh (value0);
1008 break;
1010 decode_step (buffer, offset, &(body->join.epoch));
1011 decode_step_key (buffer, offset, &(body->join.key), length);
1012 decode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
1013 break;
1015 decode_step (buffer, offset, &(body->leave.epoch));
1016 break;
1018 if (length > offset)
1019 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
1020 else
1021 body->name.name = NULL;
1022 break;
1024 decode_step_key (buffer, offset, &(body->key.key), length);
1025 decode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
1026 break;
1028 decode_step (buffer, offset, &(body->peer.peer));
1029 break;
1031 decode_step (buffer, offset, &(body->id.id));
1032 break;
1034 decode_step (buffer, offset, &(body->miss.peer));
1035 break;
1037 decode_step (buffer, offset, &(body->merge.epochs[0]));
1038 decode_step (buffer, offset, &(body->merge.epochs[1]));
1039 decode_step (buffer, offset, &(body->merge.previous));
1040 break;
1042 decode_step (buffer, offset, &(body->request.hash));
1043 break;
1045 decode_step (buffer, offset, &(body->invite.door));
1046 decode_step (buffer, offset, &(body->invite.key));
1047 break;
1049 if (length > offset)
1050 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
1051 else
1052 body->text.text = NULL;
1053 break;
1055 decode_step (buffer, offset, &(body->file.hash));
1056 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
1057 if (length > offset)
1058 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
1059 else
1060 body->file.uri = NULL;
1061 break;
1063 if (length > offset)
1064 {
1065 body->privacy.length = (length - offset);
1066 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
1067 0);
1068 }
1069 else
1070 {
1071 body->privacy.length = 0;
1072 body->privacy.data = NULL;
1073 }
1074
1075 break;
1077 decode_step (buffer, offset, &(body->deletion.hash));
1078 decode_step (buffer, offset, &(body->deletion.delay));
1079 break;
1081 decode_step (buffer, offset, &value0);
1082 decode_step (buffer, offset, &value1);
1083
1084 body->connection.amount = GNUNET_be32toh (value0);
1085 body->connection.flags = GNUNET_be32toh (value1);
1086 break;
1088 if (length > offset)
1089 decode_step_malloc (buffer, offset, body->ticket.identifier, length
1090 - offset, 1);
1091 else
1092 body->ticket.identifier = NULL;
1093 break;
1095 decode_step (buffer, offset, &(body->transcript.hash));
1096 decode_step_key (buffer, offset, &(body->transcript.key), length);
1097
1098 if (length > offset)
1099 {
1100 body->transcript.length = (length - offset);
1101 decode_step_malloc (buffer, offset, body->transcript.data,
1102 length - offset, 0);
1103 }
1104 else
1105 {
1106 body->transcript.length = 0;
1107 body->transcript.data = NULL;
1108 }
1109
1110 break;
1112 decode_step (buffer, offset, &(body->tag.hash));
1113 if (length > offset)
1114 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
1115 else
1116 body->tag.tag = NULL;
1117 break;
1119 decode_step (buffer, offset, &(body->subscription.discourse));
1120 decode_step (buffer, offset, &(body->subscription.time));
1121 decode_step (buffer, offset, &value0);
1122
1123 body->subscription.flags = GNUNET_be32toh (value0);
1124 break;
1126 decode_step (buffer, offset, &(body->talk.discourse));
1127
1128 if (length > offset)
1129 {
1130 body->talk.length = (length - offset);
1131 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
1132 0);
1133 }
1134 else
1135 {
1136 body->talk.length = 0;
1137 body->talk.data = NULL;
1138 }
1139
1140 break;
1142 decode_step (buffer, offset, &(body->announcement.identifier));
1143 decode_step (buffer, offset, &(body->announcement.key));
1144 decode_step (buffer, offset, &(body->announcement.nonce));
1145 decode_step (buffer, offset, &(body->announcement.timeout));
1146 decode_step (buffer, offset, &(body->announcement.hmac));
1147 break;
1149 decode_step (buffer, offset, &(body->secret.identifier));
1150 decode_step (buffer, offset, &(body->secret.iv));
1151 decode_step (buffer, offset, &(body->secret.mac));
1152
1153 if (length > offset)
1154 {
1155 body->secret.length = (length - offset);
1156 decode_step_malloc (buffer, offset, body->secret.data, length - offset,
1157 0);
1158 }
1159 else
1160 {
1161 body->secret.length = 0;
1162 body->secret.data = NULL;
1163 }
1164
1165 break;
1167 decode_step (buffer, offset, &(body->appeal.event));
1168 decode_step (buffer, offset, &(body->appeal.key));
1169 decode_step (buffer, offset, &(body->appeal.timeout));
1170 break;
1172 decode_step (buffer, offset, &(body->access.event));
1173 decode_step (buffer, offset, &(body->access.key));
1174 decode_step (buffer, offset, &(body->access.hmac));
1175 break;
1177 decode_step (buffer, offset, &(body->revolution.identifier));
1178 decode_step (buffer, offset, &(body->revolution.nonce));
1179 decode_step (buffer, offset, &(body->revolution.hmac));
1180 break;
1182 decode_step (buffer, offset, &(body->group.identifier));
1183 decode_step (buffer, offset, &(body->group.initiator));
1184 decode_step (buffer, offset, &(body->group.partner));
1185 decode_step (buffer, offset, &(body->group.timeout));
1186 break;
1188 decode_step (buffer, offset, &(body->authorization.identifier));
1189 decode_step (buffer, offset, &(body->authorization.event));
1190 decode_step (buffer, offset, &(body->authorization.key));
1191 decode_step (buffer, offset, &(body->authorization.hmac));
1192 break;
1193 default:
1195 break;
1196 }
1197
1198 return padding;
1199}
#define GNUNET_be32toh(x)
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
#define decode_step(src, offset, dst)
#define decode_step_key(src, offset, dst, length)
#define decode_step_hpke_key(src, offset, dst, length)
#define decode_step_malloc(src, offset, dst, size, zero)
#define decode_step_ext(src, offset, dst, size)

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::appeal, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, decode_step, decode_step_ext, decode_step_hpke_key, decode_step_key, decode_step_malloc, GNUNET_MESSENGER_MessageDeletion::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageJoin::epoch, GNUNET_MESSENGER_MessageLeave::epoch, GNUNET_MESSENGER_MessageMerge::epochs, GNUNET_MESSENGER_MessageAppeal::event, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribtion::flags, GNUNET_assert, GNUNET_be32toh, GNUNET_memcpy, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_MessageBody::group, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDeletion::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, GNUNET_MESSENGER_MessageJoin::hpke_key, GNUNET_MESSENGER_MessageKey::hpke_key, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageGroup::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageGroup::initiator, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageSecret::iv, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageAnnouncement::key, GNUNET_MESSENGER_MessageAppeal::key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageBody::leave, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageSecret::mac, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, GNUNET_MESSENGER_MessageGroup::partner, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::revolution, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageBody::subscription, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageSubscribtion::time, GNUNET_MESSENGER_MessageAnnouncement::timeout, GNUNET_MESSENGER_MessageAppeal::timeout, GNUNET_MESSENGER_MessageGroup::timeout, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by decode_message(), and decode_short_message().

Here is the caller graph for this function:

◆ decode_message()

enum GNUNET_GenericReturnValue decode_message ( struct GNUNET_MESSENGER_Message message,
uint16_t  length,
const char *  buffer,
enum GNUNET_GenericReturnValue  include_header,
uint16_t *  padding 
)

Decodes a message from a given buffer of a maximum length in bytes.

If the buffer is too small for a message of its decoded kind the function fails with resulting GNUNET_NO after decoding only the messages header.

On success the function returns GNUNET_YES.

Parameters
[out]messageMessage
[in]lengthMaximal length to decode
[in]bufferBuffer
[in]include_headerFlag to include header
[out]paddingPadding
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1203 of file messenger_api_message.c.

1208{
1209 uint16_t offset;
1210 uint16_t count;
1211 kind_t kind;
1212
1214 (message) &&
1215 (buffer) &&
1217 include_header)));
1218
1219 offset = 0;
1220
1221 if (GNUNET_YES == include_header)
1222 {
1223 ssize_t result;
1224
1226 &(message->header.signature), buffer, length - offset);
1227
1228 if (result < 0)
1229 return GNUNET_NO;
1230 else
1231 offset += result;
1232 }
1233
1234 count = length - offset;
1236 include_header))
1237 return GNUNET_NO;
1238
1239 if (GNUNET_YES == include_header)
1240 {
1241 decode_step (buffer, offset, &(message->header.timestamp));
1242 decode_step (buffer, offset, &(message->header.sender_id));
1243 decode_step (buffer, offset, &(message->header.previous));
1244 }
1245
1246 decode_step (buffer, offset, &kind);
1247 kind = GNUNET_be32toh (kind);
1248
1249 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1250
1251 if (count < get_message_kind_size (message->header.kind, include_header))
1252 return GNUNET_NO;
1253
1254 {
1255 uint16_t result;
1256 result = decode_message_body (&(message->header.kind),
1257 &(message->body), length, buffer, offset);
1258
1259 if (padding)
1260 *padding = result;
1261 }
1262
1263 return GNUNET_YES;
1264}
ssize_t GNUNET_CRYPTO_read_blinded_key_signature_from_buffer(struct GNUNET_CRYPTO_BlindableKeySignature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_BlindableKeySignature from a compact buffer.
static uint16_t decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)

References GNUNET_MESSENGER_Message::body, decode_message_body(), decode_step, get_message_kind_size(), GNUNET_assert, GNUNET_be32toh, GNUNET_CRYPTO_read_blinded_key_signature_from_buffer(), GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, result, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_MessageHeader::signature, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by check_recv_message(), check_send_message(), check_tunnel_message(), get_store_message(), handle_recv_message(), handle_send_message(), and handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_short_message()

static enum GNUNET_GenericReturnValue decode_short_message ( struct GNUNET_MESSENGER_ShortMessage message,
uint16_t  length,
const char *  buffer 
)
static

Definition at line 1268 of file messenger_api_message.c.

1271{
1272 struct GNUNET_HashCode expected, hash;
1273 uint16_t offset;
1274 kind_t kind;
1275
1276 GNUNET_assert ((message) && (buffer));
1277
1278 offset = sizeof(hash);
1279
1280 if (length < get_short_message_size (NULL, GNUNET_NO))
1281 return GNUNET_NO;
1282
1283 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1284
1286 buffer + sizeof(hash),
1287 length - sizeof(hash),
1288 &expected);
1289
1290 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1291 return GNUNET_NO;
1292
1293 decode_step (buffer, offset, &kind);
1294 kind = GNUNET_be32toh (kind);
1295
1296 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1297
1298 if (length < get_short_message_size (message, GNUNET_NO))
1299 return GNUNET_NO;
1300
1301 decode_message_body (&(message->kind), &(message->body), length, buffer,
1302 offset);
1303
1304 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1305 return GNUNET_NO;
1306
1307 return GNUNET_YES;
1308}
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)

References GNUNET_MESSENGER_ShortMessage::body, decode_message_body(), decode_step, get_short_message_size(), GNUNET_assert, GNUNET_be32toh, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_cmp(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decrypt_message(), decrypt_secret_message(), and read_transcript_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash_message()

void hash_message ( const struct GNUNET_MESSENGER_Message message,
uint16_t  length,
const char *  buffer,
struct GNUNET_HashCode hash 
)

Calculates a hash of a given buffer with a length in bytes from a message.

Parameters
[in]messageMessage
[in]lengthLength of buffer
[in]bufferBuffer
[out]hashHash

Definition at line 1312 of file messenger_api_message.c.

1316{
1317 ssize_t offset;
1318
1319 GNUNET_assert ((message) && (buffer) && (hash));
1320
1322 signature));
1323
1324 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1325}

References GNUNET_assert, GNUNET_CRYPTO_blinded_key_signature_get_length(), GNUNET_CRYPTO_hash(), and GNUNET_MESSENGER_Message::header.

Referenced by check_tunnel_message(), get_store_message(), handle_tunnel_message(), pack_message(), and send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_message()

void sign_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_BlindablePrivateKey key 
)

Signs the hash of a message with a given private key.

Parameters
[in,out]messageMessage
[in]hashHash of message
[in]keyPrivate key

Definition at line 1329 of file messenger_api_message.c.

1332{
1333 struct GNUNET_MESSENGER_MessageSignature signature;
1334
1335 GNUNET_assert ((message) && (hash) && (key));
1336
1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1338 GNUNET_h2s (hash));
1339
1340 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1341 signature.purpose.size = htonl (sizeof(signature));
1342
1343 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1344
1346 &(message->header.signature));
1347 message->header.signature.type = key->type;
1348}
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
#define GNUNET_log(kind,...)
#define GNUNET_CRYPTO_blinded_key_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_BlindablePrivateKey.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_assert, GNUNET_CRYPTO_blinded_key_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, key, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_message_by_peer()

struct GNUNET_PILS_Operation * sign_message_by_peer ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
struct GNUNET_PILS_Handle pils,
const GNUNET_PILS_SignResultCallback  sign_cb,
void *  cls 
)

Signs the hash of a message with the peer identity of a given pils service going into a callback with a custom closure on success.

Parameters
[in,out]messageMessage
[in]hashHash of message
[in,out]pilsPils handle
[in]sign_cbSignature callback
[in,out]clsClosure
Returns
Signature operation or NULL on failure

Definition at line 1352 of file messenger_api_message.c.

1357{
1358 struct GNUNET_MESSENGER_MessageSignature signature;
1359 struct GNUNET_PILS_Operation *operation;
1360
1361 GNUNET_assert ((message) && (hash) && (pils));
1362
1363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1364 GNUNET_h2s (hash));
1365
1366 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1367 signature.purpose.size = htonl (sizeof (signature));
1368
1369 GNUNET_memcpy (&(signature.hash), hash, sizeof (signature.hash));
1370
1371 operation = GNUNET_PILS_sign_by_peer_identity (pils, &(signature.purpose),
1372 sign_cb, cls);
1373
1374 if (! operation)
1375 return NULL;
1376
1378 return operation;
1379}
static void sign_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Definition gnunet-abd.c:675
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
Sign data with the peer id.
Definition pils_api.c:528
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_PILS_sign_by_peer_identity(), GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, pils, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, sign_cb(), GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by sign_srv_room_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_message_hmac()

static enum GNUNET_GenericReturnValue calc_message_hmac ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_AeadSecretKey key,
struct GNUNET_HashCode hmac 
)
static

Definition at line 1383 of file messenger_api_message.c.

1386{
1387 struct GNUNET_CRYPTO_AuthKey auth_key;
1388
1389 GNUNET_assert ((message) && (key) && (hmac));
1390
1391 switch (message->header.kind)
1392 {
1395 &auth_key, sizeof (auth_key),
1398 key, sizeof (*key),
1402 return GNUNET_NO;
1403
1404 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1405 sizeof (message->body.announcement)
1406 - sizeof (*hmac),
1407 hmac);
1408 return GNUNET_YES;
1411 &auth_key, sizeof (auth_key),
1414 key, sizeof (*key),
1416 return GNUNET_NO;
1417
1418 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1419 sizeof (message->body.access)
1420 - sizeof (*hmac),
1421 hmac);
1422 return GNUNET_YES;
1425 &auth_key, sizeof (auth_key),
1428 key, sizeof (*key),
1432 return GNUNET_NO;
1433
1434 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1435 sizeof (message->body.revolution)
1436 - sizeof (*hmac),
1437 hmac);
1438 return GNUNET_YES;
1441 &auth_key, sizeof (auth_key),
1444 key, sizeof (*key),
1447 return GNUNET_NO;
1448
1449 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1450 sizeof (message->body.authorization)
1451 - sizeof (*hmac),
1452 hmac);
1453 return GNUNET_YES;
1454 default:
1455 return GNUNET_SYSERR;
1456 }
1457}
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
#define GNUNET_CRYPTO_kdf_arg_auto(d)
#define GNUNET_CRYPTO_kdf_arg(d, s)
#define GNUNET_MESSENGER_EPOCH_NONCE_BYTES
#define GNUNET_MESSENGER_SALT_EPOCH_KEY
#define GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY
#define GNUNET_MESSENGER_SALT_GROUP_KEY
type for (message) authentication keys

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_hmac(), GNUNET_CRYPTO_kdf_arg, GNUNET_CRYPTO_kdf_arg_auto, GNUNET_MESSENGER_EPOCH_NONCE_BYTES, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY, GNUNET_MESSENGER_SALT_EPOCH_KEY, GNUNET_MESSENGER_SALT_GROUP_KEY, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, and GNUNET_MESSENGER_MessageBody::revolution.

Referenced by sign_message_by_key(), and verify_message_by_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_message_by_key()

enum GNUNET_GenericReturnValue sign_message_by_key ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_AeadSecretKey key 
)

Signs the message body via it's own hmac with a specific shared key.

It requires the message to be of a supported kind of message which contains such an hmac.

On success the message can be verified via verify_message_by_key() afterwards.

Parameters
[in,out]messageMessage
[in]keyShared key
Returns
GNUNET_YES on success, GNUNET_NO on failure, otherwise GNUNET_SYSERR

Definition at line 1461 of file messenger_api_message.c.

1463{
1464 struct GNUNET_HashCode *hmac;
1465
1466 GNUNET_assert ((message) && (key));
1467
1468 switch (message->header.kind)
1469 {
1471 hmac = &(message->body.announcement.hmac);
1472 break;
1474 hmac = &(message->body.access.hmac);
1475 break;
1477 hmac = &(message->body.revolution.hmac);
1478 break;
1480 hmac = &(message->body.authorization.hmac);
1481 break;
1482 default:
1483 hmac = NULL;
1484 break;
1485 }
1486
1487 if (! hmac)
1488 return GNUNET_SYSERR;
1489
1490 return calc_message_hmac (message, key, hmac);
1491}
static enum GNUNET_GenericReturnValue calc_message_hmac(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key, struct GNUNET_HashCode *hmac)

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, calc_message_hmac(), GNUNET_assert, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_SYSERR, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, key, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_MessageBody::revolution.

Referenced by create_message_access(), create_message_announcement(), create_message_authorization(), and create_message_revolution().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_message()

enum GNUNET_GenericReturnValue verify_message ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_BlindablePublicKey key 
)

Verifies the signature of a given message and its hash with a specific public key.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]hashHash of message
[in]keyPublic key
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1495 of file messenger_api_message.c.

1498{
1499 struct GNUNET_MESSENGER_MessageSignature signature;
1500
1501 GNUNET_assert ((message) && (hash) && (key));
1502
1503 if (key->type != message->header.signature.type)
1504 return GNUNET_SYSERR;
1505
1506 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1507 signature.purpose.size = htonl (sizeof(signature));
1508
1509 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1510
1513 &(message->header.signature), key);
1514}
#define GNUNET_CRYPTO_blinded_key_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_CRYPTO_BlindablePublicKey.

References GNUNET_assert, GNUNET_CRYPTO_blinded_key_signature_verify, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_SYSERR, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, key, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by verify_member_session_as_sender().

Here is the caller graph for this function:

◆ verify_message_by_peer()

enum GNUNET_GenericReturnValue verify_message_by_peer ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
const struct GNUNET_PeerIdentity identity 
)

Verifies the signature of a given message and its hash with a specific peer's identity.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]hashHash of message
[in]identityPeer identity
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1518 of file messenger_api_message.c.

1521{
1522 struct GNUNET_MESSENGER_MessageSignature signature;
1523
1524 GNUNET_assert ((message) && (hash) && (identity));
1525
1526 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1527 return GNUNET_SYSERR;
1528
1529 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1530 signature.purpose.size = htonl (sizeof(signature));
1531
1532 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1533
1535 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &(signature.purpose),
1536 &(message->header.signature.
1537 eddsa_signature), identity);
1538}
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity(uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
Verify a given signature with a peer's identity.

References GNUNET_assert, GNUNET_CRYPTO_verify_peer_identity(), GNUNET_memcpy, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_SYSERR, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, identity, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by get_store_peer_of(), and verify_store_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_message_by_key()

enum GNUNET_GenericReturnValue verify_message_by_key ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_AeadSecretKey key 
)

Verifies the hmac of a given message body with a specific shared key.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]keyShared key
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1542 of file messenger_api_message.c.

1544{
1545 const struct GNUNET_HashCode *msg_hmac;
1546 struct GNUNET_HashCode hmac;
1547
1548 GNUNET_assert ((message) && (key));
1549
1550 switch (message->header.kind)
1551 {
1553 msg_hmac = &(message->body.announcement.hmac);
1554 break;
1556 msg_hmac = &(message->body.access.hmac);
1557 break;
1559 msg_hmac = &(message->body.revolution.hmac);
1560 break;
1562 msg_hmac = &(message->body.authorization.hmac);
1563 break;
1564 default:
1565 msg_hmac = NULL;
1566 break;
1567 }
1568
1569 if (! msg_hmac)
1570 return GNUNET_SYSERR;
1571
1572 if (GNUNET_YES != calc_message_hmac (message, key, &hmac))
1573 return GNUNET_SYSERR;
1574
1575 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1576 return GNUNET_OK;
1577
1578 return GNUNET_SYSERR;
1579}
@ GNUNET_OK

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, calc_message_hmac(), GNUNET_assert, GNUNET_CRYPTO_hash_cmp(), GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, key, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_MessageBody::revolution.

Referenced by extract_access_message_key(), extract_authorization_message_key(), handle_access_message(), handle_authorization_message(), handle_epoch_announcement(), handle_epoch_group_announcement(), handle_revolution_message(), and send_epoch_announcement_authorization().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encrypt_message()

enum GNUNET_GenericReturnValue encrypt_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_HpkePublicKey hpke_key 
)

Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyPublic key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1583 of file messenger_api_message.c.

1585{
1587 struct GNUNET_MESSENGER_ShortMessage shortened;
1588 uint16_t length, padded_length, encoded_length;
1589 uint8_t *data;
1590
1591 GNUNET_assert ((message) && (hpke_key));
1592
1593 if (GNUNET_YES == is_service_message (message))
1594 return GNUNET_NO;
1595
1596 fold_short_message (message, &shortened);
1597
1598 length = get_short_message_size (&shortened, GNUNET_YES);
1599 padded_length = calc_padded_length (length + encryption_overhead);
1600
1601 GNUNET_assert (padded_length >= length + encryption_overhead);
1602
1604 message->body.privacy.data = GNUNET_malloc (padded_length);
1605 message->body.privacy.length = padded_length;
1606
1607 encoded_length = (padded_length - encryption_overhead);
1608
1609 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1610
1611 result = GNUNET_NO;
1612 data = GNUNET_malloc (encoded_length);
1613
1614 encode_short_message (&shortened, encoded_length, (char *) data);
1615
1617 (const uint8_t*)
1618 "messenger",
1619 strlen ("messenger"),
1620 NULL, 0,
1621 (const uint8_t*) data,
1622 encoded_length,
1623 (uint8_t*) message->body.
1624 privacy.data,
1625 NULL))
1626 {
1627 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1628
1629 unfold_short_message (&shortened, message);
1630 goto cleanup;
1631 }
1632
1633 destroy_message_body (shortened.kind, &(shortened.body));
1635
1636cleanup:
1637 GNUNET_free (data);
1638 return result;
1639}
static char * data
The data to insert into the dht.
static void cleanup()
Cleanup task.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_HpkePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
RFC9180 HPKE encryption.
@ GNUNET_ERROR_TYPE_WARNING
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
static void fold_short_message(const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
static uint16_t calc_padded_length(uint16_t length)
const uint16_t encryption_overhead
static void encode_short_message(const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
static void unfold_short_message(struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, calc_padded_length(), cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, destroy_message_body(), encode_short_message(), encryption_overhead, fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_CRYPTO_hpke_seal_oneshot(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_service_message(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_ShortMessage::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, result, and unfold_short_message().

Referenced by dequeue_message_from_room(), and send_message_to_room_with_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_message()

enum GNUNET_GenericReturnValue decrypt_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_HpkePrivateKey hpke_key 
)

Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyPrivate key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1643 of file messenger_api_message.c.

1645{
1647 uint16_t padded_length, encoded_length;
1648 uint8_t *data;
1649 FILE *tmperr;
1650 int error_fd;
1651
1652 GNUNET_assert ((message) && (hpke_key) &&
1654
1655 padded_length = message->body.privacy.length;
1656
1657 if (padded_length < encryption_overhead)
1658 {
1660 "Message length too short to decrypt!\n");
1661
1662 return GNUNET_NO;
1663 }
1664
1665 encoded_length = (padded_length - encryption_overhead);
1666
1667 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1668
1669 result = GNUNET_NO;
1670 data = GNUNET_malloc (encoded_length);
1671
1672 tmperr = tmpfile ();
1673
1674 if (tmperr)
1675 {
1676 error_fd = dup (2 /* stderr */);
1677 dup2 (fileno (tmperr), 2 /* stderr */);
1678 }
1679
1680 if (GNUNET_OK !=
1682 (uint8_t*) "messenger",
1683 strlen ("messenger"),
1684 NULL, 0,
1685 (uint8_t*) message->body.privacy.data,
1686 padded_length,
1687 (uint8_t*) data,
1688 NULL))
1689 {
1690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1691
1692 goto cleanup;
1693 }
1694
1695 {
1696 struct GNUNET_MESSENGER_ShortMessage shortened;
1697 if (GNUNET_YES != decode_short_message (&shortened,
1698 encoded_length,
1699 (char*) data))
1700 {
1702 "Decoding decrypted message failed!\n");
1703
1704 goto cleanup;
1705 }
1706
1707 unfold_short_message (&shortened, message);
1709 }
1710
1711cleanup:
1712 if (tmperr)
1713 {
1714 dup2 (error_fd, 2 /* stderr */);
1715 fclose (tmperr);
1716 }
1717
1718 GNUNET_free (data);
1719 return result;
1720}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot(const struct GNUNET_CRYPTO_HpkePrivateKey *skR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len)
RFC9180 HPKE encryption.
static enum GNUNET_GenericReturnValue decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)

References GNUNET_MESSENGER_Message::body, cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), encryption_overhead, GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, result, and unfold_short_message().

Referenced by handle_private_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transcribe_message()

struct GNUNET_MESSENGER_Message * transcribe_message ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_BlindablePublicKey key 
)

Transcribes a message as a new transcript message using a given public key from the recipient of the encrypted message content.

Parameters
[in]messageMessage
[in]keyPublic key
Returns
Message transcript

Definition at line 1724 of file messenger_api_message.c.

1726{
1727 struct GNUNET_MESSENGER_Message *transcript;
1728
1729 GNUNET_assert ((message) && (key));
1730
1731 if (GNUNET_YES == is_service_message (message))
1732 return NULL;
1733
1735
1736 if (! transcript)
1737 {
1738 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1739 return NULL;
1740 }
1741
1742 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1743 sizeof(transcript->body.transcript.key));
1744
1745 {
1746 struct GNUNET_MESSENGER_ShortMessage shortened;
1747 uint16_t data_length;
1748
1749 fold_short_message (message, &shortened);
1750
1751 data_length = get_short_message_size (&shortened, GNUNET_YES);
1752
1753 transcript->body.transcript.data = GNUNET_malloc (data_length);
1754 transcript->body.transcript.length = data_length;
1755
1756 encode_short_message (&shortened, data_length,
1757 transcript->body.transcript.data);
1758 }
1759
1760 return transcript;
1761}
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_MESSENGER_MessageTranscript::data, encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_YES, is_service_message(), key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageTranscript::length, and GNUNET_MESSENGER_MessageBody::transcript.

Referenced by send_message_to_room_with_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encrypt_secret_message()

enum GNUNET_GenericReturnValue encrypt_secret_message ( struct GNUNET_MESSENGER_Message message,
const union GNUNET_MESSENGER_EpochIdentifier identifier,
const struct GNUNET_CRYPTO_AeadSecretKey key 
)

Encrypts a message using a given shared key from an announcement of an epoch and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]identifierEpoch identifier
[in]keyShared secret key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1765 of file messenger_api_message.c.

1769{
1771 struct GNUNET_MESSENGER_ShortMessage shortened;
1772 uint16_t length, padded_length;
1773 uint8_t *data;
1774
1775 GNUNET_assert ((message) && (identifier) && (key));
1776
1777 fold_short_message (message, &shortened);
1778
1779 length = get_short_message_size (&shortened, GNUNET_YES);
1780 padded_length = calc_padded_length (length + 0);
1781
1782 GNUNET_assert (padded_length >= length + 0);
1783
1785
1786 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1787 sizeof (message->body.secret.identifier));
1788
1791
1792 message->body.secret.data = GNUNET_malloc (padded_length);
1793 message->body.secret.length = padded_length;
1794
1795 result = GNUNET_NO;
1796 data = GNUNET_malloc (padded_length);
1797
1798 encode_short_message (&shortened, padded_length, (char *) data);
1799
1800 if (GNUNET_OK != GNUNET_CRYPTO_aead_encrypt (padded_length,
1801 data,
1802 0,
1803 NULL,
1804 key,
1805 &message->body.secret.iv,
1806 (unsigned char*) message->body.
1807 secret.data,
1808 &message->body.secret.mac))
1809 {
1810 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1811 unfold_short_message (&shortened, message);
1812 goto cleanup;
1813 }
1814
1815 destroy_message_body (shortened.kind, &(shortened.body));
1817
1818cleanup:
1819 GNUNET_free (data);
1820 return result;
1821}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt(size_t pt_len, const unsigned char pt[pt_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, void *ct, struct GNUNET_CRYPTO_AeadMac *mac)
Encrypt the given data using XChaCha20-Poly1305.
#define GNUNET_MESSENGER_SECRET_IV_BYTES

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, calc_padded_length(), cleanup(), data, GNUNET_MESSENGER_MessageSecret::data, destroy_message_body(), encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_CRYPTO_aead_encrypt(), GNUNET_CRYPTO_random_block(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_SECRET_IV_BYTES, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageSecret::iv, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_ShortMessage::kind, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageSecret::mac, result, GNUNET_MESSENGER_MessageBody::secret, and unfold_short_message().

Referenced by send_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_secret_message()

enum GNUNET_GenericReturnValue decrypt_secret_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_AeadSecretKey key 
)

Decrypts a secret message using a given shared key and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyShared secret key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1825 of file messenger_api_message.c.

1827{
1829 uint16_t padded_length;
1830 uint8_t *data;
1831
1832 GNUNET_assert ((message) && (key) &&
1834
1835 padded_length = message->body.secret.length;
1836
1837 result = GNUNET_NO;
1838 data = GNUNET_malloc (padded_length);
1839
1840 if (-1 == GNUNET_CRYPTO_aead_decrypt (padded_length,
1841 (unsigned char*) message->body.secret.
1842 data,
1843 0,
1844 NULL,
1845 key,
1846 &message->body.secret.iv,
1847 &message->body.secret.mac,
1848 data))
1849 {
1850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1851 goto cleanup;
1852 }
1853
1854 {
1855 struct GNUNET_MESSENGER_ShortMessage shortened;
1856 if (GNUNET_YES != decode_short_message (&shortened,
1857 padded_length,
1858 (char*) data))
1859 {
1861 "Decoding decrypted message failed!\n");
1862
1863 goto cleanup;
1864 }
1865
1866 unfold_short_message (&shortened, message);
1868 }
1869
1870cleanup:
1871 GNUNET_free (data);
1872 return result;
1873}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt(size_t ct_len, const unsigned char ct[ct_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, const struct GNUNET_CRYPTO_AeadMac *mac, void *pt)
Decrypt the given data using XChaCha20-Poly1305.

References GNUNET_MESSENGER_Message::body, cleanup(), data, decode_short_message(), GNUNET_assert, GNUNET_CRYPTO_aead_decrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_SECRET, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageSecret::iv, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageSecret::mac, result, GNUNET_MESSENGER_MessageBody::secret, and unfold_short_message().

Referenced by update_room_secret_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_transcript_message()

enum GNUNET_GenericReturnValue read_transcript_message ( struct GNUNET_MESSENGER_Message message)

Read the original message from a transcript message and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage transcript
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1877 of file messenger_api_message.c.

1878{
1879 uint16_t data_length;
1880 struct GNUNET_MESSENGER_ShortMessage shortened;
1881
1882 GNUNET_assert ((message) &&
1884
1885 data_length = message->body.transcript.length;
1886
1887 if (GNUNET_YES != decode_short_message (&shortened,
1888 data_length,
1889 message->body.transcript.data))
1890 {
1892 "Decoding decrypted message failed!\n");
1893
1894 return GNUNET_NO;
1895 }
1896
1897 unfold_short_message (&shortened, message);
1898 return GNUNET_YES;
1899}

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageTranscript::data, decode_short_message(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageBody::transcript, and unfold_short_message().

Referenced by handle_transcript_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_access_message_key()

enum GNUNET_GenericReturnValue extract_access_message_key ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_HpkePrivateKey key,
struct GNUNET_CRYPTO_AeadSecretKey shared_key 
)

Extracts the shared epoch or group key from an access message using the private ephemeral key from an epoch and verifies it via the HMAC from the message body.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in]messageAccess message
[in]keyPrivate ephemeral key
[out]shared_keyShared key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1903 of file messenger_api_message.c.

1907{
1908 GNUNET_assert ((message) && (key) && (shared_key) &&
1910
1911 if (GNUNET_OK !=
1913 (uint8_t*) "messenger",
1914 strlen ("messenger"),
1915 NULL, 0,
1916 (uint8_t*) message->body.access.key,
1918 (uint8_t*) shared_key,
1919 NULL))
1920 {
1921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1922 return GNUNET_NO;
1923 }
1924
1925 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1926 {
1927 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1928 return GNUNET_NO;
1929 }
1930
1931 return GNUNET_YES;
1932}
#define GNUNET_MESSENGER_ACCESS_KEY_BYTES
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key)
Verifies the hmac of a given message body with a specific shared key.

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_Message::body, GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_ACCESS_KEY_BYTES, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageHeader::kind, and verify_message_by_key().

Referenced by handle_epoch_announcement_access(), and handle_epoch_group_access().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_authorization_message_key()

enum GNUNET_GenericReturnValue extract_authorization_message_key ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_AeadSecretKey key,
struct GNUNET_CRYPTO_AeadSecretKey shared_key 
)

Extracts the shared epoch or group key from an authorization message using a previously exchanged shared key and verifies it via the HMAC from the message body.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in]messageAccess message
[in]keyPrevious shared key
[out]shared_keyShared key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1936 of file messenger_api_message.c.

1941{
1942 struct GNUNET_CRYPTO_AeadNonce iv;
1943
1944 GNUNET_assert ((message) && (key) && (shared_key) &&
1946
1948 &iv, sizeof (iv),
1951 key,
1952 sizeof (*key),
1955 {
1957 "Deriving initialization vector failed!\n");
1958 return GNUNET_NO;
1959 }
1960
1962 ,
1963 message->body.authorization.key,
1964 0,
1965 NULL,
1966 key,
1967 &iv,
1968 &message->body.authorization.mac,
1969 shared_key))
1970 {
1971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1972 return GNUNET_NO;
1973 }
1974
1975 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1976 {
1977 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1978 return GNUNET_NO;
1979 }
1980
1981 return GNUNET_YES;
1982}
#define GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES
type for session keys
struct GNUNET_CRYPTO_AeadMac mac
The mac of the key.

References GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_assert, GNUNET_CRYPTO_aead_decrypt(), GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg_auto, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_SALT_GROUP_KEY, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAuthorization::identifier, key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageAuthorization::mac, and verify_message_by_key().

Referenced by handle_authorization_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_timeout()

struct GNUNET_TIME_Relative get_message_timeout ( const struct GNUNET_MESSENGER_Message message)

Return the relative timeout of the content from a given message that controls when a delayed handling action of this message needs to be processed at least.

Parameters
[in]messageMessage
Returns
Relative timeout of message

Definition at line 1986 of file messenger_api_message.c.

1987{
1990
1991 GNUNET_assert (message);
1992
1994
1995 switch (message->header.kind)
1996 {
1999 break;
2002 break;
2005 break;
2008 break;
2009 default:
2011 break;
2012 }
2013
2015
2019
2020 return timeout;
2021}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
static uint64_t timestamp(void)
Get current timestamp.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition time.c:344
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition time.c:133
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
Definition time.c:178
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
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
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

References GNUNET_assert, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_GROUP, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_get_minute_(), GNUNET_TIME_relative_get_zero_(), GNUNET_TIME_relative_min(), GNUNET_TIME_relative_ntoh(), timeout, and timestamp().

Referenced by handle_appeal_message(), handle_delete_message(), handle_epoch_announcement(), handle_epoch_announcement_delay(), handle_message_delete(), handle_room_delayed_deletion(), and set_epoch_proposal_group().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pack_message()

struct GNUNET_MQ_Envelope * pack_message ( struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash,
enum GNUNET_MESSENGER_PackMode  mode 
)

Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE.

Independent of the mode the message will be hashed if hash is not NULL.

Parameters
[out]messageMessage
[out]hashHash of message
[in]modeMode of packing
Returns
Envelope or NULL

Definition at line 2025 of file messenger_api_message.c.

2028{
2029 struct GNUNET_MessageHeader *header;
2030 uint16_t length, padded_length;
2031 struct GNUNET_MQ_Envelope *env;
2032 char *buffer;
2033
2034 GNUNET_assert (message);
2035
2037 "Packing message kind=%u and sender: %s\n",
2038 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2039
2040 length = get_message_size (message, GNUNET_YES);
2041 padded_length = calc_padded_length (length);
2042
2044 {
2045 env = GNUNET_MQ_msg_extra (header, padded_length,
2047 buffer = (char*) &(header[1]);
2048 }
2049 else
2050 {
2051 env = NULL;
2052 buffer = GNUNET_malloc (padded_length);
2053 }
2054
2055 encode_message (message, padded_length, buffer, GNUNET_YES);
2056
2057 if (hash)
2058 hash_message (message, length, buffer, hash);
2059
2061 GNUNET_free (buffer);
2062
2063 return env;
2064}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static enum @52 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximum length in bytes.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
Header for all communications.

References calc_padded_length(), encode_message(), env, get_message_size(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_MQ_msg_extra, GNUNET_sh2s(), GNUNET_YES, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, mode, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by forward_tunnel_message(), handle_tunnel_message(), and sign_srv_room_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_peer_message()

enum GNUNET_GenericReturnValue is_peer_message ( const struct GNUNET_MESSENGER_Message message)

Returns whether a specific kind of message can be sent by the service without usage of a clients private key.

The function returns GNUNET_YES if the kind of message can be signed via a peer's identity, otherwise GNUNET_NO.

Parameters
[in]messageMessage
Returns
GNUNET_YES if sending is allowed, GNUNET_NO otherwise

Definition at line 2068 of file messenger_api_message.c.

2069{
2070 GNUNET_assert (message);
2071
2072 switch (message->header.kind)
2073 {
2079 return GNUNET_YES;
2080 default:
2081 return GNUNET_NO;
2082 }
2083}

References GNUNET_assert, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by callback_found_message(), callback_room_handle_message(), enqueue_message_control(), filter_message_sending(), get_store_member_of(), get_store_peer_of(), handle_room_messages(), is_service_message(), notify_about_members(), notify_srv_handle_message(), process_message_control(), sign_srv_room_message(), and task_message_control().

Here is the caller graph for this function:

◆ is_service_message()

enum GNUNET_GenericReturnValue is_service_message ( const struct GNUNET_MESSENGER_Message message)

Returns whether a specific kind of message contains service critical information.

That kind of information should not be encrypted via private messages for example to guarantee the service to work properly. The function returns GNUNET_YES if the kind of message needs to be transferred accessible to all peers and their running service. It returns GNUNET_NO if the message can be encrypted to specific subgroups of members without issues. If the kind of message is unknown it returns GNUNET_SYSERR.

Parameters
[in]messageMessage
Returns
GNUNET_YES if encrypting is disallowed, GNUNET_NO or GNUNET_SYSERR otherwise

Definition at line 2087 of file messenger_api_message.c.

2088{
2089 GNUNET_assert (message);
2090
2091 if (GNUNET_YES == is_peer_message (message))
2092 return GNUNET_YES;
2093
2094 switch (message->header.kind)
2095 {
2097 return GNUNET_YES; // Reserved for connection handling only!
2099 return GNUNET_YES; // Reserved for member handling only!
2101 return GNUNET_YES; // Reserved for member handling only!
2103 return GNUNET_YES; // Reserved for member name handling only!
2105 return GNUNET_YES; // Reserved for member key handling only!
2107 return GNUNET_YES; // Reserved for connection handling only!
2109 return GNUNET_YES; // Reserved for member id handling only!
2111 return GNUNET_YES; // Reserved for connection handling only!
2113 return GNUNET_YES; // Reserved for peers only!
2115 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2117 return GNUNET_NO;
2119 return GNUNET_NO;
2121 return GNUNET_NO;
2123 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2125 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2127 return GNUNET_YES; // Reserved for connection handling only!
2129 return GNUNET_NO;
2131 return GNUNET_NO;
2133 return GNUNET_NO;
2135 return GNUNET_YES; // Reserved for subscription handling only!
2137 return GNUNET_NO;
2139 return GNUNET_YES; // Reserved for epoch and group key exchange!
2141 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2143 return GNUNET_YES; // Reserved for epoch key exchange!
2145 return GNUNET_YES; // Reserved for epoch and group key exchange!
2147 return GNUNET_YES; // Reserved for epoch and group key revoking!
2149 return GNUNET_YES; // Reserved for group key exchange!
2151 return GNUNET_YES; // Reserved for epoch and group key exchange!
2152 default:
2153 return GNUNET_SYSERR;
2154 }
2155}
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...

References GNUNET_assert, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_peer_message(), and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by encrypt_message(), send_message_to_room(), and transcribe_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_epoch_message()

enum GNUNET_GenericReturnValue is_epoch_message ( const struct GNUNET_MESSENGER_Message message)

Returns whether a certain kind of message from storage contains some specific details that might be required for the overall message graph to function as intended.

The function returns GNUNET_YES if you may not delete the given message because of that, otherwise it returns GNUNET_NO.

Parameters
[in]messageMessage
Returns
GNUNET_YES if the message contains epoch graph information, GNUNET_NO otherwise

Definition at line 2159 of file messenger_api_message.c.

2160{
2161 GNUNET_assert (message);
2162
2163 switch (message->header.kind)
2164 {
2166 return GNUNET_YES;
2168 return GNUNET_YES;
2170 return GNUNET_YES;
2171 default:
2172 return GNUNET_NO;
2173 }
2174}

References GNUNET_assert, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by delete_store_message(), GNUNET_MESSENGER_delete_message(), handle_message(), request_room_message_step(), send_message_to_room(), and sign_srv_room_message().

Here is the caller graph for this function:

◆ filter_message_sending()

enum GNUNET_GenericReturnValue filter_message_sending ( const struct GNUNET_MESSENGER_Message message)

Returns whether a specific kind of message should be sent by a client.

The function returns GNUNET_YES or GNUNET_NO for recommendations and GNUNET_SYSERR for specific kinds of messages which should not be sent manually at all.

Parameters
[in]messageMessage
Returns
GNUNET_YES if sending is allowed, GNUNET_NO or GNUNET_SYSERR otherwise

Definition at line 2178 of file messenger_api_message.c.

2179{
2180 GNUNET_assert (message);
2181
2182 if (GNUNET_YES == is_peer_message (message))
2183 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2184
2185 switch (message->header.kind)
2186 {
2188 return GNUNET_SYSERR; // Reserved for connection handling only!
2190 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2192 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2194 return GNUNET_YES;
2196 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2198 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2200 return GNUNET_NO; // Reserved for member id handling only!
2202 return GNUNET_SYSERR; // Reserved for connection handling only!
2204 return GNUNET_SYSERR; // Reserved for peers only!
2206 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2208 return GNUNET_YES;
2210 return GNUNET_YES;
2212 return GNUNET_YES;
2214 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2216 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2218 return GNUNET_SYSERR; // Reserved for connection handling only!
2220 return GNUNET_YES;
2222 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2224 return GNUNET_YES;
2226 return GNUNET_YES;
2228 return GNUNET_YES;
2230 return GNUNET_NO; // Should only be used for implicit key exchange!
2232 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2234 return GNUNET_NO; // Should only be used for implicit key exchange!
2236 return GNUNET_NO; // Should only be used for implicit key exchange!
2238 return GNUNET_NO; // Should only be used for implicit key exchange!
2240 return GNUNET_NO; // Should only be used for implicit key exchange!
2242 return GNUNET_NO; // Should only be used for implicit key exchange!
2243 default:
2244 return GNUNET_SYSERR;
2245 }
2246}

References GNUNET_assert, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_peer_message(), and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by check_send_message(), and GNUNET_MESSENGER_send_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_discourse()

const struct GNUNET_ShortHashCode * get_message_discourse ( const struct GNUNET_MESSENGER_Message message)

Returns the discourse hash of a message depending on its kind.

If a message contains a discourse hash it will not be stored locally on peers.

Parameters
[in]messageMessage
Returns
Discourse hash of message or NULL

Definition at line 2250 of file messenger_api_message.c.

2251{
2252 GNUNET_assert (message);
2253
2254 switch (message->header.kind)
2255 {
2257 return &(message->body.subscription.discourse);
2259 return &(message->body.talk.discourse);
2260 default:
2261 return NULL;
2262 }
2263}

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_assert, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::subscription, and GNUNET_MESSENGER_MessageBody::talk.

Referenced by handle_message_control(), iterate_flag_for_cleanup_discourse_message(), put_store_message(), send_message_to_room(), and update_message_state().

Here is the caller graph for this function:

Variable Documentation

◆ encryption_overhead

const uint16_t encryption_overhead
Initial value:

Definition at line 36 of file messenger_api_message.c.

Referenced by decrypt_message(), and encrypt_message().