forked from awslabs/aws-lc-verification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evp-function-specs.saw
280 lines (202 loc) · 12.7 KB
/
evp-function-specs.saw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
let EVP_DigestSignVerifyInit_spec is_sign = do {
crucible_alloc_global "EVP_MD_pctx_ops_storage";
crucible_alloc_global "EVP_MD_pctx_ops_once";
crucible_alloc_global "EVP_PKEY_rsa_pkey_meth_storage";
crucible_alloc_global "EVP_PKEY_rsa_pss_pkey_meth_storage";
crucible_alloc_global "EVP_PKEY_ec_pkey_meth_storage";
crucible_alloc_global "EVP_PKEY_hkdf_pkey_meth_storage";
crucible_alloc_global "EVP_PKEY_hmac_pkey_meth_storage";
crucible_alloc_global "EVP_PKEY_rsa_pkey_meth_once";
crucible_alloc_global "EVP_PKEY_rsa_pss_pkey_meth_once";
crucible_alloc_global "EVP_PKEY_ec_pkey_meth_once";
crucible_alloc_global "EVP_PKEY_hkdf_pkey_meth_once";
crucible_alloc_global "EVP_PKEY_hmac_pkey_meth_once";
crucible_alloc_global "AWSLC_fips_evp_pkey_methods_storage.0.0";
crucible_alloc_global "AWSLC_fips_evp_pkey_methods_storage.0.1";
crucible_alloc_global "AWSLC_fips_evp_pkey_methods_storage.0.2";
crucible_alloc_global "AWSLC_fips_evp_pkey_methods_storage.0.3";
crucible_alloc_global "AWSLC_fips_evp_pkey_methods_storage.0.4";
crucible_alloc_global "AWSLC_fips_evp_pkey_methods_once";
ctx_ptr <- crucible_alloc (llvm_struct "struct.env_md_ctx_st");
points_to_env_md_ctx_st ctx_ptr crucible_null crucible_null crucible_null;
type_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_st");
points_to_env_md_st type_ptr;
pkey_ptr <- crucible_alloc (llvm_struct "struct.evp_pkey_st");
ec_group_ptr <- pointer_to_fresh_ec_group_st;
(ec_key_ptr, _pub_key, _priv_key) <- pointer_to_fresh_ec_key_st ec_group_ptr is_sign;
points_to_evp_pkey_st pkey_ptr ec_key_ptr;
crucible_execute_func [ctx_ptr, crucible_null, type_ptr, crucible_null, pkey_ptr];
points_to_evp_md_pctx_ops (crucible_global "EVP_MD_pctx_ops_storage");
sha512_state_ptr <- crucible_alloc (llvm_struct "struct.sha512_state_st");
res_block <- crucible_fresh_cryptol_var "res_block" {| ByteArray |};
points_to_sha512_state_st_array_n32 sha512_state_ptr
{{ { h = SHAInit_Array.h, block = res_block, n = SHAInit_Array.n, sz = SHAInit_Array.sz } }};
evp_pkey_ctx_ptr <- crucible_alloc (llvm_struct "struct.evp_pkey_ctx_st");
points_to_EVP_PKEY_ec_pkey_meth (crucible_global "EVP_PKEY_ec_pkey_meth_storage");
ec_pkey_ctx_ptr <- crucible_alloc (llvm_struct "struct.EC_PKEY_CTX");
points_to_EC_PKEY_CTX ec_pkey_ctx_ptr type_ptr;
points_to_evp_pkey_ctx_st evp_pkey_ctx_ptr (crucible_global "EVP_PKEY_ec_pkey_meth_storage") pkey_ptr crucible_null (if is_sign then EVP_PKEY_OP_SIGN else EVP_PKEY_OP_VERIFY) ec_pkey_ctx_ptr;
points_to_env_md_ctx_st_with_pctx ctx_ptr type_ptr sha512_state_ptr evp_pkey_ctx_ptr (crucible_global "EVP_MD_pctx_ops_storage") (crucible_global SHA_UPDATE);
crucible_return (crucible_term {{ 1 : [32] }});
};
let EVP_DigestSignVerifyUpdate_spec is_sign = do {
global_alloc_init "OPENSSL_ia32cap_P" {{ ia32cap }};
ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_ctx_st");
digest_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_st");
points_to_env_md_st digest_ptr;
(sha512_state, sha512_state_ptr) <- pointer_to_fresh_sha512_state_st_array_n32 "sha512_state";
crucible_precond {{ sha512_state.n < `SHA512_CBLOCK }};
evp_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.evp_pkey_ctx_st");
pmeth_ptr <- pointer_to_evp_pkey_method_st;
pkey_ptr <- crucible_alloc_readonly (llvm_struct "struct.evp_pkey_st");
ec_group_ptr <- pointer_to_fresh_ec_group_st;
(ec_key_ptr, _pub_key, _priv_key) <- pointer_to_fresh_ec_key_st ec_group_ptr is_sign;
points_to_evp_pkey_st pkey_ptr ec_key_ptr;
ec_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.EC_PKEY_CTX");
points_to_EC_PKEY_CTX ec_pkey_ctx_ptr digest_ptr;
points_to_evp_pkey_ctx_st evp_pkey_ctx_ptr pmeth_ptr pkey_ptr crucible_null (if is_sign then EVP_PKEY_OP_SIGN else EVP_PKEY_OP_VERIFY) ec_pkey_ctx_ptr;
pctx_ops_ptr <- pointer_to_evp_md_pctx_ops;
points_to_env_md_ctx_st_with_pctx ctx_ptr digest_ptr sha512_state_ptr evp_pkey_ctx_ptr pctx_ops_ptr (crucible_global SHA_UPDATE);
len <- crucible_fresh_var "len" i64;
(data, data_ptr) <- ptr_to_fresh_array_readonly "data" len;
crucible_execute_func [ctx_ptr, data_ptr, (crucible_term len)];
global_points_to "OPENSSL_ia32cap_P" {{ ia32cap }};
let res = {{ ECDSA_SignVerify_Update sha512_state data len }};
res_block <- crucible_fresh_cryptol_var "res_block" {| ByteArray |};
points_to_sha512_state_st_array_n32 sha512_state_ptr {{ { h = res.h, block = res_block, n = res.n, sz = res.sz } }};
crucible_postcond {{ arrayRangeEq res_block 0 res.block 0 `SHA512_CBLOCK }};
crucible_postcond {{ res.n < `SHA512_CBLOCK }};
crucible_return (crucible_term {{ 1 : [32] }});
};
let EVP_DigestSignFinal_spec = do {
global_alloc_init "OPENSSL_ia32cap_P" {{ ia32cap }};
alloc_p384_felem_methods_globals;
ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_ctx_st");
digest_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_st");
points_to_env_md_st digest_ptr;
(sha512_state, sha512_state_ptr) <- pointer_to_fresh_sha512_state_st_array_n32 "sha512_state";
crucible_precond {{ sha512_state.n < `SHA512_CBLOCK }};
evp_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.evp_pkey_ctx_st");
pmeth_ptr <- pointer_to_evp_pkey_method_st;
pkey_ptr <- crucible_alloc (llvm_struct "struct.evp_pkey_st");
ec_group_ptr <- pointer_to_fresh_ec_group_st;
(ec_key_ptr, _pub_key, priv_key) <- pointer_to_fresh_ec_key_st ec_group_ptr true;
points_to_evp_pkey_st pkey_ptr ec_key_ptr;
ec_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.EC_PKEY_CTX");
points_to_EC_PKEY_CTX ec_pkey_ctx_ptr digest_ptr;
points_to_evp_pkey_ctx_st evp_pkey_ctx_ptr pmeth_ptr pkey_ptr crucible_null EVP_PKEY_OP_SIGN ec_pkey_ctx_ptr;
pctx_ops_ptr <- pointer_to_evp_md_pctx_ops;
points_to_env_md_ctx_st_with_pctx ctx_ptr digest_ptr sha512_state_ptr evp_pkey_ctx_ptr pctx_ops_ptr (crucible_global SHA_UPDATE);
out_sig_ptr <- crucible_alloc (llvm_array max_sig_len i8);
out_sig_len_ptr <- crucible_alloc i64;
crucible_points_to out_sig_len_ptr (crucible_term {{ `max_sig_len : [64] }});
// the symbolic integer to be used as the random integer `k` by the sign
// operation
k <- nondeterministic_valid_k priv_key {{ sha512_state }} false;
crucible_execute_func [ctx_ptr, out_sig_ptr, out_sig_len_ptr];
global_points_to "OPENSSL_ia32cap_P" {{ ia32cap }};
(r, s) <- points_to_fresh_asn1_sig out_sig_ptr;
crucible_points_to out_sig_len_ptr (crucible_term {{ `sig_len : [64] }});
let res = {{ ECDSA_Sign_Final priv_key sha512_state k }};
crucible_postcond {{ join r == scalarToBV res.r }};
crucible_postcond {{ join s == scalarToBV res.s }};
crucible_return (crucible_term {{ 1 : [32] }});
};
let EVP_DigestVerifyFinal_spec = do {
global_alloc_init "OPENSSL_ia32cap_P" {{ ia32cap }};
alloc_p384_felem_methods_globals;
ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_ctx_st");
digest_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_st");
points_to_env_md_st digest_ptr;
(sha512_state, sha512_state_ptr) <- pointer_to_fresh_sha512_state_st_array_n32 "sha512_state";
crucible_precond {{ sha512_state.n < `SHA512_CBLOCK }};
evp_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.evp_pkey_ctx_st");
pmeth_ptr <- pointer_to_evp_pkey_method_st;
pkey_ptr <- crucible_alloc (llvm_struct "struct.evp_pkey_st");
ec_group_ptr <- pointer_to_fresh_ec_group_st;
(ec_key_ptr, pub_key, _priv_key) <- pointer_to_fresh_ec_key_st ec_group_ptr false;
points_to_evp_pkey_st pkey_ptr ec_key_ptr;
ec_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.EC_PKEY_CTX");
points_to_EC_PKEY_CTX ec_pkey_ctx_ptr digest_ptr;
points_to_evp_pkey_ctx_st evp_pkey_ctx_ptr pmeth_ptr pkey_ptr crucible_null EVP_PKEY_OP_VERIFY ec_pkey_ctx_ptr;
pctx_ops_ptr <- pointer_to_evp_md_pctx_ops;
points_to_env_md_ctx_st_with_pctx ctx_ptr digest_ptr sha512_state_ptr evp_pkey_ctx_ptr pctx_ops_ptr (crucible_global SHA_UPDATE);
sig_ptr <- crucible_alloc_readonly (llvm_array sig_len i8);
(r, s) <- points_to_fresh_asn1_sig sig_ptr;
crucible_precond {{ is_num_bits_bn`{r_bits} (join r) }};
crucible_precond {{ is_num_bits_bn`{s_bits} (join s) }};
crucible_execute_func [ctx_ptr, sig_ptr, (crucible_term {{ `sig_len : [64] }})];
global_points_to "OPENSSL_ia32cap_P" {{ ia32cap }};
let ret = {{ ECDSA_Verify_Final pub_key sha512_state r s }};
crucible_return (crucible_term {{ if ret then 1 : [32] else 0 }});
};
let EVP_DigestSign_spec = do {
global_alloc_init "OPENSSL_ia32cap_P" {{ ia32cap }};
alloc_p384_felem_methods_globals;
ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_ctx_st");
digest_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_st");
points_to_env_md_st digest_ptr;
(sha512_state, sha512_state_ptr) <- pointer_to_fresh_sha512_state_st_array_n32 "sha512_state";
crucible_precond {{ sha512_state.n < `SHA512_CBLOCK }};
evp_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.evp_pkey_ctx_st");
pmeth_ptr <- pointer_to_evp_pkey_method_st;
pkey_ptr <- crucible_alloc (llvm_struct "struct.evp_pkey_st");
ec_group_ptr <- pointer_to_fresh_ec_group_st;
(ec_key_ptr, _pub_key, priv_key) <- pointer_to_fresh_ec_key_st ec_group_ptr true;
points_to_evp_pkey_st pkey_ptr ec_key_ptr;
ec_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.EC_PKEY_CTX");
points_to_EC_PKEY_CTX ec_pkey_ctx_ptr digest_ptr;
points_to_evp_pkey_ctx_st evp_pkey_ctx_ptr pmeth_ptr pkey_ptr crucible_null EVP_PKEY_OP_SIGN ec_pkey_ctx_ptr;
pctx_ops_ptr <- pointer_to_evp_md_pctx_ops;
points_to_env_md_ctx_st_with_pctx ctx_ptr digest_ptr sha512_state_ptr evp_pkey_ctx_ptr pctx_ops_ptr (crucible_global SHA_UPDATE);
out_sig_ptr <- crucible_alloc (llvm_array max_sig_len i8);
out_sig_len_ptr <- crucible_alloc i64;
crucible_points_to out_sig_len_ptr (crucible_term {{ `max_sig_len : [64] }});
data_len <- crucible_fresh_var "data_len" i64;
(data, data_ptr) <- ptr_to_fresh_array_readonly "data" data_len;
// the symbolic integer to be used as the random integer `k` by the sign
// operation
k <- nondeterministic_valid_k priv_key {{ ECDSA_SignVerify_Update sha512_state data data_len }} false;
crucible_execute_func [ctx_ptr, out_sig_ptr, out_sig_len_ptr, data_ptr, (crucible_term data_len)];
global_points_to "OPENSSL_ia32cap_P" {{ ia32cap }};
(r, s) <- points_to_fresh_asn1_sig out_sig_ptr;
crucible_points_to out_sig_len_ptr (crucible_term {{ `sig_len : [64] }});
let res = {{ ECDSA_Sign_Final priv_key (ECDSA_SignVerify_Update sha512_state data data_len) k }};
crucible_postcond {{ join r == scalarToBV res.r }};
crucible_postcond {{ join s == scalarToBV res.s }};
crucible_return (crucible_term {{ 1 : [32] }});
};
let EVP_DigestVerify_spec = do {
global_alloc_init "OPENSSL_ia32cap_P" {{ ia32cap }};
alloc_p384_felem_methods_globals;
ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_ctx_st");
digest_ptr <- crucible_alloc_readonly (llvm_struct "struct.env_md_st");
points_to_env_md_st digest_ptr;
(sha512_state, sha512_state_ptr) <- pointer_to_fresh_sha512_state_st_array_n32 "sha512_state";
crucible_precond {{ sha512_state.n < `SHA512_CBLOCK }};
evp_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.evp_pkey_ctx_st");
pmeth_ptr <- pointer_to_evp_pkey_method_st;
pkey_ptr <- crucible_alloc (llvm_struct "struct.evp_pkey_st");
ec_group_ptr <- pointer_to_fresh_ec_group_st;
(ec_key_ptr, pub_key, _priv_key) <- pointer_to_fresh_ec_key_st ec_group_ptr false;
points_to_evp_pkey_st pkey_ptr ec_key_ptr;
ec_pkey_ctx_ptr <- crucible_alloc_readonly (llvm_struct "struct.EC_PKEY_CTX");
points_to_EC_PKEY_CTX ec_pkey_ctx_ptr digest_ptr;
points_to_evp_pkey_ctx_st evp_pkey_ctx_ptr pmeth_ptr pkey_ptr crucible_null EVP_PKEY_OP_VERIFY ec_pkey_ctx_ptr;
pctx_ops_ptr <- pointer_to_evp_md_pctx_ops;
points_to_env_md_ctx_st_with_pctx ctx_ptr digest_ptr sha512_state_ptr evp_pkey_ctx_ptr pctx_ops_ptr (crucible_global SHA_UPDATE);
len <- crucible_fresh_var "len" i64;
(data, data_ptr) <- ptr_to_fresh_array_readonly "data" len;
sig_ptr <- crucible_alloc_readonly (llvm_array sig_len i8);
(r, s) <- points_to_fresh_asn1_sig sig_ptr;
crucible_precond {{ is_num_bits_bn`{r_bits} (join r) }};
crucible_precond {{ is_num_bits_bn`{s_bits} (join s) }};
crucible_execute_func [ctx_ptr, sig_ptr, (crucible_term {{ `sig_len : [64] }}), data_ptr, (crucible_term len)];
global_points_to "OPENSSL_ia32cap_P" {{ ia32cap }};
let ret = {{ ECDSA_Verify_Final pub_key (ECDSA_SignVerify_Update sha512_state data len) r s }};
crucible_return (crucible_term {{ if ret then 1 : [32] else 0 }});
};