-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
320a39a
commit 8b38bc2
Showing
2 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
compiler/examples/jazzline/curve25519/common/add4/add4.jazz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// h = f + g | ||
// h = 2**0*f0 + 2**64*f1 + 2**128*f2 + 2**192*f3 + | ||
// 2**0*g0 + 2**64*g1 + 2**128*g2 + 2**192*g3 | ||
|
||
abstract predicate bool eqmod(int, int, tuple); | ||
abstract predicate tuple single(int); | ||
abstract predicate int b2i(bool); | ||
abstract predicate int u64i(u64); | ||
abstract predicate int pow(int, int); | ||
|
||
inline fn __add4_rrs(reg u64[4] f, stack u64[4] g) -> reg u64[4] | ||
ensures #[prover=cas] { | ||
eqmod ( | ||
\sum (ii \in 0:4) (pow(2, 64*ii)*u64i(result.0[ii])), | ||
\sum (ii \in 0:4) (pow(2, 64*ii)*u64i(f[ii])) + \sum (ii \in 0:4) (pow(2, 64*ii)*u64i(g[ii])), | ||
single((pow(2,255)) - 19) | ||
) | ||
} | ||
{ | ||
inline int i; | ||
|
||
reg u64[4] h; | ||
reg u64 z; | ||
reg bool cf, carryo; | ||
|
||
z = 0; | ||
|
||
for i=0 to 4 { | ||
h[i] = f[i]; | ||
} | ||
|
||
cf, h[0] += g[0]; | ||
|
||
for i=1 to 4 | ||
{ cf, h[i] += g[i] + cf; } | ||
|
||
carryo = cf; | ||
cf, z -= z - cf; | ||
|
||
#[kind=Assert, prover=smt] assert (cf == carryo); | ||
#[kind=Assume, prover=cas] assert (b2i(cf) == b2i(carryo)); | ||
|
||
z &= 38; | ||
|
||
#[kind=Assert, prover=smt] assert ((!cf && z == 0x0) || (cf && z == 0x26)); | ||
#[kind=Assume, prover=cas] assert (u64i(z) == b2i(cf)*0x26); | ||
|
||
cf, h[0] += z; | ||
j | ||
for i=1 to 4 | ||
{ cf, h[i] += 0 + cf;} | ||
|
||
carryo = cf; | ||
cf, z -= z - cf; | ||
|
||
#[kind=Assert, prover=smt] assert (cf == carryo); | ||
#[kind=Assume, prover=cas] assert (b2i(cf) == b2i(carryo)); | ||
|
||
|
||
z &= 38; | ||
|
||
#[kind=Assert, prover=smt] assert ((!cf && z == 0x0) || (cf && z == 0x26)); | ||
#[kind=Assume, prover=cas] assert (u64i(z) == b2i(cf)*0x26); | ||
|
||
|
||
cf, h[0] += z; | ||
|
||
#[kind=Assert, prover=smt] assert (!cf); | ||
#[kind=Assume, prover=cas] assert (b2i(cf) == 0); | ||
|
||
return h; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters