ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
xAOD::SimpleEncrypter Class Reference

Provide simple asymmetric encryption for blinding of float values. More...

#include <SimpleEncrypter.h>

Inheritance diagram for xAOD::SimpleEncrypter:
Collaboration diagram for xAOD::SimpleEncrypter:

Public Types

typedef long long int LLI_t
 Useful typedefs. More...
 
typedef unsigned long long int ULLI_t
 

Public Member Functions

 SimpleEncrypter (const std::string &name="SimpleEncrypter")
 Main constructor. More...
 
virtual ~SimpleEncrypter ()
 Default destructor. More...
 
virtual std::pair< std::string, std::string > genKeyPair ()
 Generate private and public keys. More...
 
virtual void setPrivKey (std::string keystr)
 Set private key. More...
 
virtual void setPubKey (std::string keystr)
 Set public key. More...
 
virtual std::string getPrivKey () const
 Get private key. More...
 
virtual std::string getPubKey () const
 Get public key. More...
 
virtual ULLI_t encrypt (ULLI_t x)
 Encrypt a positive integer value. More...
 
virtual ULLI_t decrypt (ULLI_t x)
 Decrypt a positive integer value. More...
 
virtual float encrypt (float x)
 Encrypt a positive float value. More...
 
virtual float decrypt (float x)
 Decrypt a positive float value. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc. More...
 
Key generation utilities

Internally generate numeric representation of key pair

virtual void genKeyPairInternal ()
 
virtual ULLI_t genPrime () const
 Find a prime number. More...
 
virtual bool isPrime (ULLI_t n) const
 Check for being a prime number. More...
 
virtual ULLI_t greatestCommonDenominator (ULLI_t n1, ULLI_t n2) const
 Find greatest common denominator. More...
 
virtual ULLI_t genCoprime (ULLI_t n) const
 Find a coprime number. More...
 
virtual ULLI_t genDecryptionExponent (ULLI_t phi, ULLI_t e) const
 Find decryption exponent. More...
 
Key conversion utilities

Convert key to hex string

virtual std::string keyToString (ULLI_t a, ULLI_t b) const
 
virtual std::pair< ULLI_t, ULLI_tdecodeKeyString (std::string str) const
 Decode hex string to two integers. More...
 
float <-> int conversion utilities

Interpret bits of floating point number as integer

virtual ULLI_t floatBitsToInt (float val) const
 
virtual float intBitsToFloat (ULLI_t val) const
 Interpret bits of integer as floating point number. More...
 
Internal en-/decryption methods

Encrypt using format preserving encryption w.r.t.

RSA modulus

ULLI_t encryptFPECycle (ULLI_t a) const
 
ULLI_t decryptFPECycle (ULLI_t a) const
 Decrypt using format preserving encryption w.r.t. More...
 
ULLI_t encryptInternal (ULLI_t x) const
 Encrypt integer (internal) More...
 
ULLI_t decryptInternal (ULLI_t x) const
 Decrypt integer (internal) More...
 
ULLI_t powerMod (ULLI_t a, ULLI_t d, ULLI_t n) const
 Exponentiate a with d observing modulus n. More...
 
bool isOkForEnc ()
 Check setup readiness for encryption. More...
 
bool isOkForDec ()
 Check setup readiness for decryption. More...
 

Private Attributes

std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 
Internal member variables

RSA modulus: common part of both keys

ULLI_t m_n
 
ULLI_t m_e
 encryption exponent: public key part II More...
 
ULLI_t m_d
 decryption exponent: private key part II More...
 
bool m_isOkForEnc
 indicates that keys are set and range checks are ok More...
 
bool m_isOkForDec
 

Static Private Attributes

Internal static consts

Approximate range for prime numbers to be generated in

static const ULLI_t m_MAXRANGE
 
static const ULLI_t m_MINRANGE
 
static const unsigned int m_MAXHEXDIGITS
 maximum number of hex digits for key parts More...
 

Detailed Description

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.

Member Typedef Documentation

◆ LLI_t

typedef long long int xAOD::SimpleEncrypter::LLI_t

Useful typedefs.

Definition at line 40 of file SimpleEncrypter.h.

◆ ULLI_t

Definition at line 41 of file SimpleEncrypter.h.

Constructor & Destructor Documentation

◆ SimpleEncrypter()

xAOD::SimpleEncrypter::SimpleEncrypter ( const std::string &  name = "SimpleEncrypter")

Main constructor.

Parameters
[in]nameof instance

Definition at line 42 of file SimpleEncrypter.cxx.

42  :
43  asg::AsgMessaging(name), m_n(0), m_e(0), m_d(0),
44  m_isOkForEnc(false), m_isOkForDec(false) {
45 
46  // initialize random number generator
47  srand(static_cast<unsigned>(time(0)));
48  }

◆ ~SimpleEncrypter()

xAOD::SimpleEncrypter::~SimpleEncrypter ( )
virtual

Default destructor.

Definition at line 53 of file SimpleEncrypter.cxx.

53  {
54 
55  }

Member Function Documentation

◆ decodeKeyString()

std::pair< SimpleEncrypter::ULLI_t, SimpleEncrypter::ULLI_t > xAOD::SimpleEncrypter::decodeKeyString ( std::string  str) const
privatevirtual

Decode hex string to two integers.

Definition at line 309 of file SimpleEncrypter.cxx.

309  {
310 
311  std::pair<ULLI_t, ULLI_t> keys(0,0);
312 
313  TString str(hstr);
314  if (str.IsHex() && str.Length() > 3) {
315  str.ToLower();
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(),
321  nullptr, 16);
322  keys.second = strtoll(TString(str(2*ndigits+6-rb, rb)).Data(),
323  nullptr, 16);
324  } else {
325  ATH_MSG_ERROR("Private/public key must be a hex string of " <<
326  2*m_MAXHEXDIGITS+6 << " digits!");
327  } // if Length()
328  } else {
329  ATH_MSG_ERROR("Private/public key must be a hex string of " <<
330  2*m_MAXHEXDIGITS+6 << " digits!");
331  } // if IsHex() ...
332 
333  return keys;
334  }

◆ decrypt() [1/2]

float xAOD::SimpleEncrypter::decrypt ( float  x)
virtual

Decrypt a positive float value.

Parameters
[in]positivefloat value to be decrypted
Returns
encrypted float value

Definition at line 164 of file SimpleEncrypter.cxx.

164  {
165 
166  float b = a;
167 
168  // As nan is a valid encrypted value, decrypt it as well.
169  if ( a > 0. || std::isnan(a) ) {
170  if ( isOkForDec() ) {
171  ULLI_t ia = floatBitsToInt(a);
172  ULLI_t ib = decryptFPECycle(ia);
173  b = intBitsToFloat(ib);
174  }
175  } else {
176  ATH_MSG_WARNING("Decrypt: Float value not positive: "
177  << a << Form(" (%a) !", a));
178  } // if a > 0
179  return b;
180  }

◆ decrypt() [2/2]

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::decrypt ( ULLI_t  x)
virtual

Decrypt a positive integer value.

Parameters
[in]unsignedinteger value to be decrypted
Returns
encrypted unsigned integer value

Definition at line 132 of file SimpleEncrypter.cxx.

132  {
133 
134  ULLI_t b = a;
135 
136  if ( isOkForDec() ) {
137  b = decryptFPECycle(a);
138  }
139  return b;
140  }

◆ decryptFPECycle()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::decryptFPECycle ( ULLI_t  a) const
private

Decrypt using format preserving encryption w.r.t.

RSA modulus

Definition at line 439 of file SimpleEncrypter.cxx.

439  {
440 
441  ULLI_t dec = 0;
442  if ( enc > 0 ) {
443  ULLI_t r = (int)(std::log2(m_n));
444  ULLI_t rmask = pow(2,r)-1;
445  ULLI_t d = enc & rmask;
446  ULLI_t b = enc - d;
447  do {
448  d = decryptInternal(d);
449  } while ( d > rmask );
450  dec = d + b;
451  } // if
452  return dec;
453  }

◆ decryptInternal()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::decryptInternal ( ULLI_t  x) const
private

Decrypt integer (internal)

Definition at line 464 of file SimpleEncrypter.cxx.

464  {
465 
466  return powerMod(x, m_d, m_n);
467  }

◆ encrypt() [1/2]

float xAOD::SimpleEncrypter::encrypt ( float  x)
virtual

Encrypt a positive float value.

Parameters
[in]positivefloat value to be encrypted
Returns
encrypted float value

Definition at line 144 of file SimpleEncrypter.cxx.

144  {
145 
146  float b = a;
147 
148  if ( a > 0. ) {
149  if ( isOkForEnc() ) {
150  ULLI_t ia = floatBitsToInt(a);
151  ULLI_t ib = encryptFPECycle(ia);
152  b = intBitsToFloat(ib);
153  }
154  } else {
155  ATH_MSG_WARNING("Encrypt: Float value not positive: "
156  << a << Form(" (%a) !", a));
157  } // if a > 0
158  return b;
159  }

◆ encrypt() [2/2]

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::encrypt ( ULLI_t  x)
virtual

Encrypt a positive integer value.

Parameters
[in]unsignedinteger value to be encrypted
Returns
encrypted unsigned integer value

Definition at line 120 of file SimpleEncrypter.cxx.

120  {
121 
122  ULLI_t b = a;
123 
124  if ( isOkForEnc() ) {
125  b = encryptFPECycle(a);
126  }
127  return b;
128  }

◆ encryptFPECycle()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::encryptFPECycle ( ULLI_t  a) const
private

Definition at line 420 of file SimpleEncrypter.cxx.

420  {
421 
422  ULLI_t enc = 0;
423  if ( a > 0 ) {
424  ULLI_t r = (int)(std::log2(m_n));
425  ULLI_t rmask = pow(2,r)-1;
426  ULLI_t c = a & rmask;
427  ULLI_t b = a - c;
428  do {
429  c = encryptInternal(c);
430  } while ( c > rmask );
431  enc = b + c;
432  } // if
433  return enc;
434  }

◆ encryptInternal()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::encryptInternal ( ULLI_t  x) const
private

Encrypt integer (internal)

Definition at line 457 of file SimpleEncrypter.cxx.

457  {
458 
459  return powerMod(x, m_e, m_n);
460  }

◆ floatBitsToInt()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::floatBitsToInt ( float  val) const
privatevirtual

Definition at line 338 of file SimpleEncrypter.cxx.

338  {
339 
340  ULLI_t res(0);
341 
342  if ( val < 0. ) {
343  ATH_MSG_ERROR("Float value needs to be positive!");
344  } else {
345  // convert floating point number to ULLI_t if size fits
346  if ( sizeof(float) <= sizeof(ULLI_t) ) {
347  // check whether a quick conversion is possible
348  if ( sizeof(float) == sizeof(int) ) {
349  union {
350  float f;
351  int i;
352  } fint;
353  fint.f = val;
354  res = fint.i;
355  } else {
356  // do a slow conversion
357  char* pval = reinterpret_cast<char*>(&val);
358  // loop over bytes
359  for (unsigned int i=0; i<sizeof(float); ++i) {
360  // loop over bits
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;
365  } // for bits
366  } // for bytes
367  } // if sizeof
368  } else {
369  ATH_MSG_ERROR("sizeof(float) > sizeof(ULLI_t): "
370  << sizeof(float) << " > " << sizeof(LLI_t));
371  } // if sizeof
372  } // if val < 0.
373 
374  return res;
375  }

◆ genCoprime()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::genCoprime ( ULLI_t  n) const
privatevirtual

Find a coprime number.

Definition at line 262 of file SimpleEncrypter.cxx.

262  {
263 
264  // make sure coprime is larger than 5th Fermat number (2^16+1 = 65537)
265  ULLI_t i = (65537 + rand()) % (m_MAXRANGE -1);
266  do {
267  ++i;
268  } while (greatestCommonDenominator(n, i) != 1);
269  return i;
270  }

◆ genDecryptionExponent()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::genDecryptionExponent ( ULLI_t  phi,
ULLI_t  e 
) const
privatevirtual

Find decryption exponent.

Definition at line 275 of file SimpleEncrypter.cxx.

275  {
276 
277  for (ULLI_t i=1; i<m_MAXRANGE; ++i) {
278  if ( ((phi * i + 1) % e) == 0 ) {
279  return (ULLI_t)((phi * i + 1) / e);
280  }
281  }
282  return 0;
283  }

◆ 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.

60  {
61 
62  // default preset
63  std::pair<std::string, std::string> keys =
64  std::make_pair("__NO_PRIV_KEY__", "__NO_PUB_KEY__");
65 
66  // generate keys
68 
69  if ( isOkForEnc() && isOkForDec() ) {
70  keys = std::make_pair(getPrivKey(), getPubKey());
71  }
72  return keys;
73  }

