/drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.h

http://github.com/CyanogenMod/android_frameworks_base · C++ Header · 85 lines · 20 code · 9 blank · 56 comment · 0 complexity · 8a4dda8d894eb4d2ca074220ac5032da MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. #ifndef __FWDLOCKGLUE_H__
  17. #define __FWDLOCKGLUE_H__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * Generates the specified number of cryptographically secure random bytes.
  23. *
  24. * @param[out] pBuffer A reference to the buffer that should receive the random data.
  25. * @param[in] numBytes The number of random bytes to generate.
  26. *
  27. * @return A Boolean value indicating whether the operation was successful.
  28. */
  29. int FwdLockGlue_GetRandomNumber(void *pBuffer, size_t numBytes);
  30. /**
  31. * Performs initialization of the key-encryption key. Should be called once during startup to
  32. * facilitate encryption and decryption of session keys.
  33. *
  34. * @return A Boolean value indicating whether the operation was successful.
  35. */
  36. int FwdLockGlue_InitializeKeyEncryption();
  37. /**
  38. * Returns the length of the encrypted key, given the length of the plaintext key.
  39. *
  40. * @param[in] plaintextKeyLength The length in bytes of the plaintext key.
  41. *
  42. * @return The length in bytes of the encrypted key.
  43. */
  44. size_t FwdLockGlue_GetEncryptedKeyLength(size_t plaintextKeyLength);
  45. /**
  46. * Encrypts the given session key using a key-encryption key unique to this device.
  47. *
  48. * @param[in] pPlaintextKey A reference to the buffer containing the plaintext key.
  49. * @param[in] plaintextKeyLength The length in bytes of the plaintext key.
  50. * @param[out] pEncryptedKey A reference to the buffer containing the encrypted key.
  51. * @param[in] encryptedKeyLength The length in bytes of the encrypted key.
  52. *
  53. * @return A Boolean value indicating whether the operation was successful.
  54. */
  55. int FwdLockGlue_EncryptKey(const void *pPlaintextKey,
  56. size_t plaintextKeyLength,
  57. void *pEncryptedKey,
  58. size_t encryptedKeyLength);
  59. /**
  60. * Decrypts the given session key using a key-encryption key unique to this device.
  61. *
  62. * @param[in] pEncryptedKey A reference to the buffer containing the encrypted key.
  63. * @param[in] encryptedKeyLength The length in bytes of the encrypted key.
  64. * @param[out] pDecryptedKey A reference to the buffer containing the decrypted key.
  65. * @param[in] decryptedKeyLength The length in bytes of the decrypted key.
  66. *
  67. * @return A Boolean value indicating whether the operation was successful.
  68. */
  69. int FwdLockGlue_DecryptKey(const void *pEncryptedKey,
  70. size_t encryptedKeyLength,
  71. void *pDecryptedKey,
  72. size_t decryptedKeyLength);
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif // __FWDLOCKGLUE_H__