GNUnet 0.25.2-11-g84e94e98c
 
Loading...
Searching...
No Matches
messenger_api_message.c File Reference
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_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)
 

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 (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 maximal 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 maximal 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, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
 Signs the hash of a message with a given private key and writes the signature into the buffer as well.
 
void sign_message_by_peer (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Signs the hash of a message with the peer identity of a given config and writes the signature into the buffer as well.
 
static void calc_message_hmac (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_HashCode *hmac)
 
void sign_message_by_key (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *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_SymmetricSessionKey *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_BlindablePublicKey *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_BlindablePrivateKey *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_SymmetricSessionKey *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_SymmetricSessionKey *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_SymmetricSessionKey *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_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *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, const GNUNET_MESSENGER_SignFunction sign, enum GNUNET_MESSENGER_PackMode mode, const void *cls)
 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 300 of file messenger_api_message.c.

◆ max

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

Definition at line 588 of file messenger_api_message.c.

◆ min

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

Definition at line 617 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 619 of file messenger_api_message.c.

619 { \
620 GNUNET_memcpy (dst + offset, src, size); \
621 offset += size; \
622} 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 624 of file messenger_api_message.c.

624 { \
625 encode_step_ext (dst, offset, src, sizeof(*src)); \
626} 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 628 of file messenger_api_message.c.

628 { \
630 src, dst + offset, length - offset); \
631 if (result < 0) \
632 GNUNET_break (0); \
633 else \
634 offset += result; \
635} 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 637 of file messenger_api_message.c.

637 { \
639 src, dst + offset, length - offset); \
640 if (result < 0) \
641 GNUNET_break (0); \
642 else \
643 offset += result; \
644} 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 907 of file messenger_api_message.c.

907 { \
908 GNUNET_memcpy (dst, src + offset, size); \
909 offset += size; \
910} 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 912 of file messenger_api_message.c.

912 { \
913 decode_step_ext (src, offset, dst, sizeof(*dst)); \
914} 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 916 of file messenger_api_message.c.

916 { \
917 dst = GNUNET_malloc (size + zero); \
918 if (zero) dst[size] = 0; \
919 decode_step_ext (src, offset, dst, size); \
920} 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_public_key_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 922 of file messenger_api_message.c.

922 { \
924 size_t read; \
926 src + offset, length - offset, dst, &read); \
927 if (GNUNET_SYSERR == result) \
928 GNUNET_break (0); \
929 else \
930 offset += read; \
931} while (0)

Typedef Documentation

◆ kind_t

typedef uint32_t kind_t

Definition at line 454 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 48 of file messenger_api_message.c.

49{
50 struct GNUNET_MESSENGER_Message *message;
51
52 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
53 message->header.kind = kind;
54
55 switch (message->header.kind)
56 {
58 message->body.name.name = NULL;
59 break;
61 message->body.text.text = NULL;
62 break;
64 message->body.file.uri = NULL;
65 break;
67 message->body.privacy.length = 0;
68 message->body.privacy.data = NULL;
69 break;
71 message->body.ticket.identifier = NULL;
72 break;
74 message->body.transcript.length = 0;
75 message->body.transcript.data = NULL;
76 break;
78 message->body.tag.tag = NULL;
79 break;
81 message->body.talk.length = 0;
82 message->body.talk.data = NULL;
83 break;
85 message->body.secret.length = 0;
86 message->body.secret.data = NULL;
87 break;
88 default:
89 break;
90 }
91
92 return message;
93}
#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
char * uri
The uri of the encrypted file.
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 97 of file messenger_api_message.c.

98{
99 struct GNUNET_MESSENGER_Message *copy;
100
101 GNUNET_assert (message);
102
103 copy = GNUNET_new (struct GNUNET_MESSENGER_Message);
104 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
105
106 switch (message->header.kind)
107 {
109 copy->body.name.name = message->body.name.name? GNUNET_strdup (
110 message->body.name.name) : NULL;
111 break;
113 copy->body.text.text = message->body.text.text? GNUNET_strdup (
114 message->body.text.text) : NULL;
115 break;
117 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
118 message->body.file.uri) : NULL;
119 break;
122 copy->body.privacy.length) : NULL;
123
124 if (copy->body.privacy.data)
125 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
126 copy->body.privacy.length);
127
128 break;
130 copy->body.ticket.identifier = message->body.ticket.identifier?
132 message->body.ticket.identifier) : NULL;
133 break;
136 copy->body.transcript.length) : NULL;
137
138 if (copy->body.transcript.data)
140 copy->body.transcript.length);
141
142 break;
144 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
145 message->body.tag.tag) : NULL;
146 break;
148 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
149 copy->body.talk.length) : NULL;
150
151 if (copy->body.talk.data)
152 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
153 copy->body.talk.length);
154
155 break;
157 copy->body.secret.data = copy->body.secret.length ? GNUNET_malloc (
158 copy->body.secret.length) : NULL;
159
160 if (copy->body.secret.data)
161 GNUNET_memcpy (copy->body.secret.data, message->body.secret.data,
162 copy->body.secret.length);
163
164 break;
165 default:
166 break;
167 }
168
169 return copy;
170}
#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 174 of file messenger_api_message.c.

176{
178
179 GNUNET_assert ((message) && (header));
180
181 kind = message->header.kind;
182
183 GNUNET_memcpy (&(message->header), header,
184 sizeof(struct GNUNET_MESSENGER_MessageHeader));
185
186 message->header.kind = kind;
187}
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 191 of file messenger_api_message.c.

193{
194 GNUNET_assert (body);
195
196 switch (kind)
197 {
199 if (body->name.name)
200 GNUNET_free (body->name.name);
201 break;
203 if (body->text.text)
204 GNUNET_free (body->text.text);
205 break;
207 if (body->file.uri)
208 GNUNET_free (body->file.uri);
209 break;
211 if (body->privacy.data)
212 GNUNET_free (body->privacy.data);
213 break;
215 if (body->ticket.identifier)
217 break;
219 if (body->transcript.data)
221 break;
223 if (body->tag.tag)
224 GNUNET_free (body->tag.tag);
225 break;
227 if (body->talk.data)
228 GNUNET_free (body->talk.data);
229 break;
231 if (body->secret.data)
232 GNUNET_free (body->secret.data);
233 break;
234 default:
235 break;
236 }
237}
#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 241 of file messenger_api_message.c.

242{
243 GNUNET_assert (message);
244
245 destroy_message_body (message->header.kind, &(message->body));
246}
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 250 of file messenger_api_message.c.

251{
252 GNUNET_assert (message);
253
254 destroy_message_body (message->header.kind, &(message->body));
255
256 GNUNET_free (message);
257}

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

Referenced by clear_queue_messages(), create_message_access(), create_message_authorization(), create_message_peer(), 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_destroy_message(), iterate_destroy_messages(), iterate_destroy_subscription(), iterate_flag_for_cleanup_discourse_message(), keep_subscription_alive(), send_message_to_room_with_key(), send_tunnel_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 261 of file messenger_api_message.c.

