Skip to content

Commit 15c0630

Browse files
authored
+ More postconditions
* Added post conditions for the stream conversion functions.
1 parent 9150982 commit 15c0630

File tree

2 files changed

+83
-22
lines changed

2 files changed

+83
-22
lines changed

artifacts/gnatprove.out

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
date : 2017-10-19 17:36:46
1+
date : 2017-10-23 14:52:55
22
gnatprove version : 2017 (20170515)
33
host : Windows 32 bits
44
command line : gnatprove.exe --assumptions --output-header -P security.gpr
@@ -15,12 +15,12 @@ Data Dependencies . . . .
1515
Flow Dependencies . . . . . . .
1616
Initialization 171 164 . . . 7 .
1717
Non-Aliasing . . . . . . .
18-
Run-time Checks 168 . . . 168 (CVC4 99%, Z3 1%, altergo 0%) . .
18+
Run-time Checks 187 . . . 187 (CVC4 99%, Z3 1%, altergo 0%) . .
1919
Assertions 22 . . . 22 (CVC4 98%, Z3 2%) . .
20-
Functional Contracts 20 . . . 20 (CVC4 99%, Z3 1%) . .
20+
Functional Contracts 21 . . . 21 (CVC4 99%, Z3 1%) . .
2121
LSP Verification . . . . . . .
2222
-------------------------------------------------------------------------------------------------------------------------------------
23-
Total 381 164 (43%) . . 210 (55%) 7 (2%) .
23+
Total 401 164 (41%) . . 230 (57%) 7 (2%) .
2424

2525

2626
Analyzed 2 units
@@ -34,7 +34,7 @@ absence of run-time errors of Crypto.Oadd fully established
3434
the postcondition of Crypto.Oadd.Add_Carry fully established
3535
effects on parameters and Global variables of Crypto.Oadd.Add_Carry fully established
3636
absence of run-time errors of Crypto.Oadd.Add_Carry fully established
37-
Crypto.To_Stream at crypto.ads:64 flow analyzed (0 errors and 0 warnings) and proved (9 checks)
37+
Crypto.To_Stream at crypto.ads:64 flow analyzed (0 errors and 0 warnings) and proved (21 checks)
3838
the postcondition of Crypto.To_Stream depends on
3939
effects on parameters and Global variables of Interfaces.Shift_Right
4040
absence of run-time errors of Interfaces.Shift_Right
@@ -43,9 +43,15 @@ effects on parameters and Global variables of Crypto.To_Stream depends on
4343
absence of run-time errors of Crypto.To_Stream depends on
4444
effects on parameters and Global variables of Interfaces.Shift_Right
4545
absence of run-time errors of Interfaces.Shift_Right
46-
Crypto.To_Unsigned at crypto.ads:75 flow analyzed (0 errors and 0 warnings) and proved (8 checks)
47-
effects on parameters and Global variables of Crypto.To_Unsigned fully established
48-
absence of run-time errors of Crypto.To_Unsigned fully established
46+
Crypto.To_Unsigned at crypto.ads:79 flow analyzed (0 errors and 0 warnings) and proved (16 checks)
47+
the postcondition of Crypto.To_Unsigned depends on
48+
effects on parameters and Global variables of Interfaces.Shift_Left
49+
absence of run-time errors of Interfaces.Shift_Left
50+
effects on parameters and Global variables of Crypto.To_Unsigned depends on
51+
effects on parameters and Global variables of Interfaces.Shift_Left
52+
absence of run-time errors of Crypto.To_Unsigned depends on
53+
effects on parameters and Global variables of Interfaces.Shift_Left
54+
absence of run-time errors of Interfaces.Shift_Left
4955
in unit crypto-phelix, 26 subprograms and packages out of 26 analyzed
5056
Crypto.Phelix at crypto-phelix.ads:57 flow analyzed (0 errors and 0 warnings) and proved (1 checks)
5157
absence of run-time errors of Crypto.Phelix fully established
@@ -75,65 +81,85 @@ absence of run-time errors of Crypto.Phelix.Ctx_Msg_Len fully established
7581
crypto-phelix.adb:163:41: "Destination" is initialized, there's an explicit assignment above
7682
the postcondition of Crypto.Phelix.Decrypt_Bytes depends on
7783
effects on parameters and Global variables of Interfaces.Rotate_Left
84+
effects on parameters and Global variables of Interfaces.Shift_Left
7885
effects on parameters and Global variables of Interfaces.Shift_Right
7986
absence of run-time errors of Interfaces.Rotate_Left
87+
absence of run-time errors of Interfaces.Shift_Left
8088
absence of run-time errors of Interfaces.Shift_Right
8189
effects on parameters and Global variables of Crypto.Phelix.Decrypt_Bytes depends on
8290
effects on parameters and Global variables of Interfaces.Rotate_Left
91+
effects on parameters and Global variables of Interfaces.Shift_Left
8392
effects on parameters and Global variables of Interfaces.Shift_Right
8493
absence of run-time errors of Crypto.Phelix.Decrypt_Bytes depends on
8594
effects on parameters and Global variables of Interfaces.Rotate_Left
95+
effects on parameters and Global variables of Interfaces.Shift_Left
8696
effects on parameters and Global variables of Interfaces.Shift_Right
8797
absence of run-time errors of Interfaces.Rotate_Left
98+
absence of run-time errors of Interfaces.Shift_Left
8899
absence of run-time errors of Interfaces.Shift_Right
89100
Crypto.Phelix.Decrypt_Packet at crypto-phelix.ads:150 flow analyzed (0 errors and 0 warnings) and proved (10 checks)
90101
suppressed messages:
91102
crypto-phelix.adb:210:65: Full assignment is split between Msg_Header, and Msg_Body in Decrypt_Bytes.
92103
the postcondition of Crypto.Phelix.Decrypt_Packet depends on
93104
effects on parameters and Global variables of Interfaces.Rotate_Left
105+
effects on parameters and Global variables of Interfaces.Shift_Left
94106
effects on parameters and Global variables of Interfaces.Shift_Right
95107
absence of run-time errors of Interfaces.Rotate_Left
108+
absence of run-time errors of Interfaces.Shift_Left
96109
absence of run-time errors of Interfaces.Shift_Right
97110
effects on parameters and Global variables of Crypto.Phelix.Decrypt_Packet depends on
98111
effects on parameters and Global variables of Interfaces.Rotate_Left
112+
effects on parameters and Global variables of Interfaces.Shift_Left
99113
effects on parameters and Global variables of Interfaces.Shift_Right
100114
absence of run-time errors of Crypto.Phelix.Decrypt_Packet depends on
101115
effects on parameters and Global variables of Interfaces.Rotate_Left
116+
effects on parameters and Global variables of Interfaces.Shift_Left
102117
effects on parameters and Global variables of Interfaces.Shift_Right
103118
absence of run-time errors of Interfaces.Rotate_Left
119+
absence of run-time errors of Interfaces.Shift_Left
104120
absence of run-time errors of Interfaces.Shift_Right
105121
Crypto.Phelix.Encrypt_Bytes at crypto-phelix.ads:251 flow analyzed (0 errors and 0 warnings) and proved (35 checks)
106122
suppressed messages:
107123
crypto-phelix.ads:253:29: Encrypt_Bytes ensures full initialization of "Destination".
108124
crypto-phelix.adb:265:41: "Destination" is initialized, there's an explicit assignment above
109125
the postcondition of Crypto.Phelix.Encrypt_Bytes depends on
110126
effects on parameters and Global variables of Interfaces.Rotate_Left
127+
effects on parameters and Global variables of Interfaces.Shift_Left
111128
effects on parameters and Global variables of Interfaces.Shift_Right
112129
absence of run-time errors of Interfaces.Rotate_Left
130+
absence of run-time errors of Interfaces.Shift_Left
113131
absence of run-time errors of Interfaces.Shift_Right
114132
effects on parameters and Global variables of Crypto.Phelix.Encrypt_Bytes depends on
115133
effects on parameters and Global variables of Interfaces.Rotate_Left
134+
effects on parameters and Global variables of Interfaces.Shift_Left
116135
effects on parameters and Global variables of Interfaces.Shift_Right
117136
absence of run-time errors of Crypto.Phelix.Encrypt_Bytes depends on
118137
effects on parameters and Global variables of Interfaces.Rotate_Left
138+
effects on parameters and Global variables of Interfaces.Shift_Left
119139
effects on parameters and Global variables of Interfaces.Shift_Right
120140
absence of run-time errors of Interfaces.Rotate_Left
141+
absence of run-time errors of Interfaces.Shift_Left
121142
absence of run-time errors of Interfaces.Shift_Right
122143
Crypto.Phelix.Encrypt_Packet at crypto-phelix.ads:112 flow analyzed (0 errors and 0 warnings) and proved (11 checks)
123144
suppressed messages:
124145
crypto-phelix.adb:311:65: Full assignment is split between Msg_Header, and Msg_Body in Encrypt_Bytes.
125146
the postcondition of Crypto.Phelix.Encrypt_Packet depends on
126147
effects on parameters and Global variables of Interfaces.Rotate_Left
148+
effects on parameters and Global variables of Interfaces.Shift_Left
127149
effects on parameters and Global variables of Interfaces.Shift_Right
128150
absence of run-time errors of Interfaces.Rotate_Left
151+
absence of run-time errors of Interfaces.Shift_Left
129152
absence of run-time errors of Interfaces.Shift_Right
130153
effects on parameters and Global variables of Crypto.Phelix.Encrypt_Packet depends on
131154
effects on parameters and Global variables of Interfaces.Rotate_Left
155+
effects on parameters and Global variables of Interfaces.Shift_Left
132156
effects on parameters and Global variables of Interfaces.Shift_Right
133157
absence of run-time errors of Crypto.Phelix.Encrypt_Packet depends on
134158
effects on parameters and Global variables of Interfaces.Rotate_Left
159+
effects on parameters and Global variables of Interfaces.Shift_Left
135160
effects on parameters and Global variables of Interfaces.Shift_Right
136161
absence of run-time errors of Interfaces.Rotate_Left
162+
absence of run-time errors of Interfaces.Shift_Left
137163
absence of run-time errors of Interfaces.Shift_Right
138164
Crypto.Phelix.Exclusive_Or at crypto-phelix.adb:27 flow analyzed (0 errors and 0 warnings) and proved (6 checks)
139165
the postcondition of Crypto.Phelix.Exclusive_Or fully established
@@ -173,45 +199,72 @@ absence of run-time errors of Crypto.Phelix.MAC_Size_32Predicate fully establish
173199
Crypto.Phelix.Process_AAD at crypto-phelix.ads:226 flow analyzed (0 errors and 0 warnings) and proved (15 checks)
174200
the postcondition of Crypto.Phelix.Process_AAD depends on
175201
effects on parameters and Global variables of Interfaces.Rotate_Left
202+
effects on parameters and Global variables of Interfaces.Shift_Left
176203
absence of run-time errors of Interfaces.Rotate_Left
204+
absence of run-time errors of Interfaces.Shift_Left
177205
effects on parameters and Global variables of Crypto.Phelix.Process_AAD depends on
178206
effects on parameters and Global variables of Interfaces.Rotate_Left
207+
effects on parameters and Global variables of Interfaces.Shift_Left
179208
absence of run-time errors of Crypto.Phelix.Process_AAD depends on
180209
effects on parameters and Global variables of Interfaces.Rotate_Left
210+
effects on parameters and Global variables of Interfaces.Shift_Left
181211
absence of run-time errors of Interfaces.Rotate_Left
212+
absence of run-time errors of Interfaces.Shift_Left
182213
Crypto.Phelix.Setup_Key at crypto-phelix.ads:183 flow analyzed (0 errors and 0 warnings) and proved (33 checks)
183214
the postcondition of Crypto.Phelix.Setup_Key depends on
184215
effects on parameters and Global variables of Interfaces.Rotate_Left
216+
effects on parameters and Global variables of Interfaces.Shift_Left
185217
absence of run-time errors of Interfaces.Rotate_Left
218+
absence of run-time errors of Interfaces.Shift_Left
186219
effects on parameters and Global variables of Crypto.Phelix.Setup_Key depends on
187220
effects on parameters and Global variables of Interfaces.Rotate_Left
221+
effects on parameters and Global variables of Interfaces.Shift_Left
188222
absence of run-time errors of Crypto.Phelix.Setup_Key depends on
189223
effects on parameters and Global variables of Interfaces.Rotate_Left
224+
effects on parameters and Global variables of Interfaces.Shift_Left
190225
absence of run-time errors of Interfaces.Rotate_Left
226+
absence of run-time errors of Interfaces.Shift_Left
191227
Crypto.Phelix.Setup_Key_Called at crypto-phelix.ads:97 flow analyzed (0 errors and 0 warnings) and proved (0 checks)
192228
effects on parameters and Global variables of Crypto.Phelix.Setup_Key_Called fully established
193229
absence of run-time errors of Crypto.Phelix.Setup_Key_Called fully established
194230
Crypto.Phelix.Setup_Nonce at crypto-phelix.ads:202 flow analyzed (0 errors and 0 warnings) and proved (8 checks)
195231
the postcondition of Crypto.Phelix.Setup_Nonce depends on
196232
effects on parameters and Global variables of Interfaces.Rotate_Left
233+
effects on parameters and Global variables of Interfaces.Shift_Left
197234
absence of run-time errors of Interfaces.Rotate_Left
235+
absence of run-time errors of Interfaces.Shift_Left
198236
effects on parameters and Global variables of Crypto.Phelix.Setup_Nonce depends on
199237
effects on parameters and Global variables of Interfaces.Rotate_Left
238+
effects on parameters and Global variables of Interfaces.Shift_Left
200239
absence of run-time errors of Crypto.Phelix.Setup_Nonce depends on
201240
effects on parameters and Global variables of Interfaces.Rotate_Left
241+
effects on parameters and Global variables of Interfaces.Shift_Left
202242
absence of run-time errors of Interfaces.Rotate_Left
243+
absence of run-time errors of Interfaces.Shift_Left
203244
Crypto.Phelix.Setup_Nonce_Called at crypto-phelix.ads:101 flow analyzed (0 errors and 0 warnings) and proved (0 checks)
204245
effects on parameters and Global variables of Crypto.Phelix.Setup_Nonce_Called fully established
205246
absence of run-time errors of Crypto.Phelix.Setup_Nonce_Called fully established
206247
Crypto.Phelix.To_Unsigned at crypto-phelix.adb:38 flow analyzed (0 errors and 0 warnings) and proved (0 checks)
207-
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned fully established
208-
absence of run-time errors of Crypto.Phelix.To_Unsigned fully established
248+
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned depends on
249+
effects on parameters and Global variables of Interfaces.Shift_Left
250+
absence of run-time errors of Crypto.Phelix.To_Unsigned depends on
251+
effects on parameters and Global variables of Interfaces.Shift_Left
252+
absence of run-time errors of Interfaces.Shift_Left
209253
Crypto.Phelix.To_Unsigned at crypto-phelix.adb:46 flow analyzed (0 errors and 0 warnings) and proved (0 checks)
210-
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned fully established
211-
absence of run-time errors of Crypto.Phelix.To_Unsigned fully established
254+
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned depends on
255+
effects on parameters and Global variables of Interfaces.Shift_Left
256+
absence of run-time errors of Crypto.Phelix.To_Unsigned depends on
257+
effects on parameters and Global variables of Interfaces.Shift_Left
258+
absence of run-time errors of Interfaces.Shift_Left
212259
Crypto.Phelix.To_Unsigned at crypto-phelix.adb:54 flow analyzed (0 errors and 0 warnings) and proved (0 checks)
213-
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned fully established
214-
absence of run-time errors of Crypto.Phelix.To_Unsigned fully established
260+
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned depends on
261+
effects on parameters and Global variables of Interfaces.Shift_Left
262+
absence of run-time errors of Crypto.Phelix.To_Unsigned depends on
263+
effects on parameters and Global variables of Interfaces.Shift_Left
264+
absence of run-time errors of Interfaces.Shift_Left
215265
Crypto.Phelix.To_Unsigned at crypto-phelix.adb:62 flow analyzed (0 errors and 0 warnings) and proved (0 checks)
216-
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned fully established
217-
absence of run-time errors of Crypto.Phelix.To_Unsigned fully established
266+
effects on parameters and Global variables of Crypto.Phelix.To_Unsigned depends on
267+
effects on parameters and Global variables of Interfaces.Shift_Left
268+
absence of run-time errors of Crypto.Phelix.To_Unsigned depends on
269+
effects on parameters and Global variables of Interfaces.Shift_Left
270+
absence of run-time errors of Interfaces.Shift_Left

