bridge/class-master/depend/pari/src/basemath/ecpp.c
/* return 1 if 'cert' is a valid PARI ECPP certificate */
return 1 if 'cert' is a valid PARI ECPP certificate
return 1 if ' cert ' is a valid PARI ECPP certificate
static long
ecppisvalid_i(GEN cert)
{
  const long trustbits = 64;
  long i, lgcert = lg(cert);
  GEN ql, q = gen_0;
  if (typ(cert) == t_INT)
  {
    if (expi(cert) >= trustbits) return 0; 
    return BPSW_psp(cert);
  }
  if (typ(cert) != t_VEC || lgcert <= 1) return 0;
  ql = gel(cert, lgcert-1); if (lg(ql)-1 != 5) return 0;
  ql = cert_get_q(ql);
  if (expi(ql) >= trustbits || !BPSW_psp(ql)) return 0;
  for (i = 1; i < lgcert; i++)
  {
    GEN N, W, mP, sP, r, m, s, a, P, certi = gel(cert, i);
    if (lg(certi)-1 != 5) return 0;
    N = cert_get_N(certi);
    if (typ(N) != t_INT || signe(N) <= 0) return 0;
    switch(umodiu(N,6))
    {
      case 1: case 5: break; 
      default: return 0;
    }
    if (i > 1 && !equalii(N, q)) return 0;
    W = cert_get_t(certi);
    if (typ(W) != t_INT) return 0;
    if (!(cmpii(sqri(W), shifti(N,2)) < 0)) return 0;
    s = cert_get_s(certi);
    if (typ(s) != t_INT || signe(s) < 0) return 0;
    m = cert_get_m(certi);
    q = dvmdii(m, s, &r);
    if (!isintzero(r)) return 0;
    if (!Nq_isvalid(N, q)) return 0;
    a = cert_get_a4(certi);
    if (typ(a) != t_INT) return 0;
    P = cert_get_P(certi);
    if (typ(P) != t_VEC || lg(P) != 3) return 0;
    P = FpE_to_FpJ(P);
    mP = FpJ_mul(P, m, a, N);
    if (!FpJ_is_inf(mP)) return 0;
    sP = FpJ_mul(P, s, a, N);
    if (!isint1(gcdii(gel(sP, 3), N))) return 0;
  }
  return 1;
}
static long ecppisvalid_i ( GEN cert ) { const long trustbits = 64 ; long i , lgcert = lg ( cert ) ; GEN ql , q = gen_0 ; if ( typ ( cert ) == t_INT ) { if ( expi ( cert ) >= trustbits ) return 0 ; return BPSW_psp ( cert ) ; } if ( typ ( cert ) != t_VEC || lgcert <= 1 ) return 0 ; ql = gel ( cert , lgcert - 1 ) ; if ( lg ( ql ) - 1 != 5 ) return 0 ; ql = cert_get_q ( ql ) ; if ( expi ( ql ) >= trustbits || ! BPSW_psp ( ql ) ) return 0 ; for ( i = 1 ; i < lgcert ; i ++ ) { GEN N , W , mP , sP , r , m , s , a , P , certi = gel ( cert , i ) ; if ( lg ( certi ) - 1 != 5 ) return 0 ; N = cert_get_N ( certi ) ; if ( typ ( N ) != t_INT || signe ( N ) <= 0 ) return 0 ; switch ( umodiu ( N , 6 ) ) { case 1 : case 5 : break ; default : return 0 ; } if ( i > 1 && ! equalii ( N , q ) ) return 0 ; W = cert_get_t ( certi ) ; if ( typ ( W ) != t_INT ) return 0 ; if ( ! ( cmpii ( sqri ( W ) , shifti ( N , 2 ) ) < 0 ) ) return 0 ; s = cert_get_s ( certi ) ; if ( typ ( s ) != t_INT || signe ( s ) < 0 ) return 0 ; m = cert_get_m ( certi ) ; q = dvmdii ( m , s , & r ) ; if ( ! isintzero ( r ) ) return 0 ; if ( ! Nq_isvalid ( N , q ) ) return 0 ; a = cert_get_a4 ( certi ) ; if ( typ ( a ) != t_INT ) return 0 ; P = cert_get_P ( certi ) ; if ( typ ( P ) != t_VEC || lg ( P ) != 3 ) return 0 ; P = FpE_to_FpJ ( P ) ; mP = FpJ_mul ( P , m , a , N ) ; if ( ! FpJ_is_inf ( mP ) ) return 0 ; sP = FpJ_mul ( P , s , a , N ) ; if ( ! isint1 ( gcdii ( gel ( sP , 3 ) , N ) ) ) return 0 ; } return 1 ; }
return 1 if 'cert' is a valid PARI ECPP certificate
return 1 if ' cert ' is a valid PARI ECPP certificate
/* a pseudoprime < 2^trustbits is prime */ /* >= 2^trustbits */ /* Check if N is not divisible by 2 or 3 */ /* Check if N matches the q from the previous entry. */ /* Check if W^2 < 4N (Hasse interval) */ /* Check m%s == 0 */ /* Check q > (N^(1/4) + 1)^2 */ /* Check mP == 0 */ /* Check sP != 0 and third component is coprime to N */