path: root/include/crypt.h
diff options
authorRich Felker <>2012-06-29 00:56:37 -0400
committerRich Felker <>2012-06-29 00:56:37 -0400
commitcdf51506ce895286011ff0abe5434557845108ee (patch)
tree6060653c351115b09a1b363fcd56014cd0209d61 /include/crypt.h
parent9abab94b211c5103e3f6baf97ad76523618a553c (diff)
replace old and ugly crypt implementation
the new version is largely the work of Solar Designer, with minor changes for integration with musl. compared to the old code, text size is reduced by about 7k, stack space usage by about 70k, and performance is greatly improved by avoiding expensive calculation of constant tables on each run. this version also adds support for extended des-based password hashes, which allow for unlimited key (password) length and configurable iteration counts. i've also published the interface for crypt_r in a new crypt.h header. especially since this is not a standard interface, i did not feel compelled to match the glibc abi for the crypt_data structure. the glibc structure is way too big to allocate on the stack; in fact it's so big that the first usage may cause the main thread to exceed its pre-committed stack size of 128k and thus could cause the program to crash even on systems with overcommit disabled. the only legitimate use of crypt_data for crypt_r is to store the hash string to return, so i've reserved 256 bytes, which should be more than sufficient (longest known password hashes are ~60 characters, and beyond that is possibly even exceeding some implementations' passwd file field size limit).
Diffstat (limited to 'include/crypt.h')
1 files changed, 20 insertions, 0 deletions
diff --git a/include/crypt.h b/include/crypt.h
new file mode 100644
index 00000000..07de2169
--- /dev/null
+++ b/include/crypt.h
@@ -0,0 +1,20 @@
+#ifndef _CRYPT_H
+#define _CRYPT_H
+#ifdef __cplusplus
+extern "C" {
+struct crypt_data {
+ int initialized;
+ char __buf[256];
+char *crypt(const char *, const char *);
+char *crypt_r(const char *, const char *, struct crypt_data *);
+#ifdef __cplusplus