https://github.com/mackron/sha1
SHA-1 hashing implementation
https://github.com/mackron/sha1
Last synced: 10 months ago
JSON representation
SHA-1 hashing implementation
- Host: GitHub
- URL: https://github.com/mackron/sha1
- Owner: mackron
- Created: 2022-02-14T12:23:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T02:49:03.000Z (over 3 years ago)
- Last Synced: 2025-04-11T04:30:41.101Z (about 1 year ago)
- Language: C
- Size: 12.7 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SHA-1 Hashing
A simple SHA-1 hashing implementation. Usage:
unsigned char digest[SHA1_SIZE];
sha1_context ctx;
sha1_init(&ctx);
{
sha1_update(&ctx, src, sz);
}
sha1_finalize(&ctx, digest);
The above code is the literal implementation of `sha1()` which is a high level helper for hashing
data of a known size:
unsigned char hash[SHA1_SIZE];
sha1(hash, data, dataSize);
Use `sha1_format()` to format the digest as a hex string. The capacity of the output buffer needs to
be at least `SHA1_SIZE_FORMATTED` bytes.
This library does not perform any memory allocations and does not use anything from the standard
library except for `size_t` and `NULL`, both of which are drawn in from stddef.h. No other standard
headers are included.
There is no need to link to anything with this library. You can use SHA1_IMPLEMENTATION to define
the implementation section, or you can use sha1.c if you prefer a traditional header/source pair.
This implements both methods defined in RFC 3174. Method 1 will be used by default. If you want to
use Method 2, define `SHA1_USE_RFC_METHOD_2` at compile time.
#define SHA1_USE_RFC_METHOD_2
#define SHA1_IMPLEMENTATION
#include "sha1.h"
No effort has been made to optimize this beyond the algorithms described in RGC 3174. If you're
looking for the fastest SHA-1 implementation you'll need to look elsewhere. An optimized
implementation may come later.