SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
random_provider_base.hpp
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
30 #ifndef RANDOM_PROVIDER_BASE_IMPLEMENTATION_GUARD
31 #define RANDOM_PROVIDER_BASE_IMPLEMENTATION_GUARD
32 
33 namespace SeComLib {
34 namespace Core {
41  template <typename T_Impl>
43  static RandomProviderBase<T_Impl> instance;
44  return instance;
45  }
46 
52  template <typename T_Impl>
53  inline BigInteger RandomProviderBase<T_Impl>::GetRandomInteger (const size_t numberOfBits) {
54  BigInteger output;
55 
56  T_Impl::GetRandomInteger(output, *this, numberOfBits);
57 
58  return output;
59  }
60 
66  template <typename T_Impl>
67  inline BigInteger RandomProviderBase<T_Impl>::GetRandomInteger (const BigInteger &maximumValue) {
68  BigInteger output;
69 
70  T_Impl::GetRandomInteger(output, *this, maximumValue);
71 
72  return output;
73  }
74 
80  template <typename T_Impl>
81  inline BigInteger RandomProviderBase<T_Impl>::GetMaxLengthRandomPrime (const size_t &numberOfBits) {
82  BigInteger output;
83 
84  T_Impl::GetMaxLengthRandomPrime(output, *this, numberOfBits);
85 
86  return output;
87  }
88 
92  template <typename T_Impl>
94  T_Impl::Initialize(*this);
95  }
96 
100  template <typename T_Impl>
102  T_Impl::Destroy(*this);
103  }
104 
105 }//namespace Core
106 }//namespace SeComLib
107 
108 #endif//RANDOM_PROVIDER_BASE_IMPLEMENTATION_GUARD
BigInteger GetMaxLengthRandomPrime(const size_t &numberOfBits)
Generates a random prime, guaranteed to have numberOfBits length.
BigInteger GetRandomInteger(const size_t numberOfBits)
Generates a random integer having at most numberOfBits bits.
Template class which masks various RandomProvider implementations and provides a common interface tha...
~RandomProviderBase()
Destructor (private, Singleton Pattern)
static RandomProviderBase< T_Impl > & GetInstance()
Returns a reference to the singleton.