The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
crypt.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file crypt.h
5 * @brief password hashes: crypt() with the SHA-crypt "$5$" scheme (SHA-256),
6 * the one glibc and "openssl passwd -5" make.
7 *
8 * a hash is "$5$salt$hash" or "$5$rounds=N$salt$hash": the salt is up to
9 * 16 characters of [./0-9A-Za-z], the rounds 1000 to 999999999 (5000 when
10 * not given).
11 */
12
13#include <stddef.h>
14#include <stdint.h>
15
16/**
17 * hash a password with the scheme, rounds and salt of setting (a whole
18 * hash can be given: what is after the salt is not used).
19 * @return the hash in a static buffer, or NULL for a setting that is not
20 * "$5$".
21 */
22char *crypt(const char *key, const char *setting);
23
24/**
25 * check a password against a hash, in a time that does not depend on
26 * where the two differ (ginnOS).
27 * @return 1 when it matches, 0 when it does not or the hash is not "$5$".
28 */
29int crypt_verify(const char *key, const char *hash);
30
31/**
32 * a new hash of a password with a fresh salt and the default rounds
33 * (ginnOS). the salt is unique, not secret: the SHA-256 of the time, the
34 * CPU's cycle counter, the pid and the seed.
35 * @param seed more bytes to mix in (may be NULL).
36 * @return the hash in a static buffer.
37 */
38char *crypt_new(const char *key, const void *seed, size_t seed_length);
39
40/** SHA-256 of data (FIPS 180-4) */
41void sha256(const void *data, size_t length, uint8_t out[32]);
int crypt_verify(const char *key, const char *hash)
check a password against a hash, in a time that does not depend on where the two differ (ginnOS).
char * crypt(const char *key, const char *setting)
hash a password with the scheme, rounds and salt of setting (a whole hash can be given: what is after...
void sha256(const void *data, size_t length, uint8_t out[32])
SHA-256 of data (FIPS 180-4).
char * crypt_new(const char *key, const void *seed, size_t seed_length)
a new hash of a password with a fresh salt and the default rounds (ginnOS).
unsigned char uint8_t
Definition fb.h:18
NULL, size_t, ptrdiff_t, offsetof.
integer types of fixed width.