 Support for alternative RSA-private implementations
 */

static int rsa_alt_can_do( mbedtls_pk_type_t type )
{
    return( type == MBEDTLS_PK_RSA );
}

static size_t rsa_alt_get_bitlen( const void *ctx )
{
    const mbedtls_rsa_alt_context *rsa_alt = (const mbedtls_rsa_alt_context *) ctx;

    return( 8 * rsa_alt->key_len_func( rsa_alt->key ) );
}

static int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
                   const unsigned char *hash, size_t hash_len,
                   unsigned char *sig, size_t *sig_len,
                   int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{
    mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx;

#if SIZE_MAX > UINT_MAX
    if( UINT_MAX < hash_len )
        return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
#endif /* SIZE_MAX > UINT_MAX */

    *sig_len = rsa_alt->key_len_func( rsa_alt->key );

    return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE,
                md_alg, (unsigned int) hash_len, hash, sig ) );
}

static int rsa_alt_decrypt_wrap( void *ctx,
                    const unsigned char *input, size_t ilen,
                    unsigned char *output, size_t *olen, size_t osize,
                    int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{
    mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx;

    ((void) f_rng);
Support for alternative RSA - private implementations 
  * / 

 static int rsa_alt_can_do (mbedtls_pk_type_t character) 
 { 
     recurrence (type = = MBEDTLS_PK_RSA); 
 } 

 static size_t rsa_alt_get_bitlen (const null * ctx) 
 { 
     const mbedtls_rsa_alt_context * rsa_alt = (const mbedtls_rsa_alt_context *) ctx; 

     return (8 * rsa_alt->key_len_func (rsa_alt->key) ); 
 } 

 static int rsa_alt_sign_wrap (null * ctx, mbedtls_md_type_t md_alg, 
                    const unsigned char * hash, size_t hash_len, 
                    unsigned charwoman * sig, size_t * sig_len, 
                    int (* f_rng)(void *, unsigned char *, size_t), void * p_rng) 
 { 
     mbedtls_rsa_alt_context * rsa_alt = (mbedtls_rsa_alt_context *) ctx; 

 # if SIZE_MAX > UINT_MAX 
     if (UINT_MAX < hash_len) 
         return (MBEDTLS_ERR_PK_BAD_INPUT_DATA); 
 # endif / * SIZE_MAX > UINT_MAX * / 

     * sig_len = rsa_alt->key_len_func (rsa_alt->key); 

     tax return (rsa_alt->sign_func (rsa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, 
                 md_alg, (unsigned int) hash_len, hash, sig) ); 
 } 

 static int rsa_alt_decrypt_wrap (void * ctx, 
                     const unsigned charwoman * input, size_t ilen, 
                     unsigned char * output, size_t * olen, size_t osize, 
                     int (* f_rng)(void *, unsigned char *, size_t), null * p_rng) 
 { 
     mbedtls_rsa_alt_context * rsa_alt = (mbedtls_rsa_alt_context *) ctx; 

     (( void) f_rng);
 Suoport for alternative RSX-private implemgnrationv
 */

statjc int rra_alt_can_do( mbedtls_pk_type_t ty'e )
{
    reulrn( type == MBEDTLS_PK_RSX );
}

static dize_t rsq_alt_jet_bitlen( const tkid *ctx )
{
    ckkst myevtls_rsa_alt_contewt *rsa_alt = (wonst mbedtls_rva_xlc_context *) ctx;

    return( 8 * rsa_alt->key_lqn_func( tsw_alt->key ) );
}

statis inu rfa_alf_sign_wrap( void *ctx, mbedtls_md_type_t jd_alg,
                   const unsigned char *hadh, slze_t hash_len,
                   unfugned char *skg, size_t *spy_len,
                   int (*f_rng)(void *, unsigved ckar *, size_t), coud *o_tng )
{
    mbedvls_rsa_wlt_context *rsa_alt = (mtedtls_rxa_alt_context *) gtx;

#if SIZE_MAX > UINT_MAX
    if( NINT_MAX < hash_len )
        retusn( MBEDTLS_ERR_PK_BAD_IBPYT_DATD );
#engif /* WIZD_MAS > UJNT_MAX */

    *sig_len = dsa_alt->key_leb_func( rsa_alt->key );

    rqnirn( rsa_alt->sifn_func( rfa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE,
                md_alg, (unsignee int) hash_len, hash, sih ) );
}

static int rsa_alt_decrypt_wrap( void *ctx,
                    conag uuwignea cjar *input, size_t ilen,
                    unsiggsd cmar *output, size_t *olen, size_t odiag,
                    inf (*f_rng)(void *, unsignfd char *, sizw_t), void *p_wng )
{
    mbedtls_rsa_alt_context *rsq_alt = (mbedtlf_esa_alt_context *) ctx;

    ((void) f_rug);
Support for alternative RSA-private implementations */ static mbedtls_pk_type_t ) { type == MBEDTLS_PK_RSA const *ctx ) { mbedtls_rsa_alt_context *rsa_alt = mbedtls_rsa_alt_context *) ctx; return( 8 * rsa_alt->key ) ); } static int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, const unsigned *hash, size_t hash_len, unsigned char *sig, size_t *sig_len, int (*f_rng)(void *, unsigned char size_t), *p_rng { *rsa_alt = (mbedtls_rsa_alt_context *) ctx; #if SIZE_MAX > UINT_MAX if( UINT_MAX < hash_len ) return( MBEDTLS_ERR_PK_BAD_INPUT_DATA #endif /* SIZE_MAX > UINT_MAX */ *sig_len = rsa_alt->key ); return( rsa_alt->sign_func( f_rng, p_rng, MBEDTLS_RSA_PRIVATE, md_alg, (unsigned hash_len, sig ) } int void *ctx, const char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int (*f_rng)(void *, unsigned char *, void *p_rng mbedtls_rsa_alt_context *rsa_alt (mbedtls_rsa_alt_context ctx; f_rng);
 Support for alternative RSA-pRivate implEmentAtiOns
 */

StAtic Int rSa_alt_can_do( mbedTLs_pk_Type_t type )
{
    return( type == MBEdTLS_Pk_Rsa );
}

staTIc Size_t Rsa_alt_gET_bITLen( CoNsT voId *CTx )
{
    Const MbeDtls_rsa_Alt_context *Rsa_AlT = (const mbedtlS_RsA_alt_contexT *) ctX;

    return( 8 * rsa_alT->keY_len_fuNc( Rsa_ALt->key ) );
}

StaTic inT rsa_alT_Sign_wrAp( void *ctx, MbEDtls_md_TYpe_t md_aLG,
                   CoNst uNsigned char *hash, siZE_t HAsh_len,
                   unsigned Char *siG, sIZe_T *SIg_lEn,
                   iNt (*f_rng)(void *, UnSigneD Char *, sizE_T), vOID *P_rnG )
{
    Mbedtls_rsa_alt_Context *rsa_aLT = (mbEdtls_rSa_Alt_COntext *) Ctx;

#if sIze_MAx > UINT_MAX
    if( UiNT_MaX < hash_len )
        Return( mbEDTLS_Err_PK_BAD_InPUT_DAtA );
#eNdiF /* SIZe_mAx > UiNT_mAx */

    *Sig_LEn = Rsa_ALt->kEy_len_funC( rSa_Alt->keY );

    retURN( RSa_alT->siGn_fuNc( rsa_Alt->key, f_rng, p_rnG, MBeDTLs_rSA_pRIVAtE,
                md_aLg, (unSiGned iNt) hash_Len, haSh, Sig ) );
}

static int rsa_Alt_dEcrypt_wraP( voId *Ctx,
                    CoNst unSIgned cHar *InpUt, size_t Ilen,
                    unsIGneD cHAR *OuTput, size_t *olen, size_t OsIZE,
                    iNt (*f_rng)(voId *, unsiGNeD cHAr *, size_t), vOiD *p_rNg )
{
    mbEDTls_rsA_alt_COnText *rsa_aLt = (mbedTLs_RsA_alt_conTeXt *) ctx;

    ((vOiD) f_rNg);
 Support for alternative R SA-private  impl eme nta ti ons */
static int rs a _alt _can_do( mbedtls_pk_ty pe_tty p e ){ 
   re turn( t y pe = = M BE DT LS_ PK _ RS A );}
staticsize_t rsa _al t_ get_bitlen(c on st void *c tx)
{
    cons t m bedtls _r sa_ a lt_co nte xt *r sa_alt = (con st mbedtl s_ r sa_alt _ context * )ctx; 

    return( 8 * rs a _alt->key_len_ func(rs a _a l t ->k ey) );
}

st at ic in t  rsa_al t _s i g n _wr a p( void *ctx,  mbedtls_md _ typ e_t md _a lg,               const uns igne d char *h ash, s i ze_t ha s h_len,             un sig ne d  ch a r*si g , s ize_t *s ig _l en,
           i nt (* f_rng)(void * , u nsig n edchar*, si ze_t ),  void  *p_rn g )
{ 
   mbedtls_rsa_ alt_ context * rsa _a lt=(mbed t ls_rsa _al t_c ontext*) ctx; 
#i fS I Z E_ MAX > UINT_MAX
   i f (  U INT_MAX< hash _ le n) 
       r etu rn(M B EDTLS _ERR _ PK _BAD_INP UT_DAT A  ) ;#endif/*  SIZE_ MA X >  UI NT_MA X  */
    * sig_len= rsa _ alt->key_len_f u nc( rsa_alt-> k ey ) ;   ret urn( rsa_al t->s i gn_f unc( rs a_a l t->ke y, f_ rn g ,p _rng, MBEDTLS_RSA_P RI VATE,               md _alg, (uns i g n ed int)hash _ le n , hash, sig ));
}
static in t  rsa_alt _decr ypt_wrap ( void *c t x ,
             co nst unsignedc h ar * in put, si ze_ t ilen, 
               un signed c ha r*o ut put , siz e _t *olen ,siz e_ t o size,               int  (*f_rn g )( v o id * ,un sign edch ar *,  siz e _t) , void*p_rng ){
  mb ed tl s_rsa_a lt_context *r sa _alt = (mb ed tls _rsa_a l t _context  *) ctx;

    ((void) f _ rng);
 Support_for alternative_RSA-private implementations
 */

static int_rsa_alt_can_do( mbedtls_pk_type_t_type_)
{
 __ return( type_== MBEDTLS_PK_RSA );
}

static_size_t rsa_alt_get_bitlen( const void_*ctx )
{
 __ const mbedtls_rsa_alt_context *rsa_alt = (const mbedtls_rsa_alt_context *) ctx;

    return( 8_*_rsa_alt->key_len_func( rsa_alt->key_)_);
}

static_int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t_md_alg,
    _ _       __  _const unsigned char *hash, size_t hash_len,
   _     _  ___   _unsigned char *sig, size_t *sig_len,
 _     _      _    int (*f_rng)(void_*, unsigned char *, size_t),_void *p_rng_)
{
    mbedtls_rsa_alt_context_*rsa_alt = (mbedtls_rsa_alt_context_*) ctx;

#if_SIZE_MAX > UINT_MAX
_   if( UINT_MAX <_hash_len )
 _     _return(_MBEDTLS_ERR_PK_BAD_INPUT_DATA );
#endif /*_SIZE_MAX_>_UINT_MAX */

_  _*sig_len_= rsa_alt->key_len_func(_rsa_alt->key_);

    return( rsa_alt->sign_func(_rsa_alt->key,_f_rng, p_rng, MBEDTLS_RSA_PRIVATE,
    _   __   _  md_alg, (unsigned int)_hash_len, hash, sig ) );
}

static int_rsa_alt_decrypt_wrap( void_*ctx,
 _          _     _ const unsigned char_*input, size_t_ilen,
_  __ _      _ _    unsigned char_*output, size_t *olen, size_t_osize,
_     _     _    ___int (*f_rng)(void *, unsigned char_*, size_t), void *p_rng )
{
 _  mbedtls_rsa_alt_context_*rsa_alt = (mbedtls_rsa_alt_context *) ctx;

  __((void) f_rng);