[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/phpseclib/ -> Crypt_Rijndael.php (summary)

Pure-PHP implementation of Rijndael. Uses mcrypt, if available/possible, and an internal implementation, otherwise.

Author: Jim Wigginton
Copyright: MMVIII Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
Link: http://phpseclib.sourceforge.net
File Size: 1374 lines (67 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class

Crypt_Rijndael:: (11 methods):
  __construct()
  setKey()
  setKeyLength()
  setBlockLength()
  _setupEngine()
  _setupMcrypt()
  _encryptBlock()
  _decryptBlock()
  _setupKey()
  _subWord()
  _setupInlineCrypt()


Class: Crypt_Rijndael  - X-Ref

Pure-PHP implementation of Rijndael.

__construct($mode = CRYPT_RIJNDAEL_MODE_CBC)   X-Ref
Default Constructor.

Determines whether or not the mcrypt extension should be used.

$mode could be:

- CRYPT_RIJNDAEL_MODE_ECB

- CRYPT_RIJNDAEL_MODE_CBC

- CRYPT_RIJNDAEL_MODE_CTR

- CRYPT_RIJNDAEL_MODE_CFB

- CRYPT_RIJNDAEL_MODE_OFB

If not explictly set, CRYPT_RIJNDAEL_MODE_CBC will be used.

param: optional Integer $mode
see: Crypt_Base::Crypt_Base()

setKey($key)   X-Ref
Sets the key.

Keys can be of any length.  Rijndael, itself, requires the use of a key that's between 128-bits and 256-bits long and
whose length is a multiple of 32.  If the key is less than 256-bits and the key length isn't set, we round the length
up to the closest valid key length, padding $key with null bytes.  If the key is more than 256-bits, we trim the
excess bits.

If the key is not explicitly set, it'll be assumed to be all null bytes.

Note: 160/224-bit keys must explicitly set by setKeyLength(), otherwise they will be round/pad up to 192/256 bits.

param: String $key
see: Crypt_Base:setKey()
see: setKeyLength()

setKeyLength($length)   X-Ref
Sets the key length

Valid key lengths are 128, 160, 192, 224, and 256.  If the length is less than 128, it will be rounded up to
128.  If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.

Note: phpseclib extends Rijndael (and AES) for using 160- and 224-bit keys but they are officially not defined
and the most (if not all) implementations are not able using 160/224-bit keys but round/pad them up to
192/256 bits as, for example, mcrypt will do.

That said, if you want be compatible with other Rijndael and AES implementations,
you should not setKeyLength(160) or setKeyLength(224).

Additional: In case of 160- and 224-bit keys, phpseclib will/can, for that reason, not use
the mcrypt php extention, even if available.
This results then in slower encryption.

param: Integer $length

setBlockLength($length)   X-Ref
Sets the block length

Valid block lengths are 128, 160, 192, 224, and 256.  If the length is less than 128, it will be rounded up to
128.  If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.

param: Integer $length

_setupEngine()   X-Ref
Setup the fastest possible $engine

Determines if the mcrypt (MODE_MCRYPT) $engine available
and usable for the current $block_size and $key_size.

If not, the slower MODE_INTERNAL $engine will be set.

see: setKey()
see: setKeyLength()
see: setBlockLength()

_setupMcrypt()   X-Ref
Setup the CRYPT_MODE_MCRYPT $engine

see: Crypt_Base::_setupMcrypt()

_encryptBlock($in)   X-Ref
Encrypts a block

param: String $in
return: String

_decryptBlock($in)   X-Ref
Decrypts a block

param: String $in
return: String

_setupKey()   X-Ref
Setup the key (expansion)

see: Crypt_Base::_setupKey()

_subWord($word)   X-Ref
Performs S-Box substitutions

param: Integer $word

_setupInlineCrypt()   X-Ref
Setup the performance-optimized function for de/encrypt()

see: Crypt_Base::_setupInlineCrypt()