def pick_v

bend-collections-laws-crypto@1.0.0.0 · proofs/crypto/secp256k1/penc.bend:117

import bend-collections-laws-crypto@1.0.0.0/proofs/crypto/secp256k1/penc.bend as Penc
import Base
import bend-collections-laws-crypto@1.0.0.0/spec/crypto/secp256k1/field.bend as FS
import bend-collections-laws-crypto@1.0.0.0/spec/crypto/secp256k1/curve.bend as CV
import bend-collections-laws-crypto@1.0.0.0/src/crypto/secp256k1/limbs.bend as L
import bend-collections-laws-crypto@1.0.0.0/src/crypto/secp256k1/field.bend as F
import bend-collections-laws-crypto@1.0.0.0/proofs/crypto/secp256k1/fieldops.bend as FO
import bend-collections-laws-crypto@1.0.0.0/proofs/crypto/secp256k1/point.bend as PT
import bend-collections-laws-crypto@1.0.0.0/proofs/crypto/secp256k1/sel.bend as PM

117# y or p - y by the parities q and par (both 0 or 1)
118def pick_v(+one: Nat, +h1: {one == 1n : Nat}, q: Nat, par: Nat, +y: List<&2, Nat>, +hq: {Nat.is_lt(q, 2n) == True{} : Bool}, +hp: {Nat.is_lt(par, 2n) == True{} : Bool}, +hy: {PT.red(one, y) == True{} : Bool}) -> {FS.value(one, F.select(Nat.sub(Nat.add(q, par), Nat.mul(Nat.mul(q, par), 2n)), F.neg(y), y)) == CV.pick_if(FS.prime(one), FS.value(one, y), Nat.is_eq(q, par)) : Nat}:
119  match q par:
120    case 0n 0n:
121      %Equal.sym(List<&2, Nat>, L.select(0n, F.neg(y), y), y, PM.sel0(one, 16n, F.neg(y), y, PM.l16(one, F.neg(y), FO.neg_r(one, h1, y, hy)), PM.l16(one, y, hy))) : {FS.value(one, _) == FS.value(one, y) : Nat}
122      {==}
123    case 0n 1n:
124      %Equal.sym(List<&2, Nat>, L.select(1n, F.neg(y), y), F.neg(y), PM.sel1(one, 16n, F.neg(y), y, PM.l16(one, F.neg(y), FO.neg_r(one, h1, y, hy)), PM.l16(one, y, hy))) : {FS.value(one, _) == FS.mneg(FS.prime(one), FS.value(one, y)) : Nat}
125      FO.neg_v(one, h1, y, hy)
126    case 1n 0n:
127      %Equal.sym(List<&2, Nat>, L.select(1n, F.neg(y), y), F.neg(y), PM.sel1(one, 16n, F.neg(y), y, PM.l16(one, F.neg(y), FO.neg_r(one, h1, y, hy)), PM.l16(one, y, hy))) : {FS.value(one, _) == FS.mneg(FS.prime(one), FS.value(one, y)) : Nat}
128      FO.neg_v(one, h1, y, hy)
129    case 1n 1n:
130      %Equal.sym(List<&2, Nat>, L.select(0n, F.neg(y), y), y, PM.sel0(one, 16n, F.neg(y), y, PM.l16(one, F.neg(y), FO.neg_r(one, h1, y, hy)), PM.l16(one, y, hy))) : {FS.value(one, _) == FS.value(one, y) : Nat}
131      {==}
132    case 2n+ +c _:
133      Empty.absurd({FS.value(one, F.select(Nat.sub(Nat.add(2n+c, par), Nat.mul(Nat.mul(2n+c, par), 2n)), F.neg(y), y)) == CV.pick_if(FS.prime(one), FS.value(one, y), Nat.is_eq(2n+c, par)) : Nat}, PM.not01(c, hq))
134    case _ 2n+ +c:
135      Empty.absurd({FS.value(one, F.select(Nat.sub(Nat.add(q, 2n+c), Nat.mul(Nat.mul(q, 2n+c), 2n)), F.neg(y), y)) == CV.pick_if(FS.prime(one), FS.value(one, y), Nat.is_eq(q, 2n+c)) : Nat}, PM.not01(c, hp))

Uses (24)

Used by (1)