]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
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 | #include <sys/cdefs.h> | |
18 | #include <sys/types.h> | |
19 | #include <stdint.h> | |
20 | ||
21 | /* | |
22 | File: pbkdf2.h | |
23 | Contains: Apple Data Security Services PKCS #5 PBKDF2 function declaration. | |
24 | Copyright: (C) 1999 by Apple Computer, Inc., all rights reserved | |
25 | Written by: Michael Brouwer <mb@apple.com> | |
26 | */ | |
27 | ||
28 | #ifndef __PBKDF2__ | |
29 | #define __PBKDF2__ | |
30 | ||
31 | __BEGIN_DECLS | |
32 | ||
33 | /* This function should generate a pseudo random octect stream | |
34 | of hLen bytes long (The value hLen is specified as an argument to pbkdf2 | |
35 | and should be constant for any given prf function.) which is output in the buffer | |
36 | pointed to by randomPtr (the caller of this function is responsible for allocation | |
37 | of the buffer). | |
38 | The inputs to the pseudo random function are the first keyLen octets pointed | |
39 | to by keyPtr and the first textLen octets pointed to by textPtr. | |
40 | Both keyLen and textLen can have any nonzero value. | |
41 | A good prf would be a HMAC-SHA-1 algorithm where the keyPtr octets serve as | |
42 | HMAC's "key" and the textPtr octets serve as HMAC's "text". */ | |
43 | typedef void (*PRF)(const uint8_t *keyPtr, size_t keyLen, | |
44 | const uint8_t *textPtr, size_t textLen, | |
45 | uint8_t *randomPtr); | |
46 | ||
47 | /* This function implements the PBKDF2 key derrivation algorithm described in | |
48 | http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-5.html | |
49 | The output is a derived key of dkLen bytes which is written to the buffer | |
50 | pointed to by dkPtr. | |
51 | The caller should ensure dkPtr is at least dkLen bytes long. | |
52 | The Key is derived from passwordPtr (which is passwordLen bytes long) and from | |
53 | saltPtr (which is saltLen bytes long). The algorithm used is desacribed in | |
54 | PKCS #5 version 2.0 and iterationCount iterations are performed. | |
55 | The argument prf is a pointer to a psuedo random number generator declared above. | |
56 | It should write exactly hLen bytes into its output buffer each time it is called. | |
57 | The argument tempBuffer should point to a buffer MAX (hLen, saltLen + 4) + 2 * hLen | |
58 | bytes long. This buffer is used during the calculation for intermediate results. | |
59 | Security Considerations: | |
60 | The argument saltPtr should be a pointer to a buffer of at least 8 random bytes | |
61 | (64 bits). Thus saltLen should be >= 8. | |
62 | For each session a new salt should be generated. | |
63 | The value of iterationCount should be at least 1000 (one thousand). | |
64 | A good prf would be a HMAC-SHA-1 algorithm where the password serves as | |
65 | HMAC's "key" and the data serves as HMAC's "text". */ | |
66 | void pbkdf2 (PRF prf, size_t hLen, | |
67 | const void *passwordPtr, size_t passwordLen, | |
68 | const void *saltPtr, size_t saltLen, | |
427c49bc | 69 | size_t iterationCount, |
b1ab9ed8 A |
70 | void *dkPtr, size_t dkLen, |
71 | void *tempBuffer); | |
72 | ||
73 | ||
74 | #ifdef __cplusplus | |
75 | } | |
76 | #endif | |
77 | ||
78 | #endif /* __PBKDF2__ */ |