def verify_rs

bend-collections-laws-crypto@1.0.0.0 · spec/crypto/secp256k1/ecdsa.bend:165

import bend-collections-laws-crypto@1.0.0.0/spec/crypto/secp256k1/ecdsa.bend as Ecdsa
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

165# u1 = e s^-1, u2 = r s^-1, R = [u1] G + [u2] Q; valid when R is not the
166# point at infinity and x(R) mod n = r
167def verify_rs(+one: Nat, +q: CV.SPoint, +e: Nat, +r: Nat, +s: Nat) -> Bool:
168  +m = n(one)
169  +w = FS.minv(m, s)
170  +rr = CV.padd(p(one), CV.pmul(p(one), FS.mmul(m, e, w), CV.g(one)), CV.pmul(p(one), FS.mmul(m, r, w), q))
171  Bool.and(Bool.not(CV.is_inf(rr)), Nat.is_eq(Nat.mod(CV.aff_x(CV.to_affine(p(one), rr)), m), r))

Uses (17)

Used by (2)