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 625 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 493 of file crypt.c.

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

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

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

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

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

636 {
637  DCL_BLOCK(K, K0, K1);
638  C_block *ptabp;
639  int i;
640 
641  if (!des_ready)
642  init_des();
643 
644  PERM6464(K, K0, K1, (unsigned char *) key, (C_block *) PC1ROT);
645  key = (char *) &KS[0];
646  STORE(K & ~0x03030303L, K0 & ~0x03030303L, K1, *(C_block *) key);
647  for (i = 1; i < 16; i++)
648  {
649  key += sizeof(C_block);
650  STORE(K, K0, K1, *(C_block *) key);
651  ptabp = (C_block *) PC2ROT[Rotates[i] - 1];
652  PERM6464(K, K0, K1, (unsigned char *) key, ptabp);
653  STORE(K & ~0x03030303L, K0 & ~0x03030303L, K1, *(C_block *) key);
654  }
655  return (0);
656 }
STATIC init_des(void)
Definition: crypt.c:811
static C_block KS[KS_SIZE]
Definition: crypt.c:626
static volatile int des_ready
Definition: crypt.c:628
#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:466
int i
Definition: crypt.c:228
static C_block PC1ROT[64/CHUNKBITS][1<< CHUNKBITS]
Definition: crypt.c:463
static const unsigned char Rotates[]
Definition: crypt.c:370
STATIC init_des ( void  )

Definition at line 811 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().

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

References CHUNKBITS, i, and LGCHUNKBITS.

982 {
983  int i,
984  j,
985  k,
986  l;
987 
988  for (k = 0; k < chars_out * 8; k++)
989  { /* each output bit position */
990  l = p[k] - 1; /* where this bit comes from */
991  if (l < 0)
992  continue; /* output bit is always 0 */
993  i = l >> LGCHUNKBITS; /* which chunk this bit comes from */
994  l = 1 << (l & (CHUNKBITS - 1)); /* mask for this bit */
995  for (j = 0; j < (1 << CHUNKBITS); j++)
996  { /* each chunk value */
997  if ((j & l) != 0)
998  perm[i][j].b[k >> 3] |= 1 << (k & 07);
999  }
1000  }
1001 }
#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.

311 {
312  DCL_BLOCK(D, D0, D1);
313  C_block *tp;
314  int t;
315 
316  ZERO(D, D0, D1);
317  do
318  {
319  t = *cp++;
320  tp = &p[t & 0xf];
321  OR(D, D0, D1, *tp);
322  p += (1 << CHUNKBITS);
323  tp = &p[t >> 4];
324  OR(D, D0, D1, *tp);
325  p += (1 << CHUNKBITS);
326  } while (--chars_in > 0);
327  STORE(D, D0, D1, *out);
328 }
#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 460 of file crypt.c.

Referenced by crypt(), and init_des().

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

Definition at line 475 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 441 of file crypt.c.

Referenced by init_des().

C_block constdatablock
static

Definition at line 481 of file crypt.c.

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

Definition at line 482 of file crypt.c.

Referenced by crypt().

volatile int des_ready = 0
static

Definition at line 628 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 347 of file crypt.c.

Referenced by init_des().

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

Definition at line 469 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 334 of file crypt.c.

Referenced by init_des().

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

Definition at line 453 of file crypt.c.

Referenced by crypt(), and init_des().

C_block KS[KS_SIZE]
static

Definition at line 626 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 430 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 358 of file crypt.c.

Referenced by init_des().

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

Definition at line 463 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 375 of file crypt.c.

Referenced by init_des().

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

Definition at line 466 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 370 of file crypt.c.

Referenced by des_setkey(), and init_des().

const unsigned char S[8][64]
static

Definition at line 387 of file crypt.c.

Referenced by init_des().

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

Definition at line 472 of file crypt.c.

Referenced by init_des().