aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2025-08-12 08:07:00 +0100
committerRon Yorston <rmy@pobox.com>2025-08-12 08:07:00 +0100
commit4e6b0b3e8b8f819bc9e2f69b0c267abecfe30968 (patch)
treed030cd6daff8d3b79f1fbefa0b33bd02f33c3d5c /include
parentaa6a7ebcfb93b21916ad5fb97ecf64c22328c07b (diff)
parent628a7b2f4708037056a1432d7b6b1792c67e486a (diff)
downloadbusybox-w32-4e6b0b3e8b8f819bc9e2f69b0c267abecfe30968.tar.gz
busybox-w32-4e6b0b3e8b8f819bc9e2f69b0c267abecfe30968.tar.bz2
busybox-w32-4e6b0b3e8b8f819bc9e2f69b0c267abecfe30968.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h85
-rw-r--r--include/usage.src.h6
2 files changed, 73 insertions, 18 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 4cacdacba..7a375f4d2 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1210,6 +1210,16 @@ char *bin2hex(char *dst, const char *src, int count) FAST_FUNC;
1210/* Reverse */ 1210/* Reverse */
1211char* hex2bin(char *dst, const char *src, int count) FAST_FUNC; 1211char* hex2bin(char *dst, const char *src, int count) FAST_FUNC;
1212 1212
1213void FAST_FUNC xorbuf_3(void *dst, const void *src1, const void *src2, unsigned count);
1214void FAST_FUNC xorbuf(void* buf, const void* mask, unsigned count);
1215void FAST_FUNC xorbuf16_aligned_long(void* buf, const void* mask);
1216void FAST_FUNC xorbuf64_3_aligned64(void *dst, const void *src1, const void *src2);
1217#if BB_UNALIGNED_MEMACCESS_OK
1218# define xorbuf16(buf,mask) xorbuf16_aligned_long(buf,mask)
1219#else
1220void FAST_FUNC xorbuf16(void* buf, const void* mask);
1221#endif
1222
1213/* Generate a UUID */ 1223/* Generate a UUID */
1214void generate_uuid(uint8_t *buf) FAST_FUNC; 1224void generate_uuid(uint8_t *buf) FAST_FUNC;
1215 1225
@@ -1924,18 +1934,25 @@ extern char *pw_encrypt(const char *clear, const char *salt, int cleanup) FAST_F
1924extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC; 1934extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC;
1925/* 1935/*
1926 * rnd is additional random input. New one is returned. 1936 * rnd is additional random input. New one is returned.
1927 * Useful if you call crypt_make_salt many times in a row: 1937 * Useful if you call crypt_make_rand64encoded many times in a row:
1928 * rnd = crypt_make_salt(buf1, 4, 0); 1938 * rnd = crypt_make_rand64encoded(buf1, 4, 0);
1929 * rnd = crypt_make_salt(buf2, 4, rnd); 1939 * rnd = crypt_make_rand64encoded(buf2, 4, rnd);
1930 * rnd = crypt_make_salt(buf3, 4, rnd); 1940 * rnd = crypt_make_rand64encoded(buf3, 4, rnd);
1931 * (otherwise we risk having same salt generated) 1941 * (otherwise we risk having same salt generated)
1932 */ 1942 */
1933extern int crypt_make_salt(char *p, int cnt /*, int rnd*/) FAST_FUNC; 1943extern int crypt_make_rand64encoded(char *p, int cnt /*, int rnd*/) FAST_FUNC;
1934/* "$N$" + sha_salt_16_bytes + NUL */ 1944/* Size of char salt[] to hold randomly-generated salt string
1935#define MAX_PW_SALT_LEN (3 + 16 + 1) 1945 * sha256/512:
1946 * "$5$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>"
1947 * "$6$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>"
1948 * #define MAX_PW_SALT_LEN (3 + sizeof("rounds=999999999$")-1 + 16 + 1)
1949 * yescrypt:
1950 * "$y$" <up to 8 params of up to 6 chars each> "$" <up to 86 chars salt><NUL>
1951 * (86 chars are ascii64-encoded 64 binary bytes)
1952 */
1953#define MAX_PW_SALT_LEN (3 + 8*6 + 1 + 86 + 1)
1936extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC; 1954extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC;
1937 1955
1938
1939/* Returns number of lines changed, or -1 on error */ 1956/* Returns number of lines changed, or -1 on error */
1940#if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP) 1957#if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP)
1941#define update_passwd(filename, username, data, member) \ 1958#define update_passwd(filename, username, data, member) \
@@ -2335,6 +2352,21 @@ char *decode_base64(char *dst, const char **pp_src) FAST_FUNC;
2335char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; 2352char *decode_base32(char *dst, const char **pp_src) FAST_FUNC;
2336void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; 2353void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
2337 2354
2355int FAST_FUNC i2a64(int i);
2356int FAST_FUNC a2i64(char c);
2357char* FAST_FUNC num2str64_lsb_first(char *s, unsigned v, int n);
2358
2359enum {
2360 /* how many bytes XYZ_end() fills */
2361 MD5_OUTSIZE = 16,
2362 SHA1_OUTSIZE = 20,
2363 SHA256_OUTSIZE = 32,
2364 SHA512_OUTSIZE = 64,
2365 SHA3_OUTSIZE = 28,
2366 /* size of input block */
2367 SHA2_INSIZE = 64,
2368};
2369
2338#if defined CONFIG_FEATURE_USE_CNG_API 2370#if defined CONFIG_FEATURE_USE_CNG_API
2339struct bcrypt_hash_ctx_t { 2371struct bcrypt_hash_ctx_t {
2340 void *handle; 2372 void *handle;
@@ -2399,6 +2431,7 @@ unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
2399void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; 2431void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC;
2400void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 2432void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
2401unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; 2433unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
2434void FAST_FUNC sha256_block(const void *in, size_t len, uint8_t hash[32]);
2402/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ 2435/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */
2403#if defined CONFIG_FEATURE_USE_CNG_API 2436#if defined CONFIG_FEATURE_USE_CNG_API
2404typedef struct bcrypt_hash_ctx_t md5sha_ctx_t; 2437typedef struct bcrypt_hash_ctx_t md5sha_ctx_t;
@@ -2409,13 +2442,35 @@ typedef struct md5_ctx_t md5sha_ctx_t;
2409#define md5sha_hash md5_hash 2442#define md5sha_hash md5_hash
2410#define sha_end sha1_end 2443#define sha_end sha1_end
2411#endif 2444#endif
2412enum { 2445
2413 MD5_OUTSIZE = 16, 2446/* RFC 2104 HMAC (hash-based message authentication code) */
2414 SHA1_OUTSIZE = 20, 2447typedef struct hmac_ctx {
2415 SHA256_OUTSIZE = 32, 2448 md5sha_ctx_t hashed_key_xor_ipad;
2416 SHA512_OUTSIZE = 64, 2449 md5sha_ctx_t hashed_key_xor_opad;
2417 SHA3_OUTSIZE = 28, 2450} hmac_ctx_t;
2418}; 2451#define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1)
2452typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC;
2453#if HMAC_ONLY_SHA256
2454#define hmac_begin(ctx,key,key_size,begin) \
2455 hmac_begin(ctx,key,key_size)
2456#endif
2457void FAST_FUNC hmac_begin(hmac_ctx_t *ctx, const uint8_t *key, unsigned key_size, md5sha_begin_func *begin);
2458static ALWAYS_INLINE void hmac_hash(hmac_ctx_t *ctx, const void *in, size_t len)
2459{
2460 md5sha_hash(&ctx->hashed_key_xor_ipad, in, len);
2461}
2462unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out);
2463#if HMAC_ONLY_SHA256
2464#define hmac_block(key,key_size,begin,in,sz,out) \
2465 hmac_block(key,key_size,in,sz,out)
2466#endif
2467unsigned FAST_FUNC hmac_block(const uint8_t *key, unsigned key_size,
2468 md5sha_begin_func *begin,
2469 const void *in, unsigned sz,
2470 uint8_t *out);
2471/* HMAC helpers for TLS: */
2472void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va);
2473unsigned FAST_FUNC hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...);
2419 2474
2420extern uint32_t *global_crc32_table; 2475extern uint32_t *global_crc32_table;
2421uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; 2476uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
diff --git a/include/usage.src.h b/include/usage.src.h
index 5d2038834..0881337f8 100644
--- a/include/usage.src.h
+++ b/include/usage.src.h
@@ -17,11 +17,11 @@
17#define scripted_trivial_usage NOUSAGE_STR 17#define scripted_trivial_usage NOUSAGE_STR
18#define scripted_full_usage "" 18#define scripted_full_usage ""
19 19
20#if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA 20#if !ENABLE_USE_BB_CRYPT
21# define CRYPT_METHODS_HELP_STR "des,md5,sha256/512" \ 21# define CRYPT_METHODS_HELP_STR "des,md5,sha256/512,yescrypt" \
22 " (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")" 22 " (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
23#else 23#else
24# define CRYPT_METHODS_HELP_STR "des,md5" \ 24# define CRYPT_METHODS_HELP_STR "des,md5"IF_USE_BB_CRYPT_SHA(",sha256/512")IF_USE_BB_CRYPT_YES(",yescrypt") \
25 " (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")" 25 " (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
26#endif 26#endif
27 27