Compare commits
No commits in common. "455a5a2fce9e9dee61c7102a767bd6b02b39d797" and "27d2c8d21a122aa0c0cb623668657188f9d95444" have entirely different histories.
455a5a2fce
...
27d2c8d21a
3 changed files with 2 additions and 126 deletions
|
|
@ -10,10 +10,8 @@ pkgincludedir = $(includedir)/$(PACKAGE_NAME)
|
|||
pkginclude_HEADERS = \
|
||||
include/libft_ssl.h \
|
||||
include/compiler.h \
|
||||
include/digest_algos.h \
|
||||
include/md5.h \
|
||||
include/sha256.h \
|
||||
include/whirlpool.h
|
||||
include/sha256.h
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libft_ssl.pc
|
||||
|
|
|
|||
122
README.md
122
README.md
|
|
@ -1,122 +0,0 @@
|
|||
# libft_ssl
|
||||
|
||||
A C library implementing cryptographic hash functions from scratch.
|
||||
|
||||
Each algorithm exposes a uniform streaming API — `init` / `update` / `final`
|
||||
|
||||
## Algorithms
|
||||
|
||||
| Algorithm | Digest | Block | Notes |
|
||||
|------------|--------|-------|-------|
|
||||
| MD5 | 128-bit | 512-bit | RFC 1321 - broken, non-security use only |
|
||||
| SHA-256 | 256-bit | 512-bit | SHA-2 family, NSA/NIST - widely used in TLS, Bitcoin |
|
||||
| Whirlpool | 512-bit | 512-bit | ISO/IEC 10118-3 - Miyaguchi-Preneel construction |
|
||||
|
||||
## API
|
||||
|
||||
The public interface lives in `<libft_ssl/libft_ssl.h>`.
|
||||
|
||||
```c
|
||||
struct digest_algo {
|
||||
const char *name;
|
||||
size_t digest_size; /* bytes */
|
||||
size_t block_size; /* bytes */
|
||||
void (*init) (void *ctx);
|
||||
void (*update)(void *ctx, const uint8_t *data, size_t len);
|
||||
void (*final) (void *ctx, uint8_t *out);
|
||||
};
|
||||
|
||||
union digest_ctx { /* one allocation covers all algorithm contexts */
|
||||
struct md5_ctx md5;
|
||||
struct sha256_ctx sha256;
|
||||
struct whirlpool_ctx whirlpool;
|
||||
};
|
||||
```
|
||||
|
||||
One global instance is provided per algorithm: `g_md5`, `g_sha256`,
|
||||
`g_whirlpool`.
|
||||
|
||||
### Example
|
||||
|
||||
```c
|
||||
#include <libft_ssl/libft_ssl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct digest_algo *algo = &g_sha256;
|
||||
union digest_ctx ctx;
|
||||
uint8_t digest[32];
|
||||
|
||||
algo->init(&ctx);
|
||||
algo->update(&ctx, (const uint8_t *)"hello", 5);
|
||||
algo->final(&ctx, digest);
|
||||
|
||||
for (size_t i = 0; i < algo->digest_size; i++)
|
||||
printf("%02x", digest[i]);
|
||||
puts("");
|
||||
}
|
||||
```
|
||||
|
||||
Compile with:
|
||||
|
||||
```sh
|
||||
cc example.c -lft_ssl -o example
|
||||
# or with pkg-config:
|
||||
cc example.c $(pkg-config --cflags --libs libft_ssl) -o example
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
### Dependencies
|
||||
|
||||
- C99 compiler
|
||||
- autoconf
|
||||
- automake
|
||||
- libtool
|
||||
- `pdflatex` — only if building documentation (`--enable-doc`)
|
||||
|
||||
### Steps
|
||||
|
||||
```sh
|
||||
./autogen.sh # generate the build system (first checkout only)
|
||||
./configure
|
||||
make
|
||||
make install # installs to /usr/local by default
|
||||
```
|
||||
|
||||
Common `configure` options:
|
||||
|
||||
| Flag | Default | Description |
|
||||
|------|---------|-------------|
|
||||
| `--prefix=PATH` | `/usr/local` | Installation prefix |
|
||||
| `--enable-debug` | no | Build with `-g -O0` instead of `-O2` |
|
||||
| `--enable-doc` | no | Build PDF documentation (requires `pdflatex`) |
|
||||
|
||||
### pkg-config
|
||||
|
||||
After installation the library registers itself with pkg-config:
|
||||
|
||||
```sh
|
||||
pkg-config --cflags --libs libft_ssl
|
||||
```
|
||||
|
||||
## Project structure
|
||||
|
||||
```
|
||||
include/ public and internal headers
|
||||
src/
|
||||
md5/ MD5 init / update / compress / final
|
||||
sha256/ SHA-256 init / update / compress / final
|
||||
whirlpool/ Whirlpool init / update / compress / final
|
||||
libft_ssl.c algorithm descriptor table (X-macro generated)
|
||||
doc/ LaTeX source for the technical documentation
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
The full technical write-up is available at <https://lohic.dev/libft_ssl.html> ([PDF](https://lohic.dev/libft_ssl.pdf)).
|
||||
|
||||
## License
|
||||
|
||||
GPLv3 — see [LICENSE](LICENSE).
|
||||
|
|
@ -4,7 +4,7 @@ libdir=@libdir@
|
|||
includedir=@includedir@
|
||||
|
||||
Name: libft_ssl
|
||||
Description: Cryptographic hash functions library (MD5, SHA-256, Whirlpool)
|
||||
Description: idk
|
||||
Version: @PACKAGE_VERSION@
|
||||
Libs: -L${libdir} -lft_ssl
|
||||
Cflags: -I${includedir}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue