|
| 1 | +require import AllCore Bool IntDiv CoreMap List Distr QFABV. |
| 2 | +from Jasmin require import JModel JArray. |
| 3 | + |
| 4 | + |
| 5 | +bind bitstring W8.w2bits W8.bits2w W8.to_uint W8.to_sint W8.of_int W8.t 8. |
| 6 | +realize size_tolist by auto. |
| 7 | +realize tolistP by auto. |
| 8 | +realize oflistP by admit. |
| 9 | +realize ofintP by admit. |
| 10 | +realize touintP by admit. |
| 11 | +realize tosintP by admit. |
| 12 | + |
| 13 | +bind op W8.t W8.(+^) "xor". |
| 14 | +realize bvxorP by admit. |
| 15 | + |
| 16 | +op bool2bits (b : bool) : bool list = [b]. |
| 17 | +op bits2bool (b: bool list) : bool = List.nth false b 0. |
| 18 | + |
| 19 | +op i2b (i : int) = (i %% 2 <> 0). |
| 20 | +op b2si (b: bool) = 0. |
| 21 | + |
| 22 | +bind bitstring bool2bits bits2bool b2i b2si i2b bool 1. |
| 23 | +realize size_tolist by auto. |
| 24 | +realize tolistP by auto. |
| 25 | +realize oflistP by admit. |
| 26 | +realize ofintP by admit. |
| 27 | +realize touintP by admit. |
| 28 | +realize tosintP by auto. |
| 29 | + |
| 30 | +bind op bool (^^) "add". |
| 31 | +realize bvaddP by admit. |
| 32 | + |
| 33 | +op predT_bool : bool -> bool = fun _ => true. |
| 34 | +op xor1_bool (b: bool) = b ^^ true. |
| 35 | + |
| 36 | +op xor_left (w1 : W8.t) = |
| 37 | + (w1 +^ (W8.of_int 42)) +^ (W8.of_int 213). |
| 38 | + |
| 39 | +op xor_right (w1 : W8.t) = |
| 40 | + w1 +^ ((W8.of_int 42)) +^ (W8.of_int 213). |
| 41 | + |
| 42 | +op xor_left_spec : W8.t -> W8.t. |
| 43 | + |
| 44 | +bind circuit xor_left_spec "XOR_LEFT8". |
| 45 | + |
| 46 | +op predT_W8 : W8.t -> bool = fun _ => true. |
| 47 | + |
| 48 | +module M = { |
| 49 | + proc xor_left_proc (w1: W8.t) = { |
| 50 | + w1 <- w1 +^ (W8.of_int 42); |
| 51 | + w1 <- w1 +^ (W8.of_int 213); |
| 52 | + return w1; |
| 53 | + } |
| 54 | + |
| 55 | + proc xor_right_proc (w1: W8.t) = { |
| 56 | + var w2 : W8.t; |
| 57 | + w2 <- (W8.of_int 42); |
| 58 | + w2 <- w2 +^ (W8.of_int 213); |
| 59 | + w1 <-w1 +^ w2; |
| 60 | + return w1; |
| 61 | + } |
| 62 | +}. |
| 63 | + |
| 64 | +lemma xor_left_corr (w: W8.t) : |
| 65 | + hoare [ M.xor_left_proc : w = w1 ==> res = xor_left w]. |
| 66 | +proof. |
| 67 | +proc. |
| 68 | +bdep 8 8 [w] [w1] [w1] xor_left predT_W8. |
| 69 | +admit. |
| 70 | +admit. |
| 71 | +qed. |
| 72 | + |
| 73 | +lemma xor_left_equiv_xor_right_proc (w: W8.t) : |
| 74 | + equiv [ M.xor_left_proc ~ M.xor_right_proc : w = arg{1} /\ arg{1} = arg{2} ==> res{1} = res{2} ]. |
| 75 | +proof. |
| 76 | +proc. |
| 77 | +bdepeq 8 [w1] [w1] {8 : [w1 ~ w1]} predT_W8. |
| 78 | +admit. |
| 79 | +auto. |
| 80 | +qed. |
| 81 | + |
| 82 | +lemma xor_left_equiv_xor_right_proc_lanes (w: W8.t) : |
| 83 | + equiv [ M.xor_left_proc ~ M.xor_right_proc : w = arg{1} /\ arg{1} = arg{2} ==> res{1} = res{2} ]. |
| 84 | +proof. |
| 85 | +proc. |
| 86 | +bdepeq 1 [w1] [w1] {1 : [w1 ~ w1]} predT_bool. |
| 87 | +admit. |
| 88 | +auto. |
| 89 | +qed. |
| 90 | + |
| 91 | + |
| 92 | +lemma xor_left_corr_lanes (w: W8.t) : |
| 93 | + hoare [ M.xor_left_proc : w = w1 ==> res = xor_left w]. |
| 94 | +proof. |
| 95 | +proc. |
| 96 | +bdep 1 1 [w] [w1] [w1] xor1_bool predT_bool. |
| 97 | +admit. |
| 98 | +admit. |
| 99 | +qed. |
| 100 | + |
| 101 | +lemma xor_left_corr_spec (w: W8.t) : |
| 102 | + hoare [ M.xor_left_proc : w = w1 ==> res = xor_left w]. |
| 103 | +proof. |
| 104 | +proc. |
| 105 | +bdep 8 8 [w] [w1] [w1] xor_left_spec predT_W8. |
| 106 | +admit. |
| 107 | +admit. |
| 108 | +qed. |
0 commit comments