summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2021-02-27 17:21:09 -0500
committerZack Weinberg <zackw@panix.com>2021-03-07 11:00:43 -0500
commit03206febcd26c2ab7b94f3f5cf401d8c6ba5092f (patch)
tree76ffccd4d8df851798c704190ac4420ccde4e94f
parentd39aa30fb98330b5a894341488dd6695f557241a (diff)
downloadlibxcrypt-03206febcd26c2ab7b94f3f5cf401d8c6ba5092f.tar.gz
libxcrypt-03206febcd26c2ab7b94f3f5cf401d8c6ba5092f.tar.bz2
libxcrypt-03206febcd26c2ab7b94f3f5cf401d8c6ba5092f.zip
Fold crypt-common.h into crypt-port.h.
Miscellaneous shared utility routines and data are declared inconsistently in either crypt-common.h or crypt-port.h. The only place where crypt-common.h is included is in crypt-port.h. Simplify the situation by folding the contents of crypt-common.h into crypt-port.h.
-rw-r--r--Makefile.am1
-rw-r--r--lib/crypt-common.h53
-rw-r--r--lib/crypt-port.h38
3 files changed, 37 insertions, 55 deletions
diff --git a/Makefile.am b/Makefile.am
index 1899fc6..a9f4146 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -77,7 +77,6 @@ noinst_HEADERS = \
lib/alg-sha512.h \
lib/alg-yescrypt.h \
lib/byteorder.h \
- lib/crypt-common.h \
lib/crypt-obsolete.h \
lib/crypt-port.h \
test/des-cases.h \
diff --git a/lib/crypt-common.h b/lib/crypt-common.h
deleted file mode 100644
index 1134bc4..0000000
--- a/lib/crypt-common.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright (C) 2018-2019 Björn Esser <besser82@fedoraproject.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* Simple commonly used helper constants. */
-
-#ifndef _CRYPT_COMMON_H
-#define _CRYPT_COMMON_H 1
-
-/* The base-64 encoding table used by most hashing methods.
- (bcrypt uses a slightly different encoding.) Size 65
- because it's used as a C string in a few places. */
-extern const unsigned char ascii64[65];
-
-/* Same table gets used with other names in various places. */
-#define b64t ((const char *) ascii64)
-#define itoa64 ascii64
-
-/* For historical reasons, crypt and crypt_r are not expected ever
- to return 0, and for internal implementation reasons (see
- call_crypt_fn, in crypt.c), it is simpler if the individual
- algorithms' crypt and gensalt functions return nothing.
-
- This function generates a "failure token" in the output buffer,
- which is guaranteed not to be equal to any valid password hash or
- setting string, nor to the setting(+hash) string that was passed
- in; thus, a subsequent blind attempt to authenticate someone by
- comparing the output to a previously recorded hash string will
- fail, even if that string is itself one of these "failure tokens".
-
- We always call this function on the output buffer as the first
- step. If the individual algorithm's crypt or gensalt function
- succeeds, it overwrites the failure token with real output;
- otherwise the token is left intact, and the API functions that
- _can_ return 0 on error notice it. */
-extern void
-make_failure_token (const char *setting, char *output, int size);
-
-#endif /* crypt-common.h */
diff --git a/lib/crypt-port.h b/lib/crypt-port.h
index 0e9d6f2..0f9618f 100644
--- a/lib/crypt-port.h
+++ b/lib/crypt-port.h
@@ -396,14 +396,51 @@ extern char *fcrypt (const char *key, const char *setting);
#endif
/* Utility functions */
+
+/* Fill BUF with BUFLEN bytes whose values are chosen uniformly at
+ random, using a cryptographically strong RNG provided by the
+ operating system. BUFLEN may not be greater than 256. Returns
+ true if all BUFLEN bytes were successfully filled, false otherwise;
+ sets errno when it returns false. Can block. */
extern bool get_random_bytes (void *buf, size_t buflen);
+/* Generate a setting string in the format common to md5crypt,
+ sha256crypt, and sha512crypt. */
extern void gensalt_sha_rn (char tag, size_t maxsalt, unsigned long defcount,
unsigned long mincount, unsigned long maxcount,
unsigned long count,
const uint8_t *rbytes, size_t nrbytes,
uint8_t *output, size_t output_size);
+/* For historical reasons, crypt and crypt_r are not expected ever
+ to return 0, and for internal implementation reasons (see
+ call_crypt_fn, in crypt.c), it is simpler if the individual
+ algorithms' crypt and gensalt functions return nothing.
+
+ This function generates a "failure token" in the output buffer,
+ which is guaranteed not to be equal to any valid password hash or
+ setting string, nor to the setting(+hash) string that was passed
+ in; thus, a subsequent blind attempt to authenticate someone by
+ comparing the output to a previously recorded hash string will
+ fail, even if that string is itself one of these "failure tokens".
+
+ We always call this function on the output buffer as the first
+ step. If the individual algorithm's crypt or gensalt function
+ succeeds, it overwrites the failure token with real output;
+ otherwise the token is left intact, and the API functions that
+ _can_ return 0 on error notice it. */
+extern void
+make_failure_token (const char *setting, char *output, int size);
+
+/* The base-64 encoding table used by most hashing methods.
+ (bcrypt uses a slightly different encoding.) Size 65
+ because it's used as a C string in a few places. */
+extern const unsigned char ascii64[65];
+
+/* Same table gets used with other names in various places. */
+#define b64t ((const char *) ascii64)
+#define itoa64 ascii64
+
/* Calculate the size of a base64 encoding of N bytes:
6 bits per output byte, rounded up. */
#define BASE64_LEN(bytes) ((((bytes) * 8) + 5) / 6)
@@ -413,6 +450,5 @@ extern void gensalt_sha_rn (char tag, size_t maxsalt, unsigned long defcount,
#define ALG_SPECIFIC_SIZE 8192
#include "crypt.h"
-#include "crypt-common.h"
#endif /* crypt-port.h */