diff options
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/hash_sha256_block.c | 19 | ||||
| -rw-r--r-- | libbb/pw_encrypt_yes.c | 24 |
2 files changed, 43 insertions, 0 deletions
diff --git a/libbb/hash_sha256_block.c b/libbb/hash_sha256_block.c new file mode 100644 index 000000000..3c4366321 --- /dev/null +++ b/libbb/hash_sha256_block.c | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) 2025 Denys Vlasenko | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
| 8 | */ | ||
| 9 | //kbuild:lib-y += hash_sha256_block.o | ||
| 10 | #include "libbb.h" | ||
| 11 | |||
| 12 | void FAST_FUNC | ||
| 13 | sha256_block(const void *in, size_t len, uint8_t hash[32]) | ||
| 14 | { | ||
| 15 | sha256_ctx_t ctx; | ||
| 16 | sha256_begin(&ctx); | ||
| 17 | sha256_hash(&ctx, in, len); | ||
| 18 | sha256_end(&ctx, hash); | ||
| 19 | } | ||
diff --git a/libbb/pw_encrypt_yes.c b/libbb/pw_encrypt_yes.c new file mode 100644 index 000000000..50bd06418 --- /dev/null +++ b/libbb/pw_encrypt_yes.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* | ||
| 2 | * Utility routines. | ||
| 3 | * | ||
| 4 | * Copyright (C) 2025 by Denys Vlasenko <vda.linux@googlemail.com> | ||
| 5 | * | ||
| 6 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
| 7 | */ | ||
| 8 | #include "yescrypt/alg-yescrypt.h" | ||
| 9 | |||
| 10 | static char * | ||
| 11 | yes_crypt(const char *passwd, const char *salt_data) | ||
| 12 | { | ||
| 13 | /* prefix, '$', hash, NUL */ | ||
| 14 | char buf[YESCRYPT_PREFIX_LEN + 1 + YESCRYPT_HASH_LEN + 1]; | ||
| 15 | char *retval; | ||
| 16 | |||
| 17 | retval = yescrypt_r( | ||
| 18 | (const uint8_t *)passwd, strlen(passwd), | ||
| 19 | (const uint8_t *)salt_data, | ||
| 20 | buf, sizeof(buf)); | ||
| 21 | /* The returned value is either buf[], or NULL on error */ | ||
| 22 | |||
| 23 | return xstrdup(retval); | ||
| 24 | } | ||
