mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / extra / yassl / taocrypt / include / random.hpp
blob91058e8c5cf6b7f93dc9040601bf4550f1b7df2e
1 /*
2 Copyright (C) 2000-2007 MySQL AB
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to the
15 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
16 MA 02110-1301 USA.
19 /* random.hpp provides a crypto secure Random Number Generator using an OS
20 specific seed
24 #ifndef TAO_CRYPT_RANDOM_HPP
25 #define TAO_CRYPT_RANDOM_HPP
27 #include "arc4.hpp"
28 #include "error.hpp"
30 namespace TaoCrypt {
33 // OS specific seeder
34 class OS_Seed {
35 public:
36 OS_Seed();
37 ~OS_Seed();
39 void GenerateSeed(byte*, word32 sz);
40 Error GetError() const { return error_; }
41 private:
42 #if defined(_WIN32)
43 #if defined(_WIN64)
44 typedef unsigned __int64 ProviderHandle;
45 // type HCRYPTPROV, avoid #include <windows.h>
46 #else
47 typedef unsigned long ProviderHandle;
48 #endif
49 ProviderHandle handle_;
50 #else
51 int fd_;
52 #endif
53 Error error_;
55 OS_Seed(const OS_Seed&); // hide copy
56 OS_Seed& operator=(const OS_Seed&); // hide assign
60 // secure Random Nnumber Generator
61 class RandomNumberGenerator {
62 public:
63 RandomNumberGenerator();
64 ~RandomNumberGenerator() {}
66 void GenerateBlock(byte*, word32 sz);
67 byte GenerateByte();
69 ErrorNumber GetError() const { return seed_.GetError().What(); }
70 private:
71 OS_Seed seed_;
72 ARC4 cipher_;
74 RandomNumberGenerator(const RandomNumberGenerator&); // hide copy
75 RandomNumberGenerator operator=(const RandomNumberGenerator&); // && assign
81 } // namespace
83 #endif // TAO_CRYPT_RANDOM_HPP