FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/ge_448.c
/* Convert compressed point to negative of affine point.
 * Calculates x from the y and the negative bit.
 * Not constant time.
 *
 * r  [in]  Uncompressed point.
 * b  [in]  Array of bytes representing point.
 * returns 0 on success and -1 on failure.
 */
Convert compressed point to negative of affine point.
Calculates x from the y and the negative bit.
Not constant time.

r  [in]  Uncompressed point.
b  [in]  Array of bytes representing point.
returns 0 on success and -1 on failure.
Convert compressed point to negative of affine point . Calculates x from the y and the negative bit . Not constant time . r [ in ] Uncompressed point . b [ in ] Array of bytes representing point . returns 0 on success and - 1 on failure .
int ge448_from_bytes_negate_vartime(ge448_p2 *r, const uint8_t *b)
{
    int   ret = 0;
    ge448 u[GE448_WORDS];
    ge448 v[GE448_WORDS];
    ge448 u3[GE448_WORDS];
    ge448 vxx[GE448_WORDS];
    ge448 check[GE448_WORDS];
    fe448_from_bytes(r->Y, b);
    fe448_1(r->Z);
    fe448_sqr(u, r->Y);                
    fe448_mul39081(v, u);              
    fe448_sub(u, u, r->Z);             
    fe448_reduce(u);
    fe448_add(v, v, r->Z);             
    fe448_reduce(v);
    fe448_neg(v, v);                   
    fe448_sqr(r->X, v);                
    fe448_mul(r->X, r->X, v);          
    fe448_sqr(u3, u);                  
    fe448_mul(r->X, r->X, u3);         
    fe448_mul(u3, u3, u);              
    fe448_mul(r->X, r->X, u3);         
    fe448_pow_2_446_222_1(r->X, r->X); 
    fe448_mul(r->X, r->X, u3);         
    fe448_mul(r->X, r->X, v);          
    fe448_sqr(vxx, r->X);
    fe448_mul(vxx, vxx, v);
    fe448_sub(check, vxx, u);          
    fe448_reduce(check);
    if (fe448_isnonzero(check)) {
        ret = -1;
    }
    if (fe448_isnegative(r->X) == (b[56] >> 7)) {
        fe448_neg(r->X, r->X);
    }
    return ret;
}
int ge448_from_bytes_negate_vartime ( ge448_p2 * r , const uint8_t * b ) { int ret = 0 ; ge448 u [ GE448_WORDS ] ; ge448 v [ GE448_WORDS ] ; ge448 u3 [ GE448_WORDS ] ; ge448 vxx [ GE448_WORDS ] ; ge448 check [ GE448_WORDS ] ; fe448_from_bytes ( r -> Y , b ) ; fe448_1 ( r -> Z ) ; fe448_sqr ( u , r -> Y ) ; fe448_mul39081 ( v , u ) ; fe448_sub ( u , u , r -> Z ) ; fe448_reduce ( u ) ; fe448_add ( v , v , r -> Z ) ; fe448_reduce ( v ) ; fe448_neg ( v , v ) ; fe448_sqr ( r -> X , v ) ; fe448_mul ( r -> X , r -> X , v ) ; fe448_sqr ( u3 , u ) ; fe448_mul ( r -> X , r -> X , u3 ) ; fe448_mul ( u3 , u3 , u ) ; fe448_mul ( r -> X , r -> X , u3 ) ; fe448_pow_2_446_222_1 ( r -> X , r -> X ) ; fe448_mul ( r -> X , r -> X , u3 ) ; fe448_mul ( r -> X , r -> X , v ) ; fe448_sqr ( vxx , r -> X ) ; fe448_mul ( vxx , vxx , v ) ; fe448_sub ( check , vxx , u ) ; fe448_reduce ( check ) ; if ( fe448_isnonzero ( check ) ) { ret = -1 ; } if ( fe448_isnegative ( r -> X ) == ( b [ 56 ] >> 7 ) ) { fe448_neg ( r -> X , r -> X ) ; } return ret ; }
Convert compressed point to negative of affine point.
Convert compressed point to negative of affine point .
/* u = y^2                      */ /* v = 39081.y^2                */ /* u = y^2-1                    */ /* v = 39081.y^2-1              */ /* v = -39081.y^2-1 = d.y^2-1   */ /* x = v^2                      */ /* x = v^3                      */ /* x = u^2.v^3                  */ /* x = u^2.v^3                  */ /* u3 = u^3                     */ /* x = u^5.v^3                  */ /* x = (u^5.v^3)^((q-3)/4)      */ /* x = u^3(u^5.v^3)^((q-3)/4)   */ /* x = u^3.v(u^5.v^3)^((q-3)/4) */ /* check = v.x^2-u              */ /* Note; vx^2+u is NOT correct. */ /* Calculating negative of point in bytes - negate only if X is correct. */