APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.crypto.provider

pack-priv Class CounterMode

extends FeedbackCipher
Class Inheritance
Known Direct Subclasses
com.sun.crypto.provider.GCTR
Imports
java.security.InvalidKeyException, jdk.internal.vm.annotation.IntrinsicCandidate, sun.security.util.ArrayUtil

This class represents ciphers in counter (CTR) mode.

This mode is implemented independently of a particular cipher. Ciphers to which this mode should apply (e.g., DES) must be plugged-in using the constructor.

Note

This class does not deal with buffering or padding.

Author
Andreas Sterbenz
Since
1.4.2

Field Summary

Modifier and TypeField and Description
private final int
pack-priv final byte[]
private byte[]
private final byte[]
private byte[]
private int
private int
Inherited from com.sun.crypto.provider.FeedbackCipher:
blockSizeembeddedCipheriv

Constructor Summary

AccessConstructor and Description
pack-priv
CounterMode(SymmetricCipher embeddedCipher)

Method Summary

Modifier and TypeMethod and Description
private int
crypt(byte[] in, int inOff, int len, byte[] out, int outOff)

Do the actual encryption/decryption operation.

pack-priv int
decrypt(byte[] in, int inOff, int len, byte[] out, int outOff)

Implements abstract com.sun.crypto.provider.FeedbackCipher.decrypt.

Performs decryption operation.

pack-priv int

Returns:

the length of the encrypted data
encrypt
(byte[]
the buffer with the input data to be encrypted
in
,
int
the offset in plain
inOff
,
int
the length of the input data
len
,
byte[]
the buffer for the result
out
,
int
the offset in cipher
outOff
)

Implements abstract com.sun.crypto.provider.FeedbackCipher.encrypt.

Performs encryption operation.

pack-priv String

Returns:

the name of the feedback mechanism
getFeedback
()

Implements abstract com.sun.crypto.provider.FeedbackCipher.getFeedback.

Gets the name of the feedback mechanism

private int
implCrypt(byte[] in, int inOff, int len, byte[] out, int outOff)

private static void
increment(byte[] b)

Increment the counter value.

pack-priv void
init(boolean
flag indicating encryption or decryption
decrypting
,
String
the algorithm name
algorithm
,
byte[]
the key
key
,
byte[]
the iv
iv
)

Implements abstract com.sun.crypto.provider.FeedbackCipher.init.

Initializes the cipher in the specified mode with the given key and iv.

pack-priv void
reset()

Implements abstract com.sun.crypto.provider.FeedbackCipher.reset.

Resets the iv to its original value.

pack-priv void
restore()

Implements abstract com.sun.crypto.provider.FeedbackCipher.restore.

Restores the content of this cipher to the previous saved one.

pack-priv void
save()

Implements abstract com.sun.crypto.provider.FeedbackCipher.save.

Save the current content of this cipher.

Inherited from com.sun.crypto.provider.FeedbackCipher:
decryptFinalencryptFinalgetBlockSizegetEmbeddedCiphergetIV

Field Detail

chunkSizeback to summary
private final int chunkSize
counterback to summary
pack-priv final byte[] counter
counterSaveback to summary
private byte[] counterSave
encryptedCounterback to summary
private final byte[] encryptedCounter
encryptedCounterSaveback to summary
private byte[] encryptedCounterSave
usedback to summary
private int used
usedSaveback to summary
private int usedSave

Constructor Detail

CounterModeback to summary
pack-priv CounterMode(SymmetricCipher embeddedCipher)

Method Detail

cryptback to summary
private int crypt(byte[] in, int inOff, int len, byte[] out, int outOff)

Do the actual encryption/decryption operation. Essentially we XOR the input plaintext/ciphertext stream with a keystream generated by encrypting the counter values. Counter values are encrypted on demand.

decryptback to summary
pack-priv int decrypt(byte[] in, int inOff, int len, byte[] out, int outOff)

Implements abstract com.sun.crypto.provider.FeedbackCipher.decrypt.

Doc from com.sun.crypto.provider.FeedbackCipher.decrypt.

Performs decryption operation.

The input cipher, starting at cipherOffset and ending at (cipherOffset+cipherLen-1), is decrypted. The result is stored in plain, starting at plainOffset.

The subclass that implements Cipher should ensure that init has been called before this method is called.

encryptback to summary
pack-priv int encrypt(byte[] in, int inOff, int len, byte[] out, int outOff)

Implements abstract com.sun.crypto.provider.FeedbackCipher.encrypt.

Performs encryption operation.

The input plain text plain, starting at plainOffset and ending at (plainOffset + len - 1), is encrypted. The result is stored in cipher, starting at cipherOffset.

Parameters
in:byte[]

the buffer with the input data to be encrypted

inOff:int

the offset in plain

len:int

the length of the input data

out:byte[]

the buffer for the result

outOff:int

the offset in cipher

Returns:int

the length of the encrypted data

getFeedbackback to summary
pack-priv String getFeedback()

Implements abstract com.sun.crypto.provider.FeedbackCipher.getFeedback.

Gets the name of the feedback mechanism

Returns:String

the name of the feedback mechanism

implCryptback to summary
private int implCrypt(byte[] in, int inOff, int len, byte[] out, int outOff)
Annotations
@IntrinsicCandidate
incrementback to summary
private static void increment(byte[] b)

Increment the counter value.

initback to summary
pack-priv void init(boolean decrypting, String algorithm, byte[] key, byte[] iv) throws InvalidKeyException

Implements abstract com.sun.crypto.provider.FeedbackCipher.init.

Initializes the cipher in the specified mode with the given key and iv.

Parameters
decrypting:boolean

flag indicating encryption or decryption

algorithm:String

the algorithm name

key:byte[]

the key

iv:byte[]

the iv

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
resetback to summary
pack-priv void reset()

Implements abstract com.sun.crypto.provider.FeedbackCipher.reset.

Resets the iv to its original value. This is used when doFinal is called in the Cipher class, so that the cipher can be reused (with its original iv).

restoreback to summary
pack-priv void restore()

Implements abstract com.sun.crypto.provider.FeedbackCipher.restore.

Restores the content of this cipher to the previous saved one.

saveback to summary
pack-priv void save()

Implements abstract com.sun.crypto.provider.FeedbackCipher.save.

Save the current content of this cipher.