w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dpxcrypt.c File Reference
#include <string.h>
#include <stdlib.h>
#include "mem.h"
#include "error.h"
#include "numbers.h"
#include "dpxcrypt.h"
Include dependency graph for dpxcrypt.c:

Go to the source code of this file.

Classes

struct  AES_CONTEXT
 

Macros

#define rol(x, n)   ( ((x) << (n)) | ((x) >> (32-(n))) )
 
#define ror(x, n)   ( ((x) >> ((n)&(32-1))) | ((x) << ((32-(n))&(32-1))) )
 
#define FF(b, c, d)   (d ^ (b & (c ^ d)))
 
#define FG(b, c, d)   FF(d, b, c)
 
#define FH(b, c, d)   (b ^ c ^ d)
 
#define FI(b, c, d)   (c ^ (b | ~d))
 
#define OP(a, b, c, d, s, T)    do { a += FF(b, c, d) + (*cwp++) + T; a = rol(a, s); a += b; } while (0)
 
#define OP(f, a, b, c, d, k, s, T)    do { a += f(b, c, d) + correct_words[k] + T; a = rol(a, s); a += b; } while (0)
 
#define X(a)   do { *(uint32_t *)p = (*hd).a ; p += sizeof(uint32_t); } while (0)
 
#define le_bswap32(x)   ((uint32_t)(x))
 
#define be_bswap32(x)   _gcry_bswap32(x)
 
#define le_bswap64(x)   ((uint64_t)(x))
 
#define be_bswap64(x)   _gcry_bswap64(x)
 
#define S0(x)   (ror ((x), 7) ^ ror ((x), 18) ^ ((x) >> 3)) /* (4.6) */
 
#define S1(x)   (ror ((x), 17) ^ ror ((x), 19) ^ ((x) >> 10)) /* (4.7) */
 
#define R(a, b, c, d, e, f, g, h, k, w)
 
#define Cho(x, y, z)   ((z) ^ ((x) & ((y) ^ (z))))
 
#define Maj(x, y, z)   (((x) & (y)) | ((z) & ((x)|(y))))
 
#define Sum0(x)   (ror((x), 2) ^ ror((x), 13) ^ ror((x), 22))
 
#define Sum1(x)   (ror((x), 6) ^ ror((x), 11) ^ ror((x), 25))
 
#define X(a)   do { *(uint32_t*)p = be_bswap32(hd->h##a); p += 4; } while(0)
 
#define ROTR(x, n)   (((x) >> (n)) | ((x) << (64 - (n))))
 
#define Ch(x, y, z)   (((x) & (y)) ^ ( ~(x) & (z)))
 
#define Maj(x, y, z)   (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
 
#define Sum0(x)   (ROTR((x), 28) ^ ROTR((x), 34) ^ ROTR((x), 39))
 
#define Sum1(x)   (ROTR((x), 14) ^ ROTR((x), 18) ^ ROTR((x), 41))
 
#define U64_C(c)   (c ## UL)
 
#define S0(x)   (ROTR((x),1) ^ ROTR((x),8) ^ ((x)>>7))
 
#define S1(x)   (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6))
 
#define X(a)   do { *(uint64_t*)p = be_bswap64(hd->state.h##a) ; p += 8; } while (0)
 
#define KEYLENGTH(keybits)   ((keybits)/8)
 
#define RKLENGTH(keybits)   ((keybits)/8+28)
 
#define NROUNDS(keybits)   ((keybits)/32+6)
 
#define KEYBITS   256
 
#define FULL_UNROLL
 
#define GETU32(plaintext)
 
#define PUTU32(ciphertext, st)
 

Functions

static void _gcry_burn_stack (int bytes)
 
void MD5_init (MD5_CONTEXT *ctx)
 
static void transform (MD5_CONTEXT *ctx, const unsigned char *data)
 
void MD5_write (MD5_CONTEXT *hd, const unsigned char *inbuf, unsigned int inlen)
 
