@@ -707,6 +707,83 @@ int test_rsa_pkey_keygen(void *data)
707707 return err ;
708708}
709709
710+ int test_rsa_get_params (void * data )
711+ {
712+ int err ;
713+ EVP_PKEY * pkey = NULL ;
714+ unsigned char n [2048 / 8 ];
715+ unsigned char e [2048 / 8 ];
716+ OSSL_PARAM params [3 ];
717+ EVP_PKEY_CTX * ctx = NULL ;
718+ BIGNUM * eCmd = NULL ;
719+ BIGNUM * eRet = NULL ;
720+ const int newKeySize = 2048 ;
721+ (void )data ;
722+
723+ err = (ctx = EVP_PKEY_CTX_new_from_name (wpLibCtx , "RSA" , NULL )) == NULL ;
724+ if (err == 0 ) {
725+ err = EVP_PKEY_keygen_init (ctx ) != 1 ;
726+ }
727+ if (err == 0 ) {
728+ PRINT_MSG ("Change the key size w/ ctrl command" );
729+ err = EVP_PKEY_CTX_ctrl (ctx , EVP_PKEY_RSA , EVP_PKEY_OP_KEYGEN ,
730+ EVP_PKEY_CTRL_RSA_KEYGEN_BITS , newKeySize ,
731+ NULL ) <= 0 ;
732+ }
733+ if (err == 0 ) {
734+ err = (eCmd = BN_new ()) == NULL ;
735+ }
736+ if (err == 0 ) {
737+ err = BN_set_word (eCmd , 3 ) != 1 ;
738+ }
739+ if (err == 0 ) {
740+ PRINT_MSG ("Change the public exponent w/ ctrl command" );
741+ err = EVP_PKEY_CTX_ctrl (ctx , EVP_PKEY_RSA , EVP_PKEY_OP_KEYGEN ,
742+ EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP , 0 , eCmd ) <= 0 ;
743+ }
744+ if (err == 0 ) {
745+ PRINT_MSG ("Generate RSA key w/ new parameters" );
746+ err = EVP_PKEY_keygen (ctx , & pkey ) != 1 ;
747+ }
748+ if (pkey == NULL ) {
749+ err = 1 ;
750+ }
751+ if (err == 0 ) {
752+ memset (e , 0 , sizeof (e ));
753+ memset (n , 0 , sizeof (n ));
754+ params [0 ] = OSSL_PARAM_construct_BN (OSSL_PKEY_PARAM_RSA_N , n , sizeof (n ));
755+ params [1 ] = OSSL_PARAM_construct_BN (OSSL_PKEY_PARAM_RSA_E , e , sizeof (e ));
756+ params [2 ] = OSSL_PARAM_construct_end ();
757+
758+ PRINT_MSG ("Getting RSA params" );
759+
760+ if (EVP_PKEY_get_params (pkey , params ) != 1 ) {
761+ err = 1 ;
762+ }
763+ }
764+ /* Check return sizes, then verify e matches the one we set */
765+ if (err == 0 ) {
766+ if ((params [0 ].return_size != (size_t )(newKeySize / 8 )) ||
767+ (params [1 ].return_size != 1 )) {
768+ err = 1 ;
769+ }
770+ }
771+ if (err == 0 ) {
772+ eRet = BN_bin2bn (e , params [1 ].return_size , NULL );
773+ if (eRet == NULL ) {
774+ err = 1 ;
775+ }
776+ }
777+ if (err == 0 ) {
778+ err = BN_cmp ((const BIGNUM * )eCmd , (const BIGNUM * )eRet );
779+ }
780+
781+ BN_free (eCmd );
782+ BN_free (eRet );
783+ EVP_PKEY_free (pkey );
784+ return err ;
785+ }
786+
710787int test_rsa_pkey_invalid_key_size (void * data ) {
711788 int err ;
712789 EVP_PKEY * pkey = NULL ;
0 commit comments