CryptoSys API  6.22.1
Typedefs | Functions
diCryptoSys.h File Reference

The C/C++ interface to the diCryptoSys library. More...

Typedefs

typedef int int32_t
 Default for signed 32-bit integer type if int32_t not defined.
 

Functions

long AEAD_AddAAD (long hContext, const unsigned char *lpAAD, long nAadLen)
 Add a chunk of additional authenticated data (in incremental mode). More...
 
long AEAD_Decrypt (unsigned char *lpOutput, long nOutLen, const unsigned char *lpData, long nDataLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpNonce, long nNonceLen, const unsigned char *lpAAD, long nAadLen, const unsigned char *lpTag, long nTagLen, long nOptions)
 Decrypt and authenticate input using specified AEAD algorithm in one-off operation. More...
 
long AEAD_DecryptWithTag (unsigned char *lpOutput, long nOutLen, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpNonce, long nNonceLen, const unsigned char *lpAAD, long nAadLen, long nOptions)
 Decrypt and authenticate input using specified AEAD algorithm in one-off operation. More...
 
long AEAD_Destroy (long hContext)
 Closes the AEAD context and destroys the key (in incremental mode). More...
 
long AEAD_Encrypt (unsigned char *lpOutput, long nOutLen, unsigned char *lpTagOut, long nTagLen, const unsigned char *lpData, long nDataLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpNonce, long nNonceLen, const unsigned char *lpAAD, long nAadLen, long nOptions)
 Encrypt input using specified AEAD algorithm in one-off operation. More...
 
long AEAD_EncryptWithTag (unsigned char *lpOutput, long nOutLen, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpNonce, long nNonceLen, const unsigned char *lpAAD, long nAadLen, long nOptions)
 Encrypt input using specified AEAD algorithm in one-off operation with the authentication tag appended to output. More...
 
long AEAD_FinishDecrypt (long hContext)
 Finishes the authenticated decryption (in incremental mode) . More...
 
long AEAD_FinishEncrypt (long hContext, unsigned char *lpTagOut, long nTagLen)
 Finishes the authenticated encryption (in incremental mode) . More...
 
long AEAD_InitKey (const unsigned char *lpKey, long nKeyLen, long nOptions)
 Initializes the context with the key and algorithm ready for repeated incremental operations. More...
 
long AEAD_SetNonce (long hContext, const unsigned char *lpNonce, long nNonceLen)
 Set the nonce (in incremental mode). More...
 
long AEAD_StartDecrypt (long hContext, const unsigned char *lpTagToCheck, long nTagLen)
 Start authenticated decryption (in incremental mode). More...
 
long AEAD_StartEncrypt (long hContext)
 Start authenticated encryption (in incremental mode). More...
 
long AEAD_Update (long hContext, unsigned char *lpOutput, long nOutLen, const unsigned char *lpData, long nDataLen)
 Encrypts or decrypts a chunk of input (in incremental mode). More...
 
long AES128_B64Mode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a base64 string using a specified mode. More...
 
long AES128_Bytes (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt)
 Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode. More...
 
