FFmpeg
Loading...
Searching...
No Matches
cast5.c File Reference
#include <string.h>
#include "cast5.h"
#include "error.h"
#include "intreadwrite.h"
#include "mem.h"
#include "attributes.h"

Go to the source code of this file.

Data Structures

struct  AVCAST5
 

Macros

#define IA(x)
 
#define IB(x)
 
#define IC(x)
 
#define ID(x)
 
#define LR(x, c)
 
#define F3(l, r, i)
 
#define F2(l, r, i)
 
#define F1(l, r, i)
 
#define COMPUTE_Z
 
#define COMPUTE_X
 

Functions

static void generate_round_keys (int rnds, uint32_t *K, uint32_t *x, uint32_t *z)
 
static void encipher (AVCAST5 *cs, uint8_t *dst, const uint8_t *src)
 
static void decipher (AVCAST5 *cs, uint8_t *dst, const uint8_t *src, uint8_t *iv)
 
struct AVCAST5av_cast5_alloc (void)
 Allocate an AVCAST5 context To free the struct: av_free(ptr)
 
av_cold int av_cast5_init (AVCAST5 *cs, const uint8_t *key, int key_bits)
 Initialize an AVCAST5 context.
 
void av_cast5_crypt2 (AVCAST5 *cs, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
 Encrypt or decrypt a buffer using a previously initialized context.
 
void av_cast5_crypt (AVCAST5 *cs, uint8_t *dst, const uint8_t *src, int count, int decrypt)
 Encrypt or decrypt a buffer using a previously initialized context, ECB mode only.
 

Variables

const int av_cast5_size = sizeof(AVCAST5)
 
static const uint32_t S1 [256]
 
static const uint32_t S2 [256]
 
static const uint32_t S3 [256]
 
static const uint32_t S4 [256]
 
static const uint32_t S5 [256]
 
static const uint32_t S6 [256]
 
static const uint32_t S7 [256]
 
static const uint32_t S8 [256]
 

Macro Definition Documentation

◆ IA

#define IA ( x)
Value:
((x) >> 24)

Definition at line 30 of file cast5.c.

Referenced by generate_round_keys(), and lup_invert().

◆ IB

#define IB ( x)
Value:
(((x) >> 16) & 0xff)

Definition at line 31 of file cast5.c.

Referenced by generate_round_keys().

◆ IC

#define IC ( x)
Value:
(((x) >> 8) & 0xff)

Definition at line 32 of file cast5.c.

Referenced by generate_round_keys().

◆ ID

#define ID ( x)
Value:
((x) & 0xff)

Definition at line 33 of file cast5.c.

Referenced by generate_round_keys().

◆ LR

#define LR ( x,
c )
Value:
(((x) << (c)) | ((x) >> ((32 - (c)) & 31)))
static double c[64]

Definition at line 35 of file cast5.c.

◆ F3

#define F3 ( l,
r,
i )
Value:
do { \
I = LR(cs->Km[i] - r, cs->Kr[i]); \
f = ((S1[IA(I)] + S2[IB(I)]) ^ S3[IC(I)]) - S4[ID(I)]; \
l = f ^ l; \
} while (0)
static const uint32_t S1[256]
Definition cast5.c:83
#define IC(x)
Definition cast5.c:32
static const uint32_t S4[256]
Definition cast5.c:188
#define IB(x)
Definition cast5.c:31
#define IA(x)
Definition cast5.c:30
#define LR(x, c)
Definition cast5.c:35
static const uint32_t S3[256]
Definition cast5.c:153
static const uint32_t S2[256]
Definition cast5.c:118
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define r
Definition input.c:42
#define ID(_0)
Definition mov_chan.c:124

Definition at line 37 of file cast5.c.

Referenced by compute_error(), decipher(), and encipher().

◆ F2

#define F2 ( l,
r,
i )
Value:
do { \
I = LR(cs->Km[i] ^ r, cs->Kr[i]); \
f = ((S1[IA(I)] - S2[IB(I)]) + S3[IC(I)]) ^ S4[ID(I)]; \
l = f ^ l; \
} while (0)

Definition at line 44 of file cast5.c.

Referenced by compute_error(), decipher(), and encipher().

◆ F1

#define F1 ( l,
r,
i )
Value:
do { \
I = LR(cs->Km[i] + r, cs->Kr[i]); \
f = ((S1[IA(I)] ^ S2[IB(I)]) - S3[IC(I)]) + S4[ID(I)]; \
l = f ^ l; \
} while (0)

Definition at line 51 of file cast5.c.

Referenced by compute_error(), decipher(), and encipher().

◆ COMPUTE_Z

#define COMPUTE_Z
Value:
do { \
z[0] = x[0] ^ S5[IB(x[3])] ^ S6[ID(x[3])] ^ S7[IA(x[3])] ^ S8[IC(x[3])] ^ S7[IA(x[2])]; \
z[1] = x[2] ^ S5[IA(z[0])] ^ S6[IC(z[0])] ^ S7[IB(z[0])] ^ S8[ID(z[0])] ^ S8[IC(x[2])]; \
z[2] = x[3] ^ S5[ID(z[1])] ^ S6[IC(z[1])] ^ S7[IB(z[1])] ^ S8[IA(z[1])] ^ S5[IB(x[2])]; \
z[3] = x[1] ^ S5[IC(z[2])] ^ S6[IB(z[2])] ^ S7[ID(z[2])] ^ S8[IA(z[2])] ^ S6[ID(x[2])]; \
} while (0)
static const uint32_t S7[256]
Definition cast5.c:293
static const uint32_t S8[256]
Definition cast5.c:328
static const uint32_t S5[256]
Definition cast5.c:223
static const uint32_t S6[256]
Definition cast5.c:258

Definition at line 58 of file cast5.c.

Referenced by generate_round_keys().

◆ COMPUTE_X

#define COMPUTE_X
Value:
do { \
x[0] = z[2] ^ S5[IB(z[1])] ^ S6[ID(z[1])] ^ S7[IA(z[1])] ^ S8[IC(z[1])] ^ S7[IA(z[0])]; \
x[1] = z[0] ^ S5[IA(x[0])] ^ S6[IC(x[0])] ^ S7[IB(x[0])] ^ S8[ID(x[0])] ^ S8[IC(z[0])]; \
x[2] = z[1] ^ S5[ID(x[1])] ^ S6[IC(x[1])] ^ S7[IB(x[1])] ^ S8[IA(x[1])] ^ S5[IB(z[0])]; \
x[3] = z[3] ^ S5[IC(x[2])] ^ S6[IB(x[2])] ^ S7[ID(x[2])] ^ S8[IA(x[2])] ^ S6[ID(z[0])]; \
} while (0)

Definition at line 66 of file cast5.c.

Referenced by generate_round_keys().

Function Documentation

◆ generate_round_keys()

static void generate_round_keys ( int rnds,
uint32_t * K,
uint32_t * x,
uint32_t * z )
static

Definition at line 363 of file cast5.c.

Referenced by av_cast5_init().

◆ encipher()

static void encipher ( AVCAST5 * cs,
uint8_t * dst,
const uint8_t * src )
static

Definition at line 396 of file cast5.c.

Referenced by av_cast5_crypt(), and av_cast5_crypt2().

◆ decipher()

static void decipher ( AVCAST5 * cs,
uint8_t * dst,
const uint8_t * src,
uint8_t * iv )
static

Definition at line 423 of file cast5.c.

Referenced by av_cast5_crypt(), and av_cast5_crypt2().

Variable Documentation

◆ S1

const uint32_t S1[256]
static

Definition at line 83 of file cast5.c.

◆ S2

const uint32_t S2[256]
static

Definition at line 118 of file cast5.c.

◆ S3

const uint32_t S3[256]
static

Definition at line 153 of file cast5.c.

◆ S4

const uint32_t S4[256]
static

Definition at line 188 of file cast5.c.

◆ S5

const uint32_t S5[256]
static

Definition at line 223 of file cast5.c.

Referenced by generate_round_keys().

◆ S6

const uint32_t S6[256]
static

Definition at line 258 of file cast5.c.

Referenced by generate_round_keys().

◆ S7

const uint32_t S7[256]
static

Definition at line 293 of file cast5.c.

Referenced by generate_round_keys().

◆ S8

const uint32_t S8[256]
static

Definition at line 328 of file cast5.c.

Referenced by generate_round_keys(), PCM_CODEC(), and pcm_decode_init().