~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to extra/yassl/taocrypt/include/random.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2000-2007 MySQL AB
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
*/
 
18
 
 
19
/* random.hpp provides a crypto secure Random Number Generator using an OS
 
20
   specific seed
 
21
*/
 
22
 
 
23
 
 
24
#ifndef TAO_CRYPT_RANDOM_HPP
 
25
#define TAO_CRYPT_RANDOM_HPP
 
26
 
 
27
#include "arc4.hpp"
 
28
#include "error.hpp"
 
29
 
 
30
namespace TaoCrypt {
 
31
 
 
32
 
 
33
// OS specific seeder
 
34
class OS_Seed {
 
35
public:
 
36
    OS_Seed();
 
37
    ~OS_Seed();
 
38
 
 
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_;
 
54
 
 
55
    OS_Seed(const OS_Seed&);              // hide copy
 
56
    OS_Seed& operator=(const OS_Seed&);   // hide assign
 
57
};
 
58
 
 
59
 
 
60
// secure Random Nnumber Generator
 
61
class RandomNumberGenerator {
 
62
public:
 
63
    RandomNumberGenerator();
 
64
    ~RandomNumberGenerator() {}
 
65
 
 
66
    void GenerateBlock(byte*, word32 sz);
 
67
    byte GenerateByte();
 
68
 
 
69
    ErrorNumber GetError() const { return seed_.GetError().What(); }
 
70
private:
 
71
    OS_Seed seed_;
 
72
    ARC4    cipher_;
 
73
 
 
74
    RandomNumberGenerator(const RandomNumberGenerator&);           // hide copy
 
75
    RandomNumberGenerator operator=(const RandomNumberGenerator&); // && assign
 
76
};
 
77
 
 
78
 
 
79
 
 
80
 
 
81
}  // namespace
 
82
 
 
83
#endif // TAO_CRYPT_RANDOM_HPP
 
84