SECHASH(3)
Hey bestie, welcome to the SECHASH(3) manual page from Library Functions Manual β cryptographically secure hashes and all the details, no skips. π
π NAME π
md4, md5, sha1, hmac_md5, hmac_sha1, md5pickle, md5unpickle, sha1pickle, sha1unpickle β cryptographically secure hashes. Periodt. π
β¨ SYNOPSIS β¨
Okay so first you grab these headers, bestie:
#include <u.h>
#include <libc.h>
#include <mp.h>
#include <libsec.h>
Then the function signatures, exactly:
DigestState* md4(uchar *data, ulong dlen, uchar *digest,
DigestState *state)
DigestState* md5(uchar *data, ulong dlen, uchar *digest,
DigestState *state)
char* md5pickle(MD5state *state)
MD5state* md5unpickle(char *p);
DigestState* sha1(uchar *data, ulong dlen, uchar *digest,
DigestState *state)
char* sha1pickle(MD5state *state)
MD5state* sha1unpickle(char *p);
DigestState* hmac_md5(uchar *data, ulong dlen,
uchar *key, ulong klen,
uchar *digest, DigestState *state)
DigestState* hmac_sha1(uchar *data, ulong dlen,
uchar *key, ulong klen,
uchar *digest, DigestState *state)
π DESCRIPTION π
So here's the vibe: these functions implement the cryptographic hash functions MD4, MD5, and SHA1. The output of the hash is called a digest. A hash is secure if, given the hashed data and the digest, it is difficult to predict the change to the digest resulting from some change to the data without rehashing the whole data. Therefore, if a secret is part of the hashed data, the digest can be used as an integrity check of the data by anyone possessing the secret. Iconic. πΈ
The routines md4, md5, sha1, hmac_md5, and hmac_sha1 differ only in the length of the resulting digest and in the security of the hash. Usage for each is the same. The first call to the routine should have nil as the state parameter. This call returns a state which can be used to chain subsequent calls. The last call should have digest non-nil. Digest must point to a buffer of at least the size of the digest produced. This last call will free the state and copy the result into digest. For example, to hash a single buffer using md5:
uchar digest[MD5dlen];
md5(data, len, digest, nil);
To chain a number of buffers together, bounded on each end by some secret:
char buf[256];
uchar digest[MD5dlen];
DigestState *s;
s = md5("my password", 11, nil, nil);
while((n = read(fd, buf, 256)) > 0)
md5(buf, n, nil, s);
md5("drowssap ym", 11, digest, s);
The constants MD4dlen, MD5dlen, and SHA1dlen define the lengths of the digests. π
hmac_md5 and hmac_sha1 are used slightly differently. These hash algorithms are keyed and require a key to be specified on every call. The digest lengths for these hashes are MD5dlen and SHA1dlen respectively. π
The functions md5pickle and sha1pickle marshal the state of a digest for transmission. md5unpickle and sha1unpickle unmarshal a pickled digest. All four routines return a pointer to a newly malloc(3)'d object. π
πΈ SOURCE πΈ
/src/libsec β that's the spot. π
π¦ SEE ALSO π¦
Go read: aes(3), blowfish(3), des(3), elgamal(3), rc4(3), rsa(3). β¨
Cute sign-off: the footer is just the manual name SECHASH(3) β no extra source/version/date line was printed on this page, so that's the whole footer vibe. Bye bestie! ππ
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms