2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 #ifndef __VOLUME_MANAGER_KEY_GENERATOR_H__
18 #define __VOLUME_MANAGER_KEY_GENERATOR_H__
22 #define SHA1_DIGEST_SIZE 20
25 unsigned int state[5];
26 unsigned int count[2];
27 unsigned char buffer[64];
30 class KeyGenerator final {
32 KeyGenerator() = delete;
33 KeyGenerator(const KeyGenerator&) = delete;
34 KeyGenerator(KeyGenerator&&) = delete;
36 KeyGenerator& operator=(const KeyGenerator&) = delete;
37 KeyGenerator& operator=(KeyGenerator&&) = delete;
39 static std::string wrapKey(const std::string& decrypted, const std::string& salt, int len);
40 static std::string generateKey(int len);
43 static void sha1Init(SHA1_CTX* context);
44 static void sha1Update(SHA1_CTX* context, const void* p, unsigned int len);
45 static void sha1Final(unsigned char digsest[SHA1_DIGEST_SIZE], SHA1_CTX* context);
46 static void sha1Transform(unsigned int state[5], const unsigned char buffer[64]);
47 static void sha1Hmac(const unsigned char* key, int keyLen, const unsigned char* data, int dataLen, unsigned char out[SHA1_DIGEST_SIZE]);
49 static int pbkdf2(const char* pass, int passLen, const unsigned char* salt, int saltLen, int iter, int keyLen, unsigned char* out);
50 static std::string hexConvert(unsigned char* src, int srcLen);
53 #endif //!__VOLUME_MANAGER_KEY_GENERATOR_H__