2023-08-01 13:54:17 +08:00
|
|
|
#include "MessageDigest.h"
|
2024-10-29 21:51:37 +08:00
|
|
|
#include <mbedtls/md.h>
|
2023-08-01 13:54:17 +08:00
|
|
|
#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);
|
|
|
|
}
|