@@ -81,60 +81,189 @@ typedef struct
8181
8282MLK_EXTERNAL_API
8383void crypto_kem_marshal_pk (uint8_t pk [MLKEM_INDCCA_PUBLICKEYBYTES ],
84- const mlk_public_key * pks );
84+ const mlk_public_key * pks )
85+ __contract__ (
86+ requires (memory_no_alias (pk , MLKEM_INDCCA_PUBLICKEYBYTES ))
87+ requires (memory_no_alias (pks , sizeof (mlk_public_key )))
88+ requires (forall (k0 , 0 , MLKEM_K ,
89+ array_bound (pks - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
90+ assigns (object_whole (pk ))
91+ );
8592
8693MLK_EXTERNAL_API
8794MLK_MUST_CHECK_RETURN_VALUE
8895int crypto_kem_parse_pk (mlk_public_key * pks ,
89- const uint8_t pk [MLKEM_INDCCA_PUBLICKEYBYTES ]);
96+ const uint8_t pk [MLKEM_INDCCA_PUBLICKEYBYTES ])
97+ __contract__ (
98+ requires (memory_no_alias (pks , sizeof (mlk_public_key )))
99+ requires (memory_no_alias (pk , MLKEM_INDCCA_PUBLICKEYBYTES ))
100+ assigns (object_whole (pks ))
101+ ensures (forall (k0 , 0 , MLKEM_K ,
102+ array_bound (pks - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
103+ ensures (forall (x , 0 , MLKEM_K * MLKEM_K ,
104+ array_bound (pks - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
105+ );
90106
91107
92108MLK_EXTERNAL_API
93109void crypto_kem_marshal_sk (uint8_t sk [MLKEM_INDCCA_SECRETKEYBYTES ],
94- const mlk_secret_key * sks );
110+ const mlk_secret_key * sks )
111+ __contract__ (
112+ requires (memory_no_alias (sk , MLKEM_INDCCA_SECRETKEYBYTES ))
113+ requires (memory_no_alias (sks , sizeof (mlk_secret_key )))
114+ requires (forall (k0 , 0 , MLKEM_K ,
115+ array_bound (sks - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
116+ requires (forall (k1 , 0 , MLKEM_K ,
117+ array_bound (sks - > indcpa_sk .skpv [k1 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
118+ assigns (object_whole (sk ))
119+ );
95120
96121MLK_EXTERNAL_API
97122MLK_MUST_CHECK_RETURN_VALUE
98123int crypto_kem_parse_sk (mlk_secret_key * sks ,
99- const uint8_t sk [MLKEM_INDCCA_SECRETKEYBYTES ]);
124+ const uint8_t sk [MLKEM_INDCCA_SECRETKEYBYTES ])
125+ __contract__ (
126+ requires (memory_no_alias (sks , sizeof (mlk_secret_key )))
127+ requires (memory_no_alias (sk , MLKEM_INDCCA_SECRETKEYBYTES ))
128+ assigns (object_whole (sks ))
129+ ensures (forall (k0 , 0 , MLKEM_K ,
130+ array_bound (sks - > indcpa_sk .skpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
131+ ensures (forall (k1 , 0 , MLKEM_K ,
132+ array_bound (sks - > indcpa_pk .pkpv [k1 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
133+ ensures (forall (x , 0 , MLKEM_K * MLKEM_K ,
134+ array_bound (sks - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
135+ );
100136
101137
102138MLK_EXTERNAL_API
103139MLK_MUST_CHECK_RETURN_VALUE
104140int crypto_kem_keypair_derand_struct (mlk_public_key * pk , mlk_secret_key * sk ,
105- const uint8_t coins [2 * MLKEM_SYMBYTES ]);
141+ const uint8_t coins [2 * MLKEM_SYMBYTES ])
142+ __contract__ (
143+ requires (memory_no_alias (pk , sizeof (mlk_public_key )))
144+ requires (memory_no_alias (sk , sizeof (mlk_secret_key )))
145+ requires (memory_no_alias (coins , 2 * MLKEM_SYMBYTES ))
146+ assigns (object_whole (pk ))
147+ assigns (object_whole (sk ))
148+ ensures (forall (k0 , 0 , MLKEM_K ,
149+ array_bound (pk - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
150+ ensures (forall (x , 0 , MLKEM_K * MLKEM_K ,
151+ array_bound (pk - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
152+ ensures (forall (k1 , 0 , MLKEM_K ,
153+ array_bound (sk - > indcpa_pk .pkpv [k1 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
154+ ensures (forall (k2 , 0 , MLKEM_K ,
155+ array_bound (sk - > indcpa_sk .skpv [k2 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
156+ ensures (forall (y , 0 , MLKEM_K * MLKEM_K ,
157+ array_bound (sk - > indcpa_pk .at [y ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
158+ );
106159
107160MLK_EXTERNAL_API
108161MLK_MUST_CHECK_RETURN_VALUE
109- int crypto_kem_keypair_struct (mlk_public_key * pk , mlk_secret_key * sk );
162+ int crypto_kem_keypair_struct (mlk_public_key * pk , mlk_secret_key * sk )
163+ __contract__ (
164+ requires (memory_no_alias (pk , sizeof (mlk_public_key )))
165+ requires (memory_no_alias (sk , sizeof (mlk_secret_key )))
166+ assigns (object_whole (pk ))
167+ assigns (object_whole (sk ))
168+ ensures (forall (k0 , 0 , MLKEM_K ,
169+ array_bound (pk - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
170+ ensures (forall (x , 0 , MLKEM_K * MLKEM_K ,
171+ array_bound (pk - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
172+ ensures (forall (k1 , 0 , MLKEM_K ,
173+ array_bound (sk - > indcpa_pk .pkpv [k1 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
174+ ensures (forall (k2 , 0 , MLKEM_K ,
175+ array_bound (sk - > indcpa_sk .skpv [k2 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
176+ ensures (forall (y , 0 , MLKEM_K * MLKEM_K ,
177+ array_bound (sk - > indcpa_pk .at [y ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
178+ );
179+
110180
111181MLK_EXTERNAL_API
112182MLK_MUST_CHECK_RETURN_VALUE
113183int crypto_kem_enc_derand_struct (uint8_t ct [MLKEM_INDCCA_CIPHERTEXTBYTES ],
114184 uint8_t ss [MLKEM_SSBYTES ],
115185 const mlk_public_key * pk ,
116- const uint8_t coins [MLKEM_SYMBYTES ]);
186+ const uint8_t coins [MLKEM_SYMBYTES ])
187+ __contract__ (
188+ requires (memory_no_alias (ct , MLKEM_INDCCA_CIPHERTEXTBYTES ))
189+ requires (memory_no_alias (ss , MLKEM_SSBYTES ))
190+ requires (memory_no_alias (pk , sizeof (mlk_public_key )))
191+ requires (memory_no_alias (coins , MLKEM_SYMBYTES ))
192+ requires (forall (k0 , 0 , MLKEM_K ,
193+ array_bound (pk - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
194+ requires (forall (x , 0 , MLKEM_K * MLKEM_K ,
195+ array_bound (pk - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
196+ assigns (object_whole (ct ))
197+ assigns (object_whole (ss ))
198+ );
117199
118200MLK_EXTERNAL_API
119201MLK_MUST_CHECK_RETURN_VALUE
120202int crypto_kem_enc_struct (uint8_t ct [MLKEM_INDCCA_CIPHERTEXTBYTES ],
121- uint8_t ss [MLKEM_SSBYTES ], const mlk_public_key * pk );
203+ uint8_t ss [MLKEM_SSBYTES ], const mlk_public_key * pk )
204+ __contract__ (
205+ requires (memory_no_alias (ct , MLKEM_INDCCA_CIPHERTEXTBYTES ))
206+ requires (memory_no_alias (ss , MLKEM_SSBYTES ))
207+ requires (memory_no_alias (pk , sizeof (mlk_public_key )))
208+ requires (forall (k0 , 0 , MLKEM_K ,
209+ array_bound (pk - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
210+ requires (forall (x , 0 , MLKEM_K * MLKEM_K ,
211+ array_bound (pk - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
212+ assigns (object_whole (ct ))
213+ assigns (object_whole (ss ))
214+ );
122215
123216MLK_EXTERNAL_API
124217MLK_MUST_CHECK_RETURN_VALUE
125218int crypto_kem_dec_struct (uint8_t ss [MLKEM_SSBYTES ],
126219 const uint8_t ct [MLKEM_INDCCA_CIPHERTEXTBYTES ],
127- const mlk_secret_key * sk );
128-
220+ const mlk_secret_key * sk )
221+ __contract__ (
222+ requires (memory_no_alias (ss , MLKEM_SSBYTES ))
223+ requires (memory_no_alias (ct , MLKEM_INDCCA_CIPHERTEXTBYTES ))
224+ requires (memory_no_alias (sk , sizeof (mlk_secret_key )))
225+ requires (forall (k0 , 0 , MLKEM_K ,
226+ array_bound (sk - > indcpa_sk .skpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
227+ requires (forall (k1 , 0 , MLKEM_K ,
228+ array_bound (sk - > indcpa_pk .pkpv [k1 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
229+ requires (forall (x , 0 , MLKEM_K * MLKEM_K ,
230+ array_bound (sk - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
231+ assigns (object_whole (ss ))
232+ );
129233
130234MLK_EXTERNAL_API
131235MLK_MUST_CHECK_RETURN_VALUE
132236int crypto_kem_sk_from_seed (mlk_secret_key * sk ,
133- const uint8_t coins [2 * MLKEM_SYMBYTES ]);
237+ const uint8_t coins [2 * MLKEM_SYMBYTES ])
238+ __contract__ (
239+ requires (memory_no_alias (sk , sizeof (mlk_secret_key )))
240+ requires (memory_no_alias (coins , 2 * MLKEM_SYMBYTES ))
241+ assigns (object_whole (sk ))
242+ assigns (object_whole (coins ))
243+ ensures (forall (k0 , 0 , MLKEM_K ,
244+ array_bound (sk - > indcpa_sk .skpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
245+ ensures (forall (k1 , 0 , MLKEM_K ,
246+ array_bound (sk - > indcpa_pk .pkpv [k1 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
247+ ensures (forall (x , 0 , MLKEM_K * MLKEM_K ,
248+ array_bound (sk - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
249+ );
134250
135251MLK_EXTERNAL_API
136252MLK_MUST_CHECK_RETURN_VALUE
137- int crypto_kem_pk_from_sk (mlk_public_key * pk , const mlk_secret_key * sk );
253+ int crypto_kem_pk_from_sk (mlk_public_key * pk , const mlk_secret_key * sk )
254+ __contract__ (
255+ requires (memory_no_alias (pk , sizeof (mlk_public_key )))
256+ requires (memory_no_alias (sk , sizeof (mlk_secret_key )))
257+ requires (forall (k1 , 0 , MLKEM_K ,
258+ array_bound (sk - > indcpa_pk .pkpv [k1 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
259+ requires (forall (x , 0 , MLKEM_K * MLKEM_K ,
260+ array_bound (sk - > indcpa_pk .at [x ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
261+ assigns (object_whole (pk ))
262+ ensures (forall (k0 , 0 , MLKEM_K ,
263+ array_bound (pk - > indcpa_pk .pkpv [k0 ].coeffs , 0 , MLKEM_N , 0 , MLKEM_UINT12_LIMIT )))
264+ ensures (forall (y , 0 , MLKEM_K * MLKEM_K ,
265+ array_bound (pk - > indcpa_pk .at [y ].coeffs , 0 , MLKEM_N , 0 , MLKEM_Q )))
266+ );
138267
139268/*************************************************
140269 * Name: crypto_kem_keypair_derand
0 commit comments