Package uicc.usim.gba_u
Class GBAUCipher
java.lang.Object
uicc.usim.gba_u.GBAUCipher
- Direct Known Subclasses:
GBAUCipher.OneShot
The
The term "pad" is used in the public key cipher algorithms below to refer to all the operations specified in the referenced scheme to transform the message block into the cipher block size.
Ks_int_NAF keys, internal keys generated during GBA_U process (see 3GPP TS 31.102 and 3GPP TS 33.220), are the only ones used in this class.
Ks_int_NAF keys are 256 bits symmetric keys then all asymmetric key algorithms are not supported.
A tear or card reset event resets an initialized
Even if a transaction is in progress, update of intermediate result state in the implementation instance shall not participate in the transaction.
Note:
GBAUCipher class is the abstract base class for Cipher algorithms. Implementations of Cipher algorithms must extend this class and implement all the abstract methods.The term "pad" is used in the public key cipher algorithms below to refer to all the operations specified in the referenced scheme to transform the message block into the cipher block size.
Ks_int_NAF keys, internal keys generated during GBA_U process (see 3GPP TS 31.102 and 3GPP TS 33.220), are the only ones used in this class.
Ks_int_NAF keys are 256 bits symmetric keys then all asymmetric key algorithms are not supported.
A tear or card reset event resets an initialized
GBAUCipher object to the state it was in when previously initialized via a call to init().
For algorithms which support keys with transient key data sets, AES, and Korean SEED the GBAUCipher object
key becomes uninitialized on clear events associated with the key with the appropriate NAF ID (the Ks_int_NAF key) used to initialize the GBAUCipher object.Even if a transaction is in progress, update of intermediate result state in the implementation instance shall not participate in the transaction.
Note:
- On a tear or card reset event, the AES, Korean SEED and SM4 algorithms in CBC mode reset the initial vector(IV) to 0.
The initial vector(IV) can be re-initialized using the
init()methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classTheOneShotclass is a specialization of theGBAUCipherclass intended to support efficient one-shot ciphering and deciphering operations that may avoid persistent memory writes entirely. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract shortdoFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) Generates encrypted/decrypted output from all/last input data using Ks_int_NAF linked to NAF ID given ininit().abstract byteGets the cipher algorithm.abstract byteGets the raw cipher algorithm.static GBAUCiphergetInstance(byte algorithm, boolean externalAccess) Create an instance of theGBAUCipherclass with the selected cipher algorithm and padding algorithm.static GBAUCiphergetInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess) Create an instance of theGBAUCipherclass.abstract byteGets the padding algorithm.abstract voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key).abstract voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.abstract voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.abstract voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key).abstract shortupdate(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) Continues a multiple-part encryption or decryption operation, processing additional input data using Ks_int_NAF linked to NAF ID given ininit().
-
Constructor Details
-
GBAUCipher
protected GBAUCipher()Protected constructor
-
-
Method Details
-
getInstance
public static GBAUCipher getInstance(byte algorithm, boolean externalAccess) throws javacard.security.CryptoException Create an instance of theGBAUCipherclass with the selected cipher algorithm and padding algorithm.
Ks_int_NAF keys, internal keys generated during GBA_U process (see 3GPP TS 31.102 and 3GPP TS 33.220), are the only ones used in this class.
Ks_int_NAF keys are 256 bits symmetric keys then all asymmetric key algorithms are not supported.
- Parameters:
algorithm- the desired algorithm. Valid codes listed inALG_*constants in this class orCipherclass fromjavacardx.cryptopackage e.g.ALG_AES_BLOCK_256_CBC_NOPAD.externalAccess-trueindicates that the instance will be shared among multiple applet instances and that theGBAUCipherinstance will also be accessed (via a Shareable interface) when the owner of theGBAUCipherinstance is not the currently selected applet. Iftruethe implementation must not allocateCLEAR_ON_DESELECTtransient space for internal data.- Returns:
GBAUCipherobject of the requested algorithm;- Throws:
javacard.security.CryptoException- with the following reason codes:CryptoException.NO_SUCH_ALGORITHMif the requested algorithm is not supported.
- See Also:
-
getInstance
public static GBAUCipher getInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess) throws javacard.security.CryptoException Create an instance of theGBAUCipherclass.- Parameters:
cipherAlgorithm- the desired cipher algorithm. Valid codes listed inCIPHER_*constants in this class orCipherclass fromjavacardx.cryptopackage e.g.CIPHER_AES_CBC.paddingAlgorithm- the desired padding algorithm. Valid codes listed inPAD_*constants in this class orCipherclass fromjavacardx.cryptopackage e.g.PAD_NULL.externalAccess-trueindicates that the instance will be shared among multiple applet instances and that theGBAUCipherinstance will also be accessed (via a Shareable interface) when the owner of theGBAUCipherinstance is not the currently selected applet. Iftruethe implementation must not allocateCLEAR_ON_DESELECTtransient space for internal data.- Returns:
GBAUCipherobject of the requested algorithm;- Throws:
javacard.security.CryptoException- with the following reason codes:CryptoException.NO_SUCH_ALGORITHMif the at least one requested algorithm is not supported.
- See Also:
-
init
public abstract void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key). This method should be used for algorithms which do not need initialization parameters or use default parameter values.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Ifinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)is used, the key length is implicitly selected:- AES will use the Ks_int_NAF on 256 bits.
- Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- SM4 will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
Useinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)for different key length.- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID value- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if key size is incompatible with algorithm defined in getInstance().
NullPointerException- ifadfAIDornafIDisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray bounds- See Also:
-
getInstance(byte algorithm, boolean externalAccess)getInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)
-
init
public abstract void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key). This method should be used for algorithms which do not need initialization parameters or use default parameter values.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Depending onkeyLengthparameter the key is retrieved from Ks_int_NAF as follows:LENGTH_AES_128will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_192will use the 192 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_256will use all the 256 bits of the Ks_int_NAF 256 bits key.LENGTH_KOREAN_SEED_128Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_SM4will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID valuekeyLength- the key size in bits. The valid key bit length is key type dependent. Some common key lengths are listed inLENGTH_*constants in theKeyBuilderclass fromjavacard.securitye.g.LENGTH_AES_128.- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if keyLength is incompatible with algorithm defined in getInstance().
NullPointerException- ifadfAIDornafIDisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray bounds- Since:
- 1.2
- See Also:
-
getInstance(byte algorithm, boolean externalAccess)getInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)
-
init
public abstract void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Ifinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)is used, the key length is implicitly selected:- AES will use the Ks_int_NAF on 256 bits.
- Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- SM4 will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
Useinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)for different key length.- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID valuebArray- byte array containing algorithm specific initialization infobOff- offset within bArray where the algorithm specific data beginsbLen- byte length of algorithm specific parameter data- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if key size is incompatible with algorithm defined in getInstance().
NullPointerException- ifadfAID,nafIDorbArrayisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray boundsArrayIndexOutOfBoundsException- if the check operation onbOfforbLenwould cause access of data outsidebArrayarray bounds- See Also:
-
getInstance(byte algorithm, boolean externalAccess)getInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)
-
init
public abstract void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Depending onkeyLengthparameter the key is retrieved from Ks_int_NAF as follows:LENGTH_AES_128will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_192will use the 192 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_256will use all the 256 bits of the Ks_int_NAF 256 bits key.LENGTH_KOREAN_SEED_128Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_SM4will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID valuebArray- byte array containing algorithm specific initialization infobOff- offset within bArray where the algorithm specific data beginsbLen- byte length of algorithm specific parameter datakeyLength- the key size in bits. The valid key bit length is key type dependent. Some common key lengths are listed inLENGTH_*constants in theKeyBuilderclass fromjavacard.securitye.g.LENGTH_AES_128.- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if keyLength is incompatible with algorithm defined in getInstance().
NullPointerException- ifadfAID,nafIDorbArrayisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray boundsArrayIndexOutOfBoundsException- if the check operation onbOfforbLenwould cause access of data outsidebArrayarray bounds- Since:
- 1.2
- See Also:
-
getInstance(byte algorithm, boolean externalAccess)getInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)
-
update
public abstract short update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws javacard.security.CryptoException Continues a multiple-part encryption or decryption operation, processing additional input data using Ks_int_NAF linked to NAF ID given ininit().
This method requires temporary storage of intermediate results. In addition, if the input data length is not block aligned (multiple of block size) then additional internal storage may be allocated at this time to store a partial input data block. This may result in additional resource consumption and/or slow performance.
This method should only be used if all the input data required for the cipher is not available in one byte array. If all the input data required for the cipher is located in a single byte array, use of thedoFinal()method to process all of the input data is recommended. ThedoFinal()method must be invoked to complete processing of any remaining input data buffered by one or more calls to theupdate()method.
Note:- When using block-aligned data (multiple of block size), if the input buffer,
inBuffand the output buffer,outBuffare the same array, then the output data area must not partially overlap the input data area such that the input data is modified before it is used; ifinBuff==outBuffandinOffset < outOffset < inOffset+inLength, incorrect output may result. - When non-block aligned data is presented as input data, no amount of input and output buffer data overlap is allowed;
if
inBuff==outBuffandoutOffset < inOffset+inLength, incorrect output may result. - On decryption operations (except when ISO 9797 method 1 padding is used), the padding bytes are not written to
outBuff. - On encryption and decryption operations, block alignment considerations may require that the number of bytes output into
outBuffbe larger or smaller thaninLengthor even 0. - If
inLengthis 0 this method does nothing.
- Parameters:
inBuff- the input buffer of data to be encrypted/decryptedinOffset- the offset into the input buffer at which to begin encryption/decryptioninLength- the byte length to be encrypted/decryptedoutBuff- the output buffer, may be the same as the input bufferoutOffset- the offset into the output buffer where the resulting ciphertext/plaintext begins- Returns:
- number of bytes output in outBuff.
- Throws:
javacard.security.CryptoException- with the following reason codes:CryptoException.UNINITIALIZED_KEYif the key (Ks_int_NAF key) is uninitialized.CryptoException.INVALID_INITif thisGBAUCipherobject is not initialized.CryptoException.ILLEGAL_USEif the input message length is not supported or the message value is greater than or equal to the modulus.
NullPointerException- ifinBufforoutBuffisnullArrayIndexOutOfBoundsException- if the check operation oninOffsetorinLengthwould cause access of data outsideinBuffarray boundsArrayIndexOutOfBoundsException- if the check operation onoutOffsetwould cause access of data outsideoutBuffarray bounds- See Also:
-
getInstance(byte algorithm, boolean externalAccess)getInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
- When using block-aligned data (multiple of block size), if the input buffer,
-
doFinal
public abstract short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws javacard.security.CryptoException Generates encrypted/decrypted output from all/last input data using Ks_int_NAF linked to NAF ID given ininit(). This method must be invoked to complete a cipher operation. This method processes any remaining input data buffered by one or more calls to theupdate()method as well as input data supplied in theinBuffparameter.
A call to this method also resets this Cipher object to the state it was in when previously initialized via a call toinit()methods. That is, the object is reset and available to encrypt or decrypt (depending on the operation mode that was specified in the call toinit()methods) more data. In addition, note that the initial vector(IV) used in AES, DES, Korean SEED and SM4 algorithms will be reset to 0.
Note:- When using block-aligned data (multiple of block size), if the input buffer,
inBuffand the output buffer,outBuffare the same array, then the output data area must not partially overlap the input data area such that the input data is modified before it is used; ifinBuff==outBuffandinOffset < outOffset < inOffset+inLength, incorrect output may result. - When non-block aligned data is presented as input data, no amount of input and output buffer data overlap is allowed;
if
inBuff==outBuffandoutOffset < inOffset+inLength, incorrect output may result. - AES, DES, triple DES, Korean SEED and SM4 algorithms in CBC mode reset the initial vector(IV) to 0.
The initial vector(IV) can be re-initialized using the
init()methods. - On decryption operations (except when ISO 9797 method 1 padding is used), the padding bytes are not written to
outBuff. - On encryption and decryption operations, the number of bytes output into
outBuffmay be larger or smaller than inLength or even 0. - On decryption operations resulting in an
ArrayIndexOutOfBoundsException,outBuffmay be partially modified.
- Parameters:
inBuff- the input buffer of data to be encrypted/decryptedinOffset- the offset into the input buffer at which to begin encryption/decryptioninLength- the byte length to be encrypted/decryptedoutBuff- the output buffer, may be the same as the input bufferoutOffset- the offset into the output buffer where the resulting output data begins- Returns:
- number of bytes output in outBuff.
- Throws:
javacard.security.CryptoException- with the following reason codes:CryptoException.UNINITIALIZED_KEYif the key (Ks_int_NAF key) is uninitialized.CryptoException.INVALID_INITif thisGBAUCipherobject is not initialized.CryptoException.ILLEGAL_USEif one of the following conditions is met- This
GBAUCipheralgorithm does not pad the message and the message is not block aligned. - This
GBAUCipheralgorithm does not pad the message and no input data has been provided ininBuffor via theupdate()method. - The decrypted data is not bounded by appropriate padding bytes.
- This
NullPointerException- ifinBufforoutBuffisnullArrayIndexOutOfBoundsException- if the check operation oninOffsetorinLengthwould cause access of data outsideinBuffarray boundsArrayIndexOutOfBoundsException- if the check operation onoutOffsetwould cause access of data outsideoutBuffarray bounds- See Also:
-
getInstance(byte algorithm, boolean externalAccess)getInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
- When using block-aligned data (multiple of block size), if the input buffer,
-
getAlgorithm
public abstract byte getAlgorithm()Gets the cipher algorithm. Pre-defined codes listed inALG_*constants injavacardx.crypto.Ciphere.g.ALG_AES_BLOCK_128_CBC_NOPAD.- Returns:
- the algorithm code defined above; if the algorithm is not one of the pre-defined algorithms, 0 is returned.
- See Also:
-
getCipherAlgorithm
public abstract byte getCipherAlgorithm()Gets the raw cipher algorithm. Pre-defined codes listed in CIPHER_* constants injavacardx.crypto.Ciphere.g. CIPHER_AES_CBC.- Returns:
- the raw cipher algorithm code defined above; if the algorithm is not one of the pre-defined algorithms, 0 is returned.
- See Also:
-
getPaddingAlgorithm
public abstract byte getPaddingAlgorithm()Gets the padding algorithm. Pre-defined codes listed in PAD_* constants injavacardx.crypto.Ciphere.g. PAD_NULL.- Returns:
- the padding algorithm code defined in the Cipher class; if the algorithm is not one of the pre-defined algorithms, 0 is returned.
- See Also:
-