CMS 3D CMS Logo

Classes | Defines | Typedefs | Functions

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/CondCore/DBCommon/src/blowfish.h File Reference

Go to the source code of this file.

Classes

struct  BCoptions
struct  BLOWFISH_CTX

Defines

#define DECRYPT   1
#define ENCRYPT   0
#define endianBig   ((unsigned char) 0x45)
#define endianLittle   ((unsigned char) 0x54)
#define INCLUDE_BLOWFISH_DEFINE_H
#define MAXKEYBYTES   56
#define S_ISREG(x)   ( ((x)&S_IFMT)==S_IFREG )

Typedefs

typedef unsigned int uInt32

Functions

void Blowfish_Decrypt (BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
void Blowfish_Encrypt (BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
void Blowfish_Init (BLOWFISH_CTX *ctx, unsigned char *key, int keyLen)

Define Documentation

#define DECRYPT   1

Definition at line 21 of file blowfish.h.

#define ENCRYPT   0

Definition at line 20 of file blowfish.h.

#define endianBig   ((unsigned char) 0x45)

Definition at line 23 of file blowfish.h.

#define endianLittle   ((unsigned char) 0x54)

Definition at line 24 of file blowfish.h.

#define INCLUDE_BLOWFISH_DEFINE_H

Definition at line 9 of file blowfish.h.

#define MAXKEYBYTES   56

Definition at line 38 of file blowfish.h.

#define S_ISREG (   x)    ( ((x)&S_IFMT)==S_IFREG )

Definition at line 35 of file blowfish.h.


Typedef Documentation

typedef unsigned int uInt32

Definition at line 26 of file blowfish.h.


Function Documentation

void Blowfish_Decrypt ( BLOWFISH_CTX ctx,
uInt32 xl,
uInt32 xr 
)

Definition at line 326 of file blowfish.cc.

References F(), i, N, BLOWFISH_CTX::P, and groupFilesInBlocks::temp.

Referenced by cond::Cipher::bf_process_alloc().

     {
  uInt32  Xl;
  uInt32  Xr;
  uInt32  temp;
  short       i;

  Xl = *xl;
  Xr = *xr;

  for (i = N + 1; i > 1; --i) {
    Xl = Xl ^ ctx->P[i];
    Xr = F(ctx, Xl) ^ Xr;
    /* Exchange Xl and Xr */
    temp = Xl;
    Xl = Xr;
    Xr = temp;
  }

  /* Exchange Xl and Xr */
  temp = Xl;
  Xl = Xr;
  Xr = temp;
  Xr = Xr ^ ctx->P[1];
  Xl = Xl ^ ctx->P[0];
  *xl = Xl;
  *xr = Xr;
}
void Blowfish_Encrypt ( BLOWFISH_CTX ctx,
uInt32 xl,
uInt32 xr 
)

Definition at line 299 of file blowfish.cc.

References F(), i, N, BLOWFISH_CTX::P, and groupFilesInBlocks::temp.

Referenced by cond::Cipher::bf_process_alloc(), and Blowfish_Init().

     {
  uInt32  Xl;
  uInt32  Xr;
  uInt32  temp;
  short       i;

  Xl = *xl;
  Xr = *xr;

  for (i = 0; i < N; ++i) {
    Xl = Xl ^ ctx->P[i];
    Xr = F(ctx, Xl) ^ Xr;
    temp = Xl;
    Xl = Xr;
    Xr = temp;
  }

  temp = Xl;
  Xl = Xr;
  Xr = temp;
  Xr = Xr ^ ctx->P[N];
  Xl = Xl ^ ctx->P[N + 1];
  *xl = Xl;
  *xr = Xr;
}
void Blowfish_Init ( BLOWFISH_CTX ctx,
unsigned char *  key,
int  keyLen 
)

Definition at line 355 of file blowfish.cc.

References Blowfish_Encrypt(), data, i, j, gen::k, N, ORIG_P, ORIG_S, BLOWFISH_CTX::P, and BLOWFISH_CTX::S.

Referenced by cond::Cipher::Cipher().

                                                                      {
  int i, j, k;
  uInt32 data, datal, datar;

  for (i = 0; i < 4; i++) {

    for (j = 0; j < 256; j++)
      ctx->S[i][j] = ORIG_S[i][j];
  }

  j = 0;

  for (i = 0; i < N + 2; ++i) {
    data = 0x00000000;

    for (k = 0; k < 4; ++k) {
      data = (data << 8) | key[j];
      j = j + 1;
      if (j >= keyLen)
        j = 0;
    }

    ctx->P[i] = ORIG_P[i] ^ data;
  }

  datal = 0x00000000;
  datar = 0x00000000;

  for (i = 0; i < N + 2; i += 2) {
    Blowfish_Encrypt(ctx, &datal, &datar);
    ctx->P[i] = datal;
    ctx->P[i + 1] = datar;
  }

  for (i = 0; i < 4; ++i) {

    for (j = 0; j < 256; j += 2) {
      Blowfish_Encrypt(ctx, &datal, &datar);
      ctx->S[i][j] = datal;
      ctx->S[i][j + 1] = datar;
    }
  }
}