The MinGW.org Windows System Libraries
Revision | 34964df1b77f7291f3024c40829d75f0925c724e (tree) |
---|---|
Time | 2020-07-21 04:17:27 |
Author | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
Add support for emulation of Microsoft's rand_s() function.
@@ -1,6 +1,6 @@ | ||
1 | 1 | # VERSION.m4 -- vim: filetype=config |
2 | 2 | # |
3 | -# $Id: VERSION.m4,v bc6380b6bc4b 2020/07/18 21:59:28 keith $ | |
3 | +# $Id: VERSION.m4,v 5f021e118870 2020/07/20 19:17:27 keith $ | |
4 | 4 | # |
5 | 5 | # Non-copyrightable material; adjust the following definition, to |
6 | 6 | # assign a common version number to each of the mingwrt and w32api |
@@ -23,7 +23,7 @@ m4_define([__VERSION__],[5.4.1]) | ||
23 | 23 | # as required, in accordance with libtool conventions. |
24 | 24 | # |
25 | 25 | m4_define([MINGW_AC_ENUMERATE_DLLVERSION_SPECS],dnl |
26 | -[MINGW_AC_SET_DLLVERSION([LIBMINGWEX], [libmingwex.dll.a], [4:0:0])dnl | |
26 | +[MINGW_AC_SET_DLLVERSION([LIBMINGWEX], [libmingwex.dll.a], [5:0:1])dnl | |
27 | 27 | ]) |
28 | 28 | |
29 | 29 | # $RCSfile: VERSION.m4,v $: end of file |
@@ -1,3 +1,22 @@ | ||
1 | +2020-07-20 Keith Marshall <keith@users.osdn.me> | |
2 | + | |
3 | + Add support for emulation of Microsoft's rand_s() function. | |
4 | + | |
5 | + * mingwex/cryptnam.c (crypto_provider, crypto_randomize): Factor out | |
6 | + this pair of static inline functions; relocate them to... | |
7 | + * mingwex/memcrypt.c: ...this new file. | |
8 | + (crypto_randomize): Change linkage to extern; rename it as... | |
9 | + (__mingw_crypto_randomize): ...this; use it... | |
10 | + * mingwex/cryptnam.c (crypto_random_filename_char): ...here, via... | |
11 | + (crypto_randomize): ...this static inline reimplementation. | |
12 | + | |
13 | + * Makefile.in (libmingwex.a): Add dependency reference for... | |
14 | + (memcrypt.$OBJEXT): ...this new object file. | |
15 | + | |
16 | + * VERSION.m4 (MINGW_AC_SET_DLLVERSION) [LIBMINGWEX]: Increment it | |
17 | + to 5:0:1; __mingw_crypto_randomize adds a new interface, but it does | |
18 | + not break ABI backward compatibility. | |
19 | + | |
1 | 20 | 2020-07-08 Keith Marshall <keith@users.osdn.me> |
2 | 21 | |
3 | 22 | Prepare and publish MinGW.org WSL-5.4 release. |
@@ -1,5 +1,5 @@ | ||
1 | 1 | # @configure_input@ |
2 | -# $Id$ | |
2 | +# $Id: Makefile.in,v 5f021e118870 2020/07/20 19:17:27 keith $ | |
3 | 3 | # |
4 | 4 | # Makefile template for MinGW.org Runtime Library Package |
5 | 5 |
@@ -464,7 +464,7 @@ libmingwex.a: $(addsuffix .$(OBJEXT), glob getopt basename dirname nsleep) | ||
464 | 464 | libmingwex.a: $(addsuffix .$(OBJEXT), clockapi clockres clockset clocktime) |
465 | 465 | libmingwex.a: $(addsuffix .$(OBJEXT), insque remque tdelete tfind tsearch twalk) |
466 | 466 | libmingwex.a: $(addsuffix .$(OBJEXT), dirent wdirent dlfcn strerror_r strtok_r) |
467 | -libmingwex.a: $(addsuffix .$(OBJEXT), mkstemp mkdtemp cryptnam setenv) | |
467 | +libmingwex.a: $(addsuffix .$(OBJEXT), mkstemp mkdtemp memcrypt cryptnam setenv) | |
468 | 468 | |
469 | 469 | vpath %.s ${mingwrt_srcdir}/mingwex |
470 | 470 | vpath %.sx ${mingwrt_srcdir}/mingwex |
@@ -1028,4 +1028,4 @@ maintainer-clean-local: maintainer-clean-warning distclean-local | ||
1028 | 1028 | |
1029 | 1029 | clean mostlyclean distclean maintainer-clean: %clean: %clean-local |
1030 | 1030 | |
1031 | -# $RCSfile$: end of file | |
1031 | +# $RCSfile: Makefile.in,v $: end of file |
@@ -7,10 +7,10 @@ | ||
7 | 7 | * the file name, or the directory name, in MinGW.org implementations of |
8 | 8 | * the mkstemp(3) and mkdtemp(3) functions, respectively. |
9 | 9 | * |
10 | - * $Id$ | |
10 | + * $Id: cryptnam.c,v 5f021e118870 2020/07/20 19:17:27 keith $ | |
11 | 11 | * |
12 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
13 | - * Copyright (C) 2013, 2014, 2018, 2019, MinGW.org Project. | |
12 | + * Written by Keith Marshall <keith@users.osdn.me> | |
13 | + * Copyright (C) 2013, 2014, 2018-2020, MinGW.org Project. | |
14 | 14 | * |
15 | 15 | * |
16 | 16 | * Permission is hereby granted, free of charge, to any person obtaining a |
@@ -33,66 +33,14 @@ | ||
33 | 33 | * DEALINGS IN THE SOFTWARE. |
34 | 34 | * |
35 | 35 | */ |
36 | -#define WIN32_LEAN_AND_MEAN | |
37 | - | |
38 | 36 | #include <limits.h> |
39 | -#include <windows.h> | |
40 | -#include <wincrypt.h> | |
41 | 37 | #include <string.h> |
42 | 38 | |
43 | 39 | #define CRYPTO_INLINE static __inline__ __attribute__((__always_inline__)) |
44 | 40 | |
45 | -CRYPTO_INLINE HCRYPTPROV crypto_provider( void ) | |
46 | -#define RSA_MODE( OPT, FLAG ) PROV_RSA_##OPT, CRYPT_##FLAG | |
47 | -{ | |
48 | - /* Helper to establish a cryptographic provider context for the | |
49 | - * cryptographically secure random number generator. | |
50 | - * | |
51 | - * At the outset, this provider requires initialization. | |
52 | - */ | |
53 | - static HCRYPTPROV id = (HCRYPTPROV)(0); | |
54 | - | |
55 | - /* On second, and subsequent calls, it should already have been | |
56 | - * initialized... | |
57 | - */ | |
58 | - if( id != (HCRYPTPROV)(0) ) | |
59 | - /* | |
60 | - * ...so, simply return the saved context handle... | |
61 | - */ | |
62 | - return id; | |
63 | - | |
64 | - /* If we're still here, this must be the first call, (or any | |
65 | - * preceding call failed to initialize the context); initialize | |
66 | - * it now, and if successful... | |
67 | - */ | |
68 | - if( CryptAcquireContext( &id, NULL, NULL, RSA_MODE( FULL, VERIFYCONTEXT ) ) ) | |
69 | - /* | |
70 | - * ...return the now-initialized context handle. | |
71 | - */ | |
72 | - return id; | |
73 | - | |
74 | - /* And finally, if we ever get to here, the context remains | |
75 | - * uninitialized; ensure that it remains marked as such, and | |
76 | - * return the uninitialized context handle. | |
77 | - */ | |
78 | - return id = (HCRYPTPROV)(0); | |
79 | -} | |
80 | - | |
41 | +void *__mingw_crypto_randomize( void *, size_t ); | |
81 | 42 | CRYPTO_INLINE void *crypto_randomize( void *buf, size_t buflen ) |
82 | -{ | |
83 | - /* Helper to fill a specified buffer, of specified length, | |
84 | - * with cryptographically secure random bytes... | |
85 | - */ | |
86 | - if( CryptGenRandom( crypto_provider(), buflen, buf ) ) | |
87 | - /* | |
88 | - * ...returning a pointer to the buffer, when successful... | |
89 | - */ | |
90 | - return buf; | |
91 | - | |
92 | - /* ...or nothing, otherwise. | |
93 | - */ | |
94 | - return NULL; | |
95 | -} | |
43 | +{ return __mingw_crypto_randomize( buf, buflen ); } | |
96 | 44 | |
97 | 45 | CRYPTO_INLINE |
98 | 46 | unsigned char *crypto_random_filename_char( unsigned char *caret ) |
@@ -186,4 +134,4 @@ char *__mingw_crypto_tmpname( char *template ) | ||
186 | 134 | return template; |
187 | 135 | } |
188 | 136 | |
189 | -/* $RCSfile$: end of file */ | |
137 | +/* $RCSfile: cryptnam.c,v $: end of file */ |
@@ -0,0 +1,92 @@ | ||
1 | +/* | |
2 | + * memcrypt.c | |
3 | + * | |
4 | + * Implementation of a cryptographically secure random data generator. | |
5 | + * This provides a mechanism for filling a memory buffer, of specified | |
6 | + * length, with cryptographically secure randomly generated bytes. | |
7 | + * | |
8 | + * $Id: memcrypt.c,v 5f021e118870 2020/07/20 19:17:27 keith $ | |
9 | + * | |
10 | + * Written by Keith Marshall <keith@users.osdn.me> | |
11 | + * Copyright (C) 2013, 2014, 2018-2020, MinGW.org Project. | |
12 | + * | |
13 | + * | |
14 | + * Permission is hereby granted, free of charge, to any person obtaining a | |
15 | + * copy of this software and associated documentation files (the "Software"), | |
16 | + * to deal in the Software without restriction, including without limitation | |
17 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
18 | + * and/or sell copies of the Software, and to permit persons to whom the | |
19 | + * Software is furnished to do so, subject to the following conditions: | |
20 | + * | |
21 | + * The above copyright notice, this permission notice, and the following | |
22 | + * disclaimer shall be included in all copies or substantial portions of | |
23 | + * the Software. | |
24 | + * | |
25 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
26 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
27 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
28 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
29 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
30 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER | |
31 | + * DEALINGS IN THE SOFTWARE. | |
32 | + * | |
33 | + */ | |
34 | +#define WIN32_LEAN_AND_MEAN | |
35 | + | |
36 | +#include <wincrypt.h> | |
37 | + | |
38 | +#define CRYPTO_INLINE static __inline__ __attribute__((__always_inline__)) | |
39 | + | |
40 | +CRYPTO_INLINE HCRYPTPROV crypto_provider( void ) | |
41 | +#define RSA_MODE( OPT, FLAG ) PROV_RSA_##OPT, CRYPT_##FLAG | |
42 | +{ | |
43 | + /* Helper to establish a cryptographic provider context for the | |
44 | + * cryptographically secure random number generator. | |
45 | + * | |
46 | + * At the outset, this provider requires initialization. | |
47 | + */ | |
48 | + static HCRYPTPROV id = (HCRYPTPROV)(0); | |
49 | + | |
50 | + /* On second, and subsequent calls, it should already have been | |
51 | + * initialized... | |
52 | + */ | |
53 | + if( id != (HCRYPTPROV)(0) ) | |
54 | + /* | |
55 | + * ...so, simply return the saved context handle... | |
56 | + */ | |
57 | + return id; | |
58 | + | |
59 | + /* If we're still here, this must be the first call, (or any | |
60 | + * preceding call failed to initialize the context); initialize | |
61 | + * it now, and if successful... | |
62 | + */ | |
63 | + if( CryptAcquireContext( &id, NULL, NULL, RSA_MODE( FULL, VERIFYCONTEXT ) ) ) | |
64 | + /* | |
65 | + * ...return the now-initialized context handle. | |
66 | + */ | |
67 | + return id; | |
68 | + | |
69 | + /* And finally, if we ever get to here, the context remains | |
70 | + * uninitialized; ensure that it remains marked as such, and | |
71 | + * return the uninitialized context handle. | |
72 | + */ | |
73 | + return id = (HCRYPTPROV)(0); | |
74 | +} | |
75 | + | |
76 | +void *__mingw_crypto_randomize( void *buf, size_t buflen ) | |
77 | +{ | |
78 | + /* Helper to fill a specified buffer, of specified length, | |
79 | + * with cryptographically secure random bytes... | |
80 | + */ | |
81 | + if( CryptGenRandom( crypto_provider(), buflen, buf ) ) | |
82 | + /* | |
83 | + * ...returning a pointer to the buffer, when successful... | |
84 | + */ | |
85 | + return buf; | |
86 | + | |
87 | + /* ...or nothing, otherwise. | |
88 | + */ | |
89 | + return NULL; | |
90 | +} | |
91 | + | |
92 | +/* $RCSfile: memcrypt.c,v $: end of file */ |