-- raw types for the communication protocol -- these are used throughout at the lowest level of the protocol -- essentially they are the units of packets and of messages -- SMG.Comms has only 2 types of packets: RSA and Serpent -- a message is the decrypted content of a packet -- S.MG, 2018 with Interfaces; use Interfaces; -- Unsigned_n and Integer_n with Ada.Unchecked_Conversion; package Raw_Types is -- no side effects or internal state Pragma Pure(Raw_Types); -- constants from SMG.COMMS standard specification -- size of a serpent-encrypted packet and message, in octets -- note that this corresponds to 1472/16 = 92 Serpent blocks -- NB: lengths are the same! SERPENT_OCTETS : constant Positive := 1472; -- size of a RSA-encrypted packet and message in octets and bits RSA_PKT_OCTETS : constant Positive := 1470; RSA_MSG_OCTETS : constant Positive := 234; RSA_MSG_BITS : constant Positive := RSA_MSG_OCTETS * 8; --1872 -- raw, low-level types -- all messages and packets are simply arrays of octets at low level/raw type Octets is array( Natural range <> ) of Interfaces.Unsigned_8; -- raw representations of basic types (with fixed, well-defined sizes) subtype Octets_1 is Octets( 1 .. 1 ); subtype Octets_2 is Octets( 1 .. 2 ); subtype Octets_4 is Octets( 1 .. 4 ); subtype Octets_8 is Octets( 1 .. 8 ); -- RSA packets and contained raw messages subtype RSA_Pkt is Octets( 1 .. RSA_PKT_OCTETS ); subtype RSA_Msg is Octets( 1 .. RSA_MSG_OCTETS ); -- Serpent packets and contained raw messages -- NB: length is the same but the distinction makes the code clearer subtype Serpent_Pkt is Octets( 1 .. SERPENT_OCTETS ); subtype Serpent_Msg is Octets( 1 .. SERPENT_OCTETS ); -- blind, unchecked casts ( memcpy style ) function Cast is new Ada.Unchecked_Conversion( Integer_8 , Octets_1 ); function Cast is new Ada.Unchecked_Conversion( Octets_1 , Integer_8 ); function Cast is new Ada.Unchecked_Conversion( Unsigned_8 , Octets_1 ); function Cast is new Ada.Unchecked_Conversion( Octets_1 , Unsigned_8 ); function Cast is new Ada.Unchecked_Conversion( Integer_16 , Octets_2 ); function Cast is new Ada.Unchecked_Conversion( Octets_2 , Integer_16 ); function Cast is new Ada.Unchecked_Conversion( Unsigned_16, Octets_2 ); function Cast is new Ada.Unchecked_Conversion( Octets_2 , Unsigned_16 ); function Cast is new Ada.Unchecked_Conversion( Integer_32 , Octets_4 ); function Cast is new Ada.Unchecked_Conversion( Octets_4 , Integer_32 ); function Cast is new Ada.Unchecked_Conversion( Unsigned_32, Octets_4 ); function Cast is new Ada.Unchecked_Conversion( Octets_4 , Unsigned_32 ); -- Gnat's Float has 32 bits but this might be different with other compilers function Cast is new Ada.Unchecked_Conversion( Float, Octets_4 ); function Cast is new Ada.Unchecked_Conversion( Octets_4, Float ); function Cast is new Ada.Unchecked_Conversion( Integer_64, Octets_8 ); function Cast is new Ada.Unchecked_Conversion( Octets_8, Integer_64 ); function Cast is new Ada.Unchecked_Conversion( Unsigned_64, Octets_8 ); function Cast is new Ada.Unchecked_Conversion( Octets_8, Unsigned_64 ); end Raw_Types;