| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/include/fxcrt/fx_basic.h" | 7 #include "core/include/fxcrt/fx_basic.h" |
| 8 #include "core/include/fxcrt/fx_ext.h" | 8 #include "core/include/fxcrt/fx_ext.h" |
| 9 #include "extension.h" | 9 #include "extension.h" |
| 10 | 10 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 ; | 268 ; |
| 269 ::srand((tmCur << 16) | (tmLast & 0xFFFF)); | 269 ::srand((tmCur << 16) | (tmLast & 0xFFFF)); |
| 270 #endif | 270 #endif |
| 271 while (iCount-- > 0) { | 271 while (iCount-- > 0) { |
| 272 *pBuffer++ = (FX_DWORD)((::rand() << 16) | (::rand() & 0xFFFF)); | 272 *pBuffer++ = (FX_DWORD)((::rand() << 16) | (::rand() & 0xFFFF)); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 275 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 276 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount) { | 276 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount) { |
| 277 HCRYPTPROV hCP = NULL; | 277 HCRYPTPROV hCP = NULL; |
| 278 if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || | 278 if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || !hCP) { |
| 279 hCP == NULL) { | |
| 280 return FALSE; | 279 return FALSE; |
| 281 } | 280 } |
| 282 ::CryptGenRandom(hCP, iCount * sizeof(FX_DWORD), (uint8_t*)pBuffer); | 281 ::CryptGenRandom(hCP, iCount * sizeof(FX_DWORD), (uint8_t*)pBuffer); |
| 283 ::CryptReleaseContext(hCP, 0); | 282 ::CryptReleaseContext(hCP, 0); |
| 284 return TRUE; | 283 return TRUE; |
| 285 } | 284 } |
| 286 #endif | 285 #endif |
| 287 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) { | 286 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) { |
| 288 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 287 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 289 FX_GenerateCryptoRandom(pBuffer, iCount); | 288 FX_GenerateCryptoRandom(pBuffer, iCount); |
| 290 #else | 289 #else |
| 291 FX_Random_GenerateBase(pBuffer, iCount); | 290 FX_Random_GenerateBase(pBuffer, iCount); |
| 292 #endif | 291 #endif |
| 293 } | 292 } |
| OLD | NEW |