|
ATLAS Offline Software
|
Provide simple asymmetric encryption for blinding of float values.
More...
#include <SimpleEncrypter.h>
Provide simple asymmetric encryption for blinding of float values.
- Author
- Wolfgang Walkowiak <Wolfg.nosp@m.ang..nosp@m.Walko.nosp@m.wiak.nosp@m.@cern.nosp@m..ch.>
Provides asymmetric key encryption for blinding of positive float values. Internally it uses a simple RSA encryption of bits in the floating point numbers. This class is used by the BPhysBlindingTool.
Definition at line 36 of file SimpleEncrypter.h.
◆ LLI_t
◆ ULLI_t
◆ SimpleEncrypter()
xAOD::SimpleEncrypter::SimpleEncrypter |
( |
const std::string & |
name = "SimpleEncrypter" | ) |
|
◆ ~SimpleEncrypter()
xAOD::SimpleEncrypter::~SimpleEncrypter |
( |
| ) |
|
|
virtual |
◆ decodeKeyString()
Decode hex string to two integers.
Definition at line 309 of file SimpleEncrypter.cxx.
311 std::pair<ULLI_t, ULLI_t>
keys(0,0);
314 if (
str.IsHex() &&
str.Length() > 3) {
316 unsigned int ndigits = strtoul(TString(
str(0,2)).
Data(),
nullptr, 16);
317 unsigned int ra = strtoul(TString(
str(2,2)).
Data(),
nullptr, 16);
318 unsigned int rb = strtoul(TString(
str(4,2)).
Data(),
nullptr, 16);
319 if (
str.Length() == (
int)(2*ndigits + 6) ) {
320 keys.first = strtoll(TString(
str(ndigits+6-ra, ra)).
Data(),
325 ATH_MSG_ERROR(
"Private/public key must be a hex string of " <<
329 ATH_MSG_ERROR(
"Private/public key must be a hex string of " <<
◆ decrypt() [1/2]
Decrypt a positive float value.
- Parameters
-
[in] | positive | float value to be decrypted |
- Returns
- encrypted float value
Definition at line 164 of file SimpleEncrypter.cxx.
169 if (
a > 0. || std::isnan(
a) ) {
177 <<
a << Form(
" (%a) !",
a));
◆ decrypt() [2/2]
Decrypt a positive integer value.
- Parameters
-
[in] | unsigned | integer value to be decrypted |
- Returns
- encrypted unsigned integer value
Definition at line 132 of file SimpleEncrypter.cxx.
◆ decryptFPECycle()
Decrypt using format preserving encryption w.r.t.
RSA modulus
Definition at line 439 of file SimpleEncrypter.cxx.
449 }
while (
d > rmask );
◆ decryptInternal()
◆ encrypt() [1/2]
Encrypt a positive float value.
- Parameters
-
[in] | positive | float value to be encrypted |
- Returns
- encrypted float value
Definition at line 144 of file SimpleEncrypter.cxx.
156 <<
a << Form(
" (%a) !",
a));
◆ encrypt() [2/2]
Encrypt a positive integer value.
- Parameters
-
[in] | unsigned | integer value to be encrypted |
- Returns
- encrypted unsigned integer value
Definition at line 120 of file SimpleEncrypter.cxx.
◆ encryptFPECycle()
◆ encryptInternal()
◆ floatBitsToInt()
Definition at line 338 of file SimpleEncrypter.cxx.
346 if (
sizeof(
float) <=
sizeof(
ULLI_t) ) {
348 if (
sizeof(
float) ==
sizeof(
int) ) {
357 char* pval =
reinterpret_cast<char*
>(&
val);
359 for (
unsigned int i=0;
i<
sizeof(
float); ++
i) {
361 for (
unsigned int j=0; j<CHAR_BIT; ++j) {
362 unsigned int n =
i*CHAR_BIT + j;
363 unsigned int bit = (*(pval+
i) >> j) & 1;
364 if ( bit > 0 )
res |= 1 <<
n;
370 <<
sizeof(
float) <<
" > " <<
sizeof(
LLI_t));
◆ genCoprime()
◆ genDecryptionExponent()
◆ genKeyPair()
std::pair< std::string, std::string > xAOD::SimpleEncrypter::genKeyPair |
( |
| ) |
|
|
virtual |
Generate private and public keys.
- Returns
- key pair as string: [private key, public key]
Definition at line 60 of file SimpleEncrypter.cxx.
63 std::pair<std::string, std::string>
keys =
64 std::make_pair(
"__NO_PRIV_KEY__",
"__NO_PUB_KEY__");
◆ genKeyPairInternal()
void xAOD::SimpleEncrypter::genKeyPairInternal |
( |
| ) |
|
|
privatevirtual |
Definition at line 189 of file SimpleEncrypter.cxx.
200 while (
p ==
q || m_e < 2 || m_e >=
phi ||
m_d < 2
203 while (
p ==
q || dlog2 < 0.1 || dlog2 > 30. ) {
206 dlog2 = fabs(log2(
p)-log2(
q));
◆ genPrime()
◆ getPrivKey()
std::string xAOD::SimpleEncrypter::getPrivKey |
( |
| ) |
const |
|
virtual |
◆ getPubKey()
std::string xAOD::SimpleEncrypter::getPubKey |
( |
| ) |
const |
|
virtual |
◆ greatestCommonDenominator()
Find greatest common denominator.
Definition at line 247 of file SimpleEncrypter.cxx.
249 std::vector<LLI_t>
r;
255 r.push_back(
r[
i-2] %
r[
i-1]);
◆ initMessaging()
void AthMessaging::initMessaging |
( |
| ) |
const |
|
privateinherited |
Initialize our message level and MessageSvc.
This method should only be called once.
Definition at line 39 of file AthMessaging.cxx.
◆ intBitsToFloat()
float xAOD::SimpleEncrypter::intBitsToFloat |
( |
ULLI_t |
val | ) |
const |
|
privatevirtual |
Interpret bits of integer as floating point number.
Definition at line 379 of file SimpleEncrypter.cxx.
384 unsigned int r = (
int)(std::log2(
val))+1;
387 if (
sizeof(
float)*CHAR_BIT >=
r ) {
389 if (
sizeof(
float) ==
sizeof(
int) ) {
398 char* pres =
reinterpret_cast<char*
>(&
res);
400 for (
unsigned int i=0;
i<
sizeof(
float); ++
i) {
402 for (
unsigned int j=0; j<CHAR_BIT; ++j) {
403 unsigned int n =
i*CHAR_BIT + j;
404 unsigned int bit = (
val >>
n) & 1;
405 if ( bit > 0 ) *(pres+
i) |= 1 << j;
411 <<
sizeof(
float)*CHAR_BIT <<
" < " <<
r);
◆ isOkForDec()
bool xAOD::SimpleEncrypter::isOkForDec |
( |
| ) |
|
|
private |
◆ isOkForEnc()
bool xAOD::SimpleEncrypter::isOkForEnc |
( |
| ) |
|
|
private |
◆ isPrime()
bool xAOD::SimpleEncrypter::isPrime |
( |
ULLI_t |
n | ) |
const |
|
privatevirtual |
◆ keyToString()
std::string xAOD::SimpleEncrypter::keyToString |
( |
ULLI_t |
a, |
|
|
ULLI_t |
b |
|
) |
| const |
|
privatevirtual |
Definition at line 287 of file SimpleEncrypter.cxx.
290 unsigned int ra = (
unsigned int)(
log(
a)/
log(16.))+1;
298 TString tstr = Form(
"%02x%02x%02x%0*x%0*llx%0*x%0*llx",
303 return std::string(tstr.Data());
◆ msg() [1/2]
MsgStream & asg::AsgMessaging::msg |
( |
| ) |
const |
|
inherited |
The standard message stream.
- Returns
- A reference to the default message stream of this object.
Definition at line 49 of file AsgMessaging.cxx.
50 #ifndef XAOD_STANDALONE
52 #else // not XAOD_STANDALONE
54 #endif // not XAOD_STANDALONE
◆ msg() [2/2]
MsgStream & asg::AsgMessaging::msg |
( |
const MSG::Level |
lvl | ) |
const |
|
inherited |
The standard message stream.
- Parameters
-
lvl | The message level to set the stream to |
- Returns
- A reference to the default message stream, set to level "lvl"
Definition at line 57 of file AsgMessaging.cxx.
58 #ifndef XAOD_STANDALONE
60 #else // not XAOD_STANDALONE
63 #endif // not XAOD_STANDALONE
◆ msgLvl()
bool asg::AsgMessaging::msgLvl |
( |
const MSG::Level |
lvl | ) |
const |
|
inherited |
Test the output level of the object.
- Parameters
-
lvl | The message level to test against |
- Returns
- boolean Indicting if messages at given level will be printed
-
true
If messages at level "lvl" will be printed
Definition at line 41 of file AsgMessaging.cxx.
42 #ifndef XAOD_STANDALONE
43 return ::AthMessaging::msgLvl( lvl );
44 #else // not XAOD_STANDALONE
45 return m_msg.msgLevel( lvl );
46 #endif // not XAOD_STANDALONE
◆ powerMod()
◆ setLevel()
void AthMessaging::setLevel |
( |
MSG::Level |
lvl | ) |
|
|
inherited |
◆ setPrivKey()
void xAOD::SimpleEncrypter::setPrivKey |
( |
std::string |
keystr | ) |
|
|
virtual |
Set private key.
- Parameters
-
[in] | hex | string with private key |
Definition at line 78 of file SimpleEncrypter.cxx.
◆ setPubKey()
void xAOD::SimpleEncrypter::setPubKey |
( |
std::string |
keystr | ) |
|
|
virtual |
Set public key.
- Parameters
-
[in] | hex | string with public key |
Definition at line 92 of file SimpleEncrypter.cxx.
◆ ATLAS_THREAD_SAFE
std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT |
|
mutableprivateinherited |
◆ m_d
ULLI_t xAOD::SimpleEncrypter::m_d |
|
private |
◆ m_e
ULLI_t xAOD::SimpleEncrypter::m_e |
|
private |
◆ m_imsg
std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr } |
|
mutableprivateinherited |
◆ m_isOkForDec
bool xAOD::SimpleEncrypter::m_isOkForDec |
|
private |
◆ m_isOkForEnc
bool xAOD::SimpleEncrypter::m_isOkForEnc |
|
private |
indicates that keys are set and range checks are ok
Definition at line 236 of file SimpleEncrypter.h.
◆ m_lvl
std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL } |
|
mutableprivateinherited |
◆ m_MAXHEXDIGITS
Initial value:
maximum number of hex digits for key parts
Definition at line 223 of file SimpleEncrypter.h.
◆ m_MAXRANGE
◆ m_MINRANGE
◆ m_msg_tls
boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls |
|
mutableprivateinherited |
MsgStream instance (a std::cout like with print-out levels)
Definition at line 132 of file AthMessaging.h.
◆ m_n
ULLI_t xAOD::SimpleEncrypter::m_n |
|
private |
◆ m_nm
std::string AthMessaging::m_nm |
|
privateinherited |
The documentation for this class was generated from the following files:
ULLI_t decryptFPECycle(ULLI_t a) const
Decrypt using format preserving encryption w.r.t.
std::atomic< MSG::Level > m_lvl
Current logging level.
virtual ULLI_t genPrime() const
Find a prime number.
virtual std::pair< ULLI_t, ULLI_t > decodeKeyString(std::string str) const
Decode hex string to two integers.
virtual ULLI_t genDecryptionExponent(ULLI_t phi, ULLI_t e) const
Find decryption exponent.
virtual ULLI_t floatBitsToInt(float val) const
ULLI_t encryptFPECycle(ULLI_t a) const
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
virtual ULLI_t genCoprime(ULLI_t n) const
Find a coprime number.
ULLI_t powerMod(ULLI_t a, ULLI_t d, ULLI_t n) const
Exponentiate a with d observing modulus n.
bool isOkForEnc()
Check setup readiness for encryption.
IMessageSvc * getMessageSvc(bool quiet=false)
bool m_isOkForEnc
indicates that keys are set and range checks are ok
ULLI_t decryptInternal(ULLI_t x) const
Decrypt integer (internal)
virtual ULLI_t greatestCommonDenominator(ULLI_t n1, ULLI_t n2) const
Find greatest common denominator.
virtual bool isPrime(ULLI_t n) const
Check for being a prime number.
static const unsigned int m_MAXHEXDIGITS
maximum number of hex digits for key parts
std::pair< std::vector< unsigned int >, bool > res
std::string str(const TrigT2MbtsBits_v1 &trigT2MbtsBits)
virtual void genKeyPairInternal()
Class mimicking the AthMessaging class from the offline software.
static const ULLI_t m_MAXRANGE
unsigned long long int ULLI_t
virtual float intBitsToFloat(ULLI_t val) const
Interpret bits of integer as floating point number.
virtual std::string getPrivKey() const
Get private key.
ULLI_t encryptInternal(ULLI_t x) const
Encrypt integer (internal)
def time(flags, cells_name, *args, **kw)
#define ATH_MSG_WARNING(x)
ULLI_t m_e
encryption exponent: public key part II
std::string m_nm
Message source name.
long long int LLI_t
Useful typedefs.
ULLI_t m_d
decryption exponent: private key part II
constexpr int pow(int base, int exp) noexcept
virtual std::string getPubKey() const
Get public key.
bool isOkForDec()
Check setup readiness for decryption.
virtual std::string keyToString(ULLI_t a, ULLI_t b) const
static const ULLI_t m_MINRANGE