]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - tools/elftosb/common/Random.h
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / tools / elftosb / common / Random.h
1 /*
2  * File:        Random.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_Random_h_)
8 #define _Random_h_
9
10 #include "stdafx.h"
11
12 #ifdef WIN32
13 /*!
14  * This class is from the crypto++ library.
15  */
16 class MicrosoftCryptoProvider
17 {
18 public:
19         MicrosoftCryptoProvider();
20         ~MicrosoftCryptoProvider();
21 #if defined(_WIN64)
22         typedef unsigned __int64 ProviderHandle;        // type HCRYPTPROV, avoid #include <windows.h>
23 #else
24         typedef unsigned long ProviderHandle;
25 #endif
26         ProviderHandle GetProviderHandle() const {return m_hProvider;}
27 private:
28         ProviderHandle m_hProvider;
29 };
30
31 #pragma comment(lib, "advapi32.lib")
32 #endif  // WIN32
33
34 /*!
35  * Encapsulates the Windows CryptoAPI's CryptGenRandom or /dev/urandom on Unix systems.
36  */
37 class RandomNumberGenerator
38 {
39 public:
40         RandomNumberGenerator();
41         ~RandomNumberGenerator();
42         
43         uint8_t generateByte();
44         void generateBlock(uint8_t * output, unsigned count);
45
46 protected:
47 #ifdef WIN32
48 #       ifndef WORKAROUND_MS_BUG_Q258000
49                 MicrosoftCryptoProvider m_provider;
50 #       endif
51 #else   // WIN32
52         int m_fd;
53 #endif  // WIN32
54 };
55
56
57 #endif // _Random_h_