Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
Macros | Functions
crypt.c File Reference
#include "ruby/missing.h"
#include "crypt.h"
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "des_tables.c"

Go to the source code of this file.

Macros

#define _PASSWORD_EFMT1   '_'
 
#define numberof(array)   (int)(sizeof(array) / sizeof((array)[0]))
 
#define MUST_ALIGN
 
#define INIT_DES   0
 
#define INIT_DES   1
 
#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)   long d0, d1
 
#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 A64TOI1(c)
 
#define A64TOI4(base)   A64TOI1(base+0), A64TOI1(base+1), A64TOI1(base+2), A64TOI1(base+3)
 
#define A64TOI16(base)   A64TOI4(base+0), A64TOI4(base+4), A64TOI4(base+8), A64TOI4(base+12)
 
#define A64TOI64(base)   A64TOI16(base+0x00), A64TOI16(base+0x10), A64TOI16(base+0x20), A64TOI16(base+0x30)
 
#define KS   (data->KS)
 
#define cryptresult   (data->cryptresult)
 
#define SALT   salt
 
#define SPTAB(t, i)   (*(const unsigned long *)((const unsigned char *)(t) + (i)*(sizeof(long)/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)
 

Functions

STATIC void permute (const unsigned char *cp, C_block *out, register const C_block *p, int chars_in)
 
char * crypt_r (const char *key, const char *setting, struct crypt_data *data)
 
void setkey_r (const char *key, struct crypt_data *data)
 
void encrypt_r (char *block, int flag, struct crypt_data *data)
 

Macro Definition Documentation

◆ _PASSWORD_EFMT1

#define _PASSWORD_EFMT1   '_'

Definition at line 49 of file crypt.c.

◆ A64TOI1

#define A64TOI1 (   c)
Value:
((c) == '.' ? 0 : \
(c) == '/' ? 1 : \
('0' <= (c) && (c) <= '9') ? (c) - '0' + 2 : \
('A' <= (c) && (c) <= 'Z') ? (c) - 'A' + 12 : \
('a' <= (c) && (c) <= 'z') ? (c) - 'a' + 38 : \
0)

◆ A64TOI16

#define A64TOI16 (   base)    A64TOI4(base+0), A64TOI4(base+4), A64TOI4(base+8), A64TOI4(base+12)

◆ A64TOI4

#define A64TOI4 (   base)    A64TOI1(base+0), A64TOI1(base+1), A64TOI1(base+2), A64TOI1(base+3)

◆ A64TOI64

#define A64TOI64 (   base)    A64TOI16(base+0x00), A64TOI16(base+0x10), A64TOI16(base+0x20), A64TOI16(base+0x30)

◆ CRUNCH

#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 += 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 SALT

◆ cryptresult

#define cryptresult   (data->cryptresult)

Definition at line 370 of file crypt.c.

◆ DCL_BLOCK

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

Definition at line 127 of file crypt.c.

◆ DOXOR

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

◆ INIT_DES [1/2]

#define INIT_DES   0

Definition at line 102 of file crypt.c.

◆ INIT_DES [2/2]

#define INIT_DES   1

Definition at line 102 of file crypt.c.

◆ KS

#define KS   (data->KS)

Definition at line 369 of file crypt.c.

◆ LOAD

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

Definition at line 123 of file crypt.c.

◆ LOADREG

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

Definition at line 124 of file crypt.c.

◆ MUST_ALIGN

#define MUST_ALIGN

Definition at line 80 of file crypt.c.

◆ numberof

#define numberof (   array)    (int)(sizeof(array) / sizeof((array)[0]))

Definition at line 53 of file crypt.c.

◆ OR

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

Definition at line 125 of file crypt.c.

◆ PERM3264

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

Definition at line 149 of file crypt.c.

◆ PERM6464

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

Definition at line 147 of file crypt.c.

◆ SALT

#define SALT   salt

◆ SPTAB

#define SPTAB (   t,
 
)    (*(const unsigned long *)((const unsigned char *)(t) + (i)*(sizeof(long)/4)))

◆ STORE

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

Definition at line 126 of file crypt.c.

◆ TO_SIX_BIT

#define TO_SIX_BIT (   rslt,
  src 
)
Value:
{ \
C_block cvt; \
cvt.b[0] = (unsigned char)(src); (src) >>= 6; \
cvt.b[1] = (unsigned char)(src); (src) >>= 6; \
cvt.b[2] = (unsigned char)(src); (src) >>= 6; \
cvt.b[3] = (unsigned char)(src); \
(rslt) = (cvt.b32.i0 & 0x3f3f3f3fL) << 2; \
}
Definition: crypt.h:202
unsigned char b[8]
Definition: crypt.h:203
long i0
Definition: crypt.h:210
struct C_block::@124 b32

Definition at line 110 of file crypt.c.

◆ ZERO

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

Definition at line 122 of file crypt.c.

Function Documentation

◆ crypt_r()

char * crypt_r ( const char *  key,
const char *  setting,
struct crypt_data data 
)

Definition at line 396 of file crypt.c.

References _PASSWORD_EFMT1, C_block::b, cryptresult, key, L, long(), and t.

◆ encrypt_r()

void encrypt_r ( char *  block,
int  flag,
struct crypt_data data 
)

Definition at line 835 of file crypt.c.

References C_block::b, and L.

◆ permute()

STATIC void permute ( const unsigned char *  cp,
C_block out,
register const C_block p,
int  chars_in 
)

Definition at line 153 of file crypt.c.

References CHUNKBITS, D, DCL_BLOCK, OR, out, STORE, t, and ZERO.

◆ setkey_r()

void setkey_r ( const char *  key,
struct crypt_data data 
)

Definition at line 807 of file crypt.c.

References C_block::b, and key.