wxMaxima
Loading...
Searching...
No Matches
random.h
1/*
2** Name: random.h
3** Purpose: Random bytes generator based on ChaCha20 cipher stream
4** Copyright: (c) 2024-2024 Ulrich Telle
5** SPDX-License-Identifier: MIT
6**
7** The code was taken from the public domain implementation
8** of the sqleet project (https://github.com/resilar/sqleet)
9*/
10
11#pragma once
12#ifndef WXPDFDOC_CRYPTO_RANDOM_H_
13#define WXPDFDOC_CRYPTO_RANDOM_H_
14
15#include <cstddef>
16#include <cstdint>
17
18namespace wxpdfdoc {
19namespace crypto {
20
23{
24public:
27
30 RandomBytesGenerator& operator=(const RandomBytesGenerator&) = delete;
31
34 RandomBytesGenerator& operator=(RandomBytesGenerator&&) = delete;
35
37 virtual ~RandomBytesGenerator() = default;
38
40 void GetRandomBytes(uint8_t* out, size_t n);
41
42private:
43 uint8_t key[32] = { 0 };
44 uint8_t nonce[12] = { 0 };
45 uint8_t buffer[64] = { 0 };
46 uint32_t counter = 0;
47 size_t available = 0;
48};
49
50
51} // namespace crypto
52} // namespace wxpdfdoc
53
54#endif // WXPDFDOC_CRYPTO_RANDOM_H_
Class representing a cryptographically secure random number generator.
Definition: random.h:23
RandomBytesGenerator(const RandomBytesGenerator &)=delete
Copy constructor.
RandomBytesGenerator(RandomBytesGenerator &&)=delete
Move constructors.
virtual ~RandomBytesGenerator()=default
Destructor.
void GetRandomBytes(uint8_t *out, size_t n)
Get the X offset of the annotation.
Definition: random.cpp:310
RandomBytesGenerator()=default
Constructor for text annotation.