]> git.saurik.com Git - apple/security.git/blob - sec/Security/SecPBKDF.h
Security-55471.tar.gz
[apple/security.git] / sec / Security / SecPBKDF.h
1 /*
2 * SecPBKDF.h
3 *
4 * Copyright 2010 Apple Inc. All rights reserved.
5 *
6 */
7
8 #include <CoreFoundation/CFData.h>
9
10 #include <CommonCrypto/CommonHMAC.h>
11
12 /* CC Based HMAC PRF functions */
13 void hmac_sha1_PRF(const uint8_t *key,
14 size_t key_len,
15 const uint8_t *text,
16 size_t text_len,
17 uint8_t digest[CC_SHA1_DIGEST_LENGTH]);
18
19
20 /* PBKDF for clients who want to let us allocate the intermediate buffer.
21 We over write any intermediate results we use in calculating */
22 void pbkdf2_hmac_sha1(const uint8_t *passwordPtr, size_t passwordLen,
23 const uint8_t *saltPtr, size_t saltLen,
24 uint32_t iterationCount,
25 void *dkPtr, size_t dkLen);
26
27
28
29 /* Transformation conveninces from and to CFData where the password bytes used are the UTF-8 representation and 1000 iterations
30
31 This routine promises not to make any copies of the password or salt that aren't
32 eradicated before completion.
33
34 The size of the result buffer is used to produce the derivedKey.
35
36 Be careful when using CFTypes for secrets, they tend to copy data more than you'd like.
37 If your password and or salt aren't already in CF types use the buffer versions above.
38
39 If you already have the data in this form, the interface will unwrap and not copy the data anywhere extra for you.
40
41 void SecKeyFromPassword_HMAC_sha1(CFDataRef password, CFDataRef salt, uint32_t interationCount, CFMutableDataRef derivedKey)
42 {
43 pbkdf2_hmac_sha1(CFDataGetBytePtr(password), CFDataGetLength(password),
44 CFDataGetBytePtr(salt), CFDataGetLength(salt),
45 interationCount,
46 CFDataGetMutableBytePtr(derivedKey), CFDataGetLength(derivedKey));
47
48 }
49
50 Suggested way to transform strings into data:
51
52 CFDataRef *passwordData = CFStringCreateExternalRepresentation(NULL, password, kCFStringEncodingUTF8, 0);
53
54 ...
55
56 CFReleaseSafe(passwordData);
57
58 */
59
60 void SecKeyFromPassphraseDataHMACSHA1(CFDataRef password, CFDataRef salt, uint32_t interationCount, CFMutableDataRef derivedKey);