CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
cond::Cipher Class Reference

#include <Cipher.h>

Public Member Functions

std::string b64decrypt (const std::string &input)
 
std::string b64encrypt (const std::string &input)
 
 Cipher (const std::string &key)
 
std::string decrypt (const unsigned char *input, size_t inputSize)
 
size_t encrypt (const std::string &input, unsigned char *&output)
 
 ~Cipher ()
 

Private Member Functions

size_t bf_process_alloc (const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
 

Private Attributes

BLOWFISH_CTXm_ctx
 

Detailed Description

Definition at line 11 of file Cipher.h.

Constructor & Destructor Documentation

cond::Cipher::Cipher ( const std::string &  key)
explicit

Definition at line 9 of file Cipher.cc.

References Blowfish_Init(), gen::k, and m_ctx.

9  :
10  m_ctx(new BLOWFISH_CTX){
11  char* k = const_cast<char*>(key.c_str());
12  Blowfish_Init( m_ctx, reinterpret_cast<unsigned char*>(k), key.size());
13 }
BLOWFISH_CTX * m_ctx
Definition: Cipher.h:32
void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen)
Definition: blowfish.cc:355
int k[5][pyjets_maxn]
list key
Definition: combine.py:13
cond::Cipher::~Cipher ( )

Definition at line 15 of file Cipher.cc.

15  {
16  delete m_ctx;
17 }
BLOWFISH_CTX * m_ctx
Definition: Cipher.h:32

Member Function Documentation

std::string cond::Cipher::b64decrypt ( const std::string &  input)

Definition at line 91 of file Cipher.cc.

References base64_decode_alloc, LaserDQM_cfg::input, run_regression::ret, and cond::throwException().

Referenced by cond::CredentialStore::exportAll(), cond::CredentialStore::importForPrincipal(), cond::CredentialStore::listConnections(), cond::CredentialStore::selectForUser(), cond::CredentialStore::setPermission(), cond::CredentialStore::startSession(), cond::CredentialStore::updateConnection(), and cond::CredentialStore::updatePrincipal().

91  {
92  char* input = 0;
93  size_t inputSize = 0;
94  if( !base64_decode_alloc( b64in.c_str(), b64in.size(), &input, &inputSize ) ){
95  throwException("Input provided is not a valid base64 string.","Cipher::b64decrypt");
96  }
97  std::string ret = decrypt( reinterpret_cast<const unsigned char*>(input), inputSize );
98  free (input);
99  return ret;
100 }
std::string decrypt(const unsigned char *input, size_t inputSize)
Definition: Cipher.cc:66
#define base64_decode_alloc(in, inlen, out, outlen)
Definition: base64.h:60
void throwException(std::string const &message, std::string const &methodName)
Definition: Exception.cc:17
std::string cond::Cipher::b64encrypt ( const std::string &  input)

Definition at line 80 of file Cipher.cc.

References base64_encode_alloc(), funct::false, dbtoconf::out, and run_regression::ret.

Referenced by cond::CredentialStore::addUser(), cond::CredentialStore::installAdmin(), cond::CredentialStore::setPermission(), cond::CredentialStore::updateConnection(), and cond::CredentialStore::updatePrincipal().

80  {
81  unsigned char* out = 0;
82  size_t outSize = bf_process_alloc( reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), out, false );
83  char* b64out = 0;
84  size_t b64size = base64_encode_alloc( reinterpret_cast<const char*>(out), outSize, &b64out );
85  std::string ret( b64out, b64size );
86  free (out);
87  free (b64out);
88  return ret;
89 }
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
Definition: Cipher.cc:19
size_t base64_encode_alloc(const char *in, size_t inlen, char **out)
Definition: base64.cc:117
tuple out
Definition: dbtoconf.py:99
size_t cond::Cipher::bf_process_alloc ( const unsigned char *  input,
size_t  input_size,
unsigned char *&  output,
bool  decrypt = false 
)
private

Definition at line 19 of file Cipher.cc.

References Blowfish_Decrypt(), Blowfish_Encrypt(), i, j, dttmaxenums::L, and dttmaxenums::R.

22  {
23  uInt32 L, R;
24  unsigned int j = sizeof(uInt32);
25 
26  unsigned int output_size=0;
27  for ( unsigned int i=0; i < input_size; i+=(j*2)){
28  output_size = i+2*j;
29  }
30  output = (unsigned char*) malloc( output_size );
31  memset(output, 0, output_size);
32 
33  for (unsigned int i=0; i < input_size; i+=(j*2)) {
34  L = R = 0;
35  unsigned int nl = 0;
36  unsigned int nr = 0;
37  if( input_size > i+j ){
38  nl = j;
39  if( input_size > i+2*j ){
40  nr = j;
41  } else {
42  nr = input_size-i-j;
43  }
44  } else {
45  nl = input_size-i;
46  nr = 0;
47  }
48  if(nl) memcpy(&L, input+i, nl);
49  if(nr) memcpy(&R, input+i+j, nr);
50  if( !decrypt ){
51  Blowfish_Encrypt(m_ctx, &L, &R);
52  } else {
53  Blowfish_Decrypt(m_ctx, &L, &R);
54  }
55  memcpy(output+i, &L, j);
56  memcpy(output+i+j, &R, j);
57  }
58 
59  return output_size;
60 }
int i
Definition: DBlmapReader.cc:9
BLOWFISH_CTX * m_ctx
Definition: Cipher.h:32
void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
Definition: blowfish.cc:299
void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
Definition: blowfish.cc:326
unsigned int uInt32
Definition: blowfish.h:26
std::string decrypt(const unsigned char *input, size_t inputSize)
Definition: Cipher.cc:66
int j
Definition: DBlmapReader.cc:9
std::string cond::Cipher::decrypt ( const unsigned char *  input,
size_t  inputSize 
)

Definition at line 66 of file Cipher.cc.

References dbtoconf::out, and run_regression::ret.

Referenced by cond::DecodingKey::init().

66  {
67  unsigned char* out = 0;
68  size_t outSize = bf_process_alloc( input, inputSize, out, true );
69  char* sout = reinterpret_cast<char*>(out);
70  // the output can still contain one or more \0 chars...
71  size_t soutSize = strlen( sout );
72  if( soutSize < outSize ){
73  outSize = soutSize;
74  }
75  std::string ret( sout, outSize );
76  free (out );
77  return ret;
78 }
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
Definition: Cipher.cc:19
tuple out
Definition: dbtoconf.py:99
size_t cond::Cipher::encrypt ( const std::string &  input,
unsigned char *&  output 
)

Definition at line 62 of file Cipher.cc.

References funct::false, and convertSQLitetoXML_cfg::output.

Referenced by cond::DecodingKey::flush().

62  {
63  return bf_process_alloc( reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), output, false );;
64 }
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
Definition: Cipher.cc:19

Member Data Documentation

BLOWFISH_CTX* cond::Cipher::m_ctx
private

Definition at line 32 of file Cipher.h.

Referenced by Cipher().