void MD5_final (unsigned char *outbuf, MD5_CONTEXT *hd)
 
static uint32_t _gcry_bswap32 (uint32_t x)
 
static uint64_t _gcry_bswap64 (uint64_t x)
 
static uint32_t buf_get_be32 (const void *_buf)
 
static void buf_put_be32 (void *_buf, uint32_t val)
 
static uint64_t buf_get_be64 (const void *_buf)
 
static void buf_put_be64 (void *_buf, uint64_t val)
 
void SHA256_init (SHA256_CONTEXT *hd)
 
static unsigned int _SHA256_transform (SHA256_CONTEXT *hd, const unsigned char *data)
 
void SHA256_write (SHA256_CONTEXT *hd, const unsigned char *inbuf, unsigned int inlen)
 
void SHA256_final (unsigned char *outbuf, SHA256_CONTEXT *hd)
 
void SHA512_init (SHA512_CONTEXT *ctx)
 
void SHA384_init (SHA512_CONTEXT *ctx)
 
static unsigned int __transform (SHA512_STATE *hd, const unsigned char *data)
 
static unsigned int _SHA512_transform (SHA512_CONTEXT *ctx, const unsigned char *data)
 
void SHA512_write (SHA512_CONTEXT *hd, const unsigned char *inbuf, unsigned int inlen)
 
void SHA512_final (unsigned char *outbuf, SHA512_CONTEXT *hd)
 
static void do_encrypt_stream (ARC4_CONTEXT *ctx, unsigned char *outbuf, const unsigned char *inbuf, unsigned int len)
 
void ARC4 (ARC4_CONTEXT *ctx, unsigned int len, const unsigned char *inbuf, unsigned char *outbuf)
 
static void do_arcfour_setkey (ARC4_CONTEXT *ctx, const unsigned char *key, unsigned int keylen)
 
void ARC4_set_key (ARC4_CONTEXT *ctx, unsigned int keylen, const unsigned char *key)
 
static int rijndaelSetupEncrypt (uint32_t *rk, const uint8_t *key, int keybits)
 
static void rijndaelEncrypt (const uint32_t *rk, int nrounds, const uint8_t plaintext[16], uint8_t ciphertext[16])
 
void AES_ecb_encrypt (const unsigned char *key, size_t key_len, const unsigned char *plain, size_t plain_len, unsigned char **cipher, size_t *cipher_len)
 
void AES_cbc_encrypt (const unsigned char *key, size_t key_len, const unsigned char *iv, int padding, const unsigned char *plain, size_t plain_len, unsigned char **cipher, size_t *cipher_len)
 

Variables

static const uint64_t k []
 
static const uint32_t Te0 [256]
 
static const uint32_t Te1 [256]
 
static const uint32_t Te2 [256]
 
static const uint32_t Te3 [256]
 
static const uint32_t Te4 [256]
 
static const uint32_t rcon []
 

Macro Definition Documentation

◆ be_bswap32

#define be_bswap32 (   x)    _gcry_bswap32(x)

Definition at line 343 of file dpxcrypt.c.

◆ be_bswap64

#define be_bswap64 (   x)    _gcry_bswap64(x)

Definition at line 345 of file dpxcrypt.c.

◆ Ch

#define Ch (   x,
  y,
  z 
)    (((x) & (y)) ^ ( ~(x) & (z)))

Definition at line 651 of file dpxcrypt.c.

◆ Cho

#define Cho (   x,
  y,
  z 
)    ((z) ^ ((x) & ((y) ^ (z))))

Definition at line 422 of file dpxcrypt.c.

◆ FF

#define FF (   b,
  c,
  d 
)    (d ^ (b & (c ^ d)))

Definition at line 91 of file dpxcrypt.c.

◆ FG

#define FG (   b,
  c,
  d 
)    FF(d, b, c)

Definition at line 92 of file dpxcrypt.c.

◆ FH

#define FH (   b,
  c,
  d 
)    (b ^ c ^ d)

Definition at line 93 of file dpxcrypt.c.

◆ FI

#define FI (   b,
  c,
  d 
)    (c ^ (b | ~d))

Definition at line 94 of file dpxcrypt.c.

◆ FULL_UNROLL

#define FULL_UNROLL

Definition at line 1312 of file dpxcrypt.c.

◆ GETU32

#define GETU32 (   plaintext)
Value:
(((uint32_t)(plaintext)[0] << 24) ^ \
((uint32_t)(plaintext)[1] << 16) ^ \
((uint32_t)(plaintext)[2] << 8) ^ \
((uint32_t)(plaintext)[3]))
unsigned int uint32_t
Definition: stdint.h:80
#define uint32_t
Definition: stdint.in.h:168

Definition at line 1662 of file dpxcrypt.c.

◆ KEYBITS

#define KEYBITS   256

Definition at line 1201 of file dpxcrypt.c.

◆ KEYLENGTH

#define KEYLENGTH (   keybits)    ((keybits)/8)

Definition at line 1197 of file dpxcrypt.c.

◆ le_bswap32

#define le_bswap32 (   x)    ((uint32_t)(x))

Definition at line 342 of file dpxcrypt.c.

◆ le_bswap64

#define le_bswap64 (   x)    ((uint64_t)(x))

Definition at line 344 of file dpxcrypt.c.

◆ Maj [1/2]

#define Maj (   x,
  y,
  z 
)    (((x) & (y)) | ((z) & ((x)|(y))))

Definition at line 652 of file dpxcrypt.c.

◆ Maj [2/2]

#define Maj (   x,
  y,
  z 
)    (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))

Definition at line 652 of file dpxcrypt.c.

◆ NROUNDS

#define NROUNDS (   keybits)    ((keybits)/32+6)

Definition at line 1199 of file dpxcrypt.c.

◆ OP [1/2]

#define OP (   a,
  b,
  c,
  d,
  s,
  T 
)     do { a += FF(b, c, d) + (*cwp++) + T; a = rol(a, s); a += b; } while (0)

◆ OP [2/2]

#define OP (   f,
  a,
  b,
  c,
  d,
  k,
  s,
  T 
)     do { a += f(b, c, d) + correct_words[k] + T; a = rol(a, s); a += b; } while (0)

◆ PUTU32

#define PUTU32 (   ciphertext,
  st 
)
Value:
{ (ciphertext)[0] = (uint8_t)((st) >> 24); \
(ciphertext)[1] = (uint8_t)((st) >> 16); \
(ciphertext)[2] = (uint8_t)((st) >> 8); \
(ciphertext)[3] = (uint8_t)(st); }
unsigned char uint8_t
Definition: stdint.h:78
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst st

Definition at line 1667 of file dpxcrypt.c.

◆ R

#define R (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h,
  k,
  w 
)
Value:
do \
{ \
t1 = (h) + Sum1((e)) + Cho((e),(f),(g)) + (k) + (w); \
t2 = Sum0((a)) + Maj((a),(b),(c)); \
h = g; \
g = f; \
f = e; \
e = d + t1; \
d = c; \
c = b; \
b = a; \
a = t1 + t2; \
} while (0)
#define b
Definition: jpegint.h:372
int w
Definition: dviconv.c:26
int h
Definition: dviconv.c:9
mpz_t * f
Definition: gen-fib.c:34
#define c(n)
Definition: gpos-common.c:150
#define a(n)
Definition: gpos-common.c:148
#define d(n)
Definition: gpos-common.c:151
#define t1
#define t2
int g
Definition: ppmqvga.c:68
#define Sum0(x)
Definition: dpxcrypt.c:653
#define Maj(x, y, z)
Definition: dpxcrypt.c:652
#define Sum1(x)
Definition: dpxcrypt.c:654
static const uint64_t k[]
Definition: dpxcrypt.c:694
#define Cho(x, y, z)
Definition: dpxcrypt.c:422
ShellFileEnvironment e
Definition: sh6.c:388

