예제 #1
0
파일: cipher.cpp 프로젝트: psi-im/cutestuff
QByteArray Cipher::decrypt(const QByteArray &buf, const Key &key, const QByteArray &iv, bool pad, bool *ok)
{
	if(ok)
		*ok = false;
	const EVP_CIPHER *type = typeToCIPHER(key.type());
	if(!type)
		return QByteArray();
	QByteArray out;
	if(!lib_decryptArray(type, buf, key.data(), iv, pad, &out))
		return QByteArray();

	if(ok)
		*ok = true;
	return out;
}
예제 #2
0
vector<DirEntry>::iterator DirEntryList::_findFirst(const Key &hint, std::function<bool (const DirEntry&)> pred) {
    //TODO Factor out a datastructure that keeps a sorted std::vector and allows these _findLowerBound()/_findUpperBound operations using this hinted linear search
    if (_entries.size() == 0) {
        return _entries.end();
    }
    double startpos_percent = static_cast<double>(*static_cast<const unsigned char*>(hint.data())) / std::numeric_limits<unsigned char>::max();
    auto iter = _entries.begin() + static_cast<int>(startpos_percent * (_entries.size()-1));
    ASSERT(iter >= _entries.begin() && iter < _entries.end(), "Startpos out of range");
    while(iter != _entries.begin() && pred(*iter)) {
        --iter;
    }
    while(iter != _entries.end() && !pred(*iter)) {
        ++iter;
    }
    return iter;
}
TimeProofService::TimeProof TimeProofService::getProof(LogicalTime time, const Key& key) {
    stdx::lock_guard<stdx::mutex> lk(_cacheMutex);
    auto timeCeil = LogicalTime(Timestamp(time.asTimestamp().asULL() | kRangeMask));
    if (_cache && _cache->hasProof(timeCeil, key)) {
        return _cache->_proof;
    }

    auto unsignedTimeArray = timeCeil.toUnsignedArray();
    // update cache
    _cache =
        CacheEntry(SHA1Block::computeHmac(
                       key.data(), key.size(), unsignedTimeArray.data(), unsignedTimeArray.size()),
                   timeCeil,
                   key);
    return _cache->_proof;
}
예제 #4
0
CryptorAESIV::CryptorAESIV (const Key &key, const IV &iv) :
	encryptor(0),
	decryptor(0)
{
	LogDebug(mailiverse::core::crypt, "CryptorAES");

	SymmetricKey _key (OctetString((const byte *)key.data(), key.size()));
	InitializationVector _iv (OctetString((const byte *)iv.data(), iv.size()));
	
	int keySize = key.size();
	if (keySize == 16)
	{
		encryptor = new Pipe(get_cipher("AES-128/CBC/PKCS7", _key, _iv, ENCRYPTION));
		decryptor = new Pipe(get_cipher("AES-128/CBC/PKCS7", _key, _iv, DECRYPTION));
	}
	else
	{
		encryptor = new Pipe(get_cipher("AES-256/CBC/PKCS7", _key, _iv, ENCRYPTION));
		decryptor = new Pipe(get_cipher("AES-256/CBC/PKCS7", _key, _iv, DECRYPTION));
	}
}
예제 #5
0
 void write(std::ostream& out, const Key& key, const Val val) {
     out.write((const char*)key.data(), key_len_);
     Val v = std::min(max_val_, val);
     out.write((const char*)&v, val_len_);
 }