long AES128_BytesMode (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts an array of Bytes using a specified mode. More...
 
long AES128_File (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long AES128_FileExt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV, long nOptions)
 Encrypts or decrypts a file using a specified mode. More...
 
long AES128_FileHex (const char *szFileOut, const char *szFileIn, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long AES128_Final (long hContext)
 Closes and clears the AES context. More...
 
long AES128_Hex (char *szOutput, const char *szInput, const char *szKey, int fEncrypt)
 Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. More...
 
long AES128_HexMode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a hexadecimal string using a specified mode. More...
 
long AES128_Init (const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the AES function. More...
 
long AES128_InitError (void)
 Returns the error code after an unsuccessful call to AES128_Init or AES128_InitHex. More...
 
long AES128_InitHex (const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the AES function. More...
 
long AES128_Update (long hContext, unsigned char *lpData, long nDataLen)
 Carries out the AES transformation function on a byte array according to the direction and mode set up by an earlier call to AES128_Init() or AES128_InitHex(). More...
 
long AES128_UpdateHex (long hContext, char *szHexData)
 Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES128_Init() or AES128_InitHex(). More...
 
long AES192_B64Mode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a base64 string using a specified mode. More...
 
long AES192_Bytes (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt)
 Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode. More...
 
long AES192_BytesMode (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts an array of Bytes using a specified mode. More...
 
long AES192_File (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long AES192_FileExt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV, long nOptions)
 Encrypts or decrypts a file using a specified mode with extended options. More...
 
long AES192_FileHex (const char *szFileOut, const char *szFileIn, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long AES192_Final (long hContext)
 Closes and clears the AES context. More...
 
long AES192_Hex (char *szOutput, const char *szInput, const char *szKey, int fEncrypt)
 Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. More...
 
long AES192_HexMode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a hexadecimal string using a specified mode. More...
 
long AES192_Init (const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the AES function. More...
 
long AES192_InitError (void)
 Returns the error code after an unsuccessful call to AES192_Init or AES192_InitHex. More...
 
long AES192_InitHex (const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the AES function. More...
 
long AES192_Update (long hContext, unsigned char *lpData, long nDataLen)
 Carries out the AES transformation function on a byte array according to the direction and mode set up by an earlier call to AES192_Init() or AES192_InitHex(). More...
 
long AES192_UpdateHex (long hContext, char *szHexData)
 Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES192_Init() or AES192_InitHex(). More...
 
long AES256_B64Mode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a base64 string using a specified mode. More...
 
long AES256_Bytes (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt)
 Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode. More...
 
long AES256_BytesMode (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts an array of Bytes using a specified mode. More...
 
long AES256_File (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long AES256_FileExt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV, long nOptions)
 Encrypts or decrypts a file using a specified mode with extended options. More...
 
long AES256_FileHex (const char *szFileOut, const char *szFileIn, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long AES256_Final (long hContext)
 Closes and clears the AES context. More...
 
long AES256_Hex (char *szOutput, const char *szInput, const char *szKey, int fEncrypt)
 Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. More...
 
long AES256_HexMode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a hexadecimal string using a specified mode. More...
 
long AES256_Init (const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the AES function. More...
 
long AES256_InitError (void)
 Returns the error code after an unsuccessful call to AES256_Init or AES256_InitHex. More...
 
long AES256_InitHex (const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the AES function. More...
 
long AES256_Update (long hContext, unsigned char *lpData, long nDataLen)
 Carries out the AES transformation function on a byte array according to the direction and mode set up by an earlier call to AES256_Init() or AES256_InitHex(). More...
 
long AES256_UpdateHex (long hContext, char *szHexData)
 Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES256_Init() or AES256_InitHex(). More...
 
long API_CompileTime (char *szOutput, long nMaxChars)
 Retrieves the date and time the core library executable was last compiled. More...
 
long API_ErrorCode (void)
 Returns the error code of the error that occurred when calling the last function. More...
 
long API_ErrorLookup (char *szOutput, long nMaxChars, long nErrCode)
 Retrieves the error message associated with a given error code. More...
 
long API_LicenceType (long nOptions)
 Returns the ASCII value of the licence type. More...
 
long API_ModuleInfo (char *szOutput, long nOutChars, long nOptions)
 Get additional information about the core DLL module. More...
 
long API_ModuleName (char *szOutput, long nMaxChars, long nOptions)
 Retrieves the name of the current process's module. More...
 
long API_Platform (char *szOutput, long nOutChars)
 Gets the platform the core DLL was compiled for. More...
 
long API_PowerUpTests (long nOptions)
 Carries out on demand the full set of power-up tests automatically performed by the toolkit when first powered up (i.e. More...
 
long API_Version (void)
 Retrieves the release version number. More...
 
long BLF_B64Mode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a base64 string using a specified mode. More...
 
long BLF_Bytes (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, long keyBytes, int fEncrypt)
 Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode. More...
 
long BLF_BytesMode (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, long keyBytes, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts an array of Bytes using a specified mode. More...
 
long BLF_File (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long keyBytes, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long BLF_FileExt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long keyBytes, int fEncrypt, const char *szMode, const unsigned char *lpIV, long nOptions)
 Encrypts or decrypts a file using a specified mode with extended options. More...
 
long BLF_FileHex (const char *szFileOut, const char *szFileIn, const char *szKey, int fEncrypt, const char *szMode, const char *sHexIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long BLF_Final (long hContext)
 Closes and clears the BLF context. More...
 
long BLF_Hex (char *szOutput, const char *szInput, const char *szKey, int fEncrypt)
 Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. More...
 
long BLF_HexMode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a hexadecimal string using a specified mode. More...
 
long BLF_Init (const unsigned char *lpKey, long keyBytes, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the BLF_Update or BLF_UpdateHex functions. More...
 
long BLF_InitError (void)
 Returns the error code after an unsuccessful call to BLF_Init or BLF_InitHex. More...
 
long BLF_InitHex (const char *szKey, int fEncrypt, const char *szMode, const char *sHexIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the BLF_Update or BLF_UpdateHex functions. More...
 
long BLF_Update (long hContext, unsigned char *lpData, long nDataLen)
 Carries out the Blowfish transformation function on a byte array according to the direction and mode set up by an earlier call to BLF_Init() or BLF_InitHex(). More...
 
long BLF_UpdateHex (long hContext, char *szHexData)
 Carries out the Blowfish transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to BLF_Init() or BLF_InitHex(). More...
 
long CIPHER_DecryptBytes (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions)
 Decrypts data in a byte array using the specified block cipher algorithm, mode and padding. More...
 
long CIPHER_DecryptHex (char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex, const char *szIvHex, const char *szAlgModePad, long nOptions)
 Decrypt data using the specified block cipher algorithm, mode and padding. More...
 
long CIPHER_EncryptBytes (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions)
 Encrypts data in a byte array using the specified block cipher algorithm, mode and padding. More...
 
long CIPHER_EncryptHex (char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex, const char *szIvHex, const char *szAlgModePad, long nOptions)
 Encrypt data using the specified block cipher algorithm, mode and padding. More...
 
long CIPHER_FileDecrypt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions)
 Decrypts a file using specified block cipher algorithm, mode and padding. More...
 
long CIPHER_FileEncrypt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions)
 Encrypts a file using specified block cipher algorithm, mode and padding. More...
 
long CIPHER_Final (long hContext)
 Closes and clears the CIPHER context. More...
 
long CIPHER_Init (int fEncrypt, const char *szAlgAndMode, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, long nOptions)
 Initialize the CIPHER context with the key, iv, algorithm and mode ready for repeated update operations. More...
 
long CIPHER_InitHex (int fEncrypt, const char *szAlgAndMode, const char *szKeyHex, const char *szIvHex, long nOptions)
 Initialize the CIPHER context with hex-encoded key, iv, algorithm and mode ready for repeated update operations. More...
 
long CIPHER_KeyUnwrap (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpData, long nDataLen, const unsigned char *lpKEK, long nKekLen, long nOptions)
 Unwraps (decrypts) a content-encryption key with a key-encryption key. More...
 
long CIPHER_KeyWrap (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpData, long nDataLen, const unsigned char *lpKEK, long nKekLen, long nOptions)
 Wraps a content-encryption key with a key-encryption key. More...
 
long CIPHER_StreamBytes (unsigned char *lpOutput, unsigned char *lpData, long nDataLen, unsigned char *lpKey, long nKeyLen, unsigned char *lpIV, long nIvLen, long nCounter, long nOptions)
 Enciphers data in array of bytes using specified stream cipher. More...
 
long CIPHER_StreamFile (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long nKeyLen, unsigned char *lpIV, long nIvLen, long nCounter, long nOptions)
 Enciphers data in a file using specified stream cipher. More...
 
long CIPHER_StreamFinal (long hContext)
 Closes the CIPHERSTREAM context and destroys the key. More...
 
long CIPHER_StreamHex (char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex, const char *szIvHex, long nCounter, long nOptions)
 Enciphers data in a hex-encoded string using specified stream cipher. More...
 
long CIPHER_StreamInit (const unsigned char *lpKey, long nKeyLen, unsigned char *lpIV, long nIvLen, long nCounter, long nOptions)
 Initializes the CIPHERSTREAM context ready for repeated operations of CIPHER_StreamUpdate() More...
 
long CIPHER_StreamUpdate (long hContext, unsigned char *lpOutput, unsigned char *lpData, long nDataLen)
 Encrypts input using current CIPHERSTREAM context. More...
 
long CIPHER_Update (long hContext, unsigned char *lpOutput, long nOutBytes, const unsigned char *lpData, long nDataLen)
 Encrypts or decrypts a chunk of input (in incremental mode). More...
 
long CIPHER_UpdateHex (long hContext, char *szOutput, long nOutChars, const char *szDataHex)
 Encrypts or decrypts a chunk of hexadecimal-encoded input (in incremental mode). More...
 
long CNV_B64Filter (char *szOutput, const char *szInput, long nInStrLen)
 Removes non-base64 characters from a string. More...
 
long CNV_B64StrFromBytes (char *szOutput, long nMaxChars, const unsigned char *lpInput, long nBytes)
 Encodes an array of bytes into a base64-encoded string. More...
 
long CNV_BytesFromB64Str (unsigned char *lpOutput, long nOutputLen, const char *szInput)
 Decodes a base64-encoded string into an array of Bytes. More...
 
long CNV_BytesFromHexStr (unsigned char *lpOutput, long nOutputLen, const char *szInput)
 Decodes a hexadecimal-encoded string into an array of Bytes. More...
 
long CNV_HexFilter (char *szOutput, const char *szInput, long nInStrLen)
 Removes non-hexadecimal characters from a string. More...
 
long CNV_HexStrFromBytes (char *szOutput, long nMaxChars, const unsigned char *lpInput, long nBytes)
 Encodes an array of bytes into a hexadecimal-encoded string. More...
 
long CNV_ShortPathName (char *szOut, long nOutChars, const wchar_t *szwFilePath)
 Retrieve the Windows short path form of the specified path. More...
 
long COMPR_Compress (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nOptions)
 Compress data using compression algorithm. More...
 
long COMPR_Uncompress (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nOptions)
 Uncompress data using compression algorithm. More...
 
int32_t CRC_Bytes (const unsigned char *lpInput, long nBytes, long nOptions)
 Computes the CRC-32 checksum of an array of bytes. More...
 
int32_t CRC_File (const char *szFileName, long nOptions)
 Computes the CRC-32 checksum of a file. More...
 
int32_t CRC_String (const char *szInput, long nOptions)
 Computes the CRC-32 checksum of an ANSI string. More...
 
long DES_B64Mode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a base64 string using a specified mode. More...
 
long DES_Bytes (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt)
 Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode. More...
 
long DES_BytesMode (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts an array of Bytes in one step using a specified mode. More...
 
long DES_CheckKey (const unsigned char *lpKey, long nKeyLen)
 Checks for weak or invalid-length DES or TDEA keys. More...
 
long DES_CheckKeyHex (const char *szHexKey)
 Checks for weak or invalid-length DES or TDEA keys in hexadecimal format. More...
 
long DES_File (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long DES_FileExt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV, long nOptions)
 Encrypts or decrypts a file using a specified mode with extended options. More...
 
long DES_FileHex (const char *szFileOut, const char *szFileIn, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long DES_Final (long hContext)
 Closes and clears the DES context. More...
 
long DES_Hex (char *szOutput, const char *szInput, const char *szKey, int fEncrypt)
 Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. More...
 
long DES_HexMode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a hexadecimal string using a specified mode. More...
 
long DES_Init (const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the DES function. More...
 
long DES_InitError (void)
 Returns the error code after an unsuccessful call to DES_Init or DES_InitHex. More...
 
long DES_InitHex (const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the DES function. More...
 
long DES_Update (long hContext, unsigned char *lpData, long nDataLen)
 Carries out the DES transformation function on a byte array according to the direction and mode set up by an earlier call to DES_Init() or DES_InitHex(). More...
 
long DES_UpdateHex (long hContext, char *szHexData)
 Carries out the DES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to DES_Init() or DES_InitHex(). More...
 
long GCM_Decrypt (unsigned char *lpOutput, long nOutLen, const unsigned char *lpData, long nDataLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const unsigned char *lpAAD, long nAadLen, const unsigned char *lpTag, long nTagLen, long nOptions)
 Decrypts authenticated ciphertext using the Galois/Counter Mode (GCM) of operation with the AES algorithm (AES-GCM). More...
 
long GCM_Encrypt (unsigned char *lpOutput, long nOutLen, unsigned char *lpTagOut, long nTagLen, const unsigned char *lpData, long nDataLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const unsigned char *lpAAD, long nAadLen, long nOptions)
 Provides authenticated encryption using the Galois/Counter Mode (GCM) of operation with the AES algorithm (AES-GCM). More...
 
long GCM_FinishKey (long hContext)
 Closes the GCM context and destroys the key. More...
 
long GCM_InitKey (const unsigned char *lpKey, long nKeyLen, long nOptions)
 Initializes the context with the key ready for repeated operations of GCM_NextEncrypt and GCM_NextDecrypt. More...
 
long GCM_NextDecrypt (long hContext, unsigned char *lpOutput, long nOutLen, const unsigned char *lpData, long nDataLen, const unsigned char *lpIV, long nIvLen, const unsigned char *lpAAD, long nAadLen, const unsigned char *lpTag, long nTagLen)
 Carries out the GCM authenticated decryption operation using the key set up by an earlier call to GCM_InitKey. More...
 
long GCM_NextEncrypt (long hContext, unsigned char *lpOutput, long nOutLen, unsigned char *lpTagOut, long nTagLen, const unsigned char *lpData, long nDataLen, const unsigned char *lpIV, long nIvLen, const unsigned char *lpAAD, long nAadLen)
 Carries out the GCM authenticated encryption operation using the key set up by an earlier call to GCM_InitKey. More...
 
long HASH_AddBytes (long hContext, const void *lpData, long nDataLen)
 Adds an array of bytes to be digested in the HASH context. More...
 
long HASH_Bytes (unsigned char *lpOutput, long nOutLen, const void *lpMessage, long nMsgLen, long nOptions)
 Creates a message digest hash as a byte array from byte data. More...
 
long HASH_DigestLength (long hContext)
 Returns the number of bytes in the hash output for the algorithm defined in the current HASH context. More...
 
long HASH_File (unsigned char *lpOutput, long nOutLen, const char *szFileName, long nOptions)
 Creates a message digest hash in byte format for a file. More...
 
long HASH_Final (unsigned char *lpOutput, long nOutLen, long hContext)
 Returns the final message digest value from the HASH context. More...
 
long HASH_HexFromBits (char *szOutput, long nMaxChars, const unsigned char *lpData, long nDataBitLen, long nOptions)
 Creates a message digest hash in hexadecimal format from bit-oriented input. More...
 
long HASH_HexFromBytes (char *szOutput, long nMaxChars, const void *lpMessage, long nMsgLen, long nOptions)
 Creates a message digest hash in hexadecimal format from byte (or string) data. More...
 
long HASH_HexFromFile (char *szOutput, long nMaxChars, const char *szFileName, long nOptions)
 Creates a message digest hash in hexadecimal format for a file. More...
 
long HASH_HexFromHex (char *szOutput, long nMaxChars, const char *szMsgHex, long nOptions)
 Creates a message digest hash in hexadecimal format from data in a hexadecimal-encoded string. More...
 
long HASH_Init (long nAlg)
 Initialises the HASH context ready for subsequent calls with HASH_AddBytes and HASH_Final. More...
 
long HASH_Length (long nAlgId)
 Return length of message digest output in bytes. More...
 
long HASH_Reset (long hContext)
 Resets the HASH context. More...
 
long MAC_AddBytes (long hContext, const void *lpData, long nDataLen)
 Adds an array of bytes to be authenticated in the MAC context. More...
 
long MAC_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, const void *lpKey, long nKeyLen, long nOptions)
 Creates a keyed message authentication code (MAC) as a byte array from byte data. More...
 
long MAC_CodeLength (long hContext)
 Returns the number of bytes in the output for the algorithm defined in the current MAC context. More...
 
long MAC_Final (unsigned char *lpOutput, long nOutLen, long hContext)
 Returns the final message digest value from the MAC context. More...
 
long MAC_HexFromBytes (char *szOutput, long nMaxChars, const void *lpMessage, long nMsgLen, const void *lpKey, long nKeyLen, long nOptions)
 Creates a keyed-hash based message authentication code (HMAC) in hexadecimal format from byte data. More...
 
long MAC_HexFromHex (char *szOutput, long nMaxChars, const char *szMsgHex, const char *szKeyHex, long nOptions)
 Creates a message authentication code (MAC) in hexadecimal format from hex-encoded data and a hex-encoded key. More...
 
long MAC_Init (const void *lpKey, long nKeyLen, long nAlg)
 Initialises the MAC context ready for subsequent calls with MAC_AddBytes and MAC_Final. More...
 
long MAC_Reset (long hContext)
 Resets the MAC context. More...
 
long MD5_AddBytes (long hContext, const unsigned char *lpData, long nDataLen)
 Adds an array of bytes to the digest. More...
 
long MD5_AddString (long hContext, const char *szMessage)
 Adds a string of ascii characters to the digest. More...
 
long MD5_BytesHash (unsigned char *digest, const unsigned char *lpData, long nDataLen)
 Creates an MD5 message digest in Byte array format from a message in Byte array format. More...
 
long MD5_BytesHexHash (char *szDigest, const unsigned char *lpData, long nDataLen)
 Creates an MD5 message digest in hexadecimal format from a message in Byte array format. More...
 
long MD5_FileHexHash (char *szDigest, const char *szFileName, const char *szMode)
 Creates an MD5 message digest in hexadecimal format from a file. More...
 
long MD5_HexDigest (char *szDigest, long hContext)
 Returns the final message digest value as a hex string. More...
 
long MD5_Hmac (char *szDigest, const unsigned char *textBytes, long textLen, const unsigned char *lpKeyBytes, long keyLen)
 Is a keyed-hash function that provides message authentication using the HMAC algorithm and the MD5 hash function. More...
 
long MD5_HmacHex (char *szDigest, const char *szHexText, const char *szHexKey)
 Is a keyed-hash function that provides message authentication using the HMAC algorithm and the MD5 hash function, passing its arguments in hexadecimal format. More...
 
long MD5_Init (void)
 Initialises the MD5 context ready for subsequent calls with MD5_AddString, MD5_AddBytes, and MD5_HexDigest. More...
 
long MD5_Reset (long hContext)
 Resets the context. More...
 
long MD5_StringHexHash (char *szDigest, const char *szMessage)
 Creates an MD5 message digest in hexadecimal format from a message of String type. More...
 
long PAD_BytesBlock (unsigned char *lpOutput, long nOutputLen, const unsigned char *lpInput, long nBytes, long nBlkLen, long nOptions)
 Creates an input block suitably padded for encryption by a block cipher in ECB or CBC mode. More...
 
long PAD_HexBlock (char *szOutput, long nMaxChars, const char *szInput, long nBlkLen, long nOptions)
 Creates a hex-encoded input block suitably padded for encryption by a block cipher in ECB or CBC mode. More...
 
long PAD_UnpadBytes (unsigned char *lpOutput, long nOutputLen, const unsigned char *lpInput, long nBytes, long nBlkLen, long nOptions)
 Removes the padding from an encryption block. More...
 
long PAD_UnpadHex (char *szOutput, long nMaxChars, const char *szInput, long nBlkLen, long nOptions)
 Removes the padding from a hex-encoded encryption block. More...
 
long PBE_Kdf2 (unsigned char *lpDerivedKey, long nKeyLen, const unsigned char *lpPwd, long nPwdLen, const unsigned char *lpSalt, long nSaltLen, long nCount, long nOptions)
 Derives a key of any length from a password using the PBKDF2 algorithm from PKCS#5 v2.1. More...
 
long PBE_Kdf2Hex (char *szOutput, long nMaxChars, long dkBytes, const char *szPwd, const char *szSaltHex, long nCount, long nOptions)
 Derives a key of any length from a password using the PBKDF2 algorithm from PKCS#5 v2.1 with the salt and derived key encoded in hexadecimal. More...
 
long PBE_Scrypt (unsigned char *lpDerivedKey, long nKeyLen, const unsigned char *lpPwd, long nPwdLen, const unsigned char *lpSalt, long nSaltLen, long nParamN, long nParamR, long nParamP, long nOptions)
 Derives a key of any length from a password using the SCRYPT algorithm. More...
 
long PBE_ScryptHex (char *szOutput, long nMaxChars, long dkBytes, const char *szPwd, const char *szSaltHex, long nParamN, long nParamR, long nParamP, long nOptions)
 Derives a key of any length from a password using the SCRYPT algorithm with the salt and derived key encoded in hexadecimal. More...
 
long PC1_Bytes (unsigned char *lpOutput, unsigned char *lpInput, long nBytes, unsigned char *lpKey, long nKeyBytes)
 Enciphers an array of Bytes in one step using the RC4-compatible 'PC1' algorithm. More...
 
long PC1_File (char *szFileOut, char *szFileIn, unsigned char *lpKey, long nKeyBytes)
 Enciphers a file using the RC4-compatible 'PC1' algorithm. More...
 
long PC1_Hex (char *szOutput, long nMaxChars, const char *szInputHex, const char *szKeyHex)
 Enciphers data encoded in hex format in one step using the RC4-compatible 'PC1' algorithm. More...
 
long PRF_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, const void *lpKey, long nKeyLen, const char *szCustom, long nOptions)
 Generate output bytes using a pseudorandom function (PRF). More...
 
long RNG_BytesWithPrompt (unsigned char *lpOutput, long nOutputLen, const char *szPrompt, long nOptions)
 Generates a random set of byte data suitable for cryptographic keys with a prompt for the user to enter random keystrokes and mouse movements. More...
 
long RNG_HexWithPrompt (char *szOutput, long nMaxChars, long nBytes, const char *szPrompt, long nOptions)
 Generates a random set of data in hexadecimal format suitable for cryptographic keys with a prompt for the user to enter random keystrokes and mouse movements. More...
 
long RNG_Initialize (const char *szSeedFile, long nOptions)
 Initializes the RNG generator with a seed file. More...
 
long RNG_KeyBytes (unsigned char *lpOutput, long nOutputLen, const void *lpSeed, long nSeedLen)
 Generates a random set of byte data suitable for cryptographic keys. More...
 
long RNG_KeyHex (char *szOutput, long nMaxChars, long nBytes, const void *lpSeed, long nSeedLen)
 Generates a random set of data in hexadecimal format suitable for cryptographic keys. More...
 
long RNG_MakeSeedFile (const char *szSeedFile, const char *szPrompt, long nOptions)
 Creates a new seed file suitable for use with RNG_Initialize. More...
 
long RNG_NonceData (unsigned char *lpOutput, long nBytes)
 Returns a random nonce (number used once) as a specified-length byte array. More...
 
long RNG_NonceDataHex (char *szOutput, long nMaxChars, long nBytes)
 Returns a specified-length random nonce (number used once) as a hexadecimal string. More...
 
int32_t RNG_Number (int32_t nLower, int32_t nUpper)
 Returns a random 32-bit number between specified limits. More...
 
long RNG_Test (const char *szFileName)
 Carries out a NIST SP800-90 health check and FIPS140-2 statistical tests on the random number generator. More...
 
long RNG_TestDRBGVS (char *szOutput, long nMaxChars, long nReturnedBitsLen, const char *szEntropyInput, const char *szNonce, const char *szPersonalizationString, const char *szAdditionalInput1, const char *szEntropyReseed, const char *szAdditionalInputReseed, const char *szAdditionalInput2, long nOptions)
 Tests the random number generator for conformance to NIST SP 800-90A using the relevant test specified in the Deterministic Random Bit Generator Validation System (DRBGVS). More...
 
long RNG_UpdateSeedFile (const char *szSeedFile, long nOptions)
 Updates an RNG seed file. More...
 
long SHA1_AddBytes (long hContext, const unsigned char *lpData, long nDataLen)
 Adds an array of bytes to the digest. More...
 
long SHA1_AddString (long hContext, const char *szMessage)
 Adds a string of ascii characters to the digest. More...
 
long SHA1_BytesHash (unsigned char *digest, const unsigned char *lpData, long nDataLen)
 Creates a SHA-1 message digest in Byte array format from a message in Byte array format. More...
 
long SHA1_BytesHexHash (char *szDigest, const unsigned char *lpData, long nDataLen)
 Creates a SHA-1 message digest in hexadecimal format from a message in Byte array format. More...
 
long SHA1_FileHexHash (char *szDigest, const char *szFileName, const char *szMode)
 Creates a SHA-1 message digest in hexadecimal format from a file. More...
 
long SHA1_HexDigest (char *szDigest, long hContext)
 Returns the final message digest value as a hex string. More...
 
long SHA1_Hmac (char *szDigest, const unsigned char *textBytes, long textLen, const unsigned char *lpKeyBytes, long keyLen)
 Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-1 hash function. More...
 
long SHA1_HmacHex (char *szDigest, const char *sHexText, const char *sHexKey)
 Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-1 hash function, passing its arguments in hexadecimal format. More...
 
long SHA1_Init (void)
 Initialises the SHA-1 context ready for subsequent calls with SHA1_AddString, SHA1_AddBytes, and SHA1_HexDigest. More...
 
long SHA1_Reset (long hContext)
 Resets the context. More...
 
long SHA1_StringHexHash (char *szDigest, const char *szMessage)
 Creates a SHA-1 message digest in hexadecimal format from a message of String type. More...
 
long SHA2_AddBytes (long hContext, const unsigned char *lpData, long nDataLen)
 Adds an array of bytes to the digest. More...
 
long SHA2_AddString (long hContext, const char *szMessage)
 Adds a string of ascii characters to the digest. More...
 
long SHA2_BytesHash (unsigned char *lpDigest, const unsigned char *lpData, long nDataLen)
 Creates a SHA-256 message digest in Byte array format from a message in Byte array format. More...
 
long SHA2_BytesHexHash (char *szDigest, const unsigned char *lpData, long nDataLen)
 Creates a SHA-256 message digest in hexadecimal format from a message in Byte array format. More...
 
long SHA2_FileHexHash (char *szDigest, const char *szFileName, const char *szMode)
 Creates a SHA-256 message digest in hexadecimal format from a file. More...
 
long SHA2_HexDigest (char *szDigest, long hContext)
 Returns the final message digest value as a hex string. More...
 
long SHA2_Hmac (char *szDigest, const unsigned char *textBytes, long textLen, const unsigned char *lpKeyBytes, long keyLen)
 Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-256 hash function. More...
 
long SHA2_HmacHex (char *szDigest, const char *sHexText, const char *sHexKey)
 Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-256 hash function, passing its arguments in hexadecimal format. More...
 
long SHA2_Init (void)
 Initialises the SHA-256 context ready for subsequent calls with SHA2_AddString, SHA2_AddBytes, and SHA2_HexDigest. More...
 
long SHA2_Reset (long hContext)
 Resets the context. More...
 
long SHA2_StringHexHash (char *szDigest, const char *szMessage)
 Creates a SHA-256 message digest in hexadecimal format from a message of String type. More...
 
long SHA3_AddBytes (long hContext, const unsigned char *lpData, long nDataLen)
 Adds an array of bytes to the digest. More...
 
long SHA3_AddString (long hContext, const char *szMessage)
 Adds a string of ascii characters to the digest. More...
 
long SHA3_HexDigest (char *szOutput, long nMaxChars, long hContext)
 Returns the final message digest value as a hex string. More...
 
long SHA3_Init (long nHashBitLen)
 Initialises the SHA-3 context ready for subsequent calls with SHA3_AddString, SHA3_AddBytes, and SHA3_HexDigest. More...
 
long SHA3_LengthInBytes (long hContext)
 Returns the number of bytes in the hash output for the algorithm defined in the current SHA-3 context. More...
 
long SHA3_Reset (long hContext)
 Resets the context. More...
 
long TDEA_B64Mode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a base64 string using a specified mode. More...
 
long TDEA_Bytes (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt)
 Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode. More...
 
long TDEA_BytesMode (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts an array of Bytes in one step using a specified mode. More...
 
long TDEA_File (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long TDEA_FileExt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV, long nOptions)
 Encrypts or decrypts a file using a specified mode with extended options. More...
 
long TDEA_FileHex (const char *szFileOut, const char *szFileIn, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts a file using a specified mode. More...
 
long TDEA_Final (long hContext)
 Closes and clears the TDEA context. More...
 
long TDEA_Hex (char *szOutput, const char *szInput, const char *szKey, int fEncrypt)
 Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. More...
 
long TDEA_HexMode (char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Encrypts or decrypts data represented as a hexadecimal string using a specified mode. More...
 
long TDEA_Init (const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the TDEA function. More...
 
long TDEA_InitError (void)
 Returns the error code after an unsuccessful call to TDEA_Init or TDEA_InitHex. More...
 
long TDEA_InitHex (const char *szKey, int fEncrypt, const char *szMode, const char *szIV)
 Initialises the context with the key, direction and mode ready for repeated operations of the TDEA function. More...
 
long TDEA_Update (long hContext, unsigned char *lpData, long nDataLen)
 Carries out the TDEA transformation function on a byte array according to the direction and mode set up by an earlier call to TDEA_Init() or TDEA_InitHex(). More...
 
long TDEA_UpdateHex (long hContext, char *szHexData)
 Carries out the TDEA transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to TDEA_Init() or TDEA_InitHex(). More...
 
long WIPE_Data (void *lpData, long nDataLen)
 Zeroises data in memory. More...
 
long WIPE_File (const char *szFileName, long nOptions)
 Securely wipes and deletes a file using 7-pass DOD standards. More...
 
long XOF_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, long nOptions)
 Generate bytes using an eXtendable Output Function (XOF). More...
 
long ZLIB_Deflate (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nBytes)
 Compresses data using the ZLIB deflate algorithm. More...
 
long ZLIB_Inflate (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nBytes)
 Inflates compressed data using the ZLIB uncompress algorithm. More...
 

Detailed Description

The C/C++ interface to the diCryptoSys library.

Type conventions
The convention here is to use the char type for null-terminated strings, denoted szFoo, and the unsigned char for byte arrays, denoted lpBar. Byte arrays must have their length specified in a separate variable.
Allocation for output strings and byte arrays
The user is responsible for allocating memory for any string or byte array variable that receives output. For a string output buffer, the user must allocate one extra byte for the zero terminating byte.
long nchars;
char *szOut;
// Find out how many bytes we need
nchars = CNV_B64StrFromBytes(NULL, 0, lpData, nDataLen);
if (nchars <= 0) error();
// Pre-dimension, i.e allocate memory for string buffer
szOut = malloc(nchars+1); // NB +1
if (!szOut) error();
nchars = CNV_B64StrFromBytes(szOut, nchars, lpData, nDataLen);
// ...
// do something with szOut...
// ...
free(szOut);
long CNV_B64StrFromBytes(char *szOutput, long nMaxChars, const unsigned char *lpInput, long nBytes)
Encodes an array of bytes into a base64-encoded string.
Error codes:
Possible error codes are:
0 = OK, success, no error (SUCCESS_NO_ERROR)
1 = Cannot open input file (OPEN_ERROR)
2 = Cannot create output file (CREATE_ERROR)
3 = File read error (READ_ERROR)
4 = File write error (WRITE_ERROR)
5 = Not enough memory (MEMORY_ERROR)
6 = Parameter is wrong or missing (BAD_PARAM_ERROR)
7 = Data is in wrong format (BAD_FORMAT_ERROR)
8 = Invalid data (INVALID_DATA_ERROR)
9 = Unexpected end of file found (EOF_ERROR)
11 = Parameter out of range (RANGE_ERROR)
12 = Duplicate data or filename (DUP_ERROR)
14 = Unexpected NULL value (NULL_ERROR)
15 = Decryption error (DECRYPT_ERROR)
17 = Invalid option (BAD_FLAG_ERROR)
18 = Failed to wipe data (WIPE_ERROR)
19 = Item is not supported (NOT_SUPPORTED_ERROR)
23 = Failed a test e.g. known answer test (TEST_FAILED_ERROR)
26 = Data not a valid length (BAD_LENGTH_ERROR)
30 = Not enough room in output buffer (SHORT_BUF_ERROR)
31 = Zlib compression error (ZLIB_COMPR_ERROR)
33 = Invalid key length (BAD_KEY_LEN_ERROR)
34 = Invalid block length (BAD_BLK_LEN_ERROR)
35 = Invalid mode (BAD_MODE_ERROR)
36 = Invalid key (BAD_KEY_ERROR)
37 = Invalid initialization vector (BAD_IV_ERROR)
38 = Invalid IV length (BAD_IV_LEN_ERROR)
40 = Authentication failed (AUTH_FAIL_ERROR)
41 = Function called out of sequence (MISUSE_ERROR)
52 = Weak key (WEAK_KEY_ERROR)
64 = Invalid context handle (INVALID_HANDLE_ERROR)
201 = PRNG: Cannot open input file (PRNG_ERR_FILE_OPEN)
202 = PRNG: Cannot create output file (PRNG_ERR_FILE_CREATE)
203 = PRNG: File read error (PRNG_ERR_FILE_READ)
204 = PRNG: File write error (PRNG_ERR_FILE_WRITE)
205 = PRNG: File locking error (PRNG_ERR_FILE_LOCK)
210 = PRNG: Uninstantiation failed (PRNG_ERR_UNINST)
211 = PRNG: Requested length is too large (PRNG_ERR_TOOBIG)
212 = PRNG: Function failed (PRNG_ERR_FAILURE)
213 = PRNG: Invalid input parameter (PRNG_ERR_BADPARAM)
214 = PRNG: Function is not available (PRNG_ERR_NOTAVAIL)
299 = PRNG: Catastrophic failure (PRNG_ERR_CATASTROPHIC)
9745 = Something not expected to happen has happened (INTERNAL_ERROR)
9999 = Miscellaneous error (MISC_ERROR)
To find the error message corresponding to a numerical error code use the API_ErrorLookup() function. Use API_ErrorCode() to find the error code that occurred when calling the last function.

Function Documentation

◆ AEAD_AddAAD()

long AEAD_AddAAD ( long  hContext,
const unsigned char *  lpAAD,
long  nAadLen 
)

Add a chunk of additional authenticated data (in incremental mode).

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
[in]lpAADarray containing the chunk of Additional Authenticated Data (AAD) to add.
[in]nAadLenequal to length of the AAD chunk in bytes.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
May be repeated to add additional data in chunks. Must eventually be followed by either AEAD_StartEncrypt or AEAD_StartDecrypt. Returns MISUSE_ERROR if called out of sequence.

◆ AEAD_Decrypt()

long AEAD_Decrypt ( unsigned char *  lpOutput,
long  nOutLen,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpNonce,
long  nNonceLen,
const unsigned char *  lpAAD,
long  nAadLen,
const unsigned char *  lpTag,
long  nTagLen,
long  nOptions 
)

Decrypt and authenticate input using specified AEAD algorithm in one-off operation.

All the input and output parameters are in byte arrays. The authentication tag is specified separately.

Parameters
[out]lpOutputbyte array of sufficient length to receive the plaintext output (at least as long as the input).
[in]nOutLenlength in bytes of the output array.
[in]lpDatabyte array containing the input data.
[in]nDataLenlength of the input data in bytes.
[in]lpKeybyte array containing the key of exact length for given algorithm (currently either 16 or 32 bytes).
[in]nKeyLenlength of the key in bytes.
[in]lpNoncecontaining the nonce of exact length for the given algorithm (currently always 12 bytes).
[in]nNonceLenlength of the nonce in bytes.
[in]lpAADbyte array containing the optional Additional Authenticated Data (AAD).
[in]nAadLenlength of the AAD in bytes.
[in]lpTagbyte array containing the tag.
[in]nTagLenlength of the tag in bytes.
[in]nOptionsoption flags. Select one of the following:
API_AEAD_AES_128_GCM to use the AEAD_AES_128_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_AES_256_GCM to use the AEAD_AES_256_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_CHACHA20_POLY1305 to use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm (RFC 7539)
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
This is a one-off, stateless function. The output plaintext is always exactly the same length as the input ciphertext (excluding any IV or tags in the input). If the inputs are not authentic, the function returns the non-zero error code AUTH_FAILED_ERROR and the decrypted output should be rejected. Note that the term "IV" is used here to mean exactly the same as "nonce". For more details of AEAD see Authenticated Encryption with Additional Data (AEAD).

◆ AEAD_DecryptWithTag()

long AEAD_DecryptWithTag ( unsigned char *  lpOutput,
long  nOutLen,
const unsigned char *  lpInput,
long  nInputLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpNonce,
long  nNonceLen,
const unsigned char *  lpAAD,
long  nAadLen,
long  nOptions 
)

Decrypt and authenticate input using specified AEAD algorithm in one-off operation.

All the input and output parameters are in byte arrays. The authentication tag is expected to be appended to the input ciphertext.

Parameters
[out]lpOutputbuffer of sufficient length to receive the plaintext output.
[in]nOutLenlength in bytes of the output buffer.
[in]lpInputbyte array containing the input data.
[in]nInputLenlength of the input data in bytes.
[in]lpKeybyte array containing the key of exact length for given algorithm (currently either 16 or 32 bytes).
[in]nKeyLenlength of the key in bytes.
[in]lpNonce(optional) initialization vector (IV), a.k.a. nonce, if not provided in input.
[in]nNonceLenlength of the nonce in bytes.
[in]lpAADbyte array containing the optional Additional Authenticated Data (AAD).
[in]nAadLenlength of the AAD in bytes.
[in]nOptionsoption flags. Select one of the following:
API_AEAD_AES_128_GCM to use the AEAD_AES_128_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_AES_256_GCM to use the AEAD_AES_256_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_CHACHA20_POLY1305 to use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm (RFC 7539)
API_AEAD_ASCON_128 to use the ASCON-128 authentication scheme (see ASCON) (provisional, subject to NIST final approval)
API_AEAD_ASCON_128A to use the ASCON-128A authentication scheme (provisional, subject to NIST final approval)
and optionally add: API_IV_PREFIX to expect the IV (nonce) to be prepended at the start of the input.
Returns
If successful, the return value is the number of bytes in or required in the output otherwise it returns a negative error code.
Remarks
This is a one-off, stateless function.

The input is expected to be the ciphertext with a 16-byte tag appended ciphertext||Tag, or, if the API_IV_PREFIX option is set, then the same but with the 12/16-byte IV (nonce) prepended IV||ciphertext||Tag, where || denotes concatenation. If the IV is not prepended to the input, then it must be provided in the lpNonce argument. The length of the nonce/IV must be exactly 16 bytes for API_AEAD_ASCON_128, otherwise exactly 12 bytes. Note that the term "IV" is used here to mean exactly the same as "nonce". If additional authentication data (AAD) was provided during encryption then the exact same AAD data must be provided here.

Sizes in bytes
AlgorithmkeyLenivLentagLen
API_AEAD_AES_128_GCM161216
API_AEAD_AES_256_GCM321216
API_AEAD_CHACHA20_POLY1305321216
API_AEAD_ASCON_128161616
API_AEAD_ASCON_128A161616

The output plaintext is always exactly the same length as the input ciphertext (excluding any IV or tags in the input). If nOutBytes is set to zero or lpOutput set to 0 (or NULL in C or ByVal 0& in VBA), the required number of bytes will be returned. This will be either exactly 16 bytes shorter than the length of the input, or 28/32 bytes shorter if the API_IV_PREFIX option is used.

If the inputs are not authentic, the function returns the error code AUTH_FAILED_ERROR and the decrypted output should be rejected.

The output buffer lpOutput must not be the same as or overlap with the input lpInput.

◆ AEAD_Destroy()

long AEAD_Destroy ( long  hContext)

Closes the AEAD context and destroys the key (in incremental mode).

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.

◆ AEAD_Encrypt()

long AEAD_Encrypt ( unsigned char *  lpOutput,
long  nOutLen,
unsigned char *  lpTagOut,
long  nTagLen,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpNonce,
long  nNonceLen,
const unsigned char *  lpAAD,
long  nAadLen,
long  nOptions 
)

Encrypt input using specified AEAD algorithm in one-off operation.

All the input and output parameters are in byte arrays. The authentication tag is output separately.

Parameters
[out]lpOutputbyte array of sufficient length to receive the output.
[in]nOutLenlength in bytes of the output buffer.
[out]lpTagOutbyte array of sufficient length to receive the tag (currently 16 bytes for all supported algorithms).
[in]nTagLenlength in bytes of the tag array.
[in]lpDatabyte array containing the input data.
[in]nDataLenlength in bytes of the input data.
[in]lpKeybyte array containing the key of exact length for given algorithm (currently either 16 or 32 bytes).
[in]nKeyLenlength of the key in bytes.
[in]lpNoncecontaining the nonce (IV) of exact length for the given algorithm (currently always 12 bytes).
[in]nNonceLenlength of the nonce in bytes.
[in]lpAADbyte array containing the optional Additional Authenticated Data (AAD).
[in]nAadLenlength of the AAD in bytes.
[in]nOptionsoption flags. Must be one of the following:
API_AEAD_AES_128_GCM to use the AEAD_AES_128_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_AES_256_GCM to use the AEAD_AES_256_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_CHACHA20_POLY1305 to use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm (RFC 7539)
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
This is a one-off, stateless function. The output buffer lpOutput must be at least as long as the input. The ciphertext is always the same length as the plaintext and the authentication tag is always exactly 16 bytes long. Note this function does not concatenate the tag after the ciphertext as suggested in [RFC5116]: for that behaviour, use AEAD_EncryptWithTag.

MAC

To compute a message authentication code (MAC) over the additional data (AAD), pass zero values for both nOutLen and nDataLen (lpOutput and lpData are ignored and may be NULL). The "message" is passed in the AAD parameter and the MAC value is output in lpTagOut. A nonce is still required.

◆ AEAD_EncryptWithTag()

long AEAD_EncryptWithTag ( unsigned char *  lpOutput,
long  nOutLen,
const unsigned char *  lpInput,
long  nInputLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpNonce,
long  nNonceLen,
const unsigned char *  lpAAD,
long  nAadLen,
long  nOptions 
)

Encrypt input using specified AEAD algorithm in one-off operation with the authentication tag appended to output.

Parameters
[out]lpOutputbuffer of sufficient length to receive the output.
[in]nOutLenlength of the output buffer in bytes.
[in]lpInputbyte array containing the input data.
[in]nInputLenlength of the input data in bytes.
[in]lpKeybyte array containing the key.
[in]nKeyLenlength of the key in bytes (must be either 16 or 32).
[in]lpNonce(required) initialization vector (IV), a.k.a. nonce.
[in]nNonceLenlength of the nonce in bytes (must be either 12 or 16).
[in]lpAAD(optional) additional authenticated data (AAD).
[in]nAadLenlength of the AAD in bytes.
[in]nOptionsoption flags. Must be one of the following:
API_AEAD_AES_128_GCM to use the AEAD_AES_128_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_AES_256_GCM to use the AEAD_AES_256_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_CHACHA20_POLY1305 to use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm (RFC 7539)
API_AEAD_ASCON_128 to use the ASCON-128 authentication scheme (see ASCON) (provisional, subject to NIST final approval)
API_AEAD_ASCON_128A to use the ASCON-128A authentication scheme (provisional, subject to NIST final approval)
and optionally add:
API_IV_PREFIX to prepend the IV (nonce) before the ciphertext in the output.
Returns
If successful, the return value is the number of bytes in or required in the output; otherwise it returns a negative error code.
Remarks
This is a one-off, stateless function that carries out Authenticated Encryption with Additional Data (AEAD). In this implementation, the tag is always exactly 16 bytes (128 bits). The tag is automatically appended to the output of the encryption operation in accordance with [RFC5116]. The IV may optionally be prepended to the output using the API_IV_PREFIX option flag. Note that the term "IV" is used here to mean exactly the same as "nonce".

The length of key lpKey must be exactly the required key size in bytes: 16 for API_AEAD_AES_128_GCM and API_AEAD_ASCON_128; or 32 for API_AEAD_AES_256_GCM and API_AEAD_CHACHA20_POLY1305. It is an error if the algorithm is not specified in the nOptions argument. The length of the nonce/IV must be exactly 16 bytes for API_AEAD_ASCON_128, otherwise exactly 12 bytes. The user is responsible for providing a unique IV each time the same key is used. Be aware it is a serious security risk if the same IV and key are used to encrypt different plaintexts.

Sizes in bytes
AlgorithmkeyLenivLentagLen
API_AEAD_AES_128_GCM161216
API_AEAD_AES_256_GCM321216
API_AEAD_CHACHA20_POLY1305321216
API_AEAD_ASCON_128161616
API_AEAD_ASCON_128A161616

If nOutBytes is set to zero or lpOutput set to 0 (or NULL in C or ByVal 0& in VBA), the required number of bytes will be returned. This will be either exactly tagLen (16) bytes longer than the length of the input, or exactly tagLen+ivLen (28/32) bytes longer if the API_IV_PREFIX option is used.

The output buffer lpOutput must not be the same as or overlap with the input lpInput.

◆ AEAD_FinishDecrypt()

long AEAD_FinishDecrypt ( long  hContext)

Finishes the authenticated decryption (in incremental mode) .

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
Returns the nonzero error code AUTH_FAILED_ERROR (-40) if the inputs are not authentic. Must be preceded by AEAD_StartDecrypt and zero or more calls to AEAD_Update. May be followed by
AEAD_SetNonce to begin processing another packet with the same key and algorithm; otherwise should be followed by AEAD_Destroy . Returns MISUSE_ERROR if called out of sequence.

◆ AEAD_FinishEncrypt()

long AEAD_FinishEncrypt ( long  hContext,
unsigned char *  lpTagOut,
long  nTagLen 
)

Finishes the authenticated encryption (in incremental mode) .

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
[out]lpTagOutbyte array of sufficient length to receive the tag (currently 16 bytes for all supported algorithms).
[in]nTagLenspecifying the length in bytes of the tag array.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
Must be preceded by AEAD_StartEncrypt and zero or more calls to AEAD_Update. May be followed by
AEAD_SetNonce to begin processing another packet with the same key and algorithm; otherwise should be followed by AEAD_Destroy . Returns MISUSE_ERROR if called out of sequence.

◆ AEAD_InitKey()

long AEAD_InitKey ( const unsigned char *  lpKey,
long  nKeyLen,
long  nOptions 
)

Initializes the context with the key and algorithm ready for repeated incremental operations.

Parameters
[in]lpKeybyte array containing the key of exact length for given algorithm (currently either 16 or 32 bytes).
[in]nKeyLenequal to length of the key in bytes.
[in]nOptionsoption flags. Select one of the following:
API_AEAD_AES_128_GCM to use the AEAD_AES_128_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_AES_256_GCM to use the AEAD_AES_256_GCM authenticated encryption algorithm (RFC 5116)
API_AEAD_CHACHA20_POLY1305 to use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm (RFC 7539)
Returns
If successful, the return value is the nonzero handle of the AEAD context hContext; otherwise it returns zero if an error occurred.
Remarks
Must be followed by AEAD_SetNonce. This function can be called at any time to cancel any previous context settings. Note that a zero return value indicates an error: Use API_ErrorCode to find more details of the error. For more details of the correct sequence to call the incremental AEAD functions, see Correct sequence for AEAD incremental functions.

◆ AEAD_SetNonce()

long AEAD_SetNonce ( long  hContext,
const unsigned char *  lpNonce,
long  nNonceLen 
)

Set the nonce (in incremental mode).

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
[in]lpNoncecontaining the nonce of exact length for the given algorithm (currently always 12 bytes).
[in]nNonceLenequal to length of the nonce in bytes.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
Must be followed by zero or more calls to AEAD_AddAAD and then either AEAD_StartEncrypt or AEAD_StartDecrypt. Returns MISUSE_ERROR if called out of sequence.

◆ AEAD_StartDecrypt()

long AEAD_StartDecrypt ( long  hContext,
const unsigned char *  lpTagToCheck,
long  nTagLen 
)

Start authenticated decryption (in incremental mode).

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
[in]lpTagToCheckbyte array containing the tag to be checked.
[in]nTagLenequal to length of the tag in bytes.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
May be followed by zero or more calls to AEAD_Update to decrypt data in chunks. Must eventually be followed by
AEAD_FinishDecrypt. Returns MISUSE_ERROR if called out of sequence. Caution: do not trust decrypted data until final authentication.

◆ AEAD_StartEncrypt()

long AEAD_StartEncrypt ( long  hContext)

Start authenticated encryption (in incremental mode).

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
May be followed by zero or more calls to AEAD_Update to encrypt data in chunks. Must eventually be followed by
AEAD_FinishEncrypt. Returns MISUSE_ERROR if called out of sequence.

◆ AEAD_Update()

long AEAD_Update ( long  hContext,
unsigned char *  lpOutput,
long  nOutLen,
const unsigned char *  lpData,
long  nDataLen 
)

Encrypts or decrypts a chunk of input (in incremental mode).

Parameters
[in]hContexthandle to the AEAD context set up by an earlier call to AEAD_InitKey.
[out]lpOutputbyte array of sufficient length to receive the output (at least as long as the input).
[in]nOutLenspecifying the length in bytes of the output array.
[in]lpDatabyte array containing the input data.
[in]nDataLenequal to length of the input data in bytes.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
This function may be repeated to add input data in chunks.

The input data is encrypted or decrypted depending on the start mode set by a preceding call to AEAD_StartEncrypt or AEAD_StartDecrypt, respectively.

It must eventually be followed by either AEAD_FinishEncrypt or AEAD_FinishDecrypt, which must match the start mode.

Returns MISUSE_ERROR if called out of sequence.

◆ AES128_B64Mode()

long AES128_B64Mode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a base64 string using a specified mode.

The key and initialization vector are represented as base64 strings.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in base64.
[in]szKeycontaining the key in base64.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV), if required, in base64.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must represent a multiple of the block size (16 bytes) when decoded. If not, an error will be returned. The initialization vector string szIV must represent exactly 16 bytes unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey must also represent exactly 16 bytes, the required key length. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ AES128_Bytes()

long AES128_Bytes ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt 
)

Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be an exact multiple of 16 bytes long. If not, an error code will be returned. The key array abKey() must be exactly 16 bytes long. The output array lpOutput must be at least as long as the input array. lpOutput and lpData may be the same.

This function is equivalent to

nRet = AES128_BytesMode(lpOutput, abData, nDataLen, abKey, bEncrypt, "ECB", 0)

◆ AES128_BytesMode()

long AES128_BytesMode ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts an array of Bytes using a specified mode.

The key and IV data are in byte arrays.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVcontaining the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be an exact multiple of 16 bytes long. If not, an error code will be returned. The key array abKey() must be exactly 16 bytes long. The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). The output array lpOutput must be at least as long as the input array. lpOutput and lpData may be the same.

◆ AES128_File()

long AES128_File ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as arrays of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key array abKey() must be exactly 16 bytes long. The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0).

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

◆ AES128_FileExt()

long AES128_FileExt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV,
long  nOptions 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as arrays of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
[in]nOptionsoption flags:
Zero (0) for default behaviour as per AES128_File.
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode)
API_PAD_LEAVE to leave any padding in place when decrypting (ECB and CBC modes only; ignored if encrypting)
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
For the default behaviour, see AES128_File. The options are ignored if not applicable. For more information on the behaviour of the options, see Extensions to block cipher functions for files.

◆ AES128_FileHex()

long AES128_FileHex ( const char *  szFileOut,
const char *  szFileIn,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as hexadecimal strings.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key string szHexKey must be exactly 32 hexadecimal characters long (i.e. representing exactly 16 bytes/128 bits). The initialization vector szHexIV must be exactly 32 hexadecimal characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use "").

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.

◆ AES128_Final()

long AES128_Final ( long  hContext)

Closes and clears the AES context.

Parameters
[in]hContextcontaining the handle to the AES context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ AES128_Hex()

long AES128_Hex ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt 
)

Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation.

The process is carried out in one step in Electronic Codebook (EBC) mode.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput should be a multiple of 32 hex characters long (i.e. representing a multiple of 16 bytes). The key string szHexKey must be exactly 32 hex characters long (i.e. representing exactly 16 bytes).

The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

This function is equivalent to

nRet = AES128_HexMode(strOutput, strInput, strHexKey, bEncrypt, "ECB", 0)

◆ AES128_HexMode()

long AES128_HexMode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a hexadecimal string using a specified mode.

The key and initialization vector are represented as a hexadecimal string.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput should be a multiple of 32 hex characters long (i.e. representing a multiple of 16 bytes). The key string szHexKey must be exactly 32 hex characters long (i.e. representing exactly 16 bytes/128 bits).

The initialization vector szHexIV must be exactly 32 hex characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use ""). The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

◆ AES128_Init()

long AES128_Init ( const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the AES function.

The key and IV data are in byte arrays.

Parameters
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector, or zero (0) for ECB mode.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions AES128_Update, AES128_UpdateHex or AES128_Final. Returns zero if an error occurs.
Remarks
The key array abKey() must be exactly 16 bytes long. The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). Unlike most other functions in this API, AES128_Init returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling the AES Update function.

◆ AES128_InitError()

long AES128_InitError ( void  )

Returns the error code after an unsuccessful call to AES128_Init or AES128_InitHex.

Returns
Returns the error code from the last call to AES128_Init or AES128_InitHex.

◆ AES128_InitHex()

long AES128_InitHex ( const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the AES function.

The key and IV data are passed in hexadecimal format.

Parameters
[in]szKeycontaining the key in hexadecimal representation.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector in hexadecimal.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions AES128_Update, AES128_UpdateHex or AES128_Final. Returns zero if an error occurs.
Remarks
The key string szHexKey must be exactly 32 hexadecimal characters long (i.e. representing exactly 16 bytes/128 bits).

The initialization vector szHexIV must be exactly 32 hexadecimal characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. Unlike most other functions in this API, AES128_InitHex returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling the AES Update function.

◆ AES128_Update()

long AES128_Update ( long  hContext,
unsigned char *  lpData,
long  nDataLen 
)

Carries out the AES transformation function on a byte array according to the direction and mode set up by an earlier call to AES128_Init() or AES128_InitHex().

Parameters
[in]hContexthandle to the AES context set up by an earlier call to AES128_Init() or AES128_InitHex().
[in,out]lpDataarray containing the input to be processed by the AES function and to receive the output.
[in]nDataLencontaining length of the data in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be an exact multiple of 16 bytes long. If not, an error code will be returned. Note that the output overwrites the input.

◆ AES128_UpdateHex()

long AES128_UpdateHex ( long  hContext,
char *  szHexData 
)

Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES128_Init() or AES128_InitHex().

Parameters
[in]hContexthandle to the AES context set up by an earlier call to AES128_Init() or AES128_InitHex().
[in,out]szHexDatacontaining input in hexadecimal format to be processed by the AES function and to receive the output.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szHexString must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes).

If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.

◆ AES192_B64Mode()

long AES192_B64Mode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a base64 string using a specified mode.

The key and initialization vector are represented as base64 strings.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in base64.
[in]szKeycontaining the key in base64.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV), if required, in base64.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must represent a multiple of the block size (16 bytes) when decoded. If not, an error will be returned. The initialization vector string szIV must represent exactly 16 bytes unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey must represent exactly 24 bytes, the required key length. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ AES192_Bytes()

long AES192_Bytes ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt 
)

Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. The key array abKey() must be exactly 24 bytes (i.e. 192 bits) long. The output array lpOutput must be at least as long as the input array. lpOutput and lpData may be the same.

This function is equivalent to

nRet = AES192_BytesMode(lpOutput, abData, nDataLen, abKey, bEncrypt, "ECB", 0)

◆ AES192_BytesMode()

long AES192_BytesMode ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts an array of Bytes using a specified mode.

The key and IV data are in byte arrays.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVcontaining the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. The key array abKey() must be exactly 24 bytes long (i.e. 192 bits). The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). The output array lpOutput must be at least as long as the input array. lpOutput and lpData may be the same.

◆ AES192_File()

long AES192_File ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as arrays of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key array abKey() must be exactly 24 bytes long (i.e. 192 bits). The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0).

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

◆ AES192_FileExt()

long AES192_FileExt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV,
long  nOptions 
)

Encrypts or decrypts a file using a specified mode with extended options.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
[in]nOptionsoption flags:
Zero (0) for default behaviour as per AES192_File.
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode)
API_PAD_LEAVE to leave any padding in place when decrypting (ECB and CBC modes only; ignored if encrypting)
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ AES192_FileHex()

long AES192_FileHex ( const char *  szFileOut,
const char *  szFileIn,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as hexadecimal strings.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key string szHexKey must be exactly 48 hexadecimal characters long (i.e. representing exactly 24 bytes/192 bits). The initialization vector szHexIV must be exactly 32 hexadecimal characters long (i.e. representing the block size of exactly 16 bytes), except for ECB mode, where it is ignored (use "").

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.

◆ AES192_Final()

long AES192_Final ( long  hContext)

Closes and clears the AES context.

Parameters
[in]hContextcontaining the handle to the AES context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ AES192_Hex()

long AES192_Hex ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt 
)

Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation.

The process is carried out in one step in Electronic Codebook (EBC) mode.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes). The key string szHexKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes/192 bits).

The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

This function is equivalent to

nRet = AES192_HexMode(strOutput, strInput, strHexKey, bEncrypt, "ECB", 0)

◆ AES192_HexMode()

long AES192_HexMode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a hexadecimal string using a specified mode.

The key and initialization vector are represented as a hexadecimal string.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes). The key string szHexKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes/192 bits).

The initialization vector szHexIV must be exactly 32 hex characters long (i.e. representing the block size of exactly 16 bytes), except for ECB mode, where it is ignored (use ""). The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

◆ AES192_Init()

long AES192_Init ( const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the AES function.

The key and IV data are in byte arrays.

Parameters
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector, or zero (0) for ECB mode.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions AES192_Update, AES192_UpdateHex or AES192_Final. Returns zero if an error occurs.
Remarks
The key array abKey() must be exactly 24 bytes long (i.e. 192 bits). The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). Unlike most other functions in this API, AES192_Init returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling the AES Update function.

◆ AES192_InitError()

long AES192_InitError ( void  )

Returns the error code after an unsuccessful call to AES192_Init or AES192_InitHex.

Returns
Returns the error code from the last call to AES192_Init or AES192_InitHex.

◆ AES192_InitHex()

long AES192_InitHex ( const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the AES function.

The key and IV data are passed in hexadecimal format.

Parameters
[in]szKeycontaining the key in hexadecimal representation.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector in hexadecimal.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions AES192_Update, AES192_UpdateHex or AES192_Final. Returns zero if an error occurs.
Remarks
The key string szHexKey must be exactly 48 hexadecimal characters long (i.e. representing exactly 24 bytes/192 bits).

The initialization vector szHexIV must be exactly 32 hexadecimal characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. Unlike most other functions in this API, AES192_InitHex returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling the AES Update function.

◆ AES192_Update()

long AES192_Update ( long  hContext,
unsigned char *  lpData,
long  nDataLen 
)

Carries out the AES transformation function on a byte array according to the direction and mode set up by an earlier call to AES192_Init() or AES192_InitHex().

Parameters
[in]hContexthandle to the AES context set up by an earlier call to AES192_Init() or AES192_InitHex().
[in,out]lpDataarray containing the input to be processed by the AES function and to receive the output.
[in]nDataLencontaining length of the data in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. Note that the output overwrites the input.

◆ AES192_UpdateHex()

long AES192_UpdateHex ( long  hContext,
char *  szHexData 
)

Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES192_Init() or AES192_InitHex().

Parameters
[in]hContexthandle to the AES context set up by an earlier call to AES192_Init() or AES192_InitHex().
[in,out]szHexDatacontaining input in hexadecimal format to be processed by the AES function and to receive the output.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szHexString The length of the input string szHexString must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes).

If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.

◆ AES256_B64Mode()

long AES256_B64Mode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a base64 string using a specified mode.

The key and initialization vector are represented as base64 strings.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in base64.
[in]szKeycontaining the key in base64.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV), if required, in base64.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must represent a multiple of the block size (16 bytes) when decoded. If not, an error will be returned. The initialization vector string szIV must represent exactly 16 bytes unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey must represent exactly 32 bytes, the required key length. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ AES256_Bytes()

long AES256_Bytes ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt 
)

Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. The key array abKey() must be exactly 32 bytes long (i.e. 256 bits). The output array lpOutput must be at least as long as the input array. lpOutput and lpData may be the same.

This function is equivalent to

nRet = AES256_BytesMode(lpOutput, abData, nDataLen, abKey, bEncrypt, "ECB", 0)

◆ AES256_BytesMode()

long AES256_BytesMode ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts an array of Bytes using a specified mode.

The key and IV data are in byte arrays.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVcontaining the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. The key array abKey() must be exactly 32 bytes long (i.e. 256 bits). The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). The output array lpOutput must be at least as long as the input array. lpOutput and lpData may be the same.

