21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

On systems that support MCF through crypt( ), * you can simply use crypt( ) as discussed<br />

in Recipe 8.9 with some modification to the required salt. Otherwise, you can<br />

use the implementation in this recipe.<br />

Discussion<br />

What we are doing here isn’t really encrypting a password. Actually,<br />

we are creating a password validator. We use the term encryption<br />

because it is in common use and is a more concise way to explain the<br />

process.<br />

MCF is a 7-bit encoding that allows for encoding multiple fields into a single string.<br />

A dollar sign delimits each field, with the first field indicating the algorithm to use by<br />

way of a predefined number. At present, only two well-known algorithms are<br />

defined: 1 indicates MD5 and 2 indicates Blowfish. The contents of the first field also<br />

dictate how many fields should follow and the type of data each one contains. The<br />

first character in an MCF string is always a dollar sign, which technically leaves the<br />

0th field empty.<br />

For encoding MD5 in MCF, the first field must contain a 1, and two additional fields<br />

must follow: the first is the salt, and the second is the MD5 checksum that is calculated<br />

from a sequence of MD5 operations based on a nonintuitive process that<br />

depends on the value of the salt and the password. The intent behind this process<br />

was to slow down brute-force attacks; however, we feel that the algorithm is needlessly<br />

complex, and there are other, better ways to achieve the same goals.<br />

As with the traditional DES-based crypt( ), we do not recommend<br />

that you use MD5-MCF in new authentication systems. You should<br />

use it only when you must maintain compatibility with existing systems.<br />

We recommend that you consider using something like PBKDF2<br />

instead. (See Recipe 8.11.)<br />

The function spc_md5_encrypt( ) implements a crypt( )-like function that uses the<br />

MD5-MCF method that we’ve described. If it is successful (the only error that should<br />

ever occur is an out-of-memory error), it will return a dynamically allocated buffer<br />

that contains the encrypted password in MCF.<br />

In this recipe, we present two versions of spc_md5_encrypt( ) in their entirety. The<br />

first uses OpenSSLand standard C runtime functions; the second uses the native<br />

Win32 API and CryptoAPI.<br />

* FreeBSD, Linux, and OpenBSD support MCF via crypt( ). Darwin, NetBSD, and Solaris do not. Windows<br />

also does not because it does not support crypt( ) at all.<br />

Performing Password-Based Authentication with MD5-MCF | 403<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!