> For the complete documentation index, see [llms.txt](https://sandbox-docs.verifone.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandbox-docs.verifone.com/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8cpp.md).

# crypt.cpp

[Data Structures](#nested-classes) | [Macros](#define-members) | [Functions](#func-members)

`#include <stdio.h>` `#include "`[crypt.h](/s-adk-5.1-programmers-guide/crypt_8h_source.md)`"` `#include "`[sec/libsec.h](/s-adk-5.1-programmers-guide/libsec_8h_source.md)`"` `#include "`[sys.h](/s-adk-5.1-programmers-guide/sys_8h_source.md)`"` `#include "`[\_logf.h](/s-adk-5.1-programmers-guide/__logf_8h_source.md)`"` `#include <vector>` `#include <string>` `#include "`[ipc/jsobject.h](/s-adk-5.1-programmers-guide/ipc_2src_2ipc_2jsobject_8h_source.md)`"` `#include "`[sysinfo/sysinfo.h](/s-adk-5.1-programmers-guide/sysinfo_8h_source.md)`"` `#include "`[md5.h](/s-adk-5.1-programmers-guide/md5_8h_source.md)`"` `#include "`[pthreadutil.h](/s-adk-5.1-programmers-guide/pthreadutil_8h_source.md)`"`

Include dependency graph for crypt.cpp:

![](/files/U1Q0MIkz1qb61PClalV1)

|                 |                                                                            |
| --------------- | -------------------------------------------------------------------------- |
| Data Structures |                                                                            |
| class           | [Auth](/s-adk-5.1-programmers-guide/readme/annotated/class_auth.md)        |
| class           | [AuthSec](/s-adk-5.1-programmers-guide/readme/annotated/class_auth_sec.md) |

|         |                                                     |
| ------- | --------------------------------------------------- |
| Macros  |                                                     |
| #define | [FALL\_THROUGH](#a38dadd06badcc5b7cca444a551604399) |

|           |                                                                                                                                                                                                                                                                                                                                          |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Functions |                                                                                                                                                                                                                                                                                                                                          |
| int       | [check\_AuthScript](#aa132af50976d028410ad9789f5ec5aab) ()                                                                                                                                                                                                                                                                               |
| int       | [system\_Auth](#a853e613db30d5f21771dd5b5ba76b989) (enum [AuthStep](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8h.md#ab97c53cf460f4280eb94c660cb5e357d) as, unsigned char \*in, unsigned short in\_size, unsigned char \*out, unsigned short \*out\_size) |
| int       | [calculate\_CMAC](#affad0aaba09298a627562b262e523d93) ([Inputype](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8h.md#adcc10b90a6f6d8e58954648e01763711) type, const char \*fileToMAC, unsigned char \*dataToMAC, unsigned dataSize, unsigned char \*MAC)    |
| int       | [check\_CMAC](#a3242ff53cdc315266c6a352f86359c70) ([Inputype](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8h.md#adcc10b90a6f6d8e58954648e01763711) type, const char \*filename, unsigned char \*data, unsigned dataSize, unsigned char \*MAC)              |
| int       | [encrypt\_Data](#a7e77c714fd81df4137cfc32dc7af3584) (unsigned char \*data, unsigned long dataSize, unsigned char \*encryptedData, unsigned long \*encryptedDataSize)                                                                                                                                                                     |
| int       | [decrypt\_Data](#ab52056b7a75e86920c5b03cf2d3730ad) (unsigned char \*data, unsigned long dataSize, unsigned char \*decryptedData, unsigned long \*decryptedDataSize)                                                                                                                                                                     |
| int       | [calculate\_MD5](#a9d396bd846d00eab3b94e9c2763236cc) (const char \*file, unsigned char \*checkSum)                                                                                                                                                                                                                                       |

### MacroDefinition Documentation <a href="#macro-definition-documentation" id="macro-definition-documentation"></a>

### FALL\_THROUGH <a href="#a38dadd06badcc5b7cca444a551604399" id="a38dadd06badcc5b7cca444a551604399"></a>

\#define FALL\_THROUGH

### FunctionDocumentation <a href="#function-documentation" id="function-documentation"></a>

### calculate\_CMAC() <a href="#affad0aaba09298a627562b262e523d93" id="affad0aaba09298a627562b262e523d93"></a>

int calculate\_CMAC

Calculate the CMAC value for the given data

**Parameters**

\[in] **type** input type. can be a file or a data buffer \[in] **fileToMAC** file name (when input type is INPUT\_TYPE\_FILE) \[in] **dataToMAC** pointer to input message buffer (when input type is INPUT\_TYPE\_BUFFER) \[in] **dataSize** size of the input message (when input type is INPUT\_TYPE\_BUFFER) \[in,out] **MAC** pointer to the MAC value buffer

#### Returns

RESULT\_OK on success otherwise RESULT\_FAIL

### calculate\_MD5() <a href="#a9d396bd846d00eab3b94e9c2763236cc" id="a9d396bd846d00eab3b94e9c2763236cc"></a>

int calculate\_MD5

Compute and MD5 digest of file `file`

**Parameters**

\[in] **file** file of which MD5 checksum shall be calculated \[out] **checkSum** output buffer for calculated MD5 checksum, buffer must have at least 16 bytes

#### Returns

1 for success, else 0 for error (e.g. file does not exist)

### check\_AuthScript() <a href="#aa132af50976d028410ad9789f5ec5aab" id="aa132af50976d028410ad9789f5ec5aab"></a>

int check\_AuthScript

checks the status of VSS script used for SDI message integrity check (message MAC) and SDI message encryption

#### Returns

RESULT\_OK for success, else RESULT\_FAIL for failure

### check\_CMAC() <a href="#a3242ff53cdc315266c6a352f86359c70" id="a3242ff53cdc315266c6a352f86359c70"></a>

int check\_CMAC

Check the CMAC value of the given data

**Parameters**

\[in] **type** input type. can be a file or a data buffer \[in] **filename** file name (when input type is INPUT\_TYPE\_FILE) \[in] **data** pointer to input message buffer (when input type is INPUT\_TYPE\_BUFFER) \[in] **dataSize** size of the input message (when input type is INPUT\_TYPE\_BUFFER) \[in] **MAC** pointer to the MAC value buffer

#### Returns

RESULT\_OK on success otherwise RESULT\_FAIL

### decrypt\_Data() <a href="#ab52056b7a75e86920c5b03cf2d3730ad" id="ab52056b7a75e86920c5b03cf2d3730ad"></a>

int decrypt\_Data

Decrypt the given data

**Parameters**

\[in] **data** pointer to input message buffer \[in] **dataSize** size of the input message \[in,out] **decryptedData** pointer to decrypted data buffer \[in,out] **decryptedDataSize** pointer to decrypted data buffer size

#### Returns

RESULT\_OK on success otherwise RESULT\_FAIL

### encrypt\_Data() <a href="#a7e77c714fd81df4137cfc32dc7af3584" id="a7e77c714fd81df4137cfc32dc7af3584"></a>

int encrypt\_Data

Encrypt the given data

**Parameters**

\[in] **data** pointer to input message buffer \[in] **dataSize** size of the input message \[in,out] **encryptedData** pointer to encrypted data buffer \[in,out] **encryptedDataSize** pointer to encrypted data buffer size

#### Returns

RESULT\_OK on success otherwise RESULT\_FAIL

### system\_Auth() <a href="#a853e613db30d5f21771dd5b5ba76b989" id="a853e613db30d5f21771dd5b5ba76b989"></a>

int system\_Auth

Process System Authentication step 1 or 2. With success of step 2, the SDI client (Server) is successfully authenticated against SDI server (E105). In addition, the session key (SK) was stored to vault successfully. This is the prerequisite that other functions [calculate\_CMAC()](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8h.md#affad0aaba09298a627562b262e523d93), [check\_CMAC()](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8h.md#a3242ff53cdc315266c6a352f86359c70), [encrypt\_Data()](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8h.md#a7e77c714fd81df4137cfc32dc7af3584) and [decrypt\_Data()](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8h.md#ab52056b7a75e86920c5b03cf2d3730ad) will work, since these functions use the session key (SK).

**Parameters**

\[in] **as** For System Authentication Step 1: AuthStep\_1 For System Authentication Step 2: AuthStep\_2 Input and output data of this function depend on this parameter (see below). \[in] **in** pointer to input data buffer For AuthStep\_1 (16 bytes): 16 bytes (Server random, plain) For AuthStep\_2 (32 bytes): \[16 bytes (E105 token) + 16 bytes (Server token)] SK encrypted \[in] **in\_size** size of input buffer (depend on auth. step, see parameter in) \[out] **out** pointer to output buffer For AuthStep\_1 (42 bytes): \[16 bytes (E105 token) + 16 bytes (E105 token)] DUKPT encrypted + 10 bytes (KSN) For AuthStep\_2 (32 bytes): \[16 bytes (Server token) + 16 bytes (E105 serial number)] SK encrypted \[in,out] **out\_size** in: size of output buffer out: size of output buffer data (depend on auth. step, see parameter out)

#### Returns

RESULT\_OK for success, else RESULT\_FAIL for failure


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sandbox-docs.verifone.com/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/crypt_8cpp.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
