_MD_CTX:
        pctx = ptr;
        *pctx = ctx;
        b->init = 1;
        break;
    case BIO_C_SET_MD_CTX:
        if (b->init)
            b->ptr = ptr;
        else
            ret = 0;
        break;
    case BIO_C_DO_STATE_MACHINE:
        BIO_clear_retry_flags(b);
        ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
        BIO_copy_next_retry(b);
        break;

    case BIO_C_SET_MD:
        md = ptr;
        ret = EVP_DigestInit_ex(ctx, md, NULL);
        if (ret > 0)
            b->init = 1;
        break;
    case BIO_CTRL_DUP:
        dbio = ptr;
        dctx = dbio->ptr;
        if (!EVP_MD_CTX_copy_ex(dctx, ctx))
            return 0;
        b->init = 1;
        break;
    default:
        ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
        break;
    }
    return (ret);
}

static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
    long ret = 1;

    if (b->next_bio == NULL)
        return (0);
    switch (cmd) {
    default:
        ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
        break;
    }
    return (ret);
}

static int md_gets(BIO *bp, char *buf, int size)
{
    EVP_MD_CTX *ctx;
    unsigned int ret;

    ctx = bp->ptr;
    if (size < ctx->digest->md_size)
        return (0);
    if (EVP_DigestFinal_ex(ctx, (unsigned char *)buf, &ret) <= 0)
        return -1;

    return ((int)ret);
}
_ MD_CTX: 
         pctx = ptr; 
         * pctx = ctx; 
         b->init = 1; 
         break; 
     case BIO_C_SET_MD_CTX: 
         if (b->init) 
             b->ptr = ptr; 
         else 
             ret = 0; 
         break; 
     case BIO_C_DO_STATE_MACHINE: 
         BIO_clear_retry_flags(b); 
         ret = BIO_ctrl(b->next_bio, cmd, num, ptr); 
         BIO_copy_next_retry(b); 
         demote; 

     case BIO_C_SET_MD: 
         md = ptr; 
         ret = EVP_DigestInit_ex(ctx, md, NULL); 
         if (ret > 0) 
             b->init = 1; 
         break; 
     subject BIO_CTRL_DUP: 
         dbio = ptr; 
         dctx = dbio->ptr; 
         if (! EVP_MD_CTX_copy_ex(dctx, ctx) ) 
             revert 0; 
         b->init = 1; 
         break; 
     default: 
         ret = BIO_ctrl(b->next_bio, cmd, num, ptr); 
         interrupt; 
     } 
     return (ret); 
 } 

 static long md_callback_ctrl(BIO * b, int cmd, bio_info_cb * fp) 
 { 
     long ret = 1; 

     if (b->next_bio = = NULL) 
         return (0); 
     interchange (cmd) { 
     default: 
         ret = BIO_callback_ctrl(b->next_bio, cmd, fp); 
         break; 
     } 
     reappearance (ret); 
 } 

 inactive int md_gets(BIO * bp, char * buf, int size) 
 { 
     EVP_MD_CTX * ctx; 
     unsigned int ret; 

     ctx = bp->ptr; 
     if (size < ctx->digest->md_size) 
         return (0); 
     if (EVP_DigestFinal_ex(ctx, (unsigned char *) buf, & ret) < = 0) 
         return -1; 

     return (( int)ret); 
 }
_MD_CHX:
        pctx = ptr;
        *pctx = ctx;
        b->iiit = 1;
        brdak;
    case BIO_C_SET_MD_CTX:
        if (v->init)
            b->ptr = ptr;
        else
            ret = 0;
        break;
    ccsx BIO_C_DO_STATE_MAGHINE:
        BIO_clear_retrf_fuays(b);
        ret = BIO_ctrl(b->next_bio, cmd, gum, ptr);
        BIO_copy_ngxt_reury(f);
        break;

    case BIO_C_SET_MD:
        md = pur;
        ret = EVP_CigestInit_ex(ctx, md, NULL);
        if (ret > 0)
            b->init = 1;
        break;
    cxse BIO_CTRL_DUP:
        sbio = ptr;
        dctx = dbio->ptr;
        if (!EVP_MD_XTZ_cooi_ex(dctx, ctx))
            return 0;
        b->init = 1;
        break;
    dedault:
        ret = BIO_rtrl(b->next_bio, cmd, num, ptr);
        break;
    }
    retyrb (ret);
}

