Optimizing computation of Hash-Algorithms as an attacker. Version 1.0-2013.05.12



Similar documents
Message Authentication

Cryptography and Network Security Chapter 12

AD Image Encryption. Format Version 1.2

Chair for Network Architectures and Services Department of Informatics TU München Prof. Carle. Network Security. Chapter 13

Overview of Cryptographic Tools for Data Security. Murat Kantarcioglu

Message Authentication Codes. Lecture Outline

CSCE 465 Computer & Network Security

Authentication requirement Authentication function MAC Hash function Security of

Securing Password Storage Increasing Resistance to Brute Force Attacks

Project: Simulated Encrypted File System (SEFS)

Designing Hash functions. Reviewing... Message Authentication Codes. and message authentication codes. We have seen how to authenticate messages:

SeChat: An AES Encrypted Chat

Jeremi M Gosney Founder & CEO, Stricture Consulting Group

Lecture 4 Data Encryption Standard (DES)

Message authentication

Chapter 11 Security+ Guide to Network Security Fundamentals, Third Edition Basic Cryptography

Hash Function JH and the NIST SHA3 Hash Competition

Computer Security: Principles and Practice

IPsec Details 1 / 43. IPsec Details

Cryptographic Hash Functions Message Authentication Digital Signatures

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Disk encryption... (not only) in Linux. Milan Brož

CIS433/533 - Computer and Network Security Cryptography

Cryptography Lecture 8. Digital signatures, hash functions

Cryptography and Network Security Chapter 11

Speeding up GPU-based password cracking

Fundamentals of Computer Security

Binary Adders: Half Adders and Full Adders

Secure Password Managers and Military-Grade Encryption on Smartphones: Oh, Really? Andrey Belenko and Dmitry Sklyarov Elcomsoft Co. Ltd.

Table of Contents. Bibliografische Informationen digitalisiert durch

Secret File Sharing Techniques using AES algorithm. C. Navya Latha Garima Agarwal Anila Kumar GVN

Network Security. Security. Security Services. Crytographic algorithms. privacy authenticity Message integrity. Public key (RSA) Message digest (MD5)

Hash Functions. Integrity checks

ELECTENG702 Advanced Embedded Systems. Improving AES128 software for Altera Nios II processor using custom instructions

PKCS #5 v2.1: Password-Based Cryptography Standard

Common Pitfalls in Cryptography for Software Developers. OWASP AppSec Israel July The OWASP Foundation

Accellion Secure File Transfer Cryptographic Module Security Policy Document Version 1.0. Accellion, Inc.

Solutions to Problem Set 1

The Advanced Encryption Standard (AES)

Secure Shell SSH provides support for secure remote login, secure file transfer, and secure TCP/IP and X11 forwarding. It can automatically encrypt,

Network Security. Modes of Operation. Steven M. Bellovin February 3,

Message Authentication Codes

What users should know about Full Disk Encryption based on LUKS

How encryption works to provide confidentiality. How hashing works to provide integrity. How digital signatures work to provide authenticity and

How To Encrypt With A 64 Bit Block Cipher

Network Security Technology Network Management

Password-based encryption in ZIP files

Cryptography and Network Security

Overview of Symmetric Encryption

WIRELESS LAN SECURITY FUNDAMENTALS

The Misuse of RC4 in Microsoft Word and Excel

EXAM questions for the course TTM Information Security May Part 1

SecureDoc Disk Encryption Cryptographic Engine

Developing and Investigation of a New Technique Combining Message Authentication and Encryption

Cryptography and Network Security Block Cipher

Advanced Encryption Standard by Example. 1.0 Preface. 2.0 Terminology. Written By: Adam Berent V.1.5

Dashlane Security Whitepaper

A low-cost Alternative for OAEP

HASH CODE BASED SECURITY IN CLOUD COMPUTING

Processing Multiple Buffers in Parallel to Increase Performance on Intel Architecture Processors

SHA3 WHERE WE VE BEEN WHERE WE RE GOING

SkyRecon Cryptographic Module (SCM)

Thinking of a (block) cipher as a permutation (depending on the key) on strings of a certain size, we would not want such a permutation to have many

Symmetric and Public-key Crypto Due April , 11:59PM

lundi 1 octobre 2012 In a set of N elements, by picking at random N elements, we have with high probability a collision two elements are equal

Advanced Encryption Standard by Example. 1.0 Preface. 2.0 Terminology. Written By: Adam Berent V.1.7

Public Key Cryptography Overview

Cryptography and Network Security Chapter 3

Waspmote Encryption Libraries. Programming guide

Protection Profile for Full Disk Encryption

SENSE Security overview 2014

Cryptography and Network Security Chapter 11. Fourth Edition by William Stallings


FIPS Non Proprietary Security Policy: Kingston Technology DataTraveler DT4000 Series USB Flash Drive

Password Cracking Beyond Brute-Force

Cryptographic hash functions and MACs Solved Exercises for Cryptographic Hash Functions and MACs

Error oracle attacks and CBC encryption. Chris Mitchell ISG, RHUL

PLATFORM ENCRYPTlON ARCHlTECTURE. How to protect sensitive data without locking up business functionality.

Let s put together a Manual Processor

How To Encrypt Data With A Power Of N On A K Disk

Secure Network Communications FIPS Non Proprietary Security Policy

Introduction...3 Terms in this Document...3 Conditions for Secure Operation...3 Requirements...3 Key Generation Requirements...

Password Manager with 3-Step Authentication System

The Keyed-Hash Message Authentication Code (HMAC)

SELF SERVICE RESET PASSWORD MANAGEMENT ARCHITECTURE GUIDE

IJESRT. [Padama, 2(5): May, 2013] ISSN:

Client Server Registration Protocol

Encrypting Network Traffic

Modern Block Cipher Standards (AES) Debdeep Mukhopadhyay

How To Understand And Understand The History Of Cryptography

Efficient Software Implementation of AES on 32-bit Platforms

Passwords the server side

Lecture Note 8 ATTACKS ON CRYPTOSYSTEMS I. Sourav Mukhopadhyay

IT Networks & Security CERT Luncheon Series: Cryptography

SYMMETRIC ENCRYPTION. Mihir Bellare UCSD 1

The State of Modern Password Cracking

Using TrueCrypt to protect data

Transcription:

Optimizing computation of Hash-Algorithms as an attacker Version 1.0-2013.05.12

Name: Nick: Jens Steube atom About me Coding Projects: hashcat / oclhashcat Work Status: Employed as Coder, not crypto- or security-relevant Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 2

In the context of password guessing the computation of hash-algorithms can be optimized so that an attacker needs less work to do then a defender. The reason is that hash-algorithms typically are not designed to protect passwords - but developers use them to do it since decades. This situation leads to optimizations that are possible for an attacker that the autors of the hash-algorithms never tried to avoid. Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 3

General Techniques Overview Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 4

General Techniques Technique Zero-based optimizations Early-exit optimizations Initial-step optimizations Precomputing Reversing aka Meet-in-the-middle NOTE Some of the techniques in these slide are known, some are not All of them are used in oclhashcat-lite Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 5

Zero-based optimizations General Techniques Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 6

From computers view, passwords are just numbers The password 'password' takes two 32-bit integers 0000000: 70617373 776f7264 password Zero-based optimizations It is copied to the algorithms input data block Typically fixed 512-bit, padded with zeros 0000000: 70617373 776f7264 00000000 00000000 password... 0000010: 00000000 00000000 00000000 00000000... 0000020: 00000000 00000000 00000000 00000000... 0000030: 00000000 00000000 00000000 00000000... The above buffer shows the w[] array build out of the 16 elements Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 7

The password 'password' only took w[0] and w[1] to be populated, the rest are zero Zero-based optimizations 0000000: 70617373 776f7264 00000000 00000000 password... 0000010: 00000000 00000000 00000000 00000000... 0000020: 00000000 00000000 00000000 00000000... 0000030: 00000000 00000000 00000000 00000000... This is how a single step function from the MD4 F() is calculated: #define FF(a,b,c,d,x,s) a += F (b, c, d) + x;... The function is called 16 times, each call using a different element of the input vector Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 8

#define FF(a,b,c,d,x,s) a += F (b, c, d) + x;... Zero-based optimizations If x is 0 then there is no change in that last addition If the password only has the length 8, we know that w[2] - w[15] are zero For all function calls that use w[2] - w[15] we can remove the addition completely Note that most algorithms fill w[14] or w[15] in final() Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 9

Conclusion Zero-based optimizations NOTE In MD4, this saves (on passwords < length 12) a total of 36 / 128 ADD instructions In MD5, this saves (on passwords < length 12) a total of x / 128 ADD instructions TBD, add more hash-algorithms AFAIK, this technique works on all raw hashing algorithms HMAC defeats this Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 10

Initial-step optimizations General Techniques Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 11

Here is a snippet from MD5 a = 0x67452301; b = 0xefcdab89; c = 0x98badcfe; d = 0x10325476; Initial-step optimizations FF (a, b, c, d, w[0], 7, 0xd76aa478); FF (d, a, b, c, w[1], 12, 0xe8c7b756); FF (c, d, a, b, w[2], 17, 0x242070db); FF (b, c, d, a, w[3], 22, 0xc1bdceee);... The MD5 step macro looks like MD4 step macro in the beginning #define FF(a, b, c, d, x, s, ac) a += F (b, c, d) + x + ac; Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 12

a = 0x67452301; b = 0xefcdab89; c = 0x98badcfe; d = 0x10325476; FF (a, b, c, d, w[0], 7, 0xd76aa478); Initial-step optimizations The only unknown part in the first step is w[0] All the other data is known We can replace the original MD5 step macro: #define FF(a, b, c, d, x, s, ac) a += F (b, c, d) + x + ac;... With this one: #define FF(a, b, c, d, x, s, ac) a = 0xd76aa477 + x;... Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 13

Conclusion Initial-step optimizations Per step 1 In MD4, this saves 6 instructions (x AND, x NOT, x OR, x ADD) In MD5, this saves 6 instructions (x AND, x NOT, x OR, x ADD) TBD, add more hash-algorithms The next 3 steps can also be optimized like this Note that HMAC does not defeat this Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 14

Early-exit optimizations General Techniques Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 15

Here is a snippet from the last 4 steps of MD5 II (a, b, c, d, w[ 4], S41, 0xf7537e82); /* 61 */ II (d, a, b, c, w[11], S42, 0xbd3af235); /* 62 */ II (c, d, a, b, w[ 2], S43, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, w[ 9], S44, 0xeb86d391); /* 64 */ Early-exit optimizations state[0] += a; state[1] += b; state[2] += c; state[3] += d; Again, in password guessing, the password is to short to force a second transform Thus, we know the value of state[0], which is 0x67452301 in MD4/MD5/SHA1 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 16

Early-exit optimizations We know the value of state[0], which is 0x67452301 in MD4/MD5/SHA1 We simply subtract that constant from the hash we want to guess Example, if our hash is 8743b52063cd84097a65d1633f5c74f5, then we can do: hash[0] = 0x8743b520-0x67452301 = 0x1ffe921f Note that we do not need to be afraid to underflow the integer. Actually, this is exactly what hashes do, too Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 17

hash[0] = 0x8743b520-0x67452301 = 0x1ffe921f Early-exit optimizations Since a does not change anymore after step 61 in MD5 we can do the comparison that makes this optimization an earlyexit II (a, b, c, d, w[ 4], S41, 0xf7537e82); /* 61 */ if (a!= hash[0]) return - 1; II (d, a, b, c, w[11], S42, 0xbd3af235); /* 62 */ II (c, d, a, b, w[ 2], S43, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, w[ 9], S44, 0xeb86d391); /* 64 */ Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 18

Conclusion Early-exit optimizations We can skip 3 entire steps In MD5, this means 30 instructions In MD4, this means 20 instructions TBD, add more hash-algorithms Note that Keccak is safe from this Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 19

Precomputing General Techniques Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 20

Precomputing This technique heavily depends on how much memory we have and how fast it is to lookup a value from a table Keep our eyes open to see chances for precomputation Typically they give high rates of optimization Good examples for this is the Whirlpool and Oracle (old) hash, we'll focus them later Example following Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 21

Assume we want to compute a SHA256 and we have a candidate generator that only changes the last characters of the password In other words, do not change the first 4 characters in w[0] If w[0] does not change, in step 1 we see: Precomputing t1 = H + S1(E) + Ch(E,F,G) + K[0] + W[0]; t2 = S0(A) + Maj(A,B,C); H = G; G = F; F = E; E = D + t1; D = C; C = B; B = A; A = t1 + t2; Since A - H and K[0] are all constants and w[0] does not change, we can precompute the new values for A and D completely In the inner loop, we can start from step2 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 22

Partial reversing / Meet-in-the-middle General Techniques Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 23

This technique can not reverse back to it s original password, but it can be used to speed up the computation Partial reversing / Meet-in-themiddle There is that statement that MD5 is a one-way function. It s true and it s not true; In case we have the original data used to generate the MD5 digest we -can- reverse the digest back to the original MD5 initial values This works for MD4 and SHA1, too, maybe more But in password guessing, how does that make any sense since what we don't have is exactly the original data? Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 24

When we generate password candidates in our password guesser, we can generated them in a specific way Partial reversing / Meet-in-themiddle Assume we have a generator that only changes the first 4 characters of a password and hold the rest stay constant AAAApass AAABpass ZZZZpass As a result, we change only w[0] and w[1] w[15] stay constant Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 25

Partial reversing / Meet-in-themiddle In the outer loop The goal is to reverse back the algorithm steps as long w[0] is not required to compute that specific step Store the intermediate digest of that specific step In the inner loop Start the normal "forward" computation of the hash Once we hit the step 1.1 on which we calculated the intermediate digest we can stop the computation Compare the digest with the intermediate digest from step 1.2 If it does not match there is no need to continue to calculate the rest of the steps. This is what gives the speed boost Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 26

Targeted Algorithms Overview Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 27

Targeted Algorithms Algorithm MD4 MD5 SHA1 NetNTLMv1 Whirlpool Oracle (DES) HMAC Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 28

MD4 Targeted Algorithms Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 29

MD4 Used in MD4 (raw) NTLM Domain Cached Credentials Domain Cached Credentials2 NetNTLMv1 NetNTLMv2 Techniques Zero-based optimizations Initial-step optimizations Early-exit optimizations Precomputing Partial reversing / Meet-inthe-middle Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 30

MD4 It's a good example how to do all the techniques, especially the partial reversing As mentioned in the technique description we need to reverse the hash to a specific step This step is where w[0] is set the last time in the algorithm In case of MD4, it is step 33 HH (a, b, c, d, w[0], S31); Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 31

Here's the original HH step macro of MD4: MD4 #define HH(a, b, c, d, x, s) a += 0x6ed9eba1; a += x; a += H (b, c, d); a = ROTATE_LEFT (a, s); And the reversal is just an inverted function: #define HH_REV(a, b, c, d, x, s) a = ROTATE_RIGHT (a, s); a -= H (b, c, d); a -= x; a -= 0x6ed9eba1; Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 32

MD4 We call the inverted function from the last step back to step 34 HH_REV (d, a, b, c, w[ 8], S32); /* 34 */ We can not reverse more at this point since w[0] is unknown in the outer loop HH_REV (a, b, c, d, w[ 0], S31); /* 33 */ What we now have is the last intermediate value of D. This means we can do the comparison of D when it was set the last time which is: GG (d, a, b, c, w[ 7], S22); /* 30 */ Note that our meet-in-the-middle comparison is to do after step 30 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 33

In our inner loop, we just compute MD4 forward: FF (a, b, c, d, x[ 0], S11); /* 1 */ FF (d, a, b, c, x[ 1], S12); /* 2 */ FF (c, d, a, b, x[ 2], S13); /* 3 */ MD4 Now we can do the compare at step 30 GG (a, b, c, d, x[ 3], S21); /* 29 */ GG (d, a, b, c, w[ 7], S22); if (d!= d_rev) return -1; If d does not match, there is no need to continue the computation Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 34

NOTE MD4 Actually it s possible to reverse this even more but this takes more explanation oclhashcat-lite does it s meet-in-the-middle comparison after step 26 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 35

Conclusion MD4 We only need to calculate 30 of 48 steps due to the reversing resulting in 33% speed increase All other optimization techniques will also apply, but in combination with reversing they do not make sense, except the Initial-step optimization Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 36

MD5 Targeted Algorithms Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 37

MD5 Used in MD5 (raw) Everywhere Techniques Zero-based optimizations Initial-step optimizations Early-exit optimizations Precomputing Partial reversing / Meet-inthe-middle Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 38

The partial reversing works like in MD4 The inverted function looks a bit different MD5 #define II_REV(a, b, c, d, x, s, ac) a -= b; a = ROTATE_RIGHT (a, s); a -= I (b, c, d); a -= x; a -= ac; Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 39

Conclusion We only need to calculate 46 of 64 steps MD5 NOTE It s possible to reverse this even more but this takes more explanation oclhashcat-lite does it s meet-in-the-middle comparison after step 43 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 40

SHA1 Targeted Algorithms Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 41

SHA1 Used in SHA1 (raw) Everywhere Techniques Zero-based optimizations Initial-step optimizations Early-exit optimizations Precomputing Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 42

SHA1 I've already published a very specific optimization technique for SHA1 that is a form of precomputing at Passwords^12 It works by reducing the number of XOR's that are required in the key-stretching phase and gains a total of 22% in performance increase It s too much to explain the details in this presentation. For details, please take a look at this PDF: http://hashcat.net/p12/js-sha1exp_169.pdf There is another optimization for SHA1 based on early-exits You can use it as a standalone optimization in case you can not use the XOR based optimization and you can use it in combination with it. Both variants work Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 43

SHA1's step macro is a bit different to MD4 / MD5 It sets both B and E (not just A) for each step SHA1 #define F4(f,a,b,c,d,e,x) e += 0xca62c1d6; e += x; e += b ^ c ^ d; e += ROTATE_LEFT (a, 5); b = ROTATE_LEFT (b, 30); Typical implementation of the last steps looks like: F4 (d, e, a, b, c, w[77]); F4 (c, d, e, a, b, w[78]); F4 (b, c, d, e, a, w[79]); Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 44

From looking at the code one would say we can early-exit is in step 77, checking for E That s correct, but we can do more. Take a close look again at the step: b = ROTATE_LEFT (b, 30); SHA1 All it does is a simple rotate. Therefore we have no loss of information at all We know E at the end (from our hash) so we can pre-reverse it e = ROTATE_RIGHT (e, 30); Now, instead of doing an early-exit at step 77, we can do the early-exit at step 75 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 45

Conclusion SHA1 22% increase due to XOR optimization Another 4 steps saved due to extended early-exit optimization Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 46

NetNTLMv1 Targeted Algorithms Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 47

NetNTLMv1 Used in Windows Networks File Shares SAMBA Technique Early-exit Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 48

