Skip to content

Commit d180bb2

Browse files
author
Christopher Wagner
committed
Incorporated comments.
1 parent 6697057 commit d180bb2

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

tests/cbmc/proofs/s2n_safety_constant_time_equals/Makefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111
# implied. See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
# Expected runtime is 60 seconds.
1514

16-
CBMCFLAGS +=
15+
# Expected runtime is 40 seconds.
1716
MAX_ARR_LEN = 10
1817
DEFINES += -DMAX_ARR_LEN=$(MAX_ARR_LEN)
1918

20-
DEPENDENCIES += $(HELPERDIR)/source/cbmc_utils.c
21-
DEPENDENCIES += $(HELPERDIR)/source/make_common_datastructures.c
22-
DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c
23-
DEPENDENCIES += $(SRCDIR)/stuffer/s2n_stuffer.c
24-
DEPENDENCIES += $(SRCDIR)/utils/s2n_blob.c
25-
DEPENDENCIES += $(SRCDIR)/utils/s2n_ensure.c
26-
DEPENDENCIES += $(SRCDIR)/utils/s2n_mem.c
27-
DEPENDENCIES += $(SRCDIR)/utils/s2n_safety.c
19+
CBMCFLAGS +=
20+
21+
HARNESS_ENTRY = s2n_safety_constant_time_equals_harness
22+
HARNESS_FILE = $(HARNESS_ENTRY).c
23+
24+
PROOF_SOURCES += $(HARNESS_FILE)
25+
PROOF_SOURCES += $(PROOF_SOURCE)/cbmc_utils.c
26+
PROOF_SOURCES += $(PROOF_SOURCE)/make_common_datastructures.c
27+
PROOF_SOURCES += $(PROOF_SOURCE)/proof_allocators.c
2828

29-
ENTRY = s2n_safety_constant_time_equals_harness
29+
PROJECT_SOURCES += $(SRCDIR)/stuffer/s2n_stuffer.c
30+
PROJECT_SOURCES += $(SRCDIR)/utils/s2n_blob.c
31+
PROJECT_SOURCES += $(SRCDIR)/utils/s2n_ensure.c
32+
PROJECT_SOURCES += $(SRCDIR)/utils/s2n_mem.c
33+
PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c
3034

3135
# We abstract these functions because manual inspection demonstrates they are unreachable.
3236
REMOVE_FUNCTION_BODY += --remove-function-body s2n_blob_slice

tests/cbmc/proofs/s2n_safety_constant_time_equals/s2n_safety_constant_time_equals_harness.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
*/
1515

1616
#include "api/s2n.h"
17-
#include "stuffer/s2n_stuffer.h"
1817
#include "utils/s2n_safety.h"
1918

2019
#include <sys/param.h>
2120
#include <assert.h>
2221

2322
#include <cbmc_proof/cbmc_utils.h>
24-
#include <cbmc_proof/make_common_datastructures.h>
2523
#include <cbmc_proof/proof_allocators.h>
2624

2725
void s2n_safety_constant_time_equals_harness() {
@@ -40,10 +38,7 @@ void s2n_safety_constant_time_equals_harness() {
4038
__CPROVER_assume(S2N_IMPLIES(len != 0, a != NULL && b != NULL));
4139

4240
/* Check logical equivalence of s2n_constant_time_equals against element equality */
43-
bool result = s2n_constant_time_equals(a, b, len);
44-
if(result) {
41+
if(s2n_constant_time_equals(a, b, len)) {
4542
assert(__CPROVER_forall {size_t i; (i >=0 && i < len) ==> (a[i] == b[i])});
46-
}/* else {
47-
assert(__CPROVER_exists {size_t i; (i >= 0 && i < len) && (a[i] != b[i])}));
48-
}*/
43+
}
4944
}

utils/s2n_safety.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ pid_t s2n_actual_getpid()
5555
* Returns:
5656
* Whether all bytes in arrays "a" and "b" are identical
5757
*/
58-
bool s2n_constant_time_equals(const uint8_t * a, const uint8_t * b, uint32_t len)
58+
bool s2n_constant_time_equals(const uint8_t * a, const uint8_t * b, const uint32_t len)
5959
{
6060
S2N_PUBLIC_INPUT(a);
6161
S2N_PUBLIC_INPUT(b);
6262
S2N_PUBLIC_INPUT(len);
6363

64+
PRECONDITION_POSIX(len == 0 || a != NULL && b != NULL);
65+
6466
uint8_t xor = 0;
6567
for (int i = 0; i < len; i++) {
6668
/* Invariants must hold for each execution of the loop

utils/s2n_safety.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ int s2n_in_unit_test_set(bool newval);
307307
extern pid_t s2n_actual_getpid();
308308

309309
/* Returns 1 if a and b are equal, in constant time */
310-
extern bool s2n_constant_time_equals(const uint8_t * a, const uint8_t * b, uint32_t len);
310+
extern bool s2n_constant_time_equals(const uint8_t * a, const uint8_t * b, const uint32_t len);
311311

312312
/* Copy src to dst, or don't copy it, in constant time */
313313
extern int s2n_constant_time_copy_or_dont(uint8_t * dst, const uint8_t * src, uint32_t len, uint8_t dont);

0 commit comments

Comments
 (0)