diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-02-11 16:55:57 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-02-11 16:55:57 -0800 |
commit | d073bdc6a06f26b81457abed653c8fb9cee4ba0c (patch) | |
tree | e4454ca629f905969c4ea03c12eb7a8431953fa7 /git-compat-util.h | |
parent | 8db2f665e1b25c2e88ddb00b402a4aa3b73a4cf4 (diff) | |
parent | 47efda967cfd4ef9d39de149e1e3654b051e5d19 (diff) | |
download | git-d073bdc6a06f26b81457abed653c8fb9cee4ba0c.tar.gz |
Merge branch 'bc/csprng-mktemps'
Pick a better random number generator and use it when we prepare
temporary filenames.
* bc/csprng-mktemps:
wrapper: use a CSPRNG to generate random file names
wrapper: add a helper to generate numbers from a CSPRNG
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 1229c8296b..350b122221 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -197,6 +197,12 @@ #endif #include <windows.h> #define GIT_WINDOWS_NATIVE +#ifdef HAVE_RTLGENRANDOM +/* This is required to get access to RtlGenRandom. */ +#define SystemFunction036 NTAPI SystemFunction036 +#include <NTSecAPI.h> +#undef SystemFunction036 +#endif #endif #include <unistd.h> @@ -267,6 +273,12 @@ #else #include <stdint.h> #endif +#ifdef HAVE_ARC4RANDOM_LIBBSD +#include <bsd/stdlib.h> +#endif +#ifdef HAVE_GETRANDOM +#include <sys/random.h> +#endif #ifdef NO_INTPTR_T /* * On I16LP32, ILP32 and LP64 "long" is the safe bet, however @@ -1432,4 +1444,11 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) void sleep_millisec(int millisec); +/* + * Generate len bytes from the system cryptographically secure PRNG. + * Returns 0 on success and -1 on error, setting errno. The inability to + * satisfy the full request is an error. + */ +int csprng_bytes(void *buf, size_t len); + #endif |