32 lines
901 B
C++
32 lines
901 B
C++
|
#include "MessageDigest.h"
|
||
|
#include "mbedtls/md.h"
|
||
|
#include <cstring>
|
||
|
|
||
|
class MessageDigestPrivate {
|
||
|
public:
|
||
|
mbedtls_md_context_t context;
|
||
|
};
|
||
|
|
||
|
MessageDigest::MessageDigest(Type type) : m_d(new MessageDigestPrivate()) {
|
||
|
mbedtls_md_init(&m_d->context);
|
||
|
auto info = mbedtls_md_info_from_type(static_cast<mbedtls_md_type_t>(type));
|
||
|
mbedtls_md_setup(&m_d->context, info, 1);
|
||
|
}
|
||
|
|
||
|
MessageDigest::~MessageDigest() {
|
||
|
mbedtls_md_free(&m_d->context);
|
||
|
delete m_d;
|
||
|
}
|
||
|
|
||
|
int MessageDigest::hmacStarts(const unsigned char *key, size_t keylen) {
|
||
|
return mbedtls_md_hmac_starts(&m_d->context, key, keylen);
|
||
|
}
|
||
|
|
||
|
int MessageDigest::hmacUpdate(const unsigned char *input, size_t ilen) {
|
||
|
return mbedtls_md_hmac_update(&m_d->context, input, ilen);
|
||
|
}
|
||
|
|
||
|
int MessageDigest::hmacFinish(unsigned char *output) {
|
||
|
return mbedtls_md_hmac_finish(&m_d->context, output);
|
||
|
}
|