FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/wc_dsp.c
/* Convert an mp_int to an array of sp_digit.
 *
 * r  A single precision integer.
 * size  Maximum number of bytes to convert
 * a  A multi-precision integer.
 */
Convert an mp_int to an array of sp_digit.
r  A single precision integer.
size  Maximum number of bytes to convert
a  A multi-precision integer.
Convert an mp_int to an array of sp_digit . r A single precision integer . size Maximum number of bytes to convert a A multi - precision integer .
static void int_256_from_mp(int32* r, int size, const mp_int* a)
{
#if DIGIT_BIT == 26
    int j;
    XMEMCPY(r, a->dp, sizeof(int32) * a->used);
    for (j = a->used; j < size; j++) {
        r[j] = 0;
    }
#elif DIGIT_BIT > 26
    int i, j = 0;
    word32 s = 0;
    r[0] = 0;
    for (i = 0; i < a->used && j < size; i++) {
        r[j] |= ((int32)a->dp[i] << s);
        r[j] &= 0x3ffffff;
        s = 26U - s;
        if (j + 1 >= size) {
            break;
        }
        r[++j] = (int32)(a->dp[i] >> s); 
        while ((s + 26U) <= (word32)DIGIT_BIT) {
            s += 26U;
            r[j] &= 0x3ffffff;
            if (j + 1 >= size) {
                break;
            }
            if (s < (word32)DIGIT_BIT) {
                r[++j] = (int32)(a->dp[i] >> s); 
            }
            else {
                r[++j] = 0L;
            }
        }
        s = (word32)DIGIT_BIT - s;
    }
    for (j++; j < size; j++) {
        r[j] = 0;
    }
#else
    int i, j = 0, s = 0;
    r[0] = 0;
    for (i = 0; i < a->used && j < size; i++) {
        r[j] |= ((int32)a->dp[i]) << s;
        if (s + DIGIT_BIT >= 26) {
            r[j] &= 0x3ffffff;
            if (j + 1 >= size) {
                break;
            }
            s = 26 - s;
            if (s == DIGIT_BIT) {
                r[++j] = 0;
                s = 0;
            }
            else {
                r[++j] = a->dp[i] >> s;
                s = DIGIT_BIT - s;
            }
        }
        else {
            s += DIGIT_BIT;
        }
    }
    for (j++; j < size; j++) {
        r[j] = 0;
    }
#endif
}
static void int_256_from_mp ( int32 * r , int size , const mp_int * a ) { #if DIGIT_BIT == 26 int j ; XMEMCPY ( r , a -> dp , sizeof ( int32 ) * a -> used ) ; for ( j = a -> used ; j < size ; j ++ ) { r [ j ] = 0 ; } #elif DIGIT_BIT > 26 int i , j = 0 ; word32 s = 0 ; r [ 0 ] = 0 ; for ( i = 0 ; i < a -> used && j < size ; i ++ ) { r [ j ] |= ( ( int32 ) a -> dp [ i ] << s ) ; r [ j ] &= 0x3ffffff ; s = 26U - s ; if ( j + 1 >= size ) { break ; } r [ ++ j ] = ( int32 ) ( a -> dp [ i ] >> s ) ; while ( ( s + 26U ) <= ( word32 ) DIGIT_BIT ) { s += 26U ; r [ j ] &= 0x3ffffff ; if ( j + 1 >= size ) { break ; } if ( s < ( word32 ) DIGIT_BIT ) { r [ ++ j ] = ( int32 ) ( a -> dp [ i ] >> s ) ; } else { r [ ++ j ] = 0L ; } } s = ( word32 ) DIGIT_BIT - s ; } for ( j ++ ; j < size ; j ++ ) { r [ j ] = 0 ; } #else int i , j = 0 , s = 0 ; r [ 0 ] = 0 ; for ( i = 0 ; i < a -> used && j < size ; i ++ ) { r [ j ] |= ( ( int32 ) a -> dp [ i ] ) << s ; if ( s + DIGIT_BIT >= 26 ) { r [ j ] &= 0x3ffffff ; if ( j + 1 >= size ) { break ; } s = 26 - s ; if ( s == DIGIT_BIT ) { r [ ++ j ] = 0 ; s = 0 ; } else { r [ ++ j ] = a -> dp [ i ] >> s ; s = DIGIT_BIT - s ; } } else { s += DIGIT_BIT ; } } for ( j ++ ; j < size ; j ++ ) { r [ j ] = 0 ; } #endif }
Convert an mp_int to an array of sp_digit.
Convert an mp_int to an array of sp_digit .
/* lint allow cast of mismatch word32 and mp_digit */ /*lint !e9033*/ /* lint allow cast of mismatch word32 and mp_digit */ /*lint !e9033*/