46 using EltW =
typename LogicCircuit::EltW;
47 using Elt =
typename LogicCircuit::Elt;
48 using Nat =
typename Field::N;
52 using v8 =
typename LogicCircuit::v8;
53 using v32 =
typename LogicCircuit::v32;
54 static constexpr size_t kIndexBits = 5;
55 static constexpr size_t kMaxSHABlocks = 7;
56 static constexpr size_t kMaxMsoLen = kMaxSHABlocks * 64 - 9;
58 using vind =
typename LogicCircuit::template bitvec<kIndexBits>;
61 using ShaBlockWitness =
typename Flatsha::BlockWitness;
63 const LogicCircuit& lc_;
74 EcdsaWitness dpk_sig_;
76 v8 in_[64 * kMaxSHABlocks];
78 ShaBlockWitness sig_sha_[kMaxSHABlocks];
88 nb_ = lc.template vinput<8>();
91 for (
size_t i = 0; i < 64 * kMaxSHABlocks; ++i) {
92 in_[i] = lc.template vinput<8>();
94 for (
size_t j = 0; j < kMaxSHABlocks; j++) {
104 void input(
const LogicCircuit& lc) {
105 ind = lc.template vinput<8>();
106 len = lc.template vinput<8>();
107 for (
size_t j = 0; j < 32; ++j) {
108 v1[j] = lc.template vinput<8>();
113 EltW repack(
const v8 in[],
size_t ind)
const {
114 EltW h = lc_.konst(0);
115 EltW base = lc_.konst(0x2);
116 for (
size_t i = 0; i < 32; ++i) {
117 for (
size_t j = 0; j < 8; ++j) {
118 auto t = lc_.mul(&h, base);
119 auto tin = lc_.eval(in[ind + i][7 - j]);
120 h = lc_.add(&tin, t);
126 explicit Small(
const LogicCircuit& lc,
const EC& ec,
const Nat& order)
127 : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc) {}
129 void assert_credential(EltW pkX, EltW pkY, EltW hash_tr,
131 const v8 now[],
const Witness& vw)
const {
132 Ecdsa ecc(lc_, ec_, order_);
134 ecc.verify_signature3(pkX, pkY, vw.e_, vw.sig_);
135 ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);
137 sha_.assert_message(kMaxSHABlocks, vw.nb_, vw.in_, vw.sig_sha_);
139 const Memcmp<LogicCircuit> CMP(lc_);
141 lc_.assert1(CMP.leq(kDateLen, &vw.in_[84], &now[0]));
144 lc_.assert1(CMP.leq(kDateLen, &now[0], &vw.in_[92]));
147 EltW dpkx = repack(vw.in_, 100);
148 EltW dpky = repack(vw.in_, 132);
149 lc_.assert_eq(&dpkx, vw.dpkx_);
150 lc_.assert_eq(&dpky, vw.dpky_);
153 const v8 zz = lc_.template vbit<8>(0xff);
154 std::vector<v8> cmp_buf(32);
155 for (
size_t ai = 0; ai < kNumAttr; ++ai) {
156 r_.shift(oa[ai].ind, 32, &cmp_buf[0], kMaxMsoLen, vw.in_, zz, 3);
157 assert_attribute(32, oa[ai].len, &cmp_buf[0], &oa[ai].v1[0]);
164 void assert_attribute(
size_t max,
const v8& vlen,
const v8 got[],
165 const v8 want[])
const {
166 for (
size_t j = 0; j < max; ++j) {
167 auto ll = lc_.vlt(j, vlen);
168 auto cmp = lc_.veq(got[j], want[j]);
169 lc_.assert_implies(&ll, cmp);