Arxiv:1909.01785V2 [Cs.CR] 1 Apr 2020
Total Page:16
File Type:pdf, Size:1020Kb
Certified Side Channels Cesar Pereida García1, Sohaib ul Hassan1, Nicola Tuveri1, Iaroslav Gridin1, Alejandro Cabrera Aldaya1,2, and Billy Bob Brumley1 1Tampere University, Tampere, Finland {cesar.pereidagarcia,n.sohaibulhassan,nicola.tuveri,iaroslav.gridin,billy.brumley}@tuni.fi 2Universidad Tecnológica de la Habana (CUJAE), Habana, Cuba [email protected] Abstract the multitude of standardized cryptographic key formats to choose from when persisting keys: which one to choose, and We demonstrate that the format in which private keys are per- does the choice matter? Surprisingly, it does—we demon- sisted impacts Side Channel Analysis (SCA) security. Survey- strate different key formats trigger different behavior within ing several widely deployed software libraries, we investigate software libraries, permeating all the way down to the low the formats they support, how they parse these keys, and what level arithmetic for the corresponding cryptographic primitive. runtime decisions they make. We uncover a combination of (ii) At the specification level, alongside required parameters, weaknesses and vulnerabilities, in extreme cases inducing standardized key formats often contain optional parameters: completely disjoint multi-precision arithmetic stacks deep does including or excluding optional parameters impact se- within the cryptosystem level for keys that otherwise seem curity? Surprisingly, it does. We demonstrate that omitting logically equivalent. Exploiting these vulnerabilities, we de- optional parameters can cause extremely different execution sign and implement key recovery attacks utilizing signals flows deep within a software library, and also that two keys ranging from electromagnetic (EM) emanations, to granular seemingly mathematically identical at the specification level microarchitecture cache timings, to coarse traditional wall can be treated by a software library as inequivalent, again clock timings. reaching very different arithmetic code deep within the li- brary. 1 Introduction Furthermore, we demonstrate that key parsing in general is a lucrative SCA attack vector. This is due mostly to software Academic SCA tends to focus on implementations of crypto- engineering constraints. Complex libraries inevitably stray to graphic primitives in isolation. With this view, the assumption convoluted data structures containing generous nesting levels is that any higher level protocol or system built upon imple- to meet the demands of broad standardized cryptography. This mentations of these primitives will naturally benefit from SCA is exacerbated by the natural urge to handle keys generically mitigations in place at lower levels. when faced with extremely diverse cryptographic standards Our work questions this assumption, and invalidates it with spanning RSA, DSA, ECDSA, Ed25519, Ed448, GOST, SM2, several concrete vulnerabilities and attacks against modern etc. primitives. The motivation behind this generalization is arXiv:1909.01785v2 [cs.CR] 1 Apr 2020 software libraries: we dub these Certified Side Channels, since to abstract away underlying cryptographic details from appli- the novel attack vector is deeply rooted in cryptography stan- cation developers linking against a library—more often than dards. For this vector, “certified” is in the certificate sense (e.g. not, these developers are not cryptography experts. Never- X.509), not in the Common Criteria sense. Counter-intuitively, theless, we observe that when loading keys modern security we demonstrate that the format in which keys are stored plays libraries make varying design choices that ultimately impact a significant role in real world SCA security. Detailed security SCA security. From the functionality perspective, these de- recommendations for key persistence are scarce; e.g. FIPS sign choices are sensible; from the security perspective, we 140-2 vaguely states “Cryptographic keys stored within a demonstrate they are often questionable. cryptographic module shall be stored either in plaintext form Outline. Section 2 gives an overview of the related back- or encrypted form [::] Documentation shall specify the key ground and previous work. Section 3 discusses the vulnerabil- storage methods employed by a cryptographic module”[1, ities discovered as a result of our analysis, with microarchitec- 4.7.5]. ture SCA evaluations on OpenSSL RSA, DSA, and mbedTLS There are (at least) two high level dimensions at play re- RSA. We also demonstrate end-to-end attacks on OpenSSL garding key formats as an SCA attack vector: (i) Among ECDSA using timing and EM side channels in Section 4. We 1 conclude in Section 5. decentralization is obtained delegating the authority on sub- trees to entities such as countries and organizations. This 2 Background mechanism solves the problem of assigning globally unique identifiers to entities to facilitate global communication. 2.1 Public Key Cryptography RSA private keys. PKCS #1 (RFC 8017[ 55]) also defines the ASN.1 DER encoding for an RSA private key, defining an ECDSA. Denote an order-n generator G 2 E of an elliptic item for each of its eight parameters. As further discussed in curve group E with cardinality f n and n a large prime and Section 3.4, the standard does not strictly require implemen- f the small cofactor. The user’s private key a is an integer tations to include all the eight parameters during serialization, uniformly chosen from f1::n − 1g and the corresponding nor to invalidate the object during deserialization if one of the public key is D = [a]G. With approved hash function Hash(), parameters is not included. the ECDSA digital signature (r;s) on message m (denoting EC private keys. The ANSI X9.62 standard [51] is the nor- with h < n the representation of Hash(m) as an integer) is mative reference for the definition of the ECDSA cryptosys- −1 r = ([k]G)x mod n; s = k (h + ar) mod n (1) tem and the encoding of ECDSA public keys, but omits a serialization for private keys. The SEC1 standard [2] follows where k is a nonce chosen uniformly from f1::n − 1g. ANSI X9.62 for the public key ASN.1 and provides a DER RSA. According to the PKCS #1 v2.2 standard (RFC encoding also for EC private keys, but allows generous vari- 8017[ 55]), an RSA private key consists of the eight param- ation as it seems to assume different encapsulating options eters fN;e; p;q;d;dp;dq;iqg where all but the first two are depending on different protocols in which the EC private secret, and N = pq for primes p, q. Public exponent e is usu- key can be used. Flexibility in the format brings complexity ally small and the following holds: in the deserializer implementation, that needs to be stateful w.r.t. parsing of the container of the private key encoding and d = e−1 mod lcm(p − 1;q − 1) (2) flexible enough to interoperate with other implementations and interpretations of the standards: this already suggests In addition, Chinese Remainder Theorem (CRT) parameters that the parsing stage shows potential as a lucrative SCA at- are stored for speeding up RSA computations: tack vector. The SEC1 ASN.1 notation for ECPrivateKey contains the private scalar as an octet string, an optional (de- d = d mod p; d = d mod q; i = q−1 mod p (3) p q q pending on the container) ECDomainParameters field, and an optional bit string field to include the public part of the 2.2 Key Formats key pair. The ECDomainParameters can be null, if the curve parameters are specified in the container encapsulating the Interoperability among different software and hardware plat- ECPrivateKey, or contain either an OID for a “named” curve, forms in handling keys and other cryptographic objects re- or a SpecifiedECDomain structure. The latter, simplifying, quires common standards to serialize and deserialize such contains a description of the field over which the EC group objects. ASN.1 or Abstract Syntax Notation One is an in- is defined, the definition of the curve equation in terms of terface description language to define data structures and the coefficients of its Short Weierstrass form, an encoding their (de/)serialization, standardized [69] jointly by ITU-T of the EC base point, and its order n. Finally it can option- and ISO/IEC since 1984 and widely adopted. It supports ally contain a component to represent a small cofactor f as several encoding rules, among which the Distinguished En- defined at the beginning of this section. In Section 3.1 we coding Rules (DER), a binary format ensuring uniqueness and will further discuss about the security consequences caused concision, has been preferred for the representation of crypto- in actual implementations by the logic required to support the graphic objects. PEM (RFC 7468[45]) is a textual file format cofactor as an optional field. to store and trasmit cryptographic objects, widespread despite being originally developed as part of the now obsoleted IETF MSBLOB key format. MSBLOB is the OpenSSL implemen- 1 standards for Privacy-Enhanced Mail after which it is named. tation of Microsoft’s private key BLOB format supporting PEM uses base64 to encode the binary DER serialization of different cryptosystems, using custom defined structures and an object, providing some degree of human readability and fields. DSS key BLOB uses an arbitrary structure, while RSA support for text-based protocols like e-mail and HTTP(S). key BLOBs follows PKCS #1 with minor differences. To iden- tify each cryptosystem, a “magic member” is used in the key Object Identifiers. The ASN.1 syntax also defines an BLOB structure—the member is the hexadecimal represen- OBJECT IDENTIFIER primitive type which represents a glob- tation of the ASCII encoding of the cryptosystem name, e.g. ally unique identifier for an object. ITU-T and ISO jointly “RSA1”, “RSA2”, “DSS1”, “DSS2”, etc., where the integer manage a decentralized hierarchical registry of object iden- tifiers or OID s. The registry is organized as a tree structure, 1https://docs.microsoft.com/en-us/windows/win32/ where every node is authoritative for its descendants, and seccrypto/base-provider-key-blobs 2 dictates if it is a public or a private key.