◆ AES256_File()

long AES256_File ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as arrays of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key array abKey() must be exactly 32 bytes long (i.e. 256 bits). The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0).

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

◆ AES256_FileExt()

long AES256_FileExt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV,
long  nOptions 
)

Encrypts or decrypts a file using a specified mode with extended options.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
[in]nOptionsoption flags:
Zero (0) for default behaviour as per AES256_File.
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode)
API_PAD_LEAVE to leave any padding in place when decrypting (ECB and CBC modes only; ignored if encrypting)
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
For the default behaviour, see AES256_File. The options are ignored if not applicable. For more information on the behaviour of the options, see Extensions to block cipher functions for files.

◆ AES256_FileHex()

long AES256_FileHex ( const char *  szFileOut,
const char *  szFileIn,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as hexadecimal strings.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key string szHexKey must be exactly 64 hexadecimal characters long (i.e. representing exactly 32 bytes/256 bits). The initialization vector szHexIV must be exactly 32 hexadecimal characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use "").

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.

◆ AES256_Final()

long AES256_Final ( long  hContext)

Closes and clears the AES context.

Parameters
[in]hContextcontaining the handle to the AES context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ AES256_Hex()

long AES256_Hex ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt 
)

Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation.

The process is carried out in one step in Electronic Codebook (EBC) mode.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes). The key string szHexKey must be exactly 64 hex characters long (i.e. representing exactly 32 bytes/256 bits).

The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

This function is equivalent to

nRet = AES256_HexMode(strOutput, strInput, strHexKey, bEncrypt, "ECB", 0)

◆ AES256_HexMode()

long AES256_HexMode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a hexadecimal string using a specified mode.

The key and initialization vector are represented as a hexadecimal string.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes). The key string szHexKey must be exactly 64 hex characters long (i.e. representing exactly 32 bytes/256 bits).

The initialization vector szHexIV must be exactly 32 hex characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use ""). The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

◆ AES256_Init()

long AES256_Init ( const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the AES function.

The key and IV data are in byte arrays.

Parameters
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector, or zero (0) for ECB mode.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions AES256_Update, AES256_UpdateHex or AES256_Final. Returns zero if an error occurs.
Remarks
The key array abKey() must be exactly 32 bytes long (i.e. 256 bits). The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). Unlike most other functions in this API, AES256_Init returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling the AES Update function.

◆ AES256_InitError()

long AES256_InitError ( void  )

Returns the error code after an unsuccessful call to AES256_Init or AES256_InitHex.

Returns
Returns the error code from the last call to AES256_Init or AES256_InitHex.

◆ AES256_InitHex()

long AES256_InitHex ( const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the AES function.

The key and IV data are passed in hexadecimal format.

Parameters
[in]szKeycontaining the key in hexadecimal representation.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 128-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector in hexadecimal.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions AES256_Update, AES256_UpdateHex or AES256_Final. Returns zero if an error occurs.
Remarks
The key string szHexKey must be exactly 64 hexadecimal characters long (i.e. representing exactly 32 bytes/256 bits).

The initialization vector szHexIV must be exactly 32 hexadecimal characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. Unlike most other functions in this API, AES256_InitHex returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling the AES Update function.

◆ AES256_Update()

long AES256_Update ( long  hContext,
unsigned char *  lpData,
long  nDataLen 
)

Carries out the AES transformation function on a byte array according to the direction and mode set up by an earlier call to AES256_Init() or AES256_InitHex().

Parameters
[in]hContexthandle to the AES context set up by an earlier call to AES256_Init() or AES256_InitHex().
[in,out]lpDataarray containing the input to be processed by the AES function and to receive the output.
[in]nDataLencontaining length of the data in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. Note that the output overwrites the input.

◆ AES256_UpdateHex()

long AES256_UpdateHex ( long  hContext,
char *  szHexData 
)

Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES256_Init() or AES256_InitHex().

Parameters
[in]hContexthandle to the AES context set up by an earlier call to AES256_Init() or AES256_InitHex().
[in,out]szHexDatacontaining input in hexadecimal format to be processed by the AES function and to receive the output.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szHexString must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes).

If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.

◆ API_CompileTime()

long API_CompileTime ( char *  szOutput,
long  nMaxChars 
)

Retrieves the date and time the core library executable was last compiled.

Parameters
[out]szOutputto receive the date and time string.
[in]nMaxCharsspecifying the maximum number of characters to be received.
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

◆ API_ErrorCode()

long API_ErrorCode ( void  )

Returns the error code of the error that occurred when calling the last function.

Returns
Returns the error code of the error that occurred when calling the last function, or zero if no error occurred.
Remarks
The value returned is always a non-negative integer greater than or equal to zero. Not all functions set this value.

◆ API_ErrorLookup()

long API_ErrorLookup ( char *  szOutput,
long  nMaxChars,
long  nErrCode 
)

Retrieves the error message associated with a given error code.

Parameters
[out]szOutputto receive error message.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]nErrCodespecifying the error code for which the message is required.
Returns
the number of characters in the output string or zero if there is no corresponding error message.
Remarks
The error message will never be longer than 127 characters.

◆ API_LicenceType()

long API_LicenceType ( long  nOptions)

Returns the ASCII value of the licence type.

Parameters
[in]nOptionsnot used in this release. Specify zero.
Returns
Returns the ASCII value of the licence type, either "D" (ASCII 68, 0x44) for the Developer Edition or "T" (ASCII 84, 0x54) for the Trial Edition.
Remarks
Note the Australian/British spelling of ‘Licence’.

◆ API_ModuleInfo()

long API_ModuleInfo ( char *  szOutput,
long  nOutChars,
long  nOptions 
)

Get additional information about the core DLL module.

Parameters
[out]szOutputBuffer to receive output string.
[in]nOutCharsMaximum length of output string in bytes.
[in]nOptionsoption flags: not used in this release. Specify zero.
Returns
If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.

◆ API_ModuleName()

long API_ModuleName ( char *  szOutput,
long  nMaxChars,
long  nOptions 
)

Retrieves the name of the current process's module.

Parameters
[out]szOutputto receive the name of the module.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]nOptionsoption flags: API_GEN_PLATFORM to get the platform name, either "Win32" or "X64".
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

◆ API_Platform()

long API_Platform ( char *  szOutput,
long  nOutChars 
)

Gets the platform the core DLL was compiled for.

Parameters
[out]szOutputto receive output, either "Win32" or "X64".
[in]nOutCharsspecifying the maximum length of the string to be copied.
Returns
If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.

◆ API_PowerUpTests()

long API_PowerUpTests ( long  nOptions)

Carries out on demand the full set of power-up tests automatically performed by the toolkit when first powered up (i.e.

when the DLL is first attached to the process).

Parameters
[in]nOptionsoption flags: not used in this release. Specify zero.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This is an optional function. Unlike the tests carried out on actual power-up, this function does not cause the DLL to quit. If errors do occur, an error event will be recorded in the Application event log for NT+ operating systems or in an error log file on W9x systems. For more information on error logging after a self-test error, see Self Tests. Users are warned not to use the toolkit if an error has occurred after using this optional test. In such an event, please contact us.

◆ API_Version()

long API_Version ( void  )

Retrieves the release version number.

Returns
The value of Major*100*100 + Minor*100 + Revision. For example, version 6.2.3 (major version 6, minor version 2, revision 3) will return 60203.

◆ BLF_B64Mode()

long BLF_B64Mode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a base64 string using a specified mode.

The key and initialization vector are represented as base64 strings.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in base64.
[in]szKeycontaining the key in base64.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV), if required, in base64.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must represent a multiple of the block size (8 bytes) when decoded. If not, an error will be returned. The initialization vector string szIV must represent exactly 8 bytes unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey can represent up to 56 bytes. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ BLF_Bytes()

long BLF_Bytes ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
long  keyBytes,
int  fEncrypt 
)

Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]keyBytesequal to length of the key in bytes.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey can be any length between 1 and 56 bytes (448 bits). The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.

◆ BLF_BytesMode()

long BLF_BytesMode ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
long  keyBytes,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts an array of Bytes using a specified mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]keyBytesequal to length of the key in bytes.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey can be any length between 1 and 56 bytes (448 bits). The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.

◆ BLF_File()

long BLF_File ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
long  keyBytes,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as arrays of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]keyBytescontaining the length of the key in bytes.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The initialization vector byte array lpInitV must be exactly the block size of 8 bytes long, except for ECB mode, where it is ignored (use 0). The key array lpKey can be any length between 1 and 56 bytes (448 bits).

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

