migration.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*! A module for the protocol for the user to migrate from one bucket to
  2. another (and possibly also change trust level).
  3. For the case of migrating from trust level 0 (a one-bridge bucket) to
  4. trust level 1 (a three-bridge bucket), the user presents their current
  5. Lox credential:
  6. - id: revealed
  7. - bucket: blinded
  8. - trust_level: revealed to be 0
  9. - level_since: blinded
  10. - invites_remaining: revealed to be 0
  11. - invites_issued: revealed to be 0
  12. and a Migration credential:
  13. - id: revealed as the same as the Lox credential id above
  14. - from_bucket: blinded, but proved in ZK that it's the same as the
  15. bucket in the Lox credential above
  16. - to_bucket: blinded
  17. and a new Lox credential to be issued:
  18. - id: jointly chosen by the user and BA
  19. - bucket: blinded, but proved in ZK that it's the same as the to_bucket
  20. in the Migration credential above
  21. - trust_level: 1
  22. - level_since: today
  23. - invites_remaining: 0
  24. - invites_issued: 0
  25. */
  26. use curve25519_dalek::ristretto::RistrettoBasepointTable;
  27. use curve25519_dalek::ristretto::RistrettoPoint;
  28. use curve25519_dalek::scalar::Scalar;
  29. use curve25519_dalek::traits::IsIdentity;
  30. use zkp::CompactProof;
  31. use zkp::ProofError;
  32. use zkp::Transcript;
  33. use super::super::cred;
  34. use super::super::dup_filter::SeenType;
  35. use super::super::{BridgeAuth, IssuerPubKey};
  36. use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
  37. pub struct Request {
  38. // Fields for blind showing the Lox credential
  39. // We don't need to include invites_remaining or invites_issued,
  40. // since they must be 0
  41. P_lox: RistrettoPoint,
  42. id: Scalar,
  43. CBucket: RistrettoPoint,
  44. trust_level: Scalar,
  45. CSince: RistrettoPoint,
  46. CQ_lox: RistrettoPoint,
  47. // Fields for blind showing the Migration credential
  48. P_mig: RistrettoPoint,
  49. CFromBucket: RistrettoPoint,
  50. CToBucket: RistrettoPoint,
  51. CQ_mig: RistrettoPoint,
  52. // Fields for user blinding of the Lox credential to be issued
  53. D: RistrettoPoint,
  54. EncIdClient: (RistrettoPoint, RistrettoPoint),
  55. EncBucket: (RistrettoPoint, RistrettoPoint),
  56. // The combined ZKP
  57. piUser: CompactProof,
  58. }
  59. #[derive(Debug)]
  60. pub struct State {
  61. d: Scalar,
  62. D: RistrettoPoint,
  63. EncIdClient: (RistrettoPoint, RistrettoPoint),
  64. EncBucket: (RistrettoPoint, RistrettoPoint),
  65. id_client: Scalar,
  66. to_bucket: Scalar,
  67. }
  68. pub struct Response {
  69. // The new attributes; trust_level = 1 is implicit
  70. level_since: Scalar,
  71. // The fields for the new Lox credential
  72. P: RistrettoPoint,
  73. EncQ: (RistrettoPoint, RistrettoPoint),
  74. id_server: Scalar,
  75. TId: RistrettoPoint,
  76. TBucket: RistrettoPoint,
  77. // The fields for the implicit noop migration ("nm") credential
  78. P_nm: RistrettoPoint,
  79. EncQ_nm: (RistrettoPoint, RistrettoPoint),
  80. TId_nm: RistrettoPoint,
  81. TBucket_nm: RistrettoPoint,
  82. // The ZKP
  83. piBlindIssue: CompactProof,
  84. }
  85. define_proof! {
  86. requestproof,
  87. "Migration Request",
  88. (bucket, since, zbucket, zsince, negzQ_lox,
  89. tobucket, zfrombucket, ztobucket, negzQ_mig,
  90. d, eid_client, ebucket, id_client),
  91. (P_lox, CBucket, CSince, V_lox, Xbucket, Xsince,
  92. P_mig, CFromBucket, CToBucket, V_mig, Xfrombucket, Xtobucket,
  93. D, EncIdClient0, EncIdClient1, EncBucket0, EncBucket1),
  94. (A, B):
  95. // Blind showing of the Lox credential
  96. CBucket = (bucket*P_lox + zbucket*A),
  97. CSince = (since*P_lox + zsince*A),
  98. V_lox = (zbucket*Xbucket + zsince*Xsince + negzQ_lox*A),
  99. // Blind showing of the Migration credential; note the use of the
  100. // same "bucket" secret variable
  101. CFromBucket = (bucket*P_mig + zfrombucket*A),
  102. CToBucket = (tobucket*P_mig + ztobucket*A),
  103. V_mig = (zfrombucket*Xfrombucket + ztobucket*Xtobucket + negzQ_mig*A),
  104. // User blinding of the Lox credential to be issued; note the use of
  105. // the same "tobucket" secret variable
  106. EncIdClient0 = (eid_client*B),
  107. EncIdClient1 = (id_client*B + eid_client*D),
  108. EncBucket0 = (ebucket*B),
  109. EncBucket1 = (tobucket*B + ebucket*D),
  110. D = (d*B)
  111. }
  112. define_proof! {
  113. blindissue,
  114. "Migration Blind Issuing",
  115. (x0, x0tilde, xid, xbucket, xlevel, xsince, s, b, tid, tbucket,
  116. x0_nm, x0tilde_nm, xid_nm, xfrom_nm, xto_nm, s_nm, b_nm, tid_nm, tbucket_nm),
  117. (P, EncQ0, EncQ1, X0, Xid, Xbucket, Xlevel, Xsince, Plevel, Psince, TId, TBucket,
  118. P_nm, EncQ0_nm, EncQ1_nm, X0_nm, Xid_nm, Xfrom_nm, Xto_nm,
  119. TId_nm, TBucket_nm,
  120. D, EncId0, EncId1, EncBucket0, EncBucket1),
  121. (A, B):
  122. Xid = (xid*A),
  123. Xlevel = (xlevel*A),
  124. Xbucket = (xbucket*A),
  125. Xsince = (xsince*A),
  126. X0 = (x0*B + x0tilde*A),
  127. P = (b*B),
  128. TId = (b*Xid),
  129. TId = (tid*A),
  130. TBucket = (b*Xbucket),
  131. TBucket = (tbucket*A),
  132. EncQ0 = (s*B + tid*EncId0 + tbucket*EncBucket0),
  133. EncQ1 = (s*D + tid*EncId1 + tbucket*EncBucket1 + x0*P + xlevel*Plevel + xsince*Psince),
  134. Xid_nm = (xid_nm*A),
  135. Xfrom_nm = (xfrom_nm*A),
  136. Xto_nm = (xto_nm*A),
  137. X0_nm = (x0_nm*B + x0tilde_nm*A),
  138. P_nm = (b_nm*B),
  139. TId_nm = (b_nm*Xid_nm),
  140. TId_nm = (tid_nm*A),
  141. TBucket_nm = (b_nm*Xfrom_nm + b_nm*Xto_nm),
  142. TBucket_nm = (tbucket_nm*A),
  143. EncQ0_nm = (s_nm*B + tid_nm*EncId0 + tbucket_nm*EncBucket0),
  144. EncQ1_nm = (s_nm*D + tid_nm*EncId1 + tbucket_nm*EncBucket1 + x0_nm*P_nm)
  145. }
  146. pub fn request(
  147. lox_cred: &cred::Lox,
  148. migration_cred: &cred::Migration,
  149. lox_pub: &IssuerPubKey,
  150. migration_pub: &IssuerPubKey,
  151. ) -> Result<(Request, State), ProofError> {
  152. let A: &RistrettoPoint = &CMZ_A;
  153. let B: &RistrettoPoint = &CMZ_B;
  154. let Atable: &RistrettoBasepointTable = &CMZ_A_TABLE;
  155. let Btable: &RistrettoBasepointTable = &CMZ_B_TABLE;
  156. // Ensure that the credenials can be correctly shown; that is, the
  157. // ids match and the Lox credential bucket matches the Migration
  158. // credential from_bucket
  159. if lox_cred.id != migration_cred.lox_id || lox_cred.bucket != migration_cred.from_bucket {
  160. return Err(ProofError::VerificationFailure);
  161. }
  162. // We only support migrating from trust level 0 to trust level 1
  163. // right now
  164. if lox_cred.trust_level != Scalar::zero() {
  165. return Err(ProofError::VerificationFailure);
  166. }
  167. // Blind showing the Lox credential
  168. // Reblind P and Q
  169. let mut rng = rand::thread_rng();
  170. let t_lox = Scalar::random(&mut rng);
  171. let P_lox = t_lox * lox_cred.P;
  172. let Q_lox = t_lox * lox_cred.Q;
  173. // Form Pedersen commitments to the blinded attributes
  174. let zbucket = Scalar::random(&mut rng);
  175. let zsince = Scalar::random(&mut rng);
  176. let CBucket = lox_cred.bucket * P_lox + &zbucket * Atable;
  177. let CSince = lox_cred.level_since * P_lox + &zsince * Atable;
  178. // Form a Pedersen commitment to the MAC Q
  179. // We flip the sign of zQ from that of the Hyphae paper so that
  180. // the ZKP has a "+" instead of a "-", as that's what the zkp
  181. // macro supports.
  182. let negzQ_lox = Scalar::random(&mut rng);
  183. let CQ_lox = Q_lox - &negzQ_lox * Atable;
  184. // Compute the "error factor"
  185. let V_lox = zbucket * lox_pub.X[2] + zsince * lox_pub.X[4] + &negzQ_lox * Atable;
  186. // Blind showing the Migration credential
  187. // Reblind P and Q
  188. let t_mig = Scalar::random(&mut rng);
  189. let P_mig = t_mig * migration_cred.P;
  190. let Q_mig = t_mig * migration_cred.Q;
  191. // Form Pedersen commitments to the blinded attributes
  192. let zfrombucket = Scalar::random(&mut rng);
  193. let ztobucket = Scalar::random(&mut rng);
  194. let CFromBucket = migration_cred.from_bucket * P_mig + &zfrombucket * Atable;
  195. let CToBucket = migration_cred.to_bucket * P_mig + &ztobucket * Atable;
  196. // Form a Pedersen commitment to the MAC Q
  197. // We flip the sign of zQ from that of the Hyphae paper so that
  198. // the ZKP has a "+" instead of a "-", as that's what the zkp
  199. // macro supports.
  200. let negzQ_mig = Scalar::random(&mut rng);
  201. let CQ_mig = Q_mig - &negzQ_mig * Atable;
  202. // Compute the "error factor"
  203. let V_mig =
  204. zfrombucket * migration_pub.X[2] + ztobucket * migration_pub.X[3] + &negzQ_mig * Atable;
  205. // User blinding for the Lox certificate to be issued
  206. // Pick an ElGamal keypair
  207. let d = Scalar::random(&mut rng);
  208. let D = &d * Btable;
  209. // Pick a random client component of the id
  210. let id_client = Scalar::random(&mut rng);
  211. // Encrypt it (times the basepoint B) to the ElGamal public key D we
  212. // just created
  213. let eid_client = Scalar::random(&mut rng);
  214. let EncIdClient = (&eid_client * Btable, &id_client * Btable + eid_client * D);
  215. // Encrypt the bucket field (times B) to D as well
  216. let ebucket = Scalar::random(&mut rng);
  217. let EncBucket = (
  218. &ebucket * Btable,
  219. &migration_cred.to_bucket * Btable + ebucket * D,
  220. );
  221. // Construct the proof
  222. let mut transcript = Transcript::new(b"migration request");
  223. let piUser = requestproof::prove_compact(
  224. &mut transcript,
  225. requestproof::ProveAssignments {
  226. A: &A,
  227. B: &B,
  228. P_lox: &P_lox,
  229. CBucket: &CBucket,
  230. CSince: &CSince,
  231. V_lox: &V_lox,
  232. Xbucket: &lox_pub.X[2],
  233. Xsince: &lox_pub.X[4],
  234. P_mig: &P_mig,
  235. CFromBucket: &CFromBucket,
  236. CToBucket: &CToBucket,
  237. V_mig: &V_mig,
  238. Xfrombucket: &migration_pub.X[2],
  239. Xtobucket: &migration_pub.X[3],
  240. D: &D,
  241. EncIdClient0: &EncIdClient.0,
  242. EncIdClient1: &EncIdClient.1,
  243. EncBucket0: &EncBucket.0,
  244. EncBucket1: &EncBucket.1,
  245. bucket: &lox_cred.bucket,
  246. since: &lox_cred.level_since,
  247. zbucket: &zbucket,
  248. zsince: &zsince,
  249. negzQ_lox: &negzQ_lox,
  250. tobucket: &migration_cred.to_bucket,
  251. zfrombucket: &zfrombucket,
  252. ztobucket: &ztobucket,
  253. negzQ_mig: &negzQ_mig,
  254. d: &d,
  255. eid_client: &eid_client,
  256. ebucket: &ebucket,
  257. id_client: &id_client,
  258. },
  259. )
  260. .0;
  261. Ok((
  262. Request {
  263. P_lox,
  264. id: lox_cred.id,
  265. CBucket,
  266. trust_level: lox_cred.trust_level,
  267. CSince,
  268. CQ_lox,
  269. P_mig,
  270. CFromBucket,
  271. CToBucket,
  272. CQ_mig,
  273. D,
  274. EncIdClient,
  275. EncBucket,
  276. piUser,
  277. },
  278. State {
  279. d,
  280. D,
  281. EncIdClient,
  282. EncBucket,
  283. id_client,
  284. to_bucket: migration_cred.to_bucket,
  285. },
  286. ))
  287. }
  288. impl BridgeAuth {
  289. /// Receive a migration request
  290. pub fn handle_migration(&mut self, req: Request) -> Result<Response, ProofError> {
  291. let A: &RistrettoPoint = &CMZ_A;
  292. let B: &RistrettoPoint = &CMZ_B;
  293. let Atable: &RistrettoBasepointTable = &CMZ_A_TABLE;
  294. let Btable: &RistrettoBasepointTable = &CMZ_B_TABLE;
  295. if req.P_lox.is_identity() || req.P_mig.is_identity() {
  296. return Err(ProofError::VerificationFailure);
  297. }
  298. // We only currently support migrating from trust level 0
  299. if req.trust_level != Scalar::zero() {
  300. return Err(ProofError::VerificationFailure);
  301. }
  302. // Recompute the "error factors" using knowledge of our own
  303. // (the issuer's) private key instead of knowledge of the
  304. // hidden attributes
  305. let Vprime_lox = (self.lox_priv.x[0]
  306. + self.lox_priv.x[1] * req.id
  307. + self.lox_priv.x[3] * req.trust_level)
  308. * req.P_lox
  309. + self.lox_priv.x[2] * req.CBucket
  310. + self.lox_priv.x[4] * req.CSince
  311. - req.CQ_lox;
  312. let Vprime_mig = (self.migration_priv.x[0] + self.migration_priv.x[1] * req.id) * req.P_mig
  313. + self.migration_priv.x[2] * req.CFromBucket
  314. + self.migration_priv.x[3] * req.CToBucket
  315. - req.CQ_mig;
  316. // Verify the ZKP
  317. let mut transcript = Transcript::new(b"migration request");
  318. requestproof::verify_compact(
  319. &req.piUser,
  320. &mut transcript,
  321. requestproof::VerifyAssignments {
  322. A: &A.compress(),
  323. B: &B.compress(),
  324. P_lox: &req.P_lox.compress(),
  325. CBucket: &req.CBucket.compress(),
  326. CSince: &req.CSince.compress(),
  327. V_lox: &Vprime_lox.compress(),
  328. Xbucket: &self.lox_pub.X[2].compress(),
  329. Xsince: &self.lox_pub.X[4].compress(),
  330. P_mig: &req.P_mig.compress(),
  331. CFromBucket: &req.CFromBucket.compress(),
  332. CToBucket: &req.CToBucket.compress(),
  333. V_mig: &Vprime_mig.compress(),
  334. Xfrombucket: &self.migration_pub.X[2].compress(),
  335. Xtobucket: &self.migration_pub.X[3].compress(),
  336. D: &req.D.compress(),
  337. EncIdClient0: &req.EncIdClient.0.compress(),
  338. EncIdClient1: &req.EncIdClient.1.compress(),
  339. EncBucket0: &req.EncBucket.0.compress(),
  340. EncBucket1: &req.EncBucket.1.compress(),
  341. },
  342. )?;
  343. // Ensure the id has not been seen before, and add it to the
  344. // seen list.
  345. if self.id_filter.filter(&req.id) == SeenType::Seen {
  346. return Err(ProofError::VerificationFailure);
  347. }
  348. // Blind issuing of the new Lox credential
  349. // Choose a random server id component to add to the client's
  350. // (blinded) id component
  351. let mut rng = rand::thread_rng();
  352. let id_server = Scalar::random(&mut rng);
  353. let EncId = (req.EncIdClient.0, req.EncIdClient.1 + &id_server * Btable);
  354. // Create the trust_level attrubute (Scalar), which will be
  355. // level 1
  356. let trust_level: Scalar = Scalar::one();
  357. // Create the level_since attribute (Scalar), which is today's
  358. // Julian date
  359. let level_since: Scalar = self.today().into();
  360. // The invitations_remaining and invitations_issued attributes
  361. // are 0 for level 0 and level 1 Lox credentials, so we don't
  362. // need to explicitly create them.
  363. // Compute the MAC on the visible attributes
  364. let b = Scalar::random(&mut rng);
  365. let P = &b * Btable;
  366. // invites_remaining = invites_issued = 0
  367. let QHc = (self.lox_priv.x[0]
  368. + self.lox_priv.x[3] * trust_level
  369. + self.lox_priv.x[4] * level_since)
  370. * P;
  371. // El Gamal encrypt it to the public key req.D
  372. let s = Scalar::random(&mut rng);
  373. let EncQHc = (&s * Btable, QHc + s * req.D);
  374. // Homomorphically compute the part of the MAC corresponding to
  375. // the blinded attributes
  376. let tid = self.lox_priv.x[1] * b;
  377. let TId = &tid * Atable;
  378. let EncQId = (tid * EncId.0, tid * EncId.1);
  379. let tbucket = self.lox_priv.x[2] * b;
  380. let TBucket = &tbucket * Atable;
  381. let EncQBucket = (tbucket * req.EncBucket.0, tbucket * req.EncBucket.1);
  382. let EncQ = (
  383. EncQHc.0 + EncQId.0 + EncQBucket.0,
  384. EncQHc.1 + EncQId.1 + EncQBucket.1,
  385. );
  386. // Now the no-op migration credential
  387. // Compute the MAC on the visible attributes (none here)
  388. let b_nm = Scalar::random(&mut rng);
  389. let P_nm = &b_nm * Btable;
  390. let QHc_nm = (self.migration_priv.x[0]) * P_nm;
  391. // El Gamal encrypt it to the public key req.D
  392. let s_nm = Scalar::random(&mut rng);
  393. let EncQHc_nm = (&s_nm * Btable, QHc_nm + s_nm * req.D);
  394. // Homomorphically compute the part of the MAC corresponding to
  395. // the blinded attributes
  396. let tid_nm = self.migration_priv.x[1] * b_nm;
  397. let TId_nm = &tid_nm * Atable;
  398. let EncQId_nm = (tid_nm * EncId.0, tid_nm * EncId.1);
  399. let tbucket_nm = (self.migration_priv.x[2] + self.migration_priv.x[3]) * b_nm;
  400. let TBucket_nm = &tbucket_nm * Atable;
  401. let EncQBucket_nm = (tbucket_nm * req.EncBucket.0, tbucket_nm * req.EncBucket.1);
  402. let EncQ_nm = (
  403. EncQHc_nm.0 + EncQId_nm.0 + EncQBucket_nm.0,
  404. EncQHc_nm.1 + EncQId_nm.1 + EncQBucket_nm.1,
  405. );
  406. let mut transcript = Transcript::new(b"migration issuing");
  407. let piBlindIssue = blindissue::prove_compact(
  408. &mut transcript,
  409. blindissue::ProveAssignments {
  410. A: &A,
  411. B: &B,
  412. P: &P,
  413. EncQ0: &EncQ.0,
  414. EncQ1: &EncQ.1,
  415. X0: &self.lox_pub.X[0],
  416. Xid: &self.lox_pub.X[1],
  417. Xbucket: &self.lox_pub.X[2],
  418. Xlevel: &self.lox_pub.X[3],
  419. Xsince: &self.lox_pub.X[4],
  420. Plevel: &(trust_level * P),
  421. Psince: &(level_since * P),
  422. TId: &TId,
  423. TBucket: &TBucket,
  424. P_nm: &P_nm,
  425. EncQ0_nm: &EncQ_nm.0,
  426. EncQ1_nm: &EncQ_nm.1,
  427. X0_nm: &self.migration_pub.X[0],
  428. Xid_nm: &self.migration_pub.X[1],
  429. Xfrom_nm: &self.migration_pub.X[2],
  430. Xto_nm: &self.migration_pub.X[3],
  431. TId_nm: &TId_nm,
  432. TBucket_nm: &TBucket_nm,
  433. D: &req.D,
  434. EncId0: &EncId.0,
  435. EncId1: &EncId.1,
  436. EncBucket0: &req.EncBucket.0,
  437. EncBucket1: &req.EncBucket.1,
  438. x0: &self.lox_priv.x[0],
  439. x0tilde: &self.lox_priv.x0tilde,
  440. xid: &self.lox_priv.x[1],
  441. xbucket: &self.lox_priv.x[2],
  442. xlevel: &self.lox_priv.x[3],
  443. xsince: &self.lox_priv.x[4],
  444. s: &s,
  445. b: &b,
  446. tid: &tid,
  447. tbucket: &tbucket,
  448. x0_nm: &self.migration_priv.x[0],
  449. x0tilde_nm: &self.migration_priv.x0tilde,
  450. xid_nm: &self.migration_priv.x[1],
  451. xfrom_nm: &self.migration_priv.x[2],
  452. xto_nm: &self.migration_priv.x[3],
  453. s_nm: &s_nm,
  454. b_nm: &b_nm,
  455. tid_nm: &tid_nm,
  456. tbucket_nm: &tbucket_nm,
  457. },
  458. )
  459. .0;
  460. Ok(Response {
  461. level_since,
  462. P,
  463. EncQ,
  464. id_server,
  465. TId,
  466. TBucket,
  467. P_nm,
  468. EncQ_nm,
  469. TId_nm,
  470. TBucket_nm,
  471. piBlindIssue,
  472. })
  473. }
  474. }
  475. /// Handle the response to the request, producing the new Lox credential
  476. /// if successful.
  477. pub fn handle_response(
  478. state: State,
  479. resp: Response,
  480. lox_pub: &IssuerPubKey,
  481. migration_pub: &IssuerPubKey,
  482. ) -> Result<cred::Lox, ProofError> {
  483. let A: &RistrettoPoint = &CMZ_A;
  484. let B: &RistrettoPoint = &CMZ_B;
  485. let Btable: &RistrettoBasepointTable = &CMZ_B_TABLE;
  486. if resp.P.is_identity() || resp.P_nm.is_identity() {
  487. return Err(ProofError::VerificationFailure);
  488. }
  489. // Add the server's contribution to the id to our own, both in plain
  490. // and encrypted form
  491. let id = state.id_client + resp.id_server;
  492. let EncId = (
  493. state.EncIdClient.0,
  494. state.EncIdClient.1 + &resp.id_server * Btable,
  495. );
  496. // Verify the proof
  497. let mut transcript = Transcript::new(b"migration issuing");
  498. blindissue::verify_compact(
  499. &resp.piBlindIssue,
  500. &mut transcript,
  501. blindissue::VerifyAssignments {
  502. A: &A.compress(),
  503. B: &B.compress(),
  504. P: &resp.P.compress(),
  505. EncQ0: &resp.EncQ.0.compress(),
  506. EncQ1: &resp.EncQ.1.compress(),
  507. X0: &lox_pub.X[0].compress(),
  508. Xid: &lox_pub.X[1].compress(),
  509. Xbucket: &lox_pub.X[2].compress(),
  510. Xlevel: &lox_pub.X[3].compress(),
  511. Xsince: &lox_pub.X[4].compress(),
  512. // The new trust level is 1
  513. Plevel: &(Scalar::one() * resp.P).compress(),
  514. Psince: &(resp.level_since * resp.P).compress(),
  515. TId: &resp.TId.compress(),
  516. TBucket: &resp.TBucket.compress(),
  517. P_nm: &resp.P_nm.compress(),
  518. EncQ0_nm: &resp.EncQ_nm.0.compress(),
  519. EncQ1_nm: &resp.EncQ_nm.1.compress(),
  520. X0_nm: &migration_pub.X[0].compress(),
  521. Xid_nm: &migration_pub.X[1].compress(),
  522. Xfrom_nm: &migration_pub.X[2].compress(),
  523. Xto_nm: &migration_pub.X[3].compress(),
  524. TId_nm: &resp.TId_nm.compress(),
  525. TBucket_nm: &resp.TBucket_nm.compress(),
  526. D: &state.D.compress(),
  527. EncId0: &EncId.0.compress(),
  528. EncId1: &EncId.1.compress(),
  529. EncBucket0: &state.EncBucket.0.compress(),
  530. EncBucket1: &state.EncBucket.1.compress(),
  531. },
  532. )?;
  533. // Decrypt EncQ
  534. let Q = resp.EncQ.1 - (state.d * resp.EncQ.0);
  535. // Decrypt EncQ_nm
  536. let Q_nm = resp.EncQ_nm.1 - (state.d * resp.EncQ_nm.0);
  537. Ok(cred::Lox {
  538. P: resp.P,
  539. Q,
  540. id,
  541. bucket: state.to_bucket,
  542. trust_level: Scalar::one(),
  543. level_since: resp.level_since,
  544. invites_remaining: Scalar::zero(),
  545. invites_issued: Scalar::zero(),
  546. P_noopmigration: resp.P_nm,
  547. Q_noopmigration: Q_nm,
  548. })
  549. }