openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libxcrypt/4.4.6-r0/git/lib/alg-yescrypt-opt.c
static void smix1(uint8_t* B, size_t r, uint32_t N, yescrypt_flags_t flags,
                  salsa20_blk_t* V, uint32_t NROM, const salsa20_blk_t* VROM,
                  salsa20_blk_t* XY, pwxform_ctx_t* ctx)
{
    size_t s = 2 * r;
    salsa20_blk_t *X = V, *Y = &V[s];
    uint32_t i, j;

    for (i = 0; i < 2 * r; i++)
    {
        const salsa20_blk_t* src = (salsa20_blk_t*)&B[i * 64];
        salsa20_blk_t* tmp = Y;
        salsa20_blk_t* dst = &X[i];
        size_t k;
        for (k = 0; k < 16; k++)
            tmp->w[k] = le32dec(&src->w[k]);
        salsa20_simd_shuffle(tmp, dst);
    }

    if (VROM)
    {
        uint32_t n;
        const salsa20_blk_t* V_j;

        V_j = &VROM[(NROM - 1) * s];
        j = blockmix_xor(X, V_j, Y, r, 1, ctx) & (NROM - 1);
        V_j = &VROM[j * s];
        X = Y + s;
        j = blockmix_xor(Y, V_j, X, r, 1, ctx);

        for (n = 2; n < N; n <<= 1)
        {
            uint32_t m = (n < N / 2) ? n : (N - 1 - n);
            for (i = 1; i < m; i += 2)
            {
                j &= n - 1;
                j += i - 1;
                V_j = &V[j * s];
                Y = X + s;
                j = blockmix_xor(X, V_j, Y, r, 0, ctx) & (NROM - 1);
                V_j = &VROM[j * s];
                X = Y + s;
                j = blockmix_xor(Y, V_j, X, r, 1, ctx);
            }
        }
        n >>= 1;

        j &= n - 1;
        j += N - 2 - n;
        V_j = &V[j * s];
        Y = X + s;
        j = blockmix_xor(X, V_j, Y, r, 0, ctx) & (NROM - 1);
        V_j = &VROM[j * s];
        blockmix_xor(Y, V_j, XY, r, 1, ctx);
    }
    else if (flags & YESCRYPT_RW)
    {
        uint32_t n;
        salsa20_blk_t* V_j;

        blockmix(X, Y, r, ctx);
        X = Y + s;
        blockmix(Y, X, r, ctx);
        j = integerify(X, r);

        for (n = 2; n < N; n <<= 1)
        {
            uint32_t m = (n < N / 2) ? n : (N - 1 - n);
            for (i = 1; i < m; i += 2)
            {
                Y = X + s;
                j &= n - 1;
                j += i - 1;
                V_j = &V[j * s];
                j = blockmix_xor(X, V_j, Y, r, 0, ctx);
                j &= n - 1;
                j += i;
                V_j = &V[j * s];
                X = Y + s;
                j = blockmix_xor(Y, V_j, X, r, 0, ctx);
            }
        }
        n >>= 1;

        j &= n - 1;
        j += N - 2 - n;
        V_j = &V[j * s];
        Y = X + s;
        j = blockmix_xor(X, V_j, Y, r, 0, ctx);
        j &= n - 1;
        j += N - 1 - n;
        V_j = &V[j * s];
        blockmix_xor(Y, V_j, XY, r, 0, ctx);
    }
    else
    {
        N -= 2;
        do
        {
            blockmix_salsa8(X, Y, r);
            X = Y + s;
            blockmix_salsa8(Y, X, r);
            Y = X + s;
        } while ((N -= 2));

        blockmix_salsa8(X, Y, r);
        blockmix_salsa8(Y, XY, r);
    }

    for (i = 0; i < 2 * r; i++)
    {
        const salsa20_blk_t* src = &XY[i];
        salsa20_blk_t* tmp = &XY[s];
        salsa20_blk_t* dst = (salsa20_blk_t*)&B[i * 64];
        size_t k;
        for (k = 0; k < 16; k++)
            le32enc(&tmp->w[k], src->w[k]);
        salsa20_simd_unshuffle(tmp, dst);
    }
}
/**
 * smix1(B, r, N, flags, V, NROM, VROM, XY, ctx):
 * Compute first loop of B = SMix_r(B, N).  The input B must be 128r bytes in
 * length; the temporary storage V must be 128rN bytes in length; the temporary
 * storage XY must be 128r+64 bytes in length.  N must be even and at least 4.
 * The array V must be aligned to a multiple of 64 bytes, and arrays B and XY
 * to a multiple of at least 16 bytes.
 */