Definition at line 407 of file dpxcrypt.c.

◆ RKLENGTH

#define RKLENGTH (   keybits)    ((keybits)/8+28)

Definition at line 1198 of file dpxcrypt.c.

◆ rol

#define rol (   x,
  n 
)    ( ((x) << (n)) | ((x) >> (32-(n))) )

Definition at line 47 of file dpxcrypt.c.

◆ ror

#define ror (   x,
  n 
)    ( ((x) >> ((n)&(32-1))) | ((x) << ((32-(n))&(32-1))) )

Definition at line 48 of file dpxcrypt.c.

◆ ROTR

#define ROTR (   x,
  n 
)    (((x) >> (n)) | ((x) << (64 - (n))))

Definition at line 650 of file dpxcrypt.c.

◆ S0 [1/2]

#define S0 (   x)    (ror ((x), 7) ^ ror ((x), 18) ^ ((x) >> 3)) /* (4.6) */

Definition at line 405 of file dpxcrypt.c.

◆ S0 [2/2]

#define S0 (   x)    (ROTR((x),1) ^ ROTR((x),8) ^ ((x)>>7))

Definition at line 405 of file dpxcrypt.c.

◆ S1 [1/2]

#define S1 (   x)    (ror ((x), 17) ^ ror ((x), 19) ^ ((x) >> 10)) /* (4.7) */

Definition at line 406 of file dpxcrypt.c.

◆ S1 [2/2]

#define S1 (   x)    (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6))

Definition at line 406 of file dpxcrypt.c.

◆ Sum0 [1/2]

#define Sum0 (   x)    (ror((x), 2) ^ ror((x), 13) ^ ror((x), 22))

Definition at line 653 of file dpxcrypt.c.

◆ Sum0 [2/2]

#define Sum0 (   x)    (ROTR((x), 28) ^ ROTR((x), 34) ^ ROTR((x), 39))

Definition at line 653 of file dpxcrypt.c.

◆ Sum1 [1/2]

#define Sum1 (   x)    (ror((x), 6) ^ ror((x), 11) ^ ror((x), 25))

Definition at line 654 of file dpxcrypt.c.

◆ Sum1 [2/2]

#define Sum1 (   x)    (ROTR((x), 14) ^ ROTR((x), 18) ^ ROTR((x), 41))

Definition at line 654 of file dpxcrypt.c.

◆ U64_C

#define U64_C (   c)    (c ## UL)

Definition at line 655 of file dpxcrypt.c.

◆ X [1/3]

#define X (   a)    do { *(uint32_t *)p = (*hd).a ; p += sizeof(uint32_t); } while (0)

◆ X [2/3]

#define X (   a)    do { *(uint32_t*)p = be_bswap32(hd->h##a); p += 4; } while(0)

◆ X [3/3]

#define X (   a)    do { *(uint64_t*)p = be_bswap64(hd->state.h##a) ; p += 8; } while (0)

Function Documentation

◆ __transform()

static unsigned int __transform ( SHA512_STATE hd,
const unsigned char *  data 
)
static

Transform the message W which consists of 16 64-bit-words

Definition at line 742 of file dpxcrypt.c.

References a, b, buf_get_be64(), c, Ch, d, data, e, f, g, h, SHA512_STATE::h0, SHA512_STATE::h1, SHA512_STATE::h2, SHA512_STATE::h3, SHA512_STATE::h4, SHA512_STATE::h5, SHA512_STATE::h6, SHA512_STATE::h7, k, Maj, S0, S1, Sum0, Sum1, t, t1, t2, uint32_t, and w.

Referenced by _SHA512_transform().

◆ _gcry_bswap32()

static uint32_t _gcry_bswap32 ( uint32_t  x)
static

Definition at line 324 of file dpxcrypt.c.

References rol, ror, and cordic::x.

Referenced by _gcry_bswap64().

◆ _gcry_bswap64()

static uint64_t _gcry_bswap64 ( uint64_t  x)
static

Definition at line 330 of file dpxcrypt.c.

References _gcry_bswap32(), and cordic::x.

◆ _gcry_burn_stack()

static void _gcry_burn_stack ( int  bytes)
static

Definition at line 36 of file dpxcrypt.c.

References buf, bytes, and memset().

Referenced by ARC4(), ARC4_set_key(), MD5_final(), MD5_write(), SHA256_final(), SHA256_write(), SHA512_final(), and SHA512_write().

◆ _SHA256_transform()

static unsigned int _SHA256_transform ( SHA256_CONTEXT hd,
const unsigned char *  data 
)
static

◆ _SHA512_transform()

static unsigned int _SHA512_transform ( SHA512_CONTEXT ctx,
const unsigned char *  data 
)
static

Definition at line 1008 of file dpxcrypt.c.

References __transform(), data, and SHA512_CONTEXT::state.

Referenced by SHA512_final(), and SHA512_write().

◆ AES_cbc_encrypt()

void AES_cbc_encrypt ( const unsigned char *  key,
size_t  key_len,
const unsigned char *  iv,
int  padding,
const unsigned char *  plain,
size_t  plain_len,
unsigned char **  cipher,
size_t cipher_len 
)

◆ AES_ecb_encrypt()

void AES_ecb_encrypt ( const unsigned char *  key,
size_t  key_len,
const unsigned char *  plain,
size_t  plain_len,
unsigned char **  cipher,
size_t cipher_len 
)

◆ ARC4()

void ARC4 ( ARC4_CONTEXT ctx,
unsigned int  len,
const unsigned char *  inbuf,
unsigned char *  outbuf 
)

Definition at line 1161 of file dpxcrypt.c.

References _gcry_burn_stack(), do_encrypt_stream(), inbuf, len, and outbuf.

◆ ARC4_set_key()

void ARC4_set_key ( ARC4_CONTEXT ctx,
unsigned int  keylen,
const unsigned char *  key 
)

Definition at line 1185 of file dpxcrypt.c.

References _gcry_burn_stack(), do_arcfour_setkey(), and key.

◆ buf_get_be32()

static uint32_t buf_get_be32 ( const void _buf)
static

Definition at line 348 of file dpxcrypt.c.

References in, and uint32_t.

Referenced by _SHA256_transform().

◆ buf_get_be64()

static uint64_t buf_get_be64 ( const void _buf)
static

Definition at line 364 of file dpxcrypt.c.

References in, and uint64_t.

Referenced by __transform().

◆ buf_put_be32()

static void buf_put_be32 ( void _buf,
uint32_t  val 
)
static

Definition at line 355 of file dpxcrypt.c.

References out, and val.

Referenced by SHA256_final().

◆ buf_put_be64()

static void buf_put_be64 ( void _buf,
uint64_t  val 
)
static

Definition at line 373 of file dpxcrypt.c.

References out, and val.

Referenced by SHA512_final().

◆ do_arcfour_setkey()

static void do_arcfour_setkey ( ARC4_CONTEXT ctx,
const unsigned char *  key,
unsigned int  keylen 
)
static

Definition at line 1167 of file dpxcrypt.c.

References for(), i, ARC4_CONTEXT::idx_i, ARC4_CONTEXT::idx_j, j, key, memset(), ARC4_CONTEXT::sbox, and t.

Referenced by ARC4_set_key().

◆ do_encrypt_stream()

static void do_encrypt_stream ( ARC4_CONTEXT ctx,
unsigned char *  outbuf,
const unsigned char *  inbuf,
unsigned int  len 
)
static

Definition at line 1141 of file dpxcrypt.c.

