VatiCAN  1.1
Public Member Functions | Public Attributes | List of all members
VatiCAN Class Reference

Public Member Functions

 VatiCAN (const char *password, uint16_t spongeCap, MCP_CAN &can, CANSENDER globalNonceID)
void StartNonceServer (uint32_t everyMS)
void StopNonceServer ()
void MessageAuthentication (CANSENDER ID, uint64_t counter, const uint8_t *msg, int16_t msglength, uint8_t *mac)
void Send (CANSENDER id, uint8_t *payload, uint8_t len)
bool AddVatiCANChannel (CANSENDER legacyID, CANSENDER vatiCANID)
VerifyState Available (CANSENDER &id, uint8_t **buffer, uint8_t &lenght)
uint64_t GetRemoteCounter (CANSENDER id)
uint64_t GetGlobalNonce ()
void FillRealRandom (uint8_t *buffer, uint8_t length)

Public Attributes

uint32_t TotalMessagesSent = 0u
uint32_t TotalMessagesRecvd = 0u
uint32_t NonceIntervall = 0u
bool ForwardNoncePacket = false

Constructor & Destructor Documentation

◆ VatiCAN()

VatiCAN::VatiCAN ( const char *  password,
uint16_t  spongeCap,
MCP_CAN &  can,
CANSENDER  globalNonceID 

Creates a new VatiCAN instance

passwordThe password for the keyed-hash authentication
spongeCapThe capacity of the underlying sponge function (security/performance tradeoff)
canUnerlying CAN bus interface
globalNonceIDThe CAN ID that the Nonce (send/receive) will use

Member Function Documentation

◆ AddVatiCANChannel()

bool VatiCAN::AddVatiCANChannel ( CANSENDER  legacyID,

Registers a CAN ID for use with VatiCAN authenticated messages. Its authentication channel (usually ID + 1) must be specified as well.

legacyIDThe ID to add to the list
vatiCANIDThe ID to be used for MACs
true if sucessfully added to the list, false if list was full.

◆ Available()

VerifyState VatiCAN::Available ( CANSENDER &  id,
uint8_t **  buffer,
uint8_t &  lenght 

Needs to be called regularly. This function does the heav-duty lifting (MAC calculation) of arrived messages. It is done asynchronously and not while a a new message arrives in order to lift the burden off the ISR.

idReturn value that holds the sender's CAN ID (legacy ID, never VatiCAN ID)
bufferReturn value that points to the payload buffer
lengthReturn value that holds the payload's length
NOTHING if no new messages, otherwise one of MAC_OK, MAC_WRONG for VatiCAN messages or MSG_RAW for legacy un-authenticated messages

◆ FillRealRandom()

void VatiCAN::FillRealRandom ( uint8_t *  buffer,
uint8_t  length 

Uses the AVR hardware (floating inputs) to generate noise and use it to generate randomness

bufferBuffer to be filled, byte by byte
lengthLength of that buffer

◆ GetGlobalNonce()

uint64_t VatiCAN::GetGlobalNonce ( )

Returns the currently valid global nonce

The currently valid global nonce

◆ GetRemoteCounter()

uint64_t VatiCAN::GetRemoteCounter ( CANSENDER  id)

Returns the current counter for a remote ID

idCAN ID to check for
That CAN ID's current counter or 0ul if invalid.

◆ MessageAuthentication()

void VatiCAN::MessageAuthentication ( CANSENDER  ID,
uint64_t  counter,
const uint8_t *  msg,
int16_t  msglength,
uint8_t *  mac 

Computes a keyed-hash message authentication code (MAC)

IDThe sender/receiver CAN ID that is used for computing the MAC
msgThe message for which to compute the code
msglengthThe length of that message (typically 1 to 8 bytes for CAN)
macBuffer to save the MAC to (64 bits)

◆ Send()

void VatiCAN::Send ( CANSENDER  id,
uint8_t *  payload,
uint8_t  len 

Sends a message over the CAN bus. If the sender id is in the list of secure IDs, an MAC is automatically appended and sent from the authentication ID.

idThe sender's ID
payloadThe bytes to send (0 to 8)
lenThe length of the supplied payload

◆ StartNonceServer()

void VatiCAN::StartNonceServer ( uint32_t  everyMS)

Starts to send a new global Nonce every everyMS milliseconds.

everyMSInterval between Nonce updates

◆ StopNonceServer()

void VatiCAN::StopNonceServer ( )

Stops sending Nonces to others

The documentation for this class was generated from the following files: