• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Build and Installation Guide
2
3## 1. Preparing the Build Environment
4
5Check whether the build tools have been installed in the system and can be used properly.
6
7| **Name**| **Recommended Version**| **Description**|
8| -------- | ------------ | -------- |
9| Gcc        | ≥ 7.3.0      | Linux    |
10| Python   | ≥ 3.5         | Linux    |
11| CMake    | ≥ 3.16        | Linux    |
12| Sctp        | No restriction on versions   | Linux    |
13
14## 2. Preparing the Source Code
15
16Method 1
17
181. Download the openHiTLS code, including the service code, build script, and test code.
19
20   Repository address: https://gitcode.com/openhitls/openhitls.git
212. openHiTLS depends on the libboundscheck library. Before building openHiTLS, download the library to **openHiTLS/platform/Secure\_C**.
22
23   Repository address: https://gitee.com/openeuler/libboundscheck.git
24
25Method 2
26
27Run the **git submodule** command to download the source code and dependent SecureC library:
28
29```
30git clone --recurse-submodules https://gitcode.com/openhitls/openhitls.git
31```
32
33## 3. Building and Installing openHiTLS
34
35The openHiTLS code directory structure is as follows:
36
37```
38└── openHiTLS
39   ├── bsl
40   ├── CMakeLists.txt
41   ├── config
42   ├── configure.py
43   ├── crypto
44   ├── docs
45   ├── include
46   ├── LICENSE
47   ├── platform
48   ├── README-en.md
49   ├── README.md
50   ├── script
51   ├── testcode
52   ├── tls
53   └── pki
54   └── auth
55```
56Where:
57
58- configure.py: provides the command line function for build configuration
59- config and script: stores build-related scripts
60- bsl: stores the code related to basic functions
61- crypto: stores the code related to cryptographic algorithm capabilities.
62- tls: stores the code related to secure transmission
63- platform: stores other dependent codes
64- testcode: stores the test project code
65- pki: stores the PKI related code
66- auth: stores the auth related code
67
68**Call CMake to build the source code. The detailed method is as follows:**
69
70### 3.1 CMake Build
71
72openHiTLS provides the CMake build mode, which can be configured using **configure.py**. You are advised to create a **build** directory to store temporary files generated during the build process, and then go to the **build** directory and run "cmake .. &&make" to build openHiTLS. You can run the `python3 ./configure.py –help` command to query the configuration of **configure.py**. The related parameters are as follows.
73
74| **Script Parameter**| **Parameter Description**| **Execution Mode**|
75| ------------- | ------------ | ---------------- |
76|--help           |Displays the help information about the script.|python3 configure.py --help|
77|-m                |Generates a **moudules.cmake** file.|python3 configure.py -m|
78|--build_dir    |Specifies the temporary directory for compilation.|python3 configure.py --build_dir build|
79|--output_dir |Specifies the output path of the compilation target.|python3 configure.py --output_dir output|
80|--feature_config|Specifies the compilation feature configuration file.|python3 configure.py --feature_config path/to/xxx.json|
81|--compile_config|Specifies the compilation parameter configuration file.|python3 configure.py --compile_config path/to/xxx.json|
82|--enable|Specifies build features.<br>Please refer to [Feature Description](./4_Configuration%20guide.md#1-Feature%20Description) to get supported features|python3 configure.py --enable hitls_crypto hitls_tls hitls_pse|
83|--disable|disable buld features|python3 configure.py --disable sal_thread |
84|--asm_type|Indicates the assembly type.|python3 configure.py --lib_type  static --asm_type armv8|
85|--asm|Specifes build asm features, whicht needs to be used simultaneously with parameter `asm_type`.|python3 configure.py --lib_type  static --asm_type armv8 --asm sha2|
86|--endian|Indicates big-endian or little-endian build.|python3 configure.py --endian little|
87|--system|Specified the system type, currently only supports `linux`, used for 'sal_xxx' related features|python3 configure.py --system linux|
88|--bits|To enable feature "bn", should specify the number of OS bits, `32\|64`|python3 configure.py --bits 64|
89|--lib_type|Builds a static library, a dynamic library, or an object.|python3 configure.py --lib_type  static|
90|--add_options|Adds compilation options.|python3 configure.py --add_options "-O0 -g3"|
91|--del_options|Removes compilation options.|python3 configure.py --del_options"-O2"|
92|--add_link_flags|Adds link options.|python3 configure.py --add_link_flags="-pie"|
93|--del_link_flags|Removes link options.|python3 configure.py --del_options="-O2 -Werror"|
94
95The **configure.py** script modifies the existing configuration based on the **compile.json** and **feature.json** configuration files at the top layer.
96
97The overall CMake build procedure is as follows:
98
99```bash
100cd openHiTLS
101mkdir -p ./build
102cd ./build
103python3 ../configure.py # Modify the configuration. For details, see section 3.1.1.
104cmake ..
105make -j
106```
107
108The build result is stored in the **openHiTLS/build** directory.
109
110#### 3.1.1 Common Configuration Commands
111
112```bash
113# Disable a feature.
114python3 ../configure.py --disable [feature]::[module]
115
116# Enable a feature.
117python3 ../configure.py --enable [feature]::[module]
118
119# Default configuration file. If the file does not exist, a file is generated. Otherwise, no action is performed.
120python3 ../configure.py -m
121
122# Add or delete compilation options.
123# Note: If a compilation option already exists and you want to update it, you must run **--del_options** and **--add_options** in sequence. In this example, O0 needs to be changed to O2.
124python3 ../configure.py --del_options="-O2 -D_FORTIFY_SOURCE=2" --add_options="-O0 -g"
125
126# Add or delete link options.
127python3 ../configure.py --add_link_flags="-lxxx" --del_link_flags="-lxxx"
128
129# Generate static libraries only.
130python3 ../configure.py --lib_type static
131
132# Generate dynamic libraries only.
133python3 ../configure.py --lib_type shared
134
135# Generate object files only.
136python3 ../configure.py --lib_type object
137
138# Generate dynamic libraries, static libraries, and object files.
139python3 ../configure.py --lib_type shared static object
140```
141
142#### 3.1.2 Cross Compilation
143
144To cross compile openHiTLS, you need to use the **-DCMAKE_TOOLCHAIN_FILE** parameter of CMake to transfer the cross compilation configuration, as follows:
145
146```bash
147cd openHiTLS
148mkdir -p ./build
149cd ./build
150python3 ../configure.py --bits=64 --system=linux # Modify the configuration. For details, see section 3.1.1.
151cmake -DCMAKE_TOOLCHAIN_FILE=usr_gcc.toolchain.cmake .. # xxx.toolchain.cmake needs to be written by the user.
152make -j
153```
154
155### 3.2 Installing the Build Result
156
157To install the build result of openHiTLS, you only need to enter the following command:
158
159```bash
160make install
161```
162
163By default, header files are installed in **/usr/local/include**, and library files are installed in **/usr/local/lib**. If you need to customize the installation path, run the following command in the CMake configuration phase:
164
165```bash
166cmake -DCMAKE_INSTALL_PREFIX=<customized path> ..
167```
168