raw
smg_comms_skeys_s...    1  -- Data structures for SMG Communication Protocol
smg_comms_skeys_s... 2 -- S.MG, 2018
smg_comms_skeys_s... 3
smg_comms_skeys_s... 4 with Interfaces; -- for fixed-size types
smg_comms_skeys_s... 5 with Raw_Types; -- for protocol raw types
smg_comms_skeys_s... 6 with System; -- for Bit_Order
smg_comms_skeys_s... 7 with Serpent; -- for Serpent.Key type
smg_comms_keymgm 8 with Ada.Unchecked_Conversion; -- for counter_8bits to/from octet
smg_comms_skeys_s... 9
smg_comms_skeys_s... 10 package Data_Structs is
smg_comms_skeys_s... 11 Pragma Pure(Data_Structs);
smg_comms_skeys_s... 12
smg_comms_skeys_s... 13 -- an object in the world, with record layout fully specified
smg_comms_skeys_s... 14 -- a storage element is 8-bit aka 1 octet
smg_comms_skeys_s... 15 -- "at" gives number of storage element
smg_comms_skeys_s... 16 -- "range" gives bits inside storage element
smg_comms_skeys_s... 17
smg_comms_skeys_s... 18 type SMG_Object is
smg_comms_skeys_s... 19 record
smg_comms_skeys_s... 20 -- ID of the object
smg_comms_skeys_s... 21 ID : Interfaces.Unsigned_32;
smg_comms_skeys_s... 22
smg_comms_skeys_s... 23 -- Position of the object in the world.
smg_comms_skeys_s... 24 -- For a world with map coordinates (MC) between -500 and +500,
smg_comms_skeys_s... 25 -- the relationship with given figure (GF) is:
smg_comms_skeys_s... 26 -- MC = GF / 65.535 - 500
smg_comms_skeys_s... 27 -- where 65.535 comes from the mapping 65535 / (500 - - 500)
smg_comms_skeys_s... 28 X, Y, Z : Interfaces.Integer_16;
smg_comms_skeys_s... 29
smg_comms_skeys_s... 30 -- Rotation of the object (RO) linked to GF by:
smg_comms_skeys_s... 31 -- RO = GF / 128*pi
smg_comms_skeys_s... 32 RX, RY, RZ : Interfaces.Unsigned_8;
smg_comms_skeys_s... 33 end record;
smg_comms_skeys_s... 34 for SMG_Object'Size use 104; -- in bits!
smg_comms_skeys_s... 35 for SMG_Object'Bit_Order use System.Low_Order_First;
smg_comms_skeys_s... 36 for SMG_Object use
smg_comms_skeys_s... 37 record
smg_comms_skeys_s... 38 ID at 0 range 0 .. 31;
smg_comms_skeys_s... 39 X at 4 range 0 .. 15;
smg_comms_skeys_s... 40 Y at 6 range 0 .. 15;
smg_comms_skeys_s... 41 Z at 8 range 0 .. 15;
smg_comms_skeys_s... 42 RX at 10 range 0 .. 7;
smg_comms_skeys_s... 43 RY at 11 range 0 .. 7;
smg_comms_skeys_s... 44 RZ at 12 range 0 .. 7;
smg_comms_skeys_s... 45 end record;
smg_comms_skeys_s... 46
smg_comms_files 47 -- A set of file names glued into a single string
smg_comms_files 48 -- NB: there IS at least ONE filename and one character
smg_comms_files 49 -- Upper limit for Text_Len is due to protocol's spec of text basic type
smg_comms_actions... 50 type U16_Array is array (Raw_Types.Text_Len range <> )
smg_comms_actions... 51 of Interfaces.Unsigned_16;
smg_comms_actions... 52 type Filenames( F_No: Raw_Types.Text_Len := 1;
smg_comms_actions... 53 Sz: Raw_Types.Text_Len := 1 ) is
smg_comms_files 54 record
smg_comms_files 55 -- filenames glued together into 1 single string
smg_comms_files 56 S : String( 1 .. Sz ) := (others => '0');
smg_comms_files 57 -- indices in S, at which each filename starts
smg_comms_files 58 Starts: U16_Array( 1 .. F_No ) := (others => 1);
smg_comms_files 59 end record;
smg_comms_files 60
smg_comms_files 61 -- A chunk of a file (for file transfer)
smg_comms_actions... 62 type File_Chunk( Len : Raw_Types.Text_Len := 1;
smg_comms_files 63 Count : Interfaces.Unsigned_16 := 1;
smg_comms_actions... 64 Name_Len: Raw_Types.Text_len := 1) is
smg_comms_files 65 record
smg_comms_files 66 Filename: String(1..Name_Len);
smg_comms_files 67 Content : Raw_Types.Octets(1..Len);
smg_comms_files 68 end record;
smg_comms_files 69
smg_comms_skeys_s... 70 -------------------------
smg_comms_skeys_s... 71 -- A set of Serpent Keys
smg_comms_skeys_s... 72 -- parametrized record for a Serpent Keyset
smg_comms_skeys_s... 73 -- parameters:
smg_comms_skeys_s... 74 -- N is number of Serpent Keys contained
smg_comms_skeys_s... 75 -- this can be the content of messages 4.1 or 5.2 in protocol spec.
smg_comms_skeys_s... 76
smg_comms_skeys_s... 77 -- an array of Serpent Keys
smg_comms_skeys_s... 78 -- MAXIMUM 40 keys allowed in a message, hence subtype for key count
smg_comms_skeys_s... 79 subtype Keys_Count is Interfaces.Unsigned_8 range 1..40;
smg_comms_skeys_s... 80 type SKeys_Array is array( Keys_Count range <>) of Serpent.Key;
smg_comms_skeys_s... 81
smg_comms_skeys_s... 82 type Serpent_Keyset( N : Keys_Count := Keys_Count'Last) is
smg_comms_skeys_s... 83 record
smg_comms_skeys_s... 84 -- actual Serpent Keys
smg_comms_skeys_s... 85 Keys : SKeys_Array( 1..N );
smg_comms_skeys_s... 86 -- whether for talking to client (LSB set) or talking to server (MSB set)
smg_comms_skeys_s... 87 Flag : Interfaces.Unsigned_8;
smg_comms_skeys_s... 88 end record;
smg_comms_skeys_s... 89
smg_comms_skeys_s... 90 ------------------------------
smg_comms_skeys_s... 91 -- Serpent Keys Management
smg_comms_keymgm 92 subtype Counter_8bits is Natural range 0..255;
smg_comms_keymgm 93 function Cast is new Ada.Unchecked_Conversion( Counter_8bits,
smg_comms_keymgm 94 Raw_Types.Octets_1 );
smg_comms_keymgm 95 function Cast is new Ada.Unchecked_Conversion( Raw_Types.Octets_1,
smg_comms_keymgm 96 Counter_8bits );
smg_comms_keymgm 97 type Keys_Mgm (N_Burnt: Counter_8bits := 0) is
smg_comms_skeys_s... 98 record
smg_comms_skeys_s... 99 -- count of server keys requested
smg_comms_skeys_s... 100 N_Server: Interfaces.Unsigned_8;
smg_comms_skeys_s... 101 -- count of client keys requested
smg_comms_skeys_s... 102 N_Client: Interfaces.Unsigned_8;
smg_comms_skeys_s... 103 -- ID of Serpent key preferred for further inbound Serpent msgs.
smg_comms_skeys_s... 104 Key_ID : Interfaces.Unsigned_8;
smg_comms_skeys_s... 105 -- IDs of Serpent keys burnt by this message
smg_comms_keymgm 106 case N_Burnt is
smg_comms_keymgm 107 when 0 =>
smg_comms_keymgm 108 null;
smg_comms_keymgm 109 when others =>
smg_comms_keymgm 110 Burnt : Raw_Types.Octets( 1..N_Burnt );
smg_comms_keymgm 111 end case;
smg_comms_skeys_s... 112 end record;
smg_comms_skeys_s... 113
smg_comms_actions... 114 type Player_RSA is
smg_comms_actions... 115 record
smg_comms_actions... 116 -- communication protocol Version number
smg_comms_actions... 117 Proto_V : Interfaces.Unsigned_8;
smg_comms_actions... 118
smg_comms_actions... 119 -- communication protocol Subversion number
smg_comms_actions... 120 Proto_Subv : Interfaces.Unsigned_16;
smg_comms_actions... 121
smg_comms_actions... 122 -- Keccak hash of client binary
smg_comms_actions... 123 Client_Hash: Raw_Types.Octets_8;
smg_comms_actions... 124
smg_comms_actions... 125 -- public exponent (e) of RSA key (64 bits precisely)
smg_comms_actions... 126 -- nb: this is protocol-specific e, aka shorter than TMSR e...
smg_comms_actions... 127 e : Raw_Types.Octets_8;
smg_comms_actions... 128
smg_comms_actions... 129 -- public modulus (n) of RSA key (490 bits precisely)
smg_comms_actions... 130 n : Raw_Types.RSA_len;
smg_comms_actions... 131
smg_comms_actions... 132 -- preferred padding; magic value 0x13370000 means random padding
smg_comms_actions... 133 Padding : Raw_Types.Octets_8;
smg_comms_actions... 134
smg_comms_actions... 135 end record;
smg_comms_actions... 136
smg_comms_skeys_s... 137 end Data_Structs;