PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
crypt.c File Reference
#include "c.h"
#include <limits.h>
#include <unistd.h>
Include dependency graph for crypt.c:

Go to the source code of this file.

Data Structures

union  C_block
 

Macros

#define STATIC   static void
 
#define _PASSWORD_EFMT1   '_' /* extended encryption format */
 
#define TO_SIX_BIT(rslt, src)
 
#define ZERO(d, d0, d1)   d0 = 0, d1 = 0
 
#define LOAD(d, d0, d1, bl)   d0 = (bl).b32.i0, d1 = (bl).b32.i1
 
#define LOADREG(d, d0, d1, s, s0, s1)   d0 = s0, d1 = s1
 
#define OR(d, d0, d1, bl)   d0 |= (bl).b32.i0, d1 |= (bl).b32.i1
 
#define STORE(s, s0, s1, bl)   (bl).b32.i0 = s0, (bl).b32.i1 = s1
 
#define DCL_BLOCK(d, d0, d1)   int32_t d0, d1
 
#define LGCHUNKBITS   2
 
#define CHUNKBITS   (1<<LGCHUNKBITS)
 
#define PERM6464(d, d0, d1, cpp, p)   { C_block tblk; permute(cpp,&tblk,p,8); LOAD (d,d0,d1,tblk); }
 
#define PERM3264(d, d0, d1, cpp, p)   { C_block tblk; permute(cpp,&tblk,p,4); LOAD (d,d0,d1,tblk); }
 
#define KS_SIZE   16
 
#define SALT   salt
 
#define SPTAB(t, i)   (*(int32_t *)((unsigned char *)(t) + (i)*(sizeof(int32_t)/4)))
 
#define DOXOR(x, y, i)   k=B.b[i]; x^=SPTAB(SPE[0][i],k); y^=SPTAB(SPE[1][i],k);
 
#define CRUNCH(p0, p1, q0, q1)
 

Typedefs

typedef int int32_t
 

Functions

static int des_setkey (const char *key)
 
static int des_cipher (const char *in, char *out, long salt, int num_iter)
 
STATIC init_des (void)
 
STATIC init_perm (C_block[64/CHUNKBITS][1<< CHUNKBITS], unsigned char[64], int, int)
 
STATIC permute (unsigned char *, C_block *, C_block *, int)
 
char * __md5crypt (const char *, const char *)
 
char * __bcrypt (const char *, const char *)
 
char * crypt (char *key, const char *setting) const
 
static int des_setkey (char *key) const
 
static int des_cipher (char *in, char *out, long salt, int num_iter) const
 
STATIC init_perm (perm, p, int chars_in, int chars_out)
 

Variables

static const unsigned char IP []
 
static const unsigned char ExpandTr []
 
static const unsigned char PC1 []
 
static const unsigned char Rotates []
 
static const unsigned char PC2 []
 
static const unsigned char S [8][64]
 
static const unsigned char P32Tr []
 
static const unsigned char CIFP []
 
static const unsigned char itoa64 []
 
static unsigned char a64toi [128]
 
static C_block PC1ROT [64/CHUNKBITS][1<< CHUNKBITS]
 
static C_block PC2ROT [2][64/CHUNKBITS][1<< CHUNKBITS]
 
static C_block IE3264 [32/CHUNKBITS][1<< CHUNKBITS]
 
static int32_t SPE [2][8][64]
 
static C_block CF6464 [64/CHUNKBITS][1<< CHUNKBITS]
 
static C_block constdatablock
 
static char cryptresult [1+4+4+11+1]
 
static C_block KS [KS_SIZE]
 
static volatile int des_ready = 0
 

Macro Definition Documentation

#define _PASSWORD_EFMT1   '_' /* extended encryption format */

Definition at line 112 of file crypt.c.

Referenced by crypt().

#define CHUNKBITS   (1<<LGCHUNKBITS)

Definition at line 285 of file crypt.c.

Referenced by init_perm(), and permute().

#define CRUNCH (   p0,
  p1,
  q0,
  q1 
)
Value:
k = ((q0) ^ (q1)) & SALT; \
B.b32.i0 = k ^ (q0) ^ kp->b32.i0; \
B.b32.i1 = k ^ (q1) ^ kp->b32.i1; \
kp = (C_block *)((char *)kp+ks_inc); \
DOXOR(p0, p1, 0); \
DOXOR(p0, p1, 1); \
DOXOR(p0, p1, 2); \
DOXOR(p0, p1, 3); \
DOXOR(p0, p1, 4); \
DOXOR(p0, p1, 5); \
DOXOR(p0, p1, 6); \
DOXOR(p0, p1, 7);
#define DOXOR(x, y, i)
#define SALT
Definition: crypt.c:228

Referenced by des_cipher().

#define DCL_BLOCK (   d,
  d0,
  d1 
)    int32_t d0, d1

Definition at line 262 of file crypt.c.

Referenced by des_setkey(), and permute().

#define DOXOR (   x,
  y,
  i 
)    k=B.b[i]; x^=SPTAB(SPE[0][i],k); y^=SPTAB(SPE[1][i],k);
#define KS_SIZE   16

Definition at line 624 of file crypt.c.

Referenced by des_cipher().

#define LGCHUNKBITS   2

Definition at line 284 of file crypt.c.

Referenced by init_perm().

#define LOAD (   d,
  d0,
  d1,
  bl 
)    d0 = (bl).b32.i0, d1 = (bl).b32.i1

Definition at line 258 of file crypt.c.

Referenced by des_cipher().

#define LOADREG (   d,
  d0,
  d1,
  s,
  s0,
  s1 
)    d0 = s0, d1 = s1

Definition at line 259 of file crypt.c.

Referenced by des_cipher().

#define OR (   d,
  d0,
  d1,
  bl 
)    d0 |= (bl).b32.i0, d1 |= (bl).b32.i1

Definition at line 260 of file crypt.c.

Referenced by permute().

#define PERM3264 (   d,
  d0,
  d1,
  cpp,
 
)    { C_block tblk; permute(cpp,&tblk,p,4); LOAD (d,d0,d1,tblk); }

Definition at line 288 of file crypt.c.

Referenced by des_cipher().

#define PERM6464 (   d,
  d0,
  d1,
  cpp,
 
)    { C_block tblk; permute(cpp,&tblk,p,8); LOAD (d,d0,d1,tblk); }

Definition at line 286 of file crypt.c.

Referenced by des_cipher(), and des_setkey().

#define SALT   salt
#define SPTAB (   t,
  i 
)    (*(int32_t *)((unsigned char *)(t) + (i)*(sizeof(int32_t)/4)))
#define STATIC   static void

Definition at line 101 of file crypt.c.

#define STORE (   s,
  s0,
  s1,
  bl 
)    (bl).b32.i0 = s0, (bl).b32.i1 = s1

Definition at line 261 of file crypt.c.

Referenced by des_cipher(), des_setkey(), and permute().

#define TO_SIX_BIT (   rslt,
  src 
)
Value:
{ \
C_block cvt; \
cvt.b[0] = src; src >>= 6; \
cvt.b[1] = src; src >>= 6; \
cvt.b[2] = src; src >>= 6; \
cvt.b[3] = src; \
rslt = (cvt.b32.i0 & 0x3f3f3f3fL) << 2; \
}

Definition at line 245 of file crypt.c.

Referenced by des_cipher(), and init_des().

#define ZERO (   d,
  d0,
  d1 
)    d0 = 0, d1 = 0

Definition at line 257 of file crypt.c.

Referenced by permute().

Typedef Documentation

Definition at line 108 of file crypt.c.

Function Documentation

char* __bcrypt ( const char *  ,
const char *   
)

Referenced by crypt().

char* __md5crypt ( const char *  ,
const char *   
)

Referenced by crypt().

char* crypt ( char *  key,
const char *  setting 
) const

Definition at line 492 of file crypt.c.

References __bcrypt(), __md5crypt(), _PASSWORD_EFMT1, a64toi, C_block::b, cryptresult, des_cipher(), des_setkey(), i, itoa64, and NULL.

495 {
496  char *encp;
497  int32_t i;
498  int t;
499  int32_t salt;
500  int num_iter,
501  salt_size;
502  C_block keyblock,
503  rsltblock;
504 
505 #if 0
506  /* Non-DES encryption schemes hook in here. */
507  if (setting[0] == _PASSWORD_NONDES)
508  {
509  switch (setting[1])
510  {
511  case '2':
512  return (__bcrypt(key, setting));
513  case '1':
514  default:
515  return (__md5crypt(key, setting));
516  }
517  }
518 #endif
519 
520  for (i = 0; i < 8; i++)
521  {
522  if ((t = 2 * (unsigned char) (*key)) != 0)
523  key++;
524  keyblock.b[i] = t;
525  }
526  if (des_setkey((char *) keyblock.b)) /* also initializes "a64toi" */
527  return (NULL);
528 
529  encp = &cryptresult[0];
530  switch (*setting)
531  {
532  case _PASSWORD_EFMT1:
533 
534  /*
535  * Involve the rest of the password 8 characters at a time.
536  */
537  while (*key)
538  {
539  if (des_cipher((char *) (void *) &keyblock,
540  (char *) (void *) &keyblock, 0L, 1))
541  return (NULL);
542  for (i = 0; i < 8; i++)
543  {
544  if ((t = 2 * (unsigned char) (*key)) != 0)
545  key++;
546  keyblock.b[i] ^= t;
547  }
548  if (des_setkey((char *) keyblock.b))
549  return (NULL);
550  }
551 
552  *encp++ = *setting++;
553 
554  /* get iteration count */
555  num_iter = 0;
556  for (i = 4; --i >= 0;)
557  {
558  if ((t = (unsigned char) setting[i]) == '\0')
559  t = '.';
560  encp[i] = t;
561  num_iter = (num_iter << 6) | a64toi[t];
562  }
563  setting += 4;
564  encp += 4;
565  salt_size = 4;
566  break;
567  default:
568  num_iter = 25;
569  salt_size = 2;
570  }
571 
572  salt = 0;
573  for (i = salt_size; --i >= 0;)
574  {
575  if ((t = (unsigned char) setting[i]) == '\0')
576  t = '.';
577  encp[i] = t;
578  salt = (salt << 6) | a64toi[t];
579  }
580  encp += salt_size;
581  if (des_cipher((char *) (void *) &constdatablock,
582  (char *) (void *) &rsltblock, salt, num_iter))
583  return (NULL);
584 
585  /*
586  * Encode the 64 cipher bits as 11 ascii characters.
587  */
588  i = ((int32_t) ((rsltblock.b[0] << 8) | rsltblock.b[1]) << 8) |
589  rsltblock.b[2];
590  encp[3] = itoa64[i & 0x3f];
591  i >>= 6;
592  encp[2] = itoa64[i & 0x3f];
593  i >>= 6;
594  encp[1] = itoa64[i & 0x3f];
595  i >>= 6;
596  encp[0] = itoa64[i];
597  encp += 4;
598  i = ((int32_t) ((rsltblock.b[3] << 8) | rsltblock.b[4]) << 8) |
599  rsltblock.b[5];
600  encp[3] = itoa64[i & 0x3f];
601  i >>= 6;
602  encp[2] = itoa64[i & 0x3f];
603  i >>= 6;
604  encp[1] = itoa64[i & 0x3f];
605  i >>= 6;
606  encp[0] = itoa64[i];
607  encp += 4;
608  i = ((int32_t) ((rsltblock.b[6]) << 8) | rsltblock.b[7]) << 2;
609  encp[2] = itoa64[i & 0x3f];
610  i >>= 6;
611  encp[1] = itoa64[i & 0x3f];
612  i >>= 6;
613  encp[0] = itoa64[i];
614 
615  encp[3] = 0;
616 
617  return (cryptresult);
618 }
static unsigned char a64toi[128]
Definition: crypt.c:459
static int des_setkey(const char *key)
static C_block constdatablock
Definition: crypt.c:480
static const unsigned char itoa64[]
Definition: crypt.c:452
#define _PASSWORD_EFMT1
Definition: crypt.c:112
char * __md5crypt(const char *, const char *)
char * __bcrypt(const char *, const char *)
#define NULL
Definition: c.h:229
int i
static int des_cipher(const char *in, char *out, long salt, int num_iter)
static char cryptresult[1+4+4+11+1]
Definition: crypt.c:481
int int32_t
Definition: crypt.c:108
unsigned char b[8]
Definition: crypt.c:230
Definition: crypt.c:228
static int des_cipher ( const char *  in,
char *  out,
long  salt,
int  num_iter 
)
static

