diff --git a/sw/airborne/modules/datalink/gec/gec.h b/sw/airborne/modules/datalink/gec/gec.h index 1a94cf08eb..1aaa386f17 100644 --- a/sw/airborne/modules/datalink/gec/gec.h +++ b/sw/airborne/modules/datalink/gec/gec.h @@ -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 { diff --git a/sw/airborne/modules/datalink/gec_dl.c b/sw/airborne/modules/datalink/gec_dl.c index 03036a74b8..b73bc52991 100644 --- a/sw/airborne/modules/datalink/gec_dl.c +++ b/sw/airborne/modules/datalink/gec_dl.c @@ -29,6 +29,36 @@ #include "pprzlink/messages.h" #include // 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 @@ -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); @@ -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) @@ -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