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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 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
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)
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
ARM Limited: mbed TLS (2016). https://tls.mbed.org/
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)
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)
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
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)
Doychev, G., Köpf, B.: Rigorous analysis of software countermeasures against cache attacks (2016). https://arxiv.org/abs/1603.02187v2
Google Inc.: boringssl (2016). https://boringssl.googlesource.com/boringssl/
Gordon, D.M.: A survey of fast exponentiation methods. J. Algorithms 27(1), 129–146 (1998)
Gutmann, P.: cryptlib (2016). https://www.cs.auckland.ac.nz/~pgut001/cryptlib/
INSIDE Secure Corporation: MatrixSSL (2016). http://www.matrixssl.org
Intel Corporation: Pin - A Dynamic Binary Instrumentation Tool, June 2012. https://software.intel.com/en-us/articles/pintool
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
Koç, Ç.K.: Analysis of sliding window techniques for exponentiation. Comput. Math. Appl. 30, 17–24 (1995)
Knuth, D.: The Art of Computer Programming: Seminumerical Algorithms. Addison-Wesley Series in Computer Science and Information Processing. Addison-Wesley, Reading (1981)
Koch, W.: Libgcrypt (2016). https://www.gnu.org/software/libgcrypt/
Langley, A.: ctgrind - checking that functions are constant time with valgrind (2010). https://github.com/agl/ctgrind
Möller, N.: Nettle - a low-level cryptographic library (2016). https://www.lysator.liu.se/~nisse/nettle/
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
OpenBSD: LibreSSL (2016). http://www.libressl.org/
Percival, C.: Cache missing for fun and profit. In: Proceedings of BSDCan 2005 (2005)
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
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)
Schneier, B.: Applied Cryptography (2nd Ed.): Protocols, Algorithms, and Source Code in C. Wiley, New York (1995)
The GNU project: The GNU Multiple Precision Arithmetic Library (2016). https://gmplib.org/
The OpenSSL Project: Changes between 0.9.7g and 0.9.7h, 11 October 2005. https://www.openssl.org/news/changelog.html
The OpenSSL Project: OpenSSL (2016). https://www.openssl.org/
wolfSSL: wolfSSL User Manual, March 2016. https://www.wolfssl.com/documentation/wolfSSL-Manual.pdf, v3.9.0
wolfSSL Inc.: wolfSSL Embedded SSL Library (2016). https://www.wolfssl.com
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)
Author information
Authors and Affiliations
Corresponding author
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
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)