# Demo Programs for the GNU\* Multiple Precision Arithmetic Library\* for Intel® Software Guard Extensions
These two programs demonstrate how to use the Intel SGX build of the GMP library. For more information about this project, see the accompanying article "[Building the GNU\* Multiple Precision\* Arithmetic Library for Intel® Software Guard Extensions](https://software.intel.com/en-us/articles/building-the-gnu-multiple-precision-library-for-intel-software-guard-extensions)".
## Prerequisites
To build and run these demo applications, you'll need the following:
* The [GNU Multiple Precision Arithmetic Library for Intel Software Guard Extensions](https://github.com/intel/sgx-gmp)
* both the Intel SGX and "stock" builds of this library are required
* both builds can be produced from the above
* The [Intel SGX SDK](https://github.com/intel/linux-sgx)
* Intel SGX capable hardware
These applications have been tested on:
* Ubuntu\* Linux\* 16.04, 18.04
* CentOS\* Linux 7.4
## Building
Configure the distribution by running the `configure` script. You'll need to specify the location of the standard and Intel SGX builds of GMP:
```
--with-gmpdir=PATH specify the libgmp directory
--with-trusted-gmpdir=PATH the trusted libgmp directory (default: gmp directory)
```
If both builds of the library are installed to the same directory, you can just specify `--with-gmpdir=PATH`.
To compile the applications, run `make`.
## Running the Demo Programs
### sgxgmpmath
This program takes two numbers on the command line, and then calls into the enclave to perform addition, multiplication, integer division, and floating point division. Each of these results is printed to stdout.
This program is a more advanced example of using the GMP library in an enclave, and it exercises several of GMP’s capabilities including factorials, exponentiation, n-roots, floating point division, and bits of precision. It makes an ECALL to calculate the value of pi to the specified number of digits using the [Chudnovsky algorithm](https://en.wikipedia.org/wiki/Chudnovsky_algorithm) and places the value in a GMP variable that is passed to the ECALL as a parameter.
Usage is:
<pre>
sgxgmppi <i>ndigits</i>
</pre>
Note that the implementation of Chudnovsky’s algorithm in this demo application emphasizes clarity over performance.
Sample output:
```
$ ./sgxgmppi 1000
Enclave launched
libtgmp initialized
pi : 3.141592653589793238462643383279502884197169399375105820974944592307816