7: Password-Hashing
Total Page:16
File Type:pdf, Size:1020Kb
7: Password-Hashing I Passwords, Passphrases, “Personal Identification Numbers” (PINs) are needed all the time user name: Max passwort: ******** I Can be part of a “two-factor-authentication” (e.g., chipcard + PIN) I Adversaries trying to “guess” them: I How probable is a pwd? I How to attack unknwon pwd by making X attempts to “guess” them I Which passwords are the X most probable ones? I How to choose pwd to thwart such attacks? I . while still being able to remember pwd? Our goal: Make the usage of passwords as secure as possible. –130– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash Preliminaries . speaking words of wisdom, let it be, let it be, . (The Beatles) I QUESTION: Which of the following passwords is OK? “53cur3 pa55w0rd”, “ci90n38!P0??3ah9vhv” or “123456”? user name: Max passwort: ******** I ANSWER: None! (Not after being shown on my slides . ) I Passwords must be unpredictable ... I BUT this is actually a property of password-generation and password-handling (random choices, not published on slides, . ) I information-theory: a “password-source” must have high entropy! I very informally: k-bit of entropy ≥ 2k−1 “guesses” for the attacker –131– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash Wisdom # 1: Choose “high-entropy” passwords! . this is harder than it looks –132– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash Wisdom # 2: Do not allow Offline Attacks! . whenever you can avoid them user name: Max passwort: ******** Online: Offline: I access to server I function F I adversary sends pwd-”guess” I adversary can compute F I server accepts or rejects without the server’s aid pwd-”guess” I F(pwd) = 1 , pwd accepted X: as large as the server allows X: as large as the adversary can and can handle afford –133– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash Wisdom #3: Passwords in the Clear are bad! . worse than leaving the key to your flat under the door-mat name pwd Anakin skywalker Dagobert moneymoneymoney Donald enwo34qindk!d Luke sykwalker Tick mysecretpassword Trick mysecretpassword Track mysecretpassword –134– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash Wisdom # 4: Hashing Passwords helps . but is not good enough name H(pwd) Anakin viqwbnqwtomwm Dagobert wer4mnrt4rnrm Donald r034jionksioe Luke viqwbnqwtomwm Tick sdjklasdle9nr Trick sdjklasdle9nr Track sdjklasdle9nr best attack: I assume “dictionary” with N “common” passwords I compute another dictionary with N hashed passwords I attacking each account in time O(1), if password is “common” –135– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash Wisdom # 5: Salt and Hash Passwords name salt H(salt, pwd) Anakin 34892 4unuiio8nuue7 Dagobert 29495 ksni9m8k89kiu Donald 09858 cdk5jkambydyu Luke 45888 xumun6muzyqjo Tick 19495 cnjk9mk3msdfk Track 27849 dekcexcidklc7 Trick 90479 yei7kmdkx2dcx best attack: I assume “dictionary” with N “common” passwords I attacking each account in time O(N), if password is “common” (if the salt never repeats) –136– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching Wisdom # 6: Perform “Key Stretching” I stretching by k bit I attacks slow down 2k times I “virtual” entropy goes from β to β + k I unfortunately, the defenders’ operations may also slow down by 2k times I so the idea is to I choose k as large as possible I without annoying the defender –137– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching Generate Password Hashes with Stretching log ( ) iteration: stretch by 2 N bit pepper: stretch by p bit input: pwd, salt, N input: pwd, salt, p X H(salt; pwd) choose random R < 2p for I 1 to N do X H(salt; R; pwd) X H(salt; X) return X end for return X –138– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching Verify Password Hashes verify iteration verify pepper input: pwd, salt, N; X 0 input: pwd, salt, p, X 0 X H(salt; pwd) choose random R0 < 2p for I 1 to N do for I 0 to 2p − 1 do X H(salt; X) R00 (R0 + I) mod 2p end for X 0 H(salt; R00; X) accept if X = X 0 else reject accept if X = X 0 end for reject Advantages and disadvantages: +iteration generation and verification are the same +pepper fast generation +pepper parallelizable (why is this an advantage for the defender, and not a disadvantage?) -pepper R must be random – and even secret (why?) –139– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching Iteration – Without Knowing the Count just let the user decide for herself unknown iteration verify unknown iteration input: pwd, salt, N input: pwd, salt, N, X X H(salt; pwd) X 0 H(salt; pwd) while true do while X 6= X 0 do X H(salt; X) X 0 H(salt; X) end while end while when exception: {user: ctrl-c} accept return X when exception: {user: ctrl-c} reject –140– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching Usage Scenarios for Password Scramblers I user authentication I key derivation I proof of work I ... These uses imply different attack models / security requirements! –141– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching History until 2010 1960s: Wilkes: plain passwords are bad ! store hash and compare 1978: unix crypt I 25 iterations of DES-like operation I 12 bit salt to hinder dictionary attacks 1980s: shadow passwords I store (user; salt; dummy) in File A I store H(pwd; salt) in File B 1995: Abadi, Lomas, Needham: pepper 1997: Kelsey, Schneier, Hall, Wagner: analyzed iteration 2007: Boyen: unknown iteration count 2010: Turan, Barker, Burr, Chen: First standard for KDFs (PBKDF1/2 – Password-Based Key Derivation Function) –142– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching Practical Password Scramblers and KDFs until 2010 1978: crypt: in UNIX-based systems based on DES (25 iterations), 12-bit salt 1995: md5crypt by Poul-Henning Kamp 64-bit salt, 1000 iterations of MD5 1995: bcrypt by Provos and Mazières based on Blowfish (Schneier, 1993) needs a significant (but constant) amount of memory: S-boxes (4 × 1024 Bytes) + subkey (72 Bytes)) 2010: PBKDF2 by NIST first standard for KDFs, can use hash function or block cipher –143– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching PBKDF2 Password-Based Key Derivation Function Two F(pwd, salt, N, i) I F is the core function PRF(Key, Input) is modelled U PRF(pwd; salt jj i32) I X U as a “pseudorandom for I 1 to N do function” U PRF(pwd; U)(∗) I Why is pwd used in every X X ⊕ U round? Isn’t that dangerous? end for I Should we replace line (∗) return X by U PRF(U)? I PRF could be instantiated by I a block cipher E: PRF(K ; U) = EK (U) I a MAC M: PRF(K ; U) = MK (U) I a hash function H: PRF(K ; U) = H(K jj U) I the HMAC-construction, using H in a nested way: PRF(K ; U) = H(K ⊕ const2 jj (H(K ⊕ const1 jj U)) –144– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching PBKDF2 can Generate Large Outputs relevant for key derivation I For a required number of output bits, PBKDF2 concatenates F(pwd; salt; N; 1) jj F(pwd; salt; N; 2) jj ::: truncating the final call to F(pwd; salt; N; i) to the required number of bits I Example WPA2: I PBKDF2 with PRF = HMAC-SHA-1 and N = 4096 iterations I output 256 bits, but HMAC-SHA-1 provides 160 bits I thus, call F twice I use all the 160 bits from F(pwd, salt, N; 1) I and the first 96 bits from F(pwd, salt, N; 2) –145– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.1: Key Stretching 7.2: Considering Memory Timeline 2009: scrypt (Percival) 2013: Catena (Forler, Lucks, Wenzel) 2013–2015: Password Hashing Competition 2015: Argon2 (Biryukov, Dinu, Khovratovich) wins competition 2015–now: theoretical results on amortised costs –146– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.2: Memory The Advance of Massively Parallel Commodity Hardware http://www.nvidia.com/object/what-is-gpu-computing.html I commodity hardware with an abundance of parallel cores I attacker can try out any number of password in parallel I defender is hashing a single password I also, defender does not always have so many cores –147– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.2: Memory Wisdom # 7: Storage is Expensive . use this, to make the adversary’s life harder CPU (Multiple Cores) GPU (Hundreds of Cores) Core 1 Core 2 Core 3 Core 4 Cache Cache similar cache and memory sizes RAM RAM Adversaries with cheap of-the-shelf parallelizable hardware (GPUs, FPGAs, . ) don not have much memory – especially fast cache-memory. The cost for expensive special-purpose hardware is driven up by memory costs. –148– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.2: Memory Memory-Hard Functions Percival (2009) I let f be a function which can be computed in time T using space S I consider a machine with S=k units of memory, instead of S Definition 12 A function f is memory-hard if computing f (x) with an input of size n needs S(n) space and T 0(n) units of operations, where S(n) ∗ T 0(n) 2 Ω T 0(n)2− for > 0. ≈ computing f with S=k units of memory takes kT operations –149– Stefan Lucks Hash Fun. (2019) 7: Passw.-Hash 7.2: Memory Sequentially Memory-Hard Functions Percival (2009) I if we consider physical “time” rather than number of operations, the speet-up on a parallel machine can be a concern Definition 13 A function f is sequentially memory-hard if (1) it is memory-hard and (2) it cannot be computed on a machine with S(n) processors and S(n) space in expected time T (n), where S(n) ∗ T (n) = O T (n)2− for any > 0.