NetNTLMv1 Even if it s just an early-exit, it s an early-exit with big impact To explain it, it s important to explain how to algorithm works NOTE Examples takes from hashcat.net forum Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 49

The algorithm work by generating an NTLM hash out of the password hashcat -> b4b9b02e6f09a9bd760f388b67351e2b This hash is then broken into 3 x 56 bit parts and padded with zeros NetNTLMv1 b4b9b02e6f09a9 bd760f388b6735 1e2b0000000000 Each 56 bit part is odd parity adjusted to result in 3 x 64 bit parts b4b9b02e6f09a9 -> b55d6d04e6792652 bd760f388b6735 -> bcba83e6895b9d6b 1e2b0000000000 -> 1f15c10101010101 NOTE: MD4 outputs only 128 bit, the third part uses only 16 bits Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 50

Each of these part is then used as a key to DES encrypt the 8 byte challenge resulting in 3 ciphertext blocks: b55d6d04e6792652 KEY-> DES(1122334455667788) -> 51a539e6ee061f64 bcba83e6895b9d6b KEY-> DES(1122334455667788) -> 7cd5d48ce6c68665 1f15c10101010101 KEY-> DES(1122334455667788) -> 3737c5e1de26ac4c NetNTLMv1 The key of the DES buffer that results in the 3737c5e1de26ac4c is limited to a keyspace of only 64k possible variants This is such a tiny keyspace so that we can brute-force it in the startup phase on CPU typically in less than a second Once we found the input key, we know the last 16 bit of the NTLM that was used to generate the NetNTLMv1 hash is 0x1e2b Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 51

Instead of doing all these steps again and again for each candidate, all we need to do is to generate the NTLM hash Then we do: NetNTLMv1 if ((d & 0xffff)!= d_pre) break; Once it passes this comparison (with a chance of 2^16) we continue to calculate the hash the original way Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 52

Conclusion NetNTLMv1 By doing this optimization we can crack NetNTLMv1 by nearly the same speed as an NTLM plus we still can use Zero-based optimizations and Initial-step optimizations to speed up the NTLM computation Especially on GPU s this optimization helps a lot since this save the expensive s-box lookups from DES The performance gain is massive and it s hard to calculate, but it s at least 5-10 times faster than without the optimization, maybe more Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 53

whirlpool Targeted Algorithms Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 54

Used in TrueCrypt Technique Precomputing whirlpool Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 55

whirlpool In whirlpool we can precompute all the rounds of K[] which takes 50% of the entire whirlpool computation otherwise K[] is based on the initial hash value, which is always 0 at start. For each round it s doing some s-box lookups and XOR s them with the old value I've written a C program for precomputing, you can grab it here: http://hashcat.net/p13/whirlpool_pc_k.c Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 56

But we can do even more! Once we have K[] precomputed we can reverse our target hash as we did in the early-exits in MD5/SHA1: state[0] = digest_buf[0] ^ pc_k[10][0]; state[1] = digest_buf[1] ^ pc_k[10][1]; state[2] = digest_buf[2] ^ pc_k[10][2];... whirlpool Still there is more room for optimization. Since whirlpool does not use any arithmetic instructions but only bitwise there is no data loss that we can not reproduce That means if we use our special password candidates generator again that only changes w[0] in the inner loops, we can precompute all values of the first round of Whirlpool In the first iteration we have to "correct" the data from the precomputation. That is because w[0] changed slightly. Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 57

Conclusion Whirlpool Whirlpool can be optimized by more than 50% of the entire calculation The optimization works even when protected with HMAC Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 58

Oracle (old) Targeted Algorithms Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 59

Used in Oracle 7-10g Technique Precomputing Oracle (old) Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 60