262{
263 GNUNET_assert (message);
264
265 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
267 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
268 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
270 return GNUNET_YES;
271 else
272 return GNUNET_NO;
273}
@ 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 277 of file messenger_api_message.c.

279{
280 shortened->kind = message->header.kind;
281
282 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
284}
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 288 of file messenger_api_message.c.

290{
291 destroy_message_body (message->header.kind, &(message->body));
292
293 message->header.kind = shortened->kind;
294
295 GNUNET_memcpy (&(message->body), &(shortened->body),
296 sizeof(struct GNUNET_MESSENGER_MessageBody));
297}

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 303 of file messenger_api_message.c.

304{
305 uint16_t length;
306
307 length = 0;
308
309 switch (kind)
310 {
312 length += member_size (struct GNUNET_MESSENGER_Message,
313 body.info.messenger_version);
314 break;
316 length += member_size (struct GNUNET_MESSENGER_Message,
317 body.join.epoch);
318 break;
320 length += member_size (struct GNUNET_MESSENGER_Message,
321 body.leave.epoch);
322 break;
324 length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer);
325 break;
327 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
328 break;
330 length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer);
331 break;
333 length += member_size (struct GNUNET_MESSENGER_Message,
334 body.merge.epochs[0]);
335 length += member_size (struct GNUNET_MESSENGER_Message,
336 body.merge.epochs[1]);
337 length += member_size (struct GNUNET_MESSENGER_Message,
338 body.merge.previous);
339 break;
341 length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash);
342 break;
344 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door);
345 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key);
346 break;
348 length += member_size (struct GNUNET_MESSENGER_Message, body.file.key);
349 length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash);
350 length += member_size (struct GNUNET_MESSENGER_Message, body.file.name);
351 break;
353 length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash);
354 length += member_size (struct GNUNET_MESSENGER_Message,
355 body.deletion.delay);
356 break;
358 length += member_size (struct GNUNET_MESSENGER_Message,
359 body.connection.amount);
360 length += member_size (struct GNUNET_MESSENGER_Message,
361 body.connection.flags);
362 break;
364 length += member_size (struct GNUNET_MESSENGER_Message,
365 body.transcript.hash);
366 break;
368 length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash);
369 break;
371 length += member_size (struct GNUNET_MESSENGER_Message,
372 body.subscription.discourse);
373 length += member_size (struct GNUNET_MESSENGER_Message,
374 body.subscription.time);
375 length += member_size (struct GNUNET_MESSENGER_Message,
376 body.subscription.flags);
377 break;
379 length += member_size (struct GNUNET_MESSENGER_Message,
380 body.talk.discourse);
381 break;
383 length += member_size (struct GNUNET_MESSENGER_Message,
384 body.announcement.identifier);
385 length += member_size (struct GNUNET_MESSENGER_Message,
386 body.announcement.key);
387 length += member_size (struct GNUNET_MESSENGER_Message,
388 body.announcement.nonce);
389 length += member_size (struct GNUNET_MESSENGER_Message,
390 body.announcement.timeout);
391 length += member_size (struct GNUNET_MESSENGER_Message,
392 body.announcement.hmac);
393 break;
395 length += member_size (struct GNUNET_MESSENGER_Message,
396 body.secret.identifier);
397 length += member_size (struct GNUNET_MESSENGER_Message,
398 body.secret.iv);
399 length += member_size (struct GNUNET_MESSENGER_Message,
400 body.secret.hmac);
401 break;
403 length += member_size (struct GNUNET_MESSENGER_Message,
404 body.appeal.event);
405 length += member_size (struct GNUNET_MESSENGER_Message,
406 body.appeal.key);
407 length += member_size (struct GNUNET_MESSENGER_Message,
408 body.appeal.timeout);
409 break;
411 length += member_size (struct GNUNET_MESSENGER_Message,
412 body.access.event);
413 length += member_size (struct GNUNET_MESSENGER_Message,
414 body.access.key);
415 length += member_size (struct GNUNET_MESSENGER_Message,
416 body.access.hmac);
417 break;
419 length += member_size (struct GNUNET_MESSENGER_Message,
420 body.revolution.identifier);
421 length += member_size (struct GNUNET_MESSENGER_Message,
422 body.revolution.nonce);
423 length += member_size (struct GNUNET_MESSENGER_Message,
424 body.revolution.hmac);
425 break;
427 length += member_size (struct GNUNET_MESSENGER_Message,
428 body.group.identifier);
429 length += member_size (struct GNUNET_MESSENGER_Message,
430 body.group.initiator);
431 length += member_size (struct GNUNET_MESSENGER_Message,
432 body.group.partner);
433 length += member_size (struct GNUNET_MESSENGER_Message,
434 body.group.timeout);
435 break;
437 length += member_size (struct GNUNET_MESSENGER_Message,
438 body.authorization.identifier);
439 length += member_size (struct GNUNET_MESSENGER_Message,
440 body.authorization.event);
441 length += member_size (struct GNUNET_MESSENGER_Message,
442 body.authorization.key);
443 length += member_size (struct GNUNET_MESSENGER_Message,
444 body.authorization.hmac);
445 break;
446 default:
447 break;
448 }
449
450 return length;
451}
@ 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_MessageSecret::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_MessageFile::key, GNUNET_MESSENGER_MessageAnnouncement::key, GNUNET_MESSENGER_MessageAppeal::key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageBody::leave, 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 457 of file messenger_api_message.c.

459{
460 uint16_t length;
461
462 length = 0;
463
464 if (GNUNET_YES == include_header)
465 {
466 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
467 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
468 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
469 }
470
471 length += sizeof(kind_t);
472
473 return length + get_message_body_kind_size (kind);
474}
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 478 of file messenger_api_message.c.

480{
481 uint16_t length;
482
483 length = 0;
484
485 switch (kind)
486 {
488 length += GNUNET_CRYPTO_public_key_get_length (&(body->join.key));
489 break;
491 length += (body->name.name ? strlen (body->name.name) : 0);
492 break;
494 length += GNUNET_CRYPTO_public_key_get_length (&(body->key.key));
495 break;
497 length += (body->text.text ? strlen (body->text.text) : 0);
498 break;
500 length += (body->file.uri ? strlen (body->file.uri) : 0);
501 break;
503 length += body->privacy.length;
504 break;
506 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
507 break;
510 length += body->transcript.length;
511 break;
513 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
514 break;
516 length += body->talk.length;
517 break;
519 length += body->secret.length;
520 break;
521 default:
522 break;
523 }
524
525 return length;
526}
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_BlindablePublicKey.
Definition crypto_pkey.c:85
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_CRYPTO_BlindablePublicKey key
The senders public key to verify its signatures.
struct GNUNET_CRYPTO_BlindablePublicKey key
The new public key which replaces the current senders 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_public_key_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_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 530 of file messenger_api_message.c.

532{
533 uint16_t length;
534
535 GNUNET_assert (message);
536
537 length = 0;
538
539 if (GNUNET_YES == include_header)
541 &(message->header.signature));
542
543 length += get_message_kind_size (message->header.kind, include_header);
544 length += get_message_body_size (message->header.kind, &(message->body));
545
546 return length;
547}
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 551 of file messenger_api_message.c.

553{
554 uint16_t minimum_size;
555
556 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
557
558 if (message)
559 return minimum_size + get_message_body_kind_size (message->kind)
560 + (include_body == GNUNET_YES?
561 get_message_body_size (message->kind, &(message->body)) : 0);
562 else
563 return minimum_size;
564}
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 568 of file messenger_api_message.c.

569{
570 uint16_t padding;
571 uint16_t kind_size;
572
573 padding = 0;
574
575 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
576 {
578 GNUNET_YES);
579
580 if (kind_size > padding)
581 padding = kind_size;
582 }
583
584 return padding + GNUNET_MESSENGER_PADDING_MIN;
585}
#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 591 of file messenger_api_message.c.

592{
593 static uint16_t usual_padding = 0;
594 uint16_t padded_length;
595
596 if (! usual_padding)
597 usual_padding = calc_usual_padding ();
598
599 padded_length = max (
601 usual_padding);
602
603 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
605
606 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
608
609 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
611
613
614}
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 647 of file messenger_api_message.c.

652{
653 uint32_t value0, value1;
654
655 GNUNET_assert ((body) && (buffer));
656
657 switch (kind)
658 {
660 value0 = GNUNET_htobe32 (body->info.messenger_version);
661
662 encode_step (buffer, offset, &value0);
663 break;
665 encode_step (buffer, offset, &(body->join.epoch));
666 encode_step_key (buffer, offset, &(body->join.key), length);
667 break;
669 encode_step (buffer, offset, &(body->leave.epoch));
670 break;
672 if (body->name.name)
674 buffer,
675 offset,
676 body->name.name,
677 min (length - offset, strlen (body->name.name)));
678 break;
680 encode_step_key (buffer, offset, &(body->key.key), length);
681 break;
683 encode_step (buffer, offset, &(body->peer.peer));
684 break;
686 encode_step (buffer, offset, &(body->id.id));
687 break;
689 encode_step (buffer, offset, &(body->miss.peer));
690 break;
692 encode_step (buffer, offset, &(body->merge.epochs[0]));
693 encode_step (buffer, offset, &(body->merge.epochs[1]));
694 encode_step (buffer, offset, &(body->merge.previous));
695 break;
697 encode_step (buffer, offset, &(body->request.hash));
698 break;
700 encode_step (buffer, offset, &(body->invite.door));
701 encode_step (buffer, offset, &(body->invite.key));
702 break;
704 if (body->text.text)
706 buffer,
707 offset,
708 body->text.text,
709 min (length - offset, strlen (body->text.text)));
710 break;
712 encode_step (buffer, offset, &(body->file.key));
713 encode_step (buffer, offset, &(body->file.hash));
714 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
715 if (body->file.uri)
716 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
717 strlen (
718 body->file.uri)));
719 break;
721 if (body->privacy.data)
722 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
723 body->privacy.
724 length));
725 break;
727 encode_step (buffer, offset, &(body->deletion.hash));
728 encode_step (buffer, offset, &(body->deletion.delay));
729 break;
731 value0 = GNUNET_htobe32 (body->connection.amount);
732 value1 = GNUNET_htobe32 (body->connection.flags);
733
734 encode_step (buffer, offset, &value0);
735 encode_step (buffer, offset, &value1);
736 break;
738 encode_step_ext (buffer, offset, body->ticket.identifier,
739 min (length - offset, strlen (body->ticket.identifier)));
740 break;
742 encode_step (buffer, offset, &(body->transcript.hash));
743 encode_step_key (buffer, offset, &(body->transcript.key), length);
744
745 if (body->transcript.data)
746 encode_step_ext (buffer, offset, body->transcript.data, min (length
747 - offset,
748 body->
749 transcript.
750 length));
751 break;
753 encode_step (buffer, offset, &(body->tag.hash));
754
755 if (body->tag.tag)
756 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
757 strlen (
758 body->tag.tag)));
759 break;
761 value0 = GNUNET_htobe32 (body->subscription.flags);
762
763 encode_step (buffer, offset, &(body->subscription.discourse));
764 encode_step (buffer, offset, &(body->subscription.time));
765 encode_step (buffer, offset, &value0);
766 break;
768 encode_step (buffer, offset, &(body->talk.discourse));
769
770 if (body->talk.data)
771 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
772 body->talk.
773 length));
774 break;
776 encode_step (buffer, offset, &(body->announcement.identifier));
777 encode_step (buffer, offset, &(body->announcement.key));
778 encode_step (buffer, offset, &(body->announcement.nonce));
779 encode_step (buffer, offset, &(body->announcement.timeout));
780 encode_step (buffer, offset, &(body->announcement.hmac));
781 break;
783 encode_step (buffer, offset, &(body->secret.identifier));
784 encode_step (buffer, offset, &(body->secret.iv));
785 encode_step (buffer, offset, &(body->secret.hmac));
786
787 if (body->secret.data)
788 encode_step_ext (buffer, offset, body->secret.data, min (length - offset,
789 body->secret.
790 length));
791 break;
793 encode_step (buffer, offset, &(body->appeal.event));
794 encode_step (buffer, offset, &(body->appeal.key));
795 encode_step (buffer, offset, &(body->appeal.timeout));
796 break;
798 encode_step (buffer, offset, &(body->access.event));
799 encode_step (buffer, offset, &(body->access.key));
800 encode_step (buffer, offset, &(body->access.hmac));
801 break;
803 encode_step (buffer, offset, &(body->revolution.identifier));
804 encode_step (buffer, offset, &(body->revolution.nonce));
805 encode_step (buffer, offset, &(body->revolution.hmac));
806 break;
808 encode_step (buffer, offset, &(body->group.identifier));
809 encode_step (buffer, offset, &(body->group.initiator));
810 encode_step (buffer, offset, &(body->group.partner));
811 encode_step (buffer, offset, &(body->group.timeout));
812 break;
814 encode_step (buffer, offset, &(body->authorization.identifier));
815 encode_step (buffer, offset, &(body->authorization.event));
816 encode_step (buffer, offset, &(body->authorization.key));
817 encode_step (buffer, offset, &(body->authorization.hmac));
818 break;
819 default:
820 break;
821 }
822
823 if (offset >= length)
824 return;
825
826 {
827 uint16_t padding;
828 uint16_t used_padding;
829
830 padding = length - offset;
831 used_padding = sizeof(padding) + sizeof(char);
832
833 GNUNET_assert (padding >= used_padding);
834
835 buffer[offset++] = '\0';
836
837 if (padding > used_padding)
839 padding - used_padding);
840
841 GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
842 sizeof(padding));
843 }
844}
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_htobe32(x)
#define encode_step_ext(dst, offset, src, size)
#define encode_step(dst, offset, src)
#define min(x, y)
#define encode_step_key(dst, offset, src, length)
struct GNUNET_HashCode hmac
The hmac of the access.
struct GNUNET_HashCode event
The hash of the linked announcement or group message event.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)+16+sizeof(struct GNUNET_CRYPTO_HpkeEncapsulation)]
The encrypted group or epoch key.
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_SymmetricSessionKey)]
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.
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
char name[NAME_MAX]
The name of the original 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.
uint8_t iv[sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector)]
The IV of the secret message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_HashCode hmac
The hmac of the encrypted 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_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_QUALITY_WEAK, 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_MessageSecret::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, 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_MessageFile::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_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()

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 maximal length in bytes.

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

Definition at line 848 of file messenger_api_message.c.

852{
853 uint16_t offset;
854 kind_t kind;
855
856 GNUNET_assert ((message) && (buffer));
857
858 offset = 0;
859
860 if (GNUNET_YES == include_header)
861 encode_step_signature (buffer, offset, &(message->header.signature),
862 length);
863
864 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
865
866 if (GNUNET_YES == include_header)
867 {
868 encode_step (buffer, offset, &(message->header.timestamp));
869 encode_step (buffer, offset, &(message->header.sender_id));
870 encode_step (buffer, offset, &(message->header.previous));
871 }
872
873 encode_step (buffer, offset, &kind);
874
875 encode_message_body (message->header.kind, &(message->body),
876 length, buffer, offset);
877}
static void encode_message_body(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
#define encode_step_signature(dst, offset, src, length)
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 881 of file messenger_api_message.c.

884{
885 struct GNUNET_HashCode hash;
886 uint16_t offset;
887 kind_t kind;
888
889 GNUNET_assert ((message) && (buffer));
890
891 offset = sizeof(hash);
892 kind = GNUNET_htobe32 ((kind_t) message->kind);
893
894 encode_step (buffer, offset, &kind);
895
896 encode_message_body (message->kind, &(message->body), length, buffer, offset);
897
899 buffer + sizeof(hash),
900 length - sizeof(hash),
901 &hash);
902
903 GNUNET_memcpy (buffer, &hash, sizeof(hash));
904}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41

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 934 of file messenger_api_message.c.

939{
940 uint16_t padding;
941 uint32_t value0, value1;
942
943 GNUNET_assert ((kind) && (body) && (buffer));
944
945 padding = 0;
946
947 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
948
949 if (padding > length - offset)
950 padding = 0;
951
952 {
953 uint16_t end_zero;
954 end_zero = length - padding;
955
956 if ((padding) && (buffer[end_zero] != '\0'))
957 padding = 0;
958 }
959
960 length -= padding;
961
962 switch (*kind)
963 {
965 decode_step (buffer, offset, &value0);
966
967 body->info.messenger_version = GNUNET_be32toh (value0);
968 break;
970 decode_step (buffer, offset, &(body->join.epoch));
971 decode_step_key (buffer, offset, &(body->join.key), length);
972 break;
974 decode_step (buffer, offset, &(body->leave.epoch));
975 break;
977 if (length > offset)
978 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
979 else
980 body->name.name = NULL;
981 break;
983 decode_step_key (buffer, offset, &(body->key.key), length);
984 break;
986 decode_step (buffer, offset, &(body->peer.peer));
987 break;
989 decode_step (buffer, offset, &(body->id.id));
990 break;
992 decode_step (buffer, offset, &(body->miss.peer));
993 break;
995 decode_step (buffer, offset, &(body->merge.epochs[0]));
996 decode_step (buffer, offset, &(body->merge.epochs[1]));
997 decode_step (buffer, offset, &(body->merge.previous));
998 break;
1000 decode_step (buffer, offset, &(body->request.hash));
1001 break;
1003 decode_step (buffer, offset, &(body->invite.door));
1004 decode_step (buffer, offset, &(body->invite.key));
1005 break;
1007 if (length > offset)
1008 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
1009 else
1010 body->text.text = NULL;
1011 break;
1013 decode_step (buffer, offset, &(body->file.key));
1014 decode_step (buffer, offset, &(body->file.hash));
1015 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
1016 if (length > offset)
1017 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
1018 else
1019 body->file.uri = NULL;
1020 break;
1022 if (length > offset)
1023 {
1024 body->privacy.length = (length - offset);
1025 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
1026 0);
1027 }
1028 else
1029 {
1030 body->privacy.length = 0;
1031 body->privacy.data = NULL;
1032 }
1033
1034 break;
1036 decode_step (buffer, offset, &(body->deletion.hash));
1037 decode_step (buffer, offset, &(body->deletion.delay));
1038 break;
1040 decode_step (buffer, offset, &value0);
1041 decode_step (buffer, offset, &value1);
1042
1043 body->connection.amount = GNUNET_be32toh (value0);
1044 body->connection.flags = GNUNET_be32toh (value1);
1045 break;
1047 if (length > offset)
1048 decode_step_malloc (buffer, offset, body->ticket.identifier, length
1049 - offset, 1);
1050 else
1051 body->ticket.identifier = NULL;
1052 break;
1054 decode_step (buffer, offset, &(body->transcript.hash));
1055 decode_step_key (buffer, offset, &(body->transcript.key), length);
1056
1057 if (length > offset)
1058 {
1059 body->transcript.length = (length - offset);
1060 decode_step_malloc (buffer, offset, body->transcript.data,
1061 length - offset, 0);
1062 }
1063 else
1064 {
1065 body->transcript.length = 0;
1066 body->transcript.data = NULL;
1067 }
1068
1069 break;
1071 decode_step (buffer, offset, &(body->tag.hash));
1072 if (length > offset)
1073 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
1074 else
1075 body->tag.tag = NULL;
1076 break;
1078 decode_step (buffer, offset, &(body->subscription.discourse));
1079 decode_step (buffer, offset, &(body->subscription.time));
1080 decode_step (buffer, offset, &value0);
1081
1082 body->subscription.flags = GNUNET_be32toh (value0);
1083 break;
1085 decode_step (buffer, offset, &(body->talk.discourse));
1086
1087 if (length > offset)
1088 {
1089 body->talk.length = (length - offset);
1090 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
1091 0);
1092 }
1093 else
1094 {
1095 body->talk.length = 0;
1096 body->talk.data = NULL;
1097 }
1098
1099 break;
1101 decode_step (buffer, offset, &(body->announcement.identifier));
1102 decode_step (buffer, offset, &(body->announcement.key));
1103 decode_step (buffer, offset, &(body->announcement.nonce));
1104 decode_step (buffer, offset, &(body->announcement.timeout));
1105 decode_step (buffer, offset, &(body->announcement.hmac));
1106 break;
1108 decode_step (buffer, offset, &(body->secret.identifier));
1109 decode_step (buffer, offset, &(body->secret.iv));
1110 decode_step (buffer, offset, &(body->secret.hmac));
1111
1112 if (length > offset)
1113 {
1114 body->secret.length = (length - offset);
1115 decode_step_malloc (buffer, offset, body->secret.data, length - offset,
1116 0);
1117 }
1118 else
1119 {
1120 body->secret.length = 0;
1121 body->secret.data = NULL;
1122 }
1123
1124 break;
1126 decode_step (buffer, offset, &(body->appeal.event));
1127 decode_step (buffer, offset, &(body->appeal.key));
1128 decode_step (buffer, offset, &(body->appeal.timeout));
1129 break;
1131 decode_step (buffer, offset, &(body->access.event));
1132 decode_step (buffer, offset, &(body->access.key));
1133 decode_step (buffer, offset, &(body->access.hmac));
1134 break;
1136 decode_step (buffer, offset, &(body->revolution.identifier));
1137 decode_step (buffer, offset, &(body->revolution.nonce));
1138 decode_step (buffer, offset, &(body->revolution.hmac));
1139 break;
1141 decode_step (buffer, offset, &(body->group.identifier));
1142 decode_step (buffer, offset, &(body->group.initiator));
1143 decode_step (buffer, offset, &(body->group.partner));
1144 decode_step (buffer, offset, &(body->group.timeout));
1145 break;
1147 decode_step (buffer, offset, &(body->authorization.identifier));
1148 decode_step (buffer, offset, &(body->authorization.event));
1149 decode_step (buffer, offset, &(body->authorization.key));
1150 decode_step (buffer, offset, &(body->authorization.hmac));
1151 break;
1152 default:
1154 break;
1155 }
1156
1157 return padding;
1158}
#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_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_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_MessageSecret::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, 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_MessageFile::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_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 maximal 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 1162 of file messenger_api_message.c.

1167{
1168 uint16_t offset;
1169 uint16_t count;
1170 kind_t kind;
1171
1173 (message) &&
1174 (buffer) &&
1176 include_header)));
1177
1178 offset = 0;
1179
1180 if (GNUNET_YES == include_header)
1181 {
1182 ssize_t result;
1183
1185 &(message->header.signature), buffer, length - offset);
1186
1187 if (result < 0)
1188 return GNUNET_NO;
1189 else
1190 offset += result;
1191 }
1192
1193 count = length - offset;
1195 include_header))
1196 return GNUNET_NO;
1197
1198 if (GNUNET_YES == include_header)
1199 {
1200 decode_step (buffer, offset, &(message->header.timestamp));
1201 decode_step (buffer, offset, &(message->header.sender_id));
1202 decode_step (buffer, offset, &(message->header.previous));
1203 }
1204
1205 decode_step (buffer, offset, &kind);
1206 kind = GNUNET_be32toh (kind);
1207
1208 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1209
1210 if (count < get_message_kind_size (message->header.kind, include_header))
1211 return GNUNET_NO;
1212
1213 {
1214 uint16_t result;
1215 result = decode_message_body (&(message->header.kind),
1216 &(message->body), length, buffer, offset);
1217
1218 if (padding)
1219 *padding = result;
1220 }
1221
1222 return GNUNET_YES;
1223}
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 1227 of file messenger_api_message.c.

1230{
1231 struct GNUNET_HashCode expected, hash;
1232 uint16_t offset;
1233 kind_t kind;
1234
1235 GNUNET_assert ((message) && (buffer));
1236
1237 offset = sizeof(hash);
1238
1239 if (length < get_short_message_size (NULL, GNUNET_NO))
1240 return GNUNET_NO;
1241
1242 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1243
1245 buffer + sizeof(hash),
1246 length - sizeof(hash),
1247 &expected);
1248
1249 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1250 return GNUNET_NO;
1251
1252 decode_step (buffer, offset, &kind);
1253 kind = GNUNET_be32toh (kind);
1254
1255 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1256
1257 if (length < get_short_message_size (message, GNUNET_NO))
1258 return GNUNET_NO;
1259
1260 decode_message_body (&(message->kind), &(message->body), length, buffer,
1261 offset);
1262
1263 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1264 return GNUNET_NO;
1265
1266 return GNUNET_YES;
1267}
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 1271 of file messenger_api_message.c.

1275{
1276 ssize_t offset;
1277
1278 GNUNET_assert ((message) && (buffer) && (hash));
1279
1281 signature));
1282
1283 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1284}

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,
uint16_t  length,
char *  buffer,
const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_BlindablePrivateKey key 
)

Signs the hash of a message with a given private key and writes the signature into the buffer as well.

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

Definition at line 1288 of file messenger_api_message.c.

1293{
1294 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1295
1296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1297 GNUNET_h2s (hash));
1298
1299 {
1300 struct GNUNET_MESSENGER_MessageSignature signature;
1301
1303 signature.purpose.size = htonl (sizeof(signature));
1304
1305 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1306 GNUNET_CRYPTO_blinded_key_sign (key, &signature, &(message->header.signature
1307 ));
1308 }
1309
1310 message->header.signature.type = key->type;
1311
1312 {
1313 uint16_t offset = 0;
1315 buffer,
1316 offset,
1317 &(message->header.signature),
1318 length);
1319 }
1320}
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
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
struct GNUNET_CRYPTO_SignaturePurpose purpose

References encode_step_signature, 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()

void sign_message_by_peer ( struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer,
const struct GNUNET_HashCode hash,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

Signs the hash of a message with the peer identity of a given config and writes the signature into the buffer as well.

Parameters
[in,out]messageMessage
[in]lengthLength of buffer
[out]bufferBuffer
[in]hashHash of message
[in]cfgPeer configuration

Definition at line 1324 of file messenger_api_message.c.

1329{
1330 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1331
1332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1333 GNUNET_h2s (hash));
1334
1335 {
1336 struct GNUNET_MESSENGER_MessageSignature signature;
1338 signature.purpose.size = htonl (sizeof (signature));
1339
1340 GNUNET_memcpy (&(signature.hash), hash, sizeof (signature.hash));
1342 &(message->header.signature
1343 .
1344 eddsa_signature));
1345 }
1346
1348
1349 {
1350 uint16_t offset = 0;
1352 buffer,
1353 offset,
1354 &(message->header.signature),
1355 length);
1356 }
1357}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blinded_key_sign_by_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
Sign a given block with a specific purpose using the host's peer identity.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.

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

Referenced by sign_srv_room_message_by_peer().

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

◆ calc_message_hmac()

static void calc_message_hmac ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_SymmetricSessionKey key,
struct GNUNET_HashCode hmac 
)
static

Definition at line 1361 of file messenger_api_message.c.

1364{
1365 struct GNUNET_CRYPTO_AuthKey auth_key;
1366
1367 GNUNET_assert ((message) && (key) && (hmac));
1368
1369 switch (message->header.kind)
1370 {
1373 &auth_key, key,
1374 &(message->body.announcement.nonce),
1376 &(message->body.announcement.identifier),
1377 sizeof (message->body.announcement.identifier),
1378 NULL);
1379
1380 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1381 sizeof (message->body.announcement)
1382 - sizeof (*hmac),
1383 hmac);
1384 break;
1387 &auth_key, key, &(message->body.access.event),
1388 sizeof (message->body.access.event), NULL);
1389
1390 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1391 sizeof (message->body.access)
1392 - sizeof (*hmac),
1393 hmac);
1394 break;
1397 &auth_key, key,
1398 &(message->body.revolution.nonce),
1400 &(message->body.revolution.identifier),
1401 sizeof (message->body.revolution.identifier),
1402 NULL);
1403
1404 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1405 sizeof (message->body.revolution)
1406 - sizeof (*hmac),
1407 hmac);
1408 break;
1411 &auth_key, key,
1412 &(message->body.authorization.event),
1413 sizeof (message->body.authorization.event),
1414 &(message->body.authorization.identifier),
1415 sizeof (message->body.authorization.identifier),
1416 NULL);
1417
1418 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1419 sizeof (message->body.authorization)
1420 - sizeof (*hmac),
1421 hmac);
1422 break;
1423 default:
1424 break;
1425 }
1426}
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)
void GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
Derive an authentication key.
#define GNUNET_MESSENGER_EPOCH_NONCE_BYTES
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_hmac(), GNUNET_CRYPTO_hmac_derive_key(), GNUNET_MESSENGER_EPOCH_NONCE_BYTES, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_REVOLUTION, 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()

void sign_message_by_key ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_SymmetricSessionKey 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

Definition at line 1430 of file messenger_api_message.c.

1432{
1433 struct GNUNET_HashCode *hmac;
1434
1435 GNUNET_assert ((message) && (key));
1436
1437 switch (message->header.kind)
1438 {
1440 hmac = &(message->body.announcement.hmac);
1441 break;
1443 hmac = &(message->body.access.hmac);
1444 break;
1446 hmac = &(message->body.revolution.hmac);
1447 break;
1449 hmac = &(message->body.authorization.hmac);
1450 break;
1451 default:
1452 hmac = NULL;
1453 break;
1454 }
1455
1456 if (! hmac)
1457 return;
1458
1459 calc_message_hmac (message, key, hmac);
1460}
static void calc_message_hmac(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *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_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 1464 of file messenger_api_message.c.

1467{
1468 struct GNUNET_MESSENGER_MessageSignature signature;
1469
1470 GNUNET_assert ((message) && (hash) && (key));
1471
1472 if (key->type != message->header.signature.type)
1473 return GNUNET_SYSERR;
1474
1475 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1476 signature.purpose.size = htonl (sizeof(signature));
1477
1478 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1479
1482 &(message->header.signature), key);
1483}
#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 1487 of file messenger_api_message.c.

1490{
1491 struct GNUNET_MESSENGER_MessageSignature signature;
1492
1493 GNUNET_assert ((message) && (hash) && (identity));
1494
1495 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1496 return GNUNET_SYSERR;
1497
1498 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1499 signature.purpose.size = htonl (sizeof(signature));
1500
1501 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1502
1504 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &(signature.purpose),
1505 &(message->header.signature.
1506 eddsa_signature), identity);
1507}
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_SymmetricSessionKey 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 1511 of file messenger_api_message.c.

1513{
1514 const struct GNUNET_HashCode *msg_hmac;
1515 struct GNUNET_HashCode hmac;
1516
1517 GNUNET_assert ((message) && (key));
1518
1519 switch (message->header.kind)
1520 {
1522 msg_hmac = &(message->body.announcement.hmac);
1523 break;
1525 msg_hmac = &(message->body.access.hmac);
1526 break;
1528 msg_hmac = &(message->body.revolution.hmac);
1529 break;
1531 msg_hmac = &(message->body.authorization.hmac);
1532 break;
1533 default:
1534 msg_hmac = NULL;
1535 break;
1536 }
1537
1538 if (! msg_hmac)
1539 return GNUNET_SYSERR;
1540
1541 calc_message_hmac (message, key, &hmac);
1542
1543 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1544 return GNUNET_OK;
1545
1546 return GNUNET_SYSERR;
1547}
@ 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_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_BlindablePublicKey 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 1551 of file messenger_api_message.c.

1553{
1554 struct GNUNET_CRYPTO_HpkePublicKey hpke_key;
1556 struct GNUNET_MESSENGER_ShortMessage shortened;
1557 uint16_t length, padded_length, encoded_length;
1558 uint8_t *data;
1559
1560 GNUNET_assert ((message) && (key));
1561
1562 if (GNUNET_YES == is_service_message (message))
1563 return GNUNET_NO;
1564
1565 fold_short_message (message, &shortened);
1566
1567 length = get_short_message_size (&shortened, GNUNET_YES);
1568 padded_length = calc_padded_length (length + encryption_overhead);
1569
1570 GNUNET_assert (padded_length >= length + encryption_overhead);
1571
1573 message->body.privacy.data = GNUNET_malloc (padded_length);
1574 message->body.privacy.length = padded_length;
1575
1577 &hpke_key));
1578 encoded_length = (padded_length - encryption_overhead);
1579
1580 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1581
1582 result = GNUNET_NO;
1583 data = GNUNET_malloc (encoded_length);
1584
1585 encode_short_message (&shortened, encoded_length, (char *) data);
1586
1588 (const uint8_t*)
1589 "messenger",
1590 strlen ("messenger"),
1591 NULL, 0,
1592 (const uint8_t*) data,
1593 encoded_length,
1594 (uint8_t*) message->body.
1595 privacy.data,
1596 NULL))
1597 {
1598 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1599
1600 unfold_short_message (&shortened, message);
1601 goto cleanup;
1602 }
1603
1604 destroy_message_body (shortened.kind, &(shortened.body));
1606
1607cleanup:
1608 GNUNET_free (data);
1609 return result;
1610}
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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_BlindablePublicKey *pk, struct GNUNET_CRYPTO_HpkePublicKey *pk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
@ 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)
A public key used for encryption.

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_pk_to_x25519(), 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(), key, 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_BlindablePrivateKey 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 1614 of file messenger_api_message.c.

1616{
1617 struct GNUNET_CRYPTO_HpkePrivateKey hpke_key;
1619 uint16_t padded_length, encoded_length;
1620 uint8_t *data;
1621
1622 GNUNET_assert ((message) && (key) &&
1624
1625 padded_length = message->body.privacy.length;
1626
1627 if (padded_length < encryption_overhead)
1628 {
1630 "Message length too short to decrypt!\n");
1631
1632 return GNUNET_NO;
1633 }
1634
1636 &hpke_key));
1637 encoded_length = (padded_length - encryption_overhead);
1638
1639 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1640
1641 result = GNUNET_NO;
1642 data = GNUNET_malloc (encoded_length);
1643
1644 if (GNUNET_OK !=
1646 (uint8_t*) "messenger",
1647 strlen ("messenger"),
1648 NULL, 0,
1649 (uint8_t*) message->body.privacy.data,
1650 padded_length,
1651 (uint8_t*) data,
1652 NULL))
1653 {
1654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1655
1656 goto cleanup;
1657 }
1658
1659 {
1660 struct GNUNET_MESSENGER_ShortMessage shortened;
1661 if (GNUNET_YES != decode_short_message (&shortened,
1662 encoded_length,
1663 (char*) data))
1664 {
1666 "Decoding decrypted message failed!\n");
1667
1668 goto cleanup;
1669 }
1670
1671 unfold_short_message (&shortened, message);
1673 }
1674
1675cleanup:
1676 GNUNET_free (data);
1677 return result;
1678}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_BlindablePrivateKey *sk, struct GNUNET_CRYPTO_HpkePrivateKey *sk_enc)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
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)
A public key used for decryption.

References GNUNET_MESSENGER_Message::body, cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), encryption_overhead, GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_CRYPTO_hpke_sk_to_x25519(), 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, key, 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 1682 of file messenger_api_message.c.

1684{
1685 struct GNUNET_MESSENGER_Message *transcript;
1686
1687 GNUNET_assert ((message) && (key));
1688
1689 if (GNUNET_YES == is_service_message (message))
1690 return NULL;
1691
1693
1694 if (! transcript)
1695 {
1696 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1697 return NULL;
1698 }
1699
1700 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1701 sizeof(transcript->body.transcript.key));
1702
1703 {
1704 struct GNUNET_MESSENGER_ShortMessage shortened;
1705 uint16_t data_length;
1706
1707 fold_short_message (message, &shortened);
1708
1709 data_length = get_short_message_size (&shortened, GNUNET_YES);
1710
1711 transcript->body.transcript.data = GNUNET_malloc (data_length);
1712 transcript->body.transcript.length = data_length;
1713
1714 encode_short_message (&shortened, data_length,
1715 transcript->body.transcript.data);
1716 }
1717
1718 return transcript;
1719}
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_SymmetricSessionKey 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 1723 of file messenger_api_message.c.

1727{
1729 struct GNUNET_MESSENGER_ShortMessage shortened;
1730 uint16_t length, padded_length;
1731 uint8_t *data;
1732
1733 GNUNET_assert ((message) && (identifier) && (key));
1734
1735 fold_short_message (message, &shortened);
1736
1737 length = get_short_message_size (&shortened, GNUNET_YES);
1738 padded_length = calc_padded_length (length + 0);
1739
1740 GNUNET_assert (padded_length >= length + 0);
1741
1743
1744 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1745 sizeof (message->body.secret.identifier));
1746
1748 &(message->body.secret.iv),
1750
1751 message->body.secret.data = GNUNET_malloc (padded_length);
1752 message->body.secret.length = padded_length;
1753
1754 result = GNUNET_NO;
1755 data = GNUNET_malloc (padded_length);
1756
1757 encode_short_message (&shortened, padded_length, (char *) data);
1758
1759 {
1761
1763 message->body.secret.iv,
1765 NULL);
1766
1767 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (data, padded_length, key,
1768 &iv, message->body.secret.data))
1769 {
1770 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1771
1772 unfold_short_message (&shortened, message);
1773 goto cleanup;
1774 }
1775 }
1776
1777 {
1778 struct GNUNET_CRYPTO_AuthKey auth_key;
1779
1781 message->body.secret.iv,
1783 NULL);
1784
1785 GNUNET_CRYPTO_hmac (&auth_key, data, padded_length, &(message->body.secret.
1786 hmac));
1787 }
1788
1789 destroy_message_body (shortened.kind, &(shortened.body));
1791
1792cleanup:
1793 GNUNET_free (data);
1794 return result;
1795}
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
void GNUNET_CRYPTO_symmetric_derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
Derive an IV.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#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_hmac(), GNUNET_CRYPTO_hmac_derive_key(), GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_SECRET_IV_BYTES, GNUNET_NO, 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, 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_SymmetricSessionKey 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 1799 of file messenger_api_message.c.

1801{
1803 uint16_t padded_length;
1804 uint8_t *data;
1805
1806 GNUNET_assert ((message) && (key) &&
1808
1809 padded_length = message->body.secret.length;
1810
1811 result = GNUNET_NO;
1812 data = GNUNET_malloc (padded_length);
1813
1814 {
1816
1818 message->body.secret.iv,
1820 NULL);
1821
1822 if (-1 == GNUNET_CRYPTO_symmetric_decrypt (message->body.secret.data,
1823 padded_length,
1824 key, &iv, data))
1825 {
1826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1827
1828 goto cleanup;
1829 }
1830 }
1831
1832 {
1833 struct GNUNET_CRYPTO_AuthKey auth_key;
1834 struct GNUNET_HashCode hmac;
1835
1837 message->body.secret.iv,
1839 NULL);
1840
1841 GNUNET_CRYPTO_hmac (&auth_key, data, padded_length, &hmac);
1842
1843 if (0 != GNUNET_CRYPTO_hash_cmp (&(message->body.secret.hmac), &hmac))
1844 {
1846 "Decrypted message does not match HMAC!\n");
1847
1848 goto cleanup;
1849 }
1850 }
1851
1852 {
1853 struct GNUNET_MESSENGER_ShortMessage shortened;
1854 if (GNUNET_YES != decode_short_message (&shortened,
1855 padded_length,
1856 (char*) data))
1857 {
1859 "Decoding decrypted message failed!\n");
1860
1861 goto cleanup;
1862 }
1863
1864 unfold_short_message (&shortened, message);
1866 }
1867
1868cleanup:
1869 GNUNET_free (data);
1870 return result;
1871}
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.

References GNUNET_MESSENGER_Message::body, cleanup(), data, GNUNET_MESSENGER_MessageSecret::data, decode_short_message(), GNUNET_assert, GNUNET_CRYPTO_hash_cmp(), GNUNET_CRYPTO_hmac(), GNUNET_CRYPTO_hmac_derive_key(), GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_SECRET_IV_BYTES, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageSecret::hmac, GNUNET_MESSENGER_MessageSecret::iv, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageSecret::length, 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 1875 of file messenger_api_message.c.

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

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_SymmetricSessionKey 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 1901 of file messenger_api_message.c.

1905{
1906 GNUNET_assert ((message) && (key) && (shared_key) &&
1908
1909 if (GNUNET_OK !=
1911 (uint8_t*) "messenger",
1912 strlen ("messenger"),
1913 NULL, 0,
1914 (uint8_t*) message->body.access.key,
1916 (uint8_t*) shared_key,
1917 NULL))
1918 {
1919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1920 return GNUNET_NO;
1921 }
1922
1923 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1924 {
1925 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1926 return GNUNET_NO;
1927 }
1928
1929 return GNUNET_YES;
1930}
#define GNUNET_MESSENGER_ACCESS_KEY_BYTES
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *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_SymmetricSessionKey key,
struct GNUNET_CRYPTO_SymmetricSessionKey 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 1934 of file messenger_api_message.c.

