[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/phpseclib/phpseclib/phpseclib/Crypt/ -> RSA.php (summary)

Pure-PHP PKCS#1 (v2.1) compliant implementation of RSA. PHP version 5

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

Defines 25 functions

  setExponent()
  setSmallestPrime()
  setOpenSSLConfigPath()
  createKey()
  onLoad()
  initialize_static_variables()
  __construct()
  i2osp()
  os2ip()
  emsa_pkcs1_v1_5_encode()
  emsa_pkcs1_v1_5_encode_without_null()
  mgf1()
  getLength()
  withHash()
  withMGFHash()
  getMGFHash()
  withSaltLength()
  getSaltLength()
  withLabel()
  getLabel()
  withPadding()
  getPadding()
  getEngine()
  enableBlinding()
  disableBlinding()

Functions
Functions that are not part of a class:

setExponent($val)   X-Ref
Sets the public exponent for key generation

This will be 65537 unless changed.

param: int $val

setSmallestPrime($val)   X-Ref
Sets the smallest prime number in bits. Used for key generation

This will be 4096 unless changed.

param: int $val

setOpenSSLConfigPath($val)   X-Ref
Sets the OpenSSL config file path

Set to the empty string to use the default config file

param: string $val

createKey($bits = 2048)   X-Ref
Create a private key

The public key can be extracted from the private key

param: int $bits
return: RSA\PrivateKey

onLoad(array $components)   X-Ref
OnLoad Handler

return: bool

initialize_static_variables()   X-Ref
Initialize static variables


__construct()   X-Ref
Constructor

PublicKey and PrivateKey objects can only be created from abstract RSA class

i2osp($x, $xLen)   X-Ref
Integer-to-Octet-String primitive

See {@link http://tools.ietf.org/html/rfc3447#section-4.1 RFC3447#section-4.1}.

param: bool|\phpseclib3\Math\BigInteger $x
param: int $xLen
return: bool|string

os2ip($x)   X-Ref
Octet-String-to-Integer primitive

See {@link http://tools.ietf.org/html/rfc3447#section-4.2 RFC3447#section-4.2}.

param: string $x
return: \phpseclib3\Math\BigInteger

emsa_pkcs1_v1_5_encode($m, $emLen)   X-Ref
EMSA-PKCS1-V1_5-ENCODE

See {@link http://tools.ietf.org/html/rfc3447#section-9.2 RFC3447#section-9.2}.

param: string $m
param: int $emLen
return: string

emsa_pkcs1_v1_5_encode_without_null($m, $emLen)   X-Ref
EMSA-PKCS1-V1_5-ENCODE (without NULL)

Quoting https://tools.ietf.org/html/rfc8017#page-65,

"The parameters field associated with id-sha1, id-sha224, id-sha256,
id-sha384, id-sha512, id-sha512/224, and id-sha512/256 should
generally be omitted, but if present, it shall have a value of type
NULL"

param: string $m
param: int $emLen
return: string

mgf1($mgfSeed, $maskLen)   X-Ref
MGF1

See {@link http://tools.ietf.org/html/rfc3447#appendix-B.2.1 RFC3447#appendix-B.2.1}.

param: string $mgfSeed
param: int $maskLen
return: string

getLength()   X-Ref
Returns the key size

More specifically, this returns the size of the modulo in bits.

return: int

withHash($hash)   X-Ref
Determines which hashing function should be used

Used with signature production / verification and (if the encryption mode is self::PADDING_OAEP) encryption and
decryption.

param: string $hash

withMGFHash($hash)   X-Ref
Determines which hashing function should be used for the mask generation function

The mask generation function is used by self::PADDING_OAEP and self::PADDING_PSS and although it's
best if Hash and MGFHash are set to the same thing this is not a requirement.

param: string $hash

getMGFHash()   X-Ref
Returns the MGF hash algorithm currently being used


withSaltLength($sLen)   X-Ref
Determines the salt length

Used by RSA::PADDING_PSS

To quote from {@link http://tools.ietf.org/html/rfc3447#page-38 RFC3447#page-38}:

Typical salt lengths in octets are hLen (the length of the output
of the hash function Hash) and 0.

param: int $sLen

getSaltLength()   X-Ref
Returns the salt length currently being used


withLabel($label)   X-Ref
Determines the label

Used by RSA::PADDING_OAEP

To quote from {@link http://tools.ietf.org/html/rfc3447#page-17 RFC3447#page-17}:

Both the encryption and the decryption operations of RSAES-OAEP take
the value of a label L as input.  In this version of PKCS #1, L is
the empty string; other uses of the label are outside the scope of
this document.

param: string $label

getLabel()   X-Ref
Returns the label currently being used


withPadding($padding)   X-Ref
Determines the padding modes

Example: $key->withPadding(RSA::ENCRYPTION_PKCS1 | RSA::SIGNATURE_PKCS1);

param: int $padding

getPadding()   X-Ref
Returns the padding currently being used


getEngine()   X-Ref
Returns the current engine being used

OpenSSL is only used in this class (and it's subclasses) for key generation
Even then it depends on the parameters you're using. It's not used for
multi-prime RSA nor is it used if the key length is outside of the range
supported by OpenSSL

see: self::useInternalEngine()
see: self::useBestEngine()
return: string

enableBlinding()   X-Ref
Enable RSA Blinding


disableBlinding()   X-Ref
Disable RSA Blinding