◆ BLF_FileExt()

long BLF_FileExt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
long  keyBytes,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV,
long  nOptions 
)

Encrypts or decrypts a file using a specified mode with extended options.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]keyBytescontaining the length of the key in bytes.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
[in]nOptionsoption flags:
Zero (0) for default behaviour as per BLF_File.
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode)
API_PAD_LEAVE to leave any padding in place when decrypting (ECB and CBC modes only; ignored if encrypting)
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
For the default behaviour, see BLF_File. The options are ignored if not applicable. For more information on the behaviour of the options, see Extensions to block cipher functions for files.

◆ BLF_FileHex()

long BLF_FileHex ( const char *  szFileOut,
const char *  szFileIn,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  sHexIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as hexadecimal strings.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]sHexIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The initialization vector string szHexIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes) unless szMode is ECB, in which case szHexIV is ignored (use ""). The key szKey can be any even length between 2 and 112 hexadecimal characters. Valid hexadecimal characters are [0-9A-Fa-f].

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.

◆ BLF_Final()

long BLF_Final ( long  hContext)

Closes and clears the BLF context.

Parameters
[in]hContextcontaining the handle to the BLF context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle hContext must have been set up by an earlier call to BLF_Init() or BLF_InitHex().

◆ BLF_Hex()

long BLF_Hex ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt 
)

Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation.

The process is carried out in one step in Electronic Codebook (EBC) mode.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned.. The key szKey can be any even length between 2 and 112 hexadecimal characters. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

◆ BLF_HexMode()

long BLF_HexMode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a hexadecimal string using a specified mode.

The key and initialization vector are represented as a hexadecimal string.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned.. The initialization vector string szIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes) unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey can be any even length between 2 and 112 hexadecimal characters. Valid hexadecimal characters are [0-9A-Fa-f]. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ BLF_Init()

long BLF_Init ( const unsigned char *  lpKey,
long  keyBytes,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the BLF_Update or BLF_UpdateHex functions.

The key and IV data are provided in byte arrays.

Parameters
[in]lpKeyarray containing the key.
[in]keyBytescontaining the length of the key in bytes.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions BLF_Update, BLF_UpdateHex or BLF_Final. Returns zero if an error occurs.
Remarks
The initialization vector byte array lpInitV must be exactly the block size of 8 bytes long, except for ECB mode, where it is ignored (use 0). The key array lpKey can be any length between 1 and 56 bytes (448 bits).

Unlike most other functions in this API, BLF_InitHex returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling BLF_Update or BLF_UpdateHex.

◆ BLF_InitError()

long BLF_InitError ( void  )

Returns the error code after an unsuccessful call to BLF_Init or BLF_InitHex.

Returns
Returns the error code from the last call to BLF_Init or BLF_InitHex.

◆ BLF_InitHex()

long BLF_InitHex ( const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  sHexIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the BLF_Update or BLF_UpdateHex functions.

The key and IV data are in hexadecimal format.

Parameters
[in]szKeycontaining the key in hexadecimal representation.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]sHexIVcontaining the initialization vector in hexadecimal.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions BLF_Update, BLF_UpdateHex or BLF_Final. Returns zero if an error occurs.
Remarks
The initialization vector string szIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes) unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey can be any even length between 2 and 112 hexadecimal characters. Valid hexadecimal characters are [0-9A-Fa-f]. Unlike most other functions in this API, BLF_InitHex returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling BLF_Update or BLF_UpdateHex.

◆ BLF_Update()

long BLF_Update ( long  hContext,
unsigned char *  lpData,
long  nDataLen 
)

Carries out the Blowfish transformation function on a byte array according to the direction and mode set up by an earlier call to BLF_Init() or BLF_InitHex().

Parameters
[in]hContexthandle to the BLF context set up by an earlier call to BLF_Init() or BLF_InitHex().
[in,out]lpDataarray containing the input to be processed by the BLF function and to receive the output.
[in]nDataLencontaining length of the data in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. Note that the output overwrites the input.

◆ BLF_UpdateHex()

long BLF_UpdateHex ( long  hContext,
char *  szHexData 
)

Carries out the Blowfish transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to BLF_Init() or BLF_InitHex().

Parameters
[in]hContexthandle to the BLF context set up by an earlier call to BLF_Init() or BLF_InitHex().
[in,out]szHexDatacontaining input in hexadecimal format to be processed by the BLF function and to receive the output.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szHexString must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.

◆ CIPHER_DecryptBytes()

long CIPHER_DecryptBytes ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpInput,
long  nInputLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpIV,
long  nIvLen,
const char *  szAlgModePad,
long  nOptions 
)

Decrypts data in a byte array using the specified block cipher algorithm, mode and padding.

The key and initialization vector are passed as byte arrays.

Parameters
[out]lpOutputarray of sufficient length to receive the output (must be at least as long as the input, see ** in remarks)).
[in]nOutBytesspecifying the length of the output buffer in bytes.
[in]lpInputarray containing the input data.
[in]nInputLenspecifying the length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]nKeyLenthe length of the key in bytes.
[in]lpIVcontaining the initialization vector (IV), or zero (0) or NULL for ECB mode.
[in]nIvLenthe length of the IV in bytes.
[in]szAlgModePadcontaining the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions).
[in]nOptionsoption flags:
Zero (0) for default options. Optionally add:
API_IV_PREFIX to expect the IV to be prepended at the start of the file (ignored for ECB mode).
Returns
If successful, the return value is the number of bytes required in the output; otherwise it returns a negative error code.
Remarks
The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).

The length of key lpKey must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.

[New in v5.4] You can find the required output length in bytes by setting nOutBytes to zero or lpOutput to 0 (or NULL in C or ByVal 0& in VBA). For ECB and CBC cipher modes, the return value will be the exact length of plaintext after padding has been removed (or a negative error code).

** For ECB and CBC cipher modes, any padding must be removed. To specify the length of lpOutput you can either

  1. [ORIGINAL METHOD] specify the output length of lpOutput equal to the length of the input then truncate the result to the correct length.
  2. [NEW in v5.4] do a first pass setting nOutBytes to zero or lpOutput to 0 or NULL to find the exact decrypted length.

See the examples below. In both cases you may need to cope with the special case where the encrypted output is the empty string, a zero-length byte array.

It is an error (DECRYPT_ERROR) if the padding bytes after decryption are not as expected according to the padding method specified. If the cipher mode is ECB or CBC, it is an error (BAD_LENGTH_ERROR) if the length of the input is not an exact multiple of the block size. The input buffer lpInput may point to the same location as the output buffer. If so, the input ciphertext data will be overwritten by the output (and the user must truncate to remove any padding bytes).

Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding will be used for ECB and CBC mode and nopadding for all other modes. The default cipher mode is ECB. Thus "aes128" is the same as "aes128/ecb/pkcs5padding".

◆ CIPHER_DecryptHex()

long CIPHER_DecryptHex ( char *  szOutput,
long  nOutChars,
const char *  szInputHex,
const char *  szKeyHex,
const char *  szIvHex,
const char *  szAlgModePad,
long  nOptions 
)

Decrypt data using the specified block cipher algorithm, mode and padding.

The input data, key and initialization vector are all represented as hexadecimal strings.

Parameters
[out]szOutputstring buffer of sufficient length to receive the output.
[in]nOutCharsmaximum number of characters to be received.
[in]szInputHexthe input data in hex format.
[in]szKeyHexthe key in hex format.
[in]szIvHexthe initialization vector (IV) in hex format, ignored for ECB mode or if API_IV_PREFIX is used (use "").
[in]szAlgModePadstring specifying the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions).
[in]nOptionsoption flags:
Zero (0) for default options. Optionally add:
API_IV_PREFIX to expect the IV to be prepended before the ciphertext in the input (not applicable for ECB mode).
Returns
If successful, the return value is the number of characters in or required in the output; otherwise it returns a nonzero error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. C/C++ users must add one to this value when allocating memory.

This is the equivalent of CIPHER_DecryptBytes with all parameters passed as hex-encoded strings instead of byte arrays.

Any padding will be removed after decryption.

If the API_IV_PREFIX option is used, the IV will be expected prepended to the ciphertext in the input.

The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).

It is an error (BAD_PARAM_ERROR) to pass the empty string "" as input in szInputHex. The output buffer strOutput should not be the same as the input strInputHex.

CAUTION: be aware of the special case where the output is the empty string "" of length zero.

◆ CIPHER_EncryptBytes()

long CIPHER_EncryptBytes ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpInput,
long  nInputLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpIV,
long  nIvLen,
const char *  szAlgModePad,
long  nOptions 
)

Encrypts data in a byte array using the specified block cipher algorithm, mode and padding.

The key and initialization vector are passed as byte arrays.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]nOutBytesspecifying the length of the output buffer in bytes.
[in]lpInputarray containing the input data.
[in]nInputLenspecifying the length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]nKeyLenthe length of the key in bytes.
[in]lpIVcontaining the initialization vector (IV), or zero (0) or NULL for ECB mode.
[in]nIvLenthe length of the IV in bytes.
[in]szAlgModePadcontaining the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions).
[in]nOptionsoption flags:
Zero (0) for default options. Optionally add:
API_IV_PREFIX to prepend the IV before the ciphertext in the output (ignored for ECB mode).
Returns
If successful, the return value is the number of bytes required in the output; otherwise it returns a negative error code.
Remarks
Padding is added as specified to the input before encryption. The user must allocate an output buffer of the required length, which will always be at least as long as the input, or longer if padding is to be added.

The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).

The length of key lpKey must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.

If nOutBytes is set to zero or lpOutput set to 0 (or NULL in C or ByVal 0& in VBA), the required number of bytes will be returned. If the NoPadding option is specified, the required output length will be the same as the input.

Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding will be used for ECB and CBC mode and nopadding for all other modes. The default cipher mode is ECB. Thus "aes128" is the same as "aes128/ecb/pkcs5padding".

Note that padding is only needed for ECB or CBC mode where the input length is not a multiple of the block size. It is an error (BAD_LENGTH_ERROR) to specify NoPadding with ECB or CBC mode if the length of the input is not an exact multiple of the block size.

The padding option is ignored for CTR, OFB and CFB modes, which do not need padding. The default nopadding is always used for these modes regardless of what is specified (so just use the default, e.g. "aes128/ctr").

[New in v5.4] Use the API_IV_PREFIX to prepend the IV before the ciphertext in the output. This will add the IV before the ciphertext in the form IV||CT. This is the scheme used with block ciphers in XML encryption (see section 5.2 of [XMLENC]) where they use the phrase "The resulting cipher text is prefixed by the IV." It is the responsibility of the receiver to parse this data to recover the IV.

◆ CIPHER_EncryptHex()

long CIPHER_EncryptHex ( char *  szOutput,
long  nOutChars,
const char *  szInputHex,
const char *  szKeyHex,
const char *  szIvHex,
const char *  szAlgModePad,
long  nOptions 
)

Encrypt data using the specified block cipher algorithm, mode and padding.

The input data, key and initialization vector are all represented as hexadecimal strings.

Parameters
[out]szOutputstring buffer of sufficient length to receive the output.
[in]nOutCharsmaximum number of characters to be received.
[in]szInputHexthe input data in hex format.
[in]szKeyHexthe key in hex format.
[in]szIvHexthe initialization vector (IV) in hex format, ignored for ECB mode (use "").
[in]szAlgModePadstring specifying the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions).
[in]nOptionsoption flags:
Zero (0) for default options. Optionally add:
API_IV_PREFIX to prepend the IV before the ciphertext in the output (ignored for ECB mode).
Returns
If successful, the return value is the number of characters in or required in the output; otherwise it returns a nonzero error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. C/C++ users must add one to this value when allocating memory.

This is the equivalent of CIPHER_EncryptBytes with all parameters passed as hex-encoded strings instead of byte arrays.

Padding is added as specified to the input before encryption. The output will always be at least as long as the input, or longer if padding or a prefixed IV is to be added.

The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).

It is an error (BAD_PARAM_ERROR) to pass the empty string "" as input in szInputHex. The output buffer strOutput should not be the same as the input strInputHex.

Use the API_IV_PREFIX option to prepend the IV before the ciphertext in the output. This will add the IV before the ciphertext in the form IV||CT. This is the scheme used with block ciphers in XML encryption (see section 5.2 of [XMLENC]) where they use the phrase "The resulting cipher text is prefixed by the IV."

◆ CIPHER_FileDecrypt()

long CIPHER_FileDecrypt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpIV,
long  nIvLen,
const char *  szAlgModePad,
long  nOptions 
)

Decrypts a file using specified block cipher algorithm, mode and padding.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]nKeyLenspecifying the length of the key in bytes.
[in]lpIVcontaining the initialization vector (IV), if required.
[in]nIvLenspecifying the length of the IV in bytes.
[in]szAlgModePadcontaining the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions).
[in]nOptionsoption flags:
Zero (0) for default options. Optionally add:
API_IV_PREFIX to expect the IV to be prepended at the start of the file (ignored for ECB mode).
Returns
If successful, the return value is zero; otherwise it returns a nonzero error code.
Remarks
The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).

The length of key must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.

The output file szFileOut will be overwritten without warning. If there is an error, the output file will not exist. The input and output files must not be the same.

Prepended IV: If the ciphertext file was created with the IV prepended at the start of the file, then you must specify the API_IV_PREFIX option. In this case, leave the lpIV parameter empty. The input file is expected to be of the form IV||ciphertext.

Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding will be used for ECB and CBC mode and nopadding for all other modes. The default cipher mode is ECB. Thus "aes128" is the same as "aes128/ecb/pkcs5padding".

Padding: When decrypting you can specify NoPadding to leave any padding intact in the deciphered file. This is useful if you wish to examine an unknown padding scheme. Otherwise, when decrypting in ECB or CBC mode, you must specify the same padding scheme used when encrypting. It is an error (DECRYPT_ERROR) if the expected padding string is not found after decrypting. The padding parameter is ignored when decrypting in CTR, OFB or CFB mode.

◆ CIPHER_FileEncrypt()

long CIPHER_FileEncrypt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpIV,
long  nIvLen,
const char *  szAlgModePad,
long  nOptions 
)

Encrypts a file using specified block cipher algorithm, mode and padding.

The IV may be prepended to the file, if required.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]nKeyLenspecifying the length of the key in bytes.
[in]lpIVcontaining the initialization vector (IV), if required.
[in]nIvLenspecifying the length of the IV in bytes.
[in]szAlgModePadcontaining the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions).
[in]nOptionsoption flags:
Zero (0) for default options. Optionally add:
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode).
Returns
If successful, the return value is zero; otherwise it returns a nonzero error code.
Remarks
The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).

The length of key must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.

The output file szFileOut will be overwritten without warning. If there is an error, the output file will not exist. The input and output files must not be the same.

Prepended IV: If the API_IV_PREFIX option flag is set in nOptions then the IV will be prepended (i.e. added) at the start of the output file. That is, the output file will be of the form IV||ciphertext. The API_IV_PREFIX flag is ignored in ECB mode where an IV is not needed.

Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding will be used for ECB and CBC mode and nopadding for all other modes. The default cipher mode is ECB. Thus "aes128" is the same as "aes128/ecb/pkcs5padding".

Padding: In normal circumstances you should leave the padding unspecified and use the default padding when encrypting. The only time it should be required is if you want to use an exotic padding like OneAndZeroesPadding instead of pkcs5padding with ECB or CBC mode. Note that, unlike the behaviour with CIPHER_EncryptBytes, it is an error (BAD_PARAM_ERROR) to specify NoPadding when encrypting a file with ECB or CBC mode under any circumstances. The padding option is ignored for CTR, OFB and CFB modes; that is, the default NoPadding is always used for these modes regardless of what is specified (so just use the default, e.g. "aes128/ctr").

◆ CIPHER_Final()

long CIPHER_Final ( long  hContext)

Closes and clears the CIPHER context.

Parameters
[in]hContexthandle to the current CIPHER context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ CIPHER_Init()

long CIPHER_Init ( int  fEncrypt,
const char *  szAlgAndMode,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpIV,
long  nIvLen,
long  nOptions 
)

Initialize the CIPHER context with the key, iv, algorithm and mode ready for repeated update operations.

Parameters
[in]fEncryptDirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szAlgAndModeString specifying the block cipher algorithm and mode, e.g. "aes128/cbc" (see Specifying the algorithm and mode for generic block cipher functions).
[in]lpKeyKey of exact length for block cipher algorithm.
[in]nKeyLenLength of key in bytes.
[in]lpIVInitialization Vector (IV) of exactly the block size, or zero (0) for ECB mode.
[in]nIvLenLength of IV in bytes.
[in]nOptionsOption flags: zero (0) for default options.
Returns
Non-zero handle of the CIPHER context, or zero if an error occurs.
Remarks
The key must be of the exact key length required for the cipher algorithm. The IV, if provided, must be exactly the length of the cipher block (16 bytes for AES, 8 bytes for Triple DES).

◆ CIPHER_InitHex()

long CIPHER_InitHex ( int  fEncrypt,
const char *  szAlgAndMode,
const char *  szKeyHex,
const char *  szIvHex,
long  nOptions 
)

Initialize the CIPHER context with hex-encoded key, iv, algorithm and mode ready for repeated update operations.

The key and IV data are passed as hexadecimal-encoded strings.

Parameters
[in]fEncryptDirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szAlgAndModeString specifying the block cipher algorithm and mode, e.g. "aes128/cbc" (see Specifying the algorithm and mode for generic block cipher functions).
[in]szKeyHexHex-encoded key of exact length for block cipher algorithm.
[in]szIvHexHex-encoded Initialization Vector (IV) of exactly the block size, or "" for ECB mode.
[in]nOptionsOption flags: zero (0) for default options.
Returns
Non-zero handle of the CIPHER context, or zero if an error occurs.
Remarks
This function is the equivalent of CIPHER_Init except it passes the key and IV parameters as hexadecimal-encoded strings.

◆ CIPHER_KeyUnwrap()

long CIPHER_KeyUnwrap ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpKEK,
long  nKekLen,
long  nOptions 
)

Unwraps (decrypts) a content-encryption key with a key-encryption key.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]nOutBytesspecifying the maximum length of the output array.
[in]lpDataarray containing the input data (wrapped key).
[in]nDataLenspecifying the length of the input data in bytes.
[in]lpKEKarray containing the key encryption key.
[in]nKekLenspecifying the length of the key encryption key.
[in]nOptionsoption flags:
Select the key wrap algorithm from one of the following:
API_BC_AES128 to use AES128-Wrap
API_BC_AES192 to use AES192-Wrap
API_BC_AES256 to use AES256-Wrap
API_BC_3DES to use cms3DESWrap
Returns
If successful, the return value is the number of bytes in the output; otherwise it returns a negative error code.
Remarks
This unwraps (decrypts) key material using a key encryption key (KEK) and uses either the AES Key Wrap Algorithm from RFC 3394 [AES-WRAP] or the Triple-DES Key Wrap algorithm from RFC 3217 [WRAP-3DES]. There is no default algorithm. The algorithm must be specified in the nOptions parameter. To find the required length for the output key material, pass zero as the nOutBytes parameter. This will be 8 bytes less than the input length for AES and 16 bytes less for triple DES. No parity bit checks or changes are made for a Triple-DES key.

◆ CIPHER_KeyWrap()

long CIPHER_KeyWrap ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpKEK,
long  nKekLen,
long  nOptions 
)

Wraps a content-encryption key with a key-encryption key.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]nOutBytesspecifying the maximum length of the output array.
[in]lpDataarray containing the input data (key material).
[in]nDataLenspecifying the length of the input data in bytes.
[in]lpKEKarray containing the key encryption key.
[in]nKekLenspecifying the length of the key encryption key.
[in]nOptionsoption flags:
Select the key wrap algorithm from one of the following:
API_BC_AES128 to use AES128-Wrap
API_BC_AES192 to use AES192-Wrap
API_BC_AES256 to use AES256-Wrap
API_BC_3DES to use cms3DESWrap
Returns
If successful, the return value is the number of bytes in the output; otherwise it returns a negative error code.
Remarks
This wraps (encrypts) key material using a key encryption key (KEK) and uses either the AES Key Wrap Algorithm from RFC 3394 [AES-WRAP] or the Triple-DES Key Wrap algorithm from RFC 3217 [WRAP-3DES]. There is no default algorithm. The algorithm must be specified in the nOptions parameter. The input data to be wrapped must be a valid length for the underlying data encapsulation mechanism; specifically, at least 16 bytes and a multiple of 8 bytes for AES, or exactly 24 bytes for Triple DES. To find the required length for the output wrapped key, pass zero as the nOutBytes parameter (Hint: an AES-wrapped key is exactly 8 bytes longer than the input; a triple-DES-wrapped key is 16 bytes longer). No parity bit checks or changes are made for a Triple-DES key.

◆ CIPHER_StreamBytes()

long CIPHER_StreamBytes ( unsigned char *  lpOutput,
unsigned char *  lpData,
long  nDataLen,
unsigned char *  lpKey,
long  nKeyLen,
unsigned char *  lpIV,
long  nIvLen,
long  nCounter,
long  nOptions 
)

Enciphers data in array of bytes using specified stream cipher.

Parameters
[out]lpOutputarray of sufficient length to receive the output (at least as long as the input).
[in]lpDataarray containing the input data.
[in]nDataLenspecifying the length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]nKeyLenspecifying the length of the key in bytes.
[in]lpIVarray containing the initialization vector (IV, nonce), if required.
[in]nIvLenspecifying the length of the IV in bytes.
[in]nCounterthe value of the counter (ChaCha20 only).
[in]nOptionsoption flags:
Select one of the following:
API_SC_ARCFOUR to use ARCFOUR (RC4)
API_SC_SALSA20 to use Salsa20
API_SC_CHACHA20 to use ChaCha20
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
This performs a one-off encryption over a byte array using the specified stream cipher. The key and IV are passed as byte arrays. The output will be exactly the same length as the input. The output buffer lpOutput may be the same as the input lpInput.
  • Arcfour: any length key; specify null for IV.
  • Salsa20: key must be exactly 16 or 32 bytes and IV exactly 8 bytes long.
  • ChaCha20: key must be exactly 16 or 32 bytes and IV exactly 8, 12, or 16 bytes long. Counter is ignored if IV is 16 bytes.
  • See Stream Ciphers for more details

◆ CIPHER_StreamFile()

long CIPHER_StreamFile ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
long  nKeyLen,
unsigned char *  lpIV,
long  nIvLen,
long  nCounter,
long  nOptions 
)

Enciphers data in a file using specified stream cipher.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]nKeyLenspecifying the length of the key in bytes.
[in]lpIVarray containing the initialization vector (IV, nonce), if required.
[in]nIvLenspecifying the length of the IV in bytes.
[in]nCounterthe value of the counter (ChaCha20 only).
[in]nOptionsoption flags:
Select one of the following:
API_SC_ARCFOUR to use ARCFOUR (RC4)
API_SC_SALSA20 to use Salsa20
API_SC_CHACHA20 to use ChaCha20
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
This performs a one-off encryption of a file using the specified stream cipher. The key and IV are passed as byte arrays. The output file will be exactly the same length as the input. The output file must not be the same as the input file.
  • Arcfour: any length key; specify null for IV.
  • Salsa20: key must be exactly 16 or 32 bytes and IV exactly 8 bytes long.
  • ChaCha20: key must be exactly 16 or 32 bytes and IV exactly 8, 12, or 16 bytes long. Counter is ignored if IV is 16 bytes.
  • See Stream Ciphers for more details

◆ CIPHER_StreamFinal()

long CIPHER_StreamFinal ( long  hContext)

Closes the CIPHERSTREAM context and destroys the key.

Parameters
[in]hContextcontaining the handle to the CIPHERSTREAM context.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.

◆ CIPHER_StreamHex()

long CIPHER_StreamHex ( char *  szOutput,
long  nOutChars,
const char *  szInputHex,
const char *  szKeyHex,
const char *  szIvHex,
long  nCounter,
long  nOptions 
)

Enciphers data in a hex-encoded string using specified stream cipher.

Parameters
[out]szOutputstring of sufficient length to receive the output (at least as long as the input).
[in]nOutCharsspecifying the length of the output buffer in bytes.
[in]szInputHexstring containing the hex-encoded input data.
[in]szKeyHexstring containing the hex-encoded key.
[in]szIvHexstring containing the hex-encoded initialization vector (IV, nonce). Specify "" for Arcfour.
[in]nCounterthe value of the counter (ChaCha20 only).
[in]nOptionsoption flags:
Select one of the following:
API_SC_ARCFOUR to use ARCFOUR (RC4)
API_SC_SALSA20 to use Salsa20
API_SC_CHACHA20 to use ChaCha20
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
This performs a one-off encryption of data in a hex-encoded string using the specified stream cipher. The key and IV are passed as hex-encoded strings. The output will be exactly the same length as the input. C/C++ users must add one to this value when allocating memory.
  • Arcfour: any length key; specify "" for IV.
  • Salsa20: key must be exactly 16 or 32 bytes and IV exactly 8 bytes long.
  • ChaCha20: key must be exactly 16 or 32 bytes and IV exactly 8, 12, or 16 bytes long. Counter is ignored if IV is 16 bytes.
  • See Stream Ciphers for more details

◆ CIPHER_StreamInit()

long CIPHER_StreamInit ( const unsigned char *  lpKey,
long  nKeyLen,
unsigned char *  lpIV,
long  nIvLen,
long  nCounter,
long  nOptions 
)

Initializes the CIPHERSTREAM context ready for repeated operations of CIPHER_StreamUpdate()

Parameters
[in]lpKeyarray containing the key.
[in]nKeyLenspecifying the length of the key in bytes.
[in]lpIVarray containing the initialization vector (IV, nonce), if required.
[in]nIvLenspecifying the length of the IV in bytes.
[in]nCounterthe value of the counter (ChaCha20 only).
[in]nOptionsoption flags:
Select one of the following:
API_SC_ARCFOUR to use ARCFOUR (RC4)
API_SC_SALSA20 to use Salsa20
API_SC_CHACHA20 to use ChaCha20
Returns
If successful, the return value is a non-zero handle to the new CIPHERSTREAM context. Returns zero if an error occurs.
Remarks
It is important to check for a zero context handle and stop if one occurs. Use API_ErrorCode to find the error code of the error that occured.
  • Arcfour: any length key; specify null for IV.
  • Salsa20: key must be exactly 16 or 32 bytes and IV exactly 8 bytes long.
  • ChaCha20: key must be exactly 16 or 32 bytes and IV exactly 8, 12, or 16 bytes long. Counter is ignored if IV is 16 bytes.
  • See Stream Ciphers for more details

◆ CIPHER_StreamUpdate()

long CIPHER_StreamUpdate ( long  hContext,
unsigned char *  lpOutput,
unsigned char *  lpData,
long  nDataLen 
)

Encrypts input using current CIPHERSTREAM context.

Parameters
[in]hContextcontaining the handle to the CIPHERSTREAM context.
[out]lpOutputarray of sufficient length to receive the output (at least as long as the input).
[in]lpDataarray containing the input data.
[in]nDataLenspecifying the length of the input data in bytes.
Returns
If successful, the return value is zero; otherwise it returns a nonnegative error code.
Remarks
Only one CIPERSTREAM context can be active at one time in any thread.

◆ CIPHER_Update()

long CIPHER_Update ( long  hContext,
unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpData,
long  nDataLen 
)

Encrypts or decrypts a chunk of input (in incremental mode).

Parameters
[in]hContextHandle to the CIPHER context.
[out]lpOutputByte array to receive output.
[in]nOutBytesLength of output array in bytes.
[in]lpDataInput data to be processed.
[in]nDataLenLength of input data in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle hContext to the CIPHER context must have been set up with a prior call to CIPHER_Init or CIPHER_InitHex.

The chunks of data to be en/decrypted must be passed to the Update function in sequential order and only in lengths which are multiples of the block size (16 bytes for AES, 8 for Triple DES). For ECB and CBC modes, the last block in the sequence must be suitably padded to a length a multiple of the block size. For other modes, e.g. CTR, the last block in the sequence may be shorter than a multiple of the block length. However, once this final, shorter block has been processed, the Update function can no longer be used (well it can, but the output is wrong).

◆ CIPHER_UpdateHex()

long CIPHER_UpdateHex ( long  hContext,
char *  szOutput,
long  nOutChars,
const char *  szDataHex 
)

Encrypts or decrypts a chunk of hexadecimal-encoded input (in incremental mode).

Parameters
[in]hContextHandle to the CIPHER context.
[out]szOutputString buffer to receive output.
[in]nOutCharsLength of output buffer in bytes.
[in]szDataHexHex-encoded input data to be processed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This function is the equivalent of CIPHER_Update except the input and output are hexadecimal-encoded strings. The functions CIPHER_Update and CIPHER_UpdateHex (and their wrappers cipherUpdate and cipherUpdateHex) may be used interchangeably. For more information, see the remarks section in CIPHER_Update.

◆ CNV_B64Filter()

long CNV_B64Filter ( char *  szOutput,
const char *  szInput,
long  nInStrLen 
)

Removes non-base64 characters from a string.

Parameters
[out]szOutputto receive filtered characters.
[in]szInputto be filtered.
[in]nInStrLenspecifying the length of the input string.
Returns
If successful, the return value is the number of characters in the filtered string; otherwise it returns a negative error code.
Remarks
For the "raw" function, specify a zero nOutChars or a null string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

◆ CNV_B64StrFromBytes()

long CNV_B64StrFromBytes ( char *  szOutput,
long  nMaxChars,
const unsigned char *  lpInput,
long  nBytes 
)

Encodes an array of bytes into a base64-encoded string.

Parameters
[out]szOutputto receive encoded data.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]lpInputarray of binary data to be encoded.
[in]nBytesnumber of bytes to be encoded.
Returns
If successful, the return value is the number of characters in the encoded string; otherwise it returns a negative error code.
Remarks
For the "raw" function, specify a zero nOutChars or a null string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

◆ CNV_BytesFromB64Str()

long CNV_BytesFromB64Str ( unsigned char *  lpOutput,
long  nOutputLen,
const char *  szInput 
)

Decodes a base64-encoded string into an array of Bytes.

Parameters
[out]lpOutputarray suitably dimensioned to receive output.
[in]nOutputLenspecifying the length of the byte array.
[in]szInputof base64 data to be decoded.
Returns
If successful, the return value is the number of bytes in the decoded array; otherwise it returns a negative error code.
Remarks
This uses the base64 encoding scheme from [RFC4648]. Pass a zero value for nOutBytes to find the required maximum possible number of bytes in the output array. The final array may be shorter.
Warning
[Changed in v5.2] This function now returns an error if it finds an illegal character in the input string (previously any non-base64 character was just ignored). Whitespace characters (space, TAB, LF, CR, VT, FF) are still allowed and ignored but any other non-base64 characters will cause an error.

◆ CNV_BytesFromHexStr()

long CNV_BytesFromHexStr ( unsigned char *  lpOutput,
long  nOutputLen,
const char *  szInput 
)

Decodes a hexadecimal-encoded string into an array of Bytes.

Parameters
[out]lpOutputarray suitably dimensioned to receive output.
[in]nOutputLenspecifying the length of the byte array.
[in]szInputof hexadecimal data to be decoded.
Returns
If successful, the return value is the number of bytes in the decoded array; otherwise it returns a negative error code.
Remarks
Call the function with a zero nOutBytes or NULL lpOutput array to find the required length.
Warning
[Changed in v5.2] This function now returns an error if it finds an illegal character in the input string (previously any non-hex character was just ignored). Whitespace characters and ASCII punctuation characters are still allowed and ignored (so "DE:AD:BE:EF" is OK) but obviously non-hex characters like those in the range [G-Zg-z] will cause an error.

◆ CNV_HexFilter()

long CNV_HexFilter ( char *  szOutput,
const char *  szInput,
long  nInStrLen 
)

Removes non-hexadecimal characters from a string.

Parameters
[out]szOutputto receive filtered characters.
[in]szInputto be filtered.
[in]nInStrLenspecifying the length of the input string.
Returns
If successful, the return value is the number of characters in the filtered string; otherwise it returns a negative error code.
Remarks
For the "raw" function, specify a zero nOutChars or a null string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

◆ CNV_HexStrFromBytes()

long CNV_HexStrFromBytes ( char *  szOutput,
long  nMaxChars,
const unsigned char *  lpInput,
long  nBytes 
)

Encodes an array of bytes into a hexadecimal-encoded string.

Parameters
[out]szOutputto receive encoded data.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]lpInputarray of binary data to be encoded.
[in]nBytesnumber of bytes to be encoded.
Returns
If successful, the return value is the number of characters in the encoded string; otherwise it returns a negative error code.
Remarks
For the "raw" function, specify a zero nOutChars or a null string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

◆ CNV_ShortPathName()

long CNV_ShortPathName ( char *  szOut,
long  nOutChars,
const wchar_t *  szwFilePath 
)

Retrieve the Windows short path form of the specified path.

Parameters
[out]szOutBuffer to receive output.
[in]nOutCharsMaximum length of output string in bytes (excluding the terminating null).
[in]szwFilePathPath name in wide characters.
Returns
Number of characters (bytes) in or required for the output string; otherwise it returns a negative error code.
Remarks
Use this function to find the ASCII equivalent file path for a path represented in "Unicode" UTF-16 wchar_t characters. Then use this ASCII short name as an argument for an input file in any of the functions in this library that require a file name.

The file must exist. The output path is guaranteed to be in ASCII characters, and the base name and each folder name will be 8 characters or fewer. It may not give the same value on a different system. Windows only.

For the "raw" function, pass a NULL szOut or zero nOutChars to find the required output length in bytes. ANSI C users must add one to this value when allocating memory.

◆ COMPR_Compress()

long COMPR_Compress ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpInput,
long  nInputLen,
long  nOptions 
)

Compress data using compression algorithm.

Parameters
[out]lpOutputbyte buffer to receive output data.
[in]nOutBytessize of the output buffer in bytes.
[in]lpInputinput data to be compressed.
[in]nInputLenlength of input array in bytes.
[in]nOptionsoption flags. Select one of:
API_COMPR_ZLIB (0) to use the zlib algorithm (default)
API_COMPR_ZSTD to use the Zstandard algorithm
Returns
The number of bytes successfully copied into the output buffer or the required size in bytes. If an error occurs, it returns a negative error code.
Remarks
To determine the required size of the output buffer, call the function with nOutBytes set to zero (or lpOutput set to NULL).

◆ COMPR_Uncompress()

long COMPR_Uncompress ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpInput,
long  nInputLen,
long  nOptions 
)

Uncompress data using compression algorithm.

Parameters
[out]lpOutputbyte buffer to receive output data.
[in]nOutBytessize of the output buffer in bytes.
[in]lpInputinput data to be uncompressed.
[in]nInputLenlength of input array in bytes.
[in]nOptionsoption flags. Select one of:
API_COMPR_ZLIB (0) to use the zlib algorithm (default)
API_COMPR_ZSTD to use the Zstandard algorithm
Returns
The number of bytes successfully copied into the output buffer or the required size in bytes. If an error occurs, it returns a negative error code.
Remarks
To determine the required size of the output buffer, call the function with nOutBytes set to zero (or lpOutput set to NULL).

◆ CRC_Bytes()

int32_t CRC_Bytes ( const unsigned char *  lpInput,
long  nBytes,
long  nOptions 
)

Computes the CRC-32 checksum of an array of bytes.

Parameters
[in]lpInputarray of bytes containing input data.
[in]nBytesspecifying the number of bytes in the input.
[in]nOptionsoption flags: not used in this release. Specify zero.
Returns
The value of the CRC-32 checksum.
Remarks
The CRC-32 checksum is a 32-bit integer value. The CRC-32 algorithm uses the polynomial 0x04C11DB7 and is the one specified in ISO 3309 and ITU-T V.42 and used by WinZip.

◆ CRC_File()

int32_t CRC_File ( const char *  szFileName,
long  nOptions 
)

Computes the CRC-32 checksum of a file.

Parameters
[in]szFileNamespecifying the input file.
[in]nOptionsoption flags: not used in this release. Specify zero.
Returns
The value of the CRC-32 checksum.
Remarks
The CRC-32 checksum is a 32-bit integer value. The CRC-32 algorithm uses the polynomial 0x04C11DB7 and is the one specified in ISO 3309 and ITU-T V.42 and used by WinZip.

A return value of zero probably indicates that the file could not be found, or that the file is empty. The chances of a file with random contents giving a CRC checksum of zero is one in 4.5 billion, but it is not difficult to construct a file with such a checksum.

◆ CRC_String()

int32_t CRC_String ( const char *  szInput,
long  nOptions 
)

Computes the CRC-32 checksum of an ANSI string.

Parameters
[in]szInputANSI string input.
[in]nOptionsoption flags: not used in this release. Specify zero.
Returns
The value of the CRC-32 checksum.
Remarks
The CRC-32 checksum is a 32-bit integer value. The CRC-32 algorithm uses the polynomial 0x04C11DB7 and is the one specified in ISO 3309 and ITU-T V.42 and used by WinZip.

◆ DES_B64Mode()

long DES_B64Mode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a base64 string using a specified mode.

The key and initialization vector are represented as base64 strings.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in base64.
[in]szKeycontaining the key in base64.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV), if required, in base64.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must represent a multiple of the block size (8 bytes) when decoded. If not, an error will be returned. The initialization vector string szIV must represent exactly 8 bytes unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey must also represent exactly 8 bytes, the required key length. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ DES_Bytes()

long DES_Bytes ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt 
)

Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey must be exactly 8 bytes long. The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.

◆ DES_BytesMode()

long DES_BytesMode ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts an array of Bytes in one step using a specified mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVcontaining the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey must be exactly 8 bytes long. The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.

◆ DES_CheckKey()

long DES_CheckKey ( const unsigned char *  lpKey,
long  nKeyLen 
)

Checks for weak or invalid-length DES or TDEA keys.

Parameters
[in]lpKeyarray containing the key.
[in]nKeyLencontaining the length of the key in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
DES_CheckKey verifies that the key size is valid for a single, double or triple DES key - i.e. is 8, 16 or 24 bytes long - and that no part of the key is a weak or semi-weak DES key.

◆ DES_CheckKeyHex()

long DES_CheckKeyHex ( const char *  szHexKey)

Checks for weak or invalid-length DES or TDEA keys in hexadecimal format.

Parameters
[in]szHexKeycontaining the key in hexadecimal format.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
DES_CheckKey verifies that the key size is valid for a single, double or triple DES key - i.e. is 8, 16 or 24 bytes long - and that no part of the key is a weak or semi-weak DES key.

◆ DES_File()

long DES_File ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as arrays of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key lpKey must be exactly 8 bytes long. The initialization vector byte array lpInitV must be exactly the block size of 8 bytes long, except for ECB mode, where it is ignored (use 0).

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

◆ DES_FileExt()

long DES_FileExt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV,
long  nOptions 
)

Encrypts or decrypts a file using a specified mode with extended options.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
[in]nOptionsoption flags:
Zero (0) for default behaviour as per DES_File.
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode)
API_PAD_LEAVE to leave any padding in place when decrypting (ECB and CBC modes only; ignored if encrypting)
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
For the default behaviour, see DES_File. The options are ignored if not applicable. For more information on the behaviour of the options, see Extensions to block cipher functions for files.

◆ DES_FileHex()

long DES_FileHex ( const char *  szFileOut,
const char *  szFileIn,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as hexadecimal strings.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
Both the key string szHexKey and the initialization vector szHexIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes), unless szMode is ECB, in which case szIV is ignored (use "").

Valid hexadecimal characters are [0-9A-Fa-f].

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.

◆ DES_Final()

long DES_Final ( long  hContext)

Closes and clears the DES context.

Parameters
[in]hContextcontaining the handle to the DES context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ DES_Hex()

long DES_Hex ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt 
)

Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation.

The process is carried out in one step in Electronic Codebook (EBC) mode.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. The key string szKey must be exactly 16 hex characters long (i.e. representing exactly 8 bytes). The parity bit is ignored. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

◆ DES_HexMode()

long DES_HexMode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a hexadecimal string using a specified mode.

The key and initialization vector are represented as a hexadecimal string.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. Both the key string szHexKey and the initialization vector szHexIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes), unless szMode is ECB, in which case szIV is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ DES_Init()

long DES_Init ( const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the DES function.

The key and IV data are provided in byte arrays.

Parameters
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions DES_Update, DES_UpdateHex or DES_Final. Returns zero if an error occurs.
Remarks
The key lpKey must be exactly 24 bytes long and the IV, if required, exactly 8 bytes long. Unlike most other functions in this API, DES_Init returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling a DES_Update function.

◆ DES_InitError()

long DES_InitError ( void  )

Returns the error code after an unsuccessful call to DES_Init or DES_InitHex.

Returns
Returns the error code from the last call to DES_Init or DES_InitHex.

◆ DES_InitHex()

long DES_InitHex ( const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the DES function.

The key and IV data are provided in hexadecimal format.

Parameters
[in]szKeycontaining the key in hexadecimal representation.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector in hexadecimal.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions DES_Update, DES_UpdateHex or DES_Final. Returns zero if an error occurs.
Remarks
The key string szHexKey must be exactly 16 hex characters long (i.e. representing exactly 8 bytes/64 bits). The initialization vector string szHexIV must be exactly 16 hex characters long (i.e. representing exactly the block size of 8 bytes), except for ECB mode, where it is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. Unlike most other functions in this API, DES_InitHex returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling a DES_Update function.

◆ DES_Update()

long DES_Update ( long  hContext,
unsigned char *  lpData,
long  nDataLen 
)

Carries out the DES transformation function on a byte array according to the direction and mode set up by an earlier call to DES_Init() or DES_InitHex().

Parameters
[in]hContexthandle to the DES context set up by an earlier call to DES_Init() or DES_InitHex().
[in,out]lpDataarray containing the input data.
[in]nDataLenequal to length of the input data in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. Note that the output overwrites the input.

◆ DES_UpdateHex()

long DES_UpdateHex ( long  hContext,
char *  szHexData 
)

Carries out the DES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to DES_Init() or DES_InitHex().

Parameters
[in]hContexthandle to the DES context set up by an earlier call to DES_Init() or DES_InitHex().
[in,out]szHexDatacontaining input in hexadecimal format to be processed by the DES function and to receive the output.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szHexString must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.

◆ GCM_Decrypt()

long GCM_Decrypt ( unsigned char *  lpOutput,
long  nOutLen,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpIV,
long  nIvLen,
const unsigned char *  lpAAD,
long  nAadLen,
const unsigned char *  lpTag,
long  nTagLen,
long  nOptions 
)

Decrypts authenticated ciphertext using the Galois/Counter Mode (GCM) of operation with the AES algorithm (AES-GCM).

All the input and output parameters are in byte arrays.

Parameters
[out]lpOutputarray of sufficient length to receive the ciphertext output.
[in]nOutLenspecifying the required length of the output in bytes.
[in]lpDataarray containing the input data.
[in]nDataLenequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]nKeyLenequal to length of the key in bytes. Must be one of 16, 24 or 32 corresponding to the required key bytes for AES-128, AES-192 or AES-256, respectively.
[in]lpIVcontaining the initialization vector (IV).
[in]nIvLenequal to length of the IV in bytes.
[in]lpAADarray containing the Additional Authenticated Data (AAD).
[in]nAadLenequal to length of the AAD in bytes.
[in]lpTagarray containing the tag.
[in]nTagLenequal to the length of the tag in bytes.
[in]nOptionsfor future use. Specify zero.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This is a one-off, stateless function. If you need to use the same key repeatedly, use GCM_InitKey - GCM_NextEncrypt - GCM_FinishKey instead. The output lpOutput must be at least as long as the input. The authenticated decryption operation has five inputs: the secret key, an initialization vector (IV), the ciphertext itself, the additional authentication data (AAD), which can be zero-length; and the tag. The IV and AAD are passed in the clear. There is one output: the plaintext, which is exactly the same length as the ciphertext. If the inputs are not authentic, the function returns the non-zero error code DECRYPT_ERROR AUTH_FAIL_ERROR.

Changed in [v5.1]: Note that the error code on authentication fail has changed from
DECRYPT_ERROR (-18) to AUTH_FAIL_ERROR (-40).

◆ GCM_Encrypt()

long GCM_Encrypt ( unsigned char *  lpOutput,
long  nOutLen,
unsigned char *  lpTagOut,
long  nTagLen,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpKey,
long  nKeyLen,
const unsigned char *  lpIV,
long  nIvLen,
const unsigned char *  lpAAD,
long  nAadLen,
long  nOptions 
)

Provides authenticated encryption using the Galois/Counter Mode (GCM) of operation with the AES algorithm (AES-GCM).

It can also provide a stand-alone message authentication code (GMAC). All the input and output parameters are in byte arrays.

Parameters
[out]lpOutputarray of sufficient length to receive the ciphertext output.
[in]nOutLenspecifying the required length of the output in bytes.
[out]lpTagOutarray of sufficient length to receive the tag, at least 4 bytes long.
[in]nTagLenspecifying the required length of the tag in bytes.
[in]lpDataarray containing the input data.
[in]nDataLenequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]nKeyLenequal to length of the key in bytes. Must be one of 16, 24 or 32 corresponding to the required key bytes for AES-128, AES-192 or AES-256, respectively.
[in]lpIVcontaining the initialization vector (IV).
[in]nIvLenequal to length of the IV in bytes.
[in]lpAADarray containing the optional Additional Authenticated Data (AAD).
[in]nAadLenequal to length of the AAD in bytes.
[in]nOptionsfor future use. Specify zero.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This is a one-off, stateless function. If you need to use the same key repeatedly, use GCM_InitKey - GCM_NextEncrypt - GCM_FinishKey instead. The output lpOutput must be at least as long as the input, or zero length for GMAC. There are four inputs for authenticated encryption: the secret key, an initialization vector (IV), the plaintext itself, and optional additional authentication data (AAD). The IV and AAD are passed in the clear. There are two outputs: the ciphertext, which is exactly the same length as the plaintext, and an authentication tag (the "tag"). The tag length can be any length from 4 to 16 bytes (API_MAX_GMAC_BYTES); that is, 32 to 128 bits. You can truncate the tag value afterwards should you wish, at the cost of reduced security. The IV can, in principle, be any length, but 12 bytes (96 bits) is recommended as the algorithm is optimised for that length. The AES algorithm is decided by the length of key you pass: 16 bytes for AES-128, 24 for AES-192, 32 for AES-256; otherwise an error. See Security considerations for AEAD encryption.

GMAC

To produce a message authentication code (GMAC), pass an empty or null string for the plaintext input lpData and a zero length nOutLen for the output ciphertext. The "message" is passed in the AAD parameter and the GMAC value is output in the tag. A unique IV is still required.

◆ GCM_FinishKey()

long GCM_FinishKey ( long  hContext)

Closes the GCM context and destroys the key.

Parameters
[in]hContextcontaining the handle to the GCM context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ GCM_InitKey()

long GCM_InitKey ( const unsigned char *  lpKey,
long  nKeyLen,
long  nOptions 
)

Initializes the context with the key ready for repeated operations of GCM_NextEncrypt and GCM_NextDecrypt.

Parameters
[in]lpKeyarray containing the key.
[in]nKeyLenequal to length of the key in bytes. Must be one of 16, 24 or 32 corresponding to the required key bytes for AES-128, AES-192 or AES-256, respectively.
[in]nOptionsfor future use. Specify zero.
Returns
non-zero handle of the GCM context hContext. Returns zero if an error occurs.
Remarks
It is important to check for a zero context handle and stop if one occurs.

◆ GCM_NextDecrypt()

long GCM_NextDecrypt ( long  hContext,
unsigned char *  lpOutput,
long  nOutLen,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpIV,
long  nIvLen,
const unsigned char *  lpAAD,
long  nAadLen,
const unsigned char *  lpTag,
long  nTagLen 
)

Carries out the GCM authenticated decryption operation using the key set up by an earlier call to GCM_InitKey.

Parameters
[in]hContexthandle to the GCM context set up by an earlier call to GCM_InitKey.
[out]lpOutputarray of sufficient length to receive the ciphertext output.
[in]nOutLenspecifying the required length of the output in bytes.
[in]lpDataarray containing the input data.
[in]nDataLenequal to length of the input data in bytes.
[in]lpIVcontaining the initialization vector (IV).
[in]nIvLenequal to length of the IV in bytes.
[in]lpAADarray containing the Additional Authenticated Data (AAD).
[in]nAadLenequal to length of the AAD in bytes.
[in]lpTagarray containing the tag.
[in]nTagLenequal to the length of the tag in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
See the remarks for GCM_Decrypt and the Security considerations for AEAD encryption.

◆ GCM_NextEncrypt()

long GCM_NextEncrypt ( long  hContext,
unsigned char *  lpOutput,
long  nOutLen,
unsigned char *  lpTagOut,
long  nTagLen,
const unsigned char *  lpData,
long  nDataLen,
const unsigned char *  lpIV,
long  nIvLen,
const unsigned char *  lpAAD,
long  nAadLen 
)

Carries out the GCM authenticated encryption operation using the key set up by an earlier call to GCM_InitKey.

Parameters
[in]hContexthandle to the GCM context set up by an earlier call to GCM_InitKey.
[out]lpOutputarray of sufficient length to receive the ciphertext output.
[in]nOutLenspecifying the required length of the output in bytes.
[out]lpTagOutarray of sufficient length to receive the tag, at least 4 bytes long.
[in]nTagLenspecifying the required length of the tag in bytes.
[in]lpDataarray containing the input data.
[in]nDataLenequal to length of the input data in bytes.
[in]lpIVcontaining the initialization vector (IV).
[in]nIvLenequal to length of the IV in bytes.
[in]lpAADarray containing the optional Additional Authenticated Data (AAD).
[in]nAadLenequal to length of the AAD in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
See the remarks for GCM_Encrypt and the Security considerations for AEAD encryption.

◆ HASH_AddBytes()

long HASH_AddBytes ( long  hContext,
const void *  lpData,
long  nDataLen 
)

Adds an array of bytes to be digested in the HASH context.

Parameters
[in]hContextHandle to the HASH context.
[in]lpDataByte array containing the next part of the message.
[in]nDataLenNumber of bytes in the array
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle hContext to the context must have been set up with a prior call to HASH_Init. The HASH_AddBytes function may be called many times before creating the final message digest with HASH_Final.

VBA users can use the more convenient wrapper functions hashAddBytes and hashAddString.

◆ HASH_Bytes()

long HASH_Bytes ( unsigned char *  lpOutput,
long  nOutLen,
const void *  lpMessage,
long  nMsgLen,
long  nOptions 
)

Creates a message digest hash as a byte array from byte data.

The hash algorithm to use is passed in the options parameter.

Parameters
[out]lpOutputarray to receive the hash digest.
[in]nOutLenspecifying the length in bytes of the output array.
[in]lpMessagearray containing the message data
[in]nMsgLenspecifying length of the message data in bytes.
[in]nOptionsOption flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_MD5 to use the MD5 algorithm
API_HASH_MD2 to use the MD2 algorithm (legacy)
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
API_HASH_ASCON_HASH to use the ASCON-HASH algorithm
API_HASH_ASCON_HASHA to use the ASCON-HASHA algorithm
Returns
If successful, the return value is the number of bytes in the hash digest array; otherwise it returns a negative error code.
Remarks
Specify a zero nDigLen parameter to find out the required length of the output array. The maximum possible length is API_MAX_HASH_BYTES. Hint: SHA-1 requires 20 bytes; MD5 and MD2 require 16 bytes; SHA-512 requires 64. The final digest will be truncated to the specified length if less than the expected size.

◆ HASH_DigestLength()

long HASH_DigestLength ( long  hContext)

Returns the number of bytes in the hash output for the algorithm defined in the current HASH context.

Parameters
[in]hContexthandle to the current HASH context.
Returns
The number of bytes in the hash output for the algorithm defined in the current HASH context, or a negative error code.

◆ HASH_File()

long HASH_File ( unsigned char *  lpOutput,
long  nOutLen,
const char *  szFileName,
long  nOptions 
)

Creates a message digest hash in byte format for a file.

The hash algorithm to use is passed in the options parameter.

Parameters
[out]lpOutputarray to receive the hash digest.
[in]nOutLenspecifying the length in bytes of the output array.
[in]szFileNamecontaining the name of the file.
[in]nOptionsOption flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_MD5 to use the MD5 algorithm
API_HASH_MD2 to use the MD2 algorithm (legacy)
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
and add
API_HASH_MODE_TEXT to hash in "text" mode instead of default "binary" mode
Returns
If successful, the return value is the number of bytes in the hash digest array; otherwise it returns a negative error code.
Remarks
Specify a zero nDigLen parameter to find out the required length of the output array. The maximum size will be API_MAX_HASH_BYTES. The final digest will be truncated to the specified length if less than the expected size. Add the option API_HASH_MODE_TEXT to work in "text" mode where CR-LF pairs are treated as a single newline (LF) character. Use this option to pass hash digests of text file between Windows and Unix systems. The default mode is "binary" where each byte is treated individually. Only ANSI file names and paths are supported (but see CNV_ShortPathName as a work around). Note that Ascon-Hash is not available with this function.

◆ HASH_Final()

long HASH_Final ( unsigned char *  lpOutput,
long  nOutLen,
long  hContext 
)

Returns the final message digest value from the HASH context.

Parameters
[out]lpOutputarray to receive message digest.
[in]nOutLenlength in bytes of the output array.
[in]hContexthandle to the current HASH context.
Returns
If successful, the return value is the number of bytes in the output array; otherwise it returns a negative error code.
Remarks
Computes the result of all HASH_AddBytes calls since HASH_Init. Once called, the context is destroyed.

◆ HASH_HexFromBits()

long HASH_HexFromBits ( char *  szOutput,
long  nMaxChars,
const unsigned char *  lpData,
long  nDataBitLen,
long  nOptions 
)

Creates a message digest hash in hexadecimal format from bit-oriented input.

The hash algorithm to use is passed in the options parameter.

Parameters
[out]szOutputto receive hash digest in hexadecimal format.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]lpDataarray containing the message data
[in]nDataBitLenspecifying length of the message data in bits.
[in]nOptionsOption flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
Pass a bitstring as an array of bytes in lpData in big-endian order with the most-significant bit first. The bitstring will be truncated to the number of bits specified in nDataBitlen and extraneous bits on the right will be ignored.

For example, the byte array (0x)717F8C with nDataBitLen=23 represents the 23-bit bitstring 0111 0001 0111 1111 1000 110, and the byte array (0x)5180 with nDataBitLen=9 represents the 9-bit bitstring 0101 0001 1.

The number of bytes in the array lpData must be at least ceil(nDataBitLen / 8). Only the SHA family of hash functions is supported in bit-oriented mode.

For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length.

Specify a zero nOutChars or an empty ("") or NULL szOutput parameter to find out the required length of the output string (or use the appropriate API_SHAnnn_CHARS constant). C/C++ users must add one to this value when allocating memory.

◆ HASH_HexFromBytes()

long HASH_HexFromBytes ( char *  szOutput,
long  nMaxChars,
const void *  lpMessage,
long  nMsgLen,
long  nOptions 
)

Creates a message digest hash in hexadecimal format from byte (or string) data.

The hash algorithm to use is passed in the options parameter.

Parameters
[out]szOutputto receive hash digest in hexadecimal format.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]lpMessagearray containing the message data; or
[in]nMsgLenspecifying length of the message data in bytes.
[in]nOptionsOption flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_MD5 to use the MD5 algorithm
API_HASH_MD2 to use the MD2 algorithm (legacy)
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
API_HASH_ASCON_HASH to use the ASCON-HASH algorithm
API_HASH_ASCON_HASHA to use the ASCON-HASHA algorithm
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length.

Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory. The maximum number of characters is API_MAX_HASH_CHARS. The final digest will be truncated to the specified length if less than the expected size. Only lower-case letters [a-f] are used in the output string.

◆ HASH_HexFromFile()

long HASH_HexFromFile ( char *  szOutput,
long  nMaxChars,
const char *  szFileName,
long  nOptions 
)

Creates a message digest hash in hexadecimal format for a file.

The hash algorithm to use is passed in the options parameter.

Parameters
[out]szOutputto receive hash digest in hexadecimal format.
[in]nMaxCharsspecifying the maximum number of characters to be received in characters.
[in]szFileNamecontaining the name of the file.
[in]nOptionsOption flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_MD5 to use the MD5 algorithm
API_HASH_MD2 to use the MD2 algorithm (legacy)
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
and add
API_HASH_MODE_TEXT to hash in "text" mode instead of default "binary" mode
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length.

Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory. The maximum number of characters will be API_MAX_HASH_CHARS. C/C++ users should add one to this value before allocating memory. The final digest will be truncated to the specified length if less than the expected size. Only lower-case letters [a-f] are used.

Add the option API_HASH_MODE_TEXT to work in "text" mode where CR-LF pairs are treated as a single newline character. The default mode is "binary" where each byte is treated individually. Only ANSI file names and paths are supported (but see CNV_ShortPathName as a work around). Note that Ascon-Hash is not available with this function.

◆ HASH_HexFromHex()

long HASH_HexFromHex ( char *  szOutput,
long  nMaxChars,
const char *  szMsgHex,
long  nOptions 
)

Creates a message digest hash in hexadecimal format from data in a hexadecimal-encoded string.

The hash algorithm to use is passed in the options parameter.

Parameters
[out]szOutputto receive hash digest in hexadecimal format.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]szMsgHexcontaining the message data in hexadecimal-encoded format.
[in]nOptionsOption flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_MD5 to use the MD5 algorithm
API_HASH_MD2 to use the MD2 algorithm (legacy)
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
API_HASH_ASCON_HASH to use the ASCON-HASH algorithm
API_HASH_ASCON_HASHA to use the ASCON-HASHA algorithm
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length.

Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory. The maximum number of characters is API_MAX_HASH_CHARS. The final digest will be truncated to the specified length if less than the expected size. Only lower-case letters [a-f] are used in the output.

◆ HASH_Init()

long HASH_Init ( long  nAlg)

Initialises the HASH context ready for subsequent calls with HASH_AddBytes and HASH_Final.

Parameters
[in]nAlgAlgorithm to be used. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
API_HASH_SHA3_224 to use the SHA-3-224 algorithm
API_HASH_SHA3_256 to use the SHA-3-256 algorithm
API_HASH_SHA3_384 to use the SHA-3-384 algorithm
API_HASH_SHA3_512 to use the SHA-3-512 algorithm
Returns
Non-zero handle of the HASH context, or zero if an error occurs.
Remarks
Only the SHA-1, SHA-2 and SHA-3 families of hash algorithms are supported. While the context handle is valid, add data to be digested in blocks of any length using HASH_AddBytes. VBA users can use the wrapper functions hashAddBytes and hashAddString.

◆ HASH_Length()

long HASH_Length ( long  nAlgId)

Return length of message digest output in bytes.

Parameters
[in]nAlgIdAlgorithm Id flag. Select one of API_HASH_*:
API_HASH_SHA1 SHA-1 algorithm
API_HASH_SHA224 SHA-224 algorithm
API_HASH_SHA256 SHA-256 algorithm
API_HASH_SHA384 SHA-384 algorithm
API_HASH_SHA512 SHA-512 algorithm
API_HASH_SHA3_224 SHA-3-224 algorithm
API_HASH_SHA3_256 SHA-3-256 algorithm
API_HASH_SHA3_384 SHA-3-384 algorithm
API_HASH_SHA3_512 SHA-3-512 algorithm
API_HASH_MD5 MD5 algorithm
API_HASH_MD2 MD2 algorithm
API_HASH_RMD160 RIPEMD-160 algorithm
API_HASH_ASCON_HASHASCON-HASH algorithm
API_HASH_ASCON_HASHA ASCON-HASHA algorithm
Returns
Length of the hash function output in bytes; else a negative error code.
Remarks
[New in v6.21]

◆ HASH_Reset()

long HASH_Reset ( long  hContext)

Resets the HASH context.

Parameters
[in]hContexthandle to the HASH context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
Destroys the existing context. The results of any part-messages added to the context will be lost.

◆ MAC_AddBytes()

long MAC_AddBytes ( long  hContext,
const void *  lpData,
long  nDataLen 
)

Adds an array of bytes to be authenticated in the MAC context.

Parameters
[in]hContextHandle to the MAC context.
[in]lpDataByte array containing the next part of the message.
[in]nDataLenNumber of bytes in the array
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle hContext to the context must have been set up with a prior call to MAC_Init. The MAC_AddBytes function may be called many times before creating the final message digest with MAC_Final.

VBA users can use the more convenient wrapper functions macAddBytes and macAddString.

◆ MAC_Bytes()

long MAC_Bytes ( unsigned char *  lpOutput,
long  nOutBytes,
const void *  lpMessage,
long  nMsgLen,
const void *  lpKey,
long  nKeyLen,
long  nOptions 
)

Creates a keyed message authentication code (MAC) as a byte array from byte data.

The MAC algorithm to use is passed in the options parameter.

Parameters
[out]lpOutputbyte buffer to receive the MAC value.
[in]nOutBytessize of output buffer in bytes.
[in]lpMessagebyte array containing the message (input) data
[in]nMsgLenlength of the input data in bytes.
[in]lpKeybyte array containing the key
[in]nKeyLenlength of the key in bytes.
[in]nOptionsOption flags. Select one of:
HMAC algorithms:
API_HMAC_SHA1 (0) to use HMAC-SHA-1 (default)
API_HMAC_SHA224 to use HMAC-SHA-224
API_HMAC_SHA256 to use HMAC-SHA-256
API_HMAC_SHA384 to use HMAC-SHA-384
API_HMAC_SHA512 to use HMAC-SHA-512
API_HMAC_MD5 to use HMAC-MD5 (legacy)
API_HMAC_RMD160 to use HMAC-RIPEMD160
API_HMAC_SHA3_224 to use HMAC-SHA3-224
API_HMAC_SHA3_256 to use HMAC-SHA3-256
API_HMAC_SHA3_384 to use HMAC-SHA3-384
API_HMAC_SHA3_512 to use HMAC-SHA3-512
CMAC algorithms:
API_CMAC_TDEA to use the Triple DES (DES-EDE) block cipher
API_CMAC_AES128 to use the AES-128 block cipher
API_CMAC_AES192 to use the AES-192 block cipher
API_CMAC_AES256 to use the AES-256 block cipher
Other:
API_MAC_POLY1305 to use the Poly1305 algorithm [New in v5.0]
API_KMAC_128 to use KMAC128 with a fixed-length output of 256 bits (32 bytes) [New in v5.3]
API_KMAC_256 to use KMAC256 with a fixed-length output of 512 bits (64 bytes) [New in v5.3]
Returns
If successful, the return value is the number of bytes in the output array; otherwise it returns a negative error code.
Remarks
Specify a zero nOutBytes parameter to find out the required length of the output array. The maximum possible output length is API_MAX_MAC_BYTES. The final MAC value will be truncated to the specified length if less than the expected size (except for KMAC which must not be truncated).

To use KMAC with variable-length output or a customization string, use PRF_Bytes.

◆ MAC_CodeLength()

long MAC_CodeLength ( long  hContext)

Returns the number of bytes in the output for the algorithm defined in the current MAC context.

Parameters
[in]hContexthandle to the current MAC context.
Returns
The number of bytes in the hash output for the algorithm defined in the current MAC context, or a negative error code.

◆ MAC_Final()

long MAC_Final ( unsigned char *  lpOutput,
long  nOutLen,
long  hContext 
)

Returns the final message digest value from the MAC context.

Parameters
[out]lpOutputarray to receive message digest.
[in]nOutLenlength in bytes of the output array.
[in]hContexthandle to the current MAC context.
Returns
If successful, the return value is the number of bytes in the output array; otherwise it returns a negative error code.
Remarks
Computes the result of all MAC_AddBytes calls since MAC_Init. Once called, the context is destroyed.

◆ MAC_HexFromBytes()

long MAC_HexFromBytes ( char *  szOutput,
long  nMaxChars,
const void *  lpMessage,
long  nMsgLen,
const void *  lpKey,
long  nKeyLen,
long  nOptions 
)

Creates a keyed-hash based message authentication code (HMAC) in hexadecimal format from byte data.

The hash algorithm to use is passed in the options parameter.

Parameters
[out]szOutputto receive output in hexadecimal format.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]lpMessagearray containing the message data in a byte array
[in]nMsgLenspecifying length of the message data in bytes.
[in]lpKeyarray containing the key in a byte array
[in]nKeyLenspecifying length of the key in bytes.
[in]nOptionsOption flags. Select one of:
HMAC algorithms:
API_HMAC_SHA1 (0) to use the SHA-1 hash algorithm (default)
API_HMAC_SHA224 to use the SHA-224 algorithm
API_HMAC_SHA256 to use the SHA-256 algorithm
API_HMAC_SHA384 to use the SHA-384 algorithm
API_HMAC_SHA512 to use the SHA-512 algorithm
API_HMAC_MD5 to use the MD5 algorithm
API_HMAC_RMD160 to use the RIPEMD-160 algorithm
API_HMAC_SHA3_224 to use the SHA-3-224 algorithm
API_HMAC_SHA3_256 to use the SHA-3-256 algorithm
API_HMAC_SHA3_384 to use the SHA-3-384 algorithm
API_HMAC_SHA3_512 to use the SHA-3-512 algorithm
CMAC algorithms:
API_CMAC_TDEA to use the Triple DES (DES-EDE) block cipher
API_CMAC_AES128 to use the AES-128 block cipher
API_CMAC_AES192 to use the AES-192 block cipher
API_CMAC_AES256 to use the AES-256 block cipher
Other:
API_MAC_POLY1305 to use the Poly1305 algorithm [New in v5.0]
API_KMAC_128 to use KMAC128 with a fixed-length output of 256 bits (32 bytes) [New in v5.3]
API_KMAC_256 to use KMAC256 with a fixed-length output of 512 bits (64 bytes) [New in v5.3]
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length.

Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory. The maximum number of characters is API_MAX_MAC_CHARS. The final digest will be truncated to the specified length if less than the expected size (except for KMAC which must not be truncated).

◆ MAC_HexFromHex()

long MAC_HexFromHex ( char *  szOutput,
long  nMaxChars,
const char *  szMsgHex,
const char *  szKeyHex,
long  nOptions 
)

Creates a message authentication code (MAC) in hexadecimal format from hex-encoded data and a hex-encoded key.

The MAC algorithm to use is passed in the options parameter.

Parameters
[out]szOutputto receive output in hexadecimal format.
[in]nMaxCharsspecifying the maximum number of characters to be received.
[in]szMsgHexarray containing the message data in hexadecimal-encoded format.
[in]szKeyHexarray containing the key in hexadecimal-encoded format.
[in]nOptionsOption flags. Select one of:
HMAC algorithms:
API_HMAC_SHA1 (0) to use the SHA-1 hash algorithm (default)
API_HMAC_SHA224 to use the SHA-224 algorithm
API_HMAC_SHA256 to use the SHA-256 algorithm
API_HMAC_SHA384 to use the SHA-384 algorithm
API_HMAC_SHA512 to use the SHA-512 algorithm
API_HMAC_MD5 to use the MD5 algorithm
API_HMAC_RMD160 to use the RIPEMD-160 algorithm
API_HMAC_SHA3_224 to use the SHA-3-224 algorithm
API_HMAC_SHA3_256 to use the SHA-3-256 algorithm
API_HMAC_SHA3_384 to use the SHA-3-384 algorithm
API_HMAC_SHA3_512 to use the SHA-3-512 algorithm
CMAC algorithms:
API_CMAC_TDEA to use the Triple DES (DES-EDE) block cipher
API_CMAC_AES128 to use the AES-128 block cipher
API_CMAC_AES192 to use the AES-192 block cipher
API_CMAC_AES256 to use the AES-256 block cipher
Other:
API_MAC_POLY1305 to use the Poly1305 algorithm [New in v5.0]
API_KMAC_128 to use KMAC128 with a fixed-length output of 256 bits (32 bytes) [New in v5.3]
API_KMAC_256 to use KMAC256 with a fixed-length output of 512 bits (64 bytes) [New in v5.3]
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length.

Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory. The maximum number of characters is API_MAX_MAC_CHARS.

The final digest will be truncated to the specified length if less than the expected size (except for KMAC which must not be truncated).

◆ MAC_Init()

long MAC_Init ( const void *  lpKey,
long  nKeyLen,
long  nAlg 
)

Initialises the MAC context ready for subsequent calls with MAC_AddBytes and MAC_Final.

Parameters
[in]lpKeyKey in byte format.
[in]nKeyLenLength of key in bytes.
[in]nAlgAlgorithm to be used. Select one of:
API_HMAC_SHA1 (0) to use the HMAC-SHA-1 algorithm (default)
API_HMAC_SHA224 to use the HMAC-SHA-224 algorithm
API_HMAC_SHA256 to use the HMAC-SHA-256 algorithm
API_HMAC_SHA384 to use the HMAC-SHA-384 algorithm
API_HMAC_SHA512 to use the HMAC-SHA-512 algorithm
Returns
Non-zero handle of the MAC context, or zero if an error occurs.
Remarks
Only the HMAC-SHA-1 and HMAC-SHA-2 families of MAC algorithms are currently supported. While the context handle is valid, add data to be digested in blocks of any length using MAC_AddBytes. VBA users can use the wrapper functions macAddBytes and macAddString.

◆ MAC_Reset()

long MAC_Reset ( long  hContext)

Resets the MAC context.

Parameters
[in]hContexthandle to the MAC context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
Destroys the existing context. The results of any part-messages added to the context will be lost.

◆ MD5_AddBytes()

long MD5_AddBytes ( long  hContext,
const unsigned char *  lpData,
long  nDataLen 
)

Adds an array of bytes to the digest.

Parameters
[in]hContexthandle to the MD5 context.
[in]lpDataarray containing the next part of the message to be hashed.
[in]nDataLencontaining the number of bytes in the array
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to MD5_Init. This function may be called many times before creating the final message digest with MD5_HexDigest. MD5_AddString may also be called.

◆ MD5_AddString()

long MD5_AddString ( long  hContext,
const char *  szMessage 
)

Adds a string of ascii characters to the digest.

Parameters
[in]hContexthandle to the MD5 context.
[in]szMessagecontaining the next part of the message to be hashed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to MD5_Init. This function may be called many times before creating the final message digest with MD5_HexDigest This function should only be used to hash "printable" strings. To hash a string that contains binary characters, such as ascii zero, use MD5_AddBytes.

◆ MD5_BytesHash()

long MD5_BytesHash ( unsigned char *  digest,
const unsigned char *  lpData,
long  nDataLen 
)

Creates an MD5 message digest in Byte array format from a message in Byte array format.

Parameters
[out]digestarray to receive message digest.
[in]lpDataarray containing the message to be hashed.
[in]nDataLencontaining number of bytes in the array.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This function differs from other MD5 functions in that it creates a digest in Byte array format. This is particularly useful when you need to carry out repeated hash operations. lpDigest must be at least 16 (API_MAX_MD5_BYTES) bytes long.

◆ MD5_BytesHexHash()

long MD5_BytesHexHash ( char *  szDigest,
const unsigned char *  lpData,
long  nDataLen 
)

Creates an MD5 message digest in hexadecimal format from a message in Byte array format.

Parameters
[out]szDigestto receive message digest.
[in]lpDataarray containing the message to be hashed.
[in]nDataLencontaining number of bytes in the array.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program).

◆ MD5_FileHexHash()

long MD5_FileHexHash ( char *  szDigest,
const char *  szFileName,
const char *  szMode 
)

Creates an MD5 message digest in hexadecimal format from a file.

Parameters
[out]szDigestto receive message digest.
[in]szFileNamewith full path name of file.
[in]szModeto set mode: "t" or "b"
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program). Setting szMode equal to "t" or "T" will hash file in "text" mode treating a CR-LF pair as a single newline character. Setting szMode equal to "b" or "B" will hash file in "binary" mode treating CR-LF as two binary characters (default).

◆ MD5_HexDigest()

long MD5_HexDigest ( char *  szDigest,
long  hContext 
)

Returns the final message digest value as a hex string.

Parameters
[out]szDigestvariable long enough to receive the final message digest.
[in]hContexthandle to the MD5 context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This operation delivers the result of Add operations since the last Init or Reset operation. The handle to the context hContext must have been set up with a prior call to MD5_Init. The string variable szDigest must have been set up with at least 32 (API_MAX_MD5_CHARS) characters (33 in a C program) to receive the digest value in hex format. Note that this digest operation is a destructive, read-once operation. Once it has been performed, the context must be reset before being used to calculate another digest value.

◆ MD5_Hmac()

long MD5_Hmac ( char *  szDigest,
const unsigned char *  textBytes,
long  textLen,
const unsigned char *  lpKeyBytes,
long  keyLen 
)

Is a keyed-hash function that provides message authentication using the HMAC algorithm and the MD5 hash function.

Parameters
[out]szDigestvariable of sufficient length to receive the message digest in hex format.
[in]textBytesarray containing the text of the message.
[in]textLencontaining the number of bytes in the array
[in]lpKeyBytesarray containing the key.
[in]keyLencontaining the number of bytes in the key
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program).

◆ MD5_HmacHex()

long MD5_HmacHex ( char *  szDigest,
const char *  szHexText,
const char *  szHexKey 
)

Is a keyed-hash function that provides message authentication using the HMAC algorithm and the MD5 hash function, passing its arguments in hexadecimal format.

Parameters
[out]szDigestvariable of sufficient length to receive the message digest in hex format.
[in]szHexTextcontaining the text of the message in hexadecimal format.
[in]szHexKeycontaining the key in hexadecimal format.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program). szData and szKey are expected to be an even number of characters long, i.e. representing complete byte values. Any trailing odd character will be ignored.

◆ MD5_Init()

long MD5_Init ( void  )

Initialises the MD5 context ready for subsequent calls with MD5_AddString, MD5_AddBytes, and MD5_HexDigest.

Returns
non-zero handle of the MD5 context hContext. Returns zero if an error occurs.
Remarks
It is important to check for a zero context handle and stop if one occurs.

◆ MD5_Reset()

long MD5_Reset ( long  hContext)

Resets the context.

Parameters
[in]hContexthandle to the SHA-1 context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
Destroys the existing context. The results of any part-messages added to the context will be lost.

◆ MD5_StringHexHash()

long MD5_StringHexHash ( char *  szDigest,
const char *  szMessage 
)

Creates an MD5 message digest in hexadecimal format from a message of String type.

Parameters
[out]szDigestto receive message digest.
[in]szMessagecontaining the message to be hashed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program).

◆ PAD_BytesBlock()

long PAD_BytesBlock ( unsigned char *  lpOutput,
long  nOutputLen,
const unsigned char *  lpInput,
long  nBytes,
long  nBlkLen,
long  nOptions 
)

Creates an input block suitably padded for encryption by a block cipher in ECB or CBC mode.

Parameters
[out]lpOutputarray to be filled with padded encryption block.
[in]nOutputLenspecifying the size of the output array in bytes.
[in]lpInputarray containing the plaintext bytes to be padded.
[in]nBytesspecifying the length of the plaintext in bytes.
[in]nBlkLenspecifying the cipher block length in bytes (8 or 16).
[in]nOptionsOption flags. Select one of:
API_PAD_DEFAULT (0) to use the default PKCS5 padding
API_PAD_1ZERO to use OneAndZeroes padding
API_PAD_AX923 to use ANSIX923 padding
API_PAD_W3C to use W3C padding
Returns
If successful, the return value is the number of bytes in the output; otherwise it returns a negative error code.
Remarks
If nOutBytes is set to zero or lpOutput set to 0 (or NULL in C or ByVal 0& in VBA), then the required number of bytes will be returned. The output is always longer than the input. Only block lengths of 8 or 16 bytes are supported. For more details of the supported padding schemes, see Padding schemes for block ciphers.

◆ PAD_HexBlock()

long PAD_HexBlock ( char *  szOutput,
long  nMaxChars,
const char *  szInput,
long  nBlkLen,
long  nOptions 
)

Creates a hex-encoded input block suitably padded for encryption by a block cipher in ECB or CBC mode.

Parameters
[out]szOutputto receive the hexadecimal-encoded padded encryption block.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]szInputcontaining the hexadecimal-encoded data to be padded.
[in]nBlkLenspecifying the cipher block length in bytes (8 or 16).
[in]nOptionsOption flags. Select one of:
API_PAD_DEFAULT (0) to use the default PKCS5 padding
API_PAD_1ZERO to use OneAndZeroes padding
API_PAD_AX923 to use ANSIX923 padding
API_PAD_W3C to use W3C padding
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

The output is always longer than the input. Only block lengths of 8 or 16 bytes are supported. For more details of the supported padding schemes, see Padding schemes for block ciphers.

◆ PAD_UnpadBytes()

long PAD_UnpadBytes ( unsigned char *  lpOutput,
long  nOutputLen,
const unsigned char *  lpInput,
long  nBytes,
long  nBlkLen,
long  nOptions 
)

Removes the padding from an encryption block.

Parameters
[out]lpOutputarray to be filled with the output.
[in]nOutputLenspecifying the size of the output array in bytes.
[in]lpInputarray containing the padded data.
[in]nBytesspecifying the length of the input in bytes.
[in]nBlkLenspecifying the cipher block length in bytes (8 or 16).
[in]nOptionsOption flags. Select one of:
API_PAD_DEFAULT (0) to use the default PKCS5 padding
API_PAD_1ZERO to use OneAndZeroes padding
API_PAD_AX923 to use ANSIX923 padding
API_PAD_W3C to use W3C padding
Returns
If successful, the return value is the number of bytes in the output; otherwise it returns a negative error code.
Remarks
The padding is expected according to the convention in PKCS#5, PKCS#7 and CMS.

If nOutBytes is set to zero or lpOutput set to 0 (or NULL in C or ByVal 0& in VBA), then the required number of bytes will be returned. The output is always shorter than the input. Only block lengths of 8 or 16 bytes are supported. For more details of the supported padding schemes, see Padding schemes for block ciphers.

Note that it is still possible to have a "valid" padding string at the end of incorrectly deciphered data

  • just by coincidence - so you may get a "valid" result from using the Unpad function, but the decrypted text is garbage.

◆ PAD_UnpadHex()

long PAD_UnpadHex ( char *  szOutput,
long  nMaxChars,
const char *  szInput,
long  nBlkLen,
long  nOptions 
)

Removes the padding from a hex-encoded encryption block.

Parameters
[out]szOutputto receive the hexadecimal-encoded output.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]szInputcontaining the hexadecimal-encoded padded data.
[in]nBlkLenspecifying the cipher block length in bytes (8 or 16).
[in]nOptionsOption flags. Select one of:
API_PAD_DEFAULT (0) to use the default PKCS5 padding
API_PAD_1ZERO to use OneAndZeroes padding
API_PAD_AX923 to use ANSIX923 padding
API_PAD_W3C to use W3C padding
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
The padding is expected according to the convention specified in nOptions. The output is always shorter than the input. Only block lengths of 8 or 16 bytes are supported. Note that it is a valid result for szOutput to be an empty string. For more details of the supported padding schemes, see Padding schemes for block ciphers.

For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.

When using the VBA wrapper function padUnpadHex and there is an error, then the input is returned unchanged. The user should check for this and signal an error. See the VBA wrapper example below.

◆ PBE_Kdf2()

long PBE_Kdf2 ( unsigned char *  lpDerivedKey,
long  nKeyLen,
const unsigned char *  lpPwd,
long  nPwdLen,
const unsigned char *  lpSalt,
long  nSaltLen,
long  nCount,
long  nOptions 
)

Derives a key of any length from a password using the PBKDF2 algorithm from PKCS#5 v2.1.

Parameters
[out]lpDerivedKeyByte array to be filled with derived key.
[in]nKeyLensize of the required key in bytes.
[in]lpPwdByte array containing the password.
[in]nPwdLenlength of the password in bytes.
[in]lpSaltByte array containing the salt.
[in]nSaltLenlength of the salt in bytes.
[in]nCountrequired iteration count.
[in]nOptionsOption flags. Select one of:
API_HMAC_SHA1 (0) to use the HMAC-SHA-1 algorithm (default)
API_HMAC_SHA256 to use the HMAC-SHA-256 algorithm
API_HMAC_SHA384 to use the HMAC-SHA-384 algorithm
API_HMAC_SHA512 to use the HMAC-SHA-512 algorithm
API_HMAC_SHA224 to use the HMAC-SHA-224 algorithm
API_HMAC_MD5 to use the HMAC-MD5 algorithm
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The output buffer for the derived key abDerivedKey must have been dimensioned to at least the required length nKeyLen in bytes.

◆ PBE_Kdf2Hex()

long PBE_Kdf2Hex ( char *  szOutput,
long  nMaxChars,
long  dkBytes,
const char *  szPwd,
const char *  szSaltHex,
long  nCount,
long  nOptions 
)

Derives a key of any length from a password using the PBKDF2 algorithm from PKCS#5 v2.1 with the salt and derived key encoded in hexadecimal.

Parameters
[out]szOutputto receive the hexadecimal-encoded derived key.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]dkBytesspecifying the size of the required key in bytes.
[in]szPwdcontaining the password.
[in]szSaltHexcontaining the salt in hex format.
[in]nCountspecifying the required iteration count.
[in]nOptionsOption flags. Select one of:
API_HMAC_SHA1 (0) to use the HMAC-SHA-1 algorithm (default)
API_HMAC_SHA256 to use the HMAC-SHA-256 algorithm
API_HMAC_SHA384 to use the HMAC-SHA-384 algorithm
API_HMAC_SHA512 to use the HMAC-SHA-512 algorithm
API_HMAC_SHA224 to use the HMAC-SHA-224 algorithm
API_HMAC_MD5 to use the HMAC-MD5 algorithm
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The output string szOutput should be pre-dimensioned to be at least double the required key length in bytes. (Hint: specify nMaxChars as Len(strOutput)). The seed szSaltHex is specified in hex format and can be any even number of hex digits in length. The password szPassword is normal text, not hexadecimal.

◆ PBE_Scrypt()

long PBE_Scrypt ( unsigned char *  lpDerivedKey,
long  nKeyLen,
const unsigned char *  lpPwd,
long  nPwdLen,
const unsigned char *  lpSalt,
long  nSaltLen,
long  nParamN,
long  nParamR,
long  nParamP,
long  nOptions 
)

Derives a key of any length from a password using the SCRYPT algorithm.

Parameters
[out]lpDerivedKeyByte array to be filled with derived key.
[in]nKeyLensize of required key in bytes.
[in]lpPwdByte array containing the password.
[in]nPwdLenlength of the password in bytes.
[in]lpSaltByte array containing the salt.
[in]nSaltLenlength of the salt in bytes.
[in]nParamNCPU/Memory cost parameter N ("costParameter") a number greater than one and a power of 2.
[in]nParamRBlock size r ("blockSize")
[in]nParamPParallelization parameter p ("parallelizationParameter")
[in]nOptionsOption flags: not used in this release. Specify zero.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This uses the SCRYPT algorithm from [RFC7914]. There are restrictions on the values of the parameters N, r and p. In particular, N must be larger than 1 and a power of 2.

The output buffer for the derived key abDerivedKey must have been dimensioned to at least the required length nKeyLen in bytes.

◆ PBE_ScryptHex()

long PBE_ScryptHex ( char *  szOutput,
long  nMaxChars,
long  dkBytes,
const char *  szPwd,
const char *  szSaltHex,
long  nParamN,
long  nParamR,
long  nParamP,
long  nOptions 
)

Derives a key of any length from a password using the SCRYPT algorithm with the salt and derived key encoded in hexadecimal.

Parameters
[out]szOutputto receive the hexadecimal-encoded derived key.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]dkBytesspecifying the size of the required key in bytes.
[in]szPwdcontaining the password (as normal text).
[in]szSaltHexcontaining the salt in hex format.
[in]nParamNCPU/Memory cost parameter N ("costParameter") a number greater than one and a power of 2.
[in]nParamRBlock size r ("blockSize")
[in]nParamPParallelization parameter p ("parallelizationParameter")
[in]nOptionsOption flags: not used in this release. Specify zero.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The output string szOutput should be pre-dimensioned to be at least double the required key length in bytes. (Hint: specify nMaxChars as Len(strOutput)). The seed szSaltHex is specified in hex format and can be any even number of hex digits in length. The password szPassword is normal text, not hexadecimal.

◆ PC1_Bytes()

long PC1_Bytes ( unsigned char *  lpOutput,
unsigned char *  lpInput,
long  nBytes,
unsigned char *  lpKey,
long  nKeyBytes 
)

Enciphers an array of Bytes in one step using the RC4-compatible 'PC1' algorithm.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]nKeyBytesequal to length of the key in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData can be of any length provided lpOutput is at least as long. The key lpKey can be any length. lpOutput and lpData may be the same.

◆ PC1_File()

long PC1_File ( char *  szFileOut,
char *  szFileIn,
unsigned char *  lpKey,
long  nKeyBytes 
)

Enciphers a file using the RC4-compatible 'PC1' algorithm.

The key is passed as an array of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]nKeyBytescontaining the length of the key in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key array lpKey can be any length.

The output file szFileOut will be overwritten without warning. The input and output filenames must not be the same.

◆ PC1_Hex()

long PC1_Hex ( char *  szOutput,
long  nMaxChars,
const char *  szInputHex,
const char *  szKeyHex 
)

Enciphers data encoded in hex format in one step using the RC4-compatible 'PC1' algorithm.

Parameters
[out]szOutputto receive the hexadecimal-encoded output.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]szInputHexcontaining the input data in hex format.
[in]szKeyHexcontaining the key in hex format.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
All hex parameters must be an even number of hexadecimal digits. The input data szInputHex can be of any length provided szOutput is at least as long. The key szKeyHex can be any length. szOutput and szInputHex should be different variables.

◆ PRF_Bytes()

long PRF_Bytes ( unsigned char *  lpOutput,
long  nOutBytes,
const void *  lpMessage,
long  nMsgLen,
const void *  lpKey,
long  nKeyLen,
const char *  szCustom,
long  nOptions 
)

Generate output bytes using a pseudorandom function (PRF).

Parameters
[out]lpOutputbyte buffer to receive the output.
[in]nOutBytessize of output buffer in bytes.
[in]lpMessagebyte array containing the input data.
[in]nMsgLenlength of the input data in bytes.
[in]lpKeybyte array containing the key.
[in]nKeyLenlength of the key in bytes.
[in]szCustomcustomization string (optional).
[in]nOptionsOption flags. Select one of:
API_KMAC_128 to use KMAC128 (KMAC with SHAKE128)
API_KMAC_256 to use KMAC256 (KMAC with SHAKE256).
Returns
If successful, the return value is the number of bytes in the output; otherwise it returns a negative error code.
Remarks
The output buffer lpOutput must exist. It will be filled with exactly nOutBytes bytes. Note there is no zero option for nOptions: a valid option flag must be specified. For KMAC, the default customization string szCustom is the empty string "".

◆ RNG_BytesWithPrompt()

long RNG_BytesWithPrompt ( unsigned char *  lpOutput,
long  nOutputLen,
const char *  szPrompt,
long  nOptions 
)

Generates a random set of byte data suitable for cryptographic keys with a prompt for the user to enter random keystrokes and mouse movements.

Parameters
[out]lpOutputarray to receive the random data.
[in]nOutputLenspecifying the required length in bytes.
[in]szPromptspecifying an (optional) prompt for the dialog. Specify an empty string ("") or NULL to use the default dialog.
[in]nOptionsoption flags:
API_DEFAULT (0) for default options
API_RNG_STRENGTH_112 to make user generate an estimated 112 bits of security (default)
API_RNG_STRENGTH_128 to make user generate an estimated 128 bits of security
API_RNG_STRENGTH_192 to make user generate an estimated 192 bits of security
API_RNG_STRENGTH_256 to make user generate an estimated 256 bits of security
Returns
If successful, the return value is 0. If the parameters are invalid, it returns a negative error code.
Remarks
Once started, there is no way to abandon the dialog that prompts the user except by terminating the process. Some applications may not handle the GUI dialog. Make your own tests to check. The maximum number of random bytes that can be requested in one call is 65,536 (64 kB). See Random Number Generator for more information on the RNG and its compliance with the relevant standards.

◆ RNG_HexWithPrompt()

long RNG_HexWithPrompt ( char *  szOutput,
long  nMaxChars,
long  nBytes,
const char *  szPrompt,
long  nOptions 
)

Generates a random set of data in hexadecimal format suitable for cryptographic keys with a prompt for the user to enter random keystrokes and mouse movements.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]nBytesvalue of the required random data length in bytes.
[in]szPromptspecifying an (optional) prompt for the dialog. Specify an empty string ("") or NULL to use the default dialog.
[in]nOptionsoption flags:
API_DEFAULT (0) for default options
API_RNG_STRENGTH_112 to make user generate an estimated 112 bits of security (default)
API_RNG_STRENGTH_128 to make user generate an estimated 128 bits of security
API_RNG_STRENGTH_192 to make user generate an estimated 192 bits of security
API_RNG_STRENGTH_256 to make user generate an estimated 256 bits of security
Returns
If successful, the return value is 0. If the parameters are invalid, it returns a negative error code.
Remarks
See the remarks for RNG_BytesWithPrompt.

◆ RNG_Initialize()

long RNG_Initialize ( const char *  szSeedFile,
long  nOptions 
)

Initializes the RNG generator with a seed file.

Parameters
[in]szSeedFilespecifying a seed file. May be the empty string "".
[in]nOptionsoption flags:
API_DEFAULT (0) for default options
API_RNG_NO_INTEL_DRNG to turn off support for Intel(R) DRNG for the current session.
Returns
If successful, the return value is zero; otherwise it returns a non-zero error code. If "" is passed for szSeedFile, it returns the support status for Intel DRNG (see Remarks).
Remarks
A seed file maintains the entropy state between sessions. If the seed file does not exist, it will be created, using any existing entropy. The file must be writable by the user. File locking is used to prevent interference from simultaneous use by others. The seed file is automatically updated by this procedure. Any existing file will be overwritten without warning.

Intel(R) DRNG support: [New in v6.22.1] Pass an empty string "" for szSeedFile to query support for Intel(R) Digital Random Number Generator (DRNG) on your system (and add an extra 256 bits of entropy, if available). If supported, the return value is a positive integer (1,2,3), otherwise it returns the error code PRNG_ERR_NOTAVAIL (-214). See Intel(R) DRNG.

Alternatively, use the option API_RNG_NO_INTEL_DRNG to turn off support for Intel(R) DRNG for the current session. You might use this if calls to Intel(R) DRNG are causing problems on your system.

◆ RNG_KeyBytes()

long RNG_KeyBytes ( unsigned char *  lpOutput,
long  nOutputLen,
const void *  lpSeed,
long  nSeedLen 
)

Generates a random set of byte data suitable for cryptographic keys.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]nOutputLenvalue of the required key length in bytes.
[in]lpSeedcontaining an (optional) user-specified seed to be used by the random number generator. Specify an empty string ("") or NULL to ignore..
[in]nSeedLenspecifiying the size of the seed in bytes.
Returns
Always returns zero. If the function fails its continuous random number generator test, a critical error will occur. See Self Tests for more details.
Remarks
The seed szSeed is optional and is added to the automatic seed values generated internally. The seed cannot directly affect the value of the output; it will just ensure that it will be different.

◆ RNG_KeyHex()

long RNG_KeyHex ( char *  szOutput,
long  nMaxChars,
long  nBytes,
const void *  lpSeed,
long  nSeedLen 
)

Generates a random set of data in hexadecimal format suitable for cryptographic keys.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]nBytesvalue of the required key length in bytes.
[in]lpSeedcontaining an (optional) user-specified seed to be used by the random number generator. Specify an empty string ("") or NULL to ignore..
[in]nSeedLenspecifying the size of the seed in bytes.
Returns
Always returns zero. If the function fails its continuous random number generator test, a critical error will occur. See Self Tests for more details.
Remarks
The output string szOutput should be pre-dimensioned to be at least double the required key length in bytes. Hint: specify nMaxChars as Len(strOutput). C/C++ users must add one to this value when allocating memory. The seed szSeed is optional and is added to the automatic seed values generated internally. The seed cannot directly affect the value of the output; it will just ensure that it will be different.

◆ RNG_MakeSeedFile()

long RNG_MakeSeedFile ( const char *  szSeedFile,
const char *  szPrompt,
long  nOptions 
)

Creates a new seed file suitable for use with RNG_Initialize.

Parameters
[in]szSeedFilespecifying the seed file to be created.
[in]szPromptspecifying an (optional) prompt for the dialog. Specify an empty string ("") or NULL to use the default dialog.
[in]nOptionsoption flags:
API_DEFAULT (0) for default options
API_RNG_STRENGTH_112 to make user generate an estimated 112 bits of security (default)
API_RNG_STRENGTH_128 to make user generate an estimated 128 bits of security
API_RNG_STRENGTH_192 to make user generate an estimated 192 bits of security
API_RNG_STRENGTH_256 to make user generate an estimated 256 bits of security
Returns
If successful, the return value is zero; otherwise it returns a non-zero error code.
Remarks
This uses a dialog window and expects the user to type in random keystrokes. Such a GUI interface may not be appropriate in all circumstances. A new seed file is always created. Any existing file with the same name will be overwritten without warning. Alternatively, use the command-line program, ApiMkRngSeed.exe, provided in the distribution to make a new seed file [updated in v6.22].

◆ RNG_NonceData()

long RNG_NonceData ( unsigned char *  lpOutput,
long  nBytes 
)

Returns a random nonce (number used once) as a specified-length byte array.

This replaces the RNG_Nonce function from version 2.

Parameters
[out]lpOutputarray to be filled with random values.
[in]nBytesspecifying the number of required bytes in the nonce.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The array lpOutput must be at least nBytes bytes long.

◆ RNG_NonceDataHex()

long RNG_NonceDataHex ( char *  szOutput,
long  nMaxChars,
long  nBytes 
)

Returns a specified-length random nonce (number used once) as a hexadecimal string.

This is a safer version of the RNG_NonceHex function in version 2.

Parameters
[out]szOutputarray to be filled with random values expressed in hexadecimal.
[in]nMaxCharsspecifying the maximum number of characters in szOutput.
[in]nBytesspecifying the number of required bytes in the nonce.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The array szOutput must be filled with dummy characters to two times nBytes before calling the function. The length of the output buffer in characters must be specified.

◆ RNG_Number()

int32_t RNG_Number ( int32_t  nLower,
int32_t  nUpper 
)

Returns a random 32-bit number between specified limits.

Parameters
[in]nLowerspecifying a lower limit.
[in]nUpperspecifying an upper limit.
Returns
A random number between nLower and nUpper.
Remarks
The number returned is an integer selected at random from the set {nLower, ..., nUpper}.

◆ RNG_Test()

long RNG_Test ( const char *  szFileName)

Carries out a NIST SP800-90 health check and FIPS140-2 statistical tests on the random number generator.

Parameters
[in]szFileNamecontaining the full path name of a file to be created containing the results of the test.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
If the file specified in strFileName does not exist, it will be created. If it already exists, it will be overwritten without warning. If no directory path is specified, the file will be created in the current default directory. This function carries out, on demand, the health testing procedure from section 11.3 of [SP80090A] and the statistical tests for randomness from section 4.9.1 of the October 2001 version of FIPS-140-2 [FIPS140]. The statistical test results and the 20,000-bit sample are written to a text file. Specify an empty ("") or NULL szFileName to avoid creating an output file and just carry out the tests. The statistical tests have since been removed from FIPS-140-2, but we do them anyway. If any tests fail, a non-zero error code will be returned.

◆ RNG_TestDRBGVS()

long RNG_TestDRBGVS ( char *  szOutput,
long  nMaxChars,
long  nReturnedBitsLen,
const char *  szEntropyInput,
const char *  szNonce,
const char *  szPersonalizationString,
const char *  szAdditionalInput1,
const char *  szEntropyReseed,
const char *  szAdditionalInputReseed,
const char *  szAdditionalInput2,
long  nOptions 
)

Tests the random number generator for conformance to NIST SP 800-90A using the relevant test specified in the Deterministic Random Bit Generator Validation System (DRBGVS).

Parameters
[out]szOutputto receive the ReturnedBits in hexadecimal format.
[in]nMaxCharsspecifying the maximum number of hexadecimal characters to be received.
[in]nReturnedBitsLenspecifying the number of bits to be returned from each call to the generate function in the test.
[in]szEntropyInputcontaining the EntropyInput value in hex format.
[in]szNoncecontaining the Nonce value in hex format.
[in]szPersonalizationStringcontaining the PersonalizationString value in hex format.
[in]szAdditionalInput1containing the first AdditionalInput value in hex format.
[in]szEntropyReseedcontaining the EntropyReseed value in hex format.
[in]szAdditionalInputReseedcontaining the AdditionalInputReseed value in hex format.
[in]szAdditionalInput2containing the second AdditionalInput value in hex format.
[in]nOptionsOption flags: not used in this release. Specify zero.
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
The test procedure, the input values and the expected output are described in the [DRBGVS] document and associated test vectors. [Changed in v6.22] The relevant DRBG mechanism is HMAC_DRBG SHA-512 without prediction resistance. Use the empty string "" to pass a zero-length input. All hex strings must have an even number of characters.

◆ RNG_UpdateSeedFile()

long RNG_UpdateSeedFile ( const char *  szSeedFile,
long  nOptions 
)

Updates an RNG seed file.

