CmCrypt2
Description
CmCrypt2 encrypts or decrypts data using direct or indirect encryption (see Encryption Modes) via a CmContainer entry.
Syntax
int CMAPIENTRY CmCrypt2(HCMSysEntry hcmse, CMULONG flCtrl, CMCRYPT2 *pcmCrypt, void* pvDest, CMUINT cbDest)
Parameter
hcmse contains a handle opened by CmAccess2. Access Mode must be Entry Access to the Firm Code:Product Code entry used for en-/decryption. For software encryption (CM_CRYPT_AES_ENC_CBC_DIRECT or CM_CRYPT_AES_DEC_CBC_DIRECT) this has to be NULL.
flCtrl contains the encryption or decryption command. Following commands are supported:
CM_CRYPT_DIRECT_ENC executes the direct symmetric encryption via a CmContainer entry. The length of bytes to encrypt must be exactly 16 bytes (for CM_CRYPT_AES) or between 0 and 32 bytes (for CM_CRYPT_ECIES and CM_CRYPT_ECIES_STD) - see structure
CMBASECRYPT2.
|
CMBASECRYPT2 stores all needed parameters needed for every possible en- or decryption. Syntax
Parameter mflCtrl contains commands and flags influencing the en- or decryption. The parameter can use the following flags: Used Key:
Used Encryption Algorithm:
•d (private key) in SecretData ExtType 130 •p (secret prime) in SecretData ExtType 131 •q (secret prime) in SecretData ExtType 132 Requirements: •For d, p, and q exactly these ExtTypes must be programmed. •For security reasons these SecretData types must be programmed in this exact sequence. First ExtType 130, then 131, and finally 132. If programmed in another order, the respective preceeding SecretData fields are overwritten. •All three numbers must be specified using Little Endian. CM_CRYPT_RSA requires at least a CmContainer Firmware version 1.11. Then key lengths up to 1024 bytes are supported. Firmware version 2.02 and higher supports key lengths up to 2048 bytes. CRC calculation: The algorithm CRC-32 is used to calculate the CRC checksum of the data.
mulKeyExtType specifies the key source, if the encryption is done with a Hidden Data or a Secret Data. mulEncryptionCode contains the Encryption Code set by the user. mulEncryptionCodeOptions contains one or more of the following flags:
mulFeatureCode specifies the Feature Code mapping for the existing Feature Map. The operation fails, if the Feature Code contains bits which do not exist in the Feature Map. mcmReleaseDate specifies the Release Date in a
mulCrc contains the CRC value of the current operation. It depends on the CM_CRYPT_CALCCRC or CM_CRYPT_CHKCRC flags, if this value is set or checked.
|
CM_CRYPT_DIRECT_DEC executes the direct symmetric decryption via a CmContainer entry. The length of bytes to decrypt must be exactly 16 bytes (for CM_CRYPT_AES) or between 0 and 32 bytes (for CM_CRYPT_ECIES and CM_CRYPT_ECIES_STD) - see CMBASECRYPT2.
|
Wibu-Systems recommends this mode since CBC is the most commonly used mode of operation. Although CodeMeter supports also other older cryptographic modes. However, their use is not recommended. For more information see the technical guideline TR-02102-1 "Cryptographic Mechanisms: Recommendations and Key Lengths" (courtesy translation) edited by the German Federal Office for Information Security, BSI (Bundesamt für Sicherheit in der Informationstechnik) (BSI). |
CM_CRYPT_AES_ENC_CBC executes the indirect encryption using the AES block cipher algorithm with CBC.
By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.
|
cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen. If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS. If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB. |
CM_CRYPT_AES_DEC_CBC executes the indirect decryption using the AES block cipher algorithm with CBC.
By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.
|
cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen. If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS. If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB. |
CM_CRYPT_AES_ENC_CBC_DIRECT executes the encryption using the original AES block cipher algorithm with CBC.
By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.
|
cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen. If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS. If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB. |
It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in mabDirectAesKey, the initialization vector in mabInitKey - both see structure
CMCRYPT2).
|
CMCRYPT2 contains all needed parameters for an encryption with a CmContainer using CmCrypt2 Syntax
Parameter mcmBaseCrypt contains all needed parameters for an encryption (see CMBASECRYPT2). mabDirectAesKey contains the AES key for an encryption/decryption without CmContainer using original AES. This is only used for CmCrypt2 with the flags CM_CRYPT_AES_ENC_CBC_DIRECT or CM_CRYPT_AES_DEC_CBC_DIRECT (see also Encryption Modes). mabInitKey contains the key for the indirect encryption (see Encryption Modes). For an encryption/decryption without hardware using CmCrypt2 with the flags CM_CRYPT_AES_ENC_CBC_DIRECT or CM_CRYPT_AES_DEC_CBC_DIRECT use this member to set the initialization vector (IV).
|
CM_CRYPT_AES_DEC_CBC_DIRECT executes the decryption using the original AES block cipher algorithm with CBC.
By default, the method CTS is used. CTS stands for ciphertext stealing, i.e. swapping the final two ciphertext blocks, also in the case that cbDest is a multiple of the blocksize.
Moreover, CTS allows unpadded data, that has a length not a multiple of the block site (16 bytes), to be encrypted to the same length of the cipher text.
|
cbDest must always be equal to or larger than 16 bytes. The initialization vector (IV) is never stolen. If cbDest equals 16 bytes, the encryption results corresponds to the encryption using standard AES CBC without CTS. If cbDest equals 16 bytes and the initialization vector (IV) equals a value of 0, the encryption result corresponds to ECB. |
It does not use any CodeMeter license, therefore use NULL for hcmse. The AES key has to be placed in mabDirectAesKey, the initialization vector in mabInitKey - both see structure
CMCRYPT2).
|
CMCRYPT2 contains all needed parameters for an encryption with a CmContainer using CmCrypt2 Syntax
Parameter mcmBaseCrypt contains all needed parameters for an encryption (see CMBASECRYPT2). mabDirectAesKey contains the AES key for an encryption/decryption without CmContainer using original AES. This is only used for CmCrypt2 with the flags CM_CRYPT_AES_ENC_CBC_DIRECT or CM_CRYPT_AES_DEC_CBC_DIRECT (see also Encryption Modes). mabInitKey contains the key for the indirect encryption (see Encryption Modes). For an encryption/decryption without hardware using CmCrypt2 with the flags CM_CRYPT_AES_ENC_CBC_DIRECT or CM_CRYPT_AES_DEC_CBC_DIRECT use this member to set the initialization vector (IV).
|
pcmCrypt sets some needed data for the en-/decryption process (see CMCRYPT2).
pvDest contains the data to en-/decrypt.
cbDest contains the number of bytes to en-/decrypt stored in pvDest.
Return
This function returns the number of en-/decrypted bytes. If an error occurred, 0 will be returned.
Notes
CmCrypt2() is supported since CodeMeter Version 4.30.
Crypt sets some needed data for the en-/decryption process (see CmCrypt2).
Dest contains the data to encrypt or decrypt.
Return
This function returns true. If an error occurred, false will be returned.
Notes
CmCrypt2() is supported since CodeMeter Version 4.30.