"Fossies" - the Fresh Open Source Software Archive

Member "src/Common/Random.h" (10 Oct 2018, 2948 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Random.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Legal Notice: Some portions of the source code contained in this file were
    3  derived from the source code of TrueCrypt 7.1a, which is
    4  Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
    5  governed by the TrueCrypt License 3.0, also from the source code of
    6  Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
    7  and which is governed by the 'License Agreement for Encryption for the Masses'
    8  Modifications and additions to the original source code (contained in this file)
    9  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
   10  and are governed by the Apache License 2.0 the full text of which is
   11  contained in the file License.txt included in VeraCrypt binary and source
   12  code distribution packages. */
   13 
   14 
   15 #include "Crypto.h"
   16 
   17 #ifdef __cplusplus
   18 extern "C" {
   19 #endif
   20 
   21 /* RNG defines & pool pointers */
   22 #define RNG_POOL_SIZE   320 // Must be divisible by the size of the output of each of the implemented hash functions. (in bytes)
   23 
   24 #if RNG_POOL_SIZE % SHA512_DIGESTSIZE || RNG_POOL_SIZE % WHIRLPOOL_DIGESTSIZE || RNG_POOL_SIZE % RIPEMD160_DIGESTSIZE
   25 #error RNG_POOL_SIZE must be divisible by the size of the output of each of the implemented hash functions.
   26 #endif
   27 
   28 #define RANDOMPOOL_ALLOCSIZE    RNG_POOL_SIZE
   29 
   30 // After every RANDMIX_BYTE_INTERVAL-th byte written to the pool, the pool mixing function is applied to the entire pool
   31 #define RANDMIX_BYTE_INTERVAL   16
   32 
   33 // FastPoll interval (in milliseconds)
   34 #define FASTPOLL_INTERVAL       500
   35 
   36 void RandAddInt ( unsigned __int32 x );
   37 int Randinit ( void );
   38 void RandStop (BOOL freePool);
   39 BOOL IsRandomNumberGeneratorStarted ();
   40 void RandSetHashFunction ( int hash_algo_id );
   41 int RandGetHashFunction (void);
   42 void SetRandomPoolEnrichedByUserStatus (BOOL enriched);
   43 BOOL IsRandomPoolEnrichedByUser ();
   44 BOOL Randmix ( void );
   45 void RandaddBuf ( void *buf , int len );
   46 BOOL FastPoll ( void );
   47 BOOL SlowPoll ( void );
   48 
   49 /* Get len random bytes from the pool (max. RNG_POOL_SIZE bytes per a single call) */
   50 BOOL RandgetBytes ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll );
   51 
   52 /* Get len random bytes from the pool.
   53  *  If allowAnyLength is FALSE, then len must be less or equal to RNG_POOL_SIZE
   54  *  If allowAnyLength is TRUE, then len can have any positive value
   55  */
   56 BOOL RandgetBytesFull ( void* hwndDlg, unsigned char *buf , int len, BOOL forceSlowPoll , BOOL allowAnyLength);
   57 
   58 #ifdef _WIN32
   59 
   60 extern BOOL volatile bFastPollEnabled;
   61 extern BOOL volatile bRandmixEnabled;
   62 extern DWORD CryptoAPILastError;
   63 extern DWORD ProcessedMouseEventsCounter;
   64 
   65 BOOL RandpeekBytes ( void* hwndDlg, unsigned char *buf , int len, DWORD* mouseCounter );
   66 void RandAddInt64 ( unsigned __int64 x );
   67 
   68 LRESULT CALLBACK MouseProc ( int nCode , WPARAM wParam , LPARAM lParam );
   69 LRESULT CALLBACK KeyboardProc ( int nCode , WPARAM wParam , LPARAM lParam );
   70 static unsigned __stdcall PeriodicFastPollThreadProc (void *dummy);
   71 
   72 #endif
   73 
   74 #ifdef __cplusplus
   75 }
   76 #endif