net.rim.device.api.crypto
Class CTRPseudoRandomSource

java.lang.Object
  extended by net.rim.device.api.crypto.AbstractPseudoRandomSource
      extended by net.rim.device.api.crypto.CTRPseudoRandomSource
All Implemented Interfaces:
PseudoRandomSource

public final class CTRPseudoRandomSource
extends AbstractPseudoRandomSource
implements PseudoRandomSource

CTRPseudoRandomSource uses a symmetric key block cipher in Counter Mode to provide a sequence of pseudo random bytes. CTR mode is defined in FIPS SP 800-38A

More than one message can be encrypted with the same key provided that a different initialization vector (IV) is used every time.

Note that any change in the ciphertext directly affects the plaintext. A ciphertext error only effects the corresponding bit of plaintext (this is why it is considered a stream cipher).

The width of the feedback is the block size of the cipher. For example, when used with DES, CTR uses 64 bit feedback.

For a code sample using the CTR pseudo random source, click here.

Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

Constructor Summary
Category: Signed CTRPseudoRandomSource(SymmetricKeyEncryptorEngine engine, long iv)
          Creates an CTRPseudoRandomSource object based on the specified encryptor engine and initialization vector.
Category: Signed CTRPseudoRandomSource(SymmetricKeyEncryptorEngine engine, InitializationVector iv)
          Creates an CTRPseudoRandomSource object based on the specified encryptor engine and initialization vector.
 
Method Summary
Category: Signed  String getAlgorithm()
          Returns the name of this PseudoRandomSource.
Category: Signed  int getAvailable()
          Returns the number of pseudo random bytes currently available.
Category: Signed  int getMaxAvailable()
          Returns the maximum number of pseudo random bytes that this PRNG can produce.
Category: Signed  void xorBytes(byte[] buffer, int offset, int length)
          Exclusive-OR's random bytes into the given buffer starting at the specified array offset.
 
Methods inherited from class net.rim.device.api.crypto.AbstractPseudoRandomSource
getBytes, getBytes, getBytes, xorBytes, xorBytes, xorCopy, xorCopy
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.rim.device.api.crypto.PseudoRandomSource
getBytes, getBytes, getBytes, xorBytes, xorBytes, xorCopy, xorCopy
 



Constructor Detail

CTRPseudoRandomSource

public CTRPseudoRandomSource(SymmetricKeyEncryptorEngine engine,
                             long iv)
                      throws CryptoTokenException
Creates an CTRPseudoRandomSource object based on the specified encryptor engine and initialization vector.

Parameters:
engine - The encryption engine (algorithm) that will be used for the CTR mode.
iv - The starting value for the counter that is to be used for the CTR mode (must have the same length as the engine's block length).
Throws:
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

CTRPseudoRandomSource

public CTRPseudoRandomSource(SymmetricKeyEncryptorEngine engine,
                             InitializationVector iv)
                      throws CryptoTokenException
Creates an CTRPseudoRandomSource object based on the specified encryptor engine and initialization vector.

Parameters:
engine - The encryption engine (algorithm) that will be used for the CTR mode.
iv - The starting value for the counter that is to be used for the CTR mode (must have the same length as the engine's block length).
Throws:
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0


Method Detail

getAlgorithm

public String getAlgorithm()
Returns the name of this PseudoRandomSource. SymmetricKeyEncryptorEngine.getAlgorithm() + "/CTR".

Specified by:
getAlgorithm in interface PseudoRandomSource
Returns:
A String representing the name of the algorithm.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

xorBytes

public void xorBytes(byte[] buffer,
                     int offset,
                     int length)
              throws CryptoTokenException
Description copied from class: AbstractPseudoRandomSource
Exclusive-OR's random bytes into the given buffer starting at the specified array offset.

Specified by:
xorBytes in interface PseudoRandomSource
Specified by:
xorBytes in class AbstractPseudoRandomSource
Parameters:
buffer - The byte array to xor the bytes into.
offset - The starting offset within buffer.
length - The number of bytes to xor.
Throws:
CryptoTokenException - Occurs when a problem occurs with a crypto token or the crypto token is invalid.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

getAvailable

public int getAvailable()
Description copied from interface: PseudoRandomSource
Returns the number of pseudo random bytes currently available.

For PRNG sources that have an indefinite length but implement this interface, the value returned is Integer.MAX.

Specified by:
getAvailable in interface PseudoRandomSource
Returns:
An integer that represents the number of bytes.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

getMaxAvailable

public int getMaxAvailable()
Description copied from interface: PseudoRandomSource
Returns the maximum number of pseudo random bytes that this PRNG can produce.

For PRNG sources that have an indefinite length but implement this interface, the value returned is Integer.MAX.

Specified by:
getMaxAvailable in interface PseudoRandomSource
Returns:
An integer that specifies the maximum number of random bytes that can be produced.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal