FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/wolfmath.c
/* Conditionally copy a into b. Performed in constant time.
 *
 * a     MP integer to copy.
 * copy  On 1, copy a into b. on 0 leave b unchanged.
 * b     MP integer to copy into.
 * returns BAD_FUNC_ARG when a or b is NULL, MEMORY_E when growing b fails and
 *         MP_OKAY otherwise.
 */
Conditionally copy a into b. Performed in constant time.
a     MP integer to copy.
copy  On 1, copy a into b. on 0 leave b unchanged.
b     MP integer to copy into.
returns BAD_FUNC_ARG when a or b is NULL, MEMORY_E when growing b fails and
MP_OKAY otherwise.
Conditionally copy a into b . Performed in constant time . a MP integer to copy . copy On 1 copy a into b . on 0 leave b unchanged . b MP integer to copy into . returns BAD_FUNC_ARG when a or b is NULL MEMORY_E when growing b fails and MP_OKAY otherwise .
int mp_cond_copy(mp_int* a, int copy, mp_int* b)
{
    int err = MP_OKAY;
    int i;
    mp_digit mask = (mp_digit)0 - copy;
    if (a == NULL || b == NULL)
        err = BAD_FUNC_ARG;
    if (err == MP_OKAY)
        err = mp_grow(b, a->used + 1);
    if (err == MP_OKAY) {
        for (i = 0; i < a->used; i++) {
            b->dp[i] ^= (get_digit(a, i) ^ get_digit(b, i)) & mask;
        }
        for (; i < b->used; i++) {
            b->dp[i] ^= (get_digit(a, i) ^ get_digit(b, i)) & mask;
        }
        b->used ^= (a->used ^ b->used) & (int)mask;
    }
    return err;
}
int mp_cond_copy ( mp_int * a , int copy , mp_int * b ) { int err = MP_OKAY ; int i ; mp_digit mask = ( mp_digit ) 0 - copy ; if ( a == NULL || b == NULL ) err = BAD_FUNC_ARG ; if ( err == MP_OKAY ) err = mp_grow ( b , a -> used + 1 ) ; if ( err == MP_OKAY ) { for ( i = 0 ; i < a -> used ; i ++ ) { b -> dp [ i ] ^= ( get_digit ( a , i ) ^ get_digit ( b , i ) ) & mask ; } for ( ; i < b -> used ; i ++ ) { b -> dp [ i ] ^= ( get_digit ( a , i ) ^ get_digit ( b , i ) ) & mask ; } b -> used ^= ( a -> used ^ b -> used ) & ( int ) mask ; } return err ; }
Conditionally copy a into b.
Conditionally copy a into b .
/* Ensure b has enough space to copy a into */ /* When mask 0, b is unchanged2
         * When mask all set, b ^ b ^ a = a
         */ /* Conditionaly copy all digits and then number of used diigits.
         * get_digit() returns 0 when index greater than available digit.
         */