-
+ BE61934D440DAD950D4F63EA9A1BB941A7994C832ADB4748A1E24083887853FDD52FDF024D940740A9D3B65759AAD66A05F42B0365624B0AFFA0E12418E2FE8D
smg_comms/src/raw_types.ads
(0 . 0)(1 . 69)
137 -- raw types for the communication protocol
138 -- these are used throughout at the lowest level of the protocol
139 -- essentially they are the units of packets and of messages
140 -- SMG.Comms has only 2 types of packets: RSA and Serpent
141 -- a message is the decrypted content of a packet
142 -- S.MG, 2018
143
144 with Interfaces; use Interfaces; -- Unsigned_n and Integer_n
145 with Ada.Unchecked_Conversion;
146
147 package Raw_Types is
148
149 -- constants from SMG.COMMS standard specification
150 -- size of a serpent-encrypted packet and message, in octets
151 -- note that this corresponds to 1472/16 = 92 Serpent blocks
152 -- NB: lengths are the same but the distinction makes the code clearer
153 SERPENT_PKT_OCTETS : constant Positive := 1472;
154 SERPENT_MSG_OCTETS : constant Positive := SERPENT_PKT_OCTETS;
155
156 -- size of a RSA-encrypted packet and message in octets and bits
157 RSA_PKT_OCTETS : constant Positive := 1470;
158 RSA_MSG_OCTETS : constant Positive := 234;
159 RSA_MSG_BITS : constant Positive := RSA_MSG_OCTETS * 8; --1872
160
161 -- raw, low-level types
162 -- all messages and packets are simply arrays of octets at low level/raw
163 type Octets is array( Natural range <> ) of Interfaces.Unsigned_8;
164
165 -- raw representations of basic types (with fixed, well-defined sizes)
166 subtype Octets_1 is Octets( 1 .. 1 );
167 subtype Octets_2 is Octets( 1 .. 2 );
168 subtype Octets_4 is Octets( 1 .. 4 );
169 subtype Octets_8 is Octets( 1 .. 8 );
170
171 -- RSA packets and contained raw messages
172 subtype RSA_Pkt is Octets( 1 .. RSA_PKT_OCTETS );
173 subtype RSA_Msg is Octets( 1 .. RSA_MSG_OCTETS );
174
175 -- Serpent packets and contained raw messages
176 -- NB: length is the same but the distinction makes the code clearer
177 subtype Serpent_Pkt is Octets( 1 .. SERPENT_PKT_OCTETS );
178 subtype Serpent_Msg is Octets( 1 .. SERPENT_MSG_OCTETS );
179
180 -- blind, unchecked casts ( memcpy style )
181 function Cast is new Ada.Unchecked_Conversion( Integer_8 , Octets_1 );
182 function Cast is new Ada.Unchecked_Conversion( Octets_1 , Integer_8 );
183 function Cast is new Ada.Unchecked_Conversion( Unsigned_8 , Octets_1 );
184 function Cast is new Ada.Unchecked_Conversion( Octets_1 , Unsigned_8 );
185
186 function Cast is new Ada.Unchecked_Conversion( Integer_16 , Octets_2 );
187 function Cast is new Ada.Unchecked_Conversion( Octets_2 , Integer_16 );
188 function Cast is new Ada.Unchecked_Conversion( Unsigned_16, Octets_2 );
189 function Cast is new Ada.Unchecked_Conversion( Octets_2 , Unsigned_16 );
190
191 function Cast is new Ada.Unchecked_Conversion( Integer_32 , Octets_4 );
192 function Cast is new Ada.Unchecked_Conversion( Octets_4 , Integer_32 );
193 function Cast is new Ada.Unchecked_Conversion( Unsigned_32, Octets_4 );
194 function Cast is new Ada.Unchecked_Conversion( Octets_4 , Unsigned_32 );
195
196 -- Gnat's Float has 32 bits but this might be different with other compilers
197 function Cast is new Ada.Unchecked_Conversion( Float, Octets_4 );
198 function Cast is new Ada.Unchecked_Conversion( Octets_4, Float );
199
200 function Cast is new Ada.Unchecked_Conversion( Integer_64, Octets_8 );
201 function Cast is new Ada.Unchecked_Conversion( Octets_8, Integer_64 );
202 function Cast is new Ada.Unchecked_Conversion( Unsigned_64, Octets_8 );
203 function Cast is new Ada.Unchecked_Conversion( Octets_8, Unsigned_64 );
204
205 end Raw_Types;