Longfellow ZK
0290cb32
Loading...
Searching...
No Matches
lib
algebra
bogorng.h
1
// Copyright 2025 Google LLC.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_
16
#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_
17
18
namespace
proofs {
19
// Totally bogus "random" number generator, used only for testing.
20
// There is no guarantee that it will cycle over all elements in the
21
// field, but this keeps dependencies internal to this directory.
22
// The public and internal functions of this class all take a const Field&
23
// parameter to produce random elements in the Field. It is the caller's
24
// responsibility to ensure the object remains valid during execution.
25
template
<
class
Field>
26
class
Bogorng {
27
using
Elt =
typename
Field::Elt
;
28
29
public
:
30
explicit
Bogorng(
const
Field* F)
31
: f_(F), next_(F->of_scalar_field(123456789u)) {}
32
33
Elt next() {
34
// really old-school
35
f_->mul(next_, f_->of_scalar_field(1103515245u));
36
f_->add(next_, f_->of_scalar_field(12345u));
37
return
next_;
38
}
39
40
Elt nonzero() {
41
Elt x;
42
do
{
43
x = next();
44
}
while
(x == f_->zero());
45
return
x;
46
}
47
48
private
:
49
const
Field* f_;
50
Elt next_;
51
};
52
}
// namespace proofs
53
54
#endif
// PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_
proofs::GF2_128::Elt
Definition
gf2_128.h:63
Generated by
1.15.0