|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +#include "api/s2n.h" |
| 17 | +#include "stuffer/s2n_stuffer.h" |
| 18 | +#include "crypto/s2n_dhe.h" |
| 19 | + |
| 20 | +#include <assert.h> |
| 21 | +#include <cbmc_proof/cbmc_utils.h> |
| 22 | +#include <cbmc_proof/proof_allocators.h> |
| 23 | +#include <cbmc_proof/make_common_datastructures.h> |
| 24 | +#include <cbmc_proof/nondet.h> |
| 25 | + |
| 26 | +/* |
| 27 | + * Since this function largely serves as a way to call specific OpenSSL |
| 28 | + * functions (which we do not fully emulate in CBMC), all we can assert |
| 29 | + * is memory safety. As such, several OpenSSL functions have been stubbed, |
| 30 | + * and a few functions have been left omitted since they do not affect |
| 31 | + * the proof. |
| 32 | + */ |
| 33 | +void s2n_pkcs3_to_dh_params_harness() { |
| 34 | + /* Non-deterministic inputs. */ |
| 35 | + struct s2n_dh_params dh_params = {0}; |
| 36 | + struct s2n_blob *pkcs3 = cbmc_allocate_s2n_blob(); |
| 37 | + __CPROVER_assume(s2n_blob_is_valid(pkcs3)); |
| 38 | + uint8_t *old_data = pkcs3->data; |
| 39 | + struct store_byte_from_buffer old_byte; |
| 40 | + save_byte_from_blob(pkcs3, &old_byte); |
| 41 | + __CPROVER_assume(s2n_blob_is_bounded(pkcs3, MAX_BLOB_SIZE)); |
| 42 | + |
| 43 | + /* Non-deterministically set initialized (in s2n_mem) to true. */ |
| 44 | + if(nondet_bool()) { |
| 45 | + s2n_mem_init(); |
| 46 | + } |
| 47 | + |
| 48 | + /* Operation under verification. */ |
| 49 | + if (s2n_pkcs3_to_dh_params(&dh_params, pkcs3) == S2N_SUCCESS) { |
| 50 | + assert(pkcs3->data == old_data); |
| 51 | + assert_byte_from_blob_matches(pkcs3, &old_byte); |
| 52 | + } |
| 53 | +} |
0 commit comments