2017-01-08 2 views
1

Je commence à utiliser la bibliothèque cryptographique botan et je suis tombé sur une signature de fonction impaire:Pourquoi botan demande-t-il un générateur de nombres aléatoires qu'il ignore pour la compatibilité?

/** 
* Load an encrypted key from a data source. 
* @param source the data source providing the encoded key 
* @param rng ignored for compatability 
* @param get_passphrase a function that returns passphrases 
* @return loaded private key object 
*/ 
BOTAN_DLL Private_Key* load_key(DataSource& source, 
           RandomNumberGenerator& rng, 
           std::function<std::string()> get_passphrase); 

Je me demande pourquoi devrais-je passer un RandomNumberGenerator à une fonction qui promet de l'ignorer?

La documentation dit que c'est pour la compatibilité, mais je ne peux pas imaginer de quel type de compatibilité ils parlent? S'il s'agit d'une compatibilité amont/aval, cela signifie que dans le passé/futur la fonction a/acceptera un générateur de nombres aléatoires pour effectuer une opération déterministe.

S'il vous plaît, qu'est-ce qui me manque ici?

+0

quelle version de botan utilisez-vous? – fedepad

+0

@fedepad Version 2.0 avec horodatage: 20170106. –

Répondre

3

Il semble que ce soit pour la rétrocompatibilité, pour ne pas changer l'API pour l'utilisateur et éventuellement pour ne pas casser les applications.
Nous allons commencer à jeter un oeil à la branche principale:
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); 
    } 

appels

/* 
* 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(); 
    } 

} 

pour faire le travail, ce qui n'utilise pas rng.
Maintenant, voyons les versions précédentes de la bibliothèque. Même se produit pour la version 2.0.0 (https://github.com/randombit/botan/blob/master/src/lib/pubkey/pkcs8.cpp)
Dans la version (balise dans GitHub) 1.11.33 (https://github.com/randombit/botan/blob/1.11.33/src/lib/pubkey/pkcs8.cpp), on peut voir que rng est utilisé et il semble que les versions après celui-ci l'ont laissé tomber:

/* 
* 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(); 
    } 

} 

dans

load_private_key(alg_id, pkcs8_key, rng).release(); 

qui semble être définie en https://github.com/randombit/botan/blob/1.11.33/src/lib/pubkey/pk_algs.cpp et commence par

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 

Maintenant, si vous comparez avec la branche principale ou une version 2.0.0, vous pouvez voir que rng a été abandonnée à partir des mêmes appels

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 

Dans la version que vous utilisez, il regarde ils ont abandonné aussi, et vous avez semblable à celui de maître:

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 

il semble donc que, pour maintenir la même API pour l'utilisateur, ils ne changeaient pas la signature mais ils ont changé la mise en œuvre.