Parameters
[in]szSeedFilespecifying the seed file to be updated.
[in]nOptionsoption flags: not used in this release. Specify zero.
Returns
If successful, the return value is zero; otherwise it returns a non-zero error code.
Remarks
The seed file must be writable by the user. Use this function at periodic intervals or when exiting your application. If the file does not exist it will be created. Any existing file of the same name will be overwritten without warning.

◆ SHA1_AddBytes()

long SHA1_AddBytes ( long  hContext,
const unsigned char *  lpData,
long  nDataLen 
)

Adds an array of bytes to the digest.

Parameters
[in]hContexthandle to the SHA-1 context.
[in]lpDataarray containing the next part of the message to be hashed.
[in]nDataLencontaining the number of bytes in the array
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to SHA1_Init. This function may be called many times before creating the final message digest with SHA1_HexDigest. SHA1_AddString may also be called.

◆ SHA1_AddString()

long SHA1_AddString ( long  hContext,
const char *  szMessage 
)

Adds a string of ascii characters to the digest.

Parameters
[in]hContexthandle to the SHA-1 context.
[in]szMessagecontaining the next part of the message to be hashed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to SHA1_Init. This function may be called many times before creating the final message digest with SHA1_HexDigest This function should only be used to hash strings of "printable" ANSI characters. To hash a string that contains binary characters, such as ascii zero, use SHA1_AddBytes.

◆ SHA1_BytesHash()

long SHA1_BytesHash ( unsigned char *  digest,
const unsigned char *  lpData,
long  nDataLen 
)

Creates a SHA-1 message digest in Byte array format from a message in Byte array format.

Parameters
[out]digestarray to receive message digest.
[in]lpDataarray containing the message to be hashed.
[in]nDataLencontaining number of bytes in the array.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This function differs from other SHA1 functions in that it creates a digest in Byte array format. This is particularly useful when you need to carry out repeated hash operations. lpDigest must be at least 20 (API_MAX_SHA1_BYTES)bytes long.

◆ SHA1_BytesHexHash()

long SHA1_BytesHexHash ( char *  szDigest,
const unsigned char *  lpData,
long  nDataLen 
)

Creates a SHA-1 message digest in hexadecimal format from a message in Byte array format.

Parameters
[out]szDigestto receive message digest.
[in]lpDataarray containing the message to be hashed.
[in]nDataLencontaining number of bytes in the array.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 40 (API_MAX_SHA1_CHARS) characters long (41 in a C program).

◆ SHA1_FileHexHash()

long SHA1_FileHexHash ( char *  szDigest,
const char *  szFileName,
const char *  szMode 
)

Creates a SHA-1 message digest in hexadecimal format from a file.

Parameters
[out]szDigestto receive message digest.
[in]szFileNamewith full path name of file.
[in]szModeto set mode: "t" or "b"
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 40 (API_MAX_SHA1_CHARS) characters long (41 in a C program). Setting szMode equal to "t" or "T" will hash file in "text" mode treating a CR-LF pair as a single newline character. Setting szMode equal to "b" or "B" will hash file in "binary" mode treating CR-LF as two binary characters (default).

◆ SHA1_HexDigest()

long SHA1_HexDigest ( char *  szDigest,
long  hContext 
)

Returns the final message digest value as a hex string.

Parameters
[out]szDigestvariable long enough to receive the final message digest.
[in]hContexthandle to the SHA-1 context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This operation delivers the result of Add operations since the last Init or Reset operation. The handle to the context hContext must have been set up with a prior call to SHA1_Init. The string variable szDigest must have been set up with at least 40 (API_MAX_SHA1_CHARS) characters (41 in a C program) to receive the digest value in hex format. Note that this digest operation is a destructive, read-once operation. Once it has been performed, the context must be reset before being used to calculate another digest value.

◆ SHA1_Hmac()

long SHA1_Hmac ( char *  szDigest,
const unsigned char *  textBytes,
long  textLen,
const unsigned char *  lpKeyBytes,
long  keyLen 
)

Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-1 hash function.

Parameters
[out]szDigestvariable of sufficient length to receive the message digest in hex format.
[in]textBytesarray containing the text of the message.
[in]textLencontaining the number of bytes in the array
[in]lpKeyBytesarray containing the key.
[in]keyLencontaining the number of bytes in the key
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 40 (API_MAX_SHA1_CHARS) characters long (41 in a C program).

◆ SHA1_HmacHex()

long SHA1_HmacHex ( char *  szDigest,
const char *  sHexText,
const char *  sHexKey 
)

Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-1 hash function, passing its arguments in hexadecimal format.

Parameters
[out]szDigestvariable of sufficient length to receive the message digest in hex format.
[in]sHexTextcontaining the text of the message in hexadecimal format.
[in]sHexKeycontaining the key in hexadecimal format.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The string variable szDigest must be at least 40 (API_MAX_SHA1_CHARS) characters long (41 in a C program). szData and szKey are expected to be an even number of characters long, i.e. representing complete byte values. Any trailing odd character will be ignored.

◆ SHA1_Init()

long SHA1_Init ( void  )

Initialises the SHA-1 context ready for subsequent calls with SHA1_AddString, SHA1_AddBytes, and SHA1_HexDigest.

Returns
non-zero handle of the SHA-1 context hContext. Returns zero if an error occurs.
Remarks
It is important to check for a zero context handle and stop if one occurs.

◆ SHA1_Reset()

long SHA1_Reset ( long  hContext)

Resets the context.

Parameters
[in]hContexthandle to the SHA-1 context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
Destroys the existing context. The results of any part-messages added to the context will be lost.

◆ SHA1_StringHexHash()

long SHA1_StringHexHash ( char *  szDigest,
const char *  szMessage 
)

Creates a SHA-1 message digest in hexadecimal format from a message of String type.

Parameters
[out]szDigestto receive message digest.
[in]szMessagecontaining the message to be hashed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 40 (API_MAX_SHA1_CHARS) characters long (41 in a C program).

◆ SHA2_AddBytes()

long SHA2_AddBytes ( long  hContext,
const unsigned char *  lpData,
long  nDataLen 
)

Adds an array of bytes to the digest.

Parameters
[in]hContexthandle to the SHA-2 context.
[in]lpDataarray containing the next part of the message to be hashed.
[in]nDataLencontaining the number of bytes in the array
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to SHA2_Init. This function may be called many times before creating the final message digest with SHA2_HexDigest. SHA2_AddString may also be called.

◆ SHA2_AddString()

long SHA2_AddString ( long  hContext,
const char *  szMessage 
)

Adds a string of ascii characters to the digest.

Parameters
[in]hContexthandle to the SHA-2 context.
[in]szMessagecontaining the next part of the message to be hashed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to SHA2_Init. This function may be called many times before creating the final message digest with SHA2_HexDigest This function should only be used to hash strings of "printable" ANSI characters. To hash a string that contains binary characters, such as ascii zero, use SHA1_AddBytes.

◆ SHA2_BytesHash()

long SHA2_BytesHash ( unsigned char *  lpDigest,
const unsigned char *  lpData,
long  nDataLen 
)

Creates a SHA-256 message digest in Byte array format from a message in Byte array format.

Parameters
[out]lpDigestarray to receive message digest.
[in]lpDataarray containing the message to be hashed.
[in]nDataLencontaining number of bytes in the array.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This function differs from other SHA2 functions in that it creates a digest in Byte array format. This is particularly useful when you need to carry out repeated hash operations. lpDigest must be at least 32 (API_MAX_SHA2_BYTES) bytes long.

◆ SHA2_BytesHexHash()

long SHA2_BytesHexHash ( char *  szDigest,
const unsigned char *  lpData,
long  nDataLen 
)

Creates a SHA-256 message digest in hexadecimal format from a message in Byte array format.

Parameters
[out]szDigestto receive message digest.
[in]lpDataarray containing the message to be hashed.
[in]nDataLencontaining number of bytes in the array.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 in a C program).

◆ SHA2_FileHexHash()

long SHA2_FileHexHash ( char *  szDigest,
const char *  szFileName,
const char *  szMode 
)

Creates a SHA-256 message digest in hexadecimal format from a file.

Parameters
[out]szDigestto receive message digest.
[in]szFileNamewith full path name of file.
[in]szModeto set mode: "t" or "b"
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 in a C program). Setting szMode equal to "t" or "T" will hash file in "text" mode treating a CR-LF pair as a single newline character. Setting szMode equal to "b" or "B" will hash file in "binary" mode treating CR-LF as two binary characters (default).

◆ SHA2_HexDigest()

long SHA2_HexDigest ( char *  szDigest,
long  hContext 
)

Returns the final message digest value as a hex string.

Parameters
[out]szDigestvariable long enough to receive the final message digest.
[in]hContexthandle to the SHA-1 context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
This operation delivers the result of Add operations since the last Init or Reset operation. The handle to the context hContext must have been set up with a prior call to SHA1_Init. The string variable szDigest must have been set up with at least 64 (API_MAX_SHA2_CHARS) characters (65 in a C program) to receive the digest value in hex format. Note that this digest operation is a destructive, read-once operation. Once it has been performed, the context must be reset before being used to calculate another digest value.

◆ SHA2_Hmac()

long SHA2_Hmac ( char *  szDigest,
const unsigned char *  textBytes,
long  textLen,
const unsigned char *  lpKeyBytes,
long  keyLen 
)

Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-256 hash function.

Parameters
[out]szDigestvariable of sufficient length to receive the message digest in hex format.
[in]textBytesarray containing the text of the message.
[in]textLencontaining the number of bytes in the array
[in]lpKeyBytesarray containing the key.
[in]keyLencontaining the number of bytes in the key
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 in a C program).

◆ SHA2_HmacHex()

long SHA2_HmacHex ( char *  szDigest,
const char *  sHexText,
const char *  sHexKey 
)

Is a keyed-hash function that provides message authentication using the HMAC algorithm and the SHA-256 hash function, passing its arguments in hexadecimal format.

Parameters
[out]szDigestvariable of sufficient length to receive the message digest in hex format.
[in]sHexTextcontaining the text of the message in hexadecimal format.
[in]sHexKeycontaining the key in hexadecimal format.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 in a C program). szData and szKey are expected to be an even number of characters long, i.e. representing complete byte values. Any trailing odd character will be ignored.

◆ SHA2_Init()

long SHA2_Init ( void  )

Initialises the SHA-256 context ready for subsequent calls with SHA2_AddString, SHA2_AddBytes, and SHA2_HexDigest.

Returns
non-zero handle of the SHA-256 context hContext. Returns zero if an error occurs.
Remarks
It is important to check for a zero context handle and stop if one occurs.

◆ SHA2_Reset()

long SHA2_Reset ( long  hContext)

Resets the context.

Parameters
[in]hContexthandle to the SHA-1 context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
Destroys the existing context. The results of any part-messages added to the context will be lost.

◆ SHA2_StringHexHash()

long SHA2_StringHexHash ( char *  szDigest,
const char *  szMessage 
)

Creates a SHA-256 message digest in hexadecimal format from a message of String type.

Parameters
[out]szDigestto receive message digest.
[in]szMessagecontaining the message to be hashed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 in a C program).

◆ SHA3_AddBytes()

long SHA3_AddBytes ( long  hContext,
const unsigned char *  lpData,
long  nDataLen 
)

Adds an array of bytes to the digest.

Parameters
[in]hContexthandle to the SHA-3 context.
[in]lpDatabyte array containing the next part of the message to be hashed.
[in]nDataLennumber of bytes in the array
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to SHA3_Init. This function may be called many times before creating the final message digest with SHA3_HexDigest. SHA3_AddString may also be called.

◆ SHA3_AddString()

long SHA3_AddString ( long  hContext,
const char *  szMessage 
)

Adds a string of ascii characters to the digest.

Parameters
[in]hContexthandle to the SHA-3 context.
[in]szMessagestring containing the next part of the message to be hashed.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The handle to the context hContext must have been set up with a prior call to SHA3_Init. This function may be called many times before creating the final message digest with SHA3_HexDigest This function should only be used to hash strings of "printable" ANSI characters. To hash a string that contains binary characters, such as ascii zero, use SHA3_AddBytes.

◆ SHA3_HexDigest()

long SHA3_HexDigest ( char *  szOutput,
long  nMaxChars,
long  hContext 
)

Returns the final message digest value as a hex string.

Parameters
[out]szOutputbuffer to receive the final message digest in hexadecimal format.
[in]nMaxCharsmaximum number of hex characters to be received.
[in]hContexthandle to the SHA-3 context.
Returns
If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.
Remarks
This operation delivers the result of Add operations since the Init operation. The handle to the context hContext must have been set up with a prior call to SHA3_Init.

The final digest value will be truncated to the specified length if nMaxChars is less than the required digest size.

Note that this digest operation is a destructive, read-once operation. Once it has been performed, the context must be initialized before being used to calculate another digest value.

◆ SHA3_Init()

long SHA3_Init ( long  nHashBitLen)

Initialises the SHA-3 context ready for subsequent calls with SHA3_AddString, SHA3_AddBytes, and SHA3_HexDigest.

Parameters
[in]nHashBitLenspecifying the number of bits in the hash output. This must be one of 224, 256, 384 or 512.
Returns
Non-zero handle of the SHA-3 context hContext. Returns zero if an error occurs.
Remarks
It is important to check for a zero context handle and stop if one occurs. An error can occur, for example, if an invalid value for nHashBitLen is passed.

◆ SHA3_LengthInBytes()

long SHA3_LengthInBytes ( long  hContext)

Returns the number of bytes in the hash output for the algorithm defined in the current SHA-3 context.

Parameters
[in]hContexthandle to the current SHA-3 context.
Returns
the number of bytes in the hash output for the algorithm defined in the current SHA-3 context, or a negative error code.
Remarks
 

◆ SHA3_Reset()

long SHA3_Reset ( long  hContext)

Resets the context.

Parameters
[in]hContexthandle to the SHA-3 context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
Destroys the existing context. The results of any part-messages added to the context will be lost.

◆ TDEA_B64Mode()

long TDEA_B64Mode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a base64 string using a specified mode.

The key and initialization vector are represented as base64 strings.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in base64.
[in]szKeycontaining the key in base64.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV), if required, in base64.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must represent a multiple of the block size (8 bytes) when decoded. If not, an error will be returned. The initialization vector string szIV must represent exactly 8 bytes unless szMode is ECB, in which case szIV is ignored (use ""). The key szKey must represent exactly 24 bytes, the required key length. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ TDEA_Bytes()

long TDEA_Bytes ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt 
)

Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey must be exactly 24 bytes long. The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.

◆ TDEA_BytesMode()

long TDEA_BytesMode ( unsigned char *  lpOutput,
const unsigned char *  lpInput,
long  nBytes,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts an array of Bytes in one step using a specified mode.

Parameters
[out]lpOutputarray of sufficient length to receive the output.
[in]lpInputarray containing the input data.
[in]nBytesequal to length of the input data in bytes.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVcontaining the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey must be exactly 24 bytes long and the IV, if required, exactly 8 bytes long. The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.

◆ TDEA_File()

long TDEA_File ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as arrays of bytes.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key lpKey must be exactly 24 bytes long. The initialization vector byte array lpInitV must be exactly the block size of 8 bytes long, except for ECB mode, where it is ignored (use 0).

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

◆ TDEA_FileExt()

long TDEA_FileExt ( const char *  szFileOut,
const char *  szFileIn,
const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV,
long  nOptions 
)

Encrypts or decrypts a file using a specified mode with extended options.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]lpKeyarray containing the key.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVarray containing the initialization vector (IV), or zero (0) for ECB mode.
[in]nOptionsoption flags:
Zero (0) for default behaviour as per TDEA_File.
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode)
API_PAD_LEAVE to leave any padding in place when decrypting (ECB and CBC modes only; ignored if encrypting)
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
For the default behaviour, see TDEA_File. The options are ignored if not applicable. For more information on the behaviour of the options, see Extensions to block cipher functions for files.

◆ TDEA_FileHex()

long TDEA_FileHex ( const char *  szFileOut,
const char *  szFileIn,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts a file using a specified mode.

The key and initialization vector are passed as hexadecimal strings.

Parameters
[in]szFileOutwith the full path name of the output file to be created.
[in]szFileInwith the full path name of the input file to be processed.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The key string szHexKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes/192 bits). The initialization vector szHexIV must be exactly 16 hex characters long (i.e. representing exactly the block size of 8 bytes), except for ECB mode, where it is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f].

The output file szFileOut will be overwritten without warning. If there is an error [new in version 3.3], the output file will not exist. The input and output filepaths must not be the same.

In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] and [PKCS5].

Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.

◆ TDEA_Final()

long TDEA_Final ( long  hContext)

Closes and clears the TDEA context.

Parameters
[in]hContextcontaining the handle to the TDEA context.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.

◆ TDEA_Hex()

long TDEA_Hex ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt 
)

Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation.

The process is carried out in one step in Electronic Codebook (EBC) mode.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. The key string szKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes). The parity bit is ignored. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].

◆ TDEA_HexMode()

long TDEA_HexMode ( char *  szOutput,
const char *  szInput,
const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Encrypts or decrypts data represented as a hexadecimal string using a specified mode.

The key and initialization vector are represented as a hexadecimal string.

Parameters
[out]szOutputof sufficient length to receive the output.
[in]szInputcontaining the input data in hexadecimal.
[in]szKeycontaining the key in hexadecimal.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector (IV) in hexadecimal.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The length of the input string szInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. The key string szHexKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes). The initialization vector string szIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes) unless szMode is ECB, in which case szIV is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.

◆ TDEA_Init()

long TDEA_Init ( const unsigned char *  lpKey,
int  fEncrypt,
const char *  szMode,
const unsigned char *  lpIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the TDEA function.

The key and IV data are provided in byte arrays.

Parameters
[in]lpKeycontaining the key in hexadecimal representation.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]lpIVcontaining the initialization vector in hexadecimal. Set as zero (0) for ECB mode.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions TDEA_Update, TDEA_UpdateHex or TDEA_Final. Returns zero if an error occurs.
Remarks
The key lpKey must be exactly 24 bytes long and the IV, if required, exactly 8 bytes long. Unlike most other functions in this API, TDEA_Init returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling a TDEA function.

◆ TDEA_InitError()

long TDEA_InitError ( void  )

Returns the error code after an unsuccessful call to TDEA_Init or TDEA_InitHex.

Returns
Returns the error code from the last call to TDEA_Init or TDEA_InitHex.

◆ TDEA_InitHex()

long TDEA_InitHex ( const char *  szKey,
int  fEncrypt,
const char *  szMode,
const char *  szIV 
)

Initialises the context with the key, direction and mode ready for repeated operations of the TDEA function.

The key and IV data are provided in hexadecimal format.

Parameters
[in]szKeycontaining the key in hexadecimal representation.
[in]fEncryptdirection flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
[in]szModespecifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
[in]szIVcontaining the initialization vector in hexadecimal.
Returns
Non-zero handle of the context hContext to be used in subsequent calls to the functions TDEA_Update, TDEA_UpdateHex or TDEA_Final. Returns zero if an error occurs.
Remarks
The key string szHexKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes/192 bits). The initialization vector szHexIV must be exactly 16 hex characters long (i.e. representing exactly the block size of 8 bytes), except for ECB mode, where it is ignored (use ""). Valid hexadecimal characters are [0-9A-Fa-f]. Unlike most other functions in this API, TDEA_InitHex returns zero if an error occurs. It is important to check that the value of hContext returned is not equal to zero before calling a TDEA function.

◆ TDEA_Update()

long TDEA_Update ( long  hContext,
unsigned char *  lpData,
long  nDataLen 
)

Carries out the TDEA transformation function on a byte array according to the direction and mode set up by an earlier call to TDEA_Init() or TDEA_InitHex().

Parameters
[in]hContexthandle to the TDEA context set up by an earlier call to TDEA_Init() or TDEA_InitHex().
[in,out]lpDataarray containing the input data.
[in]nDataLenequal to length of the input data in bytes.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. Note that the output overwrites the input.

◆ TDEA_UpdateHex()

long TDEA_UpdateHex ( long  hContext,
char *  szHexData 
)

Carries out the TDEA transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to TDEA_Init() or TDEA_InitHex().

Parameters
[in]hContexthandle to the TDEA context set up by an earlier call to TDEA_Init() or TDEA_InitHex().
[in,out]szHexDatacontaining input in hexadecimal format to be processed by the TDEA function and to receive the output.
Returns
If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
szHexString must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.

◆ WIPE_Data()

long WIPE_Data ( void *  lpData,
long  nDataLen 
)

Zeroises data in memory.

Parameters
[in,out]lpDataByte array to be cleared.
[in]nDataLenspecifying the number of bytes to be cleared.
Returns
If successful, the return value is zero; otherwise it returns an error code.
Remarks
This function does not free any memory; it just zeroises it.

◆ WIPE_File()

long WIPE_File ( const char *  szFileName,
long  nOptions 
)

Securely wipes and deletes a file using 7-pass DOD standards.

Parameters
[in]szFileNamespecifying the file to be deleted.
[in]nOptionsOption flags. Select one of:
API_WIPEFILE_DOD7 (0) to use DOD 7-pass (default)
API_WIPEFILE_SIMPLE to overwrite with single pass of zero bytes (quicker but less secure) [New in v5.3].
Returns
If successful, the return value is zero; otherwise it returns a nonzero error code.
Remarks
Wipes a file using the 7-pass DOD Standard according to [NISPOM] before deleting.

◆ XOF_Bytes()

long XOF_Bytes ( unsigned char *  lpOutput,
long  nOutBytes,
const void *  lpMessage,
long  nMsgLen,
long  nOptions 
)

Generate bytes using an eXtendable Output Function (XOF).

Parameters
[out]lpOutputbyte buffer to receive the output.
[in]nOutBytessize of output buffer in bytes.
[in]lpMessagebyte array containing the input data.
[in]nMsgLenlength of the input data in bytes.
[in]nOptionsOption flags. Select one of:
API_XOF_SHAKE128 to use SHAKE128
API_XOF_SHAKE256 to use SHAKE256
API_XOF_MGF1_SHA1 to use MGF1-SHA-1
API_XOF_MGF1_SHA256 to use MGF1-SHA-256
API_XOF_MGF1_SHA512 to use MGF1-SHA-512
API_XOF_ASCON_XOF to use ASCON-XOF
API_XOF_ASCON_XOFA to use ASCON-XOFA
Returns
If successful, the return value is the number of bytes in the output; otherwise it returns a negative error code.
Remarks
The output buffer lpOutput must exist. It will be filled with exactly nOutBytes bytes. Note there is no zero option for nOptions: a valid option flag must be specified.

SHAKE128 and SHAKE256 are described in the SHA-3 Standard [FIPS202]. MGF1, despite its name as a Mask Generation Function (MGF), is also an eXtendable Output Function (XOF) using the SHA1/SHA-2 hash functions, and is described in [PKCS1]. The extendable output functions Ascon-Xof and Ascon-Xofa are from the cipher suite ASCON and are provisional subject to final approval by NIST.

◆ ZLIB_Deflate()

long ZLIB_Deflate ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpInput,
long  nBytes 
)

Compresses data using the ZLIB deflate algorithm.

Parameters
[out]lpOutputabyte buffer to receive output data.
[in]nOutBytessize of the output buffer in bytes.
[in]lpInputinput data to be compressed.
[in]nByteslength of input array in bytes.
Returns
The number of bytes successfully copied into the output buffer or the required size in bytes. If an error occurs, it returns a negative error code.
Remarks
To determine the required size of the output buffer, call the function with nOutBytes set to zero (or lpOutput set to NULL).

◆ ZLIB_Inflate()

long ZLIB_Inflate ( unsigned char *  lpOutput,
long  nOutBytes,
const unsigned char *  lpInput,
long  nBytes 
)

Inflates compressed data using the ZLIB uncompress algorithm.

Parameters
[out]lpOutputbyte buffer to receive output data.
[in]nOutBytessize of the output buffer in bytes.
[in]lpInputinput data to be uncompressed.
[in]nByteslength of input array in bytes.
Returns
The number of bytes successfully copied into the output buffer or the required size in bytes. If an error occurs, it returns a negative error code.
Remarks
[New in v5.3] This function will now compute the required output length for the output buffer. In earlier versions you needed to know the size by other means.

To determine the required size of the output buffer, call the function with nOutBytes set to zero (or lpOutput set to NULL).

Copyright © 2001-24 D.I. Management Services Pty Limited ABN 78 083 210 584 Australia. All rights reserved. <www.di-mgt.com.au> <www.cryptosys.net>. Generated on Sat Jan 6 2024 18:00:05 by Doxygen 1.9.1.