Protocol++® (Protocolpp®)  v5.6.2
ProtocolPP::jprotocol Class Referenceabstract
Inheritance diagram for ProtocolPP::jprotocol:

Public Member Functions

 jprotocol (direction_t dir)
 
 jprotocol (direction_t dir, std::string &file)
 
 jprotocol (direction_t dir, std::shared_ptr< jrand > &rand)
 
 jprotocol (direction_t dir, std::shared_ptr< jrand > &rand, std::string &file)
 
virtual ~jprotocol ()
 Standard deconstructor.
 
virtual void encap_packet (std::shared_ptr< jarray< uint8_t >> &output)
 
virtual void decap_packet (std::shared_ptr< jarray< uint8_t >> &input)
 
virtual void encap_packet (std::shared_ptr< jarray< uint8_t >> &input, std::shared_ptr< jarray< uint8_t >> &output)=0
 
virtual void decap_packet (std::shared_ptr< jarray< uint8_t >> &input, std::shared_ptr< jarray< uint8_t >> &output)=0
 
virtual jarray< uint8_t > get_hdr ()=0
 
virtual uint64_t get_field (field_t field)
 
virtual uint64_t get_field (field_t field, jarray< uint8_t > &hdr)=0
 
virtual void set_hdr (jarray< uint8_t > &hdr)=0
 
virtual void set_field (field_t field, uint64_t value)=0
 
bool hasfile ()
 
uint32_t get_status ()
 
virtual void to_xml (tinyxml2::XMLPrinter &myxml, direction_t direction)=0
 
virtual void to_json (std::ofstream &myjson, direction_t direction, std::string &indent)=0
 
jarray< uint8_t > checksum (iana_t prot, direction_t dir, jarray< uint8_t > &check, uint32_t offset=0)
 
jarray< uint8_t > pad (pad_t padtype, uint32_t len)
 
 jprotocol (jprotocol &jprotocol)=delete
 
 jprotocol (const jprotocol &jprotocol)=delete
 

Static Public Member Functions

const static std::string currentDateTime ()
 
static std::string str_status (uint32_t status)
 
static jarray< uint8_t > to_array (uint8_t input)
 
static jarray< uint8_t > to_array (uint16_t input)
 
static jarray< uint8_t > to_array (uint32_t input)
 
static jarray< uint8_t > to_array (uint64_t input)
 
static uint8_t to_u8 (jarray< uint8_t > src_array)
 
static uint16_t to_u16 (jarray< uint8_t > src_array)
 
static uint32_t to_u32 (jarray< uint8_t > src_array)
 
static uint64_t to_u64 (jarray< uint8_t > src_array)
 
static uint32_t fnv_hash (std::shared_ptr< jarray< uint8_t >> &header, jarray< uint8_t > &mask, uint32_t hdrlen)
 

Protected Member Functions

template<typename T , typename TE >
std::shared_ptr< jreplay< T, TE > > update_replay (protocol_t prot, T &seqnum, TE &extseq, bool usext, uint32_t size)
 
template<typename T , typename TE >
std::shared_ptr< jreplay< T, TE > > update_replay (protocol_t prot, T &seqnum, TE &extseq, bool usext, uint32_t size, jarray< uint8_t > &window)
 
void update_status (uint32_t stat)
 
void get_data (std::shared_ptr< jarray< uint8_t >> &data)
 
void put_data (std::shared_ptr< jarray< uint8_t >> &wdata)
 
void encryptdat (std::shared_ptr< jarray< uint8_t >> &red, std::shared_ptr< jarray< uint8_t >> &black)
 
void decryptdat (std::shared_ptr< jarray< uint8_t >> &black, std::shared_ptr< jarray< uint8_t >> &red)
 
uint32_t roundup (uint32_t value, uint32_t mult)
 

Protected Attributes

direction_t m_dir
 direction of processing
 
uint32_t m_status
 
std::shared_ptr< jrandm_rand
 random data generator passed into constructor
 
std::string m_filename
 file input string for this protocol
 
std::fstream m_file
 input file stream object for this protocol
 
endian_t m_endian
 endianess string for this protocol
 

Constructor & Destructor Documentation

◆ jprotocol() [1/4]

ProtocolPP::jprotocol::jprotocol ( direction_t  dir)
explicit

Constructor for base class of protocols which accepts the maximum transmission unit (MTU)

Parameters
dir- direction of processing either ENCAP or DECAP

◆ jprotocol() [2/4]

ProtocolPP::jprotocol::jprotocol ( direction_t  dir,
std::string &  file 
)

Constructor for base class of protocols which accepts the maximum transmission unit (MTU) and a path to a file which contains the data to transmit

Parameters
dir- direction of processing either ENCAP or DECAP
file- input file that contains data to transmit

◆ jprotocol() [3/4]

ProtocolPP::jprotocol::jprotocol ( direction_t  dir,
std::shared_ptr< jrand > &  rand 
)

Constructor for base class of protocols which accepts the maximum transmission unit (MTU), an anti-replay structure, and a pointer to a random number generator for cryptographic purposes

Parameters
dir- direction of processing either ENCAP or DECAP
rand- pointer to random number generator for cryptographic functionality such as padding

◆ jprotocol() [4/4]

ProtocolPP::jprotocol::jprotocol ( direction_t  dir,
std::shared_ptr< jrand > &  rand,
std::string &  file 
)

Constructor for base class of protocols which accepts the maximum transmission unit (MTU), an anti-replay structure, and a pointer to a random number generator for cryptographic purposes

Parameters
dir- direction of processing either ENCAP or DECAP
file- input file that contains data to transmit
rand- pointer to random number generator for cryptographic functionality such as padding

Member Function Documentation

◆ checksum()

jarray<uint8_t> ProtocolPP::jprotocol::checksum ( iana_t  prot,
direction_t  dir,
jarray< uint8_t > &  check,
uint32_t  offset = 0 
)

helper functions for use with all protocols that need them Checksum calculates a 1's complement running sum across all 16-bit values in the input data. Algorithm is based on the protocol requested

Parameters
prot- protocol to calculate the checksum for
dir- direction of the data flow
check- data to checksum
offset- offset into the data to clear checksum field
Returns
array containing calculated checkum

◆ currentDateTime()

const static std::string ProtocolPP::jprotocol::currentDateTime ( )
static

Get current date/time, format is YYYY-MM-DD.HH:mm:ss

Returns
data/time formatted as string

◆ decap_packet() [1/2]

virtual void ProtocolPP::jprotocol::decap_packet ( std::shared_ptr< jarray< uint8_t >> &  input)
inlinevirtual

packet processing functions for use with protocols that access files (TCP, UDP, IP). Decap takes packets from the system decapsulates the packet, and writes the resulting payload to the file given in the constructor with each packet containing MTU worth of data in the packet

Parameters
input- shared pointer to received packet whose payload will be written to the file passed to the constructor

Reimplemented in ProtocolPP::judp, and ProtocolPP::jip.

◆ decap_packet() [2/2]

virtual void ProtocolPP::jprotocol::decap_packet ( std::shared_ptr< jarray< uint8_t >> &  input,
std::shared_ptr< jarray< uint8_t >> &  output 
)
pure virtual

packet processing functions for use with all protocols. Decap takes a packet from an upper-layer protocol and decapsulates the packet and returns the payload. Both the input and output packets are shared pointers to arrays containing payloads and packets respectively

Implemented in ProtocolPP::jxmss, ProtocolPP::jlms, ProtocolPP::jkyber, ProtocolPP::jfalcon, ProtocolPP::jdilithium, ProtocolPP::jwimax, ProtocolPP::jwifi, ProtocolPP::judp, ProtocolPP::jtls13, ProtocolPP::jtls, ProtocolPP::jtcp, ProtocolPP::jsrtp, ProtocolPP::jrsa, ProtocolPP::jmemblob, ProtocolPP::jmacsec, ProtocolPP::jlte, ProtocolPP::jipsec, ProtocolPP::jip, ProtocolPP::jintegrity, ProtocolPP::jicmp, ProtocolPP::jgre, ProtocolPP::jecdsafp, ProtocolPP::jecdsaf2m, ProtocolPP::jecdsaed, ProtocolPP::jdtls13, ProtocolPP::jdsa, and ProtocolPP::jconfident.

◆ decryptdat()

void ProtocolPP::jprotocol::decryptdat ( std::shared_ptr< jarray< uint8_t >> &  black,
std::shared_ptr< jarray< uint8_t >> &  red 
)
protected

Decrypt data (key, context, etc) If information needed for the protocol has key material in it decrypt the data after reading from memory

Parameters
black- encrypted data to decrypt
red- decrypted plaintext

◆ encap_packet() [1/2]

virtual void ProtocolPP::jprotocol::encap_packet ( std::shared_ptr< jarray< uint8_t >> &  input,
std::shared_ptr< jarray< uint8_t >> &  output 
)
pure virtual

packet processing functions for use with all protocols. Encap takes a payload or packet generated by a lower-level protocol encapsulates the packet according to the protocol selected, and returns the resulting packet. Both the input and output packets are shared pointers to arrays containing payloads and packets respectively

Implemented in ProtocolPP::jxmss, ProtocolPP::jlms, ProtocolPP::jkyber, ProtocolPP::jfalcon, ProtocolPP::jdilithium, ProtocolPP::jwimax, ProtocolPP::jwifi, ProtocolPP::judp, ProtocolPP::jtls13, ProtocolPP::jtls, ProtocolPP::jtcp, ProtocolPP::jsrtp, ProtocolPP::jrsa, ProtocolPP::jmemblob, ProtocolPP::jmacsec, ProtocolPP::jlte, ProtocolPP::jipsec, ProtocolPP::jip, ProtocolPP::jintegrity, ProtocolPP::jicmp, ProtocolPP::jgre, ProtocolPP::jecdsafp, ProtocolPP::jecdsaf2m, ProtocolPP::jecdsaed, ProtocolPP::jdtls13, ProtocolPP::jdsa, and ProtocolPP::jconfident.

◆ encap_packet() [2/2]

virtual void ProtocolPP::jprotocol::encap_packet ( std::shared_ptr< jarray< uint8_t >> &  output)
inlinevirtual

packet processing functions for use with protocols that access files (TCP, UDP, IP). Encap generates packets from the file given in the constructor with each packet containing MTU worth of data in the packet

Parameters
output- shared pointer to generated output packet

Reimplemented in ProtocolPP::judp, and ProtocolPP::jip.

◆ encryptdat()

void ProtocolPP::jprotocol::encryptdat ( std::shared_ptr< jarray< uint8_t >> &  red,
std::shared_ptr< jarray< uint8_t >> &  black 
)
protected

Encrypt data (key, context, etc) If information needed for the protocol contains key material encrypt the data before writing to memory

Parameters
red- plaintext data to encrypt
black- encrypted data to write to memory

◆ fnv_hash()

static uint32_t ProtocolPP::jprotocol::fnv_hash ( std::shared_ptr< jarray< uint8_t >> &  header,
jarray< uint8_t > &  mask,
uint32_t  hdrlen 
)
static

helper function for use with all protocols that need them fnv_hash returns a 32-bit value of the hash over the protocol header after masking the mutable fields

Parameters
header- Header of the packet
mask- Mask for mutable header fields
hdrlen- Length of the header in bytes to hash (e.g., 20 for IPv4)
Returns
FNV hash over header for unique value

◆ get_data()

void ProtocolPP::jprotocol::get_data ( std::shared_ptr< jarray< uint8_t >> &  data)
protected

accessor functions for file I/O Get data accesses the file and retrieves MTU length of data from it

Parameters
data- array filled with data from the file returns true until EOF is reached then returns FALSE when last packet is returned with FALSE set, the array will be properly trimmed to the size of the remaining data

◆ get_field() [1/2]

◆ get_field() [2/2]

◆ get_hdr()

◆ get_status()

uint32_t ProtocolPP::jprotocol::get_status ( )

return the status for the packet with the following format

