ATLAS Offline Software
Loading...
Searching...
No Matches
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.
typedef unsigned long long int ULLI_t

Public Member Functions

 SimpleEncrypter (const std::string &name="SimpleEncrypter")
 Main constructor.
virtual ~SimpleEncrypter ()
 Default destructor.
virtual std::pair< std::string, std::string > genKeyPair ()
 Generate private and public keys.
virtual void setPrivKey (std::string keystr)
 Set private key.
virtual void setPubKey (std::string keystr)
 Set public key.
virtual std::string getPrivKey () const
 Get private key.
virtual std::string getPubKey () const
 Get public key.
virtual ULLI_t encrypt (ULLI_t x)
 Encrypt a positive integer value.
virtual ULLI_t decrypt (ULLI_t x)
 Decrypt a positive integer value.
virtual float encrypt (float x)
 Encrypt a positive float value.
virtual float decrypt (float x)
 Decrypt a positive float value.
void setLevel (MSG::Level lvl)
 Change the current logging level.
Functions providing the same interface as AthMessaging
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.

Private Member Functions

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

Internally generate numeric representation of key pair

virtual void genKeyPairInternal ()
virtual ULLI_t genPrime () const
 Find a prime number.
virtual bool isPrime (ULLI_t n) const
 Check for being a prime number.
virtual ULLI_t greatestCommonDenominator (ULLI_t n1, ULLI_t n2) const
 Find greatest common denominator.
virtual ULLI_t genCoprime (ULLI_t n) const
 Find a coprime number.
virtual ULLI_t genDecryptionExponent (ULLI_t phi, ULLI_t e) const
 Find decryption exponent.
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.
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.
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.
ULLI_t encryptInternal (ULLI_t x) const
 Encrypt integer (internal).
ULLI_t decryptInternal (ULLI_t x) const
 Decrypt integer (internal).
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.
bool isOkForDec ()
 Check setup readiness for decryption.

Private Attributes

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

RSA modulus: common part of both keys

ULLI_t m_n
ULLI_t m_e
 encryption exponent: public key part II
ULLI_t m_d
 decryption exponent: private key part II
bool m_isOkForEnc
 indicates that keys are set and range checks are ok
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

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

48 :
49 asg::AsgMessaging(name), m_n(0), m_e(0), m_d(0),
50 m_isOkForEnc(false), m_isOkForDec(false) {
51
52 // initialize random number generator
53 srand(static_cast<unsigned>(time(0)));
54 }
bool m_isOkForEnc
indicates that keys are set and range checks are ok
ULLI_t m_e
encryption exponent: public key part II
ULLI_t m_d
decryption exponent: private key part II
time(flags, cells_name, *args, **kw)

◆ ~SimpleEncrypter()

xAOD::SimpleEncrypter::~SimpleEncrypter ( )
virtual

Default destructor.

Definition at line 59 of file SimpleEncrypter.cxx.

59 {
60
61 }

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

316 {
317
318 std::pair<ULLI_t, ULLI_t> keys(0,0);
319
320 TString str(hstr);
321 if (str.IsHex() && str.Length() > 3) {
322 str.ToLower();
323 unsigned int ndigits = strtoul(TString(str(0,2)).Data(), nullptr, 16);
324 unsigned int ra = strtoul(TString(str(2,2)).Data(), nullptr, 16);
325 unsigned int rb = strtoul(TString(str(4,2)).Data(), nullptr, 16);
326 if ( str.Length() == (int)(2*ndigits + 6) ) {
327 keys.first = strtoll(TString(str(ndigits+6-ra, ra)).Data(),
328 nullptr, 16);
329 keys.second = strtoll(TString(str(2*ndigits+6-rb, rb)).Data(),
330 nullptr, 16);
331 } else {
332 ATH_MSG_ERROR("Private/public key must be a hex string of " <<
333 2*m_MAXHEXDIGITS+6 << " digits!");
334 } // if Length()
335 } else {
336 ATH_MSG_ERROR("Private/public key must be a hex string of " <<
337 2*m_MAXHEXDIGITS+6 << " digits!");
338 } // if IsHex() ...
339
340 return keys;
341 }
#define ATH_MSG_ERROR(x)
@ Data
Definition BaseObject.h:11
static const unsigned int m_MAXHEXDIGITS
maximum number of hex digits for key parts

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

168 {
169
170 float b = a;
171
172 // As nan is a valid encrypted value, decrypt it as well.
173 if ( a > 0. || std::isnan(a) ) {
174 if ( isOkForDec() ) {
175 ULLI_t ia = floatBitsToInt(a);
177 b = intBitsToFloat(ib);
178 }
179 } else {
180 ATH_MSG_WARNING("Decrypt: Float value not positive: "
181 << a << Form(" (%a) !", a));
182 } // if a > 0
183 return b;
184 }
#define ATH_MSG_WARNING(x)
static Double_t a
bool isOkForDec()
Check setup readiness for decryption.
ULLI_t decryptFPECycle(ULLI_t a) const
Decrypt using format preserving encryption w.r.t.
unsigned long long int ULLI_t
virtual float intBitsToFloat(ULLI_t val) const
Interpret bits of integer as floating point number.
virtual ULLI_t floatBitsToInt(float val) const

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

136 {
137
138 ULLI_t b = a;
139
140 if ( isOkForDec() ) {
142 }
143 return b;
144 }

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

389 {
390
391 ULLI_t dec = 0;
392 if ( enc > 0 ) {
393 ULLI_t r = (int)(std::log2(m_n));
394 ULLI_t rmask = pow(2,r)-1;
395 ULLI_t d = enc & rmask;
396 ULLI_t b = enc - d;
397 do {
398 d = decryptInternal(d);
399 } while ( d > rmask );
400 dec = d + b;
401 } // if
402 return dec;
403 }
ULLI_t decryptInternal(ULLI_t x) const
Decrypt integer (internal).
int r
Definition globals.cxx:22
constexpr int pow(int x)
Definition conifer.h:27
setRawEt setRawPhi int

◆ decryptInternal()

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

Decrypt integer (internal).

Definition at line 414 of file SimpleEncrypter.cxx.

414 {
415
416 return powerMod(x, m_d, m_n);
417 }
#define x
ULLI_t powerMod(ULLI_t a, ULLI_t d, ULLI_t n) const
Exponentiate a with d observing modulus n.

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

148 {
149
150 float b = a;
151
152 if ( a > 0. ) {
153 if ( isOkForEnc() ) {
154 ULLI_t ia = floatBitsToInt(a);
156 b = intBitsToFloat(ib);
157 }
158 } else {
159 ATH_MSG_WARNING("Encrypt: Float value not positive: "
160 << a << Form(" (%a) !", a));
161 } // if a > 0
162 return b;
163 }
ULLI_t encryptFPECycle(ULLI_t a) const
bool isOkForEnc()
Check setup readiness for encryption.

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

124 {
125
126 ULLI_t b = a;
127
128 if ( isOkForEnc() ) {
130 }
131 return b;
132 }

◆ encryptFPECycle()

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

Definition at line 370 of file SimpleEncrypter.cxx.

370 {
371
372 ULLI_t enc = 0;
373 if ( a > 0 ) {
374 ULLI_t r = (int)(std::log2(m_n));
375 ULLI_t rmask = pow(2,r)-1;
376 ULLI_t c = a & rmask;
377 ULLI_t b = a - c;
378 do {
379 c = encryptInternal(c);
380 } while ( c > rmask );
381 enc = b + c;
382 } // if
383 return enc;
384 }
ULLI_t encryptInternal(ULLI_t x) const
Encrypt integer (internal).

◆ encryptInternal()

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

Encrypt integer (internal).

Definition at line 407 of file SimpleEncrypter.cxx.

407 {
408
409 return powerMod(x, m_e, m_n);
410 }

◆ floatBitsToInt()

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

Definition at line 346 of file SimpleEncrypter.cxx.

346 {
347 static_assert(sizeof(float) == sizeof(std::uint32_t),"This code assumes a 32-bit float");
348 if (val < 0.0F) {
349 ATH_MSG_ERROR("Float value needs to be positive!");
350 return 0;
351 }
352 return std::bit_cast<std::uint32_t>(val);
353 }

◆ genCoprime()

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

Find a coprime number.

Definition at line 266 of file SimpleEncrypter.cxx.

266 {
267
268 // make sure coprime is larger than 5th Fermat number (2^16+1 = 65537)
269 //coverity[dont_call]
270 ULLI_t i = (65537 + rand()) % (m_MAXRANGE -1);
271 do {
272 ++i;
273 } while (greatestCommonDenominator(n, i) != 1);
274 return i;
275 }
virtual ULLI_t greatestCommonDenominator(ULLI_t n1, ULLI_t n2) const
Find greatest common denominator.
static const ULLI_t m_MAXRANGE

◆ genDecryptionExponent()

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

Find decryption exponent.

Definition at line 280 of file SimpleEncrypter.cxx.

280 {
281
282 for (ULLI_t i=1; i<m_MAXRANGE; ++i) {
283 if ( ((phi * i + 1) % e) == 0 ) {
284 return (ULLI_t)((phi * i + 1) / e);
285 }
286 }
287 return 0;
288 }

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

66 {
67
68 // default preset
69 std::pair<std::string, std::string> keys =
70 std::make_pair("__NO_PRIV_KEY__", "__NO_PUB_KEY__");
71
72 // generate keys
74
75 if ( isOkForEnc() && isOkForDec() ) {
76 keys = std::make_pair(getPrivKey(), getPubKey());
77 }
78 return keys;
79 }
virtual void genKeyPairInternal()
virtual std::string getPrivKey() const
Get private key.
virtual std::string getPubKey() const
Get public key.

◆ genKeyPairInternal()

void xAOD::SimpleEncrypter::genKeyPairInternal ( )
privatevirtual

Definition at line 193 of file SimpleEncrypter.cxx.

193 {
194
195 // Generate prime numbers p != q
196 ULLI_t p(1);
197 ULLI_t q(1);
198 // Euler's phi function
199 ULLI_t phi(1);
200
201 // reset encryption and decryption exponent
202 m_e = 0;
203 m_d = 0;
204 while ( p == q || m_e < 2 || m_e >= phi || m_d < 2
205 || m_e*m_d % phi != 1 ) {
206 double dlog2 = 0.;
207 while ( p == q || dlog2 < 0.1 || dlog2 > 30. ) {
208 p = genPrime();
209 q = genPrime();
210 dlog2 = fabs(log2(p)-log2(q));
211 } // inner while loop
212 phi = (p-1)*(q-1);
213 m_n = p*q;
214 m_e = genCoprime(phi);
216 } // outer while loop
217 m_isOkForDec = false;
218 m_isOkForEnc = false;
219 }
virtual ULLI_t genCoprime(ULLI_t n) const
Find a coprime number.
virtual ULLI_t genPrime() const
Find a prime number.
virtual ULLI_t genDecryptionExponent(ULLI_t phi, ULLI_t e) const
Find decryption exponent.

◆ genPrime()

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

Find a prime number.

Definition at line 223 of file SimpleEncrypter.cxx.

223 {
224 //coverity[dont_call]
225 ULLI_t t = (m_MINRANGE + rand()) % (m_MAXRANGE-1);
226 do {
227 t++;
228 } while ( !isPrime(t) || t < m_MINRANGE );
229 return t;
230 }
static const ULLI_t m_MINRANGE
virtual bool isPrime(ULLI_t n) const
Check for being a prime number.

◆ getPrivKey()

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

Get private key.

Returns
hex string with private key

Definition at line 110 of file SimpleEncrypter.cxx.

110 {
111
112 return keyToString(m_n, m_d);
113 }
virtual std::string keyToString(ULLI_t a, ULLI_t b) const

◆ getPubKey()

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

Get public key.

Returns
hex string with public key

Definition at line 117 of file SimpleEncrypter.cxx.

117 {
118
119 return keyToString(m_e, m_n);
120 }

◆ greatestCommonDenominator()

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

Find greatest common denominator.

Definition at line 251 of file SimpleEncrypter.cxx.

251 {
252
253 std::vector<LLI_t> r;
254 LLI_t i = 1;
255 r.push_back(std::max(n1, n2));
256 r.push_back(std::min(n1, n2));
257 while (r[i] != 0) {
258 ++i;
259 r.push_back(r[i-2] % r[i-1]);
260 }
261 return r[i-1];
262 }
long long int LLI_t
Useful typedefs.

