Internet Engineering Task Force | A. Malhotra |
Internet-Draft | S. Goldberg |
Intended status: Standards Track | Boston University |
Expires: April 16, 2017 | October 13, 2016 |
Message Authentication Codes for the Network Time Protocol
draft-aanchal4-ntp-mac-01
The Network Time Protocol (NTP) RFC 5905 [RFC5905] uses a message authentication code (MAC) to cryptographically authenticate its UDP packets. Currently, NTP packets are authenticated by appending a 128-bit key to the NTP data, and hashing the result with MD5 to obtain a 128-bit tag. However, as discussed in [BCK] and [RFC6151], this not a secure MAC. As such, this draft considers different secure MAC algorithms for use with NTP, evaluates their performance, and recommends the use CMAC-AES [RFC4493]. We also suggest deprecating the use of MD5 as defined in [RFC5905] for authenticating NTP packets.
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."
This Internet-Draft will expire on April 16, 2017.
Copyright (c) 2016 IETF Trust and the persons identified as the document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.
NTP uses a message authentication code (MAC) to authenticate its packets. Currently, NTP packets are authenticated by appending a 128-bit key to the NTP data, and hashing the result with MD5 to obtain a 128-bit tag. However, as discussed in [BCK] and [RFC6151], this not a secure MAC. As such, this draft considers different secure MAC algorithms for use with NTP, evaluates their performance, and and recommends the use CMAC-AES [RFC4493]. We also suggest deprecating the use of MD5, as defined in [RFC5905], for authenticating NTP packets.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].
We consider five diverse MAC algorithms, which encompass hash-based HMAC-MD5 and HMAC-SHA224 [RFC2104], block cipher-based CMAC-AES [RFC4493], and universal hashing-based Galois MAC (GMAC) [RFC4543] and Poly1305(ChaCha20) as in section 2.6 of [RFC7539]. For completeness we also benchmark the legacy MD5(key||message) from [RFC5905].
Algorithm | Input Key Length (Bytes) | Output Tag Length (Bytes) |
---|---|---|
legacy MD5 | 16 | 16 |
HMAC-MD5 | 16 | 16 |
HMAC-SHA224 | 16 | 16 |
CMAC(AES) | 16 | 16 |
GMAC(AES) | 16 | 16 |
Poly1305(ChaCha20) | 32 | 16 |
The choice of algorithms evaluated here is motivated, in part, by standardization and availablity of open source implementation. All algorithm we consider, other than plain MD5, are standardized. Four out of five algorithms are at available in the OpenSSL library, while Poly1305(ChaCha20) algorithm is implemented in LibreSSL (a fork of OpenSSL) and also in BoringSSL (Google's implementation of OpenSSL).
The output tag length for HMAC-SHA224 is 28 bytes, but we truncate it to 16 bytes as in section 4 of [RFC7630] to fit into the NTP packet. As noted in section 6 of [RFC2104] it is safe to truncate the output of MACs as long as the truncated length is greater than 80-bits and not less than half the length of the hash output.
In order to accurately compute the time, NTP ideally requires MAC algorithms to have a constant computational latency. However, this is generally not possible, since latency depends on the CPU load, temperature, and other uncontrollable factors. Instead, a MAC algorithm that requires fewer clock cycles for computation is prefered over one that requires more clock cycles, as this directly translates to a reduction in jitter (i.e., the variance of the latency for computing the MAC).
Throughput is another important consideration. NTP servers may have to deal with thousands of client requests per second. A study [NIST] on the usage analysis of NIST's NTP stratum 1 servers shows these servers caters to 28,000 requests/second on an average, per server.
Most of the Internet is served by stratum 2 and stratum 3 servers, some of which are part of voluntary NTP pool. These machines may be running old hardware. So we benchmark performance on a range of software and hardware platforms.
There are several more constraints specific to NTP that need to be taken into account.
The NTP header is 48 bytes long. We therefore consider the latency and throughput for several secure message authentication code (MAC) algorithms when computed over 48-byte messages.
We customize the in-built speed utility of OpenSSL-1.0.2g (03 May 2016) version to compute the latency and throughput for each MAC as shown in the tables below. OpenSSL, however, does not implement stream-cipher ChaCha20-based Poly1305 MAC algorithm. To speed test this MAC, we use LibreSSL 2.3.1, a fork of OpenSSL implementation. OpenSSL and LibreSSL are the most widely used cryptographic libraries and are used by the current NTP implementations.
Since the introduction of New Instruction (NI) set for hardware support in Intel chips, certain MACs like CMAC and GMAC have performance advantage on such machines. Based on this, we perform two different benchmarks: one with AES-NI enabled and the other with it disabled. Benchmarks were taken on an x86_64, Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz with one core CPU.
This table shows throughput in terms of number of 48-byte NTP payload processed per second.
Algorithm | with AES-NI | without AES-NI |
---|---|---|
legacy MD5 | 3118K | 3165K |
HMAC-MD5 | 2742K | 2749K |
HMAC-SHA224 | 1265K | 1267K |
CMAC(AES) | 7567K | 4388K |
GMAC(AES) | 16612K | 4627K |
Poly1305(ChaCha20) | 2598K | 2398K |
This table shows latency in terms of number of CPU cycles per byte (cpb) when processing a 48-byte NTP payload.
Algorithm | with AES-NI | without AES-NI |
---|---|---|
legacy MD5 | 16.0 | 15.7 |
HMAC-MD5 | 18.2 | 18.1 |
HMAC-SHA224 | 39.4 | 39.0 |
CMAC(AES) | 6.6 | 11.3 |
GMAC(AES) | 3.0 | 10.8 |
Poly1305(ChaCha20) | 14.4 | 15.0 |
TODO: Test on other types of hardware.
The MD5 (key||message) "message authentication code" specified in [RFC5905] is vulnerable to length extension attacks, and uses the insecure MD5 hash function, and therefore MUST be deprecated.
Therefore, we consider hash-based MACs (HMAC-MD5, HMAC-SHA224), and cipher-based MACs (CMAC-AES, Poly1305 (ChaCha20)). The upper bound on the security level provided by any MAC against brute-force attacks is min (key-length, tag-length). The security of these MACs can be worse but not better than this bound. All MAC algorithms we consider have comparable key-lengths and output tag-lengths. So the advantage of an adversary that wishes to forge a MAC is lower-bounded by 1/2^{128}.
Assume that an adversary can obtain a valid MAC for q distinct messages. Then the table below describes the advantage of an adversary that wishes to forge a MAC in terms of number of queries (q) it launches.
Algorithm | Advantage |
---|---|
HMAC-MD5 [MB] | q^2/2^{128} |
HMAC-SHA224 [BCK] | q^2/2^{224} |
CMAC(AES)[IK] | q^2/2^{128} |
GMAC(AES) [IOM] | q^2/2^{128} (Seems wrong) |
Poly1305(ChaCha20) [DJB] | {e^{{q^2}/{2^{129}}}}/2^{103} |
Poly1305 can easily handle up to q=2^{64} but security degrades pretty rapidly after that.
However, the bounds in the table above are somewhat optimistic, for the following reasons.
[Joux] showed that for GMAC-AES, if the IV is repeated just once, then the authentication key can be fully recovered. None of the other algorithms evaluated here have this vulnerability. Thus, for GMAC-AES to be secure, we need to make sure that IV is never repeated.
[NIST-GMAC] recommends constructing the 12-byte IV used in GMAC by concatenating a fixed 4-byte salt value and a with variable 8-byte nonce i.e. IV = ( salt|| nonce). Here salt is an implicit value established when an session is established, remains fixed for all exchanges in a session (i.e. for all invocations that use the same authenicationkey) between the sender and the receiver. Meanwhile, the nonce is freshly generated for each authenticated message.
Because NTP servers do not keep per-client state, the nonce can not be a sequential value. Instead, this nonce must be is a randomly generated 8-bytes value chosen freshly for each authenticated message. According to birthday bound, the nonce value will be repeated, with high probability, after 2^{32} messages sent in a given association . This leads to a repeated IV value and to [Joux]'s attack. Thus, to prevent repeated nonces, we would need to require the authentication key to be refereshed for the association after 2^{32} messages.
While on one hand, 2^{32} is a lot of queries for an honest client, assuming that the client queries once per minute (which is NTP's minimum polling interval [RFC5905]). On the other hand, a man-in-the-middle (MiTM) can quickly and easily exhaust this number by replaying old authenticated queries to the NTP server.
Another problem is that NTP lacks an explict in-band key refresh mechanism that can be invoked automatically (without operator intervention).
Even if there was a method by which key-refresh could be performed, there is an additional problem. An NTP server does not keep per-client state. Therefore, it cannot keep track of the number of messages it sent in a given association. One idea is to have the client keep this state, and then send an authenicated request for a key refresh. However, a man-in-the-middle (MiTM) could replay old authenticated queries to the NTP server, and then intercept the servers response before they reach the legitimate clients. In this case, the client would never know when to ask for a key refresh.
Alternatively, the server could maintain a global counter (since it can't afford to keep per client counter). And after 2^{32} messages, it can refresh the keys with all its clients. However, a man-in-the-middle could exhaust this number quickly and the server will have to refresh keys with all the clients very frequently. Thus, we conclude that a scheme that requires refreshing the key after 2^{32} client queries is not a good idea at all.
Even in the absence of a man-in-the-middle, there is the problem of multiple servers using the same authentication key. Thus, salt could be used to distinguish IVs across different client/server associations that use the same authenication key. However, this brings us back to the original key management problem. One way to deal with this is to choose the 4-byte salt at random. However, this rise to a birthday bound of 2^{16} = 65,000 unique IVs. If we consider 20,000 stratum 3 clients synchronizing to three stratum 2 servers each, all of which are in the same organization and share the same symmetric key, we get very close to the birthday bound. Thus, this leads to other disadvantages when using GMAC with NTP.
From the tables we clearly see that GMAC(AES) has the best latency and throughput performance in both hardware and software implementations. It is freely available, and there is a flexibilty of changing the underlying block-cipher. However there are several security problems surrounding the use of this mode, as highlighted above, so it is not recommended.
CMAC, on the other hand, is the next best choice in terms of performance and security. So we recommend the use of CMAC.
The authors wish to acknowledge useful discussions with Leen Alshenibr, Daniel Franke, Ethan Heilman, Kenny Paterson, Leonid Reyzin, Harlan Stenn, Mayank Varia.