C H A P T E R  13

Using Cryptography Extensions

This chapter describes how to use the basic security and cryptography classes, which do not appear in all Java Card development kits. For the location of cryptography files in the development kit, see Installed Files and Directories.

The security and cryptography classes are supported by the RI (cref). The support for security and cryptography allows you to:



Note - DES is also known as single-key DES. 3DES is also known as triple-DES.


For more information on the SHA1, DES, 3DES, and RSA encryption schemes, see:


Supported Cryptography Classes

The implementation of security and cryptography in version 3.0.3 of the RI supports the use of the following classes:



Note - In version 3.0.3 of the RI, the implementation of RandomData is not suitable for porting.


TABLE 13-1 lists the cryptography algorithms that are implemented for the RI.


TABLE 13-1 Algorithms Implemented by the Cryptography Classes

Class

Algorithm

Checksum

  • ALG_ISO3309_CRC16--ISO/IEC 3309-compliant 16-bit CRC algorithm. This algorithm uses the generator polynomial: x^16+x^12+x^5+1. The default initial checksum value used by this algorithm is 0. This algorithm is also compliant with the frame-checking sequence as specified in section 4.2.5.2 of the ISO/IEC 13239 specification.
  • ALG_ISO3309_CRC32--ISO/IEC 3309-compliant 32-bit CRC algorithm. This algorithm uses the generator polynomial: X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8 +X^7+X^5+X^4+X^2+X+1. The default initial checksum value used by this algorithm is 0. This algorithm is also compliant with the frame-checking sequence as specified in section 4.2.5.3 of the ISO/IEC 13239 specification.

Cipher

  • ALG_DES_CBC_ISO9797_M2--provides a cipher using DES in CBC mode. This algorithm uses CBC for DES and 3DES. Input data is padded according to the ISO 9797 method 2 (ISO 7816-4, EMV’96) scheme.
  • ALG_RSA_PKCS1--provides a cipher using RSA. Input data is padded according to the PKCS#1 (v1.5) scheme.
  • ALG_AES_BLOCK_128_CBC_NOPAD--provides a cipher using AES with block size 128 in CBC mode and does not pad input data.

InitializedMessageDigest

Provides the functionality of MessageDigest, with the additional ability to allow for initialization with a starting hash value corresponding to a previously hashed part of the message. Provide for SHA1 and SHA256.

KeyAgreement

  • ALG_EC_SVDP_DH--elliptic curve secret value derivation primitive, Diffie-Hellman version, as per [IEEE P1363].
  • ALG_EC_SVDP_DHC--elliptic curve secret value derivation primitive, Diffie-Hellman version, with cofactor multiplication, as per [IEEE P1363].

KeyBuilder

The algorithms define the key lengths for:

  • 128-bit AES
  • 64-bit DES
  • 112-, 128-, 160-, 192-bit ECC
  • 128-bit DES3
  • 512-bit RSA

KeyPair

The algorithms define the key lengths for:

  • 112-, 128-, 160-, 192-bit ECC
  • 512-bit RSA

MessageDigest

Message digest algorithm SHA1 and SHA256

RandomData

Pseudo-random number generator with a 48-bit seed, which is modified using a linear congruential formula.

Signature

  • ALG_DES_MAC8_ISO9797_M2--generates an 8-byte MAC (most significant 8 bytes of encrypted block) using DES or 3DES in CBC mode. This algorithm uses CBC for DES and 3DES. Input data is padded according to the ISO 9797 method 2 (ISO 7816-4, EMV’96) scheme.
  • ALG_RSA_SHA_PKCS1--encrypts the 20 byte SHA1 digest using RSA. The digest is padded according to the PKCS#1 (v1.5) scheme.
  • ALG_AES_MAC_128_NOPAD--generates a 16-byte MAC using AES with blocksize 128 in CBC mode and does not pad input data.
  • ALG_ECDSA_SHA--signs/verifies the 20-byte SHA digest using ECDSA.

SignatureMessageRecovery

  • ALG_RSA_SHA_ISO9796_MR--This algorithm uses the first part of the input message as padding bytes during signing. During verification, these message bytes (recoverable message) can be recovered to reconstruct the message.

Instantiating the Classes

Implementations of the cryptography classes extend the corresponding base class with implementations of their abstract methods. All data allocation associated with the implementation instance is performed when the instance is constructed. This is done to ensure that any lack of required resources can be flagged when the applet is installed.

Each cryptography class, except KeyPair, has a getInstance method which takes the desired algorithm as one of its parameters. The method returns an instance of the class in the context of the calling applet. Instead of using a getInstance method, KeyPair takes the desired algorithm as a parameter in its constructor.

If you request an algorithm that is not listed in TABLE 13-1 or that is not implemented in this release, getInstance will throw a CryptoException with reason code NO_SUCH_ALGORITHM.