BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
riencryptlib.c File Reference
#include "blitzlib.h"

Macros

#define TOK_rnd   ((LIB_vallib << 7) + 7)
#define NEG(n)

Functions

void _encrypt2 (void)
void _encrypt (void)
void _decrypt (void)
void _decrypt2 (void)
void _getwheel (void)
static ULONG encrypt_c (UBYTE *p, ULONG len, UWORD wheel1, UWORD wheel2, UWORD wheel3)
 Encrypt memadr,length,wheel1,wheel2,wheel3: encrypts a block in place with the three-wheel cipher.
static UBYTE rndwheel (ULONG range)
static ULONG encrypt2_c (UBYTE *p, ULONG len)
 Encrypt memadr,length: as above with random start wheels (vallib Rnd); GetWheel tells the state after it.
static ULONG decrypt_c (UBYTE *base, ULONG len, UWORD wheel1, UWORD wheel2, UWORD wheel3)
 Decrypt memadr,length,wheel1,wheel2,wheel3: decrypts a block in place, from the end backwards.
static ULONG decrypt2_c (UBYTE *p, ULONG len, UWORD wheel1, UWORD wheel2, UWORD wheel3, UWORD mode)
 Decrypt memadr,length,wheel1,wheel2,wheel3,mode: as above; mode 1 starts from the wheels Encrypt started with.
static ULONG getwheel_c (UWORD n)
 GetWheel(wheel#): a wheel after the last Encrypt/Decrypt.

Variables

static UBYTE wheels [3]

Macro Definition Documentation

◆ NEG

#define NEG ( n)
Value:
((n) & 0x80000000UL)
ULONG WORD UWORD UWORD border ULONG ULONG struct bb_bitmap *dst void UWORD n
Definition 2dlib.c:2498

◆ TOK_rnd

#define TOK_rnd   ((LIB_vallib << 7) + 7)

Function Documentation

◆ _decrypt()

void _decrypt ( void )

◆ _decrypt2()

void _decrypt2 ( void )

◆ _encrypt()

void _encrypt ( void )

◆ _encrypt2()

void _encrypt2 ( void )

◆ _getwheel()

void _getwheel ( void )

◆ decrypt2_c()

ULONG decrypt2_c ( UBYTE * p,
ULONG len,
UWORD wheel1,
UWORD wheel2,
UWORD wheel3,
UWORD mode )
static

Decrypt memadr,length,wheel1,wheel2,wheel3,mode: as above; mode 1 starts from the wheels Encrypt started with.

Mode 1 (the low byte, CMPI.b) adds the length to the wheels first, as the 24-bit number w3:w2:w1 the odometer of Encrypt counts (Fixed (#629): the original added the length's bytes 0..2 to the wheels each without the carry into the next one, so the state could be one step off).

Parameters
pd0: memadr
lend1: length
wheel1d2: wheel 1
wheel2d3: wheel 2
wheel3d4: wheel 3
moded5: 1 = the start wheels, else as Decrypt above
Returns
d0: memadr with the last byte written in its low byte

◆ decrypt_c()

ULONG decrypt_c ( UBYTE * base,
ULONG len,
UWORD wheel1,
UWORD wheel2,
UWORD wheel3 )
static

Decrypt memadr,length,wheel1,wheel2,wheel3: decrypts a block in place, from the end backwards.

The wheels are those Encrypt left (GetWheel); each byte loses w1 + w2 + w3, then the wheels step back. The last state is kept for GetWheel. A length of 0 (or one of 2^31 and above) does nothing (Fixed (#630): the original processed one byte, the one at memadr-1).

Parameters
based0: memadr
lend1: length
wheel1d2: wheel 1 (its low byte)
wheel2d3: wheel 2
wheel3d4: wheel 3
Returns
d0: memadr with the last byte written in its low byte (memadr when nothing is processed)

◆ encrypt2_c()

ULONG encrypt2_c ( UBYTE * p,
ULONG len )
static

Encrypt memadr,length: as above with random start wheels (vallib Rnd); GetWheel tells the state after it.

Parameters
pd0: memadr
lend1: length
Returns
d0: memadr with the last byte written in its low byte

◆ encrypt_c()

ULONG encrypt_c ( UBYTE * p,
ULONG len,
UWORD wheel1,
UWORD wheel2,
UWORD wheel3 )
static

Encrypt memadr,length,wheel1,wheel2,wheel3: encrypts a block in place with the three-wheel cipher.

Every byte b becomes b + w1 + w2 + w3, the wheels stepped before each byte like an odometer (w1 + 1, on its carry w2 + 1, on that w3 + 1); the last state is kept for GetWheel. A length of 0 (or one of 2^31 and above) does nothing (Fixed (#630): the original processed one byte).

Parameters
pd0: memadr
lend1: length
wheel1d2: the start of wheel 1 (its low byte, ANDI.l $ff)
wheel2d3: the start of wheel 2
wheel3d4: the start of wheel 3
Returns
d0: memadr with the last byte written in its low byte (memadr when nothing is processed)

◆ getwheel_c()

ULONG getwheel_c ( UWORD n)
static

GetWheel(wheel#): a wheel after the last Encrypt/Decrypt.

Parameters
nd0.b: wheel# 1..3
Returns
d0: the wheel zero extended, -1 for another wheel#

◆ rndwheel()

UBYTE rndwheel ( ULONG range)
static

Variable Documentation

◆ wheels

UBYTE wheels[3]
static