raw
smg_comms_skeys_s...    1  -- Message reader & writers for SMG Communication Protocol
smg_comms_skeys_s... 2 -- This part effectively serializes/deserializes game data structures
smg_comms_skeys_s... 3 -- for transmission between client and server.
smg_comms_skeys_s... 4 -- Note that messages themeselves are simply arrays of octets.
smg_comms_skeys_s... 5 -- (see also raw_types.ads/adb and packing.ads/adb for related parts)
smg_comms_skeys_s... 6 -- NB: message ids and padding as per protocol spec are handled HERE ONLY.
smg_comms_skeys_s... 7 -- Relies on:
smg_comms_skeys_s... 8 -- RNG (for random padding)
smg_comms_skeys_s... 9 -- CRC32 (for CRC calculations)
smg_comms_skeys_s... 10 -- Raw_Types
smg_comms_skeys_s... 11 -- Data_Structs
smg_comms_skeys_s... 12 -- S.MG, 2018
smg_comms_skeys_s... 13
smg_comms_skeys_s... 14 with Raw_Types;
smg_comms_skeys_s... 15 with RNG;
smg_comms_skeys_s... 16 with CRC32;
smg_comms_skeys_s... 17 with Data_Structs; use Data_Structs;
smg_comms_skeys_s... 18 with Interfaces;
smg_comms_skeys_s... 19
smg_comms_skeys_s... 20 package Messages is
smg_comms_skeys_s... 21 -- exception raised when given message to read fails sanity checks
smg_comms_skeys_s... 22 Invalid_Msg: exception;
smg_comms_skeys_s... 23
smg_comms_keymgm 24 ----------------------
smg_comms_keymgm 25 -- Serpent Messages --
smg_comms_keymgm 26 ----------------------
smg_comms_keymgm 27
smg_comms_keymgm 28 -------------------------Keys----------------------------------------
smg_comms_skeys_s... 29 -- Writes a Serpent Keyset to the given Serpent Message
smg_comms_skeys_s... 30 --
smg_comms_skeys_s... 31 -- Keyset - the set of keys to write to message
smg_comms_skeys_s... 32 -- Counter - the message count
smg_comms_skeys_s... 33 procedure Write_SKeys_SMsg( Keyset : in Serpent_Keyset;
smg_comms_skeys_s... 34 Counter : in Interfaces.Unsigned_16;
smg_comms_skeys_s... 35 Msg : out Raw_Types.Serpent_Msg);
smg_comms_skeys_s... 36
smg_comms_skeys_s... 37 -- Reads a Serpent Keyset from the given Serpent Message
smg_comms_skeys_s... 38 -- The opposite of Write_SKeys_SMsg above
smg_comms_skeys_s... 39 -- Raises Invalid_Message exception if given message fails sanity checks
smg_comms_skeys_s... 40 procedure Read_SKeys_SMsg( Msg : in Raw_Types.Serpent_Msg;
smg_comms_skeys_s... 41 Counter : out Interfaces.Unsigned_16;
smg_comms_skeys_s... 42 Keyset : out Serpent_Keyset);
smg_comms_skeys_s... 43
smg_comms_keymgm 44 ------------------------Keys Management------------------------------
smg_comms_keymgm 45 -- Writes a Key Management structure to the given Serpent Message
smg_comms_keymgm 46 --
smg_comms_keymgm 47 -- KMgm - the keys management structure to write to message
smg_comms_keymgm 48 -- Counter - the message count
smg_comms_keymgm 49 procedure Write_KMgm_SMsg( KMgm : in Keys_Mgm;
smg_comms_keymgm 50 Counter : in Interfaces.Unsigned_16;
smg_comms_keymgm 51 Msg : out Raw_Types.Serpent_Msg);
smg_comms_keymgm 52
smg_comms_keymgm 53 -- Reads a Key management structure from the given Serpent Message
smg_comms_keymgm 54 -- The opposite of Write_KMgm_SMsg above
smg_comms_keymgm 55 -- Raises Invalid_Message exception if given message fails sanity checks
smg_comms_keymgm 56 procedure Read_KMgm_SMsg( Msg : in Raw_Types.Serpent_Msg;
smg_comms_keymgm 57 Counter : out Interfaces.Unsigned_16;
smg_comms_keymgm 58 KMgm : out Keys_Mgm);
smg_comms_keymgm 59
smg_comms_keymgm 60
smg_comms_keymgm 61
smg_comms_keymgm 62 ------------------
smg_comms_keymgm 63 -- RSA Messages --
smg_comms_keymgm 64 ------------------
smg_comms_keymgm 65
smg_comms_keymgm 66 -------------------------Keys----------------------------------------
smg_comms_keymgm 67 -- Writes a Serpent Keyset to the given RSA Message
smg_comms_keymgm 68 --
smg_comms_keymgm 69 -- Keyset - the set of keys to write to message
smg_comms_keymgm 70 -- Counter - the message count
smg_comms_keymgm 71 procedure Write_SKeys_RMsg( Keyset : in Serpent_Keyset;
smg_comms_keymgm 72 Counter : in Interfaces.Unsigned_16;
smg_comms_keymgm 73 Msg : out Raw_Types.RSA_Msg);
smg_comms_keymgm 74
smg_comms_keymgm 75 -- Reads a Serpent Keyset from the given RSA Message
smg_comms_keymgm 76 -- The opposite of Write_SKeys_RMsg above
smg_comms_keymgm 77 -- Raises Invalid_Message exception if given message fails sanity checks
smg_comms_keymgm 78 procedure Read_SKeys_RMsg( Msg : in Raw_Types.RSA_Msg;
smg_comms_keymgm 79 Counter : out Interfaces.Unsigned_16;
smg_comms_keymgm 80 Keyset : out Serpent_Keyset);
smg_comms_keymgm 81
smg_comms_keymgm 82 ------------------------Keys Management------------------------------
smg_comms_keymgm 83 -- Writes a Key Management structure to the given RSA Message
smg_comms_keymgm 84 --
smg_comms_keymgm 85 -- KMgm - the keys management structure to write to message
smg_comms_keymgm 86 -- Counter - the message count
smg_comms_keymgm 87 procedure Write_KMgm_RMsg( KMgm : in Keys_Mgm;
smg_comms_keymgm 88 Counter : in Interfaces.Unsigned_16;
smg_comms_keymgm 89 Msg : out Raw_Types.RSA_Msg);
smg_comms_keymgm 90
smg_comms_keymgm 91 -- Reads a Key management structure from the given RSA Message
smg_comms_keymgm 92 -- The opposite of Write_KMgm_SMsg above
smg_comms_keymgm 93 -- Raises Invalid_Message exception if given message fails sanity checks
smg_comms_keymgm 94 procedure Read_KMgm_RMsg( Msg : in Raw_Types.RSA_Msg;
smg_comms_keymgm 95 Counter : out Interfaces.Unsigned_16;
smg_comms_keymgm 96 KMgm : out Keys_Mgm);
smg_comms_keymgm 97
smg_comms_keymgm 98
smg_comms_skeys_s... 99 private
smg_comms_skeys_s... 100
smg_comms_skeys_s... 101 -- if native is little endian, does nothing;
smg_comms_skeys_s... 102 -- if native is big endian, it flips the input's octets.
smg_comms_skeys_s... 103 -- (strictly for arrays of octets)
smg_comms_skeys_s... 104 procedure Cast_LE( LE: in out Raw_Types.Octets );
smg_comms_skeys_s... 105
smg_comms_skeys_s... 106 -- protocol message types IDs, fixed as per protocol specification
smg_comms_skeys_s... 107 -- Serpent messages end in "S_Type"
smg_comms_skeys_s... 108 -- RSA messages end in "R_Type"
smg_comms_skeys_s... 109 -- Character action types end in "A_Type"
smg_comms_skeys_s... 110
smg_comms_skeys_s... 111 -- Serpent message types
smg_comms_skeys_s... 112 SKeys_S_Type : constant Interfaces.Unsigned_8 := 1;
smg_comms_skeys_s... 113 Key_Mgm_S_Type : constant Interfaces.Unsigned_8 := 2;
smg_comms_skeys_s... 114 File_Transfer_S_Type : constant Interfaces.Unsigned_8 := 3;
smg_comms_skeys_s... 115 File_Req_S_Type : constant Interfaces.Unsigned_8 := 4;
smg_comms_skeys_s... 116 Client_Action_S_Type : constant Interfaces.Unsigned_8 := 5;
smg_comms_skeys_s... 117 World_Bulletin_S_Type: constant Interfaces.Unsigned_8 := 6;
smg_comms_skeys_s... 118 Obj_Request_S_Type : constant Interfaces.Unsigned_8 := 7;
smg_comms_skeys_s... 119 Obj_Info_S_Type : constant Interfaces.Unsigned_8 := 8;
smg_comms_skeys_s... 120
smg_comms_skeys_s... 121 -- RSA message types
smg_comms_skeys_s... 122 RKeys_R_Type : constant Interfaces.Unsigned_8 := 251;
smg_comms_skeys_s... 123 SKeys_R_Type : constant Interfaces.Unsigned_8 := 157;
smg_comms_skeys_s... 124 Key_Mgm_R_Type : constant Interfaces.Unsigned_8 := 233;
smg_comms_skeys_s... 125
smg_comms_skeys_s... 126 -- Character action types
smg_comms_skeys_s... 127 Lock_A_Type : constant Interfaces.Unsigned_8 := 0;
smg_comms_skeys_s... 128 Make_A_Type : constant Interfaces.Unsigned_8 := 1;
smg_comms_skeys_s... 129 Explore_A_Type : constant Interfaces.Unsigned_8 := 2;
smg_comms_skeys_s... 130 Exchange_A_Type : constant Interfaces.Unsigned_8 := 3;
smg_comms_skeys_s... 131 Attack_A_Type : constant Interfaces.Unsigned_8 := 4;
smg_comms_skeys_s... 132 Repair_A_Type : constant Interfaces.Unsigned_8 := 5;
smg_comms_skeys_s... 133 Move_A_Type : constant Interfaces.Unsigned_8 := 6;
smg_comms_skeys_s... 134 Train_A_Type : constant Interfaces.Unsigned_8 := 7;
smg_comms_skeys_s... 135
smg_comms_keymgm 136 -- internal read/write of Serpent Keys
smg_comms_keymgm 137 -- those are called by both interface methods for RSA and Serpent messages
smg_comms_keymgm 138
smg_comms_keymgm 139 -- NB: caller HAS TO provide ENOUGH space in Msg AND valid Type_ID
smg_comms_keymgm 140 -- Msg will be padded with random octets until full length.
smg_comms_keymgm 141 procedure Write_SKeys( Keyset : in Serpent_Keyset;
smg_comms_keymgm 142 Counter : in Interfaces.Unsigned_16;
smg_comms_keymgm 143 Type_ID : in Interfaces.Unsigned_8;
smg_comms_keymgm 144 Msg : out Raw_Types.Octets);
smg_comms_keymgm 145
smg_comms_keymgm 146 -- NB: caller has to ensure that Msg is a valid RSA or Serpent message
smg_comms_keymgm 147 procedure Read_SKeys( Msg : in Raw_Types.Octets;
smg_comms_keymgm 148 Counter : out Interfaces.Unsigned_16;
smg_comms_keymgm 149 Keyset : out Serpent_Keyset);
smg_comms_keymgm 150
smg_comms_keymgm 151
smg_comms_keymgm 152 -- internal read/write of Key Management structures
smg_comms_keymgm 153 -- those are called by both interface methods for RSA and Serpent messages
smg_comms_keymgm 154
smg_comms_keymgm 155 -- NB: caller HAS TO provide ENOUGH space in Msg AND valid Type_ID
smg_comms_keymgm 156 -- Msg will be padded with random octets until full length.
smg_comms_keymgm 157 procedure Write_KMgm( KMgm : in Keys_Mgm;
smg_comms_keymgm 158 Counter : in Interfaces.Unsigned_16;
smg_comms_keymgm 159 Type_ID : in Interfaces.Unsigned_8;
smg_comms_keymgm 160 Msg : out Raw_Types.Octets);
smg_comms_keymgm 161
smg_comms_keymgm 162 -- NB: caller has to ensure that Msg is a valid RSA or Serpent message
smg_comms_keymgm 163 procedure Read_KMgm( Msg : in Raw_Types.Octets;
smg_comms_keymgm 164 Counter : out Interfaces.Unsigned_16;
smg_comms_keymgm 165 KMgm : out Keys_Mgm);
smg_comms_keymgm 166
smg_comms_skeys_s... 167 end Messages;