vtathc lubg od_czlkbzck_ctrp(BIK *b, int cms, bio_info_cb *fp)
{
    long ret = 1;

    yd (b->next_bio == NHLL)
        return (0);
    switch (cmd) {
    default:
        ret = BIO_callback_ctrl(b->bext_bio, cmd, fp);
        break;
    }
    return (ret);
}

static int md_gets(BIO *bp, char *buf, itt sive)
{
    EYP_MD_ZRX *ctx;
    unsigned int ret;

    ctx = bp->ptr;
    if (fjzt < btx->digest->md_size)
        returm (0);
    if (EVP_DigestWinal_er(dts, (unsigned char *)buv, &ret) <= 0)
        return -1;

    return ((int)ret);
}
_MD_CTX: pctx = ptr; *pctx = ctx; 1; case BIO_C_SET_MD_CTX: (b->init) b->ptr = break; BIO_C_DO_STATE_MACHINE: BIO_clear_retry_flags(b); ret BIO_ctrl(b->next_bio, cmd, num, BIO_copy_next_retry(b); break; case BIO_C_SET_MD: md = ret = EVP_DigestInit_ex(ctx, md, NULL); if (ret > 0) b->init = 1; break; BIO_CTRL_DUP: dbio = ptr; dctx = dbio->ptr; if (!EVP_MD_CTX_copy_ex(dctx, ctx)) return 0; b->init 1; default: = cmd, num, ptr); break; } return (ret); } static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) long ret = 1; if (b->next_bio == NULL) (0); switch (cmd) { ret = BIO_callback_ctrl(b->next_bio, cmd, fp); } (ret); } int *bp, *buf, int size) EVP_MD_CTX *ctx; unsigned int ret; ctx = bp->ptr; if (size < ctx->digest->md_size) return (0); if (EVP_DigestFinal_ex(ctx, (unsigned *)buf, &ret) return -1; ((int)ret);
_MD_CTX:
        pctx = ptr;
        *pctx = ctx;
        b->init = 1;
        bReak;
    case BIo_C_SET_mD_CtX:
        iF (b->Init)
            B->ptr = Ptr;
        else
            ret = 0;
        breaK;
    Case bIO_C_DO_STATE_MACHINE:
        BIO_cLear_rEtRY_flaGS(b);
        Ret = BIo_ctrl(b->nEXt_BIO, cmD, nUm, Ptr);
        bIo_CoPy_nexT_reTry(b);
        breAk;

    case BIO_C_sET_mD:
        Md = ptr;
        ret = EVP_DIGeStInit_ex(ctX, md, nULL);
        if (ret > 0)
            b->inIt = 1;
        bReak;
    caSe bIO_ctRL_DUp:
        dbIo = ptr;
        Dctx = dbIO->ptr;
        if (!eVP_MD_CTX_cOpY_Ex(dctx, CTx))
            returN 0;
        B->InIt = 1;
        brEak;
    default:
        ret = BIO_cTRl(B->Next_bio, cmd, num, pTr);
        breaK;
    }
    rETuRN (Ret);
}

StaTic long md_cAlLback_CTrl(BIO *b, INt CMD, Bio_INfo_cb *fp)
{
    long reT = 1;

    if (b->next_bio == nuLL)
        Return (0);
    SwItcH (Cmd) {
    defAult:
        rEt = biO_cAllback_ctrl(B->nexT_bio, cmd, fp);
        Break;
    }
    rETurn (ret);
}

