bool OSSLDES::generateKey(SymmetricKey& key, RNG* rng /* = NULL */) { if (rng == NULL) { return false; } if (key.getBitLen() == 0) { return false; } ByteString keyBits; // don't count parity bit if (!rng->generateRandom(keyBits, key.getBitLen()/7)) { return false; } // fix the odd parity size_t i; for (i = 0; i < keyBits.size(); i++) { keyBits[i] = odd_parity[keyBits[i]]; } return key.setKeyBits(keyBits); }
bool SymmetricAlgorithm::generateKey(SymmetricKey& key, RNG* rng /* = NULL */) { if (rng == NULL) { return false; } if (key.getBitLen() == 0) { return false; } ByteString keyBits; if (!rng->generateRandom(keyBits, key.getBitLen()/8)) { return false; } return key.setKeyBits(keyBits); }