From f5c4671bfbad96bf346bd7e9a21fc4317b4959df Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 3 Dec 2022 17:00:20 +0530 Subject: Adds most of the tools --- .../vlib/crypto/internal/subtle/comparison_test.v | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 v_windows/v/vlib/crypto/internal/subtle/comparison_test.v (limited to 'v_windows/v/vlib/crypto/internal/subtle/comparison_test.v') diff --git a/v_windows/v/vlib/crypto/internal/subtle/comparison_test.v b/v_windows/v/vlib/crypto/internal/subtle/comparison_test.v new file mode 100644 index 0000000..b339746 --- /dev/null +++ b/v_windows/v/vlib/crypto/internal/subtle/comparison_test.v @@ -0,0 +1,65 @@ +module subtle + +fn test_constant_time_byte_eq() { + assert constant_time_byte_eq(0, 0) == 1 + assert constant_time_byte_eq(1, 1) == 1 + assert constant_time_byte_eq(255, 255) == 1 + assert constant_time_byte_eq(255, 1) == 0 + assert constant_time_byte_eq(1, 255) == 0 + assert constant_time_byte_eq(2, 1) == 0 +} + +fn test_constant_time_eq() { + assert constant_time_eq(0, 0) == 1 + assert constant_time_eq(255, 255) == 1 + assert constant_time_eq(65536, 65536) == 1 + assert constant_time_eq(-1, -1) == 1 + assert constant_time_eq(-256, -256) == 1 + assert constant_time_eq(0, 1) == 0 +} + +fn test_constant_time_select() { + assert constant_time_select(1, 1, 0) == 1 + assert constant_time_select(1, 1, 255) == 1 + assert constant_time_select(1, 1, 255 * 255) == 1 + assert constant_time_select(1, 2, 0) == 2 + assert constant_time_select(1, 2, 255) == 2 + assert constant_time_select(1, 2, 255 * 255) == 2 + // + assert constant_time_select(0, 1, 0) == 0 + assert constant_time_select(0, 1, 255) == 255 + assert constant_time_select(0, 1, 255 * 255) == 255 * 255 + assert constant_time_select(0, 2, 0) == 0 + assert constant_time_select(0, 2, 255) == 255 + assert constant_time_select(0, 2, 255 * 255) == 255 * 255 +} + +fn test_constant_time_compare() { + assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3]) == 1 + assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 9]) == 0 + assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3, 4]) == 0 + assert constant_time_compare([byte(1), 2, 3], [byte(1), 2]) == 0 +} + +fn test_constant_time_copy() { + y := [byte(3), 4, 5] + mut x := [byte(0), 0, 0] + constant_time_copy(0, mut x, y) + assert x == [byte(0), 0, 0] + constant_time_copy(1, mut x, y) + assert x == y + assert x == [byte(3), 4, 5] +} + +fn test_constant_time_less_or_eq() { + assert constant_time_less_or_eq(1, 1) == 1 + assert constant_time_less_or_eq(1, 2) == 1 + assert constant_time_less_or_eq(1, 3) == 1 + assert constant_time_less_or_eq(255, 255) == 1 + assert constant_time_less_or_eq(255, 256) == 1 + assert constant_time_less_or_eq(255, 257) == 1 + assert constant_time_less_or_eq(1, 0) == 0 + assert constant_time_less_or_eq(2, 1) == 0 + assert constant_time_less_or_eq(3, 2) == 0 + assert constant_time_less_or_eq(255, 3) == 0 +} -- cgit v1.2.3