aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/libbb.h296
-rw-r--r--include/mingw.h2
-rw-r--r--include/platform.h5
-rw-r--r--include/usage.src.h6
4 files changed, 233 insertions, 76 deletions
diff --git a/include/libbb.h b/include/libbb.h
index bc1453e12..03ca9f057 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -281,6 +281,26 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
281# endif 281# endif
282#endif 282#endif
283 283
284#if ENABLE_FEATURE_TLS_SCHANNEL || ENABLE_FEATURE_USE_CNG_API
285# define SECURITY_WIN32
286# include <windows.h>
287# include <security.h>
288#endif
289
290#if ENABLE_FEATURE_USE_CNG_API
291# include <bcrypt.h>
292
293// these work on Windows >= 10
294# define BCRYPT_HMAC_SHA1_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x000000a1)
295# define BCRYPT_HMAC_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x000000b1)
296# define sha1_begin_hmac BCRYPT_HMAC_SHA1_ALG_HANDLE
297# define sha256_begin_hmac BCRYPT_HMAC_SHA256_ALG_HANDLE
298#else
299# define sha1_begin_hmac sha1_begin
300# define sha256_begin_hmac sha256_begin
301# define hmac_uninit(...) ((void)0)
302#endif
303
284/* Tested to work correctly with all int types (IIRC :]) */ 304/* Tested to work correctly with all int types (IIRC :]) */
285#define MAXINT(T) (T)( \ 305#define MAXINT(T) (T)( \
286 ((T)-1) > 0 \ 306 ((T)-1) > 0 \
@@ -699,6 +719,8 @@ int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC;
699int sigprocmask_allsigs(int how) FAST_FUNC; 719int sigprocmask_allsigs(int how) FAST_FUNC;
700/* Return old set in the same set: */ 720/* Return old set in the same set: */
701int sigprocmask2(int how, sigset_t *set) FAST_FUNC; 721int sigprocmask2(int how, sigset_t *set) FAST_FUNC;
722/* SIG_BLOCK all signals, return old set: */
723int sigblockall(sigset_t *set) FAST_FUNC;
702#else 724#else
703#define bb_signals(s, f) 725#define bb_signals(s, f)
704#define kill_myself_with_sig(s) 726#define kill_myself_with_sig(s)
@@ -899,7 +921,36 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC;
899// Also mount.c and inetd.c are using gethostbyname(), 921// Also mount.c and inetd.c are using gethostbyname(),
900// + inet_common.c has additional IPv4-only stuff 922// + inet_common.c has additional IPv4-only stuff
901 923
924#if defined CONFIG_FEATURE_TLS_SCHANNEL
925enum schannel_connection_state {
926 BB_SCHANNEL_OPEN = 0,
927 BB_SCHANNEL_CLOSED = 1,
928 BB_SCHANNEL_CLOSED_AND_FREED = 2
929};
930
931typedef struct tls_state {
932 int ofd;
933 int ifd;
934
935 // handles
936 CredHandle cred_handle;
937 CtxtHandle ctx_handle;
938
939 // buffers
940 char in_buffer[16384 + 256]; // input buffer (to read from server), length is maximum TLS packet size
941 unsigned long in_buffer_offset;
942
943 char *out_buffer; // output buffer (for decrypted data, offset from in_buffer)
944 unsigned long out_buffer_length;
945 unsigned long out_buffer_extra;
902 946
947 // data
948 char *hostname;
949 SecPkgContext_StreamSizes stream_sizes;
950 bool initialized;
951 enum schannel_connection_state connection_state;
952} tls_state_t;
953#else
903struct tls_aes { 954struct tls_aes {
904 uint32_t key[60]; 955 uint32_t key[60];
905 unsigned rounds; 956 unsigned rounds;
@@ -956,12 +1007,14 @@ typedef struct tls_state {
956 struct tls_aes aes_decrypt; 1007 struct tls_aes aes_decrypt;
957 uint8_t H[16]; //used by AES_GCM 1008 uint8_t H[16]; //used by AES_GCM
958} tls_state_t; 1009} tls_state_t;
1010#endif
959 1011
960static inline tls_state_t *new_tls_state(void) 1012static inline tls_state_t *new_tls_state(void)
961{ 1013{
962 tls_state_t *tls = xzalloc(sizeof(*tls)); 1014 tls_state_t *tls = xzalloc(sizeof(*tls));
963 return tls; 1015 return tls;
964} 1016}
1017
965void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; 1018void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC;
966#define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0) 1019#define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0)
967void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; 1020void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC;
@@ -1071,13 +1124,13 @@ unsigned bb_clk_tck(void) FAST_FUNC;
1071 1124
1072#if SEAMLESS_COMPRESSION 1125#if SEAMLESS_COMPRESSION
1073/* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ 1126/* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */
1074int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC; 1127int setup_unzip_on_fd(int fd, int die_if_not_compressed) FAST_FUNC;
1075/* Autodetects .gz etc */ 1128/* Autodetects .gz etc */
1076extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC; 1129extern int open_zipped(const char *fname, int die_if_not_compressed) FAST_FUNC;
1077extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 1130extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
1078#else 1131#else
1079# define setup_unzip_on_fd(...) (0) 1132# define setup_unzip_on_fd(...) (0)
1080# define open_zipped(fname, fail_if_not_compressed) open((fname), O_RDONLY); 1133# define open_zipped(fname, die_if_not_compressed) open((fname), O_RDONLY);
1081# define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p)) 1134# define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p))
1082#endif 1135#endif
1083/* lzma has no signature, need a little helper. NB: exist only for ENABLE_FEATURE_SEAMLESS_LZMA=y */ 1136/* lzma has no signature, need a little helper. NB: exist only for ENABLE_FEATURE_SEAMLESS_LZMA=y */
@@ -1173,6 +1226,32 @@ char *bin2hex(char *dst, const char *src, int count) FAST_FUNC;
1173/* Reverse */ 1226/* Reverse */
1174char* hex2bin(char *dst, const char *src, int count) FAST_FUNC; 1227char* hex2bin(char *dst, const char *src, int count) FAST_FUNC;
1175 1228
1229/* Returns strlen as a bonus */
1230//size_t replace_char(char *s, char what, char with) FAST_FUNC;
1231static inline size_t replace_char(char *str, char from, char to)
1232{
1233 char *p = str;
1234 while (*p) {
1235 if (*p == from)
1236 *p = to;
1237 p++;
1238 }
1239 return p - str;
1240}
1241
1242extern const char c_escape_conv_str00[];
1243#define c_escape_conv_str07 (c_escape_conv_str00+3)
1244
1245void FAST_FUNC xorbuf_3(void *dst, const void *src1, const void *src2, unsigned count);
1246void FAST_FUNC xorbuf(void* buf, const void* mask, unsigned count);
1247void FAST_FUNC xorbuf16_aligned_long(void* buf, const void* mask);
1248void FAST_FUNC xorbuf64_3_aligned64(void *dst, const void *src1, const void *src2);
1249#if BB_UNALIGNED_MEMACCESS_OK
1250# define xorbuf16(buf,mask) xorbuf16_aligned_long(buf,mask)
1251#else
1252void FAST_FUNC xorbuf16(void* buf, const void* mask);
1253#endif
1254
1176/* Generate a UUID */ 1255/* Generate a UUID */
1177void generate_uuid(uint8_t *buf) FAST_FUNC; 1256void generate_uuid(uint8_t *buf) FAST_FUNC;
1178 1257
@@ -1887,18 +1966,25 @@ extern char *pw_encrypt(const char *clear, const char *salt, int cleanup) FAST_F
1887extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC; 1966extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC;
1888/* 1967/*
1889 * rnd is additional random input. New one is returned. 1968 * rnd is additional random input. New one is returned.
1890 * Useful if you call crypt_make_salt many times in a row: 1969 * Useful if you call crypt_make_rand64encoded many times in a row:
1891 * rnd = crypt_make_salt(buf1, 4, 0); 1970 * rnd = crypt_make_rand64encoded(buf1, 4, 0);
1892 * rnd = crypt_make_salt(buf2, 4, rnd); 1971 * rnd = crypt_make_rand64encoded(buf2, 4, rnd);
1893 * rnd = crypt_make_salt(buf3, 4, rnd); 1972 * rnd = crypt_make_rand64encoded(buf3, 4, rnd);
1894 * (otherwise we risk having same salt generated) 1973 * (otherwise we risk having same salt generated)
1895 */ 1974 */
1896extern int crypt_make_salt(char *p, int cnt /*, int rnd*/) FAST_FUNC; 1975extern int crypt_make_rand64encoded(char *p, int cnt /*, int rnd*/) FAST_FUNC;
1897/* "$N$" + sha_salt_16_bytes + NUL */ 1976/* Size of char salt[] to hold randomly-generated salt string
1898#define MAX_PW_SALT_LEN (3 + 16 + 1) 1977 * sha256/512:
1978 * "$5$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>"
1979 * "$6$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>"
1980 * #define MAX_PW_SALT_LEN (3 + sizeof("rounds=999999999$")-1 + 16 + 1)
1981 * yescrypt:
1982 * "$y$" <up to 8 params of up to 6 chars each> "$" <up to 86 chars salt><NUL>
1983 * (86 chars are ascii64-encoded 64 binary bytes)
1984 */
1985#define MAX_PW_SALT_LEN (3 + 8*6 + 1 + 86 + 1)
1899extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC; 1986extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC;
1900 1987
1901
1902/* Returns number of lines changed, or -1 on error */ 1988/* Returns number of lines changed, or -1 on error */
1903#if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP) 1989#if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP)
1904#define update_passwd(filename, username, data, member) \ 1990#define update_passwd(filename, username, data, member) \
@@ -2041,6 +2127,10 @@ int64_t windows_read_key(int fd, char *buffer, int timeout) FAST_FUNC;
2041int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; 2127int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC;
2042void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; 2128void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC;
2043 2129
2130int check_got_signal_and_poll(struct pollfd pfd[1], int timeout) FAST_FUNC;
2131#if ENABLE_PLATFORM_MINGW32
2132# define check_got_signal_and_poll(p, t) poll(p, 1, t)
2133#endif
2044 2134
2045#if ENABLE_FEATURE_EDITING 2135#if ENABLE_FEATURE_EDITING
2046/* It's NOT just ENABLEd or disabled. It's a number: */ 2136/* It's NOT just ENABLEd or disabled. It's a number: */
@@ -2087,7 +2177,7 @@ typedef struct line_input_t {
2087# if MAX_HISTORY 2177# if MAX_HISTORY
2088 int cnt_history; 2178 int cnt_history;
2089 int cur_history; 2179 int cur_history;
2090 int max_history; /* must never be <= 0 */ 2180 int max_history; /* must never be < 0 */
2091# if ENABLE_FEATURE_EDITING_SAVEHISTORY 2181# if ENABLE_FEATURE_EDITING_SAVEHISTORY
2092 /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT: 2182 /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT:
2093 * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are 2183 * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are
@@ -2153,33 +2243,6 @@ enum { COMM_LEN = 16 };
2153# endif 2243# endif
2154#endif 2244#endif
2155 2245
2156struct smaprec {
2157 unsigned long mapped_rw;
2158 unsigned long mapped_ro;
2159 unsigned long shared_clean;
2160 unsigned long shared_dirty;
2161 unsigned long private_clean;
2162 unsigned long private_dirty;
2163 unsigned long stack;
2164 unsigned long smap_pss, smap_swap;
2165 unsigned long smap_size;
2166 // For mixed 32/64 userspace, 32-bit pmap still needs
2167 // 64-bit field here to correctly show 64-bit processes:
2168 unsigned long long smap_start;
2169 // (strictly speaking, other fields need to be wider too,
2170 // but they are in kbytes, not bytes, and they hold sizes,
2171 // not start addresses, sizes tend to be less than 4 terabytes)
2172 char smap_mode[5];
2173 char *smap_name;
2174};
2175
2176#if !ENABLE_PMAP
2177#define procps_read_smaps(pid, total, cb, data) \
2178 procps_read_smaps(pid, total)
2179#endif
2180int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
2181 void (*cb)(struct smaprec *, void *), void *data);
2182
2183typedef struct procps_status_t { 2246typedef struct procps_status_t {
2184#if !ENABLE_PLATFORM_MINGW32 2247#if !ENABLE_PLATFORM_MINGW32
2185 DIR *dir; 2248 DIR *dir;
@@ -2215,7 +2278,13 @@ typedef struct procps_status_t {
2215#endif 2278#endif
2216 unsigned tty_major,tty_minor; 2279 unsigned tty_major,tty_minor;
2217#if ENABLE_FEATURE_TOPMEM 2280#if ENABLE_FEATURE_TOPMEM
2218 struct smaprec smaps; 2281 unsigned long mapped_rw;
2282 unsigned long mapped_ro;
2283 unsigned long shared_clean;
2284 unsigned long shared_dirty;
2285 unsigned long private_clean;
2286 unsigned long private_dirty;
2287 unsigned long stack;
2219#endif 2288#endif
2220 char state[4]; 2289 char state[4];
2221 /* basename of executable in exec(2), read from /proc/N/stat 2290 /* basename of executable in exec(2), read from /proc/N/stat
@@ -2264,11 +2333,15 @@ void free_procps_scan(procps_status_t* sp) FAST_FUNC;
2264procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; 2333procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC;
2265/* Format cmdline (up to col chars) into char buf[size] */ 2334/* Format cmdline (up to col chars) into char buf[size] */
2266/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ 2335/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */
2267void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; 2336int read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC;
2268pid_t *find_pid_by_name(const char* procName) FAST_FUNC; 2337pid_t *find_pid_by_name(const char* procName) FAST_FUNC;
2269pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; 2338pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC;
2270int starts_with_cpu(const char *str) FAST_FUNC; 2339int starts_with_cpu(const char *str) FAST_FUNC;
2271unsigned get_cpu_count(void) FAST_FUNC; 2340unsigned get_cpu_count(void) FAST_FUNC;
2341/* Some internals reused by pmap: */
2342unsigned long FAST_FUNC fast_strtoul_10(char **endptr);
2343unsigned long long FAST_FUNC fast_strtoull_16(char **endptr);
2344char* FAST_FUNC skip_fields(char *str, int count);
2272 2345
2273 2346
2274/* Use strict=1 if you process input from untrusted source: 2347/* Use strict=1 if you process input from untrusted source:
@@ -2294,6 +2367,56 @@ char *decode_base64(char *dst, const char **pp_src) FAST_FUNC;
2294char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; 2367char *decode_base32(char *dst, const char **pp_src) FAST_FUNC;
2295void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; 2368void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
2296 2369
2370int FAST_FUNC i2a64(int i);
2371int FAST_FUNC a2i64(char c);
2372char* FAST_FUNC num2str64_lsb_first(char *s, unsigned v, int n);
2373
2374enum {
2375 /* how many bytes XYZ_end() fills */
2376 MD5_OUTSIZE = 16,
2377 SHA1_OUTSIZE = 20,
2378 SHA256_OUTSIZE = 32,
2379 SHA384_OUTSIZE = 48,
2380 SHA512_OUTSIZE = 64,
2381 //SHA3-224_OUTSIZE = 28,
2382 /* size of input block */
2383 SHA2_INSIZE = 64,
2384};
2385
2386#if defined CONFIG_FEATURE_USE_CNG_API
2387struct bcrypt_hash_ctx_t {
2388 void *handle;
2389 void *hash_obj;
2390 unsigned int output_size;
2391};
2392typedef struct bcrypt_hash_ctx_t md5_ctx_t;
2393typedef struct bcrypt_hash_ctx_t sha1_ctx_t;
2394typedef struct bcrypt_hash_ctx_t sha256_ctx_t;
2395typedef struct bcrypt_hash_ctx_t sha384_ctx_t;
2396typedef struct bcrypt_hash_ctx_t sha512_ctx_t;
2397typedef struct sha3_ctx_t {
2398 uint64_t state[25];
2399 unsigned bytes_queued;
2400 unsigned input_block_bytes;
2401} sha3_ctx_t;
2402void md5_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2403void sha1_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2404void sha256_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2405void sha384_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2406void sha512_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2407void generic_hash(struct bcrypt_hash_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
2408unsigned generic_end(struct bcrypt_hash_ctx_t *ctx, void *resbuf) FAST_FUNC;
2409# define md5_hash generic_hash
2410# define sha1_hash generic_hash
2411# define sha256_hash generic_hash
2412# define sha384_hash generic_hash
2413# define sha512_hash generic_hash
2414# define md5_end generic_end
2415# define sha1_end generic_end
2416# define sha256_end generic_end
2417# define sha384_end generic_end
2418# define sha512_end generic_end
2419#else
2297typedef struct md5_ctx_t { 2420typedef struct md5_ctx_t {
2298 uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ 2421 uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
2299 void (*process_block)(struct md5_ctx_t*) FAST_FUNC; 2422 void (*process_block)(struct md5_ctx_t*) FAST_FUNC;
@@ -2307,6 +2430,7 @@ typedef struct sha512_ctx_t {
2307 uint64_t hash[8]; 2430 uint64_t hash[8];
2308 uint8_t wbuffer[128]; /* always correctly aligned for uint64_t */ 2431 uint8_t wbuffer[128]; /* always correctly aligned for uint64_t */
2309} sha512_ctx_t; 2432} sha512_ctx_t;
2433typedef struct sha512_ctx_t sha384_ctx_t;
2310typedef struct sha3_ctx_t { 2434typedef struct sha3_ctx_t {
2311 uint64_t state[25]; 2435 uint64_t state[25];
2312 unsigned bytes_queued; 2436 unsigned bytes_queued;
@@ -2324,20 +2448,69 @@ void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
2324void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; 2448void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
2325void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 2449void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
2326unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; 2450unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
2451void sha384_begin(sha384_ctx_t *ctx) FAST_FUNC;
2452#define sha384_hash sha512_hash
2453unsigned sha384_end(sha384_ctx_t *ctx, void *resbuf) FAST_FUNC;
2454#endif
2327void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; 2455void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC;
2328void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 2456void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
2329unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; 2457unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
2458void FAST_FUNC sha256_block(const void *in, size_t len, uint8_t hash[32]);
2330/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ 2459/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */
2460#if defined CONFIG_FEATURE_USE_CNG_API
2461typedef struct bcrypt_hash_ctx_t md5sha_ctx_t;
2462#define md5sha_hash generic_hash
2463#define sha_end generic_end
2464#else
2331typedef struct md5_ctx_t md5sha_ctx_t; 2465typedef struct md5_ctx_t md5sha_ctx_t;
2332#define md5sha_hash md5_hash 2466#define md5sha_hash md5_hash
2333#define sha_end sha1_end 2467#define sha_end sha1_end
2334enum { 2468#endif
2335 MD5_OUTSIZE = 16, 2469
2336 SHA1_OUTSIZE = 20, 2470/* RFC 2104 HMAC (hash-based message authentication code) */
2337 SHA256_OUTSIZE = 32, 2471#if !ENABLE_FEATURE_USE_CNG_API
2338 SHA512_OUTSIZE = 64, 2472typedef struct hmac_ctx {
2339 SHA3_OUTSIZE = 28, 2473 md5sha_ctx_t hashed_key_xor_ipad;
2340}; 2474 md5sha_ctx_t hashed_key_xor_opad;
2475} hmac_ctx_t;
2476#else
2477typedef struct bcrypt_hash_ctx_t hmac_ctx_t;
2478#endif
2479#define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1)
2480typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC;
2481#if !ENABLE_FEATURE_USE_CNG_API
2482#if HMAC_ONLY_SHA256
2483#define hmac_begin(ctx,key,key_size,begin) \
2484 hmac_begin(ctx,key,key_size)
2485#endif
2486void FAST_FUNC hmac_begin(hmac_ctx_t *ctx, const uint8_t *key, unsigned key_size, md5sha_begin_func *begin);
2487static ALWAYS_INLINE void hmac_hash(hmac_ctx_t *ctx, const void *in, size_t len)
2488{
2489 md5sha_hash(&ctx->hashed_key_xor_ipad, in, len);
2490}
2491#else
2492# if HMAC_ONLY_SHA256
2493# define hmac_begin(pre,key,key_size,begin) \
2494 _hmac_begin(pre, key, key_size, sha256_begin_hmac)
2495# else
2496# define hmac_begin _hmac_begin
2497# endif
2498void _hmac_begin(hmac_ctx_t *pre, uint8_t *key, unsigned key_size,
2499 BCRYPT_ALG_HANDLE alg_handle);
2500void hmac_uninit(hmac_ctx_t *pre);
2501#endif
2502unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out);
2503#if HMAC_ONLY_SHA256
2504#define hmac_block(key,key_size,begin,in,sz,out) \
2505 hmac_block(key,key_size,in,sz,out)
2506#endif
2507unsigned FAST_FUNC hmac_block(const uint8_t *key, unsigned key_size,
2508 md5sha_begin_func *begin,
2509 const void *in, unsigned sz,
2510 uint8_t *out);
2511/* HMAC helpers for TLS: */
2512void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va);
2513unsigned hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...);
2341 2514
2342extern uint32_t *global_crc32_table; 2515extern uint32_t *global_crc32_table;
2343uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; 2516uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
@@ -2473,31 +2646,10 @@ extern struct globals *BB_GLOBAL_CONST ptr_to_globals;
2473#define barrier() asm volatile ("":::"memory") 2646#define barrier() asm volatile ("":::"memory")
2474 2647
2475#if defined(__clang_major__) && __clang_major__ >= 9 2648#if defined(__clang_major__) && __clang_major__ >= 9
2476/* Clang/llvm drops assignment to "constant" storage. Silently. 2649/* {ASSIGN,XZALLOC}_CONST_PTR() are out-of-line functions
2477 * Needs serious convincing to not eliminate the store. 2650 * to prevent clang from reading pointer before it is assigned.
2478 */
2479static ALWAYS_INLINE void* not_const_pp(const void *p)
2480{
2481 void *pp;
2482 asm volatile (
2483 "# forget that p points to const"
2484 : /*outputs*/ "=r" (pp)
2485 : /*inputs*/ "0" (p)
2486 );
2487 return pp;
2488}
2489# if !ENABLE_PLATFORM_MINGW32
2490# define ASSIGN_CONST_PTR(pptr, v) do { \
2491 *(void**)not_const_pp(pptr) = (void*)(v); \
2492 barrier(); \
2493} while (0)
2494#else
2495/* On Windows it seems necessary for this to be a function too. */
2496void ASSIGN_CONST_PTR(const void *pptr, const void *ptr) FAST_FUNC;
2497#endif
2498/* XZALLOC_CONST_PTR() is an out-of-line function to prevent
2499 * clang from reading pointer before it is assigned.
2500 */ 2651 */
2652void ASSIGN_CONST_PTR(const void *pptr, void *v) FAST_FUNC;
2501void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; 2653void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC;
2502#else 2654#else
2503# define ASSIGN_CONST_PTR(pptr, v) do { \ 2655# define ASSIGN_CONST_PTR(pptr, v) do { \
diff --git a/include/mingw.h b/include/mingw.h
index 3ee1cc46f..276e40659 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -259,6 +259,7 @@ int ffs(int i);
259 */ 259 */
260 260
261#define TIOCGWINSZ 0x5413 261#define TIOCGWINSZ 0x5413
262#define TIOCSWINSZ 0x5414
262 263
263int ioctl(int fd, int code, ...); 264int ioctl(int fd, int code, ...);
264 265
@@ -670,3 +671,4 @@ enum {
670int elevation_state(void); 671int elevation_state(void);
671void set_interp(int i) FAST_FUNC; 672void set_interp(int i) FAST_FUNC;
672int mingw_shell_execute(SHELLEXECUTEINFO *info); 673int mingw_shell_execute(SHELLEXECUTEINFO *info);
674void mingw_die_if_error(NTSTATUS status, const char *function_name);
diff --git a/include/platform.h b/include/platform.h
index 5795a0cf3..0db8bf345 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -208,7 +208,7 @@
208#elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN 208#elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN
209# define BB_BIG_ENDIAN 0 209# define BB_BIG_ENDIAN 0
210# define BB_LITTLE_ENDIAN 1 210# define BB_LITTLE_ENDIAN 1
211#elif defined(__386__) 211#elif defined(__i386__)
212# define BB_BIG_ENDIAN 0 212# define BB_BIG_ENDIAN 0
213# define BB_LITTLE_ENDIAN 1 213# define BB_LITTLE_ENDIAN 1
214#else 214#else
@@ -230,6 +230,8 @@
230# define SWAP_LE64(x) bb_bswap_64(x) 230# define SWAP_LE64(x) bb_bswap_64(x)
231# define IF_BIG_ENDIAN(...) __VA_ARGS__ 231# define IF_BIG_ENDIAN(...) __VA_ARGS__
232# define IF_LITTLE_ENDIAN(...) 232# define IF_LITTLE_ENDIAN(...)
233/* How do bytes a,b,c,d (sequential in memory) look if fetched into uint32_t? */
234# define PACK32_BYTES(a,b,c,d) (uint32_t)((d)+((c)<<8)+((b)<<16)+((a)<<24))
233#else 235#else
234# define SWAP_BE16(x) bswap_16(x) 236# define SWAP_BE16(x) bswap_16(x)
235# define SWAP_BE32(x) bswap_32(x) 237# define SWAP_BE32(x) bswap_32(x)
@@ -239,6 +241,7 @@
239# define SWAP_LE64(x) (x) 241# define SWAP_LE64(x) (x)
240# define IF_BIG_ENDIAN(...) 242# define IF_BIG_ENDIAN(...)
241# define IF_LITTLE_ENDIAN(...) __VA_ARGS__ 243# define IF_LITTLE_ENDIAN(...) __VA_ARGS__
244# define PACK32_BYTES(a,b,c,d) (uint32_t)((a)+((b)<<8)+((c)<<16)+((d)<<24))
242#endif 245#endif
243 246
244 247
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