MOTION  0.01
Framework for mixed-protocol multi-party computation
rng.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Lennart Braun
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <cstddef>
26 
27 namespace encrypto::motion {
28 
29 // abstract base class for a random number generator
30 class Rng {
31  public:
32  Rng() = default;
33  virtual ~Rng() = default;
34 
35  // (re)initialize the PRG with a randomly chosen key
36  virtual void SampleKey() = 0;
37 
38  // fill the output buffer with number_of_bytes random bytes
39  virtual void RandomBytes(std::byte* output, std::size_t number_of_bytes) = 0;
40 
41  // fill the output buffer with number_of_blocks random blocks of size kBlockSize
42  virtual void RandomBlocks(std::byte* output, std::size_t number_of_blocks) = 0;
43 
44  // fill the output buffer with number_of_blocks random blocks of size kBlockSize
45  // where the buffer needs to be aligned at a multiple of kBlockSize
46  virtual void RandomBlocksAligned(std::byte* output, std::size_t number_of_blocks) = 0;
47  static constexpr std::size_t kBlockSize = 16;
48 };
49 
50 } // namespace encrypto::motion
encrypto::motion::Rng::RandomBlocks
virtual void RandomBlocks(std::byte *output, std::size_t number_of_blocks)=0
encrypto::motion::Rng::Rng
Rng()=default
encrypto::motion::Rng::SampleKey
virtual void SampleKey()=0
encrypto::motion::Rng::~Rng
virtual ~Rng()=default
encrypto::motion
Definition: algorithm_description.cpp:35
encrypto::motion::Rng::RandomBytes
virtual void RandomBytes(std::byte *output, std::size_t number_of_bytes)=0
encrypto::motion::Rng
Definition: rng.h:30
encrypto::motion::Rng::kBlockSize
static constexpr std::size_t kBlockSize
Definition: rng.h:47
encrypto::motion::Rng::RandomBlocksAligned
virtual void RandomBlocksAligned(std::byte *output, std::size_t number_of_blocks)=0