// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine License // Agreement. // // Reference implementation utilities of OEMCrypto APIs // #ifndef WVOEC_UTIL_DRM_KEY_H_ #define WVOEC_UTIL_DRM_KEY_H_ #include #include #include #include "OEMCryptoCENCCommon.h" #include "oemcrypto_ecc_key.h" #include "oemcrypto_rsa_key.h" namespace wvoec { namespace util { // DRM private key performs all of the operations required by an // OEMCrypto session's RSA/ECC private key. class DrmPrivateKey { public: // Create an RSA-based DRM key. static std::unique_ptr Create( std::shared_ptr&& rsa_key); static std::unique_ptr Create( std::unique_ptr&& rsa_key); // Create an ECC-based DRM key. static std::unique_ptr Create( std::shared_ptr&& ecc_key); static std::unique_ptr Create( std::unique_ptr&& ecc_key); bool IsRsaKey() const { return static_cast(rsa_key_); } bool IsEccKey() const { return static_cast(ecc_key_); } // Generates a session key from the key source. // For RSA keys, |key_source| is an encrypted session key. // For ECC keys, |key_source| is a ephemeral public key to be // used in ECDH. OEMCryptoResult GetSessionKey(const uint8_t* key_source, size_t key_source_size, std::vector* session_key) const; std::vector GetSessionKey( const std::vector& key_source) const; // Generates a encryption key from the key source. // For RSA keys, |key_source| is an encrypted encryption key. // For ECC keys, this method is not supported. std::vector GetEncryptionKey( const std::vector& key_source) const; // Generates a signature for the provided message. // For RSA keys, the signature is RSASSA-PSS. // For ECC keys, the signature is ECDSA. OEMCryptoResult GenerateSignature(const uint8_t* message, size_t message_length, uint8_t* signature, size_t* signature_length) const; std::vector GenerateSignature( const std::vector& message) const; size_t SignatureSize() const; // Generates a signature for the provided message. // For RSA keys, the signature is RSASSA-PKCS1. // For ECC keys, this is not supported. OEMCryptoResult GenerateRsaSignature(const uint8_t* message, size_t message_length, uint8_t* signature, size_t* signature_length) const; std::vector GenerateRsaSignature( const std::vector& message) const; ~DrmPrivateKey() {} private: DrmPrivateKey() {} // Only one will be set. std::shared_ptr ecc_key_; std::shared_ptr rsa_key_; }; } // namespace util } // namespace wvoec #endif // WVOEC_UTIL_DRM_KEY_H_