1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * *****************************************************************/
33 * The number of iterations desired to derived key.
34 * (Recommened by RFC 2898)
36 #define PBKDF_ITERATIONS 1000
39 * Function to derive cryptographic key from the password. (RFC 2898)
40 * In this implementation, HMAC with SHA2 is considered as a pseudorandom function
42 * @param[in] passwd is the master password from which a derived key is generated.
43 * @param[in] pLen is the byte size of the passwd.
44 * @param[in] salt is a cryptographic salt.
45 * @param[in] saltlen is the byte size of the salt.
46 * @param[in] iteration is the number of iterations desired.
47 * @param[in] keyLen is the desired byte size of the derived key. (should be the same as
49 * @param[out] derivedKey is the generated derived key
51 * @return 0 on success
53 int DeriveCryptoKeyFromPassword(const unsigned char* passwd, size_t pLen,
54 const uint8_t* salt, const size_t saltLen,
55 const size_t iterations,
56 const size_t keyLen, uint8_t* derivedKey);