diff --git a/tests/cbmc/include/cbmc_proof/make_common_datastructures.h b/tests/cbmc/include/cbmc_proof/make_common_datastructures.h index f60ee2b0401..49955acbba8 100644 --- a/tests/cbmc/include/cbmc_proof/make_common_datastructures.h +++ b/tests/cbmc/include/cbmc_proof/make_common_datastructures.h @@ -32,7 +32,6 @@ #include "utils/s2n_blob.h" #include "utils/s2n_map_internal.h" #include "utils/s2n_safety_macros.h" -#include "utils/s2n_set.h" #include "utils/s2n_socket.h" /* @@ -102,21 +101,6 @@ void cbmc_populate_s2n_array(struct s2n_array *array); */ struct s2n_array *cbmc_allocate_s2n_array(); -/* - * Checks whether s2n_set is bounded by max_len and max_element_size. - */ -bool s2n_set_is_bounded(const struct s2n_set *set, const size_t max_len, const size_t max_element_size); - -/* - * Populates the fields of a pre-allocated s2n_set for CBMC proofs. - */ -void cbmc_populate_s2n_set(struct s2n_set *set); - -/* - * Properly allocates s2n_set for CBMC proofs. - */ -struct s2n_set *cbmc_allocate_s2n_set(); - /* * Populates the fields of a pre-allocated s2n_dh_params for CBMC proofs. */ diff --git a/tests/cbmc/proofs/s2n_set_add/Makefile b/tests/cbmc/proofs/s2n_set_add/Makefile deleted file mode 100644 index 4c331d1ed99..00000000000 --- a/tests/cbmc/proofs/s2n_set_add/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -# -# -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use -# this file except in compliance with the License. A copy of the License is -# located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing permissions and -# limitations under the License. - -# Expected runtime is less than 50 seconds. - -MAX_ARRAY_LEN = 10 -DEFINES += -DMAX_ARRAY_LEN=$(MAX_ARRAY_LEN) - -MAX_ARRAY_ELEMENT_SIZE = 10 -DEFINES += -DMAX_ARRAY_ELEMENT_SIZE=$(MAX_ARRAY_ELEMENT_SIZE) - -BINARY_SEARCH_BOUND = 5 - -DEFINES += -DMADV_DONTDUMP=1 - -CBMCFLAGS += - -PROOF_UID = s2n_set_add -HARNESS_ENTRY = $(PROOF_UID)_harness -HARNESS_FILE = $(HARNESS_ENTRY).c - -PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) -PROOF_SOURCES += $(PROOF_SOURCE)/cbmc_utils.c -PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c -PROOF_SOURCES += $(PROOF_STUB)/madvise.c -PROOF_SOURCES += $(PROOF_STUB)/memmove_havoc.c -PROOF_SOURCES += $(PROOF_STUB)/mlock.c -PROOF_SOURCES += $(PROOF_STUB)/munlock.c -PROOF_SOURCES += $(PROOF_STUB)/posix_memalign_override.c -PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c -PROOF_SOURCES += $(PROOF_STUB)/sysconf.c - -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_array.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_ensure.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_mem.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_set.c - -# We abstract this function because manual inspection demonstrates it is unreachable. -REMOVE_FUNCTION_BODY += s2n_blob_slice -REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl - -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.0:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.1:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.2:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.3:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.4:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.5:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.6:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.7:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.8:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.9:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.10:$(call addone,$(BINARY_SEARCH_BOUND)) -UNWINDSET += __CPROVER_file_local_s2n_set_c_s2n_set_binary_search.11:$(call addone,$(BINARY_SEARCH_BOUND)) - -include ../Makefile.common diff --git a/tests/cbmc/proofs/s2n_set_add/cbmc-proof.txt b/tests/cbmc/proofs/s2n_set_add/cbmc-proof.txt deleted file mode 100644 index 6ed46f1258c..00000000000 --- a/tests/cbmc/proofs/s2n_set_add/cbmc-proof.txt +++ /dev/null @@ -1 +0,0 @@ -# This file marks this directory as containing a CBMC proof. diff --git a/tests/cbmc/proofs/s2n_set_add/s2n_set_add_harness.c b/tests/cbmc/proofs/s2n_set_add/s2n_set_add_harness.c deleted file mode 100644 index 6e86fddf0b9..00000000000 --- a/tests/cbmc/proofs/s2n_set_add/s2n_set_add_harness.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include "utils/s2n_set.h" - -#include - -#include - -void s2n_set_add_harness() -{ - /* Non-deterministic inputs. */ - struct s2n_set *set = cbmc_allocate_s2n_set(); - __CPROVER_assume(s2n_result_is_ok(s2n_set_validate(set))); - __CPROVER_assume(s2n_set_is_bounded(set, MAX_ARRAY_LEN, MAX_ARRAY_ELEMENT_SIZE)); - uint32_t idx; - void *element = malloc(set->data->element_size); - - nondet_s2n_mem_init(); - - struct s2n_array old_array = *(set->data); - struct store_byte_from_buffer old_byte; - - /* Operation under verification. */ - if(s2n_result_is_ok(s2n_set_add(set, element))) { - /* - * In the case s2n_set_add is successful, we can ensure the array isn't empty - * and index is within bounds. - */ - assert(set->data->mem.data != NULL); - assert(set->data->len == (old_array.len + 1)); - assert(s2n_result_is_ok(s2n_set_validate(set))); - } -} diff --git a/tests/cbmc/proofs/s2n_set_free/Makefile b/tests/cbmc/proofs/s2n_set_free/Makefile deleted file mode 100644 index c98075ef397..00000000000 --- a/tests/cbmc/proofs/s2n_set_free/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -# -# -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use -# this file except in compliance with the License. A copy of the License is -# located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing permissions and -# limitations under the License. - -# Expected runtime is less than 10 seconds. - -CBMCFLAGS += --memory-leak-check - -PROOF_UID = s2n_set_free -HARNESS_ENTRY = $(PROOF_UID)_harness -HARNESS_FILE = $(HARNESS_ENTRY).c - -PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) -PROOF_SOURCES += $(PROOF_SOURCE)/cbmc_utils.c -PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c -PROOF_SOURCES += $(PROOF_STUB)/munlock.c -PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c -PROOF_SOURCES += $(PROOF_STUB)/sysconf.c - -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_array.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_mem.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_set.c - -# We abstract this function because manual inspection demonstrates it is unreachable. -REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl - -UNWINDSET += - -include ../Makefile.common diff --git a/tests/cbmc/proofs/s2n_set_free/cbmc-proof.txt b/tests/cbmc/proofs/s2n_set_free/cbmc-proof.txt deleted file mode 100644 index 6ed46f1258c..00000000000 --- a/tests/cbmc/proofs/s2n_set_free/cbmc-proof.txt +++ /dev/null @@ -1 +0,0 @@ -# This file marks this directory as containing a CBMC proof. diff --git a/tests/cbmc/proofs/s2n_set_free/s2n_set_free_harness.c b/tests/cbmc/proofs/s2n_set_free/s2n_set_free_harness.c deleted file mode 100644 index 9506c871f66..00000000000 --- a/tests/cbmc/proofs/s2n_set_free/s2n_set_free_harness.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include "utils/s2n_set.h" - -#include - -#include - -void s2n_set_free_harness() -{ - /* Non-deterministic inputs. */ - struct s2n_set *set = cbmc_allocate_s2n_set(); - - /* Assumptions. */ - nondet_s2n_mem_init(); - __CPROVER_assume(s2n_result_is_ok(s2n_set_validate(set))); - - /* Operation under verification. */ - s2n_result result = s2n_set_free(set); - if (s2n_result_is_error(result)) { - assert(s2n_errno != S2N_ERR_FREE_STATIC_BLOB); - } - - /** - * Cleanup after expected error cases, for memory leak check. - * It's good proof practice not to mix state mutations (below) with property checks (above). - */ - if (s2n_result_is_error(result) && s2n_errno == S2N_ERR_NOT_INITIALIZED) { - /* s2n was not initialized, this failure is expected. */ - free(set->data->mem.data); - free(set->data); - free(set); - } -} diff --git a/tests/cbmc/proofs/s2n_set_free_p/Makefile b/tests/cbmc/proofs/s2n_set_free_p/Makefile deleted file mode 100644 index be9c26b1bd6..00000000000 --- a/tests/cbmc/proofs/s2n_set_free_p/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -# -# -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use -# this file except in compliance with the License. A copy of the License is -# located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing permissions and -# limitations under the License. - -# Expected runtime is less than 10 seconds. - -CBMCFLAGS += --memory-leak-check - -PROOF_UID = s2n_set_free_p -HARNESS_ENTRY = $(PROOF_UID)_harness -HARNESS_FILE = $(HARNESS_ENTRY).c - -PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) -PROOF_SOURCES += $(PROOF_SOURCE)/cbmc_utils.c -PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c -PROOF_SOURCES += $(PROOF_STUB)/munlock.c -PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c -PROOF_SOURCES += $(PROOF_STUB)/sysconf.c - -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_array.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_mem.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_set.c - -# We abstract this function because manual inspection demonstrates it is unreachable. -REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl - -UNWINDSET += - -include ../Makefile.common diff --git a/tests/cbmc/proofs/s2n_set_free_p/cbmc-proof.txt b/tests/cbmc/proofs/s2n_set_free_p/cbmc-proof.txt deleted file mode 100644 index 6ed46f1258c..00000000000 --- a/tests/cbmc/proofs/s2n_set_free_p/cbmc-proof.txt +++ /dev/null @@ -1 +0,0 @@ -# This file marks this directory as containing a CBMC proof. diff --git a/tests/cbmc/proofs/s2n_set_free_p/s2n_set_free_p_harness.c b/tests/cbmc/proofs/s2n_set_free_p/s2n_set_free_p_harness.c deleted file mode 100644 index 63424e2f69c..00000000000 --- a/tests/cbmc/proofs/s2n_set_free_p/s2n_set_free_p_harness.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include "utils/s2n_set.h" - -#include - -#include - -void s2n_set_free_p_harness() -{ - /* Non-deterministic inputs. */ - struct s2n_set *set = cbmc_allocate_s2n_set(); - - /* Assumptions. */ - nondet_s2n_mem_init(); - __CPROVER_assume(s2n_result_is_ok(s2n_set_validate(set))); - - /* Operation under verification. */ - s2n_result result = s2n_set_free_p(&set); - if (s2n_result_is_ok(result)) { - assert(set == NULL); - } else { - assert(s2n_errno != S2N_ERR_FREE_STATIC_BLOB); - } - - /** - * Cleanup after expected error cases, for memory leak check. - * It's good proof practice not to mix state mutations (below) with property checks (above). - */ - if (s2n_result_is_error(result) && s2n_errno == S2N_ERR_NOT_INITIALIZED) { - /* s2n was not initialized, this failure is expected. */ - free(set->data->mem.data); - free(set->data); - free(set); - } -} diff --git a/tests/cbmc/proofs/s2n_set_get/Makefile b/tests/cbmc/proofs/s2n_set_get/Makefile deleted file mode 100644 index a861cbe9746..00000000000 --- a/tests/cbmc/proofs/s2n_set_get/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# -# -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use -# this file except in compliance with the License. A copy of the License is -# located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing permissions and -# limitations under the License. - -# Expected runtime is less than 10 seconds. - -MAX_ARRAY_LEN = 10 -DEFINES += -DMAX_ARRAY_LEN=$(MAX_ARRAY_LEN) - -MAX_ARRAY_ELEMENT_SIZE = 10 -DEFINES += -DMAX_ARRAY_ELEMENT_SIZE=$(MAX_ARRAY_ELEMENT_SIZE) - -CBMCFLAGS += - -PROOF_UID = s2n_set_get -HARNESS_ENTRY = $(PROOF_UID)_harness -HARNESS_FILE = $(HARNESS_ENTRY).c - -PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) -PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c -PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c - -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_array.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_set.c - -UNWINDSET += - -include ../Makefile.common diff --git a/tests/cbmc/proofs/s2n_set_get/cbmc-proof.txt b/tests/cbmc/proofs/s2n_set_get/cbmc-proof.txt deleted file mode 100644 index 6ed46f1258c..00000000000 --- a/tests/cbmc/proofs/s2n_set_get/cbmc-proof.txt +++ /dev/null @@ -1 +0,0 @@ -# This file marks this directory as containing a CBMC proof. diff --git a/tests/cbmc/proofs/s2n_set_get/s2n_set_get_harness.c b/tests/cbmc/proofs/s2n_set_get/s2n_set_get_harness.c deleted file mode 100644 index 4da39362bcf..00000000000 --- a/tests/cbmc/proofs/s2n_set_get/s2n_set_get_harness.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include "utils/s2n_set.h" - -#include - -#include - -void s2n_set_get_harness() -{ - /* Non-deterministic inputs. */ - struct s2n_set *set = cbmc_allocate_s2n_set(); - __CPROVER_assume(s2n_result_is_ok(s2n_set_validate(set))); - __CPROVER_assume(s2n_set_is_bounded(set, MAX_ARRAY_LEN, MAX_ARRAY_ELEMENT_SIZE)); - uint32_t idx; - void **element = malloc(sizeof(void *)); - - /* Operation under verification. */ - if(s2n_result_is_ok(s2n_set_get(set, idx, element))) { - /* - * In the case s2n_set_get is successful, we can ensure the array isn't empty - * and index is within bounds. - */ - assert(set->data->mem.data != NULL); - assert(set->data->len != 0); - assert(idx < set->data->len); - assert(*element == (set->data->mem.data + (set->data->element_size * idx))); - } - - /* Post-condition. */ - assert(s2n_result_is_ok(s2n_set_validate(set))); -} diff --git a/tests/cbmc/proofs/s2n_set_len/Makefile b/tests/cbmc/proofs/s2n_set_len/Makefile deleted file mode 100644 index 8527ef4a232..00000000000 --- a/tests/cbmc/proofs/s2n_set_len/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# -# -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use -# this file except in compliance with the License. A copy of the License is -# located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing permissions and -# limitations under the License. - -# Expected runtime is less than 30 seconds. - -MAX_ARRAY_LEN = 100 -DEFINES += -DMAX_ARRAY_LEN=$(MAX_ARRAY_LEN) - -MAX_ARRAY_ELEMENT_SIZE = 100 -DEFINES += -DMAX_ARRAY_ELEMENT_SIZE=$(MAX_ARRAY_ELEMENT_SIZE) - -CBMCFLAGS += - -PROOF_UID = s2n_set_len -HARNESS_ENTRY = $(PROOF_UID)_harness -HARNESS_FILE = $(HARNESS_ENTRY).c - -PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) -PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c -PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c - -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_array.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_set.c - -UNWINDSET += - -include ../Makefile.common diff --git a/tests/cbmc/proofs/s2n_set_len/cbmc-proof.txt b/tests/cbmc/proofs/s2n_set_len/cbmc-proof.txt deleted file mode 100644 index 6ed46f1258c..00000000000 --- a/tests/cbmc/proofs/s2n_set_len/cbmc-proof.txt +++ /dev/null @@ -1 +0,0 @@ -# This file marks this directory as containing a CBMC proof. diff --git a/tests/cbmc/proofs/s2n_set_len/s2n_set_len_harness.c b/tests/cbmc/proofs/s2n_set_len/s2n_set_len_harness.c deleted file mode 100644 index 45e4479f4cf..00000000000 --- a/tests/cbmc/proofs/s2n_set_len/s2n_set_len_harness.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include "utils/s2n_set.h" - -#include - -#include - -void s2n_set_len_harness() -{ - /* Non-deterministic inputs. */ - struct s2n_set *set = cbmc_allocate_s2n_set(); - __CPROVER_assume(s2n_result_is_ok(s2n_set_validate(set))); - __CPROVER_assume(s2n_set_is_bounded(set, MAX_ARRAY_LEN, MAX_ARRAY_ELEMENT_SIZE)); - uint32_t* len = malloc(sizeof(*len)); - - /* Operation under verification. */ - if(s2n_result_is_ok(s2n_set_len(set, len))) { - /* Post-condition. */ - assert(*len == set->data->len); - } - - /* Post-condition. */ - assert(s2n_result_is_ok(s2n_set_validate(set))); -} diff --git a/tests/cbmc/proofs/s2n_set_new/Makefile b/tests/cbmc/proofs/s2n_set_new/Makefile deleted file mode 100644 index 55155b43baf..00000000000 --- a/tests/cbmc/proofs/s2n_set_new/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use -# this file except in compliance with the License. A copy of the License is -# located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing permissions and -# limitations under the License. - -# Expected runtime is less than 20 seconds. - -DEFINES += -DMADV_DONTDUMP=1 - -CBMCFLAGS += - -PROOF_UID = s2n_set_new -HARNESS_ENTRY = $(PROOF_UID)_harness -HARNESS_FILE = $(HARNESS_ENTRY).c - -PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) -PROOF_SOURCES += $(PROOF_SOURCE)/cbmc_utils.c -PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c -PROOF_SOURCES += $(PROOF_STUB)/madvise.c -PROOF_SOURCES += $(PROOF_STUB)/memset_havoc.c -PROOF_SOURCES += $(PROOF_STUB)/mlock.c -PROOF_SOURCES += $(PROOF_STUB)/munlock.c -PROOF_SOURCES += $(PROOF_STUB)/posix_memalign_override.c -PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c -PROOF_SOURCES += $(PROOF_STUB)/sysconf.c - -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_array.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_ensure.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_mem.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_set.c - -# We abstract these functions because manual inspection demonstrates they are unreachable. -REMOVE_FUNCTION_BODY += s2n_blob_slice -REMOVE_FUNCTION_BODY += s2n_ensure_memmove_trace -REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl - -UNWINDSET += - -include ../Makefile.common diff --git a/tests/cbmc/proofs/s2n_set_new/cbmc-proof.txt b/tests/cbmc/proofs/s2n_set_new/cbmc-proof.txt deleted file mode 100644 index 6ed46f1258c..00000000000 --- a/tests/cbmc/proofs/s2n_set_new/cbmc-proof.txt +++ /dev/null @@ -1 +0,0 @@ -# This file marks this directory as containing a CBMC proof. diff --git a/tests/cbmc/proofs/s2n_set_new/s2n_set_new_harness.c b/tests/cbmc/proofs/s2n_set_new/s2n_set_new_harness.c deleted file mode 100644 index 040d96255e3..00000000000 --- a/tests/cbmc/proofs/s2n_set_new/s2n_set_new_harness.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include "utils/s2n_set.h" - -#include - -#include - -void s2n_set_new_harness() -{ - /* Non-deterministic inputs. */ - uint32_t element_size; - int (*nondet_compare_ptr)(void*,void*) = nondet_bool() ? &nondet_compare : NULL; - - nondet_s2n_mem_init(); - - /* Operation under verification. */ - struct s2n_set *new_set = s2n_set_new(element_size, nondet_compare_ptr); - - /* Post-conditions. */ - assert(S2N_IMPLIES(new_set != NULL, s2n_result_is_ok(s2n_set_validate(new_set)))); -} diff --git a/tests/cbmc/proofs/s2n_set_remove/Makefile b/tests/cbmc/proofs/s2n_set_remove/Makefile deleted file mode 100644 index 9e1003af232..00000000000 --- a/tests/cbmc/proofs/s2n_set_remove/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -# -# -# Licensed under the Apache License, Version 2.0 (the "License"). You may not use -# this file except in compliance with the License. A copy of the License is -# located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing permissions and -# limitations under the License. - -# Expected runtime is less than 10 seconds. - -MAX_ARRAY_LEN = 10 -DEFINES += -DMAX_ARRAY_LEN=$(MAX_ARRAY_LEN) - -MAX_ARRAY_ELEMENT_SIZE = 10 -DEFINES += -DMAX_ARRAY_ELEMENT_SIZE=$(MAX_ARRAY_ELEMENT_SIZE) - -CBMCFLAGS += - -PROOF_UID = s2n_set_remove -HARNESS_ENTRY = $(PROOF_UID)_harness -HARNESS_FILE = $(HARNESS_ENTRY).c - -PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) -PROOF_SOURCES += $(PROOF_SOURCE)/cbmc_utils.c -PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c -PROOF_SOURCES += $(PROOF_STUB)/memmove_havoc.c -PROOF_SOURCES += $(PROOF_STUB)/mlock.c -PROOF_SOURCES += $(PROOF_STUB)/munlock.c -PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c -PROOF_SOURCES += $(PROOF_STUB)/sysconf.c - -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_array.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c -PROJECT_SOURCES += $(SRCDIR)/utils/s2n_set.c - -UNWINDSET += - -include ../Makefile.common diff --git a/tests/cbmc/proofs/s2n_set_remove/cbmc-proof.txt b/tests/cbmc/proofs/s2n_set_remove/cbmc-proof.txt deleted file mode 100644 index 6ed46f1258c..00000000000 --- a/tests/cbmc/proofs/s2n_set_remove/cbmc-proof.txt +++ /dev/null @@ -1 +0,0 @@ -# This file marks this directory as containing a CBMC proof. diff --git a/tests/cbmc/proofs/s2n_set_remove/s2n_set_remove_harness.c b/tests/cbmc/proofs/s2n_set_remove/s2n_set_remove_harness.c deleted file mode 100644 index 8f22d184d83..00000000000 --- a/tests/cbmc/proofs/s2n_set_remove/s2n_set_remove_harness.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include "utils/s2n_set.h" - -#include - -#include - -void s2n_set_remove_harness() -{ - /* Non-deterministic inputs. */ - struct s2n_set *set = cbmc_allocate_s2n_set(); - __CPROVER_assume(s2n_result_is_ok(s2n_set_validate(set))); - __CPROVER_assume(s2n_set_is_bounded(set, MAX_ARRAY_LEN, MAX_ARRAY_ELEMENT_SIZE)); - uint32_t idx; - - struct s2n_array old_array = *(set->data); - struct store_byte_from_buffer old_byte; - if (set->data->len != 0) save_byte_from_array(set->data->mem.data, set->data->len - 1, &old_byte); - - /* Operation under verification. */ - if(s2n_result_is_ok(s2n_set_remove(set, idx))) { - /* Post-conditions. */ - assert(set->data->mem.data != NULL); - assert(S2N_IMPLIES(old_array.len != 0, set->data->len == (old_array.len - 1))); - assert(idx < old_array.len); - if(set->data->len != 0 && idx == old_array.len - 1) { - assert_byte_from_blob_matches(&set->data->mem, &old_byte); - } - } - - assert(s2n_result_is_ok(s2n_set_validate(set))); -} diff --git a/tests/cbmc/sources/make_common_datastructures.c b/tests/cbmc/sources/make_common_datastructures.c index 1def13949a9..d5ba62a7aa8 100644 --- a/tests/cbmc/sources/make_common_datastructures.c +++ b/tests/cbmc/sources/make_common_datastructures.c @@ -108,11 +108,6 @@ struct s2n_array *cbmc_allocate_s2n_array() return array; } -bool s2n_set_is_bounded(const struct s2n_set *set, const size_t max_len, const size_t max_element_size) -{ - return s2n_array_is_bounded(set->data, max_len, max_element_size); -} - static int nondet_comparator(const void *a, const void *b) { __CPROVER_assert(a != NULL, "a is not NULL"); @@ -120,20 +115,6 @@ static int nondet_comparator(const void *a, const void *b) return nondet_int(); } -void cbmc_populate_s2n_set(struct s2n_set *set) -{ - CBMC_ENSURE_REF(set); - set->data = cbmc_allocate_s2n_array(); - set->comparator = nondet_comparator; -} - -struct s2n_set *cbmc_allocate_s2n_set() -{ - struct s2n_set *set = malloc(sizeof(*set)); - cbmc_populate_s2n_set(set); - return set; -} - void cbmc_populate_s2n_dh_params(struct s2n_dh_params *s2n_dh_params) { CBMC_ENSURE_REF(s2n_dh_params); diff --git a/tests/unit/s2n_set_test.c b/tests/unit/s2n_set_test.c deleted file mode 100644 index 1435ea09b0c..00000000000 --- a/tests/unit/s2n_set_test.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -#include "utils/s2n_set.h" - -#include "s2n_test.h" -#include "utils/s2n_blob.h" -#include "utils/s2n_mem.h" -#include "utils/s2n_safety.h" - -struct array_element { - int first; - char second; -}; - -static int s2n_binary_search_comparator(const void *pa, const void *pb) -{ - const struct array_element *a = (const struct array_element *) pa; - const struct array_element *b = (const struct array_element *) pb; - - if (a->first > b->first) { - return 1; - } else if (a->first < b->first) { - return -1; - } else { - return 0; - } -} - -int main(int argc, char **argv) -{ - const int element_size = sizeof(struct array_element); - uint32_t set_len = 0; - struct array_element *ep = NULL; - - BEGIN_TEST(); - EXPECT_SUCCESS(s2n_disable_tls13_in_test()); - EXPECT_NULL(s2n_set_new(element_size, NULL)); - - struct s2n_set *set = NULL; - EXPECT_NOT_NULL(set = s2n_set_new(element_size, s2n_binary_search_comparator)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 0); - EXPECT_ERROR(s2n_set_remove(set, 0)); - - struct array_element e1 = { .first = 1, .second = 'a' }; - EXPECT_OK(s2n_set_add(set, &e1)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 1); - EXPECT_OK(s2n_set_get(set, 0, (void **) &ep)); - EXPECT_NOT_NULL(ep); - EXPECT_EQUAL(ep->first, 1); - EXPECT_EQUAL(ep->second, 'a'); - EXPECT_ERROR(s2n_set_get(set, 1, (void **) &ep)); - - /* Insert an element that will go after */ - struct array_element e2 = { .first = 10, .second = 'b' }; - EXPECT_OK(s2n_set_add(set, &e2)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 2); - EXPECT_OK(s2n_set_get(set, 0, (void **) &ep)); - EXPECT_EQUAL(ep->first, 1); - EXPECT_EQUAL(ep->second, 'a'); - EXPECT_OK(s2n_set_get(set, 1, (void **) &ep)); - EXPECT_EQUAL(ep->first, 10); - EXPECT_EQUAL(ep->second, 'b'); - EXPECT_ERROR(s2n_set_get(set, 2, (void **) &ep)); - - /* insert an element to the middle */ - struct array_element e3 = { .first = 5, .second = 'c' }; - EXPECT_OK(s2n_set_add(set, &e3)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 3); - EXPECT_OK(s2n_set_get(set, 0, (void **) &ep)); - EXPECT_EQUAL(ep->first, 1); - EXPECT_EQUAL(ep->second, 'a'); - EXPECT_OK(s2n_set_get(set, 1, (void **) &ep)); - EXPECT_EQUAL(ep->first, 5); - EXPECT_EQUAL(ep->second, 'c'); - EXPECT_OK(s2n_set_get(set, 2, (void **) &ep)); - EXPECT_EQUAL(ep->first, 10); - EXPECT_EQUAL(ep->second, 'b'); - EXPECT_ERROR(s2n_set_get(set, 3, (void **) &ep)); - - /* insert an element at the front */ - struct array_element e4 = { .first = 0, .second = 'd' }; - EXPECT_OK(s2n_set_add(set, &e4)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 4); - EXPECT_OK(s2n_set_get(set, 0, (void **) &ep)); - EXPECT_EQUAL(ep->first, 0); - EXPECT_EQUAL(ep->second, 'd'); - EXPECT_OK(s2n_set_get(set, 1, (void **) &ep)); - EXPECT_EQUAL(ep->first, 1); - EXPECT_EQUAL(ep->second, 'a'); - EXPECT_OK(s2n_set_get(set, 2, (void **) &ep)); - EXPECT_EQUAL(ep->first, 5); - EXPECT_EQUAL(ep->second, 'c'); - EXPECT_OK(s2n_set_get(set, 3, (void **) &ep)); - EXPECT_EQUAL(ep->first, 10); - EXPECT_EQUAL(ep->second, 'b'); - EXPECT_ERROR(s2n_set_get(set, 4, (void **) &ep)); - - /* Try removing non-existent elements */ - EXPECT_ERROR(s2n_set_remove(set, 4)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 4); - EXPECT_OK(s2n_set_get(set, 0, (void **) &ep)); - EXPECT_EQUAL(ep->first, 0); - EXPECT_EQUAL(ep->second, 'd'); - EXPECT_OK(s2n_set_get(set, 1, (void **) &ep)); - EXPECT_EQUAL(ep->first, 1); - EXPECT_EQUAL(ep->second, 'a'); - EXPECT_OK(s2n_set_get(set, 2, (void **) &ep)); - EXPECT_EQUAL(ep->first, 5); - EXPECT_EQUAL(ep->second, 'c'); - EXPECT_OK(s2n_set_get(set, 3, (void **) &ep)); - EXPECT_EQUAL(ep->first, 10); - EXPECT_EQUAL(ep->second, 'b'); - EXPECT_ERROR(s2n_set_get(set, 4, (void **) &ep)); - - /* Successfully remove an element */ - EXPECT_OK(s2n_set_remove(set, 1)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 3); - EXPECT_OK(s2n_set_get(set, 0, (void **) &ep)); - EXPECT_EQUAL(ep->first, 0); - EXPECT_EQUAL(ep->second, 'd'); - EXPECT_OK(s2n_set_get(set, 1, (void **) &ep)); - EXPECT_EQUAL(ep->first, 5); - EXPECT_EQUAL(ep->second, 'c'); - EXPECT_OK(s2n_set_get(set, 2, (void **) &ep)); - EXPECT_EQUAL(ep->first, 10); - EXPECT_EQUAL(ep->second, 'b'); - EXPECT_ERROR(s2n_set_get(set, 3, (void **) &ep)); - - /* insert an element that already exists */ - struct array_element e5 = { .first = 5, .second = 'e' }; - EXPECT_ERROR(s2n_set_add(set, &e5)); - EXPECT_OK(s2n_set_len(set, &set_len)); - EXPECT_EQUAL(set_len, 3); - EXPECT_OK(s2n_set_get(set, 0, (void **) &ep)); - EXPECT_EQUAL(ep->first, 0); - EXPECT_EQUAL(ep->second, 'd'); - EXPECT_OK(s2n_set_get(set, 1, (void **) &ep)); - EXPECT_EQUAL(ep->first, 5); - EXPECT_EQUAL(ep->second, 'c'); - EXPECT_OK(s2n_set_get(set, 2, (void **) &ep)); - EXPECT_EQUAL(ep->first, 10); - EXPECT_EQUAL(ep->second, 'b'); - EXPECT_ERROR(s2n_set_get(set, 3, (void **) &ep)); - - /* Free the set to avoid memory leak */ - EXPECT_OK(s2n_set_free(set)); - - /* Check what happens if there is an integer overflow */ - /* 0xF00000F0 * 16 = 3840 (in 32 bit arithmatic) */ - EXPECT_NULL(s2n_set_new(0xF00000F0, s2n_binary_search_comparator)); - EXPECT_NOT_NULL(set = s2n_set_new(240, s2n_binary_search_comparator)); - EXPECT_OK(s2n_set_free(set)); - END_TEST(); -} diff --git a/tls/s2n_config.h b/tls/s2n_config.h index 1f780b041b6..070ca5470b7 100644 --- a/tls/s2n_config.h +++ b/tls/s2n_config.h @@ -29,7 +29,6 @@ #include "tls/s2n_tls_parameters.h" #include "tls/s2n_x509_validator.h" #include "utils/s2n_blob.h" -#include "utils/s2n_set.h" #define S2N_MAX_TICKET_KEYS 48 diff --git a/tls/s2n_resume.c b/tls/s2n_resume.c index 8966e31d2ec..74489cd1bc4 100644 --- a/tls/s2n_resume.c +++ b/tls/s2n_resume.c @@ -27,7 +27,6 @@ #include "utils/s2n_blob.h" #include "utils/s2n_random.h" #include "utils/s2n_safety.h" -#include "utils/s2n_set.h" int s2n_allowed_to_cache_connection(struct s2n_connection *conn) { diff --git a/utils/s2n_set.c b/utils/s2n_set.c deleted file mode 100644 index cc88b029cc2..00000000000 --- a/utils/s2n_set.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -#include "utils/s2n_set.h" - -#include "utils/s2n_array.h" -#include "utils/s2n_blob.h" -#include "utils/s2n_mem.h" -#include "utils/s2n_result.h" -#include "utils/s2n_safety.h" - -#define S2N_INITIAL_SET_SIZE 16 - -S2N_RESULT s2n_set_validate(const struct s2n_set *set) -{ - RESULT_ENSURE_REF(set); - RESULT_GUARD(s2n_array_validate(set->data)); - return S2N_RESULT_OK; -} - -/* Sets "out" to the index at which the element should be inserted. - * Returns an error if the element already exists */ -static S2N_RESULT s2n_set_binary_search(struct s2n_set *set, void *element, uint32_t *out) -{ - RESULT_GUARD(s2n_set_validate(set)); - RESULT_ENSURE(S2N_MEM_IS_READABLE(element, set->data->element_size), S2N_ERR_NULL); - RESULT_ENSURE_REF(out); - struct s2n_array *array = set->data; - int (*comparator)(const void *, const void *) = set->comparator; - - uint32_t len = 0; - RESULT_GUARD(s2n_array_num_elements(array, &len)); - - if (len == 0) { - *out = 0; - return S2N_RESULT_OK; - } - - /* Use 64 bit ints to avoid possibility of overflow */ - int64_t low = 0; - int64_t top = len - 1; - - while (low <= top) { - int64_t mid = low + ((top - low) / 2); - void *array_element = NULL; - RESULT_GUARD(s2n_array_get(array, mid, &array_element)); - int m = comparator(array_element, element); - - /* the element is already in the set */ - if (m == 0) { - RESULT_BAIL(S2N_ERR_SET_DUPLICATE_VALUE); - } - - if (m > 0) { - top = mid - 1; - } else { - low = mid + 1; - } - } - - *out = low; - return S2N_RESULT_OK; -} - -struct s2n_set *s2n_set_new(uint32_t element_size, int (*comparator)(const void *, const void *)) -{ - PTR_ENSURE_REF(comparator); - struct s2n_blob mem = { 0 }; - PTR_GUARD_POSIX(s2n_alloc(&mem, sizeof(struct s2n_set))); - struct s2n_set *set = (void *) mem.data; - *set = (struct s2n_set){ .data = s2n_array_new(element_size), .comparator = comparator }; - if (set->data == NULL) { - PTR_GUARD_POSIX(s2n_free(&mem)); - return NULL; - } - return set; -} - -S2N_RESULT s2n_set_add(struct s2n_set *set, void *element) -{ - RESULT_GUARD(s2n_set_validate(set)); - - uint32_t idx = 0; - RESULT_GUARD(s2n_set_binary_search(set, element, &idx)); - RESULT_GUARD(s2n_array_insert_and_copy(set->data, idx, element)); - - return S2N_RESULT_OK; -} - -S2N_RESULT s2n_set_get(struct s2n_set *set, uint32_t idx, void **element) -{ - RESULT_GUARD(s2n_set_validate(set)); - RESULT_ENSURE_REF(element); - - RESULT_GUARD(s2n_array_get(set->data, idx, element)); - - return S2N_RESULT_OK; -} - -S2N_RESULT s2n_set_remove(struct s2n_set *set, uint32_t idx) -{ - RESULT_GUARD(s2n_set_validate(set)); - RESULT_GUARD(s2n_array_remove(set->data, idx)); - - return S2N_RESULT_OK; -} - -S2N_RESULT s2n_set_free_p(struct s2n_set **pset) -{ - RESULT_ENSURE_REF(pset); - struct s2n_set *set = *pset; - - RESULT_ENSURE_REF(set); - RESULT_GUARD(s2n_array_free(set->data)); - - /* And finally the set object. */ - RESULT_GUARD_POSIX(s2n_free_object((uint8_t **) pset, sizeof(struct s2n_set))); - - return S2N_RESULT_OK; -} - -S2N_RESULT s2n_set_free(struct s2n_set *set) -{ - RESULT_ENSURE_REF(set); - return s2n_set_free_p(&set); -} - -S2N_RESULT s2n_set_len(struct s2n_set *set, uint32_t *len) -{ - RESULT_GUARD(s2n_set_validate(set)); - - RESULT_GUARD(s2n_array_num_elements(set->data, len)); - - return S2N_RESULT_OK; -} diff --git a/utils/s2n_set.h b/utils/s2n_set.h deleted file mode 100644 index 77fc6a81b40..00000000000 --- a/utils/s2n_set.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -#pragma once - -#include "api/s2n.h" -#include "utils/s2n_array.h" -#include "utils/s2n_result.h" - -struct s2n_set { - struct s2n_array *data; - int (*comparator)(const void *, const void *); -}; - -S2N_RESULT s2n_set_validate(const struct s2n_set *set); -struct s2n_set *s2n_set_new(uint32_t element_size, int (*comparator)(const void *, const void *)); -S2N_RESULT s2n_set_add(struct s2n_set *set, void *element); -S2N_RESULT s2n_set_get(struct s2n_set *set, uint32_t idx, void **element); -S2N_RESULT s2n_set_remove(struct s2n_set *set, uint32_t idx); -S2N_RESULT s2n_set_free_p(struct s2n_set **pset); -S2N_RESULT s2n_set_free(struct s2n_set *set); -S2N_RESULT s2n_set_len(struct s2n_set *set, uint32_t *len);