raw
smg_comms_raw_types     1  -- raw types for the communication protocol
smg_comms_raw_types 2 -- these are used throughout at the lowest level of the protocol
smg_comms_raw_types 3 -- essentially they are the units of packets and of messages
smg_comms_raw_types 4 -- SMG.Comms has only 2 types of packets: RSA and Serpent
smg_comms_raw_types 5 -- a message is the decrypted content of a packet
smg_comms_raw_types 6 -- S.MG, 2018
smg_comms_raw_types 7
smg_comms_raw_types 8 with Interfaces; use Interfaces; -- Unsigned_n and Integer_n
smg_comms_raw_types 9 with Ada.Unchecked_Conversion;
smg_comms_raw_types 10
smg_comms_raw_types 11 package Raw_Types is
smg_comms_raw_types 12
smg_comms_raw_types 13 -- constants from SMG.COMMS standard specification
smg_comms_raw_types 14 -- size of a serpent-encrypted packet and message, in octets
smg_comms_raw_types 15 -- note that this corresponds to 1472/16 = 92 Serpent blocks
smg_comms_raw_types 16 -- NB: lengths are the same but the distinction makes the code clearer
smg_comms_raw_types 17 SERPENT_PKT_OCTETS : constant Positive := 1472;
smg_comms_raw_types 18 SERPENT_MSG_OCTETS : constant Positive := SERPENT_PKT_OCTETS;
smg_comms_raw_types 19
smg_comms_raw_types 20 -- size of a RSA-encrypted packet and message in octets and bits
smg_comms_raw_types 21 RSA_PKT_OCTETS : constant Positive := 1470;
smg_comms_raw_types 22 RSA_MSG_OCTETS : constant Positive := 234;
smg_comms_raw_types 23 RSA_MSG_BITS : constant Positive := RSA_MSG_OCTETS * 8; --1872
smg_comms_raw_types 24
smg_comms_raw_types 25 -- raw, low-level types
smg_comms_raw_types 26 -- all messages and packets are simply arrays of octets at low level/raw
smg_comms_raw_types 27 type Octets is array( Natural range <> ) of Interfaces.Unsigned_8;
smg_comms_raw_types 28
smg_comms_raw_types 29 -- raw representations of basic types (with fixed, well-defined sizes)
smg_comms_raw_types 30 subtype Octets_1 is Octets( 1 .. 1 );
smg_comms_raw_types 31 subtype Octets_2 is Octets( 1 .. 2 );
smg_comms_raw_types 32 subtype Octets_4 is Octets( 1 .. 4 );
smg_comms_raw_types 33 subtype Octets_8 is Octets( 1 .. 8 );
smg_comms_raw_types 34
smg_comms_raw_types 35 -- RSA packets and contained raw messages
smg_comms_raw_types 36 subtype RSA_Pkt is Octets( 1 .. RSA_PKT_OCTETS );
smg_comms_raw_types 37 subtype RSA_Msg is Octets( 1 .. RSA_MSG_OCTETS );
smg_comms_raw_types 38
smg_comms_raw_types 39 -- Serpent packets and contained raw messages
smg_comms_raw_types 40 -- NB: length is the same but the distinction makes the code clearer
smg_comms_raw_types 41 subtype Serpent_Pkt is Octets( 1 .. SERPENT_PKT_OCTETS );
smg_comms_raw_types 42 subtype Serpent_Msg is Octets( 1 .. SERPENT_MSG_OCTETS );
smg_comms_raw_types 43
smg_comms_raw_types 44 -- blind, unchecked casts ( memcpy style )
smg_comms_raw_types 45 function Cast is new Ada.Unchecked_Conversion( Integer_8 , Octets_1 );
smg_comms_raw_types 46 function Cast is new Ada.Unchecked_Conversion( Octets_1 , Integer_8 );
smg_comms_raw_types 47 function Cast is new Ada.Unchecked_Conversion( Unsigned_8 , Octets_1 );
smg_comms_raw_types 48 function Cast is new Ada.Unchecked_Conversion( Octets_1 , Unsigned_8 );
smg_comms_raw_types 49
smg_comms_raw_types 50 function Cast is new Ada.Unchecked_Conversion( Integer_16 , Octets_2 );
smg_comms_raw_types 51 function Cast is new Ada.Unchecked_Conversion( Octets_2 , Integer_16 );
smg_comms_raw_types 52 function Cast is new Ada.Unchecked_Conversion( Unsigned_16, Octets_2 );
smg_comms_raw_types 53 function Cast is new Ada.Unchecked_Conversion( Octets_2 , Unsigned_16 );
smg_comms_raw_types 54
smg_comms_raw_types 55 function Cast is new Ada.Unchecked_Conversion( Integer_32 , Octets_4 );
smg_comms_raw_types 56 function Cast is new Ada.Unchecked_Conversion( Octets_4 , Integer_32 );
smg_comms_raw_types 57 function Cast is new Ada.Unchecked_Conversion( Unsigned_32, Octets_4 );
smg_comms_raw_types 58 function Cast is new Ada.Unchecked_Conversion( Octets_4 , Unsigned_32 );
smg_comms_raw_types 59
smg_comms_raw_types 60 -- Gnat's Float has 32 bits but this might be different with other compilers
smg_comms_raw_types 61 function Cast is new Ada.Unchecked_Conversion( Float, Octets_4 );
smg_comms_raw_types 62 function Cast is new Ada.Unchecked_Conversion( Octets_4, Float );
smg_comms_raw_types 63
smg_comms_raw_types 64 function Cast is new Ada.Unchecked_Conversion( Integer_64, Octets_8 );
smg_comms_raw_types 65 function Cast is new Ada.Unchecked_Conversion( Octets_8, Integer_64 );
smg_comms_raw_types 66 function Cast is new Ada.Unchecked_Conversion( Unsigned_64, Octets_8 );
smg_comms_raw_types 67 function Cast is new Ada.Unchecked_Conversion( Octets_8, Unsigned_64 );
smg_comms_raw_types 68
smg_comms_raw_types 69 end Raw_Types;