diff options
author | anonymix007 <48598263+anonymix007@users.noreply.github.com> | 2024-09-10 15:58:20 +0200 |
---|---|---|
committer | anonymix007 <48598263+anonymix007@users.noreply.github.com> | 2024-10-11 22:10:21 +0200 |
commit | 18c19a029cc50850019aba9a0252a9412a8b3f06 (patch) | |
tree | 3b8a7db0dee6adbab8f22039214af5f55ff25e33 /src/fundamental/sha1-fundamental.h | |
parent | macro: Add DISABLE_WARNING_STRINGOP_OVERREAD (diff) | |
download | systemd-18c19a029cc50850019aba9a0252a9412a8b3f06.tar.xz systemd-18c19a029cc50850019aba9a0252a9412a8b3f06.zip |
fundamental: Import SHA1 implementation from libxcrypt
Diffstat (limited to 'src/fundamental/sha1-fundamental.h')
-rw-r--r-- | src/fundamental/sha1-fundamental.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/fundamental/sha1-fundamental.h b/src/fundamental/sha1-fundamental.h new file mode 100644 index 0000000000..3577ad5809 --- /dev/null +++ b/src/fundamental/sha1-fundamental.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LicenseRef-alg-sha1-public-domain */ + +/* + * This is an implementation of the National Institute of Standards + * and Technology US Secure Hash Algorithm 1 (SHA1). + * + * Public api for steve reid's public domain SHA-1 implementation. + * This file is in the public domain. + */ +#pragma once + +#include <stddef.h> +#include <stdint.h> + +#define SHA1_DIGEST_SIZE 20 + +/* Structure to save state of computation between the single steps. */ +struct sha1_ctx { + uint32_t state[5]; + uint32_t count[2]; + uint8_t buffer[64]; +}; + +/* Initialize structure containing state of computation. + (RFC 3174, 6.1) */ +void sha1_init_ctx(struct sha1_ctx *ctx); + +/* Starting with the result of former calls of this function (or the + initialization function) update the context for the next LEN bytes + starting at BUFFER. LEN does not need to be a multiple of 64. */ +void sha1_process_bytes(const void *buffer, size_t size, struct sha1_ctx *ctx); + +/* Process the remaining bytes in the buffer and write the finalized + hash to RESBUF, which should point to 20 bytes of storage. All + data written to CTX is erased before returning from the function. */ +void *sha1_finish_ctx(struct sha1_ctx *ctx, uint8_t result[static SHA1_DIGEST_SIZE]); |