Skip to content

Commit 5b11980

Browse files
notoriagaJason Mobarak
andauthored
variable length ecdsa signature [GV2-193] (#1306)
* Add signature length field to MsgEcdsaSignature Co-authored-by: Jason Mobarak <jason@swift-nav.com>
1 parent e0fc9bf commit 5b11980

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+18395
-11866
lines changed

c/include/libsbp/cpp/message_traits.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,43 @@ struct MessageTraits<sbp_msg_ecdsa_certificate_t> {
14751475
}
14761476
};
14771477

1478+
template <>
1479+
struct MessageTraits<sbp_msg_ecdsa_signature_dep_t> {
1480+
static constexpr sbp_msg_type_t id = SbpMsgEcdsaSignatureDep;
1481+
static constexpr const char *name = "MSG_ECDSA_SIGNATURE_DEP";
1482+
static const sbp_msg_ecdsa_signature_dep_t &get(const sbp_msg_t &msg) {
1483+
return msg.ecdsa_signature_dep;
1484+
}
1485+
static sbp_msg_ecdsa_signature_dep_t &get(sbp_msg_t &msg) {
1486+
return msg.ecdsa_signature_dep;
1487+
}
1488+
static void to_sbp_msg(const sbp_msg_ecdsa_signature_dep_t &msg,
1489+
sbp_msg_t *sbp_msg) {
1490+
sbp_msg->ecdsa_signature_dep = msg;
1491+
}
1492+
static sbp_msg_t to_sbp_msg(const sbp_msg_ecdsa_signature_dep_t &msg) {
1493+
sbp_msg_t sbp_msg;
1494+
sbp_msg.ecdsa_signature_dep = msg;
1495+
return sbp_msg;
1496+
}
1497+
static s8 send(sbp_state_t *state, u16 sender_id,
1498+
const sbp_msg_ecdsa_signature_dep_t &msg,
1499+
sbp_write_fn_t write) {
1500+
return sbp_msg_ecdsa_signature_dep_send(state, sender_id, &msg, write);
1501+
}
1502+
static s8 encode(uint8_t *buf, uint8_t len, uint8_t *n_written,
1503+
const sbp_msg_ecdsa_signature_dep_t &msg) {
1504+
return sbp_msg_ecdsa_signature_dep_encode(buf, len, n_written, &msg);
1505+
}
1506+
static s8 decode(const uint8_t *buf, uint8_t len, uint8_t *n_read,
1507+
sbp_msg_ecdsa_signature_dep_t *msg) {
1508+
return sbp_msg_ecdsa_signature_dep_decode(buf, len, n_read, msg);
1509+
}
1510+
static size_t encoded_len(const sbp_msg_ecdsa_signature_dep_t &msg) {
1511+
return sbp_msg_ecdsa_signature_dep_encoded_len(&msg);
1512+
}
1513+
};
1514+
14781515
template <>
14791516
struct MessageTraits<sbp_msg_ecdsa_signature_t> {
14801517
static constexpr sbp_msg_type_t id = SbpMsgEcdsaSignature;

c/include/libsbp/legacy/cpp/message_traits.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,11 +1192,17 @@ struct MessageTraits<msg_certificate_chain_t> {
11921192

11931193

11941194
template<>
1195-
struct MessageTraits<msg_ecdsa_signature_t> {
1195+
struct MessageTraits<msg_ecdsa_signature_dep_t> {
11961196
static constexpr u16 id = 3078;
11971197
};
11981198

11991199

1200+
template<>
1201+
struct MessageTraits<msg_ecdsa_signature_t> {
1202+
static constexpr u16 id = 3079;
1203+
};
1204+
1205+
12001206
template<>
12011207
struct MessageTraits<msg_fileio_config_req_t> {
12021208
static constexpr u16 id = 4097;

c/include/libsbp/legacy/signing.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,45 @@ typedef struct SBP_ATTR_PACKED {
8181
`http(s)://certs.swiftnav.com/chain`. */
8282
} msg_certificate_chain_t;
8383

84+
/** An ECDSA signature
85+
*
86+
* An ECDSA-256 signature using SHA-256 as the message digest algorithm.
87+
*/
88+
89+
typedef struct SBP_ATTR_PACKED {
90+
u8 flags; /**< Describes the format of the `signed\_messages`
91+
field below. */
92+
u8 stream_counter; /**< Signature message counter. Zero indexed and
93+
incremented with each signature message. The
94+
counter will not increment if this message was
95+
in response to an on demand request. The
96+
counter will roll over after 256 messages.
97+
Upon connection, the value of the counter may
98+
not initially be zero. */
99+
u8 on_demand_counter; /**< On demand message counter. Zero indexed and
100+
incremented with each signature message sent
101+
in response to an on demand message. The
102+
counter will roll over after 256 messages.
103+
Upon connection, the value of the counter may
104+
not initially be zero. */
105+
u8 certificate_id[4]; /**< The last 4 bytes of the certificate's SHA-1
106+
fingerprint */
107+
u8 n_signature_bytes; /**< Number of bytes to use of the signature field.
108+
The DER encoded signature has a maximum size
109+
of 72 bytes but can vary between 70 and 72
110+
bytes in length. */
111+
u8 signature[72]; /**< DER encoded ECDSA signature for the messages
112+
using SHA-256 as the digest algorithm. */
113+
u8 signed_messages[0]; /**< CRCs of the messages covered by this
114+
signature. For Skylark, which delivers SBP
115+
messages wrapped in Swift's proprietary RTCM
116+
message, these are the 24-bit CRCs from the
117+
RTCM message framing. For SBP only streams,
118+
this will be 16-bit CRCs from the SBP framing.
119+
See the `flags` field to determine the type of
120+
CRCs covered. */
121+
} msg_ecdsa_signature_t;
122+
84123
/** An ECDSA signature
85124
*
86125
* An ECDSA-256 signature using SHA-256 as the message digest algorithm.
@@ -114,7 +153,7 @@ typedef struct SBP_ATTR_PACKED {
114153
this will be 16-bit CRCs from the SBP framing.
115154
See the `flags` field to determine the type of
116155
CRCs covered. */
117-
} msg_ecdsa_signature_t;
156+
} msg_ecdsa_signature_dep_t;
118157

119158
typedef struct SBP_ATTR_PACKED {
120159
u8 n_msg; /**< Total number messages that make up the

c/include/libsbp/sbp_msg_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ typedef enum {
9393
SbpMsgDopsDepA = SBP_MSG_DOPS_DEP_A,
9494
SbpMsgDops = SBP_MSG_DOPS,
9595
SbpMsgEcdsaCertificate = SBP_MSG_ECDSA_CERTIFICATE,
96+
SbpMsgEcdsaSignatureDep = SBP_MSG_ECDSA_SIGNATURE_DEP,
9697
SbpMsgEcdsaSignature = SBP_MSG_ECDSA_SIGNATURE,
9798
SbpMsgEd25519CertificateDep = SBP_MSG_ED25519_CERTIFICATE_DEP,
9899
SbpMsgEd25519SignatureDepA = SBP_MSG_ED25519_SIGNATURE_DEP_A,

c/include/libsbp/signing_macros.h

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
*/
113113
#define SBP_MSG_CERTIFICATE_CHAIN_ENCODED_LEN 135u
114114

115-
#define SBP_MSG_ECDSA_SIGNATURE 0x0C06
115+
#define SBP_MSG_ECDSA_SIGNATURE 0x0C07
116116
#define SBP_ECDSA_SIGNATURE_CRC_TYPE_MASK (0x3u)
117117
#define SBP_ECDSA_SIGNATURE_CRC_TYPE_SHIFT (0u)
118118
#define SBP_ECDSA_SIGNATURE_CRC_TYPE_GET(flags) \
@@ -142,15 +142,15 @@
142142
* msg_ecdsa_signature_t::signature (legacy API) before the maximum SBP message
143143
* size is exceeded
144144
*/
145-
#define SBP_MSG_ECDSA_SIGNATURE_SIGNATURE_MAX 64u
145+
#define SBP_MSG_ECDSA_SIGNATURE_SIGNATURE_MAX 72u
146146

147147
/**
148148
* The maximum number of items that can be stored in
149149
* sbp_msg_ecdsa_signature_t::signed_messages (V4 API) or
150150
* msg_ecdsa_signature_t::signed_messages (legacy API) before the maximum SBP
151151
* message size is exceeded
152152
*/
153-
#define SBP_MSG_ECDSA_SIGNATURE_SIGNED_MESSAGES_MAX 184u
153+
#define SBP_MSG_ECDSA_SIGNATURE_SIGNED_MESSAGES_MAX 175u
154154

155155
/**
156156
* Encoded length of sbp_msg_ecdsa_signature_t (V4 API) and
@@ -165,7 +165,62 @@
165165
* See the documentation for libsbp for more details regarding the message
166166
* structure and its variable length component(s)
167167
*/
168-
#define SBP_MSG_ECDSA_SIGNATURE_ENCODED_OVERHEAD 71u
168+
#define SBP_MSG_ECDSA_SIGNATURE_ENCODED_OVERHEAD 80u
169+
170+
#define SBP_MSG_ECDSA_SIGNATURE_DEP 0x0C06
171+
#define SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_MASK (0x3u)
172+
#define SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_SHIFT (0u)
173+
#define SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_GET(flags) \
174+
((u8)((u8)((flags) >> SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_SHIFT) & \
175+
SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_MASK))
176+
#define SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_SET(flags, val) \
177+
do { \
178+
(flags) = (u8)((flags & (~(SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_MASK \
179+
<< SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_SHIFT))) | \
180+
(((val) & (SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_MASK)) \
181+
<< (SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_SHIFT))); \
182+
} while (0)
183+
184+
#define SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_24_BIT_CRCS_FROM_RTCM_FRAMING (0)
185+
#define SBP_ECDSA_SIGNATURE_DEP_CRC_TYPE_16_BIT_CRCS_FROM_SBP_FRAMING (1)
186+
/**
187+
* The maximum number of items that can be stored in
188+
* sbp_msg_ecdsa_signature_dep_t::certificate_id (V4 API) or
189+
* msg_ecdsa_signature_dep_t::certificate_id (legacy API) before the maximum SBP
190+
* message size is exceeded
191+
*/
192+
#define SBP_MSG_ECDSA_SIGNATURE_DEP_CERTIFICATE_ID_MAX 4u
193+
194+
/**
195+
* The maximum number of items that can be stored in
196+
* sbp_msg_ecdsa_signature_dep_t::signature (V4 API) or
197+
* msg_ecdsa_signature_dep_t::signature (legacy API) before the maximum SBP
198+
* message size is exceeded
199+
*/
200+
#define SBP_MSG_ECDSA_SIGNATURE_DEP_SIGNATURE_MAX 64u
201+
202+
/**
203+
* The maximum number of items that can be stored in
204+
* sbp_msg_ecdsa_signature_dep_t::signed_messages (V4 API) or
205+
* msg_ecdsa_signature_dep_t::signed_messages (legacy API) before the maximum
206+
* SBP message size is exceeded
207+
*/
208+
#define SBP_MSG_ECDSA_SIGNATURE_DEP_SIGNED_MESSAGES_MAX 184u
209+
210+
/**
211+
* Encoded length of sbp_msg_ecdsa_signature_dep_t (V4 API) and
212+
* msg_ecdsa_signature_dep_t (legacy API)
213+
*
214+
* This type is not fixed size and an instance of this message may be longer
215+
* than the value indicated by this symbol. Users of the V4 API should call
216+
* #sbp_msg_ecdsa_signature_dep_encoded_len to determine the actual size of an
217+
* instance of this message. Users of the legacy API are required to track the
218+
* encoded message length when interacting with the legacy type.
219+
*
220+
* See the documentation for libsbp for more details regarding the message
221+
* structure and its variable length component(s)
222+
*/
223+
#define SBP_MSG_ECDSA_SIGNATURE_DEP_ENCODED_OVERHEAD 71u
169224

170225
#define SBP_MSG_ED25519_CERTIFICATE_DEP 0x0C02
171226
/**

c/include/libsbp/v4/sbp_msg.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef union {
9999
sbp_msg_dops_dep_a_t dops_dep_a;
100100
sbp_msg_dops_t dops;
101101
sbp_msg_ecdsa_certificate_t ecdsa_certificate;
102+
sbp_msg_ecdsa_signature_dep_t ecdsa_signature_dep;
102103
sbp_msg_ecdsa_signature_t ecdsa_signature;
103104
sbp_msg_ed25519_certificate_dep_t ed25519_certificate_dep;
104105
sbp_msg_ed25519_signature_dep_a_t ed25519_signature_dep_a;
@@ -419,6 +420,9 @@ static inline s8 sbp_message_encode(uint8_t *buf, uint8_t len,
419420
case SbpMsgEcdsaCertificate:
420421
return sbp_msg_ecdsa_certificate_encode(buf, len, n_written,
421422
&msg->ecdsa_certificate);
423+
case SbpMsgEcdsaSignatureDep:
424+
return sbp_msg_ecdsa_signature_dep_encode(buf, len, n_written,
425+
&msg->ecdsa_signature_dep);
422426
case SbpMsgEcdsaSignature:
423427
return sbp_msg_ecdsa_signature_encode(buf, len, n_written,
424428
&msg->ecdsa_signature);
@@ -1065,6 +1069,9 @@ static inline s8 sbp_message_decode(const uint8_t *buf, uint8_t len,
10651069
case SbpMsgEcdsaCertificate:
10661070
return sbp_msg_ecdsa_certificate_decode(buf, len, n_read,
10671071
&msg->ecdsa_certificate);
1072+
case SbpMsgEcdsaSignatureDep:
1073+
return sbp_msg_ecdsa_signature_dep_decode(buf, len, n_read,
1074+
&msg->ecdsa_signature_dep);
10681075
case SbpMsgEcdsaSignature:
10691076
return sbp_msg_ecdsa_signature_decode(buf, len, n_read,
10701077
&msg->ecdsa_signature);
@@ -1681,6 +1688,8 @@ static inline size_t sbp_message_encoded_len(sbp_msg_type_t msg_type,
16811688
return sbp_msg_dops_encoded_len(&msg->dops);
16821689
case SbpMsgEcdsaCertificate:
16831690
return sbp_msg_ecdsa_certificate_encoded_len(&msg->ecdsa_certificate);
1691+
case SbpMsgEcdsaSignatureDep:
1692+
return sbp_msg_ecdsa_signature_dep_encoded_len(&msg->ecdsa_signature_dep);
16841693
case SbpMsgEcdsaSignature:
16851694
return sbp_msg_ecdsa_signature_encoded_len(&msg->ecdsa_signature);
16861695
case SbpMsgEd25519CertificateDep:
@@ -2226,6 +2235,9 @@ static inline int sbp_message_cmp(sbp_msg_type_t msg_type, const sbp_msg_t *a,
22262235
case SbpMsgEcdsaCertificate:
22272236
return sbp_msg_ecdsa_certificate_cmp(&a->ecdsa_certificate,
22282237
&b->ecdsa_certificate);
2238+
case SbpMsgEcdsaSignatureDep:
2239+
return sbp_msg_ecdsa_signature_dep_cmp(&a->ecdsa_signature_dep,
2240+
&b->ecdsa_signature_dep);
22292241
case SbpMsgEcdsaSignature:
22302242
return sbp_msg_ecdsa_signature_cmp(&a->ecdsa_signature,
22312243
&b->ecdsa_signature);

c/include/libsbp/v4/signing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <libsbp/v4/signing/MSG_CERTIFICATE_CHAIN.h>
2121
#include <libsbp/v4/signing/MSG_ECDSA_CERTIFICATE.h>
2222
#include <libsbp/v4/signing/MSG_ECDSA_SIGNATURE.h>
23+
#include <libsbp/v4/signing/MSG_ECDSA_SIGNATURE_DEP.h>
2324
#include <libsbp/v4/signing/MSG_ED25519_CERTIFICATE_DEP.h>
2425
#include <libsbp/v4/signing/MSG_ED25519_SIGNATURE_DEP_A.h>
2526
#include <libsbp/v4/signing/MSG_ED25519_SIGNATURE_DEP_B.h>

c/include/libsbp/v4/signing/MSG_ECDSA_SIGNATURE.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ typedef struct {
7070
u8 certificate_id[SBP_MSG_ECDSA_SIGNATURE_CERTIFICATE_ID_MAX];
7171

7272
/**
73-
* ECDSA signature for the messages using SHA-256 as the digest algorithm.
73+
* Number of bytes to use of the signature field. The DER encoded signature
74+
* has a maximum size of 72 bytes but can vary between 70 and 72 bytes in
75+
* length.
76+
*/
77+
u8 n_signature_bytes;
78+
79+
/**
80+
* DER encoded ECDSA signature for the messages using SHA-256 as the digest
81+
* algorithm.
7482
*/
7583
u8 signature[SBP_MSG_ECDSA_SIGNATURE_SIGNATURE_MAX];
7684

0 commit comments

Comments
 (0)