ggm.rs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. // Implementation of CMZ14 credentials (GGM version, which is more
  2. // efficient, but makes a stronger security assumption): "Algebraic MACs
  3. // and Keyed-Verification Anonymous Credentials" (Chase, Meiklejohn,
  4. // and Zaverucha, CCS 2014)
  5. // The notation follows that of the paper "Hyphae: Social Secret
  6. // Sharing" (Lovecruft and de Valence, 2017), Section 4.
  7. // We really want points to be capital letters and scalars to be
  8. // lowercase letters
  9. #![allow(non_snake_case)]
  10. use sha2::Sha512;
  11. use curve25519_dalek::constants as dalek_constants;
  12. use curve25519_dalek::ristretto::RistrettoPoint;
  13. use curve25519_dalek::ristretto::RistrettoBasepointTable;
  14. use curve25519_dalek::scalar::Scalar;
  15. use lazy_static::lazy_static;
  16. lazy_static! {
  17. pub static ref CMZ_A: RistrettoPoint =
  18. RistrettoPoint::hash_from_bytes::<Sha512>(b"CMZ Generator A");
  19. pub static ref CMZ_B: RistrettoPoint =
  20. dalek_constants::RISTRETTO_BASEPOINT_POINT;
  21. pub static ref CMZ_A_TABLE: RistrettoBasepointTable =
  22. RistrettoBasepointTable::create(&CMZ_A);
  23. pub static ref CMZ_B_TABLE: RistrettoBasepointTable =
  24. dalek_constants::RISTRETTO_BASEPOINT_TABLE;
  25. }
  26. #[derive(Clone,Debug)]
  27. pub struct IssuerPrivKey {
  28. x0tilde: Scalar,
  29. x: Vec<Scalar>,
  30. }
  31. impl IssuerPrivKey {
  32. // Create an IssuerPrivKey for credentials with the given number of
  33. // attributes.
  34. pub fn new(n: u16) -> IssuerPrivKey {
  35. let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
  36. let x0tilde: Scalar = Scalar::random(&mut rng);
  37. let mut x: Vec<Scalar> = Vec::with_capacity((n+1) as usize);
  38. // Set x to a vector of n+1 random Scalars
  39. x.resize_with((n+1) as usize, || { Scalar::random(&mut rng) });
  40. IssuerPrivKey { x0tilde, x }
  41. }
  42. }
  43. #[derive(Clone,Debug)]
  44. pub struct IssuerPubKey {
  45. X: Vec<RistrettoPoint>,
  46. }
  47. impl IssuerPubKey {
  48. // Create an IssuerPubKey from the corresponding IssuerPrivKey
  49. pub fn new(privkey: &IssuerPrivKey) -> IssuerPubKey {
  50. let Atable : &RistrettoBasepointTable = &CMZ_A_TABLE;
  51. let Btable : &RistrettoBasepointTable = &CMZ_B_TABLE;
  52. let n_plus_one: usize = privkey.x.len();
  53. let mut X: Vec<RistrettoPoint> = Vec::with_capacity(n_plus_one);
  54. // The first element is a special case; it is
  55. // X[0] = x0tilde*A + x[0]*B
  56. X.push(&privkey.x0tilde * Atable + &privkey.x[0] * Btable);
  57. // The other elements (1 through n) are X[i] = x[i]*A
  58. for i in 1..n_plus_one {
  59. X.push(&privkey.x[i] * Atable);
  60. }
  61. IssuerPubKey { X }
  62. }
  63. }
  64. #[derive(Debug)]
  65. pub struct Issuer {
  66. privkey: IssuerPrivKey,
  67. pub pubkey: IssuerPubKey,
  68. }
  69. impl Issuer {
  70. // Create an issuer for credentials with the given number of
  71. // attributes
  72. pub fn new(n: u16) -> Issuer {
  73. let privkey = IssuerPrivKey::new(n);
  74. let pubkey = IssuerPubKey::new(&privkey);
  75. Issuer { privkey, pubkey }
  76. }
  77. }
  78. #[derive(Debug)]
  79. pub struct Credential5 {
  80. P: RistrettoPoint,
  81. Q: RistrettoPoint,
  82. m1: Scalar,
  83. m2: Scalar,
  84. m3: Scalar,
  85. m4: Scalar,
  86. m5: Scalar,
  87. }
  88. // A submodule for issuing credentials with 5 attributes, none of which
  89. // are blinded to the issuer.
  90. pub mod issue_nonblind_5 {
  91. use curve25519_dalek::ristretto::RistrettoPoint;
  92. use curve25519_dalek::scalar::Scalar;
  93. use curve25519_dalek::traits::IsIdentity;
  94. use zkp::CompactProof;
  95. use zkp::ProofError;
  96. use zkp::Transcript;
  97. use super::{CMZ_A,CMZ_B,Issuer,IssuerPubKey,Credential5};
  98. #[derive(Debug)]
  99. pub struct CredentialRequest {
  100. m1: Scalar,
  101. m2: Scalar,
  102. m3: Scalar,
  103. m4: Scalar,
  104. m5: Scalar,
  105. }
  106. #[derive(Debug)]
  107. pub struct CredentialRequestState {
  108. m1: Scalar,
  109. m2: Scalar,
  110. m3: Scalar,
  111. m4: Scalar,
  112. m5: Scalar,
  113. }
  114. pub struct CredentialResponse {
  115. P: RistrettoPoint,
  116. Q: RistrettoPoint,
  117. piNonblindIssue: CompactProof,
  118. }
  119. define_proof! {
  120. issue,
  121. "Nonblind 5 issuing proof",
  122. (x0, x0tilde, x1, x2, x3, x4, x5),
  123. (P, Q, X0, X1, X2, X3, X4, X5, P1, P2, P3, P4, P5),
  124. (A, B) :
  125. X1 = (x1*A),
  126. X2 = (x2*A),
  127. X3 = (x3*A),
  128. X4 = (x4*A),
  129. X5 = (x5*A),
  130. X0 = (x0*B + x0tilde*A),
  131. Q = (x0*P + x1*P1 + x2*P2 + x3*P3 + x4*P4 + x5*P5)
  132. }
  133. pub fn request(m1: &Scalar, m2: &Scalar, m3: &Scalar,
  134. m4: &Scalar, m5: &Scalar) -> (CredentialRequest,
  135. CredentialRequestState) {
  136. // For nonblind requests, just send the attributes in the clear
  137. (
  138. CredentialRequest {
  139. m1: *m1,
  140. m2: *m2,
  141. m3: *m3,
  142. m4: *m4,
  143. m5: *m5
  144. },
  145. CredentialRequestState {
  146. m1: *m1,
  147. m2: *m2,
  148. m3: *m3,
  149. m4: *m4,
  150. m5: *m5
  151. }
  152. )
  153. }
  154. impl Issuer {
  155. // Issue a credential with (for example) 5 given attributes. In
  156. // this (nonblinded) version, the issuer sees all of the attributes.
  157. pub fn issue_nonblind_5(&self, req: &CredentialRequest)
  158. -> CredentialResponse {
  159. let A : &RistrettoPoint = &CMZ_A;
  160. let B : &RistrettoPoint = &CMZ_B;
  161. let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
  162. let b: Scalar = Scalar::random(&mut rng);
  163. let P: RistrettoPoint = b * B;
  164. // There is a typo in the Hyphae paper: in Section 4.1, Q should
  165. // also have an x0*P term (also in Q'). (You can see that term
  166. // in Section 4.2.)
  167. let Q: RistrettoPoint = (self.privkey.x[0] + (
  168. self.privkey.x[1] * req.m1 +
  169. self.privkey.x[2] * req.m2 +
  170. self.privkey.x[3] * req.m3 +
  171. self.privkey.x[4] * req.m4 +
  172. self.privkey.x[5] * req.m5)) * P;
  173. let mut transcript = Transcript::new(b"Nonblind 5 issuing proof");
  174. let piNonblindIssue: CompactProof = issue::prove_compact(
  175. &mut transcript,
  176. issue::ProveAssignments {
  177. A: &A,
  178. B: &B,
  179. P: &P,
  180. Q: &Q,
  181. X0: &self.pubkey.X[0],
  182. X1: &self.pubkey.X[1],
  183. X2: &self.pubkey.X[2],
  184. X3: &self.pubkey.X[3],
  185. X4: &self.pubkey.X[4],
  186. X5: &self.pubkey.X[5],
  187. P1: &(&req.m1 * &P),
  188. P2: &(&req.m2 * &P),
  189. P3: &(&req.m3 * &P),
  190. P4: &(&req.m4 * &P),
  191. P5: &(&req.m5 * &P),
  192. x0: &self.privkey.x[0],
  193. x1: &self.privkey.x[1],
  194. x2: &self.privkey.x[2],
  195. x3: &self.privkey.x[3],
  196. x4: &self.privkey.x[4],
  197. x5: &self.privkey.x[5],
  198. x0tilde: &self.privkey.x0tilde
  199. }).0;
  200. CredentialResponse { P, Q, piNonblindIssue }
  201. }
  202. }
  203. pub fn verify(state: CredentialRequestState,
  204. resp: CredentialResponse, pubkey: &IssuerPubKey)
  205. -> Result<Credential5, ProofError> {
  206. let A : &RistrettoPoint = &CMZ_A;
  207. let B : &RistrettoPoint = &CMZ_B;
  208. if resp.P.is_identity() {
  209. return Err(ProofError::VerificationFailure);
  210. }
  211. let mut transcript = Transcript::new(b"Nonblind 5 issuing proof");
  212. issue::verify_compact(
  213. &resp.piNonblindIssue,
  214. &mut transcript,
  215. issue::VerifyAssignments {
  216. A: &A.compress(),
  217. B: &B.compress(),
  218. P: &resp.P.compress(),
  219. Q: &resp.Q.compress(),
  220. X0: &pubkey.X[0].compress(),
  221. X1: &pubkey.X[1].compress(),
  222. X2: &pubkey.X[2].compress(),
  223. X3: &pubkey.X[3].compress(),
  224. X4: &pubkey.X[4].compress(),
  225. X5: &pubkey.X[5].compress(),
  226. P1: &(&state.m1 * &resp.P).compress(),
  227. P2: &(&state.m2 * &resp.P).compress(),
  228. P3: &(&state.m3 * &resp.P).compress(),
  229. P4: &(&state.m4 * &resp.P).compress(),
  230. P5: &(&state.m5 * &resp.P).compress(),
  231. }
  232. )?;
  233. Ok(Credential5 {
  234. P: resp.P,
  235. Q: resp.Q,
  236. m1: state.m1,
  237. m2: state.m2,
  238. m3: state.m3,
  239. m4: state.m4,
  240. m5: state.m5,
  241. })
  242. }
  243. }
  244. // A submodule for issuing credentials with 5 attributes, of which
  245. // attributes 1, 2, and 4 are blinded (the issuer does not see them),
  246. // and only attributes 3 and 5 are visible to the issuer.
  247. //
  248. // One might imagine generalizing this submodule using a macro.
  249. // Currently, the number of attributes and the selection of which are
  250. // blinded have to be hardcoded in order to use the very helpful zkp
  251. // proof macros. This shouldn't be a problem in practice, as one
  252. // generally knows the set of statements one will require at compile,
  253. // and not at run, time.
  254. pub mod issue_blind124_5 {
  255. use curve25519_dalek::ristretto::RistrettoPoint;
  256. use curve25519_dalek::ristretto::RistrettoBasepointTable;
  257. use curve25519_dalek::scalar::Scalar;
  258. use curve25519_dalek::traits::IsIdentity;
  259. use zkp::CompactProof;
  260. use zkp::ProofError;
  261. use zkp::Transcript;
  262. use super::{CMZ_A,CMZ_B,CMZ_B_TABLE,Issuer,IssuerPubKey,Credential5};
  263. // Example of a 5-attribute credential where the issuer sees attributes
  264. // 3 and 5, but attributes 1, 2, and 4 are blinded.
  265. pub struct CredentialRequest {
  266. D: RistrettoPoint,
  267. Encm1B: (RistrettoPoint, RistrettoPoint),
  268. Encm2B: (RistrettoPoint, RistrettoPoint),
  269. m3: Scalar,
  270. Encm4B: (RistrettoPoint, RistrettoPoint),
  271. m5: Scalar,
  272. piUserBlinding: CompactProof,
  273. }
  274. #[derive(Debug)]
  275. pub struct CredentialRequestState {
  276. d: Scalar,
  277. D: RistrettoPoint,
  278. Encm1B: (RistrettoPoint, RistrettoPoint),
  279. Encm2B: (RistrettoPoint, RistrettoPoint),
  280. Encm4B: (RistrettoPoint, RistrettoPoint),
  281. m1: Scalar,
  282. m2: Scalar,
  283. m3: Scalar,
  284. m4: Scalar,
  285. m5: Scalar,
  286. }
  287. pub struct CredentialResponse {
  288. P: RistrettoPoint,
  289. EncQ: (RistrettoPoint, RistrettoPoint),
  290. T1: RistrettoPoint,
  291. T2: RistrettoPoint,
  292. T4: RistrettoPoint,
  293. piBlindIssue: CompactProof,
  294. }
  295. // The client-created proof that the blinded attributes in the request
  296. // to issue a credential are well formed. If you want the client to
  297. // prove other statements about the blinded attributes (m1, m2, m4 in
  298. // this example), this is where to add them (and in the code that
  299. // creates and verifies this proof of course).
  300. define_proof! {
  301. userblinding,
  302. "Blind124 5 userblind proof",
  303. (d, e1, e2, e4, m1, m2, m4),
  304. (Encm1B0, Encm1B1, Encm2B0, Encm2B1, Encm4B0, Encm4B1, D),
  305. (B) :
  306. Encm1B0 = (e1*B),
  307. Encm1B1 = (m1*B + e1*D),
  308. Encm2B0 = (e2*B),
  309. Encm2B1 = (m2*B + e2*D),
  310. Encm4B0 = (e4*B),
  311. Encm4B1 = (m4*B + e4*D),
  312. D = (d*B)
  313. }
  314. // The issuer-created proof for the same scenario
  315. define_proof! {
  316. blindissue,
  317. "Blind124 5 issuing proof",
  318. (x0, x0tilde, x1, x2, x3, x4, x5, s, b, t1, t2, t4),
  319. (P, EncQ0, EncQ1, X0, X1, X2, X3, X4, X5, P3, P5, T1, T2, T4, D,
  320. Encm1B0, Encm1B1, Encm2B0, Encm2B1, Encm4B0, Encm4B1),
  321. (A, B) :
  322. X1 = (x1*A),
  323. X2 = (x2*A),
  324. X3 = (x3*A),
  325. X4 = (x4*A),
  326. X5 = (x5*A),
  327. X0 = (x0*B + x0tilde*A),
  328. P = (b*B),
  329. T1 = (b*X1),
  330. T2 = (b*X2),
  331. T4 = (b*X4),
  332. T1 = (t1*A),
  333. T2 = (t2*A),
  334. T4 = (t4*A),
  335. EncQ0 = (s*B + t1*Encm1B0 + t2*Encm2B0 + t4*Encm4B0),
  336. EncQ1 = (s*D + t1*Encm1B1 + t2*Encm2B1 + t4*Encm4B1 +
  337. x0*P + x3*P3 + x5*P5)
  338. }
  339. pub fn request(m1: &Scalar, m2: &Scalar, m3: &Scalar,
  340. m4: &Scalar, m5: &Scalar) -> (CredentialRequest,
  341. CredentialRequestState) {
  342. let B : &RistrettoPoint = &CMZ_B;
  343. let Btable : &RistrettoBasepointTable = &CMZ_B_TABLE;
  344. // Pick an ElGamal keypair
  345. let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
  346. let d: Scalar = Scalar::random(&mut rng);
  347. let D: RistrettoPoint = &d * Btable;
  348. let e1: Scalar = Scalar::random(&mut rng);
  349. let e2: Scalar = Scalar::random(&mut rng);
  350. let e4: Scalar = Scalar::random(&mut rng);
  351. let Encm1B = (&e1 * Btable, m1 * Btable + &e1 * D);
  352. let Encm2B = (&e2 * Btable, m2 * Btable + &e2 * D);
  353. let Encm4B = (&e4 * Btable, m4 * Btable + &e4 * D);
  354. let mut transcript = Transcript::new(b"Blind124 5 userblind proof");
  355. let piUserBlinding: CompactProof = userblinding::prove_compact(
  356. &mut transcript,
  357. userblinding::ProveAssignments {
  358. B: &B,
  359. Encm1B0: &Encm1B.0,
  360. Encm1B1: &Encm1B.1,
  361. Encm2B0: &Encm2B.0,
  362. Encm2B1: &Encm2B.1,
  363. Encm4B0: &Encm4B.0,
  364. Encm4B1: &Encm4B.1,
  365. D: &D,
  366. d: &d,
  367. e1: &e1,
  368. e2: &e2,
  369. e4: &e4,
  370. m1: &m1,
  371. m2: &m2,
  372. m4: &m4,
  373. }).0;
  374. (
  375. CredentialRequest {
  376. D: D,
  377. Encm1B, Encm2B, Encm4B, piUserBlinding,
  378. m3: *m3,
  379. m5: *m5,
  380. },
  381. CredentialRequestState {
  382. d, D, Encm1B, Encm2B, Encm4B,
  383. m1: *m1,
  384. m2: *m2,
  385. m3: *m3,
  386. m4: *m4,
  387. m5: *m5,
  388. }
  389. )
  390. }
  391. impl Issuer {
  392. // Issue a credential with 5 attributes, of which attributes 1, 2,
  393. // and 4 are blinded from the issuer, and 3 and 5 are visible.
  394. pub fn issue_blind124_5(&self, req: &CredentialRequest)
  395. -> Result<CredentialResponse, ProofError> {
  396. let A : &RistrettoPoint = &CMZ_A;
  397. let B : &RistrettoPoint = &CMZ_B;
  398. // First check the proof in the request
  399. let mut transcript = Transcript::new(b"Blind124 5 userblind proof");
  400. userblinding::verify_compact(
  401. &req.piUserBlinding,
  402. &mut transcript,
  403. userblinding::VerifyAssignments {
  404. B: &B.compress(),
  405. Encm1B0: &req.Encm1B.0.compress(),
  406. Encm1B1: &req.Encm1B.1.compress(),
  407. Encm2B0: &req.Encm2B.0.compress(),
  408. Encm2B1: &req.Encm2B.1.compress(),
  409. Encm4B0: &req.Encm4B.0.compress(),
  410. Encm4B1: &req.Encm4B.1.compress(),
  411. D: &req.D.compress(),
  412. }
  413. )?;
  414. // Compute the MAC on the visible attributes
  415. let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
  416. let b: Scalar = Scalar::random(&mut rng);
  417. let P: RistrettoPoint = b * B;
  418. let QHc: RistrettoPoint = (self.privkey.x[0] + (
  419. self.privkey.x[3] * req.m3 +
  420. self.privkey.x[5] * req.m5)) * P;
  421. // El Gamal encrypt it to the public key req.D
  422. let s: Scalar = Scalar::random(&mut rng);
  423. let EncQHc = (s*B, QHc + s*req.D);
  424. // Homomorphically compute the part of the MAC corresponding to
  425. // the blinded attributes
  426. let t1 = self.privkey.x[1] * b;
  427. let T1 = t1 * A;
  428. let EncQ1 = ( t1 * req.Encm1B.0, t1 * req.Encm1B.1 );
  429. let t2 = self.privkey.x[2] * b;
  430. let T2 = t2 * A;
  431. let EncQ2 = ( t2 * req.Encm2B.0, t2 * req.Encm2B.1 );
  432. let t4 = self.privkey.x[4] * b;
  433. let T4 = t4 * A;
  434. let EncQ4 = ( t4 * req.Encm4B.0, t4 * req.Encm4B.1 );
  435. let EncQ = ( EncQHc.0 + EncQ1.0 + EncQ2.0 + EncQ4.0,
  436. EncQHc.1 + EncQ1.1 + EncQ2.1 + EncQ4.1 );
  437. let mut transcript = Transcript::new(b"Blind124 5 issuing proof");
  438. let piBlindIssue: CompactProof = blindissue::prove_compact(
  439. &mut transcript,
  440. blindissue::ProveAssignments {
  441. A: &A,
  442. B: &B,
  443. P: &P,
  444. EncQ0: &EncQ.0,
  445. EncQ1: &EncQ.1,
  446. X0: &self.pubkey.X[0],
  447. X1: &self.pubkey.X[1],
  448. X2: &self.pubkey.X[2],
  449. X3: &self.pubkey.X[3],
  450. X4: &self.pubkey.X[4],
  451. X5: &self.pubkey.X[5],
  452. P3: &(&req.m3 * &P),
  453. P5: &(&req.m5 * &P),
  454. T1: &T1,
  455. T2: &T2,
  456. T4: &T4,
  457. D: &req.D,
  458. Encm1B0: &req.Encm1B.0,
  459. Encm1B1: &req.Encm1B.1,
  460. Encm2B0: &req.Encm2B.0,
  461. Encm2B1: &req.Encm2B.1,
  462. Encm4B0: &req.Encm4B.0,
  463. Encm4B1: &req.Encm4B.1,
  464. x0: &self.privkey.x[0],
  465. x0tilde: &self.privkey.x0tilde,
  466. x1: &self.privkey.x[1],
  467. x2: &self.privkey.x[2],
  468. x3: &self.privkey.x[3],
  469. x4: &self.privkey.x[4],
  470. x5: &self.privkey.x[5],
  471. s: &s,
  472. b: &b,
  473. t1: &t1,
  474. t2: &t2,
  475. t4: &t4
  476. }).0;
  477. Ok(CredentialResponse {
  478. P, EncQ, T1, T2, T4, piBlindIssue
  479. })
  480. }
  481. }
  482. pub fn verify(state: CredentialRequestState,
  483. resp: CredentialResponse, pubkey: &IssuerPubKey)
  484. -> Result<Credential5, ProofError> {
  485. let A : &RistrettoPoint = &CMZ_A;
  486. let B : &RistrettoPoint = &CMZ_B;
  487. if resp.P.is_identity() {
  488. return Err(ProofError::VerificationFailure);
  489. }
  490. let mut transcript = Transcript::new(b"Blind124 5 issuing proof");
  491. blindissue::verify_compact(
  492. &resp.piBlindIssue,
  493. &mut transcript,
  494. blindissue::VerifyAssignments {
  495. A: &A.compress(),
  496. B: &B.compress(),
  497. P: &resp.P.compress(),
  498. EncQ0: &resp.EncQ.0.compress(),
  499. EncQ1: &resp.EncQ.1.compress(),
  500. X0: &pubkey.X[0].compress(),
  501. X1: &pubkey.X[1].compress(),
  502. X2: &pubkey.X[2].compress(),
  503. X3: &pubkey.X[3].compress(),
  504. X4: &pubkey.X[4].compress(),
  505. X5: &pubkey.X[5].compress(),
  506. P3: &(&state.m3 * &resp.P).compress(),
  507. P5: &(&state.m5 * &resp.P).compress(),
  508. T1: &resp.T1.compress(),
  509. T2: &resp.T2.compress(),
  510. T4: &resp.T4.compress(),
  511. D: &state.D.compress(),
  512. Encm1B0: &state.Encm1B.0.compress(),
  513. Encm1B1: &state.Encm1B.1.compress(),
  514. Encm2B0: &state.Encm2B.0.compress(),
  515. Encm2B1: &state.Encm2B.1.compress(),
  516. Encm4B0: &state.Encm4B.0.compress(),
  517. Encm4B1: &state.Encm4B.1.compress(),
  518. }
  519. )?;
  520. // Decrypt EncQ
  521. let Q = &resp.EncQ.1 - (state.d * &resp.EncQ.0);
  522. Ok(Credential5 {
  523. P: resp.P,
  524. Q: Q,
  525. m1: state.m1,
  526. m2: state.m2,
  527. m3: state.m3,
  528. m4: state.m4,
  529. m5: state.m5,
  530. })
  531. }
  532. }