1 USING: accessors alien.c-types byte-arrays continuations
2 kernel windows.advapi32 init namespaces random destructors
3 locals windows.errors ;
6 TUPLE: windows-rng provider type ;
7 C: <windows-rng> windows-rng
9 TUPLE: windows-crypto-context handle ;
10 C: <windows-crypto-context> windows-crypto-context
12 M: windows-crypto-context dispose ( tuple -- )
13 handle>> 0 CryptReleaseContext win32-error=0/f ;
15 : factor-crypto-container ( -- string ) "FactorCryptoContainer" ; inline
17 :: (acquire-crypto-context) ( provider type flags -- handle )
18 [let | handle [ "HCRYPTPROV" <c-object> ] |
20 factor-crypto-container
24 CryptAcquireContextW win32-error=0/f
27 : acquire-crypto-context ( provider type -- handle )
28 [ 0 (acquire-crypto-context) ]
29 [ drop CRYPT_NEWKEYSET (acquire-crypto-context) ] recover ;
32 : windows-crypto-context ( provider type -- context )
33 acquire-crypto-context <windows-crypto-context> ;
35 M: windows-rng random-bytes* ( n tuple -- bytes )
37 [ provider>> ] [ type>> ] bi
38 windows-crypto-context &dispose
39 handle>> swap dup <byte-array>
40 [ CryptGenRandom win32-error=0/f ] keep
45 PROV_RSA_FULL <windows-rng> system-random-generator set-global
48 PROV_RSA_FULL <windows-rng> secure-random-generator set-global
51 ! PROV_RSA_AES <windows-rng> secure-random-generator set-global
52 ] "random.windows" add-init-hook