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