Oracle (old) This algorithm uses a cipher not a hash to store the password The scheme is the following: Encryption is DES-CBC IV = 0x0000000000000000 KEY = 0x0123456789ABCDEF DATA = password In ciphers, to make cracking attempts slow, they have designed the keysetup phase to calculate slow In this algorithm is that part that should be the slow part, the keysetup, useless since it only the IV and the KEY and both of them are known :) We can precompute the slow part by 100%, the 16x 48-bit subkeys Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 61

Conclusion Oracle (old) Since the algorithm steps depend on the password length it s hard to say how much time is saved Again, especially on GPU s this optimization helps alot since this save the expensive s-box lookups from DES Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 62

HMAC Targeted Algorithms Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 63

HMAC Used in TrueCrypt WPA/WPA2 1password LUKS LastPass DCC2 PBKDF2 (always used) Technique Precomputing Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 64

HMAC Most important to say here, HMAC is not an algorithm itself. HMAC is a construction of a MAC (keyed hash) using a hash function We can call HMAC very important since it's used in many important algorithms to protect passwords It also defeats zero-based optimizations HMAC definition is simple HMAC (K,m) = H ((K ^ opad) H ((K ^ ipad) m)) Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 65

HMAC Because of the HMAC paddings of the ipad and the opad, we have a special situation The HMAC fills this buffer by it s definition with 0x363636363636... and 0x5c5c5c5c5c5c5... and then XOR's the password on it This construct completely fills the buffers so that we have all data ready to run the first call to the selected hash transform We do this as soon we know the final password and then cache the results of both ipad and opad for later usage Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 66

Conclusion HMAC Reduces the number of calls to H() by 2 for each iteration Number of calls to H() in WPA/WPA2 is 4, lead to a performance increase of 50% compared to defender Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 67

Failed custom schemes Overview Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 68

Application IPB2 1Password Failure type Salt integration Block-chaining Failed custom Schemes Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 69

IPB2 Failed custom schemes Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 70

Used in Invision Power Board Technique Precomputing IPB2 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 71

This is simple to explain The IPB2 scheme is defined as IPB2 md5 (md5 (salt) + md5 (pass)) Since the salt is known, we can precompute it after loading the hash Attacker requires just 2 calls to H() but defender requires 3 Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 72

IPB2 Conclusion Performance increased by > 30% Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 73

1Password Failed custom schemes Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 74

Used in AgileBits 1Password Techniques Early-exit Precomputing 1Password Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 75

1Password This is an example of how an algorithm was designed in a way where the designer was lacking the vision of an attacker 1Password uses PBKDF2-HMAC-SHA1 to derive a 256 bit key PBKDF2 can be configured on how much bits of output to produce In this case it s HMAC-SHA1, but SHA1 outputs only 160 bits. So that means the defender has to run two rounds on SHA1 to produce 320 bits output and then let PBKDF2 truncates it to 256 bits 1Password then uses AES in CBC mode to decrypt 1040 byte of data To be exact, it takes the first 128 bit of the derived key to setup the AES key and takes another 128 bit as an IV for the CBC Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 76

1Password The goal is match the final padding block after decrypting 1040 byte of data. If you find the last four 32-bit integers at 0x10101010 the padding is correct and you know your key was correct But in combination with the CBC mode you use the IV only for the first decryption. You then replace it with the ciphertext of current block (which is used for the next block) Again, to validate the masterkey is correct, all we need is to match the padding value. To satisfy the CBC we just need the previous 16 byte of data from the 1040 byte block. We do have it already since it was provided by the keychain There is no need to calculate the IV at all Instead of calculating a 256 bit key in the PBKDF2, we just need to calculate 128 bit Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 77

Conclusion 1Password Using both optimizations, Early-exit (using HMAC optimization) plus only calculating 128 bits instead of 256 increased the performance of an attacker compared to the defender by 400% Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 78

Feel free to contact me! Thank you for listening! via Twitter: @hashcat via Hashcat forum: http://hashcat.net/forum/ via IRC: freenode #hashcat via Email: atom at hashcat.net Jens Steube - Optimizing computation of Hash-Algorithms as an attacker 79