Skip to content

Commit

Permalink
Fix in crypto header
Browse files Browse the repository at this point in the history
  • Loading branch information
podhrmic committed Mar 28, 2018
1 parent f99ed9b commit e3fe8ff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
28 changes: 0 additions & 28 deletions sw/airborne/modules/datalink/gec/gec.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,6 @@
// basepoint value for the scalar curve multiplication
#define PPRZ_CURVE_BASEPOINT 9

#if PPRZLINK_DEFAULT_VER == 2
// minimal size of the encrypted message
#define PPRZ_MSG_ID 3
// index of the message ID for plaintext messages
#define PPRZ_PLAINTEXT_MSG_ID_IDX 4
// 4 bytes of MSG info (source_ID, dest_ID, class_byte, msg_ID) + 1 GEC byte
#define PPRZ_PLAINTEXT_MSG_MIN_LEN 5
// 20 bytes crypto overhead + 4 bytes MSG info + 1 GEC byte
#define PPRZ_ENCRYPTED_MSG_MIN_LEN 25
// length of the authenticated data (SOURCE ID, DEST ID)
#define PPRZ_AUTH_LEN 2
// index of the beginning of the ciphertext
#define PPRZ_CIPH_IDX 7
#else // PPRZLINK_DEFAULT_VER = 1
// minimal size of the encrypted message
#define PPRZ_MSG_ID 1
// index of the message ID for plaintext messages
#define PPRZ_PLAINTEXT_MSG_ID_IDX 2
// 2 bytes of MSG info (source_ID, msg_ID) + 1 GEC byte
#define PPRZ_PLAINTEXT_MSG_MIN_LEN 3
// 20 bytes crypto overhead + 2 bytes MSG info + 1 GEC byte
#define PPRZ_ENCRYPTED_MSG_MIN_LEN 23
// length of the authenticated data (SOURCE ID)
#define PPRZ_AUTH_LEN 1
// index of the beginning of the ciphertext
#define PPRZ_CIPH_IDX 6
#endif

typedef unsigned char ed25519_signature[64];

struct gec_privkey {
Expand Down
39 changes: 34 additions & 5 deletions sw/airborne/modules/datalink/gec_dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@
#include "pprzlink/messages.h"
#include <string.h> // for memset()

#if PPRZLINK_DEFAULT_VER == 2
// minimal size of the encrypted message
#define PPRZ_MSG_ID 3
// index of the message ID for plaintext messages
#define PPRZ_PLAINTEXT_MSG_ID_IDX 4
// 4 bytes of MSG info (source_ID, dest_ID, class_byte, msg_ID) + 1 GEC byte
#define PPRZ_PLAINTEXT_MSG_MIN_LEN 5
// 20 bytes crypto overhead + 4 bytes MSG info + 1 GEC byte
#define PPRZ_ENCRYPTED_MSG_MIN_LEN 25
// length of the authenticated data (SOURCE ID, DEST ID)
#define PPRZ_AUTH_LEN 2
// index of the beginning of the ciphertext
#define PPRZ_CIPH_IDX 7
#else
#if PPRZLINK_DEFAULT_VER == 1
// minimal size of the encrypted message
#define PPRZ_MSG_ID 1
// index of the message ID for plaintext messages
#define PPRZ_PLAINTEXT_MSG_ID_IDX 2
// 2 bytes of MSG info (source_ID, msg_ID) + 1 GEC byte
#define PPRZ_PLAINTEXT_MSG_MIN_LEN 3
// 20 bytes crypto overhead + 2 bytes MSG info + 1 GEC byte
#define PPRZ_ENCRYPTED_MSG_MIN_LEN 23
// length of the authenticated data (SOURCE ID)
#define PPRZ_AUTH_LEN 1
// index of the beginning of the ciphertext
#define PPRZ_CIPH_IDX 6
#endif // PPRZLINK_DEFAULT_VER = 1
#endif // PPRZLINK_DEFAULT_VER = 2

#ifdef GEC_STATUS_LED
#include "led.h" // for LED indication
#endif
Expand Down Expand Up @@ -187,8 +217,8 @@ void gec_encapsulate_and_send_msg(struct pprzlink_msg *msg, long fd)
get_trans(msg)->pprz_tp.trans_tx.end_message(msg, fd);
}

#else // Pprzlink 1.0

#else
#if PPRZLINK_DEFAULT_VER == 1
void gec_encapsulate_and_send_msg(struct gec_transport *trans,
struct link_device *dev, long fd);

Expand Down Expand Up @@ -279,8 +309,8 @@ static int check_available_space(
}
return 0;
}

#endif // PPRZLINK 2.0/1.0
#endif // PPRZLINK_DEFAULT_VER == 1
#endif // PPRZLINK_DEFAULT_VER == 2

// Init pprz transport structure
void gec_transport_init(struct gec_transport *t)
Expand Down Expand Up @@ -498,7 +528,6 @@ void gec_dl_event(void)
gec_tp.pprz_tp.trans_rx.payload, (bool *) &gec_tp.trans_rx.msg_received);
// we have (CRYPTO_BYTE .. MSG_PAYLOAD) in
if (gec_tp.trans_rx.msg_received) { // self.rx.parse_byte(b)

switch (gec_tp.sts.protocol_stage) {
case CRYPTO_OK:
// decrypt message
Expand Down

0 comments on commit e3fe8ff

Please sign in to comment.