The Battle for Wesnoth  1.19.7+dev
Classes | Macros | Typedefs | Functions | Variables
crypt_blowfish.c File Reference
#include <string.h>
#include <errno.h>
#include "crypt_blowfish.h"
Include dependency graph for crypt_blowfish.c:

Go to the source code of this file.

Classes

struct  BF_ctx
 

Macros

#define __set_errno(val)   errno = (val)
 
#define BF_ASM   0
 
#define BF_SCALE   0
 
#define BF_N   16
 
#define BF_safe_atoi64(dst, src)
 
#define BF_INDEX(S, i)    (*((BF_word *)(((unsigned char *)S) + (i))))
 
#define BF_ROUND(L, R, N)
 
#define BF_ENCRYPT
 
#define BF_body()
 

Typedefs

typedef unsigned int BF_word
 
typedef signed int BF_word_signed
 
typedef BF_word BF_key[BF_N+2]
 

Functions

static int BF_decode (BF_word *dst, const char *src, int size)
 
static void BF_encode (char *dst, const BF_word *src, int size)
 
static void BF_swap (BF_word *x, int count)
 
static void BF_set_key (const char *key, BF_key expanded, BF_key initial, unsigned char flags)
 
static char * BF_crypt (const char *key, const char *setting, char *output, int size, BF_word min)
 
static int _crypt_output_magic (const char *setting, char *output, int size)
 
char * php_crypt_blowfish_rn (const char *key, const char *setting, char *output, int size)
 

Variables

static BF_word BF_magic_w [6]
 
static BF_ctx BF_init_state
 
static unsigned char BF_itoa64 [64+1]
 
static unsigned char BF_atoi64 [0x60]
 
static const unsigned char flags_by_subtype [26]
 

Macro Definition Documentation

◆ __set_errno

#define __set_errno (   val)    errno = (val)

Definition at line 51 of file crypt_blowfish.c.

◆ BF_ASM

#define BF_ASM   0

Definition at line 64 of file crypt_blowfish.c.

◆ BF_body

#define BF_body ( )
Value:
L = R = 0; \
ptr = data.ctx.P; \
do { \
ptr += 2; \
BF_ENCRYPT; \
*(ptr - 2) = L; \
*(ptr - 1) = R; \
} while (ptr < &data.ctx.P[BF_N + 2]); \
\
ptr = data.ctx.S[0]; \
do { \
ptr += 2; \
BF_ENCRYPT; \
*(ptr - 2) = L; \
*(ptr - 1) = R; \
} while (ptr < &data.ctx.S[3][0xFF]);
#define BF_N
std::string_view data
Definition: picture.cpp:178

Definition at line 533 of file crypt_blowfish.c.

◆ BF_ENCRYPT

#define BF_ENCRYPT
Value:
L ^= data.ctx.P[0]; \
BF_ROUND(L, R, 0); \
BF_ROUND(R, L, 1); \
BF_ROUND(L, R, 2); \
BF_ROUND(R, L, 3); \
BF_ROUND(L, R, 4); \
BF_ROUND(R, L, 5); \
BF_ROUND(L, R, 6); \
BF_ROUND(R, L, 7); \
BF_ROUND(L, R, 8); \
BF_ROUND(R, L, 9); \
BF_ROUND(L, R, 10); \
BF_ROUND(R, L, 11); \
BF_ROUND(L, R, 12); \
BF_ROUND(R, L, 13); \
BF_ROUND(L, R, 14); \
BF_ROUND(R, L, 15); \
tmp4 = R; \
R = L; \
L = tmp4 ^ data.ctx.P[BF_N + 1];

Definition at line 507 of file crypt_blowfish.c.

◆ BF_INDEX

#define BF_INDEX (   S,
  i 
)     (*((BF_word *)(((unsigned char *)S) + (i))))

Definition at line 483 of file crypt_blowfish.c.

◆ BF_N

#define BF_N   16

Definition at line 72 of file crypt_blowfish.c.

◆ BF_ROUND

#define BF_ROUND (   L,
  R,
 
)
Value:
tmp1 = L & 0xFF; \
tmp1 <<= 2; \
tmp2 = L >> 6; \
tmp2 &= 0x3FC; \
tmp3 = L >> 14; \
tmp3 &= 0x3FC; \
tmp4 = L >> 22; \
tmp4 &= 0x3FC; \
tmp1 = BF_INDEX(data.ctx.S[3], tmp1); \
tmp2 = BF_INDEX(data.ctx.S[2], tmp2); \
tmp3 = BF_INDEX(data.ctx.S[1], tmp3); \
tmp3 += BF_INDEX(data.ctx.S[0], tmp4); \
tmp3 ^= tmp2; \
R ^= data.ctx.P[N + 1]; \
tmp3 += tmp1; \
R ^= tmp3;
#define BF_INDEX(S, i)

Definition at line 485 of file crypt_blowfish.c.

◆ BF_safe_atoi64

#define BF_safe_atoi64 (   dst,
  src 
)
Value:
{ \
tmp = (unsigned char)(src); \
if (tmp == '$') break; /* PHP hack */ \
if ((unsigned int)(tmp -= 0x20) >= 0x60) return -1; \
tmp = BF_atoi64[tmp]; \
if (tmp > 63) return -1; \
(dst) = tmp; \
}
static unsigned char BF_atoi64[0x60]
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.

Definition at line 377 of file crypt_blowfish.c.

◆ BF_SCALE

#define BF_SCALE   0

Definition at line 65 of file crypt_blowfish.c.

Typedef Documentation

◆ BF_key

typedef BF_word BF_key[BF_N+2]

Definition at line 74 of file crypt_blowfish.c.

◆ BF_word

typedef unsigned int BF_word

Definition at line 68 of file crypt_blowfish.c.

◆ BF_word_signed

typedef signed int BF_word_signed

Definition at line 69 of file crypt_blowfish.c.

Function Documentation

◆ _crypt_output_magic()

static int _crypt_output_magic ( const char *  setting,
char *  output,
int  size 
)
static

Definition at line 790 of file crypt_blowfish.c.

References output(), and utf8::size().

Referenced by php_crypt_blowfish_rn().

◆ BF_crypt()

static char* BF_crypt ( const char *  key,
const char *  setting,
char *  output,
int  size,
BF_word  min 
)
static

◆ BF_decode()

static int BF_decode ( BF_word dst,
const char *  src,
int  size 
)
static

Definition at line 387 of file crypt_blowfish.c.

References BF_safe_atoi64, dst, utf8::size(), and src.

Referenced by BF_crypt().

◆ BF_encode()

static void BF_encode ( char *  dst,
const BF_word src,
int  size 
)
static

Definition at line 418 of file crypt_blowfish.c.

References BF_itoa64, dst, utf8::size(), and src.

Referenced by BF_crypt().

◆ BF_set_key()

static void BF_set_key ( const char *  key,
BF_key  expanded,
BF_key  initial,
unsigned char  flags 
)
static

Definition at line 552 of file crypt_blowfish.c.

References BF_init_state, BF_N, i, and BF_ctx::P.

Referenced by BF_crypt(), and php_crypt_blowfish_rn().

◆ BF_swap()

static void BF_swap ( BF_word x,
int  count 
)
static

Definition at line 450 of file crypt_blowfish.c.

Referenced by BF_crypt().

◆ php_crypt_blowfish_rn()

char* php_crypt_blowfish_rn ( const char *  key,
const char *  setting,
char *  output,
int  size 
)

Variable Documentation

◆ BF_atoi64

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

Definition at line 368 of file crypt_blowfish.c.

Referenced by BF_crypt().

◆ BF_init_state

BF_ctx BF_init_state
static

Definition at line 93 of file crypt_blowfish.c.

Referenced by BF_crypt(), and BF_set_key().

◆ BF_itoa64

unsigned char BF_itoa64[64+1]
static
Initial value:
=
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

Definition at line 365 of file crypt_blowfish.c.

Referenced by BF_crypt(), and BF_encode().

◆ BF_magic_w

BF_word BF_magic_w[6]
static
Initial value:
= {
0x4F727068, 0x65616E42, 0x65686F6C,
0x64657253, 0x63727944, 0x6F756274
}

Definition at line 85 of file crypt_blowfish.c.

Referenced by BF_crypt().

◆ flags_by_subtype

const unsigned char flags_by_subtype[26]
static
Initial value:
=
{2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0}

Definition at line 654 of file crypt_blowfish.c.

Referenced by BF_crypt(), and php_crypt_blowfish_rn().