# Understanding-the-code

## Overview

In this page we are going to explain/describe the coherence's code, this code is built with the help of:

* [argon2](https://github.com/P-H-C/phc-winner-argon2)
* [cryptopp](https://github.com/P-H-C/phc-winner-argon2)
* [libntru](https://github.com/tbuktu/libntru)
* [liboqs](https://github.com/open-quantum-safe/liboqs/)
* [libuv](https://github.com/libuv/libuv)
* [rapidjson](https://github.com/Tencent/rapidjson)

## params.h

* It defines (with preprocessor) which algorithms are going to supported
* It defines info\_log structure to store the log data
* It defines params structure to help to parse json data and share it with the functions&#x20;

## coherence.c

In this file is main function. We create a tcp server with libuv, validate the input, create the logs output and send the client's input to be parsed.

* *main()* displays the banner, create the tcp server, starts the event loop and call *on\_new\_connection()*
* *on\_new\_connection()* accepts the clients, calls *alloc\_buffer()* and *on\_read()*
* *alloc\_buffer()* creates the buffer to store client's input
* *on\_read()* reads data from socket, starts t
  * *if (nread < 0)* an error on  reading socket data
  * *if (nread >= 0)* data is read, creates log info, validate the buffer with *ok\_buff()*,if the buffer isn't ok close the connection, if the buffer is ok sends the input to *PARSING()* , writes the answer, *parse\_log* cleans the log structure and prints the log.

### Further reading

* [libuv - uv\_stream](http://docs.libuv.org/en/v1.x/stream.html)
* [libuv sample](https://github.com/trevnorris/libuv-examples)
* [libuv-dox-examples](https://github.com/thlorenz/libuv-dox/tree/master/examples)

## parsing.h

* *PARSING()* parse the json input with *Parsingjson()* ,and address the algorithm to its functions
* *parse\_log* parse the log, basically delete sensitive information like private keys with *Clear2json()*

### Further reading

* [rapidjson intro](http://rapidjson.org/md_doc_tutorial.html)

## parse-func.h

In this file we can find functions to validate inputs from json client input.

## crypt-argon2.h

Functions to process argon2 requests

### Further reading

* [example](https://github.com/P-H-C/phc-winner-argon2/blob/master/src/argon2.c)&#x20;

## crypt-block.h

Functions to process block cipher requests

### Further reading

* [example](https://www.cryptopp.com/wiki/Block_Cipher)
* [aes example](https://www.cryptopp.com/wiki/Advanced_encryption_standard)

## crypt-dh.h

Functions to process Diffie-Hellman requests

### Further reading

* [example](https://www.cryptopp.com/wiki/Diffie-Hellman)

## crypt-dsa.h

Functions to process DSA requests

### Further reading

* [example](https://www.cryptopp.com/wiki/Digital_Signature_Algorithm)

## crypt-ecc.h

Functions to process Elliptic Curves requests

### Further reading

* [example](https://www.cryptopp.com/wiki/Elliptic_Curve_Cryptography)

## crypt-hash.h

Functions to process HASh requests

### Further reading

* [example](https://www.cryptopp.com/wiki/Hash_Functions)

## crypt-mac.h

Functions to process MAC requests

### Further reading

* [hmac example](https://www.cryptopp.com/wiki/HMAC)
* \[cmac example] (<https://www.cryptopp.com/wiki/CMAC>)

## crypt-ntru.h

Functions to process NTRU requests

### Further reading

* [example](https://github.com/tbuktu/libntru)

## crypt-oqs.h

Functions to process Post Quantum Algorithms requests

### Further reading

* [example](https://github.com/open-quantum-safe/liboqs/blob/master/tests/example_sig.c)

## crypt-rand.h

Functions to process Rand numbers generation requests

### Further reading

* [example](https://www.cryptopp.com/wiki/RandomNumberGenerator)

## crypt-rsa.h

Functions to process RSA requests

### Further reading

* [example](https://www.cryptopp.com/wiki/RSA_Cryptography)

## crypt-stream.h

Functions to process Stream Ciphers requests

### Further reading

* [example](https://www.cryptopp.com/wiki/Stream_Cipher)


---

# Agent Instructions: 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:

```
GET https://coherence.3vidence.com/understanding-the-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