Referenced by crypt().

static int des_cipher ( char *  in,
char *  out,
long  salt,
int  num_iter 
) const
static

Definition at line 666 of file crypt.c.

References C_block::b, CRUNCH, KS_SIZE, LOAD, LOADREG, PERM3264, PERM6464, R, STORE, and TO_SIX_BIT.

671 {
672  /* variables that we want in registers, most important first */
673 #if defined(pdp11)
674  int j;
675 #endif
676  int32_t L0,
677  L1,
678  R0,
679  R1,
680  k;
681  C_block *kp;
682  int ks_inc,
683  loop_count;
684  C_block B;
685 
686  L0 = salt;
687  TO_SIX_BIT(salt, L0); /* convert to 4*(6+2) format */
688 
689 #if defined(__vax__) || defined(pdp11)
690  salt = ~salt; /* "x &~ y" is faster than "x & y". */
691 #define SALT (~salt)
692 #else
693 #define SALT salt
694 #endif
695 
696 #if defined(MUST_ALIGN)
697  B.b[0] = in[0];
698  B.b[1] = in[1];
699  B.b[2] = in[2];
700  B.b[3] = in[3];
701  B.b[4] = in[4];
702  B.b[5] = in[5];
703  B.b[6] = in[6];
704  B.b[7] = in[7];
705  LOAD(L, L0, L1, B);
706 #else
707  LOAD(L, L0, L1, *(C_block *) in);
708 #endif
709  LOADREG(R, R0, R1, L, L0, L1);
710  L0 &= 0x55555555L;
711  L1 &= 0x55555555L;
712  L0 = (L0 << 1) | L1; /* L0 is the even-numbered input bits */
713  R0 &= 0xaaaaaaaaL;
714  R1 = (R1 >> 1) & 0x55555555L;
715  L1 = R0 | R1; /* L1 is the odd-numbered input bits */
716  STORE(L, L0, L1, B);
717  PERM3264(L, L0, L1, B.b, (C_block *) IE3264); /* even bits */
718  PERM3264(R, R0, R1, B.b + 4, (C_block *) IE3264); /* odd bits */
719 
720  if (num_iter >= 0)
721  { /* encryption */
722  kp = &KS[0];
723  ks_inc = sizeof(*kp);
724  }
725  else
726  { /* decryption */
727  num_iter = -num_iter;
728  kp = &KS[KS_SIZE - 1];
729  ks_inc = -(long) sizeof(*kp);
730  }
731 
732  while (--num_iter >= 0)
733  {
734  loop_count = 8;
735  do
736  {
737 
738 #define SPTAB(t, i) \
739  (*(int32_t *)((unsigned char *)(t) + (i)*(sizeof(int32_t)/4)))
740 #if defined(gould)
741  /* use this if B.b[i] is evaluated just once ... */
742 #define DOXOR(x,y,i) x^=SPTAB(SPE[0][i],B.b[i]); y^=SPTAB(SPE[1][i],B.b[i]);
743 #else
744 #if defined(pdp11)
745  /* use this if your "long" int indexing is slow */
746 #define DOXOR(x,y,i) j=B.b[i]; x^=SPTAB(SPE[0][i],j); y^=SPTAB(SPE[1][i],j);
747 #else
748  /* use this if "k" is allocated to a register ... */
749 #define DOXOR(x,y,i) k=B.b[i]; x^=SPTAB(SPE[0][i],k); y^=SPTAB(SPE[1][i],k);
750 #endif
751 #endif
752 
753 #define CRUNCH(p0, p1, q0, q1) \
754  k = ((q0) ^ (q1)) & SALT; \
755  B.b32.i0 = k ^ (q0) ^ kp->b32.i0; \
756  B.b32.i1 = k ^ (q1) ^ kp->b32.i1; \
757  kp = (C_block *)((char *)kp+ks_inc); \
758  \
759  DOXOR(p0, p1, 0); \
760  DOXOR(p0, p1, 1); \
761  DOXOR(p0, p1, 2); \
762  DOXOR(p0, p1, 3); \
763  DOXOR(p0, p1, 4); \
764  DOXOR(p0, p1, 5); \
765  DOXOR(p0, p1, 6); \
766  DOXOR(p0, p1, 7);
767 
768  CRUNCH(L0, L1, R0, R1);
769  CRUNCH(R0, R1, L0, L1);
770  } while (--loop_count != 0);
771  kp = (C_block *) ((char *) kp - (ks_inc * KS_SIZE));
772 
773 
774  /* swap L and R */
775  L0 ^= R0;
776  L1 ^= R1;
777  R0 ^= L0;
778  R1 ^= L1;
779  L0 ^= R0;
780  L1 ^= R1;
781  }
782 
783  /* store the encrypted (or decrypted) result */
784  L0 = ((L0 >> 3) & 0x0f0f0f0fL) | ((L1 << 1) & 0xf0f0f0f0L);
785  L1 = ((R0 >> 3) & 0x0f0f0f0fL) | ((R1 << 1) & 0xf0f0f0f0L);
786  STORE(L, L0, L1, B);
787  PERM6464(L, L0, L1, B.b, (C_block *) CF6464);
788 #if defined(MUST_ALIGN)
789  STORE(L, L0, L1, B);
790  out[0] = B.b[0];
791  out[1] = B.b[1];
792  out[2] = B.b[2];
793  out[3] = B.b[3];
794  out[4] = B.b[4];
795  out[5] = B.b[5];
796  out[6] = B.b[6];
797  out[7] = B.b[7];
798 #else
799  STORE(L, L0, L1, *(C_block *) out);
800 #endif
801  return (0);
802 }
#define R(b, x)
Definition: sha2.c:121
#define CRUNCH(p0, p1, q0, q1)
#define KS_SIZE
Definition: crypt.c:624
#define PERM3264(d, d0, d1, cpp, p)
Definition: crypt.c:288
static C_block KS[KS_SIZE]
Definition: crypt.c:625
#define LOADREG(d, d0, d1, s, s0, s1)
Definition: crypt.c:259
static C_block CF6464[64/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:474
#define TO_SIX_BIT(rslt, src)
Definition: crypt.c:245
#define PERM6464(d, d0, d1, cpp, p)
Definition: crypt.c:286
#define STORE(s, s0, s1, bl)
Definition: crypt.c:261
#define LOAD(d, d0, d1, bl)
Definition: crypt.c:258
int int32_t
Definition: crypt.c:108
static C_block IE3264[32/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:468
unsigned char b[8]
Definition: crypt.c:230
Definition: crypt.c:228
static int des_setkey ( const char *  key)
static

Referenced by crypt().

static int des_setkey ( char *  key) const
static

Definition at line 633 of file crypt.c.

References DCL_BLOCK, des_ready, i, init_des(), K, PERM6464, Rotates, and STORE.

635 {
636  DCL_BLOCK(K, K0, K1);
637  C_block *ptabp;
638  int i;
639 
640  if (!des_ready)
641  init_des();
642 
643  PERM6464(K, K0, K1, (unsigned char *) key, (C_block *) PC1ROT);
644  key = (char *) &KS[0];
645  STORE(K & ~0x03030303L, K0 & ~0x03030303L, K1, *(C_block *) key);
646  for (i = 1; i < 16; i++)
647  {
648  key += sizeof(C_block);
649  STORE(K, K0, K1, *(C_block *) key);
650  ptabp = (C_block *) PC2ROT[Rotates[i] - 1];
651  PERM6464(K, K0, K1, (unsigned char *) key, ptabp);
652  STORE(K & ~0x03030303L, K0 & ~0x03030303L, K1, *(C_block *) key);
653  }
654  return (0);
655 }
STATIC init_des(void)
Definition: crypt.c:810
static C_block KS[KS_SIZE]
Definition: crypt.c:625
static volatile int des_ready
Definition: crypt.c:627
#define DCL_BLOCK(d, d0, d1)
Definition: crypt.c:262
#define K(t)
Definition: sha1.c:48
#define PERM6464(d, d0, d1, cpp, p)
Definition: crypt.c:286
#define STORE(s, s0, s1, bl)
Definition: crypt.c:261
static C_block PC2ROT[2][64/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:465
int i
Definition: crypt.c:228
static C_block PC1ROT[64/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:462
static const unsigned char Rotates[]
Definition: crypt.c:369
STATIC init_des ( void  )

Definition at line 810 of file crypt.c.

References a64toi, CIFP, des_ready, ExpandTr, i, init_perm(), IP, itoa64, P32Tr, PC1, PC2, Rotates, S, SPE, and TO_SIX_BIT.

Referenced by des_setkey().

811 {
812  int i,
813  j;
814  int32_t k;
815  int tableno;
816  static unsigned char perm[64],
817  tmp32[32]; /* "static" for speed */
818 
819 /* static volatile long init_start = 0; not used */
820 
821  /*
822  * table that converts chars "./0-9A-Za-z"to integers 0-63.
823  */
824  for (i = 0; i < 64; i++)
825  a64toi[itoa64[i]] = i;
826 
827  /*
828  * PC1ROT - bit reverse, then PC1, then Rotate, then PC2.
829  */
830  for (i = 0; i < 64; i++)
831  perm[i] = 0;
832  for (i = 0; i < 64; i++)
833  {
834  if ((k = PC2[i]) == 0)
835  continue;
836  k += Rotates[0] - 1;
837  if ((k % 28) < Rotates[0])
838  k -= 28;
839  k = PC1[k];
840  if (k > 0)
841  {
842  k--;
843  k = (k | 07) - (k & 07);
844  k++;
845  }
846  perm[i] = k;
847  }
848 #ifdef DEBUG
849  prtab("pc1tab", perm, 8);
850 #endif
851  init_perm(PC1ROT, perm, 8, 8);
852 
853  /*
854  * PC2ROT - PC2 inverse, then Rotate (once or twice), then PC2.
855  */
856  for (j = 0; j < 2; j++)
857  {
858  unsigned char pc2inv[64];
859 
860  for (i = 0; i < 64; i++)
861  perm[i] = pc2inv[i] = 0;
862  for (i = 0; i < 64; i++)
863  {
864  if ((k = PC2[i]) == 0)
865  continue;
866  pc2inv[k - 1] = i + 1;
867  }
868  for (i = 0; i < 64; i++)
869  {
870  if ((k = PC2[i]) == 0)
871  continue;
872  k += j;
873  if ((k % 28) <= j)
874  k -= 28;
875  perm[i] = pc2inv[k];
876  }
877 #ifdef DEBUG
878  prtab("pc2tab", perm, 8);
879 #endif
880  init_perm(PC2ROT[j], perm, 8, 8);
881  }
882 
883  /*
884  * Bit reverse, then initial permutation, then expansion.
885  */
886  for (i = 0; i < 8; i++)
887  {
888  for (j = 0; j < 8; j++)
889  {
890  k = (j < 2) ? 0 : IP[ExpandTr[i * 6 + j - 2] - 1];
891  if (k > 32)
892  k -= 32;
893  else if (k > 0)
894  k--;
895  if (k > 0)
896  {
897  k--;
898  k = (k | 07) - (k & 07);
899  k++;
900  }
901  perm[i * 8 + j] = k;
902  }
903  }
904 #ifdef DEBUG
905  prtab("ietab", perm, 8);
906 #endif
907  init_perm(IE3264, perm, 4, 8);
908 
909  /*
910  * Compression, then final permutation, then bit reverse.
911  */
912  for (i = 0; i < 64; i++)
913  {
914  k = IP[CIFP[i] - 1];
915  if (k > 0)
916  {
917  k--;
918  k = (k | 07) - (k & 07);
919  k++;
920  }
921  perm[k - 1] = i + 1;
922  }
923 #ifdef DEBUG
924  prtab("cftab", perm, 8);
925 #endif
926  init_perm(CF6464, perm, 8, 8);
927 
928  /*
929  * SPE table
930  */
931  for (i = 0; i < 48; i++)
932  perm[i] = P32Tr[ExpandTr[i] - 1];
933  for (tableno = 0; tableno < 8; tableno++)
934  {
935  for (j = 0; j < 64; j++)
936  {
937  k = (((j >> 0) & 01) << 5) |
938  (((j >> 1) & 01) << 3) |
939  (((j >> 2) & 01) << 2) |
940  (((j >> 3) & 01) << 1) |
941  (((j >> 4) & 01) << 0) |
942  (((j >> 5) & 01) << 4);
943  k = S[tableno][k];
944  k = (((k >> 3) & 01) << 0) |
945  (((k >> 2) & 01) << 1) |
946  (((k >> 1) & 01) << 2) |
947  (((k >> 0) & 01) << 3);
948  for (i = 0; i < 32; i++)
949  tmp32[i] = 0;
950  for (i = 0; i < 4; i++)
951  tmp32[4 * tableno + i] = (k >> i) & 01;
952  k = 0;
953  for (i = 24; --i >= 0;)
954  k = (k << 1) | tmp32[perm[i] - 1];
955  TO_SIX_BIT(SPE[0][tableno][j], k);
956  k = 0;
957  for (i = 24; --i >= 0;)
958  k = (k << 1) | tmp32[perm[i + 24] - 1];
959  TO_SIX_BIT(SPE[1][tableno][j], k);
960  }
961  }
962 
963  des_ready = 1;
964 }
static const unsigned char S[8][64]
Definition: crypt.c:386
static const unsigned char CIFP[]
Definition: crypt.c:440
static unsigned char a64toi[128]
Definition: crypt.c:459
static C_block CF6464[64/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:474
#define TO_SIX_BIT(rslt, src)
Definition: crypt.c:245
static const unsigned char IP[]
Definition: crypt.c:333
static volatile int des_ready
Definition: crypt.c:627
static const unsigned char PC2[]
Definition: crypt.c:374
static const unsigned char ExpandTr[]
Definition: crypt.c:346
static const unsigned char itoa64[]
Definition: crypt.c:452
static C_block PC2ROT[2][64/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:465
static int32_t SPE[2][8][64]
Definition: crypt.c:471
static const unsigned char PC1[]
Definition: crypt.c:357
static const unsigned char P32Tr[]
Definition: crypt.c:429
int i
int int32_t
Definition: crypt.c:108
STATIC init_perm(C_block[64/CHUNKBITS][1<< CHUNKBITS], unsigned char[64], int, int)
static C_block IE3264[32/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:468
static C_block PC1ROT[64/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:462
static const unsigned char Rotates[]
Definition: crypt.c:369
STATIC init_perm ( C_block  [64/CHUNKBITS][1<< CHUNKBITS],
unsigned  char[64],
int  ,
int   
)

Referenced by init_des().

STATIC init_perm ( perm  ,
,
int  chars_in,
int  chars_out 
)

Definition at line 975 of file crypt.c.

References CHUNKBITS, i, and LGCHUNKBITS.

980 {
981  int i,
982  j,
983  k,
984  l;
985 
986  for (k = 0; k < chars_out * 8; k++)
987  { /* each output bit position */
988  l = p[k] - 1; /* where this bit comes from */
989  if (l < 0)
990  continue; /* output bit is always 0 */
991  i = l >> LGCHUNKBITS; /* which chunk this bit comes from */
992  l = 1 << (l & (CHUNKBITS - 1)); /* mask for this bit */
993  for (j = 0; j < (1 << CHUNKBITS); j++)
994  { /* each chunk value */
995  if ((j & l) != 0)
996  perm[i][j].b[k >> 3] |= 1 << (k & 07);
997  }
998  }
999 }
#define CHUNKBITS
Definition: crypt.c:285
#define LGCHUNKBITS
Definition: crypt.c:284
int i
STATIC permute ( unsigned char *  cp,
C_block out,
C_block p,
int  chars_in 
)

Definition at line 305 of file crypt.c.

References CHUNKBITS, DCL_BLOCK, OR, STORE, and ZERO.

310 {
311  DCL_BLOCK(D, D0, D1);
312  C_block *tp;
313  int t;
314 
315  ZERO(D, D0, D1);
316  do
317  {
318  t = *cp++;
319  tp = &p[t & 0xf];
320  OR(D, D0, D1, *tp);
321  p += (1 << CHUNKBITS);
322  tp = &p[t >> 4];
323  OR(D, D0, D1, *tp);
324  p += (1 << CHUNKBITS);
325  } while (--chars_in > 0);
326  STORE(D, D0, D1, *out);
327 }
#define CHUNKBITS
Definition: crypt.c:285
#define ZERO(d, d0, d1)
Definition: crypt.c:257
#define OR(d, d0, d1, bl)
Definition: crypt.c:260
#define DCL_BLOCK(d, d0, d1)
Definition: crypt.c:262
#define STORE(s, s0, s1, bl)
Definition: crypt.c:261
Definition: crypt.c:228

Variable Documentation

unsigned char a64toi[128]
static

Definition at line 459 of file crypt.c.

Referenced by crypt(), and init_des().

C_block CF6464[64/CHUNKBITS][1<< CHUNKBITS]
static

Definition at line 474 of file crypt.c.

const unsigned char CIFP[]
static
Initial value:
= {
1, 2, 3, 4, 17, 18, 19, 20,
5, 6, 7, 8, 21, 22, 23, 24,
9, 10, 11, 12, 25, 26, 27, 28,
13, 14, 15, 16, 29, 30, 31, 32,
33, 34, 35, 36, 49, 50, 51, 52,
37, 38, 39, 40, 53, 54, 55, 56,
41, 42, 43, 44, 57, 58, 59, 60,
45, 46, 47, 48, 61, 62, 63, 64,
}

Definition at line 440 of file crypt.c.

Referenced by init_des().

C_block constdatablock
static

Definition at line 480 of file crypt.c.

char cryptresult[1+4+4+11+1]
static

Definition at line 481 of file crypt.c.

Referenced by crypt().

volatile int des_ready = 0
static

Definition at line 627 of file crypt.c.

Referenced by des_setkey(), and init_des().

const unsigned char ExpandTr[]
static
Initial value:
= {
32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13,
12, 13, 14, 15, 16, 17,
16, 17, 18, 19, 20, 21,
20, 21, 22, 23, 24, 25,
24, 25, 26, 27, 28, 29,
28, 29, 30, 31, 32, 1,
}

Definition at line 346 of file crypt.c.

Referenced by init_des().

C_block IE3264[32/CHUNKBITS][1<< CHUNKBITS]
static

Definition at line 468 of file crypt.c.

const unsigned char IP[]
static
Initial value:
= {
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7,
}

Definition at line 333 of file crypt.c.

Referenced by init_des().

const unsigned char itoa64[]
static
Initial value:
=
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Definition at line 452 of file crypt.c.

Referenced by crypt(), and init_des().

C_block KS[KS_SIZE]
static

Definition at line 625 of file crypt.c.

const unsigned char P32Tr[]
static
Initial value:
= {
16, 7, 20, 21,
29, 12, 28, 17,
1, 15, 23, 26,
5, 18, 31, 10,
2, 8, 24, 14,
32, 27, 3, 9,
19, 13, 30, 6,
22, 11, 4, 25,
}

Definition at line 429 of file crypt.c.

Referenced by init_des().

const unsigned char PC1[]
static
Initial value:
= {
57, 49, 41, 33, 25, 17, 9,
1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27,
19, 11, 3, 60, 52, 44, 36,
63, 55, 47, 39, 31, 23, 15,
7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29,
21, 13, 5, 28, 20, 12, 4,
}

Definition at line 357 of file crypt.c.

Referenced by init_des().

C_block PC1ROT[64/CHUNKBITS][1<< CHUNKBITS]
static

Definition at line 462 of file crypt.c.

const unsigned char PC2[]
static
Initial value:
= {
9, 18, 14, 17, 11, 24, 1, 5,
22, 25, 3, 28, 15, 6, 21, 10,
35, 38, 23, 19, 12, 4, 26, 8,
43, 54, 16, 7, 27, 20, 13, 2,
0, 0, 41, 52, 31, 37, 47, 55,
0, 0, 30, 40, 51, 45, 33, 48,
0, 0, 44, 49, 39, 56, 34, 53,
0, 0, 46, 42, 50, 36, 29, 32,
}

Definition at line 374 of file crypt.c.

Referenced by init_des().

C_block PC2ROT[2][64/CHUNKBITS][1<< CHUNKBITS]
static

Definition at line 465 of file crypt.c.

const unsigned char Rotates[]
static
Initial value:
= {
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1,
}

Definition at line 369 of file crypt.c.

Referenced by des_setkey(), and init_des().

const unsigned char S[8][64]
static

Definition at line 386 of file crypt.c.

Referenced by init_des().

int32_t SPE[2][8][64]
static

Definition at line 471 of file crypt.c.

Referenced by init_des().