Skip to main content

Automated Detection of Instruction Cache Leaks in Modular Exponentiation Software

  • Conference paper
  • First Online:
Book cover Smart Card Research and Advanced Applications (CARDIS 2016)

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

Abstract

The shared instruction cache of modern processors is an established side-channel that allows adversaries to observe the execution flow of other applications. This has been shown to be a threat to cryptographic software whose execution flow depends on the processed secrets. Testing implementations for these dependencies, or leaks, is essential to develop protected cryptographic software. In this work, we present an automated testing methodology that allows to detect execution flow leaks in implementations of modular exponentiation, a key operation in schemes like RSA, ElGamal, and Diffie-Hellman. We propose a simple and effective leakage test that captures problematic properties of vulnerable exponentiation algorithms. The execution flow of an implementation is directly monitored during exponentiation using a dynamic binary instrumentation framework. This allows to efficiently detect leaking code with instruction-level granularity in a noiseless and controlled environment. As a practical demonstration, we test multiple RSA implementations of modern cryptographic libraries with the proposed methodology. It reliably detects leaking code in vulnerable implementations and also identifies leaks in a protected implementation that are non-trivial to spot in a code review. We present a fix for these leaks and strongly recommend to also patch the other implementations. Because instruction cache attacks have been shown to be a threat in practice, it seems advisable to integrate an automated leakage test in the software release process of cryptographic libraries.

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 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.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.

    To facilitate the integration, the source code used in this work can be obtained from https://github.com/Fraunhofer-AISEC/cache-leak-detector.

References

  1. Acıiçmez, O.: Yet another microarchitectural attack: exploiting i-cache. In: Proceedings of the 2007 ACM Workshop on Computer Security Architecture, CSAW 2007, pp. 11–18. ACM (2007)

    Google Scholar 

  2. Acıiçmez, O., Brumley, B.B., Grabher, P.: New results on instruction cache attacks. In: Mangard, S., Standaert, F.-X. (eds.) CHES 2010. LNCS, vol. 6225, pp. 110–124. Springer, Heidelberg (2010). doi:10.1007/978-3-642-15031-9_8

    Chapter  Google Scholar 

  3. ARM Limited: mbed TLS (2016). https://tls.mbed.org/

  4. Barthe, G., Betarte, G., Campo, J., Luna, C., Pichardie, D.: System-level non-interference for constant-time cryptography. In: Proceedings of the 2014 ACM SIGSAC Conference on Computer and Communications Security, CCS 2014, pp. 1267–1279. ACM, New York (2014)

    Google Scholar 

  5. Chen, C., Wang, T., Kou, Y., Chen, X., Li, X.: Improvement of trace-driven i-cache timing attack on the RSA algorithm. J. Syst. Softw. 86(1), 100–107 (2013)

    Article  Google Scholar 

  6. Coron, J.-S.: Resistance against differential power analysis for elliptic curve cryptosystems. In: Koç, Ç.K., Paar, C. (eds.) CHES 1999. LNCS, vol. 1717, pp. 292–302. Springer, Heidelberg (1999). doi:10.1007/3-540-48059-5_25

    Chapter  Google Scholar 

  7. Doychev, G., Feld, D., Köpf, B., Mauborgne, L., Reineke, J.: Cacheaudit: a tool for the static analysis of cache side channels. In: Presented as Part of the 22nd USENIX Security Symposium (USENIX Security 13), pp. 431–446. USENIX, Washington, D.C. (2013)

    Google Scholar 

  8. Doychev, G., Köpf, B.: Rigorous analysis of software countermeasures against cache attacks (2016). https://arxiv.org/abs/1603.02187v2

  9. Google Inc.: boringssl (2016). https://boringssl.googlesource.com/boringssl/

  10. Gordon, D.M.: A survey of fast exponentiation methods. J. Algorithms 27(1), 129–146 (1998)

    Article  MathSciNet  MATH  Google Scholar 

  11. Gutmann, P.: cryptlib (2016). https://www.cs.auckland.ac.nz/~pgut001/cryptlib/

  12. INSIDE Secure Corporation: MatrixSSL (2016). http://www.matrixssl.org

  13. Intel Corporation: Pin - A Dynamic Binary Instrumentation Tool, June 2012. https://software.intel.com/en-us/articles/pintool

  14. Joye, M., Yen, S.-M.: The montgomery powering ladder. In: Kaliski, B.S., Koç, K., Paar, C. (eds.) CHES 2002. LNCS, vol. 2523, pp. 291–302. Springer, Heidelberg (2003). doi:10.1007/3-540-36400-5_22

    Chapter  Google Scholar 

  15. Koç, Ç.K.: Analysis of sliding window techniques for exponentiation. Comput. Math. Appl. 30, 17–24 (1995)

    Article  MathSciNet  MATH  Google Scholar 

  16. Knuth, D.: The Art of Computer Programming: Seminumerical Algorithms. Addison-Wesley Series in Computer Science and Information Processing. Addison-Wesley, Reading (1981)

    MATH  Google Scholar 

  17. Koch, W.: Libgcrypt (2016). https://www.gnu.org/software/libgcrypt/

  18. Langley, A.: ctgrind - checking that functions are constant time with valgrind (2010). https://github.com/agl/ctgrind

  19. Möller, N.: Nettle - a low-level cryptographic library (2016). https://www.lysator.liu.se/~nisse/nettle/

  20. Molnar, D., Piotrowski, M., Schultz, D., Wagner, D.: The program counter security model: automatic detection and removal of control-flow side channel attacks. Cryptology ePrint Archive, Report 2005/368 (2005). http://eprint.iacr.org/2005/368

  21. OpenBSD: LibreSSL (2016). http://www.libressl.org/

  22. Percival, C.: Cache missing for fun and profit. In: Proceedings of BSDCan 2005 (2005)

    Google Scholar 

  23. Reparaz, O., Balasch, J., Verbauwhede, I.: Dude, is my code constant time? Cryptology ePrint Archive, Report 2016/1123 (2016). http://eprint.iacr.org/2016/1123

  24. Rodrigues, B., Quintão Pereira, F.M., Aranha, D.F.: Sparse representation of implicit flows with applications to side-channel detection. In: Proceedings of the 25th International Conference on Compiler Construction, CC 2016, pp. 110–120. ACM, New York (2016)

    Google Scholar 

  25. Schneier, B.: Applied Cryptography (2nd Ed.): Protocols, Algorithms, and Source Code in C. Wiley, New York (1995)

    MATH  Google Scholar 

  26. The GNU project: The GNU Multiple Precision Arithmetic Library (2016). https://gmplib.org/

  27. The OpenSSL Project: Changes between 0.9.7g and 0.9.7h, 11 October 2005. https://www.openssl.org/news/changelog.html

  28. The OpenSSL Project: OpenSSL (2016). https://www.openssl.org/

  29. wolfSSL: wolfSSL User Manual, March 2016. https://www.wolfssl.com/documentation/wolfSSL-Manual.pdf, v3.9.0

  30. wolfSSL Inc.: wolfSSL Embedded SSL Library (2016). https://www.wolfssl.com

  31. Yarom, Y., Falkner, K.: Flush+reload: a high resolution, low noise, l3 cache side-channel attack. In: Proceedings of the 23rd USENIX Security Symposium, San Diego, CA, USA, 20–22 August 2014, pp. 719–732 (2013)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Andreas Zankl .

Editor information

Editors and Affiliations

A Configuration of Cryptographic Libraries

A Configuration of Cryptographic Libraries

Most of the cryptographic libraries configure themselves with automatic scripts that adapt the library to the current processor, which is an Intel Xeon E5440 in our tests. The paragraphs beneath discuss all manual configuration steps and also list the functions and source code files containing the exponentiation code. This is important to verify and reproduce our results, because libraries often feature multiple implementations of modular exponentiation and pick one depending on their configuration.

wolfSSL. On our x86-64 test system, wolfSSL automatically speeds up public key operations by defining the fastmath option. In addition, we define the flag TFM_TIMING_RESISTANT, because it is recommended in the documentation [29]. The exponentiation function _fp_exptmod is defined in wolfcrypt/src/tfm.c.

MatrixSSL. For MatrixSSL no extra configuration steps are done. The exponentiation function pstm_exptmod is implemented in crypto/math/pstm.c.

Nettle. This library offers two functions for RSA decryption, rsa_decrypt and rsa_decrypt_tr. We use the latter one, because it implements base blinding to mitigate timing attacks and is therefore recommended in practice. For the required random numbers, we use the included implementation of the Yarrow PRNG. By default Nettle calls the external GNU multi precision arithmetic library (GMP) [26] to perform exponentiation. In particular, it relies on the function mpn_powm in the source file mpn/generic/powm.c. We compile GMP in version 6.1.0 with default configuration and link it with decryption program.

mbed TLS. The mbed TLS library is compiled with the flag MBEDTLS_RSA_NO_CRT to enforce decryption without CRT components. Setting this flag does not affect the exponentiation code in function mbedtls_mpi_exp_mod defined in library/bignum.c. For the implemented base blinding countermeasure the CTR_DRBG random number generator is used.

Libgcrypt. The Libgcrypt library implements a secure memory feature that can be used for key storage. Because this is not required in our tests and does not change the exponentiation algorithm, we disable the feature during runtime. Exponentiation is done in function _gcry_mpi_powm, which is implemented in mpi/mpi-pow.c.

cryptlib. Before triggering the decryption in the cryptlib library, we set the CRYPT_RANDOM_SLOWPOLL and CRYPT_OPTION_MISC_SIDECHANNELPROTECTION options. A random slowpoll gathers entropy before the library actually needs it, which speeds up the retrieval of random numbers at a later point in time. The enabled side-channel protection activates a base blinding countermeasure, sanity checks in the code and the constant-time, fixed window exponentiation in function BN_mod_exp_mont_consttime, which is defined in bn/bn_exp.c.

OpenSSL and Forks. The OpenSSL library is compiled with the options OPENSSL_BN_ASM_MONT and OPENSSL_BN_ASM_MONT5, which activate assembly optimized Montgomery multiplication. By default, the base blinding countermeasure and the constant-time, fixed window exponentiation in function BN_mod_exp_mont_consttime defined in crypto/bn/bn_exp.c are enabled. The LibreSSL and BoringSSL libraries are compiled and used with the default options, which enable a similar exponentiation implementation as in OpenSSL. Sliding window exponentiation can be manually enabled in OpenSSL and LibreSSL by setting the RSA_FLAG_NO_CONSTTIME flag during runtime.

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG

About this paper

Cite this paper

Zankl, A., Heyszl, J., Sigl, G. (2017). Automated Detection of Instruction Cache Leaks in Modular Exponentiation Software. In: Lemke-Rust, K., Tunstall, M. (eds) Smart Card Research and Advanced Applications. CARDIS 2016. Lecture Notes in Computer Science(), vol 10146. Springer, Cham. https://doi.org/10.1007/978-3-319-54669-8_14

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-54669-8_14

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-54668-1

  • Online ISBN: 978-3-319-54669-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics