aes-gcm for efficient authenticated encryption – ending the reign of hmac-sha-1?

32
Workshop on Real-World Cryptography Stanford University Jan. 9-11, 2013 AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1? Shay Gueron University of Haifa Department of Mathematics, Faculty of Natural Sciences, University of Haifa, Israel Intel Corporation Intel Corporation, Israel Development Center, Haifa, Israel [email protected], [email protected] 1

Upload: others

Post on 12-Sep-2021

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Workshop on Real-World Cryptography Stanford University Jan. 9-11, 2013

AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Shay Gueron

University of Haifa

Department of Mathematics, Faculty of Natural Sciences, University of Haifa, Israel

Intel Corporation Intel Corporation, Israel Development Center, Haifa, Israel

[email protected], [email protected]

1

Page 2: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Agenda

• Why is the ecosystem using HMAC SHA-1 for authenticated encryption?

– What can be done to change this?

• AES-GCM dirty secrets… and how to optimize it

(… and save the honor of AES-GCM after Adam’s talk)

S. Gueron. RWC 2013 2

Page 3: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Optimizing cryptographic primitives

• Why care? Who cares?

– The need for end-to-end security in the internet, constantly increases the world-wide number (and percentage) of SSL/TLS connections.

– Why aren’t all connections https:// ? Overheads’ costs

• Cryptographic algorithms for secure communications = computational overhead

• Mainly on the servers side

– Any latency client side influences (indirectly) the ecosystem

• Authenticated Encryption: a fundamental cryptographic primitive

• Is the ecosystem using an efficient AE scheme?

– Apparently no… a better alternative exists

S. Gueron. RWC 2013 3

Page 4: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Ciphers in use in SSL/TLS connections

S. Gueron. RWC 2013 4

ASE256-SHA-1 44%

AES128-SHA-1 36%

RC4-MD5-128 15%

RC4-SHA-128 3%

DES-CBC3-SHA-168

2%

• Akamai serves service millions of requests per sec. for secure

content over HTTPS/SSL

• Observed the client-side SSL ciphers in popular use

• Statistics for SSLv3 and TLSv1

• http://www.akamai.com/stateoftheinternet

AES-GCM is a more efficient Authenticated Encryption scheme

Today’s most frequently used AE in

browser/server connections

RC4 + HMAC-MD5 (don’t care)

RC4 + HMAC-SHA-1

AES + HMAC-SHA-1

authentication: mostly HMAC SHA-1

Is it the best AE (performance wise)?

No – a faster alternative exists

We already know that HMAC is not an

efficient MAC scheme, and as an ingredient

in AE – it makes an inefficient AE

Page 5: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

AES-GCM Authenticated Encryption

• AES-GCM Authenticated Encryption (D. McGrew & J. Viega)

• Designed for high performance (Mainly with a HW viewpoint)

• A NIST standard FIPS 800-38D (since 2008)

• Included in the NSA Suite B Cryptography.

• Also in:

– IPsec (RFC 4106)

– IEEE P1619 Security in Storage Working Group http://siswg.net/

• TLS 1.2

• How it works:

• Encryption is done with AES in CTR mode

• Authentication tag computations - “Galois Hash” :

• A Carter-Wegman-Shoup universal hash construction: polynomial evaluation over a binary field

• Uses GF(2128) defined by the “lowest” irreducible polynomial

g = g(x) = x128 + x7 + x2 + x + 1

• Computations based on GF(2128) arithmetic

S. Gueron. RWC 2013 5

But not really the standard GF(2128)

arithmetic

Page 6: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

AES-GCM and Intel’s AES-NI / PCLMULQDQ

• Intel introduced a new set of instructions (2010)

• AES-NI:

– Facilitate high performance AES encryption and decryption

• PCLMULQDQ 64 x 64 128 (carry-less)

– Binary polynomial multiplication; speeds up computations in binary fields

• Has several usages --- AES-GCM is one

• To use it for the GHASH computations: GF(2128) multiplication:

1. Compute 128 x 128 256 via carry-less multiplication (of 64-bit operands)

2. Reduction: 256 128 modulo x128 + x7 + x2 + x + 1 (done efficiently via software)

AES-NI and PCLMULQDQ can be used for speeding up AES-GCM Authenticated Encryption

S. Gueron. RWC 2013 6

It ain’t necessarily so

Page 7: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

The performance order is reversed!

AES-NI accelerate the encryption

PCLMULQDQ GF(2128) stuff (w/o tables)

21.96

2.47 2.42

22.51

6.16 5.59

9.46 9.46 8.97

0

5

10

15

20

25

pre-AES NI Core i7-2600K Core i7-3770

Cyc

les

pe

r B

yte

- lo

wer

is b

ette

r

AES-GCM

AES-SHA1

RC4-SHA1

Some Authenticated Encryption performance

2010 -… POST AES-NI / CLMUL

2nd Generation; 3rd Generation Core

S. Gueron. RWC 2013 7

PRE AES-NI / CLMUL(lookup tables)

RC4 + HMAC SHA-1

AES + HMAC SHA-1

AES-GCM

Page 8: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

If AES-GCM is so good, why everyone is still using SHA-1 HMAC?

• Inertia: If is works – don’t upgrade it

– Migration costs and effort

– Problem is not painful enough / Painful – but to whom?

– “Legacy”: RC4/AES + HMAC-SHA1 is all over the place

• Ecosystem awareness: performance benefit & progression - not fully understood

• Kickoff latency

– AES-GCM is a relatively new standard (2008);

• Part of TLS -- only from TLS 1.2 (which is not proliferated yet)

– Superior performance: only from 2010 (emergence of AES-NI & PCLMULQDQ)

• The chicken and the egg problem:

– Browsers (client) will not upgrade (TLS1.2) and implement (GCM) before “all” servers support TLS 1.2

– Servers will not upgrade/implement before “all” browsers have TLS1.2 and offer GCM as an option

S. Gueron. RWC 2013 8

In an ideal world: all servers and clients support TLS 1.2, clients offer AES-GCM at handshake And the ecosystem would see performance gain

But how can we get there?

Page 9: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

What needs to happen? • Clients (browsers): add TLS 1.2, as well as GCM support.

– The client will then offer that as one of their ciphers

• Server: support TLS 1.2 and GCM (today ~9% of the servers)

– Servers with AES-NI/CLMUL would enjoy the faster cipher

• What happens now?

– OpenSSL 1.0.1 already has GCM and TLS 1.2. (and that is slowly deploying)

– Internet Explorer and MSFT server support TLS 1.2

• AES-GCM (version 8 on Win 7)

– Safari (?) (announced TLS 1.2 and AES-GCM)

• The next big move: --- NSS to add support – (NSS is the stack behind Firefox and Chrome)

– There is ongoing work there on both GCM and TLS 1.2

S. Gueron. RWC 2013 9

Wan-Teh Chang (Google), Bob Relyea (Red Hat), Brian Smith (Mozilla), Eric Rescorla, Shay Gueron (Intel)

Page 10: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

What did we contribute to this? The new AES-GCM patches (2012)

• Sept./Oct. 2012: We published two patches for two popular open source distributions: OpenSSL and NSS

– Authors: S. Gueron and V. Krasnov

Inherently side channel protected

“constant time” in the strict definition

Fast on the current x86_64 processors (2nd and 3rd Generation Core)

Fastest we know of

And also ready to boost performance on the coming processors generation (4th Generation Core)

• Let’s review how this was done

S. Gueron. RWC 2013 10

Page 11: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

AES-GCM optimization

1. The encryption

2. The Galois Hash

3. Putting them together

S. Gueron. RWC 2013 11

Page 12: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

AES-NI: Throughput vs. Latency

S. Gueron. RWC 2013

AESENC data, key0

AESENC data, key1

AESENC data, key2

AESENC data0, key0

AESENC data1, key0

AESENC data2, key0

AESENC data3, key0

AESENC data4, key0

AESENC data5, key0

AESENC data6, key0

AESENC data7, key0

AESENC data0, key1

12

Parallelizable modes (CTR, CBC decryption, XTS) can interleave processing of multiple messages They become much faster with AES-NI

Page 13: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

How much to parallelize? The effect of the parallelization parameter

Encryption of 8 blocks in parallel vs. encryption of 4 blocks in parallel

S. Gueron. RWC 2013

0 0.2 0.4 0.6 0.8 1

8 blocks

4 blocks

13

AES ECB on 1KB buffer (in CPU cycles per Byte, Intel® Core™ i7-2600K)

We found the 8 blocks in parallel is a sweat point

Page 14: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

AES-CTR performance

1.30

1.53

1.78

0.83

0.96

1.09

0.83

0.97

1.09

0.00

0.20

0.40

0.60

0.80

1.00

1.20

1.40

1.60

1.80

2.00

