def bytes_okb

bend-collections-laws-crypto@1.0.0.0 · proofs/crypto/curve25519/limbs.bend:115

import bend-collections-laws-crypto@1.0.0.0/proofs/crypto/curve25519/limbs.bend as Limbs
import Base
import bend-collections-laws-crypto@1.0.0.0/spec/crypto/curve25519/field.bend as FS
import bend-collections-laws-crypto@1.0.0.0/proofs/lib/nat.bend as N
import bend-collections-laws-crypto@1.0.0.0/proofs/lib/logic.bend as L

115# the spec's tight (bytes_ok 32: limbs below 256) is okb 32 with bound 255
116def bytes_okb(+n: Nat, +xs: List<&2, U32>, +e: {FS.bytes_ok(n, xs) == True{} : Bool}) -> {okb(n, xs, 255n) == True{} : Bool}:
117  match n xs:
118    case 0n Nil{}:
119      {==}
120    case 0n Con{y, yt}:
121      Empty.absurd({okb(0n, Con{y, yt}, 255n) == True{} : Bool}, L.false_true(e))
122    case 1n+m Nil{}:
123      Empty.absurd({okb(1n+m, Nil{}, 255n) == True{} : Bool}, L.false_true(e))
124    case 1n+ +m Con{+y, +yt}:
125      +h = L.and_left(Nat.is_lt(v(y), 256n), FS.bytes_ok(m, yt), e)
126      +t = L.and_right(Nat.is_lt(v(y), 256n), FS.bytes_ok(m, yt), e)
127      L.and_intro(Nat.is_le(v(y), 255n), okb(m, yt, 255n), N.lt_succ_le(v(y), 255n, h), bytes_okb(m, yt, t))

Uses (15)

Used by (3)