References i, ARC4_CONTEXT::idx_i, ARC4_CONTEXT::idx_j, inbuf, j, len, outbuf, sbox, ARC4_CONTEXT::sbox, and t.

Referenced by ARC4().

◆ MD5_final()

void MD5_final ( unsigned char *  outbuf,
MD5_CONTEXT hd 
)

◆ MD5_init()

void MD5_init ( MD5_CONTEXT ctx)

◆ MD5_write()

void MD5_write ( MD5_CONTEXT hd,
const unsigned char *  inbuf,
unsigned int  inlen 
)

◆ rijndaelEncrypt()

void rijndaelEncrypt ( const uint32_t rk,
int  nrounds,
const uint8_t  plaintext[16],
uint8_t  ciphertext[16] 
)
static

Definition at line 1761 of file dpxcrypt.c.

References GETU32, PUTU32, r, s0, s1, s2, s3, t0, t1, t2, t3, Te0, Te1, Te2, Te3, and Te4.

Referenced by AES_cbc_encrypt(), and AES_ecb_encrypt().

◆ rijndaelSetupEncrypt()

int rijndaelSetupEncrypt ( uint32_t rk,
const uint8_t key,
int  keybits 
)
static

Expand the cipher key into the encryption key schedule.

Returns
the number of rounds for the given cipher key size.

Definition at line 1677 of file dpxcrypt.c.

References GETU32, i, key, rcon, Te4, and temp.

Referenced by AES_cbc_encrypt(), and AES_ecb_encrypt().

◆ SHA256_final()

void SHA256_final ( unsigned char *  outbuf,
SHA256_CONTEXT hd 
)

◆ SHA256_init()

◆ SHA256_write()

void SHA256_write ( SHA256_CONTEXT hd,
const unsigned char *  inbuf,
unsigned int  inlen 
)

◆ SHA384_init()

◆ SHA512_final()

void SHA512_final ( unsigned char *  outbuf,
SHA512_CONTEXT hd 
)

◆ SHA512_init()

◆ SHA512_write()

void SHA512_write ( SHA512_CONTEXT hd,
const unsigned char *  inbuf,
unsigned int  inlen 
)

◆ transform()

static void transform ( MD5_CONTEXT ctx,
const unsigned char *  data 
)
static

Definition at line 97 of file dpxcrypt.c.

References MD5_CONTEXT::A, A, B, MD5_CONTEXT::B, C, MD5_CONTEXT::C, MD5_CONTEXT::D, D, data, FG, FH, FI, i, memcpy, OP, p1, and p2.

Referenced by MD5_final(), and MD5_write().

Variable Documentation

◆ k

const uint64_t k[]
static

Definition at line 694 of file dpxcrypt.c.

Referenced by __transform().

◆ rcon

const uint32_t rcon[]
static
Initial value:
=
{
0x01000000, 0x02000000, 0x04000000, 0x08000000,
0x10000000, 0x20000000, 0x40000000, 0x80000000,
0x1B000000, 0x36000000,
}

Definition at line 1654 of file dpxcrypt.c.

Referenced by rijndaelSetupEncrypt().

◆ Te0

const uint32_t Te0[256]
static

Definition at line 1314 of file dpxcrypt.c.

Referenced by rijndaelEncrypt().

◆ Te1

const uint32_t Te1[256]
static

Definition at line 1382 of file dpxcrypt.c.

Referenced by rijndaelEncrypt().

◆ Te2

const uint32_t Te2[256]
static

Definition at line 1450 of file dpxcrypt.c.

Referenced by rijndaelEncrypt().

◆ Te3

const uint32_t Te3[256]
static

Definition at line 1518 of file dpxcrypt.c.

Referenced by rijndaelEncrypt().

◆ Te4

const uint32_t Te4[256]
static

Definition at line 1586 of file dpxcrypt.c.

Referenced by rijndaelEncrypt(), and rijndaelSetupEncrypt().