Browse code

Add implementation

Robert Cranston authored on 16/11/2023 00:31:51
Showing 4 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+/cryptgen
0 2
new file mode 100644
... ...
@@ -0,0 +1,2 @@
1
+LDLIBS += -lcrypt
2
+all: cryptgen
... ...
@@ -2,9 +2,38 @@
2 2
 
3 3
 A thin command-line wrapper around [`crypt(3)`][] and [`crypt_gensalt(3)`][].
4 4
 
5
+**NOTE**: This security-related software includes no error checking and uses
6
+functions whose documentation states "This function is obsolete. Do not use
7
+it.". Results are platform-dependent and should be verified manually. It exists
8
+because its constituent 15 non-empty lines of C provides functionality
9
+(specifically [`yescrypt`][], the default password hashing scheme on many Linux
10
+distributions, with automatic parameter encoding and salt generation) that at
11
+the time of writing is not easily accessible from the command line elsewhere
12
+([OpenSSL's `passwd`][], [Perl's `crypt`][], [Python's `crypt`][], [Python's
13
+`hashlib`][]).
14
+
5 15
 [`cryptgen`]: https://git.rcrnstn.net/rcrnstn/cryptgen
6 16
 [`crypt(3)`]: https://manpages.debian.org/crypt.3
7 17
 [`crypt_gensalt(3)`]: https://manpages.debian.org/crypt_gensalt.3
18
+[`yescrypt`]: https://www.openwall.com/yescrypt
19
+[OpenSSL's `passwd`]: https://github.com/openssl/openssl/issues/19340
20
+[Perl's `crypt`]: https://perldoc.perl.org/functions/crypt
21
+[Python's `crypt`]: https://docs.python.org/3/library/crypt
22
+[Python's `hashlib`]: https://docs.python.org/3/library/hashlib
23
+
24
+## Usage
25
+
26
+```
27
+cryptgen [<prefix> [<count>]]
28
+```
29
+
30
+where the valid values of the optional `<prefix>` (hashing method) and
31
+`<count>` ("CPU time cost") parameters are documented in [`crypt(5)`][]. On
32
+most distributions, if `<prefix>` is not given the best available hashing
33
+method will be selected, if `<count>` is not given a low default cost will be
34
+selected.
35
+
36
+[`crypt(5)`]: https://manpages.debian.org/crypt.5
8 37
 
9 38
 ## License
10 39
 
11 40
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+#define _XOPEN_SOURCE 500
2
+
3
+#include <stdio.h>
4
+#include <stdlib.h>
5
+
6
+#include <unistd.h>
7
+#include <crypt.h>
8
+
9
+
10
+int main(int argc, char * argv[])
11
+{
12
+    puts(crypt(getpass("Password: "), crypt_gensalt(
13
+        argc >= 2 ?      argv[1]  : NULL,
14
+        argc >= 3 ? atoi(argv[2]) : 0,
15
+        NULL,
16
+        0
17
+    )));
18
+    return EXIT_SUCCESS;
19
+}