Back to index

glibc  2.9
Defines | Functions
des_crypt.c File Reference
#include <sys/types.h>
#include <rpc/des_crypt.h>
#include "des.h"

Go to the source code of this file.

Defines

#define COPY8(src, dst)
#define DESCOPY(src, dst, len)

Functions

int _des_crypt (char *, unsigned, struct desparams *)
static int common_crypt (char *key, char *buf, register unsigned len, unsigned mode, register struct desparams *desp)
int cbc_crypt (char *key, char *buf, unsigned int len, unsigned int mode, char *ivec)
 libc_hidden_def (cbc_crypt)

Define Documentation

#define COPY8 (   src,
  dst 
)
Value:
{ \
       register char *a = (char *) dst; \
       register char *b = (char *) src; \
       *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
       *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
}

Definition at line 46 of file des_crypt.c.

#define DESCOPY (   src,
  dst,
  len 
)
Value:
{ \
       register char *a = (char *) dst; \
       register char *b = (char *) src; \
       register int i; \
       for (i = (int) len; i > 0; i -= 8) { \
              *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
              *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
       } \
}

Definition at line 56 of file des_crypt.c.


Function Documentation

int _des_crypt ( char *  ,
unsigned  ,
struct desparams  
)

Definition at line 520 of file des_impl.c.

{
  unsigned long schedule[32];
  register unsigned long tin0, tin1;
  register unsigned long tout0, tout1, xor0, xor1;
  register unsigned char *in, *out;
  unsigned long tbuf[2];
  unsigned char *iv, *oiv;
  int cbc_mode;

  cbc_mode = (desp->des_mode == CBC) ? 1 : 0;

  in = (unsigned char *) buf;
  out = (unsigned char *) buf;
  oiv = iv = (unsigned char *) desp->des_ivec;

  des_set_key (desp->des_key, schedule);

  tin0 = tin1 = 0;          /* For GCC */
  if (desp->des_dir == ENCRYPT)
    {
      c2l (iv, tout0);
      c2l (iv, tout1);
      for (; len > 0; len -= 8)
       {
         c2l (in, tin0);
         c2l (in, tin1);
         if (cbc_mode)
           {
             tin0 ^= tout0;
             tin1 ^= tout1;
           }
         tbuf[0] = tin0;
         tbuf[1] = tin1;
         des_encrypt (tbuf, schedule, 1);
         tout0 = tbuf[0];
         tout1 = tbuf[1];
         l2c (tout0, out);
         l2c (tout1, out);
       }
      l2c (tout0, oiv);
      l2c (tout1, oiv);
    }
  else
    {
      c2l (iv, xor0);
      c2l (iv, xor1);
      for (; len > 0; len -= 8)
       {
         c2l (in, tin0);
         c2l (in, tin1);
         tbuf[0] = tin0;
         tbuf[1] = tin1;
         des_encrypt (tbuf, schedule, 0);
         if (cbc_mode)
           {
             tout0 = tbuf[0] ^ xor0;
             tout1 = tbuf[1] ^ xor1;
             xor0 = tin0;
             xor1 = tin1;
           }
         else
           {
             tout0 = tbuf[0];
             tout1 = tbuf[1];
           }
         l2c (tout0, out);
         l2c (tout1, out);
       }
      l2c (tin0, oiv);
      l2c (tin1, oiv);
    }
  tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
  tbuf[0] = tbuf[1] = 0;
  __bzero (schedule, sizeof (schedule));

  return (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cbc_crypt ( char *  key,
char *  buf,
unsigned int  len,
unsigned int  mode,
char *  ivec 
)

Definition at line 96 of file des_crypt.c.

{
  int err;
  struct desparams dp;

  dp.des_mode = CBC;
  COPY8 (ivec, dp.des_ivec);
  err = common_crypt (key, buf, len, mode, &dp);
  COPY8 (dp.des_ivec, ivec);
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int common_crypt ( char *  key,
char *  buf,
register unsigned  len,
unsigned  mode,
register struct desparams desp 
) [static]

Definition at line 70 of file des_crypt.c.

{
  register int desdev;

  if ((len % 8) != 0 || len > DES_MAXDATA)
    return DESERR_BADPARAM;

  desp->des_dir =
    ((mode & DES_DIRMASK) == DES_ENCRYPT) ? ENCRYPT : DECRYPT;

  desdev = mode & DES_DEVMASK;
  COPY8 (key, desp->des_key);
  /* 
   * software
   */
  if (!_des_crypt (buf, len, desp))
    return DESERR_HWERROR;

  return desdev == DES_SW ? DESERR_NONE : DESERR_NOHWDEVICE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 108 of file des_crypt.c.

{
  struct desparams dp;

  dp.des_mode = ECB;
  return common_crypt (key, buf, len, mode, &dp);
}

Here is the call graph for this function: