Back to index

glibc  2.9
Functions | Variables
xcrypt.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <rpc/des_crypt.h>

Go to the source code of this file.

Functions

static char hexval (char)
void passwd2des (char *pw, char *key)
int xencrypt (char *secret, char *passwd)
int xdecrypt (char *secret, char *passwd)
static void internal_function hex2bin (int len, char *hexnum, char *binnum)
static void internal_function bin2hex (int len, unsigned char *binnum, char *hexnum)

Variables

static const char hex [16]

Function Documentation

static void internal_function bin2hex ( int  len,
unsigned char *  binnum,
char *  hexnum 
) [static]

Definition at line 183 of file xcrypt.c.

{
  int i;
  unsigned val;

  for (i = 0; i < len; i++)
    {
      val = binnum[i];
      hexnum[i * 2] = hex[val >> 4];
      hexnum[i * 2 + 1] = hex[val & 0xf];
    }
  hexnum[len * 2] = 0;
}

Here is the caller graph for this function:

static void internal_function hex2bin ( int  len,
char *  hexnum,
char *  binnum 
) [static]

Definition at line 170 of file xcrypt.c.

{
  int i;

  for (i = 0; i < len; i++)
    *binnum++ = 16 * hexval (hexnum[2 * i]) + hexval (hexnum[2 * i + 1]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char hexval ( char  c) [static]

Definition at line 67 of file xcrypt.c.

{
  int i;

  memset (key, 0, 8);
  for (i = 0; *pw && i < 8; ++i)
    key[i] ^= *pw++ << 1;

  des_setparity (key);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void passwd2des ( char *  pw,
char *  key 
)

Definition at line 96 of file xcrypt.c.

{
  return passwd2des_internal (pw, key);
}
int xdecrypt ( char *  secret,
char *  passwd 
)

Definition at line 139 of file xcrypt.c.

{
  char key[8];
  char ivec[8];
  char *buf;
  int err;
  int len;

  len = strlen (secret) / 2;
  buf = malloc ((unsigned) len);

  hex2bin (len, secret, buf);
  passwd2des_internal (passwd, key);
  memset (ivec, 0, 8);

  err = cbc_crypt (key, buf, len, DES_DECRYPT | DES_HW, ivec);
  if (DES_FAILED (err))
    {
      free (buf);
      return 0;
    }
  bin2hex (len, (unsigned char *) buf, secret);
  free (buf);
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int xencrypt ( char *  secret,
char *  passwd 
)

Definition at line 108 of file xcrypt.c.

{
  char key[8];
  char ivec[8];
  char *buf;
  int err;
  int len;

  len = strlen (secret) / 2;
  buf = malloc ((unsigned) len);
  hex2bin (len, secret, buf);
  passwd2des_internal (passwd, key);
  memset (ivec, 0, 8);

  err = cbc_crypt (key, buf, len, DES_ENCRYPT | DES_HW, ivec);
  if (DES_FAILED (err))
    {
      free (buf);
      return 0;
    }
  bin2hex (len, (unsigned char *) buf, secret);
  free (buf);
  return 1;
}

Here is the call graph for this function:


Variable Documentation

const char hex[16] [static]
Initial value:
{
  '0', '1', '2', '3', '4', '5', '6', '7',
  '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
}

Definition at line 53 of file xcrypt.c.