AtlatestRepositorysigil-crypto
sigil-crypto / treeREADME.md
1
# sigil-crypto3
Cryptographic primitives for [Sigil](https://codeberg.org/sigil/sigil).5
Hashing, message authentication, key derivation, base64 encoding, and6
cryptographically secure random bytes. Built on a vendored mbedTLS and7
usable independently of TLS.9
## Modules11
| Module | Purpose |12
|-----------------|-----------------------------------------------|13
| `(sigil crypto)`| SHA/HMAC/PBKDF2 hashes, base64, random bytes |15
## API summary17
| Procedure | Purpose |18
|-------------------------|-------------------------------------------------|19
| `sha1` | SHA-1 hex digest of a string or bytevector |20
| `sha256` | SHA-256 hex digest of a string or bytevector |21
| `sha256-bytes` | SHA-256 digest as a bytevector |22
| `hmac-sha256` | HMAC-SHA256 hex digest (key + message) |23
| `hmac-sha1` | HMAC-SHA1 hex digest (key + message) |24
| `pbkdf2-sha1` | PBKDF2-SHA1 key derivation (hex digest) |25
| `base64-encode` | Base64 encoding of a string or bytevector |26
| `base64-decode` | Base64 decoding to a string |27
| `random-bytes` | Cryptographically secure random bytevector |28
| `timing-safe-equal?` | Constant-time string comparison |30
## System prerequisites32
None beyond a working C toolchain. mbedTLS is vendored under33
`vendor/mbedtls/` and compiled in-tree with a minimal34
`sigil_mbedtls_config.h` (TLS 1.2 primitives only — TLS 1.3 and the PSA35
crypto machinery are compiled out).37
## Dependencies39
- sigil-stdlib41
## Build43
```sh44
sigil deps install45
sigil build46
sigil test --report47
```49
The first build compiles ~108 mbedTLS translation units plus50
`native/crypto.c`. Subsequent builds hit the cache.52
## Usage54
```scheme55
(import (sigil crypto))57
(sha256 "hello") ; => hex string58
(sha256-bytes "hello") ; => 32-byte bytevector59
(hmac-sha256 "secret-key" "message") ; => hex string60
(pbkdf2-sha1 "password" "salt" 4096 20) ; => hex string61
(base64-encode "hello") ; => "aGVsbG8="62
(base64-decode "aGVsbG8=") ; => "hello"63
(random-bytes 16) ; => #u8(...)64
(timing-safe-equal? "abc" "abc") ; => #t65
```67
## License69
BSD-3-Clause.71
Vendored mbedTLS (under `vendor/mbedtls/`) is distributed under72
Apache-2.0 OR GPL-2.0-or-later. sigil-crypto's own sources are73
BSD-3-Clause. See `vendor/mbedtls/LICENSE` for the mbedTLS terms.