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