diff options
author | Steffen Jaeckel <jaeckel-floss@eyet-services.de> | 2021-07-08 15:57:34 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-07-23 13:36:20 -0400 |
commit | 29bbe71ccfef3440b4881259c6f8e39b6e7924c6 (patch) | |
tree | 94cb413cee26ff74dd02e3b70ca42a378c6d2ae1 /lib/crypt/crypt-sha512.c | |
parent | 26dd9936574864155b989b9f14319ca2779f0598 (diff) |
lib: wrap crypt API to hide errno usage
In order to prevent using the global errno, replace it with a static
version and create a wrapper function which returns the error value.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'lib/crypt/crypt-sha512.c')
-rw-r--r-- | lib/crypt/crypt-sha512.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/crypt/crypt-sha512.c b/lib/crypt/crypt-sha512.c index 3616019445..8c8e6dd3de 100644 --- a/lib/crypt/crypt-sha512.c +++ b/lib/crypt/crypt-sha512.c @@ -1,10 +1,14 @@ +// SPDX-License-Identifier: CC0-1.0 +/* Based on libxcrypt v4.4.17-0-g6b110bc */ /* One way encryption based on the SHA512-based Unix crypt implementation. * * Written by Ulrich Drepper <drepper at redhat.com> in 2007 [1]. * Modified by Zack Weinberg <zackw at panix.com> in 2017, 2018. * Composed by Björn Esser <besser82 at fedoraproject.org> in 2018. * Modified by Björn Esser <besser82 at fedoraproject.org> in 2020. - * Modified by Steffen Jaeckel <jaeckel-floss at eyet-services.de> in 2020. + * Modified by Steffen Jaeckel <jaeckel-floss at eyet-services.de> in 2021 + * for U-Boot, instead of using the global errno to use a static one + * inside this file. * To the extent possible under law, the named authors have waived all * copyright and related or neighboring rights to this work. * @@ -20,7 +24,7 @@ #include "crypt-port.h" #include "alg-sha512.h" -#include <errno.h> +#include <linux/errno.h> #include <stdio.h> #include <stdlib.h> @@ -69,6 +73,25 @@ static_assert (sizeof (struct sha512_buffer) <= ALG_SPECIFIC_SIZE, "ALG_SPECIFIC_SIZE is too small for SHA512"); +/* Use this instead of including errno.h */ +static int errno; + +void crypt_sha512crypt_rn(const char *phrase, size_t phr_size, + const char *setting, size_t ARG_UNUSED(set_size), + uint8_t *output, size_t out_size, void *scratch, + size_t scr_size); + +int crypt_sha512crypt_rn_wrapped(const char *phrase, size_t phr_size, + const char *setting, size_t set_size, + u8 *output, size_t out_size, void *scratch, + size_t scr_size) +{ + errno = 0; + crypt_sha512crypt_rn(phrase, phr_size, setting, set_size, output, + out_size, scratch, scr_size); + return -errno; +} + /* Subroutine of _xcrypt_crypt_sha512crypt_rn: Feed CTX with LEN bytes of a virtual byte sequence consisting of BLOCK repeated over and over indefinitely. */ |