@@ -136,7 +136,6 @@ mod imp {
136136 use os;
137137 use rand:: Rng ;
138138 use result:: { Ok , Err } ;
139- use rt:: stack;
140139 use self :: libc:: { DWORD , BYTE , LPCSTR , BOOL } ;
141140 use self :: libc:: types:: os:: arch:: extra:: { LONG_PTR } ;
142141 use slice:: MutableSlice ;
@@ -159,7 +158,6 @@ mod imp {
159158 static PROV_RSA_FULL : DWORD = 1 ;
160159 static CRYPT_SILENT : DWORD = 64 ;
161160 static CRYPT_VERIFYCONTEXT : DWORD = 0xF0000000 ;
162- static NTE_BAD_SIGNATURE : DWORD = 0x80090006 ;
163161
164162 #[ allow( non_snake_case) ]
165163 extern "system" {
@@ -178,48 +176,12 @@ mod imp {
178176 /// Create a new `OsRng`.
179177 pub fn new ( ) -> IoResult < OsRng > {
180178 let mut hcp = 0 ;
181- let mut ret = unsafe {
179+ let ret = unsafe {
182180 CryptAcquireContextA ( & mut hcp, 0 as LPCSTR , 0 as LPCSTR ,
183181 PROV_RSA_FULL ,
184182 CRYPT_VERIFYCONTEXT | CRYPT_SILENT )
185183 } ;
186184
187- // FIXME #13259:
188- // It turns out that if we can't acquire a context with the
189- // NTE_BAD_SIGNATURE error code, the documentation states:
190- //
191- // The provider DLL signature could not be verified. Either the
192- // DLL or the digital signature has been tampered with.
193- //
194- // Sounds fishy, no? As it turns out, our signature can be bad
195- // because our Thread Information Block (TIB) isn't exactly what it
196- // expects. As to why, I have no idea. The only data we store in the
197- // TIB is the stack limit for each thread, but apparently that's
198- // enough to make the signature valid.
199- //
200- // Furthermore, this error only happens the *first* time we call
201- // CryptAcquireContext, so we don't have to worry about future
202- // calls.
203- //
204- // Anyway, the fix employed here is that if we see this error, we
205- // pray that we're not close to the end of the stack, temporarily
206- // set the stack limit to 0 (what the TIB originally was), acquire a
207- // context, and then reset the stack limit.
208- //
209- // Again, I'm not sure why this is the fix, nor why we're getting
210- // this error. All I can say is that this seems to allow libnative
211- // to progress where it otherwise would be hindered. Who knew?
212- if ret == 0 && os:: errno ( ) as DWORD == NTE_BAD_SIGNATURE {
213- unsafe {
214- let limit = stack:: get_sp_limit ( ) ;
215- stack:: record_sp_limit ( 0 ) ;
216- ret = CryptAcquireContextA ( & mut hcp, 0 as LPCSTR , 0 as LPCSTR ,
217- PROV_RSA_FULL ,
218- CRYPT_VERIFYCONTEXT | CRYPT_SILENT ) ;
219- stack:: record_sp_limit ( limit) ;
220- }
221- }
222-
223185 if ret == 0 {
224186 Err ( IoError :: last_error ( ) )
225187 } else {
0 commit comments