tree checksum vpatch file split hunks

all signers: diana_coman

antecedents: smg_comms_genesis

press order:

smg_comms_genesisdiana_coman
smg_comms_raw_typesdiana_coman

patch:

- 865132E483B57DCF86C4BEB6F0123019747CBCB3745F8E297103D0E931AF958D9A4E57F213B6B41BA8B7AD0FCD6B0DD0967150243D24A9BC24C5F6FC6A365B1C
+ 7D5ACFD1981B93AD649DAAB47B2EC552E09AC46AD0329914B6C5503C092C899A9804C9A506B4C22FB8C930E2A3ACEDCD55470F9F4CBA5C4C7993C7903F5722F4
smg_comms/manifest
(1 . 2)(1 . 2)
5 532398 smg_comms_genesis diana_coman The first seed of an implementation of S.MG's communication protocol for Eulora: definitions for basic types, methods to/from network format, basic client/server test running locally on the same machine.
6
7 546000 smg_comms_raw_types diana_coman Part of layer 0 - raw types for the updated version of the protocol containing only two types of packets: 1470 octets RSA packet and 1472 octets Serpent packet.
-
+ 52AE9657AD5ABADAC6412597E48D26257703F293EB9348353097EEB9F2B00934FC862B075776B751B68E0423CBF452FBD1F3A9DB0FB99C93E6D9F551114B33D7
smg_comms/restrict.adc
(0 . 0)(1 . 64)
12 pragma Restrictions(Immediate_Reclamation);
13 pragma Restrictions(Max_Asynchronous_Select_Nesting => 0);
14 pragma Restrictions(Max_Protected_Entries => 0);
15 pragma Restrictions(Max_Select_Alternatives => 0);
16 pragma Restrictions(Max_Task_Entries => 0);
17 pragma Restrictions(Max_Tasks => 0);
18 pragma Restrictions(No_Abort_Statements);
19 pragma Restrictions(No_Access_Parameter_Allocators);
20 pragma Restrictions(No_Allocators);
21 pragma Restrictions(No_Asynchronous_Control);
22 pragma Restrictions(No_Calendar);
23 pragma Restrictions(No_Coextensions);
24 pragma Restrictions(No_Default_Stream_Attributes);
25 pragma Restrictions(No_Delay);
26 pragma Restrictions(No_Dispatch);
27 pragma Restrictions(No_Dispatching_Calls);
28 pragma Restrictions(No_Dynamic_Attachment);
29 pragma Restrictions(No_Dynamic_Priorities);
30 pragma Restrictions(No_Entry_Calls_In_Elaboration_Code);
31 pragma Restrictions(No_Entry_Queue);
32 pragma Restrictions(No_Enumeration_Maps);
33 --pragma Restrictions(No_Exception_Propagation);
34 pragma Restrictions(No_Exception_Registration);
35 pragma Restrictions(No_Finalization);
36 pragma Restrictions(No_Fixed_Io);
37 --pragma Restrictions(No_Floating_Point);
38 pragma Restrictions(No_Implementation_Aspect_Specifications);
39 pragma Restrictions(No_Implementation_Units);
40 pragma Restrictions(No_Implicit_Conditionals);
41 pragma Restrictions(No_Implicit_Dynamic_Code);
42 pragma Restrictions(No_Implicit_Heap_Allocations);
43 pragma Restrictions(No_Implicit_Protected_Object_Allocations);
44 pragma Restrictions(No_Implicit_Task_Allocations);
45 pragma Restrictions(No_Initialize_Scalars);
46 pragma Restrictions(No_Local_Protected_Objects);
47 pragma Restrictions(No_Local_Timing_Events);
48 pragma Restrictions(No_Multiple_Elaboration);
49 pragma Restrictions(No_Nested_Finalization);
50 pragma Restrictions(No_Protected_Type_Allocators);
51 pragma Restrictions(No_Protected_Types);
52 pragma Restrictions(No_Relative_Delay);
53 pragma Restrictions(No_Requeue_Statements);
54 pragma Restrictions(No_Secondary_Stack);
55 pragma Restrictions(No_Select_Statements);
56 pragma Restrictions(No_Specific_Termination_Handlers);
57 pragma Restrictions(No_Standard_Allocators_After_Elaboration);
58 pragma Restrictions(No_Stream_Optimizations);
59 pragma Restrictions(No_Streams);
60 pragma Restrictions(No_Task_Allocators);
61 pragma Restrictions(No_Task_At_Interrupt_Priority);
62 pragma Restrictions(No_Task_Attributes_Package);
63 pragma Restrictions(No_Task_Hierarchy);
64 pragma Restrictions(No_Tasking);
65 pragma Restrictions(No_Task_Termination);
66 pragma Restrictions(No_Terminate_Alternatives);
67 pragma Restrictions(No_Unchecked_Access);
68 --pragma Restrictions(No_Unchecked_Conversion);
69 pragma Restrictions(No_Unchecked_Deallocation);
70 pragma Restrictions(No_Wide_Characters);
71 pragma Restrictions(Pure_Barriers);
72 pragma Restrictions(Simple_Barriers);
73 pragma Restrictions(Static_Priorities);
74 pragma Restrictions(Static_Storage_Size);
75 pragma Validity_Checks(ALL_CHECKS);
- 7CA4898EA436586CB87F25161C03B7118CD3F7FF3805079EA8E73A523B2A6F97B0E698256954AB2C3FCFCBD2DB8D6FE1545D618054CDB04072CD3D784F17BE2F
+ 5834ABB16DF880D02AC7208FB19A1C2CB14CAD43AFA73537246D0734D9A845F156F5519BC93D2DF74AA479611FC015E5F5A62023025606E5C2E43CFE894730DD
smg_comms/smg_comms.gpr
(3 . 22)(3 . 46)
80 -- http://trilema.com/2018/euloras-communication-protocol-restated/
81
82 project SMG_comms is
83
84 type Mode_Type is ("debug", "release");
85 Mode : Mode_Type := external ("mode", "release");
86
87 for Languages use ("Ada");
88
89 for Source_Dirs use ("src");
90 for Ignore_Source_Sub_Dirs use (".svn", ".git", "@*");
91
92 for Object_Dir use "obj";
93 for Exec_Dir use ".";
94
95 for Main use ("test_comms.adb");
96 package Compiler is
97
98 case Mode is
99 when "debug" =>
100 for Switches ("Ada")
101 use ("-g");
102 when "release" =>
103 for Switches ("Ada")
104 use ("-O2", "-fdump-scos", "-gnata", "-fstack-check",
105 "-gnatyd", "-gnatym",
106 "-fdata-sections", "-ffunction-sections", "-gnatwr", "-gnatw.d",
107 "-gnatec=" & SMG_Comms'Project_Dir & "restrict.adc");
108 end case;
109 end Compiler;
110
111 package Builder is
112 for Executable ("test_comms.adb") use "test_comms";
113 for Switches ("Ada")
114 use ("-nostdlib");
115 end Builder;
116
117 package Compiler is
118 for Default_Switches ("Ada") use ("-O2");
119 end Compiler;
120
121 package Binder is
122 case Mode is
123 when "debug" =>
124 for Switches ("Ada")
125 use ();
126 when "release" =>
127 for Switches ("Ada")
128 use ("-static");
129 end case;
130 end Binder;
131
132 end SMG_comms;
-
+ 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;
- 59000F9E3569F550C5994913E7BA3CDB6CBB964DEB307A47676B5FEBA9220F70B0BEF3F187B22A4E69948037E6A046ED91001BCB66ADAB6EEEE42199A0E84208
+
smg_comms/src/smg_comms_types.adb
(1 . 69)(0 . 0)
210 -- S.MG, 2018
211 -- prototype implementation of S.MG communication protocol
212
213 with SMG_comms_types; use SMG_comms_types;
214 with System; use System; -- endianness
215 with Ada.Exceptions;
216 with Ada.Streams; use Ada.Streams;
217
218 package body SMG_comms_types is
219
220 -- to and from network format (i.e. big endian, stream_element_array)
221 procedure ToNetworkFormat(
222 Item : in Octet_Array;
223 Buffer : out Stream_Element_Array) is
224 begin
225 if Item'Length /= Buffer'Length then
226 raise Constraint_Error with "Item and Buffer lengths do NOT match!";
227 end if;
228
229 if Default_Bit_Order = Low_Order_First then
230 for I in 0 .. Item'Length - 1 loop
231 Buffer( Buffer'Last - Stream_Element_Offset(I) ) := Stream_Element(Item(Item'First + I));
232 end loop;
233 else
234 for I in 0 .. Item'Length - 1 loop
235 Buffer( Buffer'First + Stream_Element_Offset(I) ) := Stream_Element(Item(Item'First + I));
236 end loop;
237 end if;
238 end ToNetworkFormat;
239
240 procedure FromNetworkFormat(
241 Buffer : in Stream_Element_Array;
242 Item : out Octet_Array) is
243 begin
244 if Item'Length /= Buffer'Length then
245 raise Constraint_Error with "Buffer and Item length do NOT match!";
246 end if;
247
248 if Default_Bit_Order = Low_Order_First then
249 for I in 0 .. Buffer'Length - 1 loop
250 Item( Item'Last - I ) :=
251 Unsigned_8( Buffer( Buffer'First + Stream_Element_Offset( I ) ) );
252 end loop;
253 else
254 for I in 0 .. Buffer'Length - 1 loop
255 Item( Item'First + I ) :=
256 Unsigned_8( Buffer( Buffer'First + Stream_Element_Offset( I ) ) );
257 end loop;
258 end if;
259 end FromNetworkFormat;
260
261 -- Integer_8
262 procedure ToNetworkFormat(
263 Item : in Integer_8;
264 Buffer : out Stream_Element_Array) is
265 begin
266 ToNetworkFormat( Cast( Item ), Buffer );
267 end ToNetworkFormat;
268
269 procedure FromNetworkFormat(
270 Buffer : in Stream_Element_Array;
271 Item : out Integer_8) is
272 octets: Octets_1;
273 begin
274 FromNetworkFormat(Buffer, octets);
275 Item := Cast( octets );
276 end FromNetworkFormat;
277
278 end SMG_comms_types;
- A2253E5B8F18B3F3D7D9F7D0198761771470D53DC72986C9BE61B9809F101290F7DEF2F92970DD973E523E567A84375A25FFAE2C7A80F227AE49542B75F9B259
+
smg_comms/src/smg_comms_types.ads
(1 . 52)(0 . 0)
283 -- S.MG, 2018
284 -- prototype implementation of S.MG communication protocol
285
286 with Ada.Streams; use Ada.Streams;
287 with Interfaces; use Interfaces; -- Integer_n and Unsigned_n
288 with Ada.Unchecked_Conversion; -- converting int/uint to array of octets
289
290 package SMG_comms_types is
291 -- basic types with guaranteed lengths
292 type Octet_Array is array(Natural range <>) of Unsigned_8;
293
294 subtype Octets_1 is Octet_Array( 1 .. 1 );
295 subtype Octets_2 is Octet_Array( 1 .. 2 );
296 subtype Octets_4 is Octet_Array( 1 .. 4 );
297 subtype Octets_8 is Octet_Array( 1 .. 8 );
298
299 subtype Message is Octet_Array( 1 .. 512 );
300 subtype RSAMessage is Octet_Array( 1 .. 245 );
301
302 -- blind, unchecked casts ( memcpy style )
303 function Cast is new Ada.Unchecked_Conversion( Integer_8, Octets_1 );
304 function Cast is new Ada.Unchecked_Conversion( Octets_1, Integer_8 );
305
306 function Cast is new Ada.Unchecked_Conversion( Integer_16, Octets_2 );
307 function Cast is new Ada.Unchecked_Conversion( Octets_2, Integer_16 );
308
309 function Cast is new Ada.Unchecked_Conversion( Integer_32, Octets_4 );
310 function Cast is new Ada.Unchecked_Conversion( Octets_4, Integer_32 );
311
312 function Cast is new Ada.Unchecked_Conversion( Integer_64, Octets_8 );
313 function Cast is new Ada.Unchecked_Conversion( Octets_8, Integer_64 );
314
315 -- to and from streams for network communications - general
316 procedure ToNetworkFormat(
317 Item : in Octet_Array;
318 Buffer : out Stream_Element_Array);
319
320 procedure FromNetworkFormat(
321 Buffer : in Stream_Element_Array;
322 Item : out Octet_Array);
323
324 -- specific, convenience methods for the basic types
325 -- Integer_8
326 procedure ToNetworkFormat(
327 Item : in Integer_8;
328 Buffer : out Stream_Element_Array);
329
330 procedure FromNetworkFormat(
331 Buffer : in Stream_Element_Array;
332 Item : out Integer_8);
333
334 end SMG_comms_types;
- ABF3A0700182A7622A7468465C37F038B72818DDD9500EFE683A923E7CA8F020C08A236BFDB0BCE0C0D65FBC2425D90251688E21B834B1EF8EF5982C6F94071C
+
smg_comms/src/test_comms.adb
(1 . 87)(0 . 0)
339 -- S.MG, 2018
340 -- prototype implementation of S.MG communication protocol
341
342 with GNAT.Sockets; use GNAT.Sockets;
343 with Ada.Text_IO; use Ada.Text_IO;
344 with Ada.Streams; use Ada.Streams;
345 with Interfaces; use Interfaces;
346
347 with SMG_comms_types; use SMG_comms_types;
348
349 procedure test_comms is
350 Port_No : constant := 2222;
351
352 task type Client is
353 entry Send;
354 end Client;
355
356 task type Server is
357 entry Listen;
358 entry Ready;
359 end Server;
360
361 task body Client is
362 Sock: Socket_Type;
363 Address: Sock_Addr_Type;
364 Data: Ada.Streams.Stream_Element_Array(1..10) := (others => 42);
365 Last: Ada.Streams.Stream_Element_Offset;
366 N : Integer_8 := -36;
367 begin
368 accept Send; -- task WILL block here until asked to send
369 Address.Port := Port_No;
370 Address.Addr := Inet_Addr("127.0.0.1");
371 Create_Socket(Sock, Family_Inet, Socket_Datagram);
372
373 ToNetworkFormat( N, Data(1..1));
374
375 Send_Socket(Sock, Data, Last, Address);
376 Put_Line("Client sent data " & "last: " & Last'Img);
377 end Client;
378
379 task body Server is
380 Sock: Socket_Type;
381 Address, From: Sock_Addr_Type;
382 Data: Ada.Streams.Stream_Element_Array(1..512);
383 Last: Ada.Streams.Stream_Element_Offset;
384 N : Integer_8;
385 begin
386 accept Listen; -- wait to be started!
387 Put_Line("Server started!");
388 -- create UDP socket
389 Create_Socket( Sock, Family_Inet, Socket_Datagram );
390
391 -- set options on UDP socket
392 Set_Socket_Option( Sock, Socket_Level, (Reuse_Address, True));
393 Set_Socket_Option( Sock, Socket_Level, (Receive_Timeout, Timeout => 10.0));
394
395 -- set address and bind
396 Address.Addr := Any_Inet_Addr;
397 Address.Port := Port_No;
398 Bind_Socket( Sock, Address );
399
400 accept Ready; -- server IS ready, when here
401 -- receive on socket
402 begin
403 Receive_Socket( Sock, Data, Last, From );
404 Put_Line("last: " & Last'Img);
405 Put_Line("from: " & Image(From.Addr));
406 Put_Line("data is:");
407 for I in Data'First .. Last loop
408 FromNetworkFormat(Data(I..I), N);
409 Put_Line(N'Image);
410 end loop;
411 exception
412 when Socket_Error =>
413 Put_Line("Socket error! (timeout?)");
414 end; -- end of receive
415
416 end Server;
417
418 S: Server;
419 C: Client;
420 begin
421 S.Listen;
422 S.Ready; -- WAIT for server to be ready!
423 C.Send; -- client is started only after server!
424 end test_comms;
425