mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
crypt.c: protoize
* missing/crypt.c: protoize function definitions and make always-zero functions void. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f4b4a19eb2
commit
4cec7e8e35
1 changed files with 30 additions and 54 deletions
|
@ -108,16 +108,13 @@ static char sccsid[] = "@(#)crypt.c 8.1 (Berkeley) 6/4/93";
|
||||||
#define LARGEDATA
|
#define LARGEDATA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int des_setkey(), des_cipher();
|
void des_setkey(const char *key);
|
||||||
|
void des_cipher(const char *in, char *out, long salt, int num_iter);
|
||||||
|
|
||||||
/* compile with "-DSTATIC=int" when profiling */
|
/* compile with "-DSTATIC=int" when profiling */
|
||||||
#ifndef STATIC
|
#ifndef STATIC
|
||||||
#define STATIC static
|
#define STATIC static
|
||||||
#endif
|
#endif
|
||||||
STATIC void init_des(), init_perm(), permute();
|
|
||||||
#ifdef DEBUG
|
|
||||||
STATIC void prtab();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ==================================== */
|
/* ==================================== */
|
||||||
|
|
||||||
|
@ -303,11 +300,7 @@ typedef union {
|
||||||
{ C_block tblk; permute((cpp),&tblk,(p),4); LOAD ((d),(d0),(d1),tblk); }
|
{ C_block tblk; permute((cpp),&tblk,(p),4); LOAD ((d),(d0),(d1),tblk); }
|
||||||
|
|
||||||
STATIC void
|
STATIC void
|
||||||
permute(cp, out, p, chars_in)
|
permute(unsigned char *cp, C_block *out, register C_block *p, int chars_in)
|
||||||
unsigned char *cp;
|
|
||||||
C_block *out;
|
|
||||||
register C_block *p;
|
|
||||||
int chars_in;
|
|
||||||
{
|
{
|
||||||
register DCL_BLOCK(D,D0,D1);
|
register DCL_BLOCK(D,D0,D1);
|
||||||
register C_block *tp;
|
register C_block *tp;
|
||||||
|
@ -323,6 +316,12 @@ permute(cp, out, p, chars_in)
|
||||||
}
|
}
|
||||||
#endif /* LARGEDATA */
|
#endif /* LARGEDATA */
|
||||||
|
|
||||||
|
STATIC void init_des(void);
|
||||||
|
STATIC void init_perm(C_block perm[64/CHUNKBITS][1<<CHUNKBITS], unsigned char p[64], int chars_in, int chars_out);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
STATIC void prtab(const char *s, const unsigned char *t, int num_rows);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ===== (mostly) Standard DES Tables ==================== */
|
/* ===== (mostly) Standard DES Tables ==================== */
|
||||||
|
|
||||||
|
@ -497,9 +496,7 @@ static char cryptresult[1+4+4+11+1]; /* encrypted result */
|
||||||
* followed by an encryption produced by the "key" and "setting".
|
* followed by an encryption produced by the "key" and "setting".
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
crypt(key, setting)
|
crypt(const char *key, const char *setting)
|
||||||
register const char *key;
|
|
||||||
register const char *setting;
|
|
||||||
{
|
{
|
||||||
register char *encp;
|
register char *encp;
|
||||||
register long i;
|
register long i;
|
||||||
|
@ -513,8 +510,7 @@ crypt(key, setting)
|
||||||
key++;
|
key++;
|
||||||
keyblock.b[i] = t;
|
keyblock.b[i] = t;
|
||||||
}
|
}
|
||||||
if (des_setkey((char *)keyblock.b)) /* also initializes "a64toi" */
|
des_setkey((char *)keyblock.b); /* also initializes "a64toi" */
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
encp = &cryptresult[0];
|
encp = &cryptresult[0];
|
||||||
switch (*setting) {
|
switch (*setting) {
|
||||||
|
@ -523,16 +519,14 @@ crypt(key, setting)
|
||||||
* Involve the rest of the password 8 characters at a time.
|
* Involve the rest of the password 8 characters at a time.
|
||||||
*/
|
*/
|
||||||
while (*key) {
|
while (*key) {
|
||||||
if (des_cipher((char *)&keyblock,
|
des_cipher((char *)&keyblock,
|
||||||
(char *)&keyblock, 0L, 1))
|
(char *)&keyblock, 0L, 1);
|
||||||
return (NULL);
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
if ((t = 2*(unsigned char)(*key)) != 0)
|
if ((t = 2*(unsigned char)(*key)) != 0)
|
||||||
key++;
|
key++;
|
||||||
keyblock.b[i] ^= t;
|
keyblock.b[i] ^= t;
|
||||||
}
|
}
|
||||||
if (des_setkey((char *)keyblock.b))
|
des_setkey((char *)keyblock.b);
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*encp++ = *setting++;
|
*encp++ = *setting++;
|
||||||
|
@ -562,9 +556,8 @@ crypt(key, setting)
|
||||||
salt = (salt<<6) | a64toi[t];
|
salt = (salt<<6) | a64toi[t];
|
||||||
}
|
}
|
||||||
encp += salt_size;
|
encp += salt_size;
|
||||||
if (des_cipher((char *)&constdatablock, (char *)&rsltblock,
|
des_cipher((char *)&constdatablock, (char *)&rsltblock,
|
||||||
salt, num_iter))
|
salt, num_iter);
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encode the 64 cipher bits as 11 ascii characters.
|
* Encode the 64 cipher bits as 11 ascii characters.
|
||||||
|
@ -599,9 +592,8 @@ static C_block KS[KS_SIZE];
|
||||||
/*
|
/*
|
||||||
* Set up the key schedule from the key.
|
* Set up the key schedule from the key.
|
||||||
*/
|
*/
|
||||||
int
|
void
|
||||||
des_setkey(key)
|
des_setkey(const char *key)
|
||||||
register const char *key;
|
|
||||||
{
|
{
|
||||||
register DCL_BLOCK(K, K0, K1);
|
register DCL_BLOCK(K, K0, K1);
|
||||||
register C_block *ptabp;
|
register C_block *ptabp;
|
||||||
|
@ -623,7 +615,6 @@ des_setkey(key)
|
||||||
PERM6464(K,K0,K1,(unsigned char *)key,ptabp);
|
PERM6464(K,K0,K1,(unsigned char *)key,ptabp);
|
||||||
STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key);
|
STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key);
|
||||||
}
|
}
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -634,12 +625,8 @@ des_setkey(key)
|
||||||
* NOTE: the performance of this routine is critically dependent on your
|
* NOTE: the performance of this routine is critically dependent on your
|
||||||
* compiler and machine architecture.
|
* compiler and machine architecture.
|
||||||
*/
|
*/
|
||||||
int
|
void
|
||||||
des_cipher(in, out, salt, num_iter)
|
des_cipher(const char *in, char *out, long salt, int num_iter)
|
||||||
const char *in;
|
|
||||||
char *out;
|
|
||||||
long salt;
|
|
||||||
int num_iter;
|
|
||||||
{
|
{
|
||||||
/* variables that we want in registers, most important first */
|
/* variables that we want in registers, most important first */
|
||||||
#if defined(pdp11)
|
#if defined(pdp11)
|
||||||
|
@ -747,7 +734,6 @@ des_cipher(in, out, salt, num_iter)
|
||||||
#else
|
#else
|
||||||
STORE(L,L0,L1,*(C_block *)out);
|
STORE(L,L0,L1,*(C_block *)out);
|
||||||
#endif
|
#endif
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -756,7 +742,7 @@ des_cipher(in, out, salt, num_iter)
|
||||||
* done at compile time, if the compiler were capable of that sort of thing.
|
* done at compile time, if the compiler were capable of that sort of thing.
|
||||||
*/
|
*/
|
||||||
STATIC void
|
STATIC void
|
||||||
init_des()
|
init_des(void)
|
||||||
{
|
{
|
||||||
register int i, j;
|
register int i, j;
|
||||||
register long k;
|
register long k;
|
||||||
|
@ -900,10 +886,8 @@ init_des()
|
||||||
* "perm" must be all-zeroes on entry to this routine.
|
* "perm" must be all-zeroes on entry to this routine.
|
||||||
*/
|
*/
|
||||||
STATIC void
|
STATIC void
|
||||||
init_perm(perm, p, chars_in, chars_out)
|
init_perm(C_block perm[64/CHUNKBITS][1<<CHUNKBITS],
|
||||||
C_block perm[64/CHUNKBITS][1<<CHUNKBITS];
|
unsigned char p[64], int chars_in, int chars_out)
|
||||||
unsigned char p[64];
|
|
||||||
int chars_in, chars_out;
|
|
||||||
{
|
{
|
||||||
register int i, j, k, l;
|
register int i, j, k, l;
|
||||||
|
|
||||||
|
@ -923,9 +907,8 @@ init_perm(perm, p, chars_in, chars_out)
|
||||||
/*
|
/*
|
||||||
* "setkey" routine (for backwards compatibility)
|
* "setkey" routine (for backwards compatibility)
|
||||||
*/
|
*/
|
||||||
int
|
void
|
||||||
setkey(key)
|
setkey(const char *key)
|
||||||
register const char *key;
|
|
||||||
{
|
{
|
||||||
register int i, j, k;
|
register int i, j, k;
|
||||||
C_block keyblock;
|
C_block keyblock;
|
||||||
|
@ -938,16 +921,14 @@ setkey(key)
|
||||||
}
|
}
|
||||||
keyblock.b[i] = k;
|
keyblock.b[i] = k;
|
||||||
}
|
}
|
||||||
return (des_setkey((char *)keyblock.b));
|
des_setkey((char *)keyblock.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "encrypt" routine (for backwards compatibility)
|
* "encrypt" routine (for backwards compatibility)
|
||||||
*/
|
*/
|
||||||
int
|
void
|
||||||
encrypt(block, flag)
|
encrypt(char *block, int flag)
|
||||||
register char *block;
|
|
||||||
int flag;
|
|
||||||
{
|
{
|
||||||
register int i, j, k;
|
register int i, j, k;
|
||||||
C_block cblock;
|
C_block cblock;
|
||||||
|
@ -960,8 +941,7 @@ encrypt(block, flag)
|
||||||
}
|
}
|
||||||
cblock.b[i] = k;
|
cblock.b[i] = k;
|
||||||
}
|
}
|
||||||
if (des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1)))
|
des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1));
|
||||||
return (1);
|
|
||||||
for (i = 7; i >= 0; i--) {
|
for (i = 7; i >= 0; i--) {
|
||||||
k = cblock.b[i];
|
k = cblock.b[i];
|
||||||
for (j = 7; j >= 0; j--) {
|
for (j = 7; j >= 0; j--) {
|
||||||
|
@ -969,15 +949,11 @@ encrypt(block, flag)
|
||||||
k >>= 1;
|
k >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
STATIC void
|
STATIC void
|
||||||
prtab(s, t, num_rows)
|
prtab(const char *s, const unsigned char *t, int num_rows)
|
||||||
char *s;
|
|
||||||
unsigned char *t;
|
|
||||||
int num_rows;
|
|
||||||
{
|
{
|
||||||
register int i, j;
|
register int i, j;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue