Skip to main content

COSAC: COmpact and Scalable Arbitrary-Centered Discrete Gaussian Sampling over Integers

  • Conference paper
  • First Online:
Post-Quantum Cryptography (PQCrypto 2020)

Part of the book series: Lecture Notes in Computer Science ((LNSC,volume 12100))

Included in the following conference series:

Abstract

The arbitrary-centered discrete Gaussian sampler is a fundamental subroutine in implementing lattice trapdoor sampling algorithms. However, existing approaches typically rely on either a fast implementation of another discrete Gaussian sampler or pre-computations with regards to some specific discrete Gaussian distributions with fixed centers and standard deviations. These approaches may only support sampling from standard deviations within a limited range, or cannot efficiently sample from arbitrary standard deviations determined on-the-fly at run-time.

In this paper, we propose a compact and scalable rejection sampling algorithm by sampling from a continuous normal distribution and performing rejection sampling on rounded samples. Our scheme does not require pre-computations related to any specific discrete Gaussian distributions. Our scheme can sample from both arbitrary centers and arbitrary standard deviations determined on-the-fly at run-time. In addition, we show that our scheme only requires a low number of trials close to 2 per sample on average, and our scheme maintains good performance when scaling up the standard deviation. We also provide a concrete error analysis of our scheme based on the Rényi divergence. We implement our sampler and analyse its performance in terms of storage and speed compared to previous results. Our sampler’s running time is center-independent and is therefore applicable to implementation of convolution-style lattice trapdoor sampling and identity-based encryption resistant against timing side-channel attacks.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 89.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 119.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    One may employ different implementations for different \(\sigma \), similar to the implementation of Falcon.

  2. 2.

    https://github.com/lbibe/code.

  3. 3.

    Our implementation is available at https://github.com/raykzhao/gaussian_ac.

  4. 4.

    Here we compare the performance with our center-independent run-time implementation because the implementation in [17] is constant-time.

References

  1. Aumasson, J.P.: Guidelines for low-level cryptography software (2019). https://github.com/veorq/cryptocoding. Accessed 28 Jan 2020

  2. Bai, S., Langlois, A., Lepoint, T., Stehlé, D., Steinfeld, R.: Improved security proofs in lattice-based cryptography: using the Rényi divergence rather than the statistical distance. In: Iwata, T., Cheon, J.H. (eds.) ASIACRYPT 2015. LNCS, vol. 9452, pp. 3–24. Springer, Heidelberg (2015). https://doi.org/10.1007/978-3-662-48797-6_1

    Chapter  MATH  Google Scholar 

  3. Bert, P., Fouque, P.-A., Roux-Langlois, A., Sabt, M.: Practical implementation of ring-SIS/LWE based signature and IBE. In: Lange, T., Steinwandt, R. (eds.) PQCrypto 2018. LNCS, vol. 10786, pp. 271–291. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-79063-3_13

    Chapter  Google Scholar 

  4. Devroye, L.: Non-Uniform Random Variate Generation. Springer, New York (1986). https://doi.org/10.1007/978-1-4613-8643-8

    Book  MATH  Google Scholar 

  5. Du, Y., Wei, B., Zhang, H.: A rejection sampling algorithm for off-centered discrete Gaussian distributions over the integers. Sci. China Inf. Sci. 62(3), 39103:1–39103:3 (2019)

    Article  MathSciNet  Google Scholar 

  6. Ducas, L., Durmus, A., Lepoint, T., Lyubashevsky, V.: Lattice signatures and bimodal Gaussians. In: Canetti, R., Garay, J.A. (eds.) CRYPTO 2013. LNCS, vol. 8042, pp. 40–56. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-40041-4_3

    Chapter  Google Scholar 

  7. Ducas, L., Lyubashevsky, V., Prest, T.: Efficient identity-based encryption over NTRU lattices. In: Sarkar, P., Iwata, T. (eds.) ASIACRYPT 2014. LNCS, vol. 8874, pp. 22–41. Springer, Heidelberg (2014). https://doi.org/10.1007/978-3-662-45608-8_2

    Chapter  Google Scholar 

  8. Ducas, L., Nguyen, P.Q.: Faster gaussian lattice sampling using lazy floating-point arithmetic. In: Wang, X., Sako, K. (eds.) ASIACRYPT 2012. LNCS, vol. 7658, pp. 415–432. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-34961-4_26

    Chapter  Google Scholar 

  9. Fog, A.: VCL C++ vector class library. www.agner.org/optimize/vectorclass.pdf. Accessed 01 Aug 2019

  10. Gentry, C., Peikert, C., Vaikuntanathan, V.: Trapdoors for hard lattices and new cryptographic constructions. In: STOC, pp. 197–206. ACM (2008)

    Google Scholar 

  11. Hülsing, A., Lange, T., Smeets, K.: Rounded Gaussians. In: Abdalla, M., Dahab, R. (eds.) PKC 2018. LNCS, vol. 10770, pp. 728–757. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-76581-5_25

    Chapter  Google Scholar 

  12. Karney, C.F.F.: Sampling exactly from the normal distribution. ACM Trans. Math. Softw. 42(1), 3:1–3:14 (2016)

    Article  MathSciNet  Google Scholar 

  13. Knuth, D., Yao, A.: Algorithms and Complexity: New Directions and Recent Results, chap. The complexity of nonuniform random number generation. Academic Press, Cambridge (1976)

    Google Scholar 

  14. Aguilar-Melchor, C., Albrecht, M.R., Ricosset, T.: Sampling from arbitrary centered discrete gaussians for lattice-based cryptography. In: Gollmann, D., Miyaji, A., Kikuchi, H. (eds.) ACNS 2017. LNCS, vol. 10355, pp. 3–19. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-61204-1_1

    Chapter  Google Scholar 

  15. Melchor, C.A., Ricosset, T.: CDT-based Gaussian sampling: From multi to double precision. IEEE Trans. Comput. 67(11), 1610–1621 (2018)

    MathSciNet  MATH  Google Scholar 

  16. Micciancio, D., Peikert, C.: Trapdoors for lattices: simpler, tighter, faster, smaller. In: Pointcheval, D., Johansson, T. (eds.) EUROCRYPT 2012. LNCS, vol. 7237, pp. 700–718. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-29011-4_41

    Chapter  Google Scholar 

  17. Micciancio, D., Walter, M.: Gaussian sampling over the integers: efficient, generic, constant-time. In: Katz, J., Shacham, H. (eds.) CRYPTO 2017. LNCS, vol. 10402, pp. 455–485. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-63715-0_16

    Chapter  Google Scholar 

  18. Peikert, C.: An efficient and parallel Gaussian sampler for lattices. In: Rabin, T. (ed.) CRYPTO 2010. LNCS, vol. 6223, pp. 80–97. Springer, Heidelberg (2010). https://doi.org/10.1007/978-3-642-14623-7_5

    Chapter  Google Scholar 

  19. Prest, T.: Sharper bounds in lattice-based cryptography using the Rényi divergence. In: Takagi, T., Peyrin, T. (eds.) ASIACRYPT 2017. LNCS, vol. 10624, pp. 347–374. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-70694-8_13

    Chapter  Google Scholar 

  20. Prest, T., et al.: Falcon: fast-fourier lattice-based compact signatures over NTRU. https://falcon-sign.info/ (2017). Accessed 31 Oct 2018

  21. Prest, T., Ricosset, T., Rossi, M.: Simple, fast and constant-time Gaussian sampling over the integers for Falcon. In: Second PQC Standardization Conference. https://csrc.nist.gov/CSRC/media/Events/Second-PQC-Standardization-Conference/documents/accepted-papers/rossi-simple-fast-constant.pdf (2019). Accessed 13 Aug 2019

  22. Thomas, D.B., Luk, W., Leong, P.H.W., Villasenor, J.D.: Gaussian random number generators. ACM Comput. Surv. 39(4), 11 (2007)

    Article  Google Scholar 

  23. von Neumann, J.: Various techniques used in connection with random digits. In: Householder, A., Forsythe, G., Germond, H. (eds.) Monte Carlo Method, pp. 36–38 (1951). National Bureau of Standards Applied Mathematics Series, 12, Washington, D.C.: U.S. Government Printing Office

    Google Scholar 

  24. Walter, M.: Private communication (2020). Accessed 29 Jan 2020

    Google Scholar 

  25. Zhang, Z., Chen, C., Hoffstein, J., Whyte, W.: NIST PQ submission: pqNTRUSign a modular lattice signature scheme (2017). https://www.onboardsecurity.com/nist-post-quantum-crypto-submission. Accessed 01 Aug 2019

  26. Zhao, R.K., Steinfeld, R., Sakzad, A.: FACCT: fast, compact, and constant-time discrete Gaussian sampler over integers. IEEE Trans. Comput. 69(1), 126–137 (2020)

    Article  Google Scholar 

Download references

Acknowledgments

Ron Steinfeld was supported in part by ARC Discovery Project grant DP180102199.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Raymond K. Zhao .

Editor information

Editors and Affiliations

Appendices

A Precision Analysis

To avoid sampling a uniformly random real r with high absolute precisions at rejection steps 11 and 23 in Algorithm 2, and step 4 in Algorithm 3, we adapt the comparison approach similar to [26]. Assume an IEEE-754 floating-point value \(f\in (0,1)\) with \((\delta _{f}+1)\)-bit precision is represented by \(f=\left( 1+mantissa\cdot 2^{-\delta _{f}}\right) \cdot 2^{exponent}\), where integer mantissa has \(\delta _{f}\) bits and \(exponent\in \mathbb {Z}^{-}\). To check \(r<f\), one can sample \(r_{m}\hookleftarrow \mathcal {U}\left( \{0,1\}^{\delta _{f}+1}\right) \), \(r_{e}\hookleftarrow \mathcal {U}\left( \{0,1\}^{l}\right) \), and check \(r_{m}<mantissa+2^{\delta _{f}}\) and \(r_{e}<2^{l+exponent+1}\) instead for some l such that \(l+exponent+1\ge 0\).

Here we analyse the precision requirement of \(r_e\). We have the following theorem for the worst-case acceptance rate in Algorithm 2:

Theorem 5

Assume \(x\in [-\tau ,\tau ]\) and \(y\in [-\tau \sigma -1,\tau \sigma +1]\). In worst case, step 11 in Algorithm 2 has the acceptance rate:

$$\begin{aligned} p_1\ge \exp \left( -\frac{\left( -2\tau \sigma +c_{F}-3/2\right) \left( c_{F}-3/2\right) }{2\sigma ^2}\right) , \end{aligned}$$

and step 23 in Algorithm 2 has the acceptance rate:

$$\begin{aligned} p_2\ge \exp \left( -\frac{\left( 2\tau \sigma +c_{F}+3/2\right) \left( c_{F}+3/2\right) }{2\sigma ^2}\right) . \end{aligned}$$

Proof

For \(b=0\) and \(y\le -1/2\), we have the acceptance rate \(p_1=\exp \left( -Y_1/\left( 2\sigma ^2\right) \right) \) at step 11 in Algorithm 2 where:

$$\begin{aligned} Y_1&=\left( \lfloor y\rceil +c_{F}\right) ^2-\left( y+1\right) ^2 \\&= \left( y+\delta +c_{F}\right) ^2-\left( y+1\right) ^2 \quad (\lfloor y\rceil =y+\delta \text { where } \delta \in [-1/2,1/2]) \\&= \left( 2y+\delta +c_{F}+1\right) \left( \delta +c_{F}-1\right) \\&\le \left( -2\tau \sigma +c_{F}-3/2\right) \left( c_{F}-3/2\right) . \quad \text {(when }\delta =-1/2 \text { and }y=-\tau \sigma -1) \end{aligned}$$

Similarly, for \(b=1\) and \(y\ge 1/2\), we have the acceptance rate \(p_2=\exp \left( -Y_2/\left( 2\sigma ^2\right) \right) \) at step 23 in Algorithm 2 where:

$$\begin{aligned} Y_2&=\left( \lfloor y\rceil +c_{F}\right) ^2-\left( y-1\right) ^2 \\&= \left( y+\delta +c_{F}\right) ^2-\left( y-1\right) ^2 \quad (\lfloor y\rceil =y+\delta \text { where }\delta \in [-1/2,1/2]) \\&= \left( 2y+\delta +c_{F}-1\right) \left( \delta +c_{F}+1\right) \\&\le \left( 2\tau \sigma +c_{F}+3/2\right) \left( c_{F}+3/2\right) . \quad \text {(when }\delta =1/2\text { and }y=\tau \sigma +1) \end{aligned}$$

   \(\square \)

Let \(\varDelta \le 1/2\) be the maximum relative error of the right hand side computations at rejection steps 11 and 23 in Algorithm 2, and step 4 in Algorithm 3. For \(\exp \left( -Y_1/\left( 2\sigma ^2\right) \right) \) at step 11 in Algorithm 2, we have:

$$\begin{aligned}&exponent_{1} \ge \left\lfloor \log _2\left( (1-\varDelta )\cdot \exp \left( -\frac{Y_1}{2\sigma ^2}\right) \right) \right\rfloor \\&\ge \left\lfloor -1-\frac{\left( -2\tau \sigma +c_{F}-3/2\right) \left( c_{F}-3/2\right) }{2\sigma ^2}\cdot \log _{2}e\right\rfloor \quad \text {(by Thm. 5 and }\varDelta \le 1/2) \\&\ge \left\lfloor -1-\frac{2\tau \sigma +2}{\sigma ^2}\cdot \log _{2}e\right\rfloor . \quad \text {(when }c_{F}=-1/2) \end{aligned}$$

Similarly, for \(\exp \left( -Y_2/\left( 2\sigma ^2\right) \right) \) at step 23 in Algorithm 2, we have:

$$\begin{aligned}&exponent_{2} \ge \left\lfloor \log _2\left( (1-\varDelta )\cdot \exp \left( -\frac{Y_2}{2\sigma ^2}\right) \right) \right\rfloor \\&\ge \left\lfloor -1-\frac{\left( 2\tau \sigma +c_{F}+3/2\right) \left( c_{F}+3/2\right) }{2\sigma ^2}\cdot \log _{2}e\right\rfloor \quad \text {(by Thm. 5 and }\varDelta \le 1/2) \\&\ge \left\lfloor -1-\frac{2\tau \sigma +2}{\sigma ^2}\cdot \log _{2}e\right\rfloor . \quad \text {(when }c_{F}=1/2) \end{aligned}$$

For \(\exp \left( -c_{F}^2/\left( 2\sigma ^2\right) \right) /S\) at step 4 in Algorithm 3, we have:

$$\begin{aligned}&exponent_{3} \ge \left\lfloor \log _2\left( (1-\varDelta )\cdot \exp \left( -\frac{c_{F}^2}{2\sigma ^2}\right) /S\right) \right\rfloor \\&\ge \left\lfloor -1-\frac{1}{8\sigma ^2}\cdot \log _{2}e-\log _{2}\left( \sigma \sqrt{2\pi }\right) \right\rfloor . \quad \text {(when }c_{F}=\pm 1/2 \text { and }\varDelta \le 1/2) \end{aligned}$$

Therefore, we have:

$$\begin{aligned} exponent\ge \min \left\{ \left\lfloor -1-\frac{2\tau \sigma +2}{\sigma ^2}\cdot \log _{2}e\right\rfloor , \left\lfloor -1-\frac{1}{8\sigma ^2}\cdot \log _{2}e-\log _{2}\left( \sigma \sqrt{2\pi }\right) \right\rfloor \right\} . \end{aligned}$$

Since the probability \(\mathrm {Pr}\left[ -\tau \le x\le \tau \right] =\text {erf}\left( \tau /\sqrt{2}\right) \) for \(x\hookleftarrow \mathcal {N}(0,1)\), to ensure \(1-\mathrm {Pr}\left[ -\tau \le x\le \tau \right] \le 2^{-\lambda }\), we need \(\tau \ge \sqrt{2}\cdot \text {erf}^{-1}\left( 1-2^{-\lambda }\right) \). Therefore, for \(\lambda =128\) and \(\sigma \in \left[ 2,2^{20}\right] \), we have \(\tau \ge 13.11\), \(exponent\ge -23\), and thus \(l\ge 22\), i.e. \(r_e\) needs to have at least 22 bits.

B Proof of Algorithm 1

Since Algorithm 1 was an exercise in [4] without solutions, here we provide a brief proof of Algorithm 1.

Normalisation Factor. By definition, we have the normalisation factor:

$$\begin{aligned} \frac{1}{c}&=\sum _{k\in \mathbb {Z}}\exp \left( -\frac{\left( |k|+1/2\right) ^2}{2\sigma ^2}\right) \\&=\sum _{k\in \mathbb {Z}^-}\exp \left( -\frac{\left( k-1/2\right) ^2}{2\sigma ^2}\right) +\exp \left( -\frac{1}{8\sigma ^2}\right) +\sum _{k\in \mathbb {Z}^+}\exp \left( -\frac{\left( k+1/2\right) ^2}{2\sigma ^2}\right) \\&=\rho _{1/2,\sigma }\left( \mathbb {Z}^-\right) +\rho _{-1/2,\sigma }\left( \mathbb {Z}^+\right) +\exp \left( -\frac{1}{8\sigma ^2}\right) \\&\ge \frac{1-\epsilon }{1+\epsilon }\cdot \rho _{\sigma }\left( \mathbb {Z}\right) +\exp \left( -\frac{1}{8\sigma ^2}\right) -2. \quad \text {(By Lemma 1)} \end{aligned}$$

Correctness. Let \(z_0=\lfloor x\rceil \). We have \(Y=\left( \left| z_0\right| +1/2\right) ^2-x^2\ge 0\) for any \(x\in \mathbb {R}\). Therefore, the rejection condition \(\exp \left( -Y/\left( 2\sigma ^2\right) \right) \in \left( 0,1\right] \). We have the output distribution:

$$\begin{aligned} \mathrm {Pr}\left[ z=z_0\right]&\propto \int _{z_0-1/2}^{z_0+1/2} \exp \left( -\frac{x^2}{2\sigma ^2}\right) \cdot \exp \left( -\frac{\left( \left| z_0\right| +1/2\right) ^2-x^2}{2\sigma ^2}\right) \,\mathrm {d}x \\&=\int _{z_0-1/2}^{z_0+1/2} \exp \left( -\frac{\left( \left| z_0\right| +1/2\right) ^2}{2\sigma ^2}\right) \,\mathrm {d}x=\exp \left( -\frac{\left( \left| z_0\right| +1/2\right) ^2}{2\sigma ^2}\right) . \end{aligned}$$

Rejection Rate. By definition, we have the output probability density function \(f(x)=c\cdot \exp \left( -\frac{\left( |\lfloor x\rceil |+1/2\right) ^2}{2\sigma ^2}\right) \) and the input probability density function \(g(x)=\rho _{\sigma }\left( x\right) /\left( \sigma \sqrt{2\pi }\right) \). The expected number of trials can be written as:

$$\begin{aligned} M=\max \frac{f(x)}{g(x)}=\max \left( \frac{\exp \left( -\frac{\left( |\lfloor x\rceil |+1/2\right) ^2}{2\sigma ^2}\right) }{\rho _{\sigma }\left( x\right) }\cdot \frac{\sigma \sqrt{2\pi }}{1/c}\right) . \end{aligned}$$

We have:

$$\begin{aligned} \frac{\exp \left( -\frac{\left( |\lfloor x\rceil |+1/2\right) ^2}{2\sigma ^2}\right) }{\rho _{\sigma }\left( x\right) }=\frac{\exp \left( -\frac{\left( |\lfloor x\rceil |+1/2\right) ^2}{2\sigma ^2}\right) }{\exp \left( -\frac{x^2}{2\sigma ^2}\right) }=\exp \left( -\frac{\left( |\lfloor x\rceil |+1/2\right) ^2-x^2}{2\sigma ^2}\right) \le 1. \end{aligned}$$

Therefore,

$$\begin{aligned} M\le \frac{\sigma \sqrt{2\pi }}{1/c}&\le \frac{\sigma \sqrt{2\pi }}{\frac{1-\epsilon }{1+\epsilon }\cdot \rho _{\sigma }\left( \mathbb {Z}\right) +\exp \left( -\frac{1}{8\sigma ^2}\right) -2} \\&\le \frac{\sigma \sqrt{2\pi }}{\frac{1-\epsilon }{1+\epsilon }\cdot \left( \sigma \sqrt{2\pi }-1\right) +\exp \left( -\frac{1}{8\sigma ^2}\right) -2}, \end{aligned}$$

where the second inequality follows from the inequality of 1/c and the third inequality follows from the fact that \(\rho _{\sigma }\left( \mathbb {Z}\right) \ge \sigma \sqrt{2\pi }-1\). Thus, we have the rejection probability:

$$\begin{aligned} 1-\frac{1}{M}\le \frac{\left( 1-\frac{1-\epsilon }{1+\epsilon }\right) \cdot \sigma \sqrt{2\pi }+\frac{1-\epsilon }{1+\epsilon }-\exp \left( -\frac{1}{8\sigma ^2}\right) +2}{\sigma \sqrt{2\pi }} \approx \frac{3-\exp \left( -\frac{1}{8\sigma ^2}\right) }{\sigma \sqrt{2\pi }}\le \frac{2}{\sigma }\sqrt{\frac{2}{\pi }}, \end{aligned}$$

when \(\epsilon \) is small.

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Zhao, R.K., Steinfeld, R., Sakzad, A. (2020). COSAC: COmpact and Scalable Arbitrary-Centered Discrete Gaussian Sampling over Integers. In: Ding, J., Tillich, JP. (eds) Post-Quantum Cryptography. PQCrypto 2020. Lecture Notes in Computer Science(), vol 12100. Springer, Cham. https://doi.org/10.1007/978-3-030-44223-1_16

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-44223-1_16

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-44222-4

  • Online ISBN: 978-3-030-44223-1

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics