它看起来是为了向后兼容,不为用户更改 API 并且可能不破坏应用程序。
我们开始看一下master分支:
https ://github.com/randombit/botan/blob/master/src/lib/pubkey/pkcs8.cpp
/*
* Extract an encrypted private key and return it
*/
Private_Key* load_key(DataSource& source,
RandomNumberGenerator& rng,
std::function<std::string ()> get_pass)
{
return load_key(source, rng, get_pass, true);
}
来电
/*
* Extract a private key (encrypted/unencrypted) and return it
*/
Private_Key* load_key(DataSource& source,
RandomNumberGenerator& /*rng*/,
std::function<std::string ()> get_pass,
bool is_encrypted)
{
AlgorithmIdentifier alg_id;
secure_vector<uint8_t> pkcs8_key = PKCS8_decode(source, get_pass, alg_id, is_encrypted);
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name.empty() || alg_name == alg_id.oid.as_string())
throw PKCS8_Exception("Unknown algorithm OID: " +
alg_id.oid.as_string());
return load_private_key(alg_id, pkcs8_key).release();
}
}
做这项工作,而这又不使用rng
.
现在,让我们看看以前版本的库。版本 2.0.0 ( https://github.com/randombit/botan/blob/master/src/lib/pubkey/pkcs8.cpp )
版本 (GitHub 中的标记) 1.11.33 ( https://github .com/randombit/botan/blob/1.11.33/src/lib/pubkey/pkcs8.cpp)可以看到它rng
已被使用,并且看起来在此之后的版本删除了它:
/*
* Extract a private key (encrypted/unencrypted) and return it
*/
Private_Key* load_key(DataSource& source,
RandomNumberGenerator& rng,
std::function<std::string ()> get_pass,
bool is_encrypted)
{
AlgorithmIdentifier alg_id;
secure_vector<byte> pkcs8_key = PKCS8_decode(source, get_pass, alg_id, is_encrypted);
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name.empty() || alg_name == alg_id.oid.as_string())
throw PKCS8_Exception("Unknown algorithm OID: " +
alg_id.oid.as_string());
return load_private_key(alg_id, pkcs8_key, rng).release();
}
}
在
load_private_key(alg_id, pkcs8_key, rng).release();
这似乎在https://github.com/randombit/botan/blob/1.11.33/src/lib/pubkey/pk_algs.cpp中定义并以
std::unique_ptr<Private_Key>
load_private_key(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits,
RandomNumberGenerator& rng)
{
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name == "")
throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
#if defined(BOTAN_HAS_RSA)
if(alg_name == "RSA")
return std::unique_ptr<Private_Key>(new RSA_PrivateKey(alg_id, key_bits, rng));
#endif
#if defined(BOTAN_HAS_CURVE_25519)
if(alg_name == "Curve25519")
return std::unique_ptr<Private_Key>(new Curve25519_PrivateKey(alg_id, key_bits, rng));
#endif
现在,如果您将它与 master 分支或版本 2.0.0 进行比较,您可以看到它rng
已从相同的调用中删除
https://github.com/randombit/botan/blob/master/src/lib/pubkey/pk_algs.cpp
std::unique_ptr<Private_Key>
load_private_key(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits)
{
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name == "")
throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
#if defined(BOTAN_HAS_RSA)
if(alg_name == "RSA")
return std::unique_ptr<Private_Key>(new RSA_PrivateKey(alg_id, key_bits));
#endif
在您使用的版本中,他们看起来也删除了它,并且您与 master 中的版本相似:
std::unique_ptr<Private_Key>
load_private_key(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits)
{
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name == "")
throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
#if defined(BOTAN_HAS_RSA)
if(alg_name == "RSA")
return std::unique_ptr<Private_Key>(new RSA_PrivateKey(alg_id, key_bits));
#endif
因此,看起来为了为用户维护相同的 API,他们没有更改签名,但他们更改了实现。