2012-05-19 03:04:51 +00:00
|
|
|
//
|
|
|
|
// DigestEngine.cpp
|
|
|
|
//
|
|
|
|
// $Id: //poco/1.4/Crypto/src/DigestEngine.cpp#1 $
|
|
|
|
//
|
|
|
|
// Library: Crypto
|
|
|
|
// Package: Digest
|
|
|
|
// Module: DigestEngine
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
|
|
|
// and Contributors.
|
|
|
|
//
|
2014-05-04 21:02:42 +02:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2012-05-19 03:04:51 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "Poco/Crypto/DigestEngine.h"
|
|
|
|
#include "Poco/Exception.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Poco {
|
|
|
|
namespace Crypto {
|
|
|
|
|
|
|
|
|
|
|
|
DigestEngine::DigestEngine(const std::string& name):
|
|
|
|
_name(name)
|
|
|
|
{
|
|
|
|
const EVP_MD* md = EVP_get_digestbyname(_name.c_str());
|
|
|
|
if (!md) throw Poco::NotFoundException(_name);
|
|
|
|
_ctx = EVP_MD_CTX_create();
|
|
|
|
EVP_DigestInit_ex(_ctx, md, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DigestEngine::~DigestEngine()
|
|
|
|
{
|
|
|
|
EVP_MD_CTX_destroy(_ctx);
|
|
|
|
}
|
|
|
|
|
2014-02-21 04:43:05 -08:00
|
|
|
int DigestEngine::nid() const
|
|
|
|
{
|
|
|
|
return EVP_MD_nid(_ctx->digest);
|
|
|
|
}
|
2012-05-19 03:04:51 +00:00
|
|
|
|
2012-07-20 02:48:41 +00:00
|
|
|
std::size_t DigestEngine::digestLength() const
|
2012-05-19 03:04:51 +00:00
|
|
|
{
|
|
|
|
return EVP_MD_CTX_size(_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DigestEngine::reset()
|
|
|
|
{
|
|
|
|
EVP_MD_CTX_cleanup(_ctx);
|
|
|
|
const EVP_MD* md = EVP_get_digestbyname(_name.c_str());
|
|
|
|
if (!md) throw Poco::NotFoundException(_name);
|
|
|
|
EVP_DigestInit_ex(_ctx, md, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Poco::DigestEngine::Digest& DigestEngine::digest()
|
|
|
|
{
|
|
|
|
_digest.clear();
|
|
|
|
unsigned len = EVP_MD_CTX_size(_ctx);
|
|
|
|
_digest.resize(len);
|
|
|
|
EVP_DigestFinal_ex(_ctx, &_digest[0], &len);
|
|
|
|
reset();
|
|
|
|
return _digest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-25 04:42:58 +00:00
|
|
|
void DigestEngine::updateImpl(const void* data, std::size_t length)
|
2012-05-19 03:04:51 +00:00
|
|
|
{
|
|
|
|
EVP_DigestUpdate(_ctx, data, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace Poco::Crypto
|