AES-128 AES-192 AES-256

CP

U C

ycle

s/B

yte

Key Size

Performance on Intel® Core™ i7-880 Processor

128-bit LegacySSE AESinstructions

VEX encoded AESinstructions

Previous Generation Core, Second Generation Core, Thirds Generation Core Intel® Core™ i7-2600K vs. Intel® Core™ i7-880 Processor

(1KB buffer; performance in CPU cycles per Byte)

S. Gueron. RWC 2013 14

Page 15: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

128-bit Carry-less Multiplication using PCLMULQDQ

(Gueron Kounavis, 2009) Multiply 128 x 128 → 256 𝐴1: 𝐴0 • 𝐵1: 𝐵0

• Schoolbook (4 PCLMULQDQ invocations) 𝐴0•𝐵0 = 𝐶1: 𝐶0 , 𝐴1•𝐵1 = 𝐷1: 𝐷0 𝐴0•𝐵1 = 𝐸1: 𝐸0 , 𝐴1•𝐵0 = 𝐹1: 𝐹0

𝐴1: 𝐴0 • 𝐵1: 𝐵0 = [𝐷1: 𝐷0 ⊕ 𝐸1 ⊕ 𝐹1: 𝐶1 ⊕ 𝐸0 ⊕ 𝐹0: 𝐶0]

• Carry-less Karatsuba (3 PCLMULQDQ invocations) 𝐴1•𝐵1 = 𝐶1: 𝐶0 , 𝐴0•𝐵0 = 𝐷1: 𝐷0

𝐴1 ⊕ 𝐴0 • 𝐵1 ⊕ 𝐵0 = [𝐸0: 𝐸1]

𝐴1: 𝐴0 • 𝐵1: 𝐵0 = [𝐶1: 𝐶0 ⊕ 𝐶1 ⊕ 𝐷1 ⊕ 𝐸1: 𝐷1 ⊕ 𝐶0 ⊕ 𝐷0 ⊕ 𝐸0: 𝐷0]

S. Gueron. RWC 2013 15

This is

fixed

So this is

also fixed

Page 16: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

AES-GCM dirty secrets revealed A new interpretation to GHASH operations

• Not what you expected: GHASH does not use GF(2128) computations

– At least not in the usual polynomial representation convention

– The bits inside the 128-bit operands are reflected

– Actually - it is an operation on a permutation of the elements of GF(2128)

• T1 = reflect (A)

• T2 = reflect (B)

• T3 = T1 × T2 modulo x128 + x7 + x2 + x + 1 (a GF(2128) multiplication)

• Reflect (T3)

• We can prove (a new interpretation) that this operation is:

– A × B × x-127 mod x128 + x127+x126+x121 + 1

– i.e., a weird Montgomery Multiplication in GF(2128) modulo a reversed poly

– Better written as

– A × B × x × x-128 mod x128 + x127+x126+x121 + 1

S. Gueron. RWC 2013 16

No need to reflect the data

Page 17: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

The Shift-XOR reflected reduction (Gueron Kounavis 2009)

S. Gueron. RWC 2013

CipherText HKey

X1 X0 X2 X3

X1 X0 X2 X3

1

17

Page 18: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

S. Gueron. RWC 2013

X0

X0

X0

A

B

C

X1

63

62

57

D X0

D X0

D X0

1

2

7

E0 E0

F0 F0

G0 G0

18

Page 19: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

S. Gueron. RWC 2013

E0 E0

F0 F0

G0 G0

X2 X3

H0 H0

19

Voila

Page 20: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Algorithm 4: “Montgomery reduction”

Input 256-bit operand [X3:X2:X1:X0]

[A1:A0] = X0 • 0xc200000000000000

[B1:B0] = [X0⊕A1:X1⊕A0]

[C1:C0] = B0 • 0xc200000000000000

[D1:D0] = [B0⊕C1:B1⊕C0]

Output: [D1⊕X3:D0⊕X2]

Fast reduction modulo x128+x127+x126+x121+1 (Gueron 2012)

S. Gueron. RWC 2013 20

The cost: 2 x PCLMULQDQ 3 x shift/xor Ideal with fast PCLMULQDQ

; Input is in T1:T7

vmovdqa T3, [W]

vpclmulqdq T2, T3, T7, 0x01

vpshufd T4, T7, 78

vpxor T4, T4, T2

vpclmulqdq T2, T3, T4, 0x01

vpshufd T4, T4, 78

vpxor T4, T4, T2

vpxor T1, T4 ; result in T1

Page 21: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

S. Gueron. RWC 2013 21

X0

A0 A1

X1 X0

B0 B1

0xc200000000000000

B0

C0 C1

B1 B0

D0 D1

0xc200000000000000

X2 X3

X1 X0 X2 X3

CipherText Hkey’

H0 H1

The optimized reflected reduction

Voila

Page 22: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Aggregated Reduction

The Ghash operation is:

MM (CT1 , Hx”m”) + MM (CT 2 , Hx”m-1”) + … + MM (CT m , Hx)

mod x128 + x127+x126+x121 + 1

• In a Horner form (facilitating iterative computation)

• Yi = MM [(Xi + Yi-1), Hx] …everything mod Q= x128 + x127 + x126 + x121 + 1

• 4-way expanded Horner form (aggregate results & defer the reduction step)

– Yi = MM [(Xi + Yi-1) , Hx] = MM [(Xi , Hx) ] + MM [(Yi-1 , Hx)]

= MM [(Xi , Hx)] + MM [(Xi-1+ Yi-2) , Hx”2”] =

= MM [(Xi , H)] + MM [(Xi-1 , Hx”2”)] + MM [(Xi-2+Yi-3) , Hx”3”]

= MM [(Xi , Hx)] + MM [(Xi-1 , Hx”2”)] + MM [(Xi-2 , Hx”3”)] + MM [(Xi-3+Yi-4) , Hx”4”]

– Can be expanded further

– The gain: reduction deferred to once per “N” blocks

– Overhead: pre-calculate the powers of H (amortized for reasonably long buffer)

S. Gueron. RWC 2013 22

Page 23: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Interleaving CTR and GHASH

• There are two approaches to GCM

– Use dedicated AES-CTR function for the encryption and another GHASH function to generate the MAC

– Gain additional performance by interleaving the calculation of CTR and GHASH in a single function

• The first approach can only achieve the performance of “CTR+GHASH”

• The second approach achieves a better performance

– Filling the execution pipe more efficiently.

S. Gueron. RWC 2013 23

Page 24: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

The new AES-GCM patches (2012) putting it (and more…) all together

• Sept./Oct. 2012: We published two patches for two popular open source distributions: OpenSSL and NSS • NSS patch to be committed into version 3.14.2

• Both patches share similar code and use :

– Carry-less Karatsuba multiplication

– Reduce using “Montgomery”

– Encrypt 8 counter blocks

– Deferred reduction (using 8 block aggregation)

– Fixed elements outside the brackets

– Interleave CTR and GHASH

• Inherently side channel protected

– “constant time” in the strict definition

• Fast on current processors (2nd and 3rd Generation Core)

• And also ready to boost on the coming processors (4th Generation Core)

S. Gueron. RWC 2013 24

Page 25: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Results The performance of AES-128 GCM Encryption on 4KB buffer in CPU cycles per Byte,

Intel® Core™ i7-2600K vs. Intel® Core™ i7-880 Processor, Lower is better

S. Gueron. RWC 2013

* E. Käsper, P. Schwabe, Faster and Timing-Attack Resistant AES-GCM,

http://homes.esat.kuleuven.be/~ekasper/papers/fast_aes_slides.pdf

10.42

3.90

2.53

0.00 2.00 4.00 6.00 8.00 10.00 12.00

Best known AES-GCM without AES-NI* on i7-2600K Processor

Performance on Intel® Core™ i7-880 Processor

Performance on Intel® Core™ i7-2600K Processor

25

Page 26: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Some breakdown

• AES-GCM:

– 4KB message: 2.53 C/B

– 16KB message: 2.47 C/B

• Breakdown

– CTR performance for 16KB: 0.79 C/B

– The cost of the GHASH is ~1.68 C/B

• ~68% of the computations

– The performance of standalone GHASH is 1.75 C/B

• The delta is the gain from interleaving GHASH with CTR.

• Notes: the MAC computations are still significant – Limited by the current performance of PCLMULQDQ

– Ultimate goal: achieve AES-GCM at the performance of CTR+ ε

S. Gueron. RWC 2013 26

Page 27: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

The NSS patch (2012)

S. Gueron. RWC 2013 27

The performance of NSS AES GCM Encryption on 8KB buffer in CPU cycles per Byte, Intel®

Core™ i7-2600K and Intel® Core™ i7-3770 Processors, Lower is better

55.42 53.67

2.70 2.66

