@@ -124,7 +124,11 @@ fn generate_fips_aliases() -> Result<()> {
124124 if non_fips_re. is_match ( & binding) {
125125 // Add any new known names defined with both a _fips suffix and not
126126 // here. Warn if any new ones are discovered.
127- if base_name != "wc_AesGcmEncrypt" {
127+ let known_both = & [
128+ "wc_AesGcmEncrypt" ,
129+ "wc_AesCcmEncrypt" ,
130+ ] ;
131+ if !known_both. contains ( & base_name) {
128132 println ! ( "cargo:warning=Skipping FIPS symbols alias for {}" , base_name) ;
129133 }
130134 } else {
@@ -166,18 +170,21 @@ fn read_file(path: String) -> Result<String> {
166170 Ok ( content)
167171}
168172
169- fn check_cfg ( binding : & str , function_name : & str , cfg_name : & str ) {
173+ fn check_cfg ( binding : & str , function_name : & str , cfg_name : & str ) -> bool {
170174 let pattern = format ! ( r"\b{}(_fips)?\b" , function_name) ;
171175 let re = match Regex :: new ( & pattern) {
172176 Ok ( r) => r,
173177 Err ( e) => {
174178 eprintln ! ( "Error compiling regex '{}': {}" , pattern, e) ;
175- return ;
179+ std :: process :: exit ( 1 ) ;
176180 }
177181 } ;
178182 println ! ( "cargo::rustc-check-cfg=cfg({})" , cfg_name) ;
179183 if re. is_match ( binding) {
180184 println ! ( "cargo:rustc-cfg={}" , cfg_name) ;
185+ true
186+ } else {
187+ false
181188 }
182189}
183190
@@ -199,6 +206,7 @@ fn scan_cfg() -> Result<()> {
199206 check_cfg ( & binding, "wc_AesOfbEncrypt" , "aes_ofb" ) ;
200207 check_cfg ( & binding, "wc_AesXtsInit" , "aes_xts" ) ;
201208 check_cfg ( & binding, "wc_AesXtsEncryptInit" , "aes_xts_stream" ) ;
209+ check_cfg ( & binding, "WC_AES_BLOCK_SIZE" , "aes_wc_block_size" ) ;
202210
203211 /* blake2 */
204212 check_cfg ( & binding, "wc_InitBlake2b" , "blake2b" ) ;
@@ -234,10 +242,19 @@ fn scan_cfg() -> Result<()> {
234242 check_cfg ( & binding, "wc_ecc_verify_hash" , "ecc_verify" ) ;
235243 check_cfg ( & binding, "wc_ecc_export_x963" , "ecc_export" ) ;
236244 check_cfg ( & binding, "wc_ecc_import_x963" , "ecc_import" ) ;
237- check_cfg ( & binding, "ecc_curve_ids_ECC_X25519" , "ecc_curve_25519" ) ;
238- check_cfg ( & binding, "ecc_curve_ids_ECC_X448" , "ecc_curve_448" ) ;
239- check_cfg ( & binding, "ecc_curve_ids_ECC_SAKKE_1" , "ecc_curve_sakke" ) ;
240- check_cfg ( & binding, "ecc_curve_ids_ECC_CURVE_CUSTOM" , "ecc_custom_curves" ) ;
245+ if check_cfg ( & binding, "ecc_curve_ids_ECC_CURVE_INVALID" , "ecc_curve_ids" ) {
246+ check_cfg ( & binding, "ecc_curve_ids_ECC_SM2P256V1" , "ecc_curve_sm2p256v1" ) ;
247+ check_cfg ( & binding, "ecc_curve_ids_ECC_X25519" , "ecc_curve_25519" ) ;
248+ check_cfg ( & binding, "ecc_curve_ids_ECC_X448" , "ecc_curve_448" ) ;
249+ check_cfg ( & binding, "ecc_curve_ids_ECC_SAKKE_1" , "ecc_curve_sakke" ) ;
250+ check_cfg ( & binding, "ecc_curve_ids_ECC_CURVE_CUSTOM" , "ecc_custom_curves" ) ;
251+ } else {
252+ check_cfg ( & binding, "ecc_curve_id_ECC_SM2P256V1" , "ecc_curve_sm2p256v1" ) ;
253+ check_cfg ( & binding, "ecc_curve_id_ECC_X25519" , "ecc_curve_25519" ) ;
254+ check_cfg ( & binding, "ecc_curve_id_ECC_X448" , "ecc_curve_448" ) ;
255+ check_cfg ( & binding, "ecc_curve_id_ECC_SAKKE_1" , "ecc_curve_sakke" ) ;
256+ check_cfg ( & binding, "ecc_curve_id_ECC_CURVE_CUSTOM" , "ecc_custom_curves" ) ;
257+ }
241258
242259 /* ed25519 */
243260 check_cfg ( & binding, "wc_ed25519_init" , "ed25519" ) ;
@@ -263,6 +280,7 @@ fn scan_cfg() -> Result<()> {
263280
264281 /* hmac */
265282 check_cfg ( & binding, "wc_HmacSetKey" , "hmac" ) ;
283+ check_cfg ( & binding, "wc_HmacSetKey_ex" , "hmac_setkey_ex" ) ;
266284
267285 /* kdf */
268286 check_cfg ( & binding, "wc_PBKDF2" , "kdf_pbkdf2" ) ;
@@ -283,6 +301,15 @@ fn scan_cfg() -> Result<()> {
283301 check_cfg ( & binding, "wc_RsaDirect" , "rsa_direct" ) ;
284302 check_cfg ( & binding, "wc_MakeRsaKey" , "rsa_keygen" ) ;
285303 check_cfg ( & binding, "wc_RsaPSS_Sign" , "rsa_pss" ) ;
304+ check_cfg ( & binding, "wc_RsaSetRNG" , "rsa_setrng" ) ;
305+ check_cfg ( & binding, "WC_MGF1SHA512_224" , "rsa_mgf1sha512_224" ) ;
306+ check_cfg ( & binding, "WC_MGF1SHA512_256" , "rsa_mgf1sha512_256" ) ;
307+ // Detect whether wc_RsaExportKey takes a const first arg (new API) or non-const (old API)
308+ let re = Regex :: new ( r"pub fn wc_RsaExportKey(_fips)?\s*\(\s*\w+\s*:\s*\*\s*const" ) . unwrap ( ) ;
309+ println ! ( "cargo::rustc-check-cfg=cfg(rsa_const_api)" ) ;
310+ if re. is_match ( & binding) {
311+ println ! ( "cargo:rustc-cfg=rsa_const_api" ) ;
312+ }
286313
287314 /* sha */
288315 check_cfg ( & binding, "wc_InitSha" , "sha" ) ;
0 commit comments