-- Data structures for SMG Communication Protocol -- S.MG, 2018 with Interfaces; -- for fixed-size types with Raw_Types; -- for protocol raw types with System; -- for Bit_Order with Serpent; -- for Serpent.Key type with Ada.Unchecked_Conversion; -- for counter_8bits to/from octet package Data_Structs is Pragma Pure(Data_Structs); -- an object in the world, with record layout fully specified -- a storage element is 8-bit aka 1 octet -- "at" gives number of storage element -- "range" gives bits inside storage element type SMG_Object is record -- ID of the object ID : Interfaces.Unsigned_32; -- Position of the object in the world. -- For a world with map coordinates (MC) between -500 and +500, -- the relationship with given figure (GF) is: -- MC = GF / 65.535 - 500 -- where 65.535 comes from the mapping 65535 / (500 - - 500) X, Y, Z : Interfaces.Integer_16; -- Rotation of the object (RO) linked to GF by: -- RO = GF / 128*pi RX, RY, RZ : Interfaces.Unsigned_8; end record; for SMG_Object'Size use 104; -- in bits! for SMG_Object'Bit_Order use System.Low_Order_First; for SMG_Object use record ID at 0 range 0 .. 31; X at 4 range 0 .. 15; Y at 6 range 0 .. 15; Z at 8 range 0 .. 15; RX at 10 range 0 .. 7; RY at 11 range 0 .. 7; RZ at 12 range 0 .. 7; end record; -- A set of file names glued into a single string -- NB: there IS at least ONE filename and one character -- Upper limit for Text_Len is due to protocol's spec of text basic type type U16_Array is array (Raw_Types.Text_Len range <> ) of Interfaces.Unsigned_16; type Filenames( F_No: Raw_Types.Text_Len := 1; Sz: Raw_Types.Text_Len := 1 ) is record -- filenames glued together into 1 single string S : String( 1 .. Sz ) := (others => '0'); -- indices in S, at which each filename starts Starts: U16_Array( 1 .. F_No ) := (others => 1); end record; -- A chunk of a file (for file transfer) type File_Chunk( Len : Raw_Types.Text_Len := 1; Count : Interfaces.Unsigned_16 := 1; Name_Len: Raw_Types.Text_len := 1) is record Filename: String(1..Name_Len); Content : Raw_Types.Octets(1..Len); end record; ------------------------- -- A set of Serpent Keys -- parametrized record for a Serpent Keyset -- parameters: -- N is number of Serpent Keys contained -- this can be the content of messages 4.1 or 5.2 in protocol spec. -- an array of Serpent Keys -- MAXIMUM 40 keys allowed in a message, hence subtype for key count subtype Keys_Count is Interfaces.Unsigned_8 range 1..40; type SKeys_Array is array( Keys_Count range <>) of Serpent.Key; type Serpent_Keyset( N : Keys_Count := Keys_Count'Last) is record -- actual Serpent Keys Keys : SKeys_Array( 1..N ); -- whether for talking to client (LSB set) or talking to server (MSB set) Flag : Interfaces.Unsigned_8; end record; ------------------------------ -- Serpent Keys Management subtype Counter_8bits is Natural range 0..255; function Cast is new Ada.Unchecked_Conversion( Counter_8bits, Raw_Types.Octets_1 ); function Cast is new Ada.Unchecked_Conversion( Raw_Types.Octets_1, Counter_8bits ); type Keys_Mgm (N_Burnt: Counter_8bits := 0) is record -- count of server keys requested N_Server: Interfaces.Unsigned_8; -- count of client keys requested N_Client: Interfaces.Unsigned_8; -- ID of Serpent key preferred for further inbound Serpent msgs. Key_ID : Interfaces.Unsigned_8; -- IDs of Serpent keys burnt by this message case N_Burnt is when 0 => null; when others => Burnt : Raw_Types.Octets( 1..N_Burnt ); end case; end record; type Player_RSA is record -- communication protocol Version number Proto_V : Interfaces.Unsigned_8; -- communication protocol Subversion number Proto_Subv : Interfaces.Unsigned_16; -- Keccak hash of client binary Client_Hash: Raw_Types.Octets_8; -- public exponent (e) of RSA key (64 bits precisely) -- nb: this is protocol-specific e, aka shorter than TMSR e... e : Raw_Types.Octets_8; -- public modulus (n) of RSA key (490 bits precisely) n : Raw_Types.RSA_len; -- preferred padding; magic value 0x13370000 means random padding Padding : Raw_Types.Octets_8; end record; end Data_Structs;