◆ genKeyPairInternal()

void xAOD::SimpleEncrypter::genKeyPairInternal ( )
privatevirtual

Definition at line 189 of file SimpleEncrypter.cxx.

189  {
190 
191  // Generate prime numbers p != q
192  ULLI_t p(1);
193  ULLI_t q(1);
194  // Euler's phi function
195  ULLI_t phi(1);
196 
197  // reset encryption and decryption exponent
198  m_e = 0;
199  m_d = 0;
200  while ( p == q || m_e < 2 || m_e >= phi || m_d < 2
201  || m_e*m_d % phi != 1 ) {
202  double dlog2 = 0.;
203  while ( p == q || dlog2 < 0.1 || dlog2 > 30. ) {
204  p = genPrime();
205  q = genPrime();
206  dlog2 = fabs(log2(p)-log2(q));
207  } // inner while loop
208  phi = (p-1)*(q-1);
209  m_n = p*q;
210  m_e = genCoprime(phi);
212  } // outer while loop
213  m_isOkForDec = false;
214  m_isOkForEnc = false;
215  }

◆ genPrime()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::genPrime ( ) const
privatevirtual

Find a prime number.

Definition at line 219 of file SimpleEncrypter.cxx.

219  {
220 
221  ULLI_t t = (m_MINRANGE + rand()) % (m_MAXRANGE-1);
222  do {
223  t++;
224  } while ( !isPrime(t) || t < m_MINRANGE );
225  return t;
226  }

◆ getPrivKey()

std::string xAOD::SimpleEncrypter::getPrivKey ( ) const
virtual

Get private key.

Returns
hex string with private key

Definition at line 106 of file SimpleEncrypter.cxx.

106  {
107 
108  return keyToString(m_n, m_d);
109  }

◆ getPubKey()

std::string xAOD::SimpleEncrypter::getPubKey ( ) const
virtual

Get public key.

Returns
hex string with public key

Definition at line 113 of file SimpleEncrypter.cxx.

113  {
114 
115  return keyToString(m_e, m_n);
116  }

◆ greatestCommonDenominator()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::greatestCommonDenominator ( ULLI_t  n1,
ULLI_t  n2 
) const
privatevirtual

Find greatest common denominator.

Definition at line 247 of file SimpleEncrypter.cxx.

247  {
248 
249  std::vector<LLI_t> r;
250  LLI_t i = 1;
251  r.push_back(std::max(n1, n2));
252  r.push_back(std::min(n1, n2));
253  while (r[i] != 0) {
254  ++i;
255  r.push_back(r[i-2] % r[i-1]);
256  }
257  return r[i-1];
258  }

◆ 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.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ 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.

379  {
380 
381  float res(0.);
382 
383  // number of bits needed
384  unsigned int r = (int)(std::log2(val))+1;
385 
386  // convert ULLI_t to floating point number if size fits
387  if ( sizeof(float)*CHAR_BIT >= r ) {
388  // check whether a quick conversion is possible
389  if ( sizeof(float) == sizeof(int) ) {
390  union {
391  float f;
392  ULLI_t i;
393  } ficnv;
394  ficnv.i = val;
395  res = ficnv.f;
396  } else {
397  // do a slow conversion
398  char* pres = reinterpret_cast<char*>(&res);
399  // loop over bytes
400  for (unsigned int i=0; i<sizeof(float); ++i) {
401  // loop over bits
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;
406  } // for bits
407  } // for bytes
408  } // if sizeof
409  } else {
410  ATH_MSG_WARNING("sizeof(float)*CHAR_BIT < r: "
411  << sizeof(float)*CHAR_BIT << " < " << r);
412  } // if sizeof
413 
414  return res;
415  }

◆ isOkForDec()

bool xAOD::SimpleEncrypter::isOkForDec ( )
private

Check setup readiness for decryption.

Definition at line 514 of file SimpleEncrypter.cxx.

514  {
515 
516  if ( !m_isOkForDec ) {
517  if ( m_n > 0 && m_d > 1 && m_d < m_n ) {
518  m_isOkForDec = true;
519  } else {
520  ATH_MSG_ERROR("Setup not OK for decryption: private key set?");
521  }
522  } // if ! m_isOkForDec
523 
524  return m_isOkForDec;
525  }

◆ isOkForEnc()

bool xAOD::SimpleEncrypter::isOkForEnc ( )
private

Check setup readiness for encryption.

Definition at line 498 of file SimpleEncrypter.cxx.

498  {
499 
500  if ( !m_isOkForEnc ) {
501  if ( m_n > 0 && m_e > 1 && m_e < m_n ) {
502  m_isOkForEnc = true;
503  } else {
504  ATH_MSG_ERROR("Setup not OK for encryption: public key set?");
505  }
506  } // if ! m_isOkForEnc
507 
508  return m_isOkForEnc;
509  }

◆ isPrime()

bool xAOD::SimpleEncrypter::isPrime ( ULLI_t  n) const
privatevirtual

Check for being a prime number.

Definition at line 230 of file SimpleEncrypter.cxx.

230  {
231 
232  bool isPrime = true;
233  if (n != 2) {
234  for (LLI_t i = 2; i < (LLI_t)sqrt(n) + 1; ++i) {
235  if (n % i == 0) {
236  isPrime = false;
237  break;
238  }
239  }
240  }
241  return isPrime;
242  }

◆ keyToString()

std::string xAOD::SimpleEncrypter::keyToString ( ULLI_t  a,
ULLI_t  b 
) const
privatevirtual

Definition at line 287 of file SimpleEncrypter.cxx.

287  {
288 
289  // length of keys w.r.t. hex digits
290  unsigned int ra = (unsigned int)(log(a)/log(16.))+1;
291  unsigned int rb = (unsigned int)(log(b)/log(16.))+1;
292 
293  // random numbers for padding
294  unsigned int r1 = rand() & ((1 << 4*(m_MAXHEXDIGITS-ra))-1);
295  unsigned int r2 = rand() & ((1 << 4*(m_MAXHEXDIGITS-rb))-1);
296 
297  // format string
298  TString tstr = Form("%02x%02x%02x%0*x%0*llx%0*x%0*llx",
299  m_MAXHEXDIGITS, ra, rb,
300  m_MAXHEXDIGITS-ra, r1, ra, a,
301  m_MAXHEXDIGITS-rb, r2, rb, b);
302 
303  return std::string(tstr.Data());
304  }

◆ 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.

49  {
50 #ifndef XAOD_STANDALONE
52 #else // not XAOD_STANDALONE
53  return m_msg;
54 #endif // not XAOD_STANDALONE
55  }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level  lvl) const
inherited

The standard message stream.

Parameters
lvlThe 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.

57  {
58 #ifndef XAOD_STANDALONE
60 #else // not XAOD_STANDALONE
61  m_msg << lvl;
62  return m_msg;
63 #endif // not XAOD_STANDALONE
64  }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level  lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe 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.

41  {
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
47  }

◆ powerMod()

SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::powerMod ( ULLI_t  a,
ULLI_t  d,
ULLI_t  n 
) const
private

Exponentiate a with d observing modulus n.

Definition at line 472 of file SimpleEncrypter.cxx.

472  {
473 
474  int bin[sizeof(ULLI_t)*CHAR_BIT];
475  ULLI_t dec[sizeof(ULLI_t)*CHAR_BIT];
476 
477  ULLI_t r = (ULLI_t)(std::log2(d))+1;
478  ULLI_t tmp = d;
479  // decompose exponent into binary number (reverse order!)
480  for (ULLI_t i=0; i < r; ++i) {
481  bin[r-i-1] = tmp % 2;
482  tmp = (LLI_t)(tmp/2);
483  } // for i
484 
485  // perform the exponentiation taking modulus into account
486  dec[0] = a;
487  for (ULLI_t i=1; i < r; ++i) {
488  ULLI_t d2 = dec[i-1]*dec[i-1] % n;
489  if ( bin[i] > 0 ) d2 *= a;
490  dec[i] = d2 % n;
491  } // for i
492 
493  return dec[r-1];
494  }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

◆ setPrivKey()

void xAOD::SimpleEncrypter::setPrivKey ( std::string  keystr)
virtual

Set private key.

Parameters
[in]hexstring with private key

Definition at line 78 of file SimpleEncrypter.cxx.

78  {
79 
80  std::pair<ULLI_t, ULLI_t> keys = decodeKeyString(keystr);
81 
82  if ( m_n > 0 && m_n != keys.first ) {
83  ATH_MSG_WARNING("RSA module already set!");
84  }
85  m_n = keys.first;
86  m_d = keys.second;
87  m_isOkForDec = false;
88  }

◆ setPubKey()

void xAOD::SimpleEncrypter::setPubKey ( std::string  keystr)
virtual

Set public key.

Parameters
[in]hexstring with public key

Definition at line 92 of file SimpleEncrypter.cxx.

92  {
93 
94  std::pair<ULLI_t, ULLI_t> keys = decodeKeyString(keystr);
95 
96  if ( m_n > 0 && m_n != keys.second ) {
97  ATH_MSG_WARNING("RSA module already set!");
98  }
99  m_e = keys.first;
100  m_n = keys.second;
101  m_isOkForEnc = false;
102  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_d

ULLI_t xAOD::SimpleEncrypter::m_d
private

decryption exponent: private key part II

Definition at line 233 of file SimpleEncrypter.h.

◆ m_e

ULLI_t xAOD::SimpleEncrypter::m_e
private

encryption exponent: public key part II

Definition at line 231 of file SimpleEncrypter.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_isOkForDec

bool xAOD::SimpleEncrypter::m_isOkForDec
private

Definition at line 237 of file SimpleEncrypter.h.

◆ 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

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_MAXHEXDIGITS

const unsigned int xAOD::SimpleEncrypter::m_MAXHEXDIGITS
staticprivate
Initial value:
=
(unsigned int)(log(pow(SimpleEncrypter::m_MAXRANGE,2))/log(16.))+3

maximum number of hex digits for key parts

Definition at line 223 of file SimpleEncrypter.h.

◆ m_MAXRANGE

const SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::m_MAXRANGE
staticprivate
Initial value:

Definition at line 220 of file SimpleEncrypter.h.

◆ m_MINRANGE

const SimpleEncrypter::ULLI_t xAOD::SimpleEncrypter::m_MINRANGE
staticprivate
Initial value:

Definition at line 221 of file SimpleEncrypter.h.

◆ 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

Definition at line 229 of file SimpleEncrypter.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.


The documentation for this class was generated from the following files:
xAOD::SimpleEncrypter::decryptFPECycle
ULLI_t decryptFPECycle(ULLI_t a) const
Decrypt using format preserving encryption w.r.t.
Definition: SimpleEncrypter.cxx:439
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
xAOD::SimpleEncrypter::genPrime
virtual ULLI_t genPrime() const
Find a prime number.
Definition: SimpleEncrypter.cxx:219
xAOD::SimpleEncrypter::m_n
ULLI_t m_n
Definition: SimpleEncrypter.h:229
beamspotman.r
def r
Definition: beamspotman.py:676
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
xAOD::SimpleEncrypter::decodeKeyString
virtual std::pair< ULLI_t, ULLI_t > decodeKeyString(std::string str) const
Decode hex string to two integers.
Definition: SimpleEncrypter.cxx:309
xAOD::int
setRawEt setRawPhi int
Definition: TrigCaloCluster_v1.cxx:33
xAOD::float
float
Definition: BTagging_v1.cxx:168
WriteCellNoiseToCool.rb
rb
Definition: WriteCellNoiseToCool.py:229
hist_file_dump.d
d
Definition: hist_file_dump.py:137
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
Data
@ Data
Definition: BaseObject.h:11
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
xAOD::SimpleEncrypter::genDecryptionExponent
virtual ULLI_t genDecryptionExponent(ULLI_t phi, ULLI_t e) const
Find decryption exponent.
Definition: SimpleEncrypter.cxx:275
xAOD::SimpleEncrypter::floatBitsToInt
virtual ULLI_t floatBitsToInt(float val) const
Definition: SimpleEncrypter.cxx:338
bin
Definition: BinsDiffFromStripMedian.h:43
PlotCalibFromCool.ib
ib
Definition: PlotCalibFromCool.py:419
xAOD::SimpleEncrypter::encryptFPECycle
ULLI_t encryptFPECycle(ULLI_t a) const
Definition: SimpleEncrypter.cxx:420
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
MCP::ScaleSmearParam::r2
@ r2
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
x
#define x
xAOD::SimpleEncrypter::genCoprime
virtual ULLI_t genCoprime(ULLI_t n) const
Find a coprime number.
Definition: SimpleEncrypter.cxx:262
xAOD::SimpleEncrypter::powerMod
ULLI_t powerMod(ULLI_t a, ULLI_t d, ULLI_t n) const
Exponentiate a with d observing modulus n.
Definition: SimpleEncrypter.cxx:472
xAOD::SimpleEncrypter::isOkForEnc
bool isOkForEnc()
Check setup readiness for encryption.
Definition: SimpleEncrypter.cxx:498
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
xAOD::SimpleEncrypter::m_isOkForEnc
bool m_isOkForEnc
indicates that keys are set and range checks are ok
Definition: SimpleEncrypter.h:236
xAOD::phi
setEt phi
Definition: TrigEMCluster_v1.cxx:29
xAOD::SimpleEncrypter::decryptInternal
ULLI_t decryptInternal(ULLI_t x) const
Decrypt integer (internal)
Definition: SimpleEncrypter.cxx:464
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
xAOD::SimpleEncrypter::greatestCommonDenominator
virtual ULLI_t greatestCommonDenominator(ULLI_t n1, ULLI_t n2) const
Find greatest common denominator.
Definition: SimpleEncrypter.cxx:247
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArG4FSStartPointFilter.rand
rand
Definition: LArG4FSStartPointFilter.py:80
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
xAOD::e
setPy e
Definition: CompositeParticle_v1.cxx:166
xAOD::SimpleEncrypter::isPrime
virtual bool isPrime(ULLI_t n) const
Check for being a prime number.
Definition: SimpleEncrypter.cxx:230
xAOD::SimpleEncrypter::m_MAXHEXDIGITS
static const unsigned int m_MAXHEXDIGITS
maximum number of hex digits for key parts
Definition: SimpleEncrypter.h:223
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
hist_file_dump.f
f
Definition: hist_file_dump.py:135
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
xAOD::str
std::string str(const TrigT2MbtsBits_v1 &trigT2MbtsBits)
Definition: TrigT2MbtsBits_v1.cxx:37
xAOD::SimpleEncrypter::genKeyPairInternal
virtual void genKeyPairInternal()
Definition: SimpleEncrypter.cxx:189
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
xAOD::SimpleEncrypter::m_MAXRANGE
static const ULLI_t m_MAXRANGE
Definition: SimpleEncrypter.h:220
xAOD::SimpleEncrypter::ULLI_t
unsigned long long int ULLI_t
Definition: SimpleEncrypter.h:41
xAOD::SimpleEncrypter::m_isOkForDec
bool m_isOkForDec
Definition: SimpleEncrypter.h:237
xAOD::SimpleEncrypter::intBitsToFloat
virtual float intBitsToFloat(ULLI_t val) const
Interpret bits of integer as floating point number.
Definition: SimpleEncrypter.cxx:379
xAOD::SimpleEncrypter::getPrivKey
virtual std::string getPrivKey() const
Get private key.
Definition: SimpleEncrypter.cxx:106
Rtt_histogram.n1
n1
Definition: Rtt_histogram.py:21
a
TList * a
Definition: liststreamerinfos.cxx:10
xAOD::SimpleEncrypter::encryptInternal
ULLI_t encryptInternal(ULLI_t x) const
Encrypt integer (internal)
Definition: SimpleEncrypter.cxx:457
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::SimpleEncrypter::m_e
ULLI_t m_e
encryption exponent: public key part II
Definition: SimpleEncrypter.h:231
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
extractSporadic.q
list q
Definition: extractSporadic.py:98
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
xAOD::SimpleEncrypter::LLI_t
long long int LLI_t
Useful typedefs.
Definition: SimpleEncrypter.h:40
xAOD::SimpleEncrypter::m_d
ULLI_t m_d
decryption exponent: private key part II
Definition: SimpleEncrypter.h:233
MCP::ScaleSmearParam::r1
@ r1
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
xAOD::SimpleEncrypter::getPubKey
virtual std::string getPubKey() const
Get public key.
Definition: SimpleEncrypter.cxx:113
python.compressB64.c
def c
Definition: compressB64.py:93
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
xAOD::SimpleEncrypter::isOkForDec
bool isOkForDec()
Check setup readiness for decryption.
Definition: SimpleEncrypter.cxx:514
xAOD::SimpleEncrypter::keyToString
virtual std::string keyToString(ULLI_t a, ULLI_t b) const
Definition: SimpleEncrypter.cxx:287
xAOD::SimpleEncrypter::m_MINRANGE
static const ULLI_t m_MINRANGE
Definition: SimpleEncrypter.h:221