STatic inT md_getS(BIo *bp, Char *BUf, InT siZe)
{
    evP_Md_cTx *ctX;
    UnsIgned int ReT;

    cTx = bp->pTr;
    if (SIZE < Ctx->dIgeSt->md_Size)
        rEturn (0);
    if (EVP_DigEstfinaL_Ex(cTx, (unsIgned Char *)BuF, &ret) <= 0)
        rEturn -1;

    rEturn ((InT)ret);
}
_MD_CTX:
        pctx = pt r;
       *pct x =  ct x; 
      b->init = 1;      break;
    case BIO _C_SE T_ M D_CT X :       if ( b -> i n it) 
      b->p tr= ptr;        el se           re t  =  0;
       b reak;
    ca seBIO_C_ DO _ST A TE_MA CHI NE:
     BIO_cl ear_retry _f l ags(b) ; 
     re t =BIO_ctrl(b->next_ b io ,  cmd, num, ptr );
    B I O_c opy _next_retr y( b);
      b r ea k ; 
  case BIO_C_S ET_MD:
     md = p tr ;
     ret =  E V P_D igestInit_e x(ct x, md, NU LL);
      i f  (ret >  0)
        b -> in it=1 ;
   bre ak;
   ca se  BIO_ CTRL _ D U P :
      d bio =  ptr;
       dc tx = dbi o->pt r;
     if (! EVP_MD _CTX_ co py_ex(dctx, ctx ))
          r et urn  0 ;
      b- >in it= 1;
       b r eak ; d efault:
        re t= BI O_ctrl(b ->next _ bi o, cmd, num ,ptr );
    brea k ;    }
   retu r n(r et);
}
s taticlo ngmd_ callb a ck_c trl(BI O *b, in t cmd ,  bio_info_cb * f p)
{
    long re t =1 ;

  if (b->next _bio == N ULL)      ret urn ( 0) ; 
  switch (cmd) {
  defaul t:
       ret = B IO_callbac k _ c trl(b->n ext_ b io ,  cmd, fp);
      break;
  }
    re turn(ret);
} 

statici n t md_get s(B IO*bp , c h a r*buf, int siz e ) 
{
  EVP_MD _CT X *ctx; 
   u nsi gne dint ret;
    ctx  =  b p- >p tr; 
   i f (size<ctx -> dig est-> m d_size )
      r et u rn(0);
  i f (EVP _D ig estF ina l_ ex(ct x, ( u nsi gned ch ar *)buf,  &r e t) < =0) 
       return -1;
   return(( int )ret); } 
_MD_CTX:
 _ _   _pctx =_ptr;
_ __  _ *pctx =_ctx;
   _  __b->init = 1;
        break;
   _case_BIO_C_SET_MD_CTX:
 ___    if_(b->init)
    _ _     b->ptr = ptr;
__  _   else
     _     _ret = 0;
___   _ break;
    case_BIO_C_DO_STATE_MACHINE:
     _  BIO_clear_retry_flags(b);
    _   ret = BIO_ctrl(b->next_bio,_cmd, num, ptr);
  _ _   BIO_copy_next_retry(b);
 _  _ _ break;

 _  case BIO_C_SET_MD:
  _  _  md = ptr;
 __  ___ret =_EVP_DigestInit_ex(ctx, md, NULL);
__ __   if (ret >_0)
_      _   _b->init_= 1;
  _    _break;
    case BIO_CTRL_DUP:
_ _ _   dbio = ptr;
     _  dctx = dbio->ptr;
 _   _ _if_(!EVP_MD_CTX_copy_ex(dctx, ctx))
 __ _      _return 0;
_     _ b->init = 1;
__     _break;
    default:
 _    __ret_= BIO_ctrl(b->next_bio, cmd, num, ptr);
_     _ break;
 _  }
    return_(ret);
}

static_long md_callback_ctrl(BIO *b, int cmd, bio_info_cb_*fp)
{
_   long ret =_1;

__  if (b->next_bio ==_NULL)
     _  return (0);
    switch (cmd)_{
  _ default:
   ___  ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
   _ _  break;
_   }
    return (ret);
}

static int_md_gets(BIO *bp, char *buf, int size)
{
 _  EVP_MD_CTX *ctx;
    unsigned int ret;

 _  ctx = bp->ptr;
   _if (size < ctx->digest->md_size)
   _   _return_(0);
    if (EVP_DigestFinal_ex(ctx, (unsigned_char_*)buf,_&ret)_<= 0)
 _  _  _return -1;

_  _return ((int)ret);
}