|
1 | | -# lib/meson.build |
2 | | -# WolfSSL cryptographic library build configuration |
| 1 | +# wolfCrypt library build configuration |
| 2 | +# Extracted from main meson.build for modularity |
3 | 3 |
|
4 | | -# Get build options from parent |
| 4 | +# Get configuration from parent |
| 5 | +fs = import('fs') |
| 6 | +inc_dirs = include_directories('..') |
| 7 | +c_args = [] |
| 8 | + |
| 9 | +# Re-inherit key configuration values from parent |
5 | 10 | arch = get_option('arch') |
6 | | -target = get_option('target') |
7 | 11 | sign = get_option('sign') |
8 | | -hash = get_option('hash') |
9 | | -encrypt = get_option('encrypt') |
10 | | -debug = get_option('wolfboot_debug') |
| 12 | +hash_alg = get_option('hash') |
| 13 | +encrypt_enabled = get_option('encrypt') |
| 14 | +tpm_enabled = get_option('tpm') |
| 15 | + |
| 16 | +# Math selection flags (inherit from parent logic) |
| 17 | +if get_option('spmathall') |
| 18 | + c_args += ['-DWOLFSSL_SP_MATH_ALL'] |
| 19 | +elif get_option('spmath') |
| 20 | + if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm') |
| 21 | + c_args += ['-DWOLFSSL_SP_ASM', '-DWOLFSSL_SP_ARM_CORTEX_M_ASM'] |
| 22 | + endif |
| 23 | +else |
| 24 | + # Fastmath |
| 25 | + c_args += ['-DUSE_FAST_MATH'] |
| 26 | +endif |
11 | 27 |
|
12 | | -# Base WolfCrypt sources (matching arch.mk defaults) |
| 28 | +# Core wolfCrypt sources (always included) |
13 | 29 | wolfcrypt_sources = [ |
14 | 30 | 'wolfssl/wolfcrypt/src/sha256.c', |
15 | 31 | 'wolfssl/wolfcrypt/src/hash.c', |
16 | 32 | 'wolfssl/wolfcrypt/src/memory.c', |
17 | 33 | 'wolfssl/wolfcrypt/src/wc_port.c', |
18 | 34 | 'wolfssl/wolfcrypt/src/wolfmath.c', |
19 | | - 'wolfssl/wolfcrypt/src/asn.c', # From options.mk |
20 | | - 'wolfssl/wolfcrypt/src/logging.c', # Debug logging support from arch.mk |
| 35 | + 'wolfssl/wolfcrypt/src/asn.c', |
| 36 | + 'wolfssl/wolfcrypt/src/logging.c', |
21 | 37 | ] |
22 | 38 |
|
23 | | -# Math library sources |
24 | | -if get_option('spmath') |
| 39 | +# Math library selection (matches arch.mk logic) |
| 40 | +if get_option('spmathall') |
25 | 41 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_int.c'] |
26 | | - |
27 | | - # Add Cortex-M optimized SP math if building for ARM Cortex-M and assembly is enabled |
28 | | - # Only include when actually cross-compiling for ARM (not on native x86_64) |
29 | | - if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm') and meson.is_cross_build() |
30 | | - cortex_m_targets = ( |
31 | | - get_option('cortex_m0') |
32 | | - or get_option('cortex_m3') |
33 | | - or get_option('cortex_m33') |
34 | | - or get_option('cortex_m7') |
35 | | - ) |
36 | | - if cortex_m_targets |
37 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_cortexm.c'] |
38 | | - # Add corresponding compiler flags - these will be handled by parent |
39 | | - # wolfcrypt_c_args += ['-DWOLFSSL_SP_ASM', '-DWOLFSSL_SP_ARM_CORTEX_M_ASM'] |
40 | | - # if get_option('cortex_m7') |
41 | | - # wolfcrypt_c_args += ['-DWOLFSSL_ARM_ARCH=7'] |
42 | | - # elif get_option('cortex_m3') |
43 | | - # wolfcrypt_c_args += ['-DWOLFSSL_SP_NO_UMAAL', '-DWOLFSSL_ARM_ARCH=7'] |
44 | | - # endif |
45 | | - else |
46 | | - # Default to C implementation for other ARM targets |
47 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c'] |
48 | | - endif |
| 42 | + if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm') |
| 43 | + wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_cortexm.c'] |
49 | 44 | else |
50 | | - # Use C implementation when assembly is disabled or not cross-compiling |
51 | | - if arch == 'ARM' or arch == 'AARCH64' |
52 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c'] |
53 | | - elif arch == 'x86_64' |
54 | | - # x86_64 specific SP math handling |
55 | | - if get_option('no_asm') |
56 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c64.c'] |
57 | | - else |
58 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_x86_64.c'] |
59 | | - endif |
60 | | - else |
61 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c64.c'] |
62 | | - endif |
| 45 | + wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c'] |
| 46 | + endif |
| 47 | +elif get_option('spmath') |
| 48 | + # SP Math |
| 49 | + wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_int.c'] |
| 50 | + if arch == 'ARM' and not get_option('no_asm') and not get_option('no_arm_asm') |
| 51 | + wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_cortexm.c'] |
| 52 | + else |
| 53 | + wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sp_c32.c'] |
63 | 54 | endif |
64 | 55 | else |
| 56 | + # Fastmath |
65 | 57 | wolfcrypt_sources += [ |
66 | 58 | 'wolfssl/wolfcrypt/src/integer.c', |
67 | 59 | 'wolfssl/wolfcrypt/src/tfm.c', |
68 | 60 | ] |
69 | 61 | endif |
70 | 62 |
|
71 | | -# Signature algorithm specific sources (matching options.mk) |
72 | | -if sign == 'ECC256' or sign == 'ECC384' or sign == 'ECC521' |
| 63 | +# Signature algorithm sources |
| 64 | +if sign in ['ECC256', 'ECC384', 'ECC521'] |
| 65 | + # Elliptic Curve Cryptography |
73 | 66 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/ecc.c'] |
74 | 67 | elif sign == 'ED25519' |
| 68 | + # Edwards-curve Digital Signature Algorithm (25519) |
75 | 69 | wolfcrypt_sources += [ |
| 70 | + 'wolfssl/wolfcrypt/src/sha512.c', |
76 | 71 | 'wolfssl/wolfcrypt/src/ed25519.c', |
77 | 72 | 'wolfssl/wolfcrypt/src/ge_low_mem.c', |
78 | 73 | 'wolfssl/wolfcrypt/src/fe_low_mem.c', |
79 | | - 'wolfssl/wolfcrypt/src/sha512.c', |
80 | 74 | ] |
81 | 75 | elif sign == 'ED448' |
| 76 | + # Edwards-curve Digital Signature Algorithm (448) |
82 | 77 | wolfcrypt_sources += [ |
83 | 78 | 'wolfssl/wolfcrypt/src/ed448.c', |
84 | 79 | 'wolfssl/wolfcrypt/src/ge_low_mem.c', |
85 | 80 | 'wolfssl/wolfcrypt/src/ge_448.c', |
86 | 81 | 'wolfssl/wolfcrypt/src/fe_448.c', |
87 | 82 | 'wolfssl/wolfcrypt/src/fe_low_mem.c', |
88 | 83 | ] |
89 | | - # ED448 adds SHA3 if HASH is not already SHA3 (from options.mk) |
90 | | - if hash != 'SHA3' |
| 84 | + if hash_alg != 'SHA3' |
91 | 85 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha3.c'] |
92 | 86 | endif |
93 | 87 | elif sign.startswith('RSA') |
| 88 | + # RSA signature algorithm |
94 | 89 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/rsa.c'] |
95 | 90 | elif sign == 'LMS' |
| 91 | + # Leighton-Micali Signatures |
96 | 92 | wolfcrypt_sources += [ |
97 | 93 | 'wolfssl/wolfcrypt/src/wc_lms.c', |
98 | 94 | 'wolfssl/wolfcrypt/src/wc_lms_impl.c', |
99 | 95 | ] |
100 | 96 | elif sign == 'XMSS' |
| 97 | + # eXtended Merkle Signature Scheme |
101 | 98 | wolfcrypt_sources += [ |
102 | 99 | 'wolfssl/wolfcrypt/src/wc_xmss.c', |
103 | 100 | 'wolfssl/wolfcrypt/src/wc_xmss_impl.c', |
104 | 101 | ] |
105 | 102 | elif sign == 'ML_DSA' |
106 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/dilithium.c'] |
107 | | - # ML_DSA adds SHA3 if HASH is not already SHA3 (from options.mk) |
108 | | - if hash != 'SHA3' |
| 103 | + # Module-Lattice-Based Digital Signature Algorithm (Dilithium) |
| 104 | + wolfcrypt_sources += [ |
| 105 | + 'wolfssl/wolfcrypt/src/dilithium.c', |
| 106 | + ] |
| 107 | + if hash_alg != 'SHA3' |
109 | 108 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha3.c'] |
110 | 109 | endif |
111 | 110 | endif |
112 | 111 |
|
113 | | -# Hash algorithm specific sources |
114 | | -if hash == 'SHA384' |
| 112 | +# Hash algorithm sources |
| 113 | +if hash_alg == 'SHA384' |
115 | 114 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha512.c'] |
116 | | -elif hash == 'SHA3' |
| 115 | +elif hash_alg == 'SHA3' |
117 | 116 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/sha3.c'] |
118 | 117 | endif |
119 | 118 |
|
120 | | -# Encryption sources |
121 | | -if encrypt |
122 | | - if get_option('encrypt_with_chacha') |
123 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/chacha.c'] |
124 | | - elif get_option('encrypt_with_aes128') or get_option('encrypt_with_aes256') |
| 119 | +# Encryption algorithm sources |
| 120 | +if encrypt_enabled |
| 121 | + if get_option('encrypt_with_aes128') or get_option('encrypt_with_aes256') |
| 122 | + # AES encryption (128-bit or 256-bit keys) |
125 | 123 | wolfcrypt_sources += ['wolfssl/wolfcrypt/src/aes.c'] |
| 124 | + else |
| 125 | + # ChaCha20 stream cipher (default for encryption) |
| 126 | + wolfcrypt_sources += ['wolfssl/wolfcrypt/src/chacha.c'] |
126 | 127 | endif |
127 | 128 | endif |
128 | 129 |
|
129 | | -# Disk lock coding helper |
130 | | -if get_option('disk_lock') |
131 | | - wolfcrypt_sources += ['wolfssl/wolfcrypt/src/coding.c'] |
132 | | -endif |
133 | | - |
134 | | -# TPM sources |
135 | | -tpm_enabled = ( |
136 | | - get_option('wolfboot_tpm_verify') |
137 | | - or get_option('measured_boot') |
138 | | - or get_option('wolfboot_tpm_keystore') |
139 | | - or get_option('wolfboot_tpm_seal') |
140 | | -) |
141 | | - |
142 | | -if tpm_enabled |
143 | | - # Add additional wolfSSL crypto sources needed for TPM to wolfcrypt |
144 | | - if fs.exists('wolfTPM') |
145 | | - wolfcrypt_sources += [ |
146 | | - 'wolfssl/wolfcrypt/src/aes.c', |
147 | | - 'wolfssl/wolfcrypt/src/hmac.c', |
148 | | - 'wolfssl/wolfcrypt/src/random.c', |
149 | | - ] |
150 | | - endif |
151 | | -endif |
152 | | - |
153 | | -# Get compiler args and include dirs from parent |
154 | | -wolfcrypt_c_args = c_args # Use parent's c_args |
155 | | -wolfcrypt_inc_dirs = inc_dirs # Use parent's inc_dirs |
156 | | - |
157 | | -# Add ARM Cortex-M assembly optimization flags (matching CMakeLists.txt behavior) |
158 | | -if arch == 'ARM' and meson.is_cross_build() |
159 | | - cortex_m_targets = ( |
160 | | - get_option('cortex_m0') |
161 | | - or get_option('cortex_m3') |
162 | | - or get_option('cortex_m33') |
163 | | - or get_option('cortex_m7') |
164 | | - ) |
165 | | - if cortex_m_targets and not get_option('no_asm') and not get_option('no_arm_asm') |
166 | | - wolfcrypt_c_args += ['-DWOLFSSL_SP_ASM', '-DWOLFSSL_SP_ARM_CORTEX_M_ASM'] |
167 | | - if get_option('cortex_m7') |
168 | | - wolfcrypt_c_args += ['-DWOLFSSL_ARM_ARCH=7'] |
169 | | - elif get_option('cortex_m3') |
170 | | - wolfcrypt_c_args += ['-DWOLFSSL_SP_NO_UMAAL', '-DWOLFSSL_ARM_ARCH=7'] |
171 | | - endif |
172 | | - endif |
173 | | -endif |
174 | | - |
175 | | -wolfcrypt_build_inc_dirs = [] |
176 | | - |
177 | | -# WolfSSL include directory |
178 | | -wolfssl_inc = include_directories('wolfssl') |
179 | | - |
180 | | -# Build WolfCrypt library (cryptographic functions) |
| 130 | +# Build the wolfCrypt static library |
181 | 131 | libwolfcrypt = static_library( |
182 | 132 | 'wolfcrypt', |
183 | 133 | wolfcrypt_sources, |
184 | | - include_directories: [wolfcrypt_inc_dirs, wolfcrypt_build_inc_dirs, wolfssl_inc], |
185 | | - c_args: wolfcrypt_c_args + ['-Wno-unused', '-Wno-array-bounds'], |
| 134 | + include_directories: inc_dirs, |
| 135 | + c_args: c_args + ['-Wno-unused'], |
186 | 136 | install: false, |
187 | 137 | ) |
188 | 138 |
|
189 | | -# WolfTPM library (if TPM support is enabled and not a subproject) |
| 139 | +# Optional WolfTPM library (compile from sources if present) |
190 | 140 | libwolftpm = [] |
191 | | -wolftpm_sources = [] |
192 | | -if tpm_enabled and fs.exists('wolfTPM') and not meson.is_subproject() |
193 | | - wolftpm_sources = [ |
194 | | - 'wolfTPM/src/tpm2.c', |
195 | | - 'wolfTPM/src/tpm2_packet.c', |
196 | | - 'wolfTPM/src/tpm2_tis.c', |
197 | | - 'wolfTPM/src/tpm2_wrap.c', |
198 | | - 'wolfTPM/src/tpm2_param_enc.c', |
199 | | - ] |
200 | | - |
201 | | - wolftpm_inc = include_directories('wolfTPM') |
202 | | - |
| 141 | +if tpm_enabled and fs.exists('wolfTPM') |
| 142 | + inc_dirs_tpm = [inc_dirs, include_directories('wolfTPM')] |
203 | 143 | libwolftpm = static_library( |
204 | 144 | 'wolftpm', |
205 | | - wolftpm_sources, |
206 | | - include_directories: [wolfcrypt_inc_dirs, wolfcrypt_build_inc_dirs, wolfssl_inc, wolftpm_inc], |
207 | | - c_args: wolfcrypt_c_args, |
| 145 | + [ |
| 146 | + 'wolfTPM/src/tpm2.c', |
| 147 | + 'wolfTPM/src/tpm2_packet.c', |
| 148 | + 'wolfTPM/src/tpm2_tis.c', |
| 149 | + 'wolfTPM/src/tpm2_wrap.c', |
| 150 | + 'wolfTPM/src/tpm2_param_enc.c', |
| 151 | + ], |
| 152 | + include_directories: inc_dirs_tpm, |
| 153 | + c_args: c_args, |
208 | 154 | install: false, |
209 | 155 | ) |
210 | 156 | endif |
| 157 | + |
| 158 | +# Export dependency for parent build system |
| 159 | +wolfcrypt_dep = declare_dependency( |
| 160 | + include_directories: inc_dirs, |
| 161 | + link_with: [libwolfcrypt], |
| 162 | + compile_args: c_args, |
| 163 | +) |
| 164 | + |
| 165 | +# Export wolfTPM library variable for parent to access |
| 166 | +# Note: Set a variable that can be checked by parent |
| 167 | +wolfcrypt_has_tpm = libwolftpm != [] |
0 commit comments