/*
- * sha1.c
+ * sha1.c - implementation of the Secure Hash Algorithm version 1 (FIPS 180-1)
*
- * Implementation of the Secure Hash Algorithm version 1 (FIPS 180-1).
+ * Copyright 2022 Eric Biggers
*
- * Author: Eric Biggers
- * Year: 2014
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
*
- * The default SHA-1 transform is based on public domain code by Steve Reid.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
*
- * The author dedicates this file to the public domain.
- * You can do whatever you want with this file.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
store_be32_unaligned(cpu_to_be32(ctx->state[i]), &md[i * 4]);
}
-/* Calculate the SHA-1 message digest of the specified buffer.
- * @len is the buffer length in bytes. */
+/* Calculate the SHA-1 message digest of the given data. */
void
-sha1_buffer(const void *buffer, size_t len, u8 md[20])
+sha1(const void *data, size_t len, u8 hash[SHA1_HASH_SIZE])
{
SHA_CTX ctx;
sha1_init(&ctx);
- sha1_update(&ctx, buffer, len);
- sha1_final(md, &ctx);
+ sha1_update(&ctx, data, len);
+ sha1_final(hash, &ctx);
}
#endif /* !WITH_LIBCRYPTO */