tree checksum vpatch file split hunks

all signers: diana_coman

antecedents: smg_comms_packing_rsa smg_comms_80cols

press order:

smg_comms_genesisdiana_coman
smg_comms_raw_typesdiana_coman
smg_comms_packing_serpentdiana_coman
smg_comms_c_wrappersdiana_coman
smg_comms_rsa_oaepdiana_coman
smg_comms_packing_rsadiana_coman
smg_comms_80colsdiana_coman
smg_comms_skeys_smsgsdiana_coman

patch:

- 7E1D9C77E461686BA11E96F1F50ADFB9B9B9749714940766072489C1E3B9ACDE5A892C7422CE2EAF6712AF95317DFA09984CE8EC57D1E69A9674F85650BE7287
+ 32A691949AF3FB21EAF17C73269D01A30CB9F940EE5662772EB2C5E67A8352AEDC07B8A7CBA6A6D7F7BE1E42559E003B82BBEB97FB059FFB579BCC33A9AB2693
smg_comms/manifest
(5 . 3)(5 . 4)
5 547983 smg_comms_rsa_oaep diana_coman RSA with OAEP from ADA using the c_wrappers for RSA only. It includes reading from FG in Ada and repeat of OAEP until first octet is < first octet of key's modulus (i.e. without going through MPI for comparison).
6 548433 smg_comms_packing_rsa diana_coman Packing/Unpacking RSA messages <-> RSA packets of Eulora's communication protocol.
7 548894 smg_comms_80cols diana_coman Changes tests for RSA to read the key from a file in order to avoid lines > 80 columns in the code itself.
8 549511 smg_comms_skeys_smsgs diana_coman Defines data structures and message types as well as methods for reading/writing Serpent keysets to/from Serpent messages.
-
+ 936D9785BC02F35A58AC415074D9A7DAA857D24AF3093BAEA9BBF082D71E83EDB881EFCD2FCE95F774F600C6A99E8FE8F3C2C2EF7553C1E72556C31F6C7B7C3A
smg_comms/src/crc32.adb
(0 . 0)(1 . 52)
13 ------------------------------------------------------------------------------
14 ------------------------------------------------------------------------------
15 -- This file is part of 'CRC32' --
16 -- --
17 -- You do not have, nor can you ever acquire the right to use, copy or --
18 -- distribute this software ; Should you use this software for any purpose, --
19 -- or copy and distribute it to anyone or in any manner, you are breaking --
20 -- the laws of whatever soi-disant jurisdiction, and you promise to --
21 -- continue doing so for the indefinite future. In any case, please --
22 -- always : read and understand any software ; verify any PGP signatures --
23 -- that you use - for any purpose. --
24 -- --
25 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
26 ------------------------------------------------------------------------------
27 ------------------------------------------------------------------------------
28
29 -- CRC32 implementation
30 -- S.MG, 2018
31
32 package body CRC32 is
33 function CRC( S: in String ) return CRC32 is
34 Result : CRC32 := Init_Value;
35 Value : CRC32;
36 begin
37 -- process input character by character
38 for C of S loop
39 Value := CRC32( Character'Pos( C ) );
40 Result := Shift_Right(Result, 8) xor
41 Lookup( Value xor (Result and LSB_MASK));
42 end loop;
43 -- reflect result
44 Result := Result xor Xor_Out;
45
46 return Result;
47 end CRC;
48
49 function CRC( Data: in Octet_Array ) return CRC32 is
50 Result : CRC32 := Init_Value;
51 begin
52 -- process input octet by octet
53 for C of Data loop
54 Result := Shift_Right(Result, 8) xor
55 Lookup( CRC32(C) xor (Result and LSB_MASK));
56 end loop;
57 -- reflect result
58 Result := Result xor Xor_Out;
59
60 return Result;
61 end CRC;
62
63 end CRC32;
64
-
+ 6B3F7A4B32FF15ECBA5B7B580107CFD8B32083EE75BCD75191A394F9BD0E3E4369B0D4960D6693497047EE26FCD4442CD340A53D9CE10E9247B44DA98737146C
smg_comms/src/crc32.ads
(0 . 0)(1 . 131)
69 ------------------------------------------------------------------------------
70 ------------------------------------------------------------------------------
71 -- This file is part of 'CRC32' --
72 -- --
73 -- You do not have, nor can you ever acquire the right to use, copy or --
74 -- distribute this software ; Should you use this software for any purpose, --
75 -- or copy and distribute it to anyone or in any manner, you are breaking --
76 -- the laws of whatever soi-disant jurisdiction, and you promise to --
77 -- continue doing so for the indefinite future. In any case, please --
78 -- always : read and understand any software ; verify any PGP signatures --
79 -- that you use - for any purpose. --
80 -- --
81 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
82 ------------------------------------------------------------------------------
83 ------------------------------------------------------------------------------
84
85 -- CRC32, lookup-based implementation
86 -- S.MG, 2018
87 --
88 -- The CRC32 is a checksum calculated as the remainder of dividing
89 -- the input data by the 0x04C11DB7 polynomial. Specifications:
90 -- Name : "CRC-32"
91 -- Width : 32 (number of bits)
92 -- Poly : 04C11DB7 (generator polynomial)
93 -- Init : FFFFFFFF
94 -- RefIn : True (input is reflected)
95 -- RefOut : True (output is reflected)
96 -- XorOut : FFFFFFFF
97 -- Check : CBF43926 (expected value for input "123456789")
98 --
99 -- This implementation is based on the CRC32 specification in:
100 -- Sarwate, D.V. "Computation of Cyclic Redundancy Checks via Table Look-Up"
101 -- in Communications of the ACM, Vol. 31 No. 8, pp.1008-1013, Aug. 1988
102
103 with Interfaces; use Interfaces;
104 with Raw_Types;
105
106 package CRC32 is
107 -- local, shorthand version of Interfaces. types
108 subtype CRC32 is Interfaces.Unsigned_32;
109 subtype Octet is Interfaces.Unsigned_8;
110
111 subtype Octet_Array is Raw_Types.Octets;
112
113 -- interface for external callers
114 -- calculate CRC32 for the given string
115 function CRC( S: in String ) return CRC32;
116
117 -- calculate CRC32 for the given array of octets
118 function CRC( Data: in Octet_Array ) return CRC32;
119
120
121 -- internal constants and helper methods
122 private
123 function Shift_Right( Value : CRC32;
124 Amount : Natural)
125 return CRC32;
126 pragma Import(Intrinsic, Shift_Right);
127
128 Init_Value : constant CRC32 := 16#FFFF_FFFF#; -- Initial value
129 Xor_Out : constant CRC32 := 16#FFFF_FFFF#; -- For extracting result
130 LSB_Mask : constant CRC32 := 16#0000_00FF#; -- lsb mask for a CRC32 value
131
132 -- lookup table with precomputed values for CRC32
133 Lookup : constant array (CRC32 range 0 .. 255) of CRC32 :=
134 (16#0000_0000#, 16#7707_3096#, 16#EE0E_612C#, 16#9909_51BA#,
135 16#076D_C419#, 16#706A_F48F#, 16#E963_A535#, 16#9E64_95A3#,
136 16#0EDB_8832#, 16#79DC_B8A4#, 16#E0D5_E91E#, 16#97D2_D988#,
137 16#09B6_4C2B#, 16#7EB1_7CBD#, 16#E7B8_2D07#, 16#90BF_1D91#,
138 16#1DB7_1064#, 16#6AB0_20F2#, 16#F3B9_7148#, 16#84BE_41DE#,
139 16#1ADA_D47D#, 16#6DDD_E4EB#, 16#F4D4_B551#, 16#83D3_85C7#,
140 16#136C_9856#, 16#646B_A8C0#, 16#FD62_F97A#, 16#8A65_C9EC#,
141 16#1401_5C4F#, 16#6306_6CD9#, 16#FA0F_3D63#, 16#8D08_0DF5#,
142 16#3B6E_20C8#, 16#4C69_105E#, 16#D560_41E4#, 16#A267_7172#,
143 16#3C03_E4D1#, 16#4B04_D447#, 16#D20D_85FD#, 16#A50A_B56B#,
144 16#35B5_A8FA#, 16#42B2_986C#, 16#DBBB_C9D6#, 16#ACBC_F940#,
145 16#32D8_6CE3#, 16#45DF_5C75#, 16#DCD6_0DCF#, 16#ABD1_3D59#,
146 16#26D9_30AC#, 16#51DE_003A#, 16#C8D7_5180#, 16#BFD0_6116#,
147 16#21B4_F4B5#, 16#56B3_C423#, 16#CFBA_9599#, 16#B8BD_A50F#,
148 16#2802_B89E#, 16#5F05_8808#, 16#C60C_D9B2#, 16#B10B_E924#,
149 16#2F6F_7C87#, 16#5868_4C11#, 16#C161_1DAB#, 16#B666_2D3D#,
150 16#76DC_4190#, 16#01DB_7106#, 16#98D2_20BC#, 16#EFD5_102A#,
151 16#71B1_8589#, 16#06B6_B51F#, 16#9FBF_E4A5#, 16#E8B8_D433#,
152 16#7807_C9A2#, 16#0F00_F934#, 16#9609_A88E#, 16#E10E_9818#,
153 16#7F6A_0DBB#, 16#086D_3D2D#, 16#9164_6C97#, 16#E663_5C01#,
154 16#6B6B_51F4#, 16#1C6C_6162#, 16#8565_30D8#, 16#F262_004E#,
155 16#6C06_95ED#, 16#1B01_A57B#, 16#8208_F4C1#, 16#F50F_C457#,
156 16#65B0_D9C6#, 16#12B7_E950#, 16#8BBE_B8EA#, 16#FCB9_887C#,
157 16#62DD_1DDF#, 16#15DA_2D49#, 16#8CD3_7CF3#, 16#FBD4_4C65#,
158 16#4DB2_6158#, 16#3AB5_51CE#, 16#A3BC_0074#, 16#D4BB_30E2#,
159 16#4ADF_A541#, 16#3DD8_95D7#, 16#A4D1_C46D#, 16#D3D6_F4FB#,
160 16#4369_E96A#, 16#346E_D9FC#, 16#AD67_8846#, 16#DA60_B8D0#,
161 16#4404_2D73#, 16#3303_1DE5#, 16#AA0A_4C5F#, 16#DD0D_7CC9#,
162 16#5005_713C#, 16#2702_41AA#, 16#BE0B_1010#, 16#C90C_2086#,
163 16#5768_B525#, 16#206F_85B3#, 16#B966_D409#, 16#CE61_E49F#,
164 16#5EDE_F90E#, 16#29D9_C998#, 16#B0D0_9822#, 16#C7D7_A8B4#,
165 16#59B3_3D17#, 16#2EB4_0D81#, 16#B7BD_5C3B#, 16#C0BA_6CAD#,
166 16#EDB8_8320#, 16#9ABF_B3B6#, 16#03B6_E20C#, 16#74B1_D29A#,
167 16#EAD5_4739#, 16#9DD2_77AF#, 16#04DB_2615#, 16#73DC_1683#,
168 16#E363_0B12#, 16#9464_3B84#, 16#0D6D_6A3E#, 16#7A6A_5AA8#,
169 16#E40E_CF0B#, 16#9309_FF9D#, 16#0A00_AE27#, 16#7D07_9EB1#,
170 16#F00F_9344#, 16#8708_A3D2#, 16#1E01_F268#, 16#6906_C2FE#,
171 16#F762_575D#, 16#8065_67CB#, 16#196C_3671#, 16#6E6B_06E7#,
172 16#FED4_1B76#, 16#89D3_2BE0#, 16#10DA_7A5A#, 16#67DD_4ACC#,
173 16#F9B9_DF6F#, 16#8EBE_EFF9#, 16#17B7_BE43#, 16#60B0_8ED5#,
174 16#D6D6_A3E8#, 16#A1D1_937E#, 16#38D8_C2C4#, 16#4FDF_F252#,
175 16#D1BB_67F1#, 16#A6BC_5767#, 16#3FB5_06DD#, 16#48B2_364B#,
176 16#D80D_2BDA#, 16#AF0A_1B4C#, 16#3603_4AF6#, 16#4104_7A60#,
177 16#DF60_EFC3#, 16#A867_DF55#, 16#316E_8EEF#, 16#4669_BE79#,
178 16#CB61_B38C#, 16#BC66_831A#, 16#256F_D2A0#, 16#5268_E236#,
179 16#CC0C_7795#, 16#BB0B_4703#, 16#2202_16B9#, 16#5505_262F#,
180 16#C5BA_3BBE#, 16#B2BD_0B28#, 16#2BB4_5A92#, 16#5CB3_6A04#,
181 16#C2D7_FFA7#, 16#B5D0_CF31#, 16#2CD9_9E8B#, 16#5BDE_AE1D#,
182 16#9B64_C2B0#, 16#EC63_F226#, 16#756A_A39C#, 16#026D_930A#,
183 16#9C09_06A9#, 16#EB0E_363F#, 16#7207_6785#, 16#0500_5713#,
184 16#95BF_4A82#, 16#E2B8_7A14#, 16#7BB1_2BAE#, 16#0CB6_1B38#,
185 16#92D2_8E9B#, 16#E5D5_BE0D#, 16#7CDC_EFB7#, 16#0BDB_DF21#,
186 16#86D3_D2D4#, 16#F1D4_E242#, 16#68DD_B3F8#, 16#1FDA_836E#,
187 16#81BE_16CD#, 16#F6B9_265B#, 16#6FB0_77E1#, 16#18B7_4777#,
188 16#8808_5AE6#, 16#FF0F_6A70#, 16#6606_3BCA#, 16#1101_0B5C#,
189 16#8F65_9EFF#, 16#F862_AE69#, 16#616B_FFD3#, 16#166C_CF45#,
190 16#A00A_E278#, 16#D70D_D2EE#, 16#4E04_8354#, 16#3903_B3C2#,
191 16#A767_2661#, 16#D060_16F7#, 16#4969_474D#, 16#3E6E_77DB#,
192 16#AED1_6A4A#, 16#D9D6_5ADC#, 16#40DF_0B66#, 16#37D8_3BF0#,
193 16#A9BC_AE53#, 16#DEBB_9EC5#, 16#47B2_CF7F#, 16#30B5_FFE9#,
194 16#BDBD_F21C#, 16#CABA_C28A#, 16#53B3_9330#, 16#24B4_A3A6#,
195 16#BAD0_3605#, 16#CDD7_0693#, 16#54DE_5729#, 16#23D9_67BF#,
196 16#B366_7A2E#, 16#C461_4AB8#, 16#5D68_1B02#, 16#2A6F_2B94#,
197 16#B40B_BE37#, 16#C30C_8EA1#, 16#5A05_DF1B#, 16#2D02_EF8D#);
198
199 end CRC32;
-
+ 50379B31ED9F6B3E63C7037DB679ADE8309A44C6B0510520288AFC535A8FFD55E006CC20A479374E992991116253625C588278B21B0E12C254AD035A64E57258
smg_comms/src/data_structs.ads
(0 . 0)(1 . 80)
204 -- Data structures for SMG Communication Protocol
205 -- S.MG, 2018
206
207 with Interfaces; -- for fixed-size types
208 with Raw_Types; -- for protocol raw types
209 with System; -- for Bit_Order
210 with Serpent; -- for Serpent.Key type
211
212 package Data_Structs is
213 Pragma Pure(Data_Structs);
214
215 -- an object in the world, with record layout fully specified
216 -- a storage element is 8-bit aka 1 octet
217 -- "at" gives number of storage element
218 -- "range" gives bits inside storage element
219
220 type SMG_Object is
221 record
222 -- ID of the object
223 ID : Interfaces.Unsigned_32;
224
225 -- Position of the object in the world.
226 -- For a world with map coordinates (MC) between -500 and +500,
227 -- the relationship with given figure (GF) is:
228 -- MC = GF / 65.535 - 500
229 -- where 65.535 comes from the mapping 65535 / (500 - - 500)
230 X, Y, Z : Interfaces.Integer_16;
231
232 -- Rotation of the object (RO) linked to GF by:
233 -- RO = GF / 128*pi
234 RX, RY, RZ : Interfaces.Unsigned_8;
235 end record;
236 for SMG_Object'Size use 104; -- in bits!
237 for SMG_Object'Bit_Order use System.Low_Order_First;
238 for SMG_Object use
239 record
240 ID at 0 range 0 .. 31;
241 X at 4 range 0 .. 15;
242 Y at 6 range 0 .. 15;
243 Z at 8 range 0 .. 15;
244 RX at 10 range 0 .. 7;
245 RY at 11 range 0 .. 7;
246 RZ at 12 range 0 .. 7;
247 end record;
248
249 -------------------------
250 -- A set of Serpent Keys
251 -- parametrized record for a Serpent Keyset
252 -- parameters:
253 -- N is number of Serpent Keys contained
254 -- this can be the content of messages 4.1 or 5.2 in protocol spec.
255
256 -- an array of Serpent Keys
257 -- MAXIMUM 40 keys allowed in a message, hence subtype for key count
258 subtype Keys_Count is Interfaces.Unsigned_8 range 1..40;
259 type SKeys_Array is array( Keys_Count range <>) of Serpent.Key;
260
261 type Serpent_Keyset( N : Keys_Count := Keys_Count'Last) is
262 record
263 -- actual Serpent Keys
264 Keys : SKeys_Array( 1..N );
265 -- whether for talking to client (LSB set) or talking to server (MSB set)
266 Flag : Interfaces.Unsigned_8;
267 end record;
268
269 ------------------------------
270 -- Serpent Keys Management
271 type Keys_Mgm (N_Burnt: Interfaces.Unsigned_8) is
272 record
273 -- count of server keys requested
274 N_Server: Interfaces.Unsigned_8;
275 -- count of client keys requested
276 N_Client: Interfaces.Unsigned_8;
277 -- ID of Serpent key preferred for further inbound Serpent msgs.
278 Key_ID : Interfaces.Unsigned_8;
279 -- IDs of Serpent keys burnt by this message
280 Burnt : SKeys_Array( 1..N_Burnt );
281 end record;
282
283 end Data_Structs;
-
+ 899126526FA67B199AE8B8C17F0DCBBB68F59E0C6E88BFB21DACAC13D02FC11F3C6A2AF97920AFD44660C7AC689B51D474E3671CDDEE4443EEEAA5891CA374E6
smg_comms/src/messages.adb
(0 . 0)(1 . 139)
288 -- Message reader & writers for SMG Communication Protocol
289 -- S.MG, 2018
290
291 with Interfaces; use Interfaces;
292 with Serpent;
293 with System; use System;
294
295 package body Messages is
296
297 procedure Write_SKeys_SMsg( Keyset : in Serpent_Keyset;
298 Counter : in Interfaces.Unsigned_16;
299 Msg : out Raw_Types.Serpent_Msg) is
300 Pos : Integer := Msg'First;
301 Check : CRC32.CRC32;
302 PadLen: Integer;
303 K : Serpent.Key;
304 begin
305 -- write Type ID
306 Msg(Pos) := SKeys_S_Type;
307 Pos := Pos + 1;
308
309 -- write count of keys (NB: this IS 8 bits by definition)
310 Msg(Pos) := Keyset.Keys'Length;
311 Pos := Pos + 1;
312
313 -- write keys
314 for I in Keyset.Keys'Range loop
315 -- retrieve Key to write
316 K := Keyset.Keys( I );
317
318 -- write key itself
319 Msg(Pos..Pos+K'Length-1) := K;
320 -- ensure little endian order in message
321 Cast_LE(Msg(Pos..Pos+K'Length-1));
322 Pos := Pos + K'Length;
323
324 -- write CRC of key
325 Check := CRC32.CRC( K );
326 Msg(Pos..Pos+3) := Raw_Types.Cast(Check);
327 Cast_LE(Msg(Pos..Pos+3));
328 Pos := Pos + 4;
329 end loop;
330
331 -- write flag
332 Msg(Pos) := Keyset.Flag;
333 Pos := Pos + 1;
334
335 -- write message counter
336 Msg(Pos..Pos+1) := Raw_Types.Cast(Counter);
337 Cast_LE(Msg(Pos..Pos+1));
338 Pos := Pos + 2;
339
340 -- write padding as needed; endianness is irrelevant here
341 PadLen := Msg'Last - Pos + 1;
342 if PadLen > 0 then
343 declare
344 Pad : Raw_Types.Octets(1..PadLen);
345 begin
346 RNG.Get_Octets( Pad );
347 Msg(Pos..Pos+PadLen-1) := Pad;
348 end;
349 end if;
350 end Write_SKeys_SMsg;
351
352
353 -- Reads a Serpent keyset from given Serpent Message
354 procedure Read_SKeys_SMsg( Msg : in Raw_Types.Serpent_Msg;
355 Counter : out Interfaces.Unsigned_16;
356 Keyset : out Serpent_Keyset) is
357 Pos: Integer := Msg'First;
358 begin
359 -- read type and check
360 if Msg(Pos) = SKeys_S_Type then
361 Pos := Pos + 1;
362 else
363 raise Invalid_Msg;
364 end if;
365
366 -- read count of keys and check
367 if Msg(Pos) in Keys_Count'Range then
368 declare
369 N : Keys_Count := Keys_Count(Msg(Pos));
370 KS : Serpent_Keyset(N);
371 K : Serpent.Key;
372 Check : CRC32.CRC32;
373 O4 : Raw_Types.Octets_4;
374 O2 : Raw_Types.Octets_2;
375 begin
376 Pos := Pos + 1;
377 --read keys and check crc for each
378 for I in 1 .. N loop
379 -- read key and advance pos
380 K := Msg(Pos..Pos+K'Length-1);
381 Cast_LE(K);
382 Pos := Pos + K'Length;
383 -- read crc and compare to crc32(key)
384 O4 := Msg(Pos..Pos+3);
385 Cast_LE(O4);
386 Check := Raw_Types.Cast(O4);
387 Pos := Pos + 4;
388 if Check /= CRC32.CRC(K) then
389 raise Invalid_Msg;
390 end if;
391 -- if it got here, key is fine so add to set
392 KS.Keys(KS.Keys'First + I -1) := K;
393 end loop;
394 -- read and set flag
395 KS.Flag := Msg(Pos);
396 Pos := Pos + 1;
397 -- read and set message counter
398 O2 := Msg(Pos..Pos+1);
399 Cast_LE(O2);
400 Counter := Raw_Types.Cast(O2);
401 -- rest of message is padding so it's ignored
402 -- copy keyset to output variable
403 Keyset := KS;
404 end;
405 else
406 raise Invalid_Msg;
407 end if;
408 end Read_SKeys_SMsg;
409
410 -- private part
411 procedure Cast_LE( LE: in out Raw_Types.Octets ) is
412 begin
413 -- flip octets ONLY if native is big endian.
414 if System.Default_Bit_Order = System.High_Order_First then
415 declare
416 BE: constant Raw_Types.Octets := LE;
417 begin
418 for I in 1..LE'Length loop
419 LE(LE'First+I-1) := BE(BE'Last-I+1);
420 end loop;
421 end;
422 end if;
423 -- NOTHING to do for native little endian
424 end Cast_LE;
425
426 end Messages;
-
+ 1190FB877B7956B9B38F1D817858FE872F6E93B7E4FAC674BF3C82D664ACB11204FC88DE2563B33298A2A9AD547343CDF03F2CF068B3B1208DB0B1EE0B3C246C
smg_comms/src/messages.ads
(0 . 0)(1 . 77)
431 -- Message reader & writers for SMG Communication Protocol
432 -- This part effectively serializes/deserializes game data structures
433 -- for transmission between client and server.
434 -- Note that messages themeselves are simply arrays of octets.
435 -- (see also raw_types.ads/adb and packing.ads/adb for related parts)
436 -- NB: message ids and padding as per protocol spec are handled HERE ONLY.
437 -- Relies on:
438 -- RNG (for random padding)
439 -- CRC32 (for CRC calculations)
440 -- Raw_Types
441 -- Data_Structs
442 -- S.MG, 2018
443
444 with Raw_Types;
445 with RNG;
446 with CRC32;
447 with Data_Structs; use Data_Structs;
448 with Interfaces;
449
450 package Messages is
451 -- exception raised when given message to read fails sanity checks
452 Invalid_Msg: exception;
453
454 ------------------------------------------------
455 -- Writes a Serpent Keyset to the given Serpent Message
456 --
457 -- Keyset - the set of keys to write to message
458 -- Counter - the message count
459 procedure Write_SKeys_SMsg( Keyset : in Serpent_Keyset;
460 Counter : in Interfaces.Unsigned_16;
461 Msg : out Raw_Types.Serpent_Msg);
462
463 -- Reads a Serpent Keyset from the given Serpent Message
464 -- The opposite of Write_SKeys_SMsg above
465 -- Raises Invalid_Message exception if given message fails sanity checks
466 procedure Read_SKeys_SMsg( Msg : in Raw_Types.Serpent_Msg;
467 Counter : out Interfaces.Unsigned_16;
468 Keyset : out Serpent_Keyset);
469
470 private
471
472 -- if native is little endian, does nothing;
473 -- if native is big endian, it flips the input's octets.
474 -- (strictly for arrays of octets)
475 procedure Cast_LE( LE: in out Raw_Types.Octets );
476
477 -- protocol message types IDs, fixed as per protocol specification
478 -- Serpent messages end in "S_Type"
479 -- RSA messages end in "R_Type"
480 -- Character action types end in "A_Type"
481
482 -- Serpent message types
483 SKeys_S_Type : constant Interfaces.Unsigned_8 := 1;
484 Key_Mgm_S_Type : constant Interfaces.Unsigned_8 := 2;
485 File_Transfer_S_Type : constant Interfaces.Unsigned_8 := 3;
486 File_Req_S_Type : constant Interfaces.Unsigned_8 := 4;
487 Client_Action_S_Type : constant Interfaces.Unsigned_8 := 5;
488 World_Bulletin_S_Type: constant Interfaces.Unsigned_8 := 6;
489 Obj_Request_S_Type : constant Interfaces.Unsigned_8 := 7;
490 Obj_Info_S_Type : constant Interfaces.Unsigned_8 := 8;
491
492 -- RSA message types
493 RKeys_R_Type : constant Interfaces.Unsigned_8 := 251;
494 SKeys_R_Type : constant Interfaces.Unsigned_8 := 157;
495 Key_Mgm_R_Type : constant Interfaces.Unsigned_8 := 233;
496
497 -- Character action types
498 Lock_A_Type : constant Interfaces.Unsigned_8 := 0;
499 Make_A_Type : constant Interfaces.Unsigned_8 := 1;
500 Explore_A_Type : constant Interfaces.Unsigned_8 := 2;
501 Exchange_A_Type : constant Interfaces.Unsigned_8 := 3;
502 Attack_A_Type : constant Interfaces.Unsigned_8 := 4;
503 Repair_A_Type : constant Interfaces.Unsigned_8 := 5;
504 Move_A_Type : constant Interfaces.Unsigned_8 := 6;
505 Train_A_Type : constant Interfaces.Unsigned_8 := 7;
506
507 end Messages;
-
+ 0B7D9C9BA8094D32022CAFC676276DDF492FC26965DDAE35CB67DDDFC906B95B5D9025896BAE70ED46A1C6FFD8999D87C707A1EDB5577E5751FC48272108C8DD
smg_comms/tests/test_serializing.adb
(0 . 0)(1 . 59)
512 -- Tests for the serialization of data structures in SMG Protocol
513 -- S.MG, 2018
514
515 with RNG;
516 with Data_Structs; use Data_Structs;
517 with Messages; use Messages;
518 with Interfaces; use Interfaces;
519 with System;
520 with System.Storage_Elements; use System.Storage_Elements;
521 with Ada.Text_IO; use Ada.Text_IO;
522
523 package body Test_Serializing is
524
525 procedure Serialize_Keyset_SS is
526 Msg : Serpent_Msg;
527 KSet : Serpent_Keyset(5);
528 LSB : Interfaces.Unsigned_8 := 16#01#;
529 MSB : Interfaces.Unsigned_8 := 16#80#;
530 LMSB: Interfaces.Unsigned_8 := 16#81#;
531 Counter : Interfaces.Unsigned_16 := 101;
532 NewSet: Serpent_Keyset;
533 NewCounter: Interfaces.Unsigned_16:=0;
534 begin
535 Put_Line("Generating the Serpent Keys...");
536 -- fill a set of Serpent Keys
537 for I in 1..KSet.N loop
538 RNG.Get_Octets(KSet.Keys(Interfaces.Unsigned_8(I)));
539 end loop;
540 KSet.Flag := LSB;
541
542 Put_Line("Writing the keys to message...");
543 -- write keyset to serpent message
544 Write_SKeys_SMsg( KSet, Counter, Msg );
545
546 Put_Line("Reading keys back from message...");
547 -- read keyset from message
548 Read_SKeys_SMsg( Msg, Counter, NewSet );
549
550 Put_Line("Comparing the keysets...");
551 -- compare the two keysets
552 if NewSet /= KSet then
553 Put_Line("FAIL: keysets are different!");
554 else
555 Put_Line("PASS: keysets are the same!");
556 end if;
557
558 Put_Line("Attempting to read from mangled message");
559 begin
560 Msg(Msg'First) := Msg(Msg'First)+25;
561 Read_SKeys_SMsg( Msg, Counter, NewSet);
562 Put_Line("FAIL: read failed to raise invalid message exception!");
563 exception
564 when Invalid_Msg =>
565 Put_Line("PASS: exception correctly raised for invalid message");
566 end;
567 end Serialize_Keyset_SS;
568
569 end Test_Serializing;
570
-
+ 0571DD3EA06E4684EFB6CA56739FE9FF7F56BEFEF87C107AA38F356772338418AFB8562F989C615FF9D9B10CFA95CDB57BF88A395524ADB6194E62BD66812637
smg_comms/tests/test_serializing.ads
(0 . 0)(1 . 12)
575 -- Tests for the serialization of data structures in SMG Protocol
576 -- S.MG, 2018
577
578 with Raw_Types; use Raw_Types;
579
580 package Test_Serializing is
581
582 procedure Serialize_Keyset_SS;
583
584 private
585
586 end Test_Serializing;
- 01DED6598577BF4FB8027BEAA9678239EF98F27ABB62E3C5739B9347E4A747A1107052A6F908C7B4D3603C8DB762B59AAAC9EFA6EBF64C8CFFE1287985D87BB6
+ C0A18FD4B745715568D7EF048D6D39F9E161B859D781CDAF1BA656CD327407F11CA302B1E1F58BC6A5D17DE14B871F577C151BFD17C6BA560B1A6F111F4021FC
smg_comms/tests/testall.adb
(3 . 6)(3 . 7)
591 with Test_Serpent;
592 with Test_Packing;
593 with Test_RSA_OAEP;
594 with Test_Serializing;
595
596 procedure testall is
597 begin
(13 . 4)(14 . 5)
599 Test_RSA_OAEP.test_rsa_oaep;
600 Test_Packing.Test_Pack_Unpack_Serpent;
601 Test_Packing.Test_Pack_Unpack_RSA;
602 Test_Serializing.Serialize_Keyset_SS;
603 end testall;