--------------------------------------------------------------
| Protocol (8-bits) | Error (8-bits) | Line Number (16-bits) |
--------------------------------------------------------------
  • Protocol codes in STATUS:
    • NO_ERROR - No errors (value of 0)
    • PROTOCOL - JProtocol base class (value of 1)
    • MACSEC - Macsec protocol (value of 2)
    • WIFI - Wifi protocol (value of 3)
    • WIGIG - WiGig protocol (value of 4)
    • WIMAX - WiMax protocol (value of 5)
    • LTE - Long Term Evolution (LTE/3GPP) protocol (value of 6)
    • RLC - Radio Link Control (value of 7)
    • TLS - Transport Layer Security (TLS/SSL) protocol (value of 8)
    • SRTP - Secure RTP protocol (value of 9)
    • UDP - User Datagram Protocol (UDP) (value of 10)
    • TCP - Transport Control Protocol (TCP) (value of 11)
    • ICMP - Internet Control Message Protocol (ICMP) (value of 12)
    • IP - Internet Protocol (IP) (value of 13)
    • IPSEC - Encapsulating Security Protocol (ESP) (value of 14)
    • XMLPARSER - TinyXML2 parser (value of 15)
    • RINGDRIVER - Ring driver (value of 16)
    • DIRECTDRIVER - Direct driver (value of 17)
    • DRIVER - Driver (value of 18)
    • LOOPBACK - Ethernet Loopback mode (value of 19)
    • ETHERNET - Ethernet protocol (value of 20)
    • RSA - RSA Signature and Encryption Scheme (value of 21)
    • DSA - Digital Signature Algorithm (value of 22)
    • ECDSAFp- Elliptic Curve Digital Signature Algorithm Fp (value 23)
    • ECDSAF2M - Elliptic Curve Digital Signature Algorithm F2M (value 24)
    • ECDSAEd - Edwards Curve Digital Signature Algorithm (value 25)
    • IKEV2 - Internet Key Exchange v2 (value of 26)
    • INTEGRITY - Standalone integrity algorithms in testbench (value of 27)
    • CONFIDENT - Standalone confidentialy algorithms in testbench (value of 28)
    • BLOB - Memory blobs (value of 29)
    • XMSS - XMSS Signature Scheme (value of 30)
    • LMS - LMS Signature Scheme (value of 31)
    • TLS13 - Version 1.3 of the TLS protocol (value of 32)
    • DTLS13 - Version 1.3 of the DTLS protocol (value of 33)
    • EGRE - Extended GRE protocol (value of 34)
    • NVGRE - NVGRE protocol (value of 35)
    • VXLAN - VXLAN protocol (value of 36)
    • KYBER - Kyber KEM protocol (value of 37)
    • DILITHIUM - Dilithium signature algorithm (value of 38)
    • FALCON - Falcon signature algorithm (value of 39)
    • SPHINCS - Sphincs+ signature algirthm (value of 40)
    • NOPROTO - No protocol (value of 41)
  • Error Codes in STATUS:
    • ERR_NONE - No error (value of 0)
    • ERR_LATE - Anti-replay late packet error found (value of 1)
    • ERR_REPLAY - Anti-replay error found (value of 2)
    • ERR_ROLLOVER - Packet number rollover error (value of 3)
    • ERR_ROLLUNDER - Packet number rollunder error (value of 4)
    • ERR_PROGRAM - Programming error (value of 5)
    • ERR_ICV - ICV check failure (value of 6)
    • ERR_CRC - CRC check failure (value of 7)
    • ERR_READ_ENDOFILE - Read end of file (value of 8)
    • ERR_READ_FAILFILE - Read failed in input file (value of 9)
    • ERR_READ_BADFILE - Read of missing file (value of 10)
    • ERR_WRITE_FAILFILE - Write to missing file (value of 11)
    • ERR_WRITE_BADFILE - Write error to output file (value of 12)
    • ERR_CHECKSUM - Checksum error (value of 13)
    • ERR_LISTEN - TCP server received packet while listening without SYN=1 (value of 14)
    • ERR_ACKNUM - TCP ACKNUM is incorrect (value of 15)
    • ERR_CLOSED - TCP session CLOSED during TX/RX (value of 16)
    • ERR_BITS - TCP header reserved bits error (value of 17)
    • ERR_TTL - TTL field of packet is zero (value of 18)
    • ERR_JUMBOGRAM_FORMAT - IPv6 JUMBOGRAM formatting error (value of 19)
    • WARN_DUMMY - Dummy packet received warning (value of 20)
    • WARN_IPV6_ROUTE - IPv6 Route header but not for this destination (value of 21)
    • WARN_ZERO_DATA - Zero length payload warning (value of 22)
    • ERR_ICMP_HDR_EXT_LEN - Header extension length is ODD for ROUTE header (value of 23)
    • ERR_ICMP_SEGMENTS_LEFT - In ROUTE header, Segments left is larger than N (value of 24)
    • ERR_MULTICAST_EXT_HDR - In ROUTE header, Multicast address present (value of 25)
    • ERR_UNKNOWN_ROUTE_TYPE - In ROUTE header, Unknown route type (only type 0 is supported, value of 26
    • ERR_CIPHER_KEY_SIZE - For the cipher requested, the key size is incorrect (value of 27)
    • ERR_AUTH_KEY_SIZE - For the authentication requested, the key size is incorrect (value of 28)
    • ERR_IV_SIZE - For the initialization vector requested, the size is incorrect (value of 29)
    • ERR_SALT_SIZE - For the cipher salt requested, the size is incorrect (value of 30)
    • ERR_ICV_SIZE - For the authentication requested, the ICV size is incorrect (value of 31)
    • ERR_UNKNOWN_NXTHDR - For the IP packet, unknown NH value (value of 32)
    • ERR_FORMAT_ERROR - Malformed packet (value of 33)
    • WARN_INPUT_QUEUE_FULL - Send queue is full (value of 34)
    • WARN_OUTPUT_QUEUE_EMPTY - Receive queue is empty (value of 35)
    • ERR_SA_NOT_FOUND - Security Association not found (value of 36)
    • ERR_KEY_NOKEY - The key specified is invalid or not found (value of 37)
    • ERR_KEY_EXPIRED - The key specified has expired (value of 38)
    • ERR_KEY_REVOKED - The key specified has been revoked (value of 39)
    • ERR_KEY_ACCESS - The key exists but is not readable by the calling process or cant be modified by the user (value of 40)
    • ERR_KEY_NOT_SUPP - The key type does not support reading of the payload data (value of 41)
    • ERR_KEY_QUOTA - The key quota for this user would be exceeded by creating this key (value of 42)
    • ERR_KEY_INVALID - The payload data was invalid (value of 43)
    • ERR_KEY_REJECTED - The attempt to generate a new key was rejected (value of 44)
    • ERR_KEY_NOMEM - Insufficient memory to create a key (value of 45)
    • ERR_KEY_INTR - The request was interrupted by a signal (value of 46)
    • ERR_RSA_INVALID_CODING - Coding of RSA decrypted data was incorrect (value of 47)
    • ERR_RSA_MESSAGE_LENGTH - Decrypted RSA message length was incorrect (value of 48)
    • ERR_INVALID_SIGNATURE - Signature verification failed (value of 49)
    • WARN_NO_VLAN - VLAN tags did not match (value of 50)
    • ERR_ICVFAIL_LIMIT - DTLSv13 maximum packet ICV fail limit reached
    • ERR_PADDING - DTLSv13 non-zero padding found
    • ERR_EPOCH_DTLS13 - DTLSv13 incorrect EPOCH used with key association
    • ERR_UNKNOWN - Unknown error (value of 51)
  • Line number in code where the error occurred

◆ hasfile()

bool ProtocolPP::jprotocol::hasfile ( )

check for file input/output

Returns
- file is present or not

◆ pad()

jarray<uint8_t> ProtocolPP::jprotocol::pad ( pad_t  padtype,
uint32_t  len 
)

helper functions for use with all protocols that need them Pad generates padding material to be appended to the packet if needed. Supports either ZERO, INCREMENTING, SIZE, or RANDOM padding

Parameters
padtype- Type of padding to generate (ZERO, INCREMENT, SIZE, RANDOM)
len- the amount of padding to generate
Returns
array containing padding requested

◆ put_data()

void ProtocolPP::jprotocol::put_data ( std::shared_ptr< jarray< uint8_t >> &  wdata)
protected

accessor functions for file I/O Put data accesses the file and writes the payload to the file

Parameters
wdata- an array of data to write to the file

◆ roundup()

uint32_t ProtocolPP::jprotocol::roundup ( uint32_t  value,
uint32_t  mult 
)
protected

roundup the value

Parameters
value- Value to round up
mult- Next multiple of value to round to
Returns
value rounded up to next multiple of mult

◆ set_field()

◆ set_hdr()

◆ str_status()

static std::string ProtocolPP::jprotocol::str_status ( uint32_t  status)
static

Interpret the status word and return as a printable string

Parameters
status- Status word to interpret
Returns
Printable string representation of the status word

◆ to_array() [1/4]

static jarray<uint8_t> ProtocolPP::jprotocol::to_array ( uint16_t  input)
static

Convert uint16_t into a byte array

Parameters
input- uint16_t to convert
Returns
byte array in current endian format

◆ to_array() [2/4]

static jarray<uint8_t> ProtocolPP::jprotocol::to_array ( uint32_t  input)
static

Convert uint32_t into a byte array

Parameters
input- uint32_t to convert
Returns
byte array in current endian format

◆ to_array() [3/4]

static jarray<uint8_t> ProtocolPP::jprotocol::to_array ( uint64_t  input)
static

Convert uint64_t into a byte array

Parameters
input- uint64_t to convert
Returns
byte array in current endian format

◆ to_array() [4/4]

static jarray<uint8_t> ProtocolPP::jprotocol::to_array ( uint8_t  input)
static

Convert uint8_t into a byte array

Parameters
input- uint8_t to convert
Returns
byte array in current endian format

◆ to_json()

virtual void ProtocolPP::jprotocol::to_json ( std::ofstream &  myjson,
direction_t  direction,
std::string &  indent 
)
pure virtual

◆ to_u16()

static uint16_t ProtocolPP::jprotocol::to_u16 ( jarray< uint8_t >  src_array)
static

Convert a byte array into a uint16_t

Parameters
src_array- jarray to convert, must be 2 or fewer bytes
Returns
uint16_t in current endian format

◆ to_u32()

static uint32_t ProtocolPP::jprotocol::to_u32 ( jarray< uint8_t >  src_array)
static

Convert a byte array into a uint32_t

Parameters
src_array- jarray to convert, must be 4 or fewer bytes
Returns
uint32_t in current endian format

◆ to_u64()

static uint64_t ProtocolPP::jprotocol::to_u64 ( jarray< uint8_t >  src_array)
static

Convert a byte array into a uint64_t

Parameters
src_array- jarray to convert, must be 8 or fewer bytes
Returns
uint64_t in current endian format

◆ to_u8()

static uint8_t ProtocolPP::jprotocol::to_u8 ( jarray< uint8_t >  src_array)
static

Convert a byte array into a uint8_t

Parameters
src_array- jarray to convert, must be 1 byte
Returns
uint8_t in current endian format

◆ to_xml()

◆ update_replay() [1/2]

template<typename T , typename TE >
std::shared_ptr<jreplay<T,TE> > ProtocolPP::jprotocol::update_replay ( protocol_t  prot,
T &  seqnum,
TE &  extseq,
bool  usext,
uint32_t  size 
)
inlineprotected

helper functions for use with all protocols that need them Update_replay returns a shared_ptr pointing at a new jreplay() object for anti-replay functionality

Parameters
prot- protocol to use anti-replay
seqnum- initial sequence number
extseq- initial extended sequence number
usext- extended sequence number is used for anti-replay
size- number of packets to track
Returns
shared_ptr to the anti-replay object

◆ update_replay() [2/2]

template<typename T , typename TE >
std::shared_ptr<jreplay<T,TE> > ProtocolPP::jprotocol::update_replay ( protocol_t  prot,
T &  seqnum,
TE &  extseq,
bool  usext,
uint32_t  size,
jarray< uint8_t > &  window 
)
inlineprotected

helper functions for use with all protocols that need them Update_replay returns a shared_ptr pointing at a new jreplay() object for anti-replay functionality

Parameters
prot- protocol to use anti-replay
seqnum- initial sequence number
extseq- initial extended sequence number
usext- extended sequence number is used for anti-replay
size- number of packets to track
window- initial anti-replay window
Returns
shared_ptr to the anti-replay object

◆ update_status()

void ProtocolPP::jprotocol::update_status ( uint32_t  stat)
protected

accessor functions for the status Updates the status with the new value

Parameters
stat- new value for the status

Member Data Documentation

◆ m_status

uint32_t ProtocolPP::jprotocol::m_status
protected

Status value for packet processing with format

--------------------------------------------------------------
| Protocol (8-bits) | Error (8-bits) | Line Number (16-bits) |
--------------------------------------------------------------

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