0.00

10.00

20.00

30.00

40.00

50.00

60.00

Core i7-2600K Core i7-3770

NSS 3.14 RC0

Our patch

Ready to boost performance on the coming processors generation (4th Generation Core)

Page 28: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

The OpenSSL patch (2012)

S. Gueron. RWC 2013 28

2.89 2.88 2.69 2.64

0.00

0.50

1.00

1.50

2.00

2.50

3.00

3.50

Core i7-2600K Core i7-3770

OpenSSL 1.0.1c

Our patch

The performance of OpenSSL AES GCM Encryption on 8KB buffer in CPU cycles per Byte, Intel®

Core™ i7-2600K and Intel® Core™ i7-3770 Processors, Lower is better

Ready to boost performance on the coming processors generation (4th Generation Core)

Page 29: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

What does it give? AES-GCM vs. other (NIST standard) Authenticated Encryption

16.80

15.57

9.46 8.97

6.16 5.59

2.47 2.42

0.00

2.00

4.00

6.00

8.00

10.00

12.00

14.00

16.00

18.00

Core i7-2600K Core i7-3770

AES CBC+HMAC-SHA256 (serial)

RC4-SHA1

AES CBC+HMAC-SHA1

AES GCM

The performance of NSS AES GCM Encryption on 32KB buffer in CPU cycles per

Byte, Intel® Core™ i7-2600K and Intel® Core™ i7-3770 Processors, Lower is better

S. Gueron. RWC 2013 29

Page 30: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

Summary

• AES-GCM is the best performing Authenticated Encryption combination among the NIST standard options (esp. compared to using HMAC SHA-1)

• SE on x86-64

• + Performance keeps improving across CPU generations

• Just wait for the coming “4th Generation Core” (2013)

• We try to actively help the eco-system move to the more efficient AE

• With some luck, we might see significant deployment already in 2013

• Optimized algorithms & implementations released as patches for Open Source

• Thanks to Google/Mozilla/RedHat colleagues

• Review and commit to NSS; add TLS1.2; enable Firefox / Chrome support

• The ultimate goal: achieve AES-GCM at the performance of CTR+ ε • All the codes and papers are publicly available (see reference)

S. Gueron. RWC 2013 30

Page 31: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

References

S. Gueron. RWC 2013 31

Page 32: AES-GCM for Efficient Authenticated Encryption – Ending the Reign of HMAC-SHA-1?

References

AES-GCM (The algorithms and methods that underlie the AES-GCM patches codes are detailed in references [1-4])

1. S. Gueron, Michael E. Kounavis: Intel® Carry-Less Multiplication Instruction and its Usage for Computing the GCM Mode (Rev. 2.01) http://software.intel.com/sites/default/files/article/165685/clmul-wp-rev-2.01-2012-09-21.pdf

2. S. Gueron, M. E. Kounavis: Efficient Implementation of the Galois Counter Mode Using a Carry-less Multiplier and a Fast Reduction Algorithm. Information Processing Letters 110: 549û553 (2010).

3. S. Gueron: AES Performance on the 2nd Generation Intel Core Processor Family (to be posted) (2012).

4. S. Gueron: Fast GHASH computations for speeding up AES-GCM (to be published soon) (2012).

AES-NI

5. S. Gueron. Intel Advanced Encryption Standard (AES) Instructions Set, Rev 3.01. Intel Software Network. http://software.intel.com/sites/default/files/article/165683/aes-wp-2012-09-22-v01.pdf

6. S. Gueron. Intel's New AES Instructions for Enhanced Performance and Security. Fast Software Encryption, 16th International Workshop (FSE 2009), Lecture Notes in Computer Science: 5665, p. 51-66 (2009).

OpenSSL patch:

• S. Gueron, V. Krasnov, “[PATCH] Efficient implementation of AES-GCM, using Intel's AES-NI, PCLMULQDQ instruction, and the

Advanced Vector Extension (AVX). http://rt.openssl.org/Ticket/Display.html?id=2900&user=guest&pass=guest (2012)

NSS patch:

• S. Gueron, V. Krasnov, “Efficient AES-GCM implementation that uses Intel's AES and PCLMULQDQ instructions (AES-NI), and the Advanced Vector Extension (AVX) architecture. For the NSS library”, Attachment 673021 Details for Bug 373108, [PATCH] https://bugzilla.mozilla.org/show_bug.cgi?id=805604#c0 (2012)

S. Gueron. RWC 2013 32