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 310 of file SimpleEncrypter.cxx.

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

◆ 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 162 of file SimpleEncrypter.cxx.

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

◆ 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 130 of file SimpleEncrypter.cxx.

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

◆ 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 440 of file SimpleEncrypter.cxx.

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

◆ decryptInternal()

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

Decrypt integer (internal)

Definition at line 465 of file SimpleEncrypter.cxx.

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

◆ 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 142 of file SimpleEncrypter.cxx.

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

◆ 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 118 of file SimpleEncrypter.cxx.

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

◆ encryptFPECycle()

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

Definition at line 421 of file SimpleEncrypter.cxx.

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

◆ encryptInternal()

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

Encrypt integer (internal)

Definition at line 458 of file SimpleEncrypter.cxx.

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

◆ floatBitsToInt()

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

Definition at line 339 of file SimpleEncrypter.cxx.

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

◆ genCoprime()

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

Find a coprime number.

Definition at line 260 of file SimpleEncrypter.cxx.

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

◆ genDecryptionExponent()

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

Find decryption exponent.

Definition at line 274 of file SimpleEncrypter.cxx.

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

◆ 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 187 of file SimpleEncrypter.cxx.

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

◆ genPrime()

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

Find a prime number.

Definition at line 217 of file SimpleEncrypter.cxx.

217  {
218  //coverity[dont_call]
219  ULLI_t t = (m_MINRANGE + rand()) % (m_MAXRANGE-1);
220  do {
221  t++;
222  } while ( !isPrime(t) || t < m_MINRANGE );
223  return t;
224  }

◆ getPrivKey()

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

Get private key.

Returns
hex string with private key

Definition at line 104 of file SimpleEncrypter.cxx.

104  {
105 
106  return keyToString(m_n, m_d);
107  }

◆ getPubKey()

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

Get public key.

Returns
hex string with public key

Definition at line 111 of file SimpleEncrypter.cxx.

111  {
112 
113  return keyToString(m_e, m_n);
114  }

◆ greatestCommonDenominator()

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

Find greatest common denominator.

Definition at line 245 of file SimpleEncrypter.cxx.

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

◆ 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 380 of file SimpleEncrypter.cxx.

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

◆ isOkForDec()

bool xAOD::SimpleEncrypter::isOkForDec ( )
private

Check setup readiness for decryption.

Definition at line 515 of file SimpleEncrypter.cxx.

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

◆ isOkForEnc()

bool xAOD::SimpleEncrypter::isOkForEnc ( )
private

Check setup readiness for encryption.

Definition at line 499 of file SimpleEncrypter.cxx.

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

◆ isPrime()

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

Check for being a prime number.

Definition at line 228 of file SimpleEncrypter.cxx.

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

◆ keyToString()

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

Definition at line 286 of file SimpleEncrypter.cxx.

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

◆ 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 473 of file SimpleEncrypter.cxx.

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

◆ 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(std::move(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  std::pair<ULLI_t, ULLI_t> keys = decodeKeyString(std::move(keystr));
94  if ( m_n > 0 && m_n != keys.second ) {
95  ATH_MSG_WARNING("RSA module already set!");
96  }
97  m_e = keys.first;
98  m_n = keys.second;
99  m_isOkForEnc = false;
100  }

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:440
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:217
xAOD::SimpleEncrypter::m_n
ULLI_t m_n
Definition: SimpleEncrypter.h:229
beamspotman.r
def r
Definition: beamspotman.py:672
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:310
ParticleDataType::Data
@ Data
Definition: Event/EventKernel/EventKernel/IParticle.h:36
WriteCellNoiseToCool.rb
rb
Definition: WriteCellNoiseToCool.py:229
hist_file_dump.d
d
Definition: hist_file_dump.py:142
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
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:274
xAOD::SimpleEncrypter::floatBitsToInt
virtual ULLI_t floatBitsToInt(float val) const
Definition: SimpleEncrypter.cxx:339
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:421
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:260
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:473
xAOD::SimpleEncrypter::isOkForEnc
bool isOkForEnc()
Check setup readiness for encryption.
Definition: SimpleEncrypter.cxx:499
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:465
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
xAOD::SimpleEncrypter::greatestCommonDenominator
virtual ULLI_t greatestCommonDenominator(ULLI_t n1, ULLI_t n2) const
Find greatest common denominator.
Definition: SimpleEncrypter.cxx:245
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:727
xAOD::float
float
Definition: BTagging_v1.cxx:168
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:228
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:11
hist_file_dump.f
f
Definition: hist_file_dump.py:140
xAOD::int
setRawEt setRawPhi int
Definition: TrigCaloCluster_v1.cxx:33
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:187
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
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:380
xAOD::SimpleEncrypter::getPrivKey
virtual std::string getPrivKey() const
Get private key.
Definition: SimpleEncrypter.cxx:104
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:458
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
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
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:97
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
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:111
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:515
xAOD::SimpleEncrypter::keyToString
virtual std::string keyToString(ULLI_t a, ULLI_t b) const
Definition: SimpleEncrypter.cxx:286
xAOD::SimpleEncrypter::m_MINRANGE
static const ULLI_t m_MINRANGE
Definition: SimpleEncrypter.h:221