69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
// 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_KEY_DERIVER_H_
|
|
#define WVOEC_UTIL_KEY_DERIVER_H_
|
|
|
|
#include <inttypes.h>
|
|
#include <stddef.h>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "cmac.h"
|
|
#include "wv_class_utils.h"
|
|
|
|
namespace wvoec {
|
|
namespace util {
|
|
class KeyDeriver {
|
|
public:
|
|
~KeyDeriver() = default;
|
|
WVCDM_DISALLOW_COPY_AND_MOVE(KeyDeriver);
|
|
|
|
// Create a new key deriver using either the session key or the device
|
|
// key.
|
|
// Returns an empty pointer if the key size is not valid.
|
|
static std::unique_ptr<KeyDeriver> Create(const uint8_t* key,
|
|
size_t key_size);
|
|
static std::unique_ptr<KeyDeriver> Create(const std::vector<uint8_t>& key);
|
|
|
|
// Derive the mac_key[server] from the provided |mac_key_context|.
|
|
bool DeriveServerMacKey(const uint8_t* mac_key_context,
|
|
size_t mac_key_context_size,
|
|
std::vector<uint8_t>* mac_key_server);
|
|
bool DeriveServerMacKey(const std::vector<uint8_t>& mac_key_context,
|
|
std::vector<uint8_t>* mac_key_server);
|
|
|
|
// Derive the mac_key[client] from the provided |mac_key_context|.
|
|
bool DeriveClientMacKey(const uint8_t* mac_key_context,
|
|
size_t mac_key_context_size,
|
|
std::vector<uint8_t>* mac_key_client);
|
|
bool DeriveClientMacKey(const std::vector<uint8_t>& mac_key_context,
|
|
std::vector<uint8_t>* mac_key_client);
|
|
|
|
// Derive the enc_key from the provided |enc_key_context|.
|
|
bool DeriveEncryptionKey(const uint8_t* enc_key_context,
|
|
size_t enc_key_context_size,
|
|
std::vector<uint8_t>* enc_key);
|
|
bool DeriveEncryptionKey(const std::vector<uint8_t>& enc_key_context,
|
|
std::vector<uint8_t>* enc_key);
|
|
|
|
// Derive renewed device key. Use on KeyDeriver initialized with old device
|
|
// key. |context| should be just the context field, eg A_priv+CA_token.
|
|
bool DeriveRenewedDeviceKey(const std::vector<uint8_t>& context,
|
|
std::vector<uint8_t>* renewed_device_key);
|
|
|
|
private:
|
|
KeyDeriver() {}
|
|
|
|
bool Init(const uint8_t* key, size_t key_size);
|
|
|
|
std::unique_ptr<Cmac> cmac_;
|
|
}; // class KeyDeriver
|
|
} // namespace util
|
|
} // namespace wvoec
|
|
#endif // WVOEC_UTIL_KEY_DERIVER_H_
|