]> git.saurik.com Git - apple/security.git/blob - AppleCSP/PBKDF2/pbkdf2.h
Security-179.tar.gz
[apple/security.git] / AppleCSP / PBKDF2 / pbkdf2.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 File: pbkdf2.h
21 Contains: Apple Data Security Services PKCS #5 PBKDF2 function declaration.
22 Copyright: (C) 1999 by Apple Computer, Inc., all rights reserved
23 Written by: Michael Brouwer <mb@apple.com>
24 */
25
26 #ifndef __PBKDF2__
27 #define __PBKDF2__
28
29 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* This function should generate a pseudo random octect stream
36 of hLen bytes long (The value hLen is specified as an argument to pbkdf2
37 and should be constant for any given prf function.) which is output in the buffer
38 pointed to by randomPtr (the caller of this function is responsible for allocation
39 of the buffer).
40 The inputs to the pseudo random function are the first keyLen octets pointed
41 to by keyPtr and the first textLen octets pointed to by textPtr.
42 Both keyLen and textLen can have any nonzero value.
43 A good prf would be a HMAC-SHA-1 algorithm where the keyPtr octets serve as
44 HMAC's "key" and the textPtr octets serve as HMAC's "text". */
45 typedef void (*PRF)(const void *keyPtr, UInt32 keyLen,
46 const void *textPtr, UInt32 textLen,
47 void *randomPtr);
48
49 /* This function implements the PBKDF2 key derrivation algorithm described in
50 http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-5.html
51 The output is a derived key of dkLen bytes which is written to the buffer
52 pointed to by dkPtr.
53 The caller should ensure dkPtr is at least dkLen bytes long.
54 The Key is derived from passwordPtr (which is passwordLen bytes long) and from
55 saltPtr (which is saltLen bytes long). The algorithm used is desacribed in
56 PKCS #5 version 2.0 and iterationCount iterations are performed.
57 The argument prf is a pointer to a psuedo random number generator declared above.
58 It should write exactly hLen bytes into its output buffer each time it is called.
59 The argument tempBuffer should point to a buffer MAX (hLen, saltLen + 4) + 2 * hLen
60 bytes long. This buffer is used during the calculation for intermediate results.
61 Security Considerations:
62 The argument saltPtr should be a pointer to a buffer of at least 8 random bytes
63 (64 bits). Thus saltLen should be >= 8.
64 For each session a new salt should be generated.
65 The value of iterationCount should be at least 1000 (one thousand).
66 A good prf would be a HMAC-SHA-1 algorithm where the password serves as
67 HMAC's "key" and the data serves as HMAC's "text". */
68 void pbkdf2 (PRF prf, UInt32 hLen,
69 const void *passwordPtr, UInt32 passwordLen,
70 const void *saltPtr, UInt32 saltLen,
71 UInt32 iterationCount,
72 void *dkPtr, UInt32 dkLen,
73 void *tempBuffer);
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #endif /* __PBKDF2__ */