/* * Find the group id associated with an (almost filled) group as generated by * pk_group_from_specified(), or return an error if unknown. */ static int pk_group_id_from_group( const ecp_group *grp, ecp_group_id *grp_id ) { int ret = 0; ecp_group ref; const ecp_group_id *id; ecp_group_init( &ref ); for( id = ecp_grp_id_list(); *id != POLARSSL_ECP_DP_NONE; id++ ) { /* Load the group associated to that id */ ecp_group_free( &ref ); MPI_CHK( ecp_use_known_dp( &ref, *id ) ); /* Compare to the group we were given, starting with easy tests */ if( grp->pbits == ref.pbits && grp->nbits == ref.nbits && mpi_cmp_mpi( &grp->P, &ref.P ) == 0 && mpi_cmp_mpi( &grp->A, &ref.A ) == 0 && mpi_cmp_mpi( &grp->B, &ref.B ) == 0 && mpi_cmp_mpi( &grp->N, &ref.N ) == 0 && mpi_cmp_mpi( &grp->G.X, &ref.G.X ) == 0 && mpi_cmp_mpi( &grp->G.Z, &ref.G.Z ) == 0 && /* For Y we may only know the parity bit, so compare only that */ mpi_get_bit( &grp->G.Y, 0 ) == mpi_get_bit( &ref.G.Y, 0 ) ) { break; } } cleanup: ecp_group_free( &ref ); *grp_id = *id; if( ret == 0 && *id == POLARSSL_ECP_DP_NONE ) ret = POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE; return( ret ); }
static int Bisodd(lua_State *L) { mpi *a=Bget(L,1); lua_pushboolean(L, mpi_get_bit(a,0)); return 1; }