FFmpeg
Macros | Functions | Variables
des.c File Reference
#include <stdint.h>
#include "avutil.h"
#include "common.h"
#include "intreadwrite.h"
#include "mem.h"
#include "des.h"

Go to the source code of this file.

Macros

#define T(a, b, c, d, e, f, g, h)   64 - a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g, 64 - h
 
#define T(a, b, c, d, e, f, g)   64 - a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g
 
#define T(a, b, c, d, e, f)   56 - a, 56 - b, 56 - c, 56 - d, 56 - e, 56 - f
 

Functions

static uint64_t shuffle (uint64_t in, const uint8_t *shuffle, int shuffle_len)
 
static uint64_t shuffle_inv (uint64_t in, const uint8_t *shuffle, int shuffle_len)
 
static uint32_t f_func (uint32_t r, uint64_t k)
 
static uint64_t key_shift_left (uint64_t CDn)
 rotate the two halves of the expanded 56 bit key each 1 bit left More...
 
static void gen_roundkeys (uint64_t K[16], uint64_t key)
 
static uint64_t des_encdec (uint64_t in, uint64_t K[16], int decrypt)
 
AVDESav_des_alloc (void)
 Allocate an AVDES context. More...
 
int av_des_init (AVDES *d, const uint8_t *key, int key_bits, av_unused int decrypt)
 
static void av_des_crypt_mac (AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt, int mac)
 
void av_des_crypt (AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
 Encrypts / decrypts using the DES algorithm. More...
 
void av_des_mac (AVDES *d, uint8_t *dst, const uint8_t *src, int count)
 Calculates CBC-MAC using the DES algorithm. More...
 

Variables

static const uint8_t IP_shuffle []
 
static const uint8_t PC1_shuffle []
 
static const uint8_t PC2_shuffle []
 
static const uint32_t S_boxes_P_shuffle [8][64]
 This table contains the results of applying both the S-box and P-shuffle. More...
 

Macro Definition Documentation

◆ T [1/3]

#define T (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h 
)    64 - a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g, 64 - h

Definition at line 71 of file des.c.

◆ T [2/3]

#define T (   a,
  b,
  c,
  d,
  e,
  f,
  g 
)    64 - a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g

Definition at line 71 of file des.c.

◆ T [3/3]

#define T (   a,
  b,
  c,
  d,
  e,
  f 
)    56 - a, 56 - b, 56 - c, 56 - d, 56 - e, 56 - f

Definition at line 71 of file des.c.

Function Documentation

◆ shuffle()

static uint64_t shuffle ( uint64_t  in,
const uint8_t shuffle,
int  shuffle_len 
)
static

Definition at line 177 of file des.c.

Referenced by des_encdec(), f_func(), gen_roundkeys(), main(), and shuffle_inv().

◆ shuffle_inv()

static uint64_t shuffle_inv ( uint64_t  in,
const uint8_t shuffle,
int  shuffle_len 
)
static

Definition at line 186 of file des.c.

Referenced by des_encdec().

◆ f_func()

static uint32_t f_func ( uint32_t  r,
uint64_t  k 
)
static

Definition at line 198 of file des.c.

Referenced by des_encdec().

◆ key_shift_left()

static uint64_t key_shift_left ( uint64_t  CDn)
static

rotate the two halves of the expanded 56 bit key each 1 bit left

Note: the specification calls this "shift", so I kept it although it is confusing.

Definition at line 231 of file des.c.

Referenced by gen_roundkeys().

◆ gen_roundkeys()

static void gen_roundkeys ( uint64_t  K[16],
uint64_t  key 
)
static

Definition at line 240 of file des.c.

Referenced by av_des_init(), and main().

◆ des_encdec()

static uint64_t des_encdec ( uint64_t  in,
uint64_t  K[16],
int  decrypt 
)
static

Definition at line 254 of file des.c.

Referenced by av_des_crypt_mac(), and main().

◆ av_des_init()

int av_des_init ( AVDES d,
const uint8_t key,
int  key_bits,
av_unused int  decrypt 
)

Definition at line 278 of file des.c.

Referenced by decrypt_init(), ff_asfcrypt_dec(), main(), nprobe(), rprobe(), run_lavu_des(), and run_test().

◆ av_des_crypt_mac()

static void av_des_crypt_mac ( AVDES d,
uint8_t dst,
const uint8_t src,
int  count,
uint8_t iv,
int  decrypt,
int  mac 
)
static

Definition at line 290 of file des.c.

Referenced by av_des_crypt(), and av_des_mac().

Variable Documentation

◆ IP_shuffle

const uint8_t IP_shuffle[]
static
Initial value:
= {
T(58, 50, 42, 34, 26, 18, 10, 2),
T(60, 52, 44, 36, 28, 20, 12, 4),
T(62, 54, 46, 38, 30, 22, 14, 6),
T(64, 56, 48, 40, 32, 24, 16, 8),
T(57, 49, 41, 33, 25, 17, 9, 1),
T(59, 51, 43, 35, 27, 19, 11, 3),
T(61, 53, 45, 37, 29, 21, 13, 5),
T(63, 55, 47, 39, 31, 23, 15, 7)
}

Definition at line 31 of file des.c.

Referenced by des_encdec().

◆ PC1_shuffle

const uint8_t PC1_shuffle[]
static
Initial value:
= {
T(57, 49, 41, 33, 25, 17, 9),
T( 1, 58, 50, 42, 34, 26, 18),
T(10, 2, 59, 51, 43, 35, 27),
T(19, 11, 3, 60, 52, 44, 36),
T(63, 55, 47, 39, 31, 23, 15),
T( 7, 62, 54, 46, 38, 30, 22),
T(14, 6, 61, 53, 45, 37, 29),
T(21, 13, 5, 28, 20, 12, 4)
}

Definition at line 59 of file des.c.

Referenced by gen_roundkeys().

◆ PC2_shuffle

const uint8_t PC2_shuffle[]
static
Initial value:
= {
T(14, 17, 11, 24, 1, 5),
T( 3, 28, 15, 6, 21, 10),
T(23, 19, 12, 4, 26, 8),
T(16, 7, 27, 20, 13, 2),
T(41, 52, 31, 37, 47, 55),
T(30, 40, 51, 45, 33, 48),
T(44, 49, 39, 56, 34, 53),
T(46, 42, 50, 36, 29, 32)
}

Definition at line 72 of file des.c.

Referenced by gen_roundkeys().

◆ S_boxes_P_shuffle

const uint32_t S_boxes_P_shuffle[8][64]
static

This table contains the results of applying both the S-box and P-shuffle.

It can be regenerated by compiling tests/des.c with "-DCONFIG_SMALL -DGENTABLES".

Definition at line 109 of file des.c.

Referenced by f_func().

T
#define T(a, b, c, d, e, f, g, h)
Definition: des.c:71