From e4ad766315879e1ff05bb111229f073f8f0ed68e Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Mon, 10 Oct 2022 21:30:02 +0200 Subject: PassFish: Initial Commit Well, that's a lie. But nobody needs to see all the iterations I decided to sweep under the rug. That said, I think the repo is, while not clean, clean enough now, to not be embarrassed by uploading it to github. --- src/pwm_qhash.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/pwm_qhash.cpp (limited to 'src/pwm_qhash.cpp') diff --git a/src/pwm_qhash.cpp b/src/pwm_qhash.cpp new file mode 100644 index 0000000..f9528d4 --- /dev/null +++ b/src/pwm_qhash.cpp @@ -0,0 +1,22 @@ +#include + +extern "C" { + /** + * Forwards the call to QCryptographicHash::hash() and copies the output into the provided buffer. + * Returns zero on error (unsupported hash type or insufficient output_capacity). Number of written output bytes otherwise. + */ + Q_DECL_EXPORT size_t pwm_qhash(size_t algorithm, const unsigned char * input, size_t input_length, unsigned char * output, size_t output_capacity) + { + if(algorithm > 6) + return 0; //failed. + const auto algo{static_cast(algorithm)}; + QCryptographicHash hasher{algo}; + hasher.addData(reinterpret_cast(input), input_length); + const auto hash{hasher.result()}; + const auto count_as_size{static_cast(hash.length())}; + if(count_as_size > output_capacity) + return 0; + memcpy(output,hash.constData(),count_as_size); + return count_as_size; + } +} -- cgit v1.2.3