◆ 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 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ intBitsToFloat()

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

Interpret bits of integer as floating point number.

Definition at line 358 of file SimpleEncrypter.cxx.

358 {
359 static_assert(sizeof(float) == sizeof(std::uint32_t),"This code assumes a 32-bit float");
360 if (val > std::numeric_limits<std::uint32_t>::max()) {
361 ATH_MSG_WARNING("Value does not fit in float bit representation: "<< val);
362 return 0.0F;
363 }
364 return std::bit_cast<float>(static_cast<std::uint32_t>(val));
365 }

◆ isOkForDec()

bool xAOD::SimpleEncrypter::isOkForDec ( )
private

Check setup readiness for decryption.

Definition at line 464 of file SimpleEncrypter.cxx.

464 {
465
466 if ( !m_isOkForDec ) {
467 if ( m_n > 0 && m_d > 1 && m_d < m_n ) {
468 m_isOkForDec = true;
469 } else {
470 ATH_MSG_ERROR("Setup not OK for decryption: private key set?");
471 }
472 } // if ! m_isOkForDec
473
474 return m_isOkForDec;
475 }

◆ isOkForEnc()

bool xAOD::SimpleEncrypter::isOkForEnc ( )
private

Check setup readiness for encryption.

Definition at line 448 of file SimpleEncrypter.cxx.

448 {
449
450 if ( !m_isOkForEnc ) {
451 if ( m_n > 0 && m_e > 1 && m_e < m_n ) {
452 m_isOkForEnc = true;
453 } else {
454 ATH_MSG_ERROR("Setup not OK for encryption: public key set?");
455 }
456 } // if ! m_isOkForEnc
457
458 return m_isOkForEnc;
459 }

◆ isPrime()

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

Check for being a prime number.

Definition at line 234 of file SimpleEncrypter.cxx.

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

◆ keyToString()

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

Definition at line 292 of file SimpleEncrypter.cxx.

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

◆ 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
51 return ::AthMessaging::msg();
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
59 return ::AthMessaging::msg( lvl );
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 422 of file SimpleEncrypter.cxx.

422 {
423
424 int bin[sizeof(ULLI_t)*CHAR_BIT];
425 ULLI_t dec[sizeof(ULLI_t)*CHAR_BIT];
426
427 ULLI_t r = (ULLI_t)(std::log2(d))+1;
428 ULLI_t tmp = d;
429 // decompose exponent into binary number (reverse order!)
430 for (ULLI_t i=0; i < r; ++i) {
431 bin[r-i-1] = tmp % 2;
432 tmp = (LLI_t)(tmp/2);
433 } // for i
434
435 // perform the exponentiation taking modulus into account
436 dec[0] = a;
437 for (ULLI_t i=1; i < r; ++i) {
438 ULLI_t d2 = dec[i-1]*dec[i-1] % n;
439 if ( bin[i] > 0 ) d2 *= a;
440 dec[i] = d2 % n;
441 } // for i
442
443 return dec[r-1];
444 }

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

84 {
85
86 std::pair<ULLI_t, ULLI_t> keys = decodeKeyString(std::move(keystr));
87
88 if ( m_n > 0 && m_n != keys.first ) {
89 ATH_MSG_WARNING("RSA module already set!");
90 }
91 m_n = keys.first;
92 m_d = keys.second;
93 m_isOkForDec = false;
94 }
virtual std::pair< ULLI_t, ULLI_t > decodeKeyString(std::string str) const
Decode hex string to two integers.

◆ setPubKey()

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

Set public key.

Parameters
[in]hexstring with public key

Definition at line 98 of file SimpleEncrypter.cxx.

98 {
99 std::pair<ULLI_t, ULLI_t> keys = decodeKeyString(std::move(keystr));
100 if ( m_n > 0 && m_n != keys.second ) {
101 ATH_MSG_WARNING("RSA module already set!");
102 }
103 m_e = keys.first;
104 m_n = keys.second;
105 m_isOkForEnc = false;
106 }

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.

135{ nullptr };

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

138{ MSG::NIL };

◆ 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:
=
(SimpleEncrypter::ULLI_t)pow(static_cast<double>(std::numeric_limits<ULLI_t>::max()), 0.25)

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: