Exemple #1
0
// Helper function for multithreaded key transformation
PwDatabase::ErrorCode PwDatabase::performKeyTransformRounds(const unsigned char* pTransformSeed,
        unsigned char* pTransKey, const quint64 nRounds, bool reportProgress) {
    // make a local copy of the subkey and the key
    unsigned char transKey[SUBKEY_SIZE];
    unsigned char key[32];
    memcpy(transKey, pTransKey, SUBKEY_SIZE);
    memcpy(key, pTransformSeed, 32);

    // prepare key transform
    Rijndael aes;
    int ec = (qint8)aes.init(Rijndael::ECB, Rijndael::Encrypt, key, Rijndael::Key32Bytes, 0);
    if (ec != RIJNDAEL_SUCCESS) {
        LOG("Rijndael init error %d", ec);
        return KEY_TRANSFORM_INIT_ERROR;
    }

    if (reportProgress) {
        for (quint64 round = 0; round < nRounds; round++) {
            setProgress(round);
            aes.encrypt(transKey, transKey); // only works with 16-byte buffers
        }
    } else {
        for (quint64 round = 0; round < nRounds; round++) {
            aes.encrypt(transKey, transKey); // only works with 16-byte buffers
        }
    }
    memcpy(pTransKey, transKey, SUBKEY_SIZE);
    return SUCCESS;
}