@@ -214,8 +214,9 @@ void wolfCLU_CertSignSetCA(WOLFCLU_CERT_SIGN* csign, WOLFSSL_X509* ca,
214214
215215/* ref: https://github.com/wolfssl/wolfssl-examples/X9.146/gen_ecdsa_mldsa_dual_keysig_cert.c */
216216void wolfCLU_GenChimeraCertSign (WOLFSSL_BIO * bioCaKey , WOLFSSL_BIO * bioAltCaKey ,
217- WOLFSSL_BIO * bioAltSubjPubKey , WOLFSSL_BIO * bioSubjKey , WOLFSSL_X509 * caCert ,
218- const char * subject , const char * outFileName , int outForm )
217+ WOLFSSL_BIO * bioAltSubjPubKey , WOLFSSL_BIO * bioSubjKey ,
218+ WOLFSSL_X509 * caCert , const char * subject ,
219+ const char * outFileName , int outForm )
219220{
220221#if defined(WOLFSSL_DUAL_ALG_CERTS ) && defined(HAVE_DILITHIUM )
221222 int ret = WOLFCLU_SUCCESS ;
@@ -279,7 +280,7 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
279280
280281 if (bioCaKey == NULL || bioAltCaKey == NULL || bioAltSubjPubKey == NULL
281282 || subject == NULL || outFileName == NULL ) {
282- wolfCLU_LogError ("Error NULL argument in wolfCLU_GenChimeraCertSign" );
283+ wolfCLU_LogError ("Error invalid argument wolfCLU_GenChimeraCertSign" );
283284 ret = BAD_FUNC_ARG ;
284285 }
285286 else if (bioSubjKey == NULL && caCert == NULL ) {
@@ -291,7 +292,7 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
291292 WOLFCLU_LOG (WOLFCLU_L0 , "Generating Chimera server certificate\n" );
292293 }
293294 else {
294- wolfCLU_LogError ("Error invalid argument in wolfCLU_GenChimeraCertSign" );
295+ wolfCLU_LogError ("Error invalid argument wolfCLU_GenChimeraCertSign" );
295296 ret = BAD_FUNC_ARG ;
296297 }
297298
@@ -348,7 +349,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
348349 }
349350 else {
350351 serverKeySz = ret ;
351- WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from server key file" , serverKeySz );
352+ WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from server key file" ,
353+ serverKeySz );
352354 ret = WOLFCLU_SUCCESS ;
353355 }
354356 }
@@ -370,7 +372,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
370372 }
371373 else {
372374 caKeySz = ret ;
373- WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from CA key file" , caKeySz );
375+ WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from CA key file" ,
376+ caKeySz );
374377 ret = WOLFCLU_SUCCESS ;
375378 }
376379 }
@@ -386,7 +389,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
386389
387390 /* load CA ecc private key */
388391 if (ret == WOLFCLU_SUCCESS ) {
389- ret = wc_PemToDer (caKeyBuf , caKeySz , ECC_PRIVATEKEY_TYPE , & derObj , HEAP_HINT , NULL , NULL );
392+ ret = wc_PemToDer (caKeyBuf , caKeySz , ECC_PRIVATEKEY_TYPE ,
393+ & derObj , HEAP_HINT , NULL , NULL );
390394 if (ret < 0 ) {
391395 wolfCLU_LogError ("Error convert pem to der" );
392396 ret = WOLFCLU_FATAL_ERROR ;
@@ -396,7 +400,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
396400 caKeySz = derObj -> length ;
397401 XMEMCPY (caKeyBuf , derObj -> buffer , caKeySz );
398402 wc_FreeDer (& derObj );
399- WOLFCLU_LOG (WOLFCLU_L0 , "Converted CA key to DER format; %d bytes" , caKeySz );
403+ WOLFCLU_LOG (WOLFCLU_L0 , "Converted CA key to DER format; %d bytes" ,
404+ caKeySz );
400405 ret = WOLFCLU_SUCCESS ;
401406 }
402407 }
@@ -428,7 +433,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
428433
429434 /* load server ecc private key */
430435 if (ret == WOLFCLU_SUCCESS && !isCA ) {
431- ret = wc_PemToDer (serverKeyBuf , serverKeySz , ECC_PRIVATEKEY_TYPE , & derObj , HEAP_HINT , NULL , NULL );
436+ ret = wc_PemToDer (serverKeyBuf , serverKeySz , ECC_PRIVATEKEY_TYPE ,
437+ & derObj , HEAP_HINT , NULL , NULL );
432438 if (ret < 0 ) {
433439 wolfCLU_LogError ("Error convert pem to der" );
434440 ret = WOLFCLU_FATAL_ERROR ;
@@ -438,7 +444,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
438444 serverKeySz = derObj -> length ;
439445 XMEMCPY (serverKeyBuf , derObj -> buffer , serverKeySz );
440446 wc_FreeDer (& derObj );
441- WOLFCLU_LOG (WOLFCLU_L0 , "Converted server key to DER format; %d bytes" , serverKeySz );
447+ WOLFCLU_LOG (WOLFCLU_L0 , "Converted server key to DER format; \
448+ %d bytes" , serverKeySz );
442449 ret = WOLFCLU_SUCCESS ;
443450 }
444451 }
@@ -457,7 +464,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
457464
458465 if (ret == WOLFCLU_SUCCESS && !isCA ) {
459466 idx = 0 ;
460- ret = wc_EccPrivateKeyDecode (serverKeyBuf , & idx , & serverKey , serverKeySz );
467+ ret = wc_EccPrivateKeyDecode (serverKeyBuf , & idx ,
468+ & serverKey , serverKeySz );
461469 if (ret != 0 ) {
462470 wolfCLU_LogError ("Error decoding server key" );
463471 ret = WOLFCLU_FATAL_ERROR ;
@@ -484,14 +492,16 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
484492 }
485493 else {
486494 sapkiSz = ret ;
487- WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from alternative CA public key file" , sapkiSz );
495+ WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from \
496+ alternative CA public key file" , sapkiSz );
488497 ret = WOLFCLU_SUCCESS ;
489498 }
490499 }
491500 }
492501
493502 if (ret == WOLFCLU_SUCCESS ) {
494- ret = wc_PemToDer (sapkiBuf , sapkiSz , PUBLICKEY_TYPE , & derObj , HEAP_HINT , NULL , NULL );
503+ ret = wc_PemToDer (sapkiBuf , sapkiSz , PUBLICKEY_TYPE ,
504+ & derObj , HEAP_HINT , NULL , NULL );
495505 if (ret < 0 ) {
496506 wolfCLU_LogError ("Error convert file pem to der" );
497507 ret = WOLFCLU_FATAL_ERROR ;
@@ -501,7 +511,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
501511 sapkiSz = derObj -> length ;
502512 XMEMCPY (sapkiBuf , derObj -> buffer , sapkiSz );
503513 wc_FreeDer (& derObj );
504- WOLFCLU_LOG (WOLFCLU_L0 , "Converted alternative CA public key to DER format; %d bytes" , sapkiSz );
514+ WOLFCLU_LOG (WOLFCLU_L0 , "Converted alternative CA public key \
515+ to DER format; %d bytes" , sapkiSz );
505516 ret = WOLFCLU_SUCCESS ;
506517 }
507518 }
@@ -534,14 +545,16 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
534545 }
535546 else {
536547 altCaKeySz = ret ;
537- WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from alternative CA key file" , altCaKeySz );
548+ WOLFCLU_LOG (WOLFCLU_L0 , "Read %d bytes from \
549+ alternative CA key file" , altCaKeySz );
538550 ret = WOLFCLU_SUCCESS ;
539551 }
540552 }
541553 }
542554
543555 if (ret == WOLFCLU_SUCCESS ) {
544- ret = wc_PemToDer (altCaKeyBuf , altCaKeySz , PKCS8_PRIVATEKEY_TYPE , & derObj , HEAP_HINT , NULL , NULL );
556+ ret = wc_PemToDer (altCaKeyBuf , altCaKeySz , PKCS8_PRIVATEKEY_TYPE ,
557+ & derObj , HEAP_HINT , NULL , NULL );
545558 if (ret < 0 ) {
546559 wolfCLU_LogError ("Error convert pem to der" );
547560 ret = WOLFCLU_FATAL_ERROR ;
@@ -551,20 +564,23 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
551564 altCaKeySz = derObj -> length ;
552565 XMEMCPY (altCaKeyBuf , derObj -> buffer , altCaKeySz );
553566 wc_FreeDer (& derObj );
554- WOLFCLU_LOG (WOLFCLU_L0 , "Converted alternative CA key to DER format; %d bytes" , altCaKeySz );
567+ WOLFCLU_LOG (WOLFCLU_L0 , "Converted alternative CA key \
568+ to DER format; %d bytes" , altCaKeySz );
555569 ret = WOLFCLU_SUCCESS ;
556570 }
557571 }
558572
559573 if (ret == WOLFCLU_SUCCESS ) {
560574 idx = 0 ;
561- ret = wc_Dilithium_PrivateKeyDecode (altCaKeyBuf , & idx , & altCaKey , (word32 )altCaKeySz );
575+ ret = wc_Dilithium_PrivateKeyDecode (altCaKeyBuf , & idx ,
576+ & altCaKey , (word32 )altCaKeySz );
562577 if (ret != 0 ) {
563578 wolfCLU_LogError ("Error decoding ML-DSA key" );
564579 ret = WOLFCLU_FATAL_ERROR ;
565580 }
566581 else {
567- WOLFCLU_LOG (WOLFCLU_L0 , "Successfully decoded CA alt private key" );
582+ WOLFCLU_LOG (WOLFCLU_L0 , "Successfully decoded \
583+ CA alt private key" );
568584 wc_MlDsaKey_GetParams (& altCaKey , & level );
569585 WOLFCLU_LOG (WOLFCLU_L0 , "ML-DSA level: %d" , level );
570586 ret = WOLFCLU_SUCCESS ;
@@ -574,13 +590,16 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
574590 if (ret == WOLFCLU_SUCCESS ) {
575591 switch (level ) {
576592 case 2 :
577- altSigAlgSz = SetAlgoID (CTC_ML_DSA_LEVEL2 , altSigAlgBuf , oidSigType , 0 );
593+ altSigAlgSz = SetAlgoID (CTC_ML_DSA_LEVEL2 ,
594+ altSigAlgBuf , oidSigType , 0 );
578595 break ;
579596 case 3 :
580- altSigAlgSz = SetAlgoID (CTC_ML_DSA_LEVEL3 , altSigAlgBuf , oidSigType , 0 );
597+ altSigAlgSz = SetAlgoID (CTC_ML_DSA_LEVEL3 ,
598+ altSigAlgBuf , oidSigType , 0 );
581599 break ;
582600 case 5 :
583- altSigAlgSz = SetAlgoID (CTC_ML_DSA_LEVEL5 , altSigAlgBuf , oidSigType , 0 );
601+ altSigAlgSz = SetAlgoID (CTC_ML_DSA_LEVEL5 ,
602+ altSigAlgBuf , oidSigType , 0 );
584603 break ;
585604 default :
586605 wolfCLU_LogError ("Error Invalid ML-DSA level %d" , level );
@@ -589,11 +608,13 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
589608 }
590609
591610 if (altSigAlgSz <= 0 ) {
592- wolfCLU_LogError ("Error SetAlgoID(%d) returned: %d\n" , level , altSigAlgSz );
611+ wolfCLU_LogError ("Error SetAlgoID(%d) returned: \
612+ %d\n" , level , altSigAlgSz );
593613 ret = WOLFCLU_FATAL_ERROR ;
594614 }
595615 else {
596- WOLFCLU_LOG (WOLFCLU_L0 , "Successfully generated alternative signature algorithm; %d bytes" , altSigAlgSz );
616+ WOLFCLU_LOG (WOLFCLU_L0 , "Successfully generated \
617+ alternative signature algorithm; %d bytes" , altSigAlgSz );
597618 }
598619 }
599620
@@ -684,13 +705,15 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
684705 }
685706
686707 if (ret == WOLFCLU_SUCCESS ) {
687- ret = wc_SetCustomExtension (& newCert , 0 , "2.5.29.72" , sapkiBuf , sapkiSz );
708+ ret = wc_SetCustomExtension (& newCert , 0 , "2.5.29.72" ,
709+ sapkiBuf , sapkiSz );
688710 if (ret < 0 ) {
689711 wolfCLU_LogError ("Error setting custom extension" );
690712 ret = WOLFCLU_FATAL_ERROR ;
691713 }
692714 else {
693- ret = wc_SetCustomExtension (& newCert , 0 , "2.5.29.73" , altSigAlgBuf , altSigAlgSz );
715+ ret = wc_SetCustomExtension (& newCert , 0 , "2.5.29.73" ,
716+ altSigAlgBuf , altSigAlgSz );
694717 if (ret < 0 ) {
695718 wolfCLU_LogError ("Error setting custom extension" );
696719 ret = WOLFCLU_FATAL_ERROR ;
@@ -702,13 +725,15 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
702725 }
703726
704727 if (ret == WOLFCLU_SUCCESS && isCA ) {
705- ret = wc_MakeCert (& newCert , scratchBuf , scratchSz , NULL , & caKey , & rng );
728+ ret = wc_MakeCert (& newCert , scratchBuf ,
729+ scratchSz , NULL , & caKey , & rng );
706730 if (ret <= 0 ) {
707731 wolfCLU_LogError ("Error making certificate" );
708732 ret = WOLFCLU_FATAL_ERROR ;
709733 }
710734 else {
711- ret = wc_SignCert (newCert .bodySz , newCert .sigType , scratchBuf , scratchSz , NULL , & caKey , & rng );
735+ ret = wc_SignCert (newCert .bodySz , newCert .sigType , scratchBuf ,
736+ scratchSz , NULL , & caKey , & rng );
712737 if (ret <= 0 ) {
713738 wolfCLU_LogError ("Error signing certificate" );
714739 ret = WOLFCLU_FATAL_ERROR ;
@@ -720,13 +745,15 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
720745 }
721746 }
722747 else if (ret == WOLFCLU_SUCCESS && !isCA ) {
723- ret = wc_MakeCert (& newCert , scratchBuf , scratchSz , NULL , & serverKey , & rng );
748+ ret = wc_MakeCert (& newCert , scratchBuf , scratchSz ,
749+ NULL , & serverKey , & rng );
724750 if (ret <= 0 ) {
725751 wolfCLU_LogError ("Error making server certificate" );
726752 ret = WOLFCLU_FATAL_ERROR ;
727753 }
728754 else {
729- ret = wc_SignCert (newCert .bodySz , newCert .sigType , scratchBuf , scratchSz , NULL , & caKey , & rng );
755+ ret = wc_SignCert (newCert .bodySz , newCert .sigType , scratchBuf ,
756+ scratchSz , NULL , & caKey , & rng );
730757 if (ret <= 0 ) {
731758 wolfCLU_LogError ("Error signing server certificate" );
732759 ret = WOLFCLU_FATAL_ERROR ;
@@ -790,7 +817,7 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
790817
791818 if (ret == WOLFCLU_SUCCESS ) {
792819 ret = wc_SetCustomExtension (& newCert , 0 , "2.5.29.74" ,
793- altSigValBuf , altSigValSz );
820+ altSigValBuf , altSigValSz );
794821 if (ret < 0 ) {
795822 wolfCLU_LogError ("Error setting custom extension" );
796823 ret = WOLFCLU_FATAL_ERROR ;
@@ -807,15 +834,17 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
807834 ret = WOLFCLU_FATAL_ERROR ;
808835 }
809836 else {
810- ret = wc_SignCert (newCert .bodySz , newCert .sigType , derBuf , derSz , NULL , & caKey , & rng );
837+ ret = wc_SignCert (newCert .bodySz , newCert .sigType ,
838+ derBuf , derSz , NULL , & caKey , & rng );
811839 if (ret < 0 ) {
812840 wolfCLU_LogError ("Error signing certificate" );
813841 ret = WOLFCLU_FATAL_ERROR ;
814842 }
815843 else {
816844 derSz = ret ;
817845 ret = WOLFCLU_SUCCESS ;
818- printf ("Successfully created Chimera CA certificate with %d bytes\n" , derSz );
846+ WOLFCLU_LOG (WOLFCLU_L0 , "Successfully created \
847+ Chimera CA certificate; %d bytes\n" , derSz );
819848 }
820849 }
821850 }
@@ -826,15 +855,17 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
826855 ret = WOLFCLU_FATAL_ERROR ;
827856 }
828857 else {
829- ret = wc_SignCert (newCert .bodySz , newCert .sigType , derBuf , derSz , NULL , & caKey , & rng );
858+ ret = wc_SignCert (newCert .bodySz , newCert .sigType ,
859+ derBuf , derSz , NULL , & caKey , & rng );
830860 if (ret < 0 ) {
831861 wolfCLU_LogError ("Error signing server certificate" );
832862 ret = WOLFCLU_FATAL_ERROR ;
833863 }
834864 else {
835865 derSz = ret ;
836866 ret = WOLFCLU_SUCCESS ;
837- WOLFCLU_LOG (WOLFCLU_L0 , "Successfully created Chimera certificate with %d bytes\n" , derSz );
867+ WOLFCLU_LOG (WOLFCLU_L0 , "Successfully created \
868+ Chimera certificate; %d bytes\n" , derSz );
838869 }
839870 }
840871 }
@@ -848,7 +879,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
848879 else {
849880 outSz = ret ;
850881 ret = WOLFCLU_SUCCESS ;
851- WOLFCLU_LOG (WOLFCLU_L0 , "Converted certificate to PEM format; %d bytes" , outSz );
882+ WOLFCLU_LOG (WOLFCLU_L0 , "Converted certificate to PEM format; \
883+ %d bytes" , outSz );
852884 }
853885 }
854886 else if (ret == WOLFCLU_SUCCESS && outForm == DER_FORM ) {
@@ -892,7 +924,8 @@ void wolfCLU_GenChimeraCertSign(WOLFSSL_BIO *bioCaKey, WOLFSSL_BIO *bioAltCaKey,
892924 wolfCLU_LogError ("Error in wolfCLU_ChimeraCertSignSetCA: %d" , ret );
893925 }
894926 else {
895- WOLFCLU_LOG (WOLFCLU_L0 , "Successfully created Chimera certificate: %s" , outFileName );
927+ WOLFCLU_LOG (WOLFCLU_L0 , "Successfully created \
928+ Chimera certificate: %s" , outFileName );
896929 }
897930
898931#else
0 commit comments