diff options
| author | Andreas Grois <andi@grois.info> | 2022-10-10 21:30:02 +0200 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2022-10-10 21:37:15 +0200 |
| commit | e4ad766315879e1ff05bb111229f073f8f0ed68e (patch) | |
| tree | 4b043ff47c78b2c00c80c94ebda622c32c8b6d3d /src/pwm_qhash.cpp | |
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.
Diffstat (limited to 'src/pwm_qhash.cpp')
| -rw-r--r-- | src/pwm_qhash.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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 <QCryptographicHash> + +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<QCryptographicHash::Algorithm>(algorithm)}; + QCryptographicHash hasher{algo}; + hasher.addData(reinterpret_cast<const char *>(input), input_length); + const auto hash{hasher.result()}; + const auto count_as_size{static_cast<size_t>(hash.length())}; + if(count_as_size > output_capacity) + return 0; + memcpy(output,hash.constData(),count_as_size); + return count_as_size; + } +} |
