45#define HZL_VERSION "v3.0.0"
48#define HZL_CBS_PROTOCOL_VERSION_SUPPORTED "v1.3"
79#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
80 || defined(_WIN64) || defined(__NT__)
82#define HZL_OS_AVAILABLE 1
83#define HZL_OS_AVAILABLE_WIN 1
84#define HZL_OS_AVAILABLE_NIX 0
87#include <sysinfoapi.h>
92#if defined(_MSC_VER) && _MSC_VER <= 1916
94#define _Static_assert static_assert
97#elif defined(__linux__) \
98 || defined(__APPLE__) || defined(__MACH__) \
99 || defined(__unix__) || defined(__unix) || defined(unix)
101#define HZL_OS_AVAILABLE 1
102#define HZL_OS_AVAILABLE_WIN 0
103#define HZL_OS_AVAILABLE_NIX 1
111#define HZL_OS_AVAILABLE 0
112#define HZL_OS_AVAILABLE_WIN 0
113#define HZL_OS_AVAILABLE_NIX 0
121#if HZL_OS_AVAILABLE_WIN
122#define HZL_API __declspec(dllexport)
128#define HZL_SET_BY_USER
131#define HZL_SERVER_SID 0U
134#define HZL_BROADCAST_GID 0U
137#define HZL_LTK_LEN 16U
140#define HZL_STK_LEN 16U
144#define HZL_IS_SECURITY_WARNING(err) ((err) >= 1 && (err) <= 15)
147#define HZL_MAX_CAN_FD_DATA_LEN 64U
158#define HZL_MAX_TRNG_TRIES_FOR_NONZERO_VALUE 20U
165#define HZL_LARGEST_MAX_COUNTER_NONCE_DELAY (1U << 22U)
uint32_t hzl_Timestamp_t
Opaque timestamp (timer, rolling counter) with milliseconds accuracy.
Definition: hzl.h:492
hzl_Err_t(* hzl_TimestampFunc)(hzl_Timestamp_t *timestamp)
Current-time timestamp generating function with millisecond accuracy.
Definition: hzl.h:561
uint8_t hzl_Sid_t
Source Identifier data type.
Definition: hzl.h:465
uint32_t hzl_CanId_t
CAN message identifier data type, able to hold both 11- or 29-bits values.
Definition: hzl.h:471
struct hzl_RxMsg hzl_RxSduMsg_t
Unpacked received SDU (Service Data Unit message) after validation (and optional decryption).
uint8_t hzl_Gid_t
Group Identifier data type.
Definition: hzl.h:462
uint64_t hzl_ResNonce_t
Response Nonce data type.
Definition: hzl.h:477
struct hzl_CbsPduMsg hzl_CbsPduMsg_t
Packed CBS PDU (Protocol Data Unit message) ready to be transmitted by the library user.
uint32_t hzl_CtrNonce_t
Counter Nonce data type.
Definition: hzl.h:495
uint8_t hzl_Pty_t
Payload Type data type.
Definition: hzl.h:468
struct hzl_Header hzl_Header_t
Unpacked CBS Header.
hzl_Err_t(* hzl_TrngFunc)(uint8_t *bytes, size_t amount)
True-random number generator function.
Definition: hzl.h:539
enum hzl_Err hzl_Err_t
Hazelnet error code, returned by all API functions.
#define HZL_SET_BY_USER
Identifier of the struct fields of the public API the user must set manually.
Definition: hzl.h:128
hzl_Err
Hazelnet error code, returned by all API functions.
Definition: hzl.h:169
@ HZL_ERR_SECWARN_DENIAL_OF_SERVICE
The Party is receiving too many suspect messages.
Definition: hzl.h:194
@ HZL_ERR_MALLOC_FAILED
Heap-memory allocation failure: out of memory.
Definition: hzl.h:445
@ HZL_ERR_NULL_TRNG_FUNC
The function pointer to the true-random number generating function is NULL.
Definition: hzl.h:345
@ HZL_ERR_SERVER_SID_ASSIGNED_TO_CLIENT
The Client configuration contains a Source Identifier (SID) equal to the one used by the Server HZL_S...
Definition: hzl.h:241
@ HZL_ERR_GAP_IN_SIDS
The array of Client configurations must have all SIDs from 1 to hzl_ServerConfig_t....
Definition: hzl.h:249
@ HZL_ERR_SID_TOO_LARGE_FOR_CONFIGURED_HEADER_TYPE
The Party configuration contains a Source Identifier (SID) that has a value that would not fit into t...
Definition: hzl.h:256
@ HZL_ERR_SECWARN_MESSAGE_FROM_MYSELF
Received message contained the receiver's Source Identfi␜er as the transmitter's identity.
Definition: hzl.h:180
@ HZL_ERR_TOO_SHORT_PDU_TO_CONTAIN_RES
The received Response (RES) message is too short to be a valid RES message.
Definition: hzl.h:401
@ HZL_ERR_TOO_SHORT_PDU_TO_CONTAIN_REQ
The received Request (REQ) message is too short to be a valid REQ message.
Definition: hzl.h:398
@ HZL_ERR_CLIENTS_BITMAP_ZERO_CLIENTS
The Server-side array of Group configuration has at least one Group where the bitmap of Clients in th...
Definition: hzl.h:326
@ HZL_ERR_NULL_SDU
The pointer to the Service Data Unit (unpacked user data) to transmit or the just-received one is NUL...
Definition: hzl.h:353
@ HZL_ERR_NULL_CONFIG_SERVER
The context contains a NULL pointer to the Server configuration struct.
Definition: hzl.h:223
@ HZL_ERR_SECWARN_RFU_3
Reserved warning code for future use.
Definition: hzl.h:206
@ HZL_ERR_TOO_LONG_CIPHERTEXT
The received Secured Application Data contains a too large value in the plaintext length field,...
Definition: hzl.h:407
@ HZL_ERR_SECWARN_RECEIVED_ZERO_KEY
Received Response message, once decrypted, contained an all-zeros STKG that cannot be used.
Definition: hzl.h:203
@ HZL_ERR_SECWARN_RECEIVED_OVERFLOWN_NONCE
Received message contained a Counter Nonce that exceeded its maximum allowed value.
Definition: hzl.h:200
@ HZL_ERR_GIDS_ARE_NOT_PRESORTED_STRICTLY_ASCENDING
The array of Group configurations must be sorted from smallest to largest GID without repeated GIDs.
Definition: hzl.h:290
@ HZL_ERR_PROGRAMMING
Default error value that should never appear, as it should be replaced with another one.
Definition: hzl.h:213
@ HZL_ERR_SECWARN_SERVER_ONLY_MESSAGE
Received message is of a type which only the Session Server can transmit, but the transmitter's ident...
Definition: hzl.h:186
@ HZL_ERR_INVALID_FILE_MAGIC_NUMBER
The magic number "HZL\0" (4 ASCII-encoded bytes) was not found at the beginning of the file as expect...
Definition: hzl.h:443
@ HZL_ERR_SECWARN_NOT_EXPECTING_A_RESPONSE
The Client received a Response addressed to it while not expecting any.
Definition: hzl.h:183
@ HZL_ERR_ZERO_CLIENTS
The Server configuration contains zero Clients.
Definition: hzl.h:266
@ HZL_ERR_UNEXPECTED_EOF
The configuration file was shorter than expected, some parts of the configuration are left out.
Definition: hzl.h:439
@ HZL_ERR_SECWARN_RFU_2
Reserved warning code for future use.
Definition: hzl.h:205
@ HZL_ERR_NULL_CTX
The function requires a pointer to the Hazelnet context, but NULL was provided.
Definition: hzl.h:217
@ HZL_ERR_TOO_LARGE_CTRNONCE_UPPER_LIMIT
The Server-side array of Group configuration has at least one Group where the Counter Nonce upper lim...
Definition: hzl.h:317
@ HZL_ERR_NULL_CONFIG_GROUPS
The context contains a NULL pointer to the Client configuration struct (on a Client) or array of (on ...
Definition: hzl.h:285
@ HZL_ERR_TOO_MANY_CLIENTS_FOR_CONFIGURED_HEADER_TYPE
The Server configurations contains an amount of Groups that implies there is at least one Client with...
Definition: hzl.h:277
@ HZL_ERR_CANNOT_GENERATE_NON_ZERO_RANDOM
The true-random number generation failed to provide a non-zero arrays of bytes for too many times in ...
Definition: hzl.h:429
@ HZL_ERR_TOO_LONG_SDU
The user-provided data to be transmitted is too long to fit into the specified message type.
Definition: hzl.h:369
@ HZL_ERR_NULL_CONFIG_CLIENTS
The context contains a NULL pointer to the array of Client configuration structs.
Definition: hzl.h:280
@ HZL_ERR_ZERO_GROUPS
The Party configuration contains zero Groups.
Definition: hzl.h:227
@ HZL_ERR_INVALID_DELAY_BETWEEN_REN_NOTIFICATIONS
The Server-side array of Group configuration has at least one Group where the delay between successiv...
Definition: hzl.h:322
@ HZL_ERR_SECWARN_INVALID_TAG
Received message is not intact or not authentic or does not use the proper values in the hashing/auth...
Definition: hzl.h:177
@ HZL_ERR_MISSING_GID_0
The array of Group configurations must have the GID == 0 (broadcast Group) HZL_BROADCAST_GID.
Definition: hzl.h:301
@ HZL_ERR_LTK_IS_ALL_ZEROS
The configured Client's Long Term Key (or at least 1 of them for the Server) is uninitialised,...
Definition: hzl.h:232
@ HZL_ERR_CLIENTS_BITMAP_UNKNOWN_SID
The Server-side array of Group configuration has at least one Group where the bitmap of Clients in th...
Definition: hzl.h:330
@ HZL_ERR_CANNOT_GET_CURRENT_TIME
The timestamping function failed to provide the current time.
Definition: hzl.h:417
@ HZL_ERR_GID_TOO_LARGE_FOR_CONFIGURED_HEADER_TYPE
The array of Group configurations has at least one Group with a GID value that would not fit into the...
Definition: hzl.h:313
@ HZL_ERR_NULL_CURRENT_TIME_FUNC
The function pointer to the timestamping function is NULL.
Definition: hzl.h:342
@ HZL_OK
Successful completion of the operation.
Definition: hzl.h:171
@ HZL_ERR_NULL_CONFIG_CLIENT
The context contains a NULL pointer to the Client configuration struct.
Definition: hzl.h:220
@ HZL_ERR_NULL_PDU
The pointer to the Protocol Data Unit (packed CBS message) to transmit or the just-received one is NU...
Definition: hzl.h:350
@ HZL_ERR_TOO_SHORT_PDU_TO_CONTAIN_REN
The received Session Renewal Notification (REN) message is too short to be a valid REN message.
Definition: hzl.h:404
@ HZL_ERR_GAP_IN_GIDS
The array of Group configurations must contain all GIDs from 0 to hzl_ServerConfig_t....
Definition: hzl.h:295
@ HZL_ERR_SECWARN_NOT_IN_GROUP
The Client the Request originated from does not belong into the requested Group.
Definition: hzl.h:197
@ HZL_ERR_SECWARN_RFU_1
Reserved warning code for future use.
Definition: hzl.h:204
@ HZL_ERR_SECWARN_RESPONSE_TIMEOUT
The Client did not receive a Response to its Request within the preconfi␜gured timeout.
Definition: hzl.h:189
@ HZL_ERR_SECWARN_RFU_5
Reserved warning code for future use.
Definition: hzl.h:208
@ HZL_ERR_NO_POTENTIAL_RECEIVER
The building of the Secured Application Data or a Session Renewal Notification could not be performed...
Definition: hzl.h:379
@ HZL_ERR_SECWARN_RFU_4
Reserved warning code for future use.
Definition: hzl.h:207
@ HZL_ERR_MSG_IGNORED
The received message is ignored as it's not addressed to this Party or is redundant.
Definition: hzl.h:409
@ HZL_ERR_TOO_MANY_CLIENTS
The Server configuration contains more Clients that it can hold in the bitmap of Clients in each Grou...
Definition: hzl.h:271
@ HZL_ERR_SECWARN_RECEIVED_ZERO_REQNONCE
The received Request message contained an all-zeros Request Nonce.
Definition: hzl.h:411
@ HZL_ERR_INVALID_HEADER_TYPE
The Party configuration contains an unknown or unsupported CBS Header Type.
Definition: hzl.h:236
@ HZL_ERR_TOO_SHORT_PDU_TO_CONTAIN_HEADER
The received message is too short to even contain the CBS header.
Definition: hzl.h:390
@ HZL_ERR_NULL_FILENAME
The configuration file name string is NULL.
Definition: hzl.h:433
@ HZL_ERR_CLIENTS_BITMAP_INVALID_BROADCAST_GROUP
The Server-side array of Group configuration has the broadcast Group with GID == HZL_BROADCAST_GID th...
Definition: hzl.h:335
@ HZL_ERR_UNKNOWN_SOURCE
The received message's SID field indicates a Source not available in the Server's configuration and t...
Definition: hzl.h:360
@ HZL_ERR_SECWARN_OLD_MESSAGE
Received message contained a too-old counter nonce.
Definition: hzl.h:191
@ HZL_ERR_SIDS_ARE_NOT_PRESORTED_STRICTLY_ASCENDING
The array of Client configurations must be sorted from smallest to largest SID without repeated SIDs.
Definition: hzl.h:245
@ HZL_ERR_UNKNOWN_GROUP
The user-specified Group (GID) for transmission or the received message's GID field indicate a Group ...
Definition: hzl.h:357
@ HZL_ERR_TOO_SHORT_PDU_TO_CONTAIN_SADFD
The received Secured Application Data over CAN FD (SADFD) message is too short to be a valid SADFD me...
Definition: hzl.h:395
@ HZL_ERR_RENEWAL_ONGOING
The building of the message could not be performed right now, as the Session renewal phase is ongoing...
Definition: hzl.h:383
@ HZL_ERR_INVALID_MAX_CTRNONCE_DELAY
The array of Group configuration has at least one Group where the max Counter Nonce Delay field is ou...
Definition: hzl.h:306
@ HZL_ERR_CANNOT_GENERATE_RANDOM
The true-random number generation function failed to provide a random number.
Definition: hzl.h:421
@ HZL_ERR_HANDSHAKE_ONGOING
The building of the message could not be performed right now, as the handshake process (exchange of R...
Definition: hzl.h:374
@ HZL_ERR_CANNOT_OPEN_CONFIG_FILE
The configuration file could not be opened.
Definition: hzl.h:436
@ HZL_ERR_SESSION_NOT_ESTABLISHED
The Group the message is addressed to has no valid Session information in the local state.
Definition: hzl.h:364
@ HZL_ERR_NULL_STATES_GROUPS
The context contains a NULL pointer to the Group states array.
Definition: hzl.h:339
@ HZL_ERR_INVALID_PAYLOAD_TYPE
The received message contains an unknown PTY field.
Definition: hzl.h:387
@ HZL_ERR_TOO_MANY_GROUPS_FOR_CONFIGURED_HEADER_TYPE
The party configurations contains an amount of Groups that implies there is at least one Group with a...
Definition: hzl.h:263
hzl_HeaderType
Standard CBS header types.
Definition: hzl.h:450
@ HZL_HEADER_1
Definition: hzl.h:452
@ HZL_HEADER_0
Definition: hzl.h:451
@ HZL_HEADER_5
Definition: hzl.h:456
@ HZL_HEADER_2
Definition: hzl.h:453
@ HZL_HEADER_4
Definition: hzl.h:455
@ HZL_HEADER_3
Definition: hzl.h:454
@ HZL_HEADER_6
Definition: hzl.h:457
#define HZL_MAX_CAN_FD_DATA_LEN
Maximum length of the CAN FD frame's payload in bytes.
Definition: hzl.h:147
enum hzl_HeaderType hzl_HeaderType_t
Standard CBS header types.
uint64_t hzl_ReqNonce_t
Request Nonce data type.
Definition: hzl.h:474
Packed CBS PDU (Protocol Data Unit message) ready to be transmitted by the library user.
Definition: hzl.h:512
size_t dataLen
Length in bytes of the CBS-Payload.
Definition: hzl.h:513
uint8_t data[HZL_MAX_CAN_FD_DATA_LEN]
CBS-Payload.
Definition: hzl.h:514
Functions used by Hazelnet to interact with the rest of the system in order to obtain random numbers,...
Definition: hzl.h:568
HZL_SET_BY_USER hzl_TimestampFunc currentTime
Current-time timestamp generating function.
Definition: hzl.h:584
HZL_SET_BY_USER hzl_TrngFunc trng
True random number generator function.
Definition: hzl.h:575
Unpacked received SDU (Service Data Unit message) after validation (and optional decryption).
Definition: hzl.h:519
hzl_Gid_t gid
Group IDentifier the message used (expected receivers).
Definition: hzl.h:522
hzl_Sid_t sid
Source IDentifier the message used (claimed sender).
Definition: hzl.h:523
size_t dataLen
Length in bytes of the unpacked/decrypted user data.
Definition: hzl.h:520
hzl_CanId_t canId
CAN ID the underlying frame used.
Definition: hzl.h:521
uint8_t data[HZL_MAX_CAN_FD_DATA_LEN]
User data in plaintext of dataLen bytes.
Definition: hzl.h:526
bool isForUser
True if the message contains useful data for the user, false if internal.
Definition: hzl.h:525
bool wasSecured
True if it was encrypted and authenticated during transmission.
Definition: hzl.h:524