1939{
1941
1942 GNUNET_assert ((message) && (key) && (shared_key) &&
1944
1946 &(message->body.authorization.event),
1947 sizeof (message->body.authorization.event),
1948 &(message->body.authorization.identifier),
1949 sizeof (message->body.authorization.
1950 identifier),
1951 NULL);
1952
1955 key,
1956 &iv,
1957 shared_key))
1958 {
1959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1960 return GNUNET_NO;
1961 }
1962
1963 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1964 {
1965 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1966 return GNUNET_NO;
1967 }
1968
1969 return GNUNET_YES;
1970}
#define GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES

References GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_assert, GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAuthorization::identifier, key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageHeader::kind, 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 1974 of file messenger_api_message.c.

1975{
1978
1979 GNUNET_assert (message);
1980
1982
1983 switch (message->header.kind)
1984 {
1987 break;
1990 break;
1993 break;
1996 break;
1997 default:
1999 break;
2000 }
2001
2003
2007
2008 return timeout;
2009}
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,
const GNUNET_MESSENGER_SignFunction  sign,
enum GNUNET_MESSENGER_PackMode  mode,
const void *  cls 
)

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 and it will be signed if the sign function is not NULL.

Parameters
[out]messageMessage
[out]hashHash of message
[in]signFunction to sign
[in]modeMode of packing
[in,out]clsClosure for signing
Returns
Envelope or NULL

Definition at line 2013 of file messenger_api_message.c.

2018{
2019 struct GNUNET_MessageHeader *header;
2020 uint16_t length, padded_length;
2021 struct GNUNET_MQ_Envelope *env;
2022 char *buffer;
2023
2024 GNUNET_assert (message);
2025
2027 "Packing message kind=%u and sender: %s\n",
2028 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2029
2030 length = get_message_size (message, GNUNET_YES);
2031 padded_length = calc_padded_length (length);
2032
2034 {
2035 env = GNUNET_MQ_msg_extra (header, padded_length,
2037 buffer = (char*) &(header[1]);
2038 }
2039 else
2040 {
2041 env = NULL;
2042 buffer = GNUNET_malloc (padded_length);
2043 }
2044
2045 encode_message (message, padded_length, buffer, GNUNET_YES);
2046
2047 if (hash)
2048 {
2049 hash_message (message, length, buffer, hash);
2050
2051 if (sign)
2052 sign (cls, message, length, buffer, hash);
2053 }
2054
2056 GNUNET_free (buffer);
2057
2058 return env;
2059}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static enum @49 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 maximal 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(), iterate_send_room_message(), and pack_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 2063 of file messenger_api_message.c.

2064{
2065 GNUNET_assert (message);
2066
2067 switch (message->header.kind)
2068 {
2074 return GNUNET_YES;
2075 default:
2076 return GNUNET_NO;
2077 }
2078}

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(), pack_srv_room_message(), process_message_control(), 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 2082 of file messenger_api_message.c.

2083{
2084 GNUNET_assert (message);
2085
2086 if (GNUNET_YES == is_peer_message (message))
2087 return GNUNET_YES;
2088
2089 switch (message->header.kind)
2090 {
2092 return GNUNET_YES; // Reserved for connection handling only!
2094 return GNUNET_YES; // Reserved for member handling only!
2096 return GNUNET_YES; // Reserved for member handling only!
2098 return GNUNET_YES; // Reserved for member name handling only!
2100 return GNUNET_YES; // Reserved for member key handling only!
2102 return GNUNET_YES; // Reserved for connection handling only!
2104 return GNUNET_YES; // Reserved for member id handling only!
2106 return GNUNET_YES; // Reserved for connection handling only!
2108 return GNUNET_YES; // Reserved for peers only!
2110 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2112 return GNUNET_NO;
2114 return GNUNET_NO;
2116 return GNUNET_NO;
2118 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2120 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2122 return GNUNET_YES; // Reserved for connection handling only!
2124 return GNUNET_NO;
2126 return GNUNET_NO;
2128 return GNUNET_NO;
2130 return GNUNET_YES; // Reserved for subscription handling only!
2132 return GNUNET_NO;
2134 return GNUNET_YES; // Reserved for epoch and group key exchange!
2136 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2138 return GNUNET_YES; // Reserved for epoch key exchange!
2140 return GNUNET_YES; // Reserved for epoch and group key exchange!
2142 return GNUNET_YES; // Reserved for epoch and group key revoking!
2144 return GNUNET_YES; // Reserved for group key exchange!
2146 return GNUNET_YES; // Reserved for epoch and group key exchange!
2147 default:
2148 return GNUNET_SYSERR;
2149 }
2150}
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 2154 of file messenger_api_message.c.

2155{
2156 GNUNET_assert (message);
2157
2158 switch (message->header.kind)
2159 {
2161 return GNUNET_YES;
2163 return GNUNET_YES;
2165 return GNUNET_YES;
2166 default:
2167 return GNUNET_NO;
2168 }
2169}

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(), pack_srv_room_message(), request_room_message_step(), and send_message_to_room().

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 2173 of file messenger_api_message.c.

2174{
2175 GNUNET_assert (message);
2176
2177 if (GNUNET_YES == is_peer_message (message))
2178 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2179
2180 switch (message->header.kind)
2181 {
2183 return GNUNET_SYSERR; // Reserved for connection handling only!
2185 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2187 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2189 return GNUNET_YES;
2191 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2193 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2195 return GNUNET_NO; // Reserved for member id handling only!
2197 return GNUNET_SYSERR; // Reserved for connection handling only!
2199 return GNUNET_SYSERR; // Reserved for peers only!
2201 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2203 return GNUNET_YES;
2205 return GNUNET_YES;
2207 return GNUNET_YES;
2209 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2211 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2213 return GNUNET_SYSERR; // Reserved for connection handling only!
2215 return GNUNET_YES;
2217 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2219 return GNUNET_YES;
2221 return GNUNET_YES;
2223 return GNUNET_YES;
2225 return GNUNET_NO; // Should only be used for implicit key exchange!
2227 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2229 return GNUNET_NO; // Should only be used for implicit key exchange!
2231 return GNUNET_NO; // Should only be used for implicit key exchange!
2233 return GNUNET_NO; // Should only be used for implicit key exchange!
2235 return GNUNET_NO; // Should only be used for implicit key exchange!
2237 return GNUNET_NO; // Should only be used for implicit key exchange!
2238 default:
2239 return GNUNET_SYSERR;
2240 }
2241}

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 2245 of file messenger_api_message.c.

2246{
2247 GNUNET_assert (message);
2248
2249 switch (message->header.kind)
2250 {
2252 return &(message->body.subscription.discourse);
2254 return &(message->body.talk.discourse);
2255 default:
2256 return NULL;
2257 }
2258}

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 32 of file messenger_api_message.c.

Referenced by decrypt_message(), and encrypt_message().