1fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/* 2fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Copyright (C) 2010 The Android Open Source Project 3fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 4fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Licensed under the Apache License, Version 2.0 (the "License"); 5fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * you may not use this file except in compliance with the License. 6fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * You may obtain a copy of the License at 7fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 8fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * http://www.apache.org/licenses/LICENSE-2.0 9fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 10fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Unless required by applicable law or agreed to in writing, software 11fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * distributed under the License is distributed on an "AS IS" BASIS, 12fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * See the License for the specific language governing permissions and 14fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * limitations under the License. 15fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 16fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 17fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifndef __FWDLOCKGLUE_H__ 18fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#define __FWDLOCKGLUE_H__ 19fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 20fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef __cplusplus 21fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" { 22fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 23fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 24fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 25fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Generates the specified number of cryptographically secure random bytes. 26fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 27fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[out] pBuffer A reference to the buffer that should receive the random data. 28fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] numBytes The number of random bytes to generate. 29fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 30fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the operation was successful. 31fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 32fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockGlue_GetRandomNumber(void *pBuffer, size_t numBytes); 33fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 34fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 35fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Performs initialization of the key-encryption key. Should be called once during startup to 36fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * facilitate encryption and decryption of session keys. 37fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 38fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the operation was successful. 39fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 40fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockGlue_InitializeKeyEncryption(); 41fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 42fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 43fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Returns the length of the encrypted key, given the length of the plaintext key. 44fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 45fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] plaintextKeyLength The length in bytes of the plaintext key. 46fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 47fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return The length in bytes of the encrypted key. 48fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 49fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherasize_t FwdLockGlue_GetEncryptedKeyLength(size_t plaintextKeyLength); 50fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 51fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 52fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Encrypts the given session key using a key-encryption key unique to this device. 53fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 54fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] pPlaintextKey A reference to the buffer containing the plaintext key. 55fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] plaintextKeyLength The length in bytes of the plaintext key. 56fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[out] pEncryptedKey A reference to the buffer containing the encrypted key. 57fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] encryptedKeyLength The length in bytes of the encrypted key. 58fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 59fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the operation was successful. 60fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 61fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockGlue_EncryptKey(const void *pPlaintextKey, 62fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera size_t plaintextKeyLength, 63fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void *pEncryptedKey, 64fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera size_t encryptedKeyLength); 65fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 66fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 67fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Decrypts the given session key using a key-encryption key unique to this device. 68fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 69fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] pEncryptedKey A reference to the buffer containing the encrypted key. 70fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] encryptedKeyLength The length in bytes of the encrypted key. 71fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[out] pDecryptedKey A reference to the buffer containing the decrypted key. 72fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] decryptedKeyLength The length in bytes of the decrypted key. 73fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 74fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the operation was successful. 75fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 76fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockGlue_DecryptKey(const void *pEncryptedKey, 77fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera size_t encryptedKeyLength, 78fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void *pDecryptedKey, 79fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera size_t decryptedKeyLength); 80fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 81fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef __cplusplus 82fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 83fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 84fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 85fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif // __FWDLOCKGLUE_H__ 86