43#include "siapcommon.h"
47#include "socketclient.h"
65#define SIAP_CLIENT_PASSWORD_MAX 256U
71#define SIAP_CLIENT_USERNAME_MAX 256U
77#define SIAP_CONFIG_SIZE 26U
83#define SIAP_DEVICE_ID_SIZE 4U
85#if defined(SIAP_EXTENDED_ENCRYPTION)
90# define SIAP_AUTHENTICATION_TOKEN_SIZE 64U
96# define SIAP_AUTHENTICATION_TOKEN_SIZE 32U
103#define SIAP_DOMAIN_ID_SIZE 2U
109#define SIAP_ERROR_SIZE 1U
115#define SIAP_EXPIRATION_SIZE 8U
117#if defined(SIAP_EXTENDED_ENCRYPTION)
122# define SIAP_HASH_SIZE 64U
128# define SIAP_HASH_SIZE 32U
135#define SIAP_KEY_DURATION_DAYS 365U
141#define SIAP_KEY_DURATION_SECONDS (SIAP_KEY_DURATION_DAYS * 24U * 60U * 60U)
147#define SIAP_KEY_ID_SIZE 4U
153#define SIAP_KTREE_COUNT 1024
155#if defined(SIAP_EXTENDED_ENCRYPTION)
160# define SIAP_KTAG_STATE_HASH 64U
166# define SIAP_KTAG_STATE_HASH 32U
169#if defined(SIAP_EXTENDED_ENCRYPTION)
174# define SIAP_MAC_SIZE 64U
180# define SIAP_MAC_SIZE 32U
187#define SIAP_NONCE_SIZE 32U
189#if defined(SIAP_EXTENDED_ENCRYPTION)
194# define SIAP_SALT_SIZE 64U
200# define SIAP_SALT_SIZE 32U
207#define SIAP_SERVER_GROUP_ID_SIZE 2U
213#define SIAP_SERVER_ID_SIZE 2U
215#if defined(SIAP_EXTENDED_ENCRYPTION)
220# define SIAP_SERVER_KEY_SIZE 64U
226# define SIAP_SERVER_KEY_SIZE 32U
233#define SIAP_USER_GROUP_ID_SIZE 2U
239#define SIAP_USER_ID_SIZE 4U
247#define SIAP_DID_SIZE (SIAP_DOMAIN_ID_SIZE + SIAP_SERVER_GROUP_ID_SIZE + SIAP_SERVER_ID_SIZE + SIAP_USER_GROUP_ID_SIZE + SIAP_USER_ID_SIZE + SIAP_DEVICE_ID_SIZE)
253#define SIAP_SID_SIZE (SIAP_DOMAIN_ID_SIZE + SIAP_SERVER_GROUP_ID_SIZE + SIAP_SERVER_ID_SIZE)
259#define SIAP_KID_SIZE (SIAP_DID_SIZE + SIAP_KEY_ID_SIZE)
265#define SIAP_KTREE_SIZE (SIAP_AUTHENTICATION_TOKEN_SIZE * SIAP_KTREE_COUNT)
271#define SIAP_DEVICE_KEY_ENCODED_SIZE ((SIAP_AUTHENTICATION_TOKEN_SIZE * SIAP_KTREE_COUNT) + SIAP_MAC_SIZE + SIAP_KID_SIZE + SIAP_EXPIRATION_SIZE)
277#define SIAP_DEVICE_TAG_ENCODED_SIZE (SIAP_KID_SIZE + SIAP_KTAG_STATE_HASH + SIAP_HASH_SIZE)
283#define SIAP_SERVER_KEY_ENCODED_SIZE (SIAP_SERVER_KEY_SIZE + SIAP_SID_SIZE + SIAP_SERVER_KEY_SIZE + SIAP_EXPIRATION_SIZE)
287#if defined(SIAP_EXTENDED_ENCRYPTION)
291static const char SIAP_CONFIG_STRING[
SIAP_CONFIG_SIZE + 1U] =
"r01-siap-rcs512-keccak512";
296static const char SIAP_CONFIG_STRING[
SIAP_CONFIG_SIZE + 1U] =
"r02-siap-rcs256-keccak256";
300#define SIAP_ERROR_STRING_DEPTH 12U
301#define SIAP_ERROR_STRING_WIDTH 128U
303static const char SIAP_ERROR_STRINGS[SIAP_ERROR_STRING_DEPTH][SIAP_ERROR_STRING_WIDTH] =
305 "The operation was succesful",
306 "The authentication has failed",
307 "The identity strings do not match",
308 "The key card has expired",
309 "The device passphrase is unrecognized",
310 "The cards authentication tokens are invalid",
311 "The key card decryption failed",
312 "The authentication token is invalid",
313 "The server could not generate the token",
314 "The file could not be read",
315 "The file path specified is invalid",
316 "The file is locked or unavailable",
#define SIAP_CONFIG_SIZE
The size of the protocol configuration string.
Definition siap.h:77
SIAP_EXPORT_API void siap_serialize_server_key(uint8_t *output, const siap_server_key *skey)
Serialize a server key into a byte array. This function serializes a SIAP server key structure into a...
Definition siap.c:94
SIAP_EXPORT_API void siap_deserialize_device_key(siap_device_key *dkey, const uint8_t *input)
Deserialize a client device key. This function deserializes a byte array into a SIAP device key struc...
Definition siap.c:7
#define SIAP_SALT_SIZE
The SIAP salt size in bytes.
Definition siap.h:200
SIAP_EXPORT_API void siap_log_system_error(siap_errors err)
Log a system error message.
Definition siap.c:141
#define SIAP_KTREE_SIZE
The key tree size in bytes.
Definition siap.h:265
#define SIAP_SID_SIZE
The server ID size in bytes.
Definition siap.h:253
#define SIAP_HASH_SIZE
The SIAP hash size in bytes.
Definition siap.h:128
SIAP_EXPORT_API const char * siap_error_to_string(siap_errors error)
Return a string description of an SIAP error code. This function returns a human-readable string corr...
Definition siap.c:178
#define SIAP_KTAG_STATE_HASH
The client key state hash size.
Definition siap.h:166
#define SIAP_SERVER_KEY_SIZE
The master key size in bytes.
Definition siap.h:226
#define SIAP_MAC_SIZE
The SIAP MAC size in bytes.
Definition siap.h:180
SIAP_EXPORT_API void siap_increment_device_key(siap_device_key *dkey)
Increment the device key This function clears a key at the current position and increments the kid co...
Definition siap.c:113
siap_errors
The SIAP error values. This enumeration defines the error codes returned by SIAP functions.
Definition siap.h:326
@ siap_error_decryption_failure
Definition siap.h:333
@ siap_error_none
Definition siap.h:327
@ siap_error_token_tree_invalid
Definition siap.h:332
@ siap_error_file_read_failure
Definition siap.h:336
@ siap_error_file_copy_failure
Definition siap.h:338
@ siap_error_identity_mismatch
Definition siap.h:329
@ siap_error_authentication_failure
Definition siap.h:328
@ siap_error_token_not_created
Definition siap.h:335
@ siap_error_key_expired
Definition siap.h:330
@ siap_error_token_invalid
Definition siap.h:334
@ siap_error_passphrase_unrecognized
Definition siap.h:331
@ siap_error_file_invalid_path
Definition siap.h:337
#define SIAP_KID_SIZE
The tree-key ID size in bytes.
Definition siap.h:259
SIAP_EXPORT_API const char * siap_get_error_description(siap_errors emsg)
Get the error string description.
Definition siap.c:126
SIAP_EXPORT_API void siap_serialize_device_tag(uint8_t *output, const siap_device_tag *dtag)
Serialize a device tag into a byte array. This function serializes a SIAP device tag structure into a...
Definition siap.c:58
SIAP_EXPORT_API void siap_log_error(siap_errors emsg, const char *msg)
Log the message, socket error, and string description.
Definition siap.c:154
SIAP_EXPORT_API void siap_deserialize_server_key(siap_server_key *skey, const uint8_t *input)
Deserialize a server key from a byte array. This function deserializes a byte array into a SIAP serve...
Definition siap.c:75
SIAP_EXPORT_API void siap_deserialize_device_tag(siap_device_tag *dtag, const uint8_t *input)
Deserialize a device tag from a byte array. This function deserializes a byte array into a SIAP devic...
Definition siap.c:41
SIAP_EXPORT_API void siap_serialize_device_key(uint8_t *output, const siap_device_key *dkey)
Serialize a client device key. This function serializes a SIAP device key structure into a byte array...
Definition siap.c:24
The SIAP device key structure. This structure contains the SIAP device key, the device key identity,...
Definition siap.h:347
uint8_t kid[SIAP_KID_SIZE]
Definition siap.h:349
uint64_t expiration
Definition siap.h:350
uint8_t ktree[SIAP_KTREE_SIZE+SIAP_MAC_SIZE]
Definition siap.h:348
uint8_t kid[SIAP_KID_SIZE]
Definition siap.h:360
uint8_t khash[SIAP_KTAG_STATE_HASH]
Definition siap.h:361
uint8_t phash[SIAP_HASH_SIZE]
Definition siap.h:362
The SIAP server key structure. This structure contains the SIAP server key, the server's domain ident...
Definition siap.h:371
uint64_t expiration
Definition siap.h:375
uint8_t kbase[SIAP_SERVER_KEY_SIZE]
Definition siap.h:372
uint8_t sid[SIAP_SID_SIZE]
Definition siap.h:373
uint8_t dsalt[SIAP_SALT_SIZE]
Definition siap.h:374