ATLAS Offline Software
SimpleEncrypter.h
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
5 */
6 
14 #ifndef BPHYSTOOLS_SIMPLEENCRYPTER_H
15 #define BPHYSTOOLS_SIMPLEENCRYPTER_H
16 
17 // Framework includes
19 
20 // System includes
21 #include <string>
22 #include <set>
23 
24 namespace xAOD {
37 
38  public:
40  typedef long long int LLI_t;
41  typedef unsigned long long int ULLI_t;
42 
48  SimpleEncrypter(const std::string& name = "SimpleEncrypter");
49 
53  virtual ~SimpleEncrypter();
54 
60  virtual std::pair<std::string, std::string> genKeyPair();
61 
67  virtual void setPrivKey(std::string keystr);
68 
74  virtual void setPubKey(std::string keystr);
75 
81  virtual std::string getPrivKey() const;
82 
88  virtual std::string getPubKey() const;
89 
97  virtual ULLI_t encrypt(ULLI_t x);
98 
106  virtual ULLI_t decrypt(ULLI_t x);
107 
115  virtual float encrypt(float x);
116 
124  virtual float decrypt(float x);
125 
126 
127  private:
134  virtual void genKeyPairInternal();
138  virtual ULLI_t genPrime() const;
142  virtual bool isPrime(ULLI_t n) const;
146  virtual ULLI_t greatestCommonDenominator(ULLI_t n1, ULLI_t n2) const;
150  virtual ULLI_t genCoprime(ULLI_t n) const;
154  virtual ULLI_t genDecryptionExponent(ULLI_t phi, ULLI_t e) const;
163  virtual std::string keyToString(ULLI_t a, ULLI_t b) const;
167  virtual std::pair<ULLI_t, ULLI_t> decodeKeyString(std::string str) const;
175  virtual ULLI_t floatBitsToInt(float val) const;
179  virtual float intBitsToFloat(ULLI_t val) const;
191  ULLI_t decryptFPECycle(ULLI_t a) const;
203  ULLI_t powerMod(ULLI_t a, ULLI_t d, ULLI_t n) const;
207  bool isOkForEnc();
211  bool isOkForDec();
214 
215  private:
220  static const ULLI_t m_MAXRANGE;
221  static const ULLI_t m_MINRANGE;
223  static const unsigned int m_MAXHEXDIGITS;
224 
234 
238 
239  }; // class
240 
241 } // namespace xAOD
242 
243 #endif // BPHYSTOOLS_SIMPLEENCRYPTER_H
244 
xAOD::SimpleEncrypter::decryptFPECycle
ULLI_t decryptFPECycle(ULLI_t a) const
Decrypt using format preserving encryption w.r.t.
Definition: SimpleEncrypter.cxx:439
xAOD::SimpleEncrypter::genPrime
virtual ULLI_t genPrime() const
Find a prime number.
Definition: SimpleEncrypter.cxx:219
xAOD::SimpleEncrypter::SimpleEncrypter
SimpleEncrypter(const std::string &name="SimpleEncrypter")
Main constructor.
Definition: SimpleEncrypter.cxx:42
xAOD::SimpleEncrypter::m_n
ULLI_t m_n
Definition: SimpleEncrypter.h:229
xAOD::SimpleEncrypter::encrypt
virtual ULLI_t encrypt(ULLI_t x)
Encrypt a positive integer value.
Definition: SimpleEncrypter.cxx:120
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
hist_file_dump.d
d
Definition: hist_file_dump.py:137
xAOD::SimpleEncrypter::genDecryptionExponent
virtual ULLI_t genDecryptionExponent(ULLI_t phi, ULLI_t e) const
Find decryption exponent.
Definition: SimpleEncrypter.cxx:275
xAOD::SimpleEncrypter::setPubKey
virtual void setPubKey(std::string keystr)
Set public key.
Definition: SimpleEncrypter.cxx:92
xAOD::SimpleEncrypter::floatBitsToInt
virtual ULLI_t floatBitsToInt(float val) const
Definition: SimpleEncrypter.cxx:338
xAOD::SimpleEncrypter::genKeyPair
virtual std::pair< std::string, std::string > genKeyPair()
Generate private and public keys.
Definition: SimpleEncrypter.cxx:60
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::SimpleEncrypter::encryptFPECycle
ULLI_t encryptFPECycle(ULLI_t a) const
Definition: SimpleEncrypter.cxx:420
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
Provide simple asymmetric encryption for blinding of float values.
Definition: SimpleEncrypter.h:36
xAOD::SimpleEncrypter::isOkForEnc
bool isOkForEnc()
Check setup readiness for encryption.
Definition: SimpleEncrypter.cxx:498
xAOD::SimpleEncrypter::m_isOkForEnc
bool m_isOkForEnc
indicates that keys are set and range checks are ok
Definition: SimpleEncrypter.h:236
xAOD::SimpleEncrypter::setPrivKey
virtual void setPrivKey(std::string keystr)
Set private key.
Definition: SimpleEncrypter.cxx:78
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
AsgMessaging.h
xAOD::SimpleEncrypter::greatestCommonDenominator
virtual ULLI_t greatestCommonDenominator(ULLI_t n1, ULLI_t n2) const
Find greatest common denominator.
Definition: SimpleEncrypter.cxx:247
xAOD::SimpleEncrypter::~SimpleEncrypter
virtual ~SimpleEncrypter()
Default destructor.
Definition: SimpleEncrypter.cxx:53
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
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::decrypt
virtual ULLI_t decrypt(ULLI_t x)
Decrypt a positive integer value.
Definition: SimpleEncrypter.cxx:132
xAOD::SimpleEncrypter::encryptInternal
ULLI_t encryptInternal(ULLI_t x) const
Encrypt integer (internal)
Definition: SimpleEncrypter.cxx:457
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
str
Definition: BTagTrackIpAccessor.cxx:11
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
xAOD::SimpleEncrypter::getPubKey
virtual std::string getPubKey() const
Get public key.
Definition: SimpleEncrypter.cxx:113
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