51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// Copyright 2019 Google LLC.
|
|
//
|
|
// This software is licensed under the terms defined in the Widevine Master
|
|
// License Agreement. For a copy of this agreement, please contact
|
|
// widevine-licensing@google.com.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Description:
|
|
// Implementation of local EC key generator.
|
|
|
|
#include "common/local_ec_key_source.h"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "glog/logging.h"
|
|
#include "openssl/ec.h"
|
|
#include "openssl/nid.h"
|
|
#include "common/ec_key.h"
|
|
#include "common/ec_util.h"
|
|
|
|
using widevine::ec_util::SerializeECPrivateKey;
|
|
using widevine::ec_util::SerializeECPublicKey;
|
|
|
|
namespace widevine {
|
|
|
|
bool LocalECKeySource::GetECKey(ECPrivateKey::EllipticCurve curve,
|
|
std::string* private_key,
|
|
std::string* public_key) {
|
|
DCHECK(private_key);
|
|
DCHECK(public_key);
|
|
|
|
int nid = ec_util::CurveToNid(curve);
|
|
if (nid <= 0) {
|
|
return false;
|
|
}
|
|
bssl::UniquePtr<EC_KEY> key_pair(EC_KEY_new_by_curve_name(nid));
|
|
if (key_pair == nullptr || !EC_KEY_generate_key(key_pair.get())) {
|
|
return false;
|
|
}
|
|
if (!SerializeECPrivateKey(key_pair.get(), private_key) ||
|
|
!SerializeECPublicKey(key_pair.get(), public_key)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
} // namespace widevine
|