MagickCore 7.0.10
twofish.c File Reference
Include dependency graph for twofish.c:

Go to the source code of this file.

Data Structures

struct  _TwofishInfo
 

Macros

#define G1(alpha)
 
#define G2(beta)
 
#define Read32Bits(value, p)
 
#define TwofishBlocksize   16
 
#define Write32Bits(p, value)
 
#define DecipherRound(alpha, beta, gamma, delta, i)
 
#define EncipherRound(alpha, beta, gamma, delta, i)
 
#define K128(x, j, k, l, m, n)
 
#define K192(x, j, k, l, m, n)
 
#define K256(x, j, k, l, m, n)
 
#define MaximumTwofishKeyLength   32
 
#define Q128(alpha, beta, gamma, delta, i)
 
#define Q192(alpha, beta, gamma, delta, i)
 
#define Q256(alpha, beta, i)
 
#define Sbox(alpha, beta, gamma, delta, i, w, x, y, z)
 

Functions

WizardExport TwofishInfoAcquireTwofishInfo (void)
 
WizardExport void DecipherTwofishBlock (TwofishInfo *twofish_info, const unsigned char *ciphertext, unsigned char *plaintext)
 
WizardExport TwofishInfoDestroyTwofishInfo (TwofishInfo *twofish_info)
 
WizardExport void EncipherTwofishBlock (TwofishInfo *twofish_info, const unsigned char *plaintext, unsigned char *ciphertext)
 
WizardExport unsigned int GetTwofishBlocksize (const TwofishInfo *twofish_info)
 
WizardExport void SetTwofishKey (TwofishInfo *twofish_info, const StringInfo *key)
 

Macro Definition Documentation

◆ DecipherRound

#define DecipherRound (   alpha,
  beta,
  gamma,
  delta,
 
)
Value:
{ \
rho=G1(alpha); sigma=G2(beta); rho+=sigma; sigma+=rho; \
delta^=sigma+twofish_info->k[2*(i)+1]; delta=(delta >> 1)+(delta << 31); \
gamma=(gamma << 1)+(gamma >> 31); gamma^=(rho+twofish_info->k[2*(i)]); \
}
#define G1(alpha)
Definition twofish.c:68
#define G2(beta)
Definition twofish.c:73

◆ EncipherRound

#define EncipherRound (   alpha,
  beta,
  gamma,
  delta,
 
)
Value:
{ \
rho=G1(alpha); sigma=G2(beta); \
rho+=sigma; sigma+=rho+twofish_info->k[2*(i)+1]; \
gamma^=rho+twofish_info->k[2*(i)]; gamma=(gamma >> 1)+(gamma << 31); \
delta=((delta << 1)+(delta >> 31)) ^ sigma; \
}

◆ G1

#define G1 (   alpha)
Value:
(twofish_info->sbox[0][(alpha) & 0xFF]) ^ \
(twofish_info->sbox[1][((alpha) >> 8) & 0xFF]) ^ \
(twofish_info->sbox[2][((alpha) >> 16) & 0xFF]) ^ \
(twofish_info->sbox[3][(alpha) >> 24])

Definition at line 68 of file twofish.c.

◆ G2

#define G2 (   beta)
Value:
(twofish_info->sbox[1][(beta) & 0xFF]) ^ \
(twofish_info->sbox[2][((beta) >> 8) & 0xFF]) ^ \
(twofish_info->sbox[3][((beta) >> 16) & 0xFF]) ^ \
(twofish_info->sbox[0][(beta) >> 24])

Definition at line 73 of file twofish.c.

◆ K128

#define K128 (   x,
  j,
  k,
  l,
  m,
 
)
Value:
{ \
rho=Q128(k,l,k,l,0); sigma=Q128(m,n,m,n,4); \
sigma=(sigma << 8)+(sigma >> 24); rho+=sigma; sigma+=rho; \
twofish_info->x[j]=rho; twofish_info->x[(j)+1]=(sigma << 9)+(sigma >> 23); \
}
#define Q128(alpha, beta, gamma, delta, i)

◆ K192

#define K192 (   x,
  j,
  k,
  l,
  m,
 
)
Value:
{ \
rho=Q192(l,l,k,k,0); sigma=Q192(n,n,m,m,4); \
sigma=(sigma << 8)+(sigma >> 24); rho+=sigma; sigma+=rho; \
twofish_info->x[j]=rho; twofish_info->x[(j)+1]=(sigma << 9)+(sigma >> 23); \
}
#define Q192(alpha, beta, gamma, delta, i)

◆ K256

#define K256 (   x,
  j,
  k,
  l,
  m,
 
)
Value:
{ \
rho=Q256(k,l,0); sigma=Q256(m,n,4); \
sigma=(sigma << 8)+(sigma >> 24); rho+=sigma; sigma+=rho; \
twofish_info->x[j]=rho; twofish_info->x[(j)+1]=(sigma << 9)+(sigma >> 23); \
}
#define Q256(alpha, beta, i)

◆ MaximumTwofishKeyLength

#define MaximumTwofishKeyLength   32

◆ Q128

#define Q128 (   alpha,
  beta,
  gamma,
  delta,
 
)
Value:
mds[0][q0[alpha ^ crypt_key[(i)+8]] ^ crypt_key[i]] ^ \
mds[1][q0[beta ^ crypt_key[(i)+9]] ^ crypt_key[(i)+1]] ^ \
mds[2][q1[gamma ^ crypt_key[(i)+10]] ^ crypt_key[(i)+2]] ^ \
mds[3][q1[delta ^ crypt_key[(i)+11]] ^ crypt_key[(i)+3]]

◆ Q192

#define Q192 (   alpha,
  beta,
  gamma,
  delta,
 
)
Value:
Q128(q0[alpha ^ crypt_key[(i)+16]],q1[beta ^ crypt_key[(i)+17]], \
q0[gamma ^ crypt_key[(i)+18]],q1[delta ^ crypt_key[(i)+19]],i)

◆ Q256

#define Q256 (   alpha,
  beta,
 
)
Value:
Q192(q1[beta ^ crypt_key[(i)+24]],q1[alpha ^ crypt_key[(i)+25]], \
q0[alpha ^ crypt_key[(i)+26]],q0[beta ^ crypt_key[(i)+27]],i)

◆ Read32Bits

#define Read32Bits (   value,
 
)
Value:
{ \
(value)=(*p++); \
(value)|=(*p++) << 8; \
(value)|=(*p++) << 16; \
(value)|=(*p++) << 24; \
}

Definition at line 78 of file twofish.c.

◆ Sbox

#define Sbox (   alpha,
  beta,
  gamma,
  delta,
  i,
  w,
  x,
  y,
 
)
Value:
{ \
if (crypt_key[i] != 0) \
{ \
xi=polynomial_to_exponent[crypt_key[i]-1]; \
(alpha)^=exponent_to_polynomial[xi+(w)]; \
(beta)^=exponent_to_polynomial[xi+(x)]; \
(gamma)^=exponent_to_polynomial[xi+(y)]; \
(delta)^=exponent_to_polynomial[xi+(z)]; \
} \
}

◆ TwofishBlocksize

#define TwofishBlocksize   16

Definition at line 85 of file twofish.c.

◆ Write32Bits

#define Write32Bits (   p,
  value 
)
Value:
{ \
*p++=(unsigned char) (value); \
*p++=(unsigned char) ((value) >> 8); \
*p++=(unsigned char) ((value) >> 16); \
*p++=(unsigned char) ((value) >> 24); \
}

Definition at line 86 of file twofish.c.

Function Documentation

◆ AcquireTwofishInfo()

◆ DecipherTwofishBlock()

WizardExport void DecipherTwofishBlock ( TwofishInfo twofish_info,
const unsigned char *  ciphertext,
unsigned char *  plaintext 
)

Definition at line 155 of file twofish.c.

References DecipherRound, _TwofishInfo::w, and Write32Bits.

Referenced by AcquireCipherInfo().

◆ DestroyTwofishInfo()

◆ EncipherTwofishBlock()

WizardExport void EncipherTwofishBlock ( TwofishInfo twofish_info,
const unsigned char *  plaintext,
unsigned char *  ciphertext 
)

Definition at line 283 of file twofish.c.

References EncipherRound, _TwofishInfo::w, and Write32Bits.

Referenced by AcquireCipherInfo().

◆ GetTwofishBlocksize()

WizardExport unsigned int GetTwofishBlocksize ( const TwofishInfo twofish_info)

◆ SetTwofishKey()