fix secure-random-generator for windows
parent
a00e325b96
commit
cee0eb5be3
|
@ -1,31 +1,54 @@
|
||||||
USING: accessors alien.c-types byte-arrays continuations
|
USING: accessors alien.c-types byte-arrays continuations
|
||||||
kernel windows windows.advapi32 init namespaces random ;
|
kernel windows windows.advapi32 init namespaces random
|
||||||
|
destructors locals ;
|
||||||
|
USE: tools.walker
|
||||||
IN: random.windows
|
IN: random.windows
|
||||||
|
|
||||||
TUPLE: windows-crypto-context handle ;
|
TUPLE: windows-rng provider type ;
|
||||||
|
C: <windows-rng> windows-rng
|
||||||
|
|
||||||
|
TUPLE: windows-crypto-context handle ;
|
||||||
C: <windows-crypto-context> windows-crypto-context
|
C: <windows-crypto-context> windows-crypto-context
|
||||||
|
|
||||||
M: windows-crypto-context dispose ( tuple -- )
|
M: windows-crypto-context dispose ( tuple -- )
|
||||||
handle>> 0 CryptReleaseContext win32-error=0/f ;
|
handle>> 0 CryptReleaseContext win32-error=0/f ;
|
||||||
|
|
||||||
TUPLE: windows-cryptographic-rng context ;
|
: factor-crypto-container ( -- string ) "FactorCryptoContainer" ; inline
|
||||||
|
|
||||||
C: <windows-cryptographic-rng> windows-cryptographic-rng
|
:: (acquire-crypto-context) ( provider type flags -- handle )
|
||||||
|
[let | handle [ "HCRYPTPROV" <c-object> ] |
|
||||||
|
handle
|
||||||
|
factor-crypto-container
|
||||||
|
provider
|
||||||
|
type
|
||||||
|
flags
|
||||||
|
CryptAcquireContextW win32-error=0/f
|
||||||
|
handle *void* ] ;
|
||||||
|
|
||||||
M: windows-cryptographic-rng dispose ( tuple -- )
|
: acquire-crypto-context ( provider type -- handle )
|
||||||
context>> dispose ;
|
[ 0 (acquire-crypto-context) ]
|
||||||
|
[ drop CRYPT_NEWKEYSET (acquire-crypto-context) ] recover ;
|
||||||
|
|
||||||
M: windows-cryptographic-rng random-bytes* ( tuple n -- bytes )
|
|
||||||
>r context>> r> dup <byte-array>
|
|
||||||
[ CryptGenRandom win32-error=0/f ] keep ;
|
|
||||||
|
|
||||||
: windows-aes-context ( -- context )
|
: windows-crypto-context ( provider type -- context )
|
||||||
"HCRYPTPROV" <c-object>
|
acquire-crypto-context <windows-crypto-context> ;
|
||||||
dup f f PROV_RSA_AES CRYPT_NEWKEYSET
|
|
||||||
CryptAcquireContextW win32-error=0/f *void*
|
|
||||||
<windows-crypto-context> ;
|
|
||||||
|
|
||||||
! [
|
M: windows-rng random-bytes* ( n tuple -- bytes )
|
||||||
! windows-aes-context secure-random-generator set-global
|
[
|
||||||
! ] "random.windows" add-init-hook
|
[ provider>> ] [ type>> ] bi
|
||||||
|
windows-crypto-context
|
||||||
|
dup add-always-destructor handle>>
|
||||||
|
swap dup <byte-array>
|
||||||
|
[ CryptGenRandom win32-error=0/f ] keep
|
||||||
|
] with-destructors ;
|
||||||
|
|
||||||
|
[
|
||||||
|
MS_DEF_PROV
|
||||||
|
PROV_RSA_FULL <windows-rng> insecure-random-generator set-global
|
||||||
|
|
||||||
|
! MS_STRONG_PROV
|
||||||
|
! PROV_RSA_FULL <windows-rng> secure-random-generator set-global
|
||||||
|
|
||||||
|
MS_ENH_RSA_AES_PROV
|
||||||
|
PROV_RSA_AES <windows-rng> secure-random-generator set-global
|
||||||
|
] "random.windows" add-init-hook
|
||||||
|
|
|
@ -21,6 +21,40 @@ LIBRARY: advapi32
|
||||||
: PROV_REPLACE_OWF 23 ; inline
|
: PROV_REPLACE_OWF 23 ; inline
|
||||||
: PROV_RSA_AES 24 ; inline
|
: PROV_RSA_AES 24 ; inline
|
||||||
|
|
||||||
|
: MS_DEF_DH_SCHANNEL_PROV
|
||||||
|
"Microsoft DH Schannel Cryptographic Provider" ; inline
|
||||||
|
|
||||||
|
: MS_DEF_DSS_DH_PROV
|
||||||
|
"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider" ; inline
|
||||||
|
|
||||||
|
: MS_DEF_DSS_PROV
|
||||||
|
"Microsoft Base DSS Cryptographic Provider" ; inline
|
||||||
|
|
||||||
|
: MS_DEF_PROV
|
||||||
|
"Microsoft Base Cryptographic Provider v1.0" ; inline
|
||||||
|
|
||||||
|
: MS_DEF_RSA_SCHANNEL_PROV
|
||||||
|
"Microsoft RSA Schannel Cryptographic Provider" ; inline
|
||||||
|
|
||||||
|
! Unsupported (!)
|
||||||
|
: MS_DEF_RSA_SIG_PROV
|
||||||
|
"Microsoft RSA Signature Cryptographic Provider" ; inline
|
||||||
|
|
||||||
|
: MS_ENH_DSS_DH_PROV
|
||||||
|
"Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider" ; inline
|
||||||
|
|
||||||
|
: MS_ENH_RSA_AES_PROV
|
||||||
|
"Microsoft Enhanced RSA and AES Cryptographic Provider" ; inline
|
||||||
|
|
||||||
|
: MS_ENHANCED_PROV
|
||||||
|
"Microsoft Enhanced Cryptographic Provider v1.0" ; inline
|
||||||
|
|
||||||
|
: MS_SCARD_PROV
|
||||||
|
"Microsoft Base Smart Card Crypto Provider" ; inline
|
||||||
|
|
||||||
|
: MS_STRONG_PROV
|
||||||
|
"Microsoft Strong Cryptographic Provider" ; inline
|
||||||
|
|
||||||
: CRYPT_VERIFYCONTEXT HEX: F0000000 ; inline
|
: CRYPT_VERIFYCONTEXT HEX: F0000000 ; inline
|
||||||
: CRYPT_NEWKEYSET HEX: 8 ; inline
|
: CRYPT_NEWKEYSET HEX: 8 ; inline
|
||||||
: CRYPT_DELETEKEYSET HEX: 10 ; inline
|
: CRYPT_DELETEKEYSET HEX: 10 ; inline
|
||||||
|
|
Loading…
Reference in New Issue