src/crypto.ads

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ is
6464
function To_Stream (Value : in Word_32) return General_Stream with
6565
Global => null,
6666
Depends => (To_Stream'Result => Value),
67-
Post => (To_Stream'Result'Length = 4 and To_Stream'Result'First = 0);
67+
Post => ((To_Stream'Result'Length = 4 and To_Stream'Result'First = 0) and then
68+
To_Stream'Result = (0 => Byte (Shift_Right (Value, 0) mod 256),
69+
1 => Byte (Shift_Right (Value, 8) mod 256),
70+
2 => Byte (Shift_Right (Value, 16) mod 256),
71+
3 => Byte (Shift_Right (Value, 24) mod 256)));
6872

6973
--
7074
-- To_Unsigned
@@ -74,7 +78,11 @@ is
7478
--
7579
function To_Unsigned (Value : in General_Stream) return Word_32 with
7680
Global => null,
77-
Depends => (To_Unsigned'Result => (Value));
81+
Depends => (To_Unsigned'Result => (Value)),
82+
Post => (To_Unsigned'Result = (if Value'Length > 0 then (Shift_Left (Word_32 (Value (Value'First)), 0)) else 0) +
83+
(if Value'Length > 1 then (Shift_Left (Word_32 (Value (Value'First + 1)), 8)) else 0) +
84+
(if Value'Length > 2 then (Shift_Left (Word_32 (Value (Value'First + 2)), 16)) else 0) +
85+
(if Value'Length > 3 then (Shift_Left (Word_32 (Value (Value'First + 3)), 24)) else 0));
7886

7987
private
8088

@@ -83,10 +91,10 @@ private
8391
--
8492
function To_Stream (Value : in Word_32) return General_Stream is
8593
(General_Stream'
86-
(0 => Byte (Shift_Right (Value, 0) mod 256),
87-
1 => Byte (Shift_Right (Value, 8) mod 256),
88-
2 => Byte (Shift_Right (Value, 16) mod 256),
89-
3 => Byte (Shift_Right (Value, 24) mod 256)));
94+
(0 => Byte (Value / 2 ** 0 mod 256),
95+
1 => Byte (Value / 2 ** 8 mod 256),
96+
2 => Byte (Value / 2 ** 16 mod 256),
97+
3 => Byte (Value / 2 ** 24 mod 256)));
9098

9199
--
92100
-- To_Unsigned

0 commit comments

Comments
 (0)