smix1(B, r, N, flags, V, NROM, VROM, XY, ctx):
Compute first loop of B = SMix_r(B, N).  The input B must be 128r bytes in
length; the temporary storage V must be 128rN bytes in length; the temporary
storage XY must be 128r+64 bytes in length.  N must be even and at least 4.
The array V must be aligned to a multiple of 64 bytes, and arrays B and XY
to a multiple of at least 16 bytes.
smix1 ( B r N flags V NROM VROM XY ctx ) : Compute first loop of B = SMix_r ( B N ) . The input B must be 128r bytes in length ; the temporary storage V must be 128rN bytes in length ; the temporary storage XY must be 128r + 64 bytes in length . N must be even and at least 4 . The array V must be aligned to a multiple of 64 bytes and arrays B and XY to a multiple of at least 16 bytes .
static void smix1(uint8_t* B, size_t r, uint32_t N, yescrypt_flags_t flags,
                  salsa20_blk_t* V, uint32_t NROM, const salsa20_blk_t* VROM,
                  salsa20_blk_t* XY, pwxform_ctx_t* ctx)
{
    size_t s = 2 * r;
    salsa20_blk_t *X = V, *Y = &V[s];
    uint32_t i, j;
    for (i = 0; i < 2 * r; i++)
    {
        const salsa20_blk_t* src = (salsa20_blk_t*)&B[i * 64];
        salsa20_blk_t* tmp = Y;
        salsa20_blk_t* dst = &X[i];
        size_t k;
        for (k = 0; k < 16; k++)
            tmp->w[k] = le32dec(&src->w[k]);
        salsa20_simd_shuffle(tmp, dst);
    }
    if (VROM)
    {
        uint32_t n;
        const salsa20_blk_t* V_j;
        V_j = &VROM[(NROM - 1) * s];
        j = blockmix_xor(X, V_j, Y, r, 1, ctx) & (NROM - 1);
        V_j = &VROM[j * s];
        X = Y + s;
        j = blockmix_xor(Y, V_j, X, r, 1, ctx);
        for (n = 2; n < N; n <<= 1)
        {
            uint32_t m = (n < N / 2) ? n : (N - 1 - n);
            for (i = 1; i < m; i += 2)
            {
                j &= n - 1;
                j += i - 1;
                V_j = &V[j * s];
                Y = X + s;
                j = blockmix_xor(X, V_j, Y, r, 0, ctx) & (NROM - 1);
                V_j = &VROM[j * s];
                X = Y + s;
                j = blockmix_xor(Y, V_j, X, r, 1, ctx);
            }
        }
        n >>= 1;
        j &= n - 1;
        j += N - 2 - n;
        V_j = &V[j * s];
        Y = X + s;
        j = blockmix_xor(X, V_j, Y, r, 0, ctx) & (NROM - 1);
        V_j = &VROM[j * s];
        blockmix_xor(Y, V_j, XY, r, 1, ctx);
    }
    else if (flags & YESCRYPT_RW)
    {
        uint32_t n;
        salsa20_blk_t* V_j;
        blockmix(X, Y, r, ctx);
        X = Y + s;
        blockmix(Y, X, r, ctx);
        j = integerify(X, r);
        for (n = 2; n < N; n <<= 1)
        {
            uint32_t m = (n < N / 2) ? n : (N - 1 - n);
            for (i = 1; i < m; i += 2)
            {
                Y = X + s;
                j &= n - 1;
                j += i - 1;
                V_j = &V[j * s];
                j = blockmix_xor(X, V_j, Y, r, 0, ctx);
                j &= n - 1;
                j += i;
                V_j = &V[j * s];
                X = Y + s;
                j = blockmix_xor(Y, V_j, X, r, 0, ctx);
            }
        }
        n >>= 1;
        j &= n - 1;
        j += N - 2 - n;
        V_j = &V[j * s];
        Y = X + s;
        j = blockmix_xor(X, V_j, Y, r, 0, ctx);
        j &= n - 1;
        j += N - 1 - n;
        V_j = &V[j * s];
        blockmix_xor(Y, V_j, XY, r, 0, ctx);
    }
    else
    {
        N -= 2;
        do
        {
            blockmix_salsa8(X, Y, r);
            X = Y + s;
            blockmix_salsa8(Y, X, r);
            Y = X + s;
        } while ((N -= 2));
        blockmix_salsa8(X, Y, r);
        blockmix_salsa8(Y, XY, r);
    }
    for (i = 0; i < 2 * r; i++)
    {
        const salsa20_blk_t* src = &XY[i];
        salsa20_blk_t* tmp = &XY[s];
        salsa20_blk_t* dst = (salsa20_blk_t*)&B[i * 64];
        size_t k;
        for (k = 0; k < 16; k++)
            le32enc(&tmp->w[k], src->w[k]);
        salsa20_simd_unshuffle(tmp, dst);
    }
}
static void smix1 ( uint8_t * B , size_t r , uint32_t N , yescrypt_flags_t flags , salsa20_blk_t * V , uint32_t NROM , const salsa20_blk_t * VROM , salsa20_blk_t * XY , pwxform_ctx_t * ctx ) { size_t s = 2 * r ; salsa20_blk_t * X = V , * Y = & V [ s ] ; uint32_t i , j ; for ( i = 0 ; i < 2 * r ; i ++ ) { const salsa20_blk_t * src = ( salsa20_blk_t * ) & B [ i * 64 ] ; salsa20_blk_t * tmp = Y ; salsa20_blk_t * dst = & X [ i ] ; size_t k ; for ( k = 0 ; k < 16 ; k ++ ) tmp -> w [ k ] = le32dec ( & src -> w [ k ] ) ; salsa20_simd_shuffle ( tmp , dst ) ; } if ( VROM ) { uint32_t n ; const salsa20_blk_t * V_j ; V_j = & VROM [ ( NROM - 1 ) * s ] ; j = blockmix_xor ( X , V_j , Y , r , 1 , ctx ) & ( NROM - 1 ) ; V_j = & VROM [ j * s ] ; X = Y + s ; j = blockmix_xor ( Y , V_j , X , r , 1 , ctx ) ; for ( n = 2 ; n < N ; n <<= 1 ) { uint32_t m = ( n < N / 2 ) ? n : ( N - 1 - n ) ; for ( i = 1 ; i < m ; i += 2 ) { j &= n - 1 ; j += i - 1 ; V_j = & V [ j * s ] ; Y = X + s ; j = blockmix_xor ( X , V_j , Y , r , 0 , ctx ) & ( NROM - 1 ) ; V_j = & VROM [ j * s ] ; X = Y + s ; j = blockmix_xor ( Y , V_j , X , r , 1 , ctx ) ; } } n >>= 1 ; j &= n - 1 ; j += N - 2 - n ; V_j = & V [ j * s ] ; Y = X + s ; j = blockmix_xor ( X , V_j , Y , r , 0 , ctx ) & ( NROM - 1 ) ; V_j = & VROM [ j * s ] ; blockmix_xor ( Y , V_j , XY , r , 1 , ctx ) ; } else if ( flags & YESCRYPT_RW ) { uint32_t n ; salsa20_blk_t * V_j ; blockmix ( X , Y , r , ctx ) ; X = Y + s ; blockmix ( Y , X , r , ctx ) ; j = integerify ( X , r ) ; for ( n = 2 ; n < N ; n <<= 1 ) { uint32_t m = ( n < N / 2 ) ? n : ( N - 1 - n ) ; for ( i = 1 ; i < m ; i += 2 ) { Y = X + s ; j &= n - 1 ; j += i - 1 ; V_j = & V [ j * s ] ; j = blockmix_xor ( X , V_j , Y , r , 0 , ctx ) ; j &= n - 1 ; j += i ; V_j = & V [ j * s ] ; X = Y + s ; j = blockmix_xor ( Y , V_j , X , r , 0 , ctx ) ; } } n >>= 1 ; j &= n - 1 ; j += N - 2 - n ; V_j = & V [ j * s ] ; Y = X + s ; j = blockmix_xor ( X , V_j , Y , r , 0 , ctx ) ; j &= n - 1 ; j += N - 1 - n ; V_j = & V [ j * s ] ; blockmix_xor ( Y , V_j , XY , r , 0 , ctx ) ; } else { N -= 2 ; do { blockmix_salsa8 ( X , Y , r ) ; X = Y + s ; blockmix_salsa8 ( Y , X , r ) ; Y = X + s ; } while ( ( N -= 2 ) ) ; blockmix_salsa8 ( X , Y , r ) ; blockmix_salsa8 ( Y , XY , r ) ; } for ( i = 0 ; i < 2 * r ; i ++ ) { const salsa20_blk_t * src = & XY [ i ] ; salsa20_blk_t * tmp = & XY [ s ] ; salsa20_blk_t * dst = ( salsa20_blk_t * ) & B [ i * 64 ] ; size_t k ; for ( k = 0 ; k < 16 ; k ++ ) le32enc ( & tmp -> w [ k ] , src -> w [ k ] ) ; salsa20_simd_unshuffle ( tmp , dst ) ; } }
smix1(B, r, N, flags, V, NROM, VROM, XY, ctx):
 Compute first loop of B = SMix_r(B, N).
smix1 ( B r N flags V NROM VROM XY ctx ) : Compute first loop of B = SMix_r ( B N ) .