ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
BPhys
BPhysTools
util
createBlindingKeys.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
13
14
// system includes:
15
#include <iostream>
16
#include <iomanip>
17
#include <set>
18
#include <string>
19
#include <cstdlib>
20
#include <ctime>
21
22
// Local include(s):
23
#include "
BPhysTools/SimpleEncrypter.h
"
24
25
int
main
(
int
argc,
char
* argv[]) {
26
27
// Enable check (-c flag)
28
bool
doCheck(
false
);
29
int
nChecks(1);
30
if
( argc > 1 ) {
31
std::string arg(argv[1]);
32
if
( arg ==
"-c"
) doCheck =
true
;
33
}
34
if
( argc > 2 ) {
35
nChecks = atoi(argv[2]);
36
}
37
38
// Helper object
39
xAOD::SimpleEncrypter
senc;
40
41
// Create key pair
42
std::pair<std::string, std::string> keys = senc.
genKeyPair
();
43
44
std::cout <<
"\nBlinding keys generated:\n"
;
45
std::cout <<
" Private key: "
<< keys.first <<
"\n"
;
46
std::cout <<
" Public key: "
<< keys.second <<
"\n"
;
47
std::cout << std::endl;
48
49
// check that encryption works
50
if
( doCheck ) {
51
srand(
static_cast<
unsigned
>
(time(0)));
52
53
std::cout <<
"Encryption test:\n"
;
54
int
nOK(0);
55
//going to assume that no pathological values were used.
56
//coverity[TAINTED_SCALAR]
57
for
(
int
i=0; i<nChecks; ++i) {
58
//assuming that weak crypto is ok
59
//coverity[dont_call]
60
float
val = 10000.*
static_cast <
float
>
(rand())/(
static_cast <
float
>
(RAND_MAX));
61
// float val = 5267.23;
62
float
enc = senc.
encrypt
(val);
63
float
dec = senc.
decrypt
(enc);
64
if
( dec == val ) ++nOK;
65
if
( i == 0 || dec != val ) {
66
std::cout <<
" Test # "
<< i <<
"\n"
;
67
std::cout <<
" val = "
<< val <<
"\n"
;
68
std::cout <<
" enc = "
<< enc <<
"\n"
;
69
std::cout <<
" dec = "
<< dec <<
"\n"
;
70
if
( dec == val ) {
71
std::cout <<
" => worked!\n"
;
72
}
else
{
73
std::cout <<
" => FAILED!\n"
;
74
}
75
}
// if
76
}
// for
77
std::cout << std::endl;
78
std::cout <<
"Summary:\n"
;
79
std::cout <<
" nChecks: "
<< std::setw(12) << nChecks <<
"\n"
;
80
std::cout <<
" nOK : "
<< std::setw(12) << nOK <<
"\n"
;
81
std::cout <<
" nFailed: "
<< std::setw(12) << nChecks - nOK << std::endl;
82
}
// if
83
84
return
0;
85
}
SimpleEncrypter.h
Provide simple asymmetric encryption for blinding of float values.
xAOD::SimpleEncrypter
Provide simple asymmetric encryption for blinding of float values.
Definition
SimpleEncrypter.h:36
xAOD::SimpleEncrypter::encrypt
virtual ULLI_t encrypt(ULLI_t x)
Encrypt a positive integer value.
Definition
SimpleEncrypter.cxx:124
xAOD::SimpleEncrypter::decrypt
virtual ULLI_t decrypt(ULLI_t x)
Decrypt a positive integer value.
Definition
SimpleEncrypter.cxx:136
xAOD::SimpleEncrypter::genKeyPair
virtual std::pair< std::string, std::string > genKeyPair()
Generate private and public keys.
Definition
SimpleEncrypter.cxx:66
main
int main()
Definition
hello.cxx:18
Generated on
for ATLAS Offline Software by
1.17.0