openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libgcrypt/1.8.4-r0/libgcrypt-1.8.4/cipher/chacha20.c
static void chacha20_do_encrypt_stream(CHACHA20_context_t* ctx, byte* outbuf,
                                       const byte* inbuf, size_t length)
{
    unsigned int nburn, burn = 0;

    if (ctx->unused)
    {
        unsigned char* p = (void*)ctx->pad;
        size_t n;

        gcry_assert(ctx->unused < CHACHA20_BLOCK_SIZE);

        n = ctx->unused;
        if (n > length)
            n = length;
        buf_xor(outbuf, inbuf, p + CHACHA20_BLOCK_SIZE - ctx->unused, n);
        length -= n;
        outbuf += n;
        inbuf += n;
        ctx->unused -= n;
        if (!length)
            return;
        gcry_assert(!ctx->unused);
    }

    if (length >= CHACHA20_BLOCK_SIZE)
    {
        size_t nblocks = length / CHACHA20_BLOCK_SIZE;
        size_t bytes = nblocks * CHACHA20_BLOCK_SIZE;
        burn = ctx->blocks(ctx->input, inbuf, outbuf, bytes);
        length -= bytes;
        outbuf += bytes;
        inbuf += bytes;
    }

    if (length > 0)
    {
        nburn = chacha20_core(ctx->pad, ctx);
        burn = nburn > burn ? nburn : burn;

        buf_xor(outbuf, inbuf, ctx->pad, length);
        ctx->unused = CHACHA20_BLOCK_SIZE - length;
    }

    _gcry_burn_stack(burn);
}
/* Note: This function requires LENGTH > 0.  */
This function requires LENGTH > 0.
This function requires LENGTH > 0 .
static void chacha20_do_encrypt_stream(CHACHA20_context_t* ctx, byte* outbuf,
                                       const byte* inbuf, size_t length)
{
    unsigned int nburn, burn = 0;
    if (ctx->unused)
    {
        unsigned char* p = (void*)ctx->pad;
        size_t n;
        gcry_assert(ctx->unused < CHACHA20_BLOCK_SIZE);
        n = ctx->unused;
        if (n > length)
            n = length;
        buf_xor(outbuf, inbuf, p + CHACHA20_BLOCK_SIZE - ctx->unused, n);
        length -= n;
        outbuf += n;
        inbuf += n;
        ctx->unused -= n;
        if (!length)
            return;
        gcry_assert(!ctx->unused);
    }
    if (length >= CHACHA20_BLOCK_SIZE)
    {
        size_t nblocks = length / CHACHA20_BLOCK_SIZE;
        size_t bytes = nblocks * CHACHA20_BLOCK_SIZE;
        burn = ctx->blocks(ctx->input, inbuf, outbuf, bytes);
        length -= bytes;
        outbuf += bytes;
        inbuf += bytes;
    }
    if (length > 0)
    {
        nburn = chacha20_core(ctx->pad, ctx);
        burn = nburn > burn ? nburn : burn;
        buf_xor(outbuf, inbuf, ctx->pad, length);
        ctx->unused = CHACHA20_BLOCK_SIZE - length;
    }
    _gcry_burn_stack(burn);
}
static void chacha20_do_encrypt_stream ( CHACHA20_context_t * ctx , byte * outbuf , const byte * inbuf , size_t length ) { unsigned int nburn , burn = 0 ; if ( ctx -> unused ) { unsigned char * p = ( void * ) ctx -> pad ; size_t n ; gcry_assert ( ctx -> unused < CHACHA20_BLOCK_SIZE ) ; n = ctx -> unused ; if ( n > length ) n = length ; buf_xor ( outbuf , inbuf , p + CHACHA20_BLOCK_SIZE - ctx -> unused , n ) ; length -= n ; outbuf += n ; inbuf += n ; ctx -> unused -= n ; if ( ! length ) return ; gcry_assert ( ! ctx -> unused ) ; } if ( length >= CHACHA20_BLOCK_SIZE ) { size_t nblocks = length / CHACHA20_BLOCK_SIZE ; size_t bytes = nblocks * CHACHA20_BLOCK_SIZE ; burn = ctx -> blocks ( ctx -> input , inbuf , outbuf , bytes ) ; length -= bytes ; outbuf += bytes ; inbuf += bytes ; } if ( length > 0 ) { nburn = chacha20_core ( ctx -> pad , ctx ) ; burn = nburn > burn ? nburn : burn ; buf_xor ( outbuf , inbuf , ctx -> pad , length ) ; ctx -> unused = CHACHA20_BLOCK_SIZE - length ; } _gcry_burn_stack ( burn ) ; }
Note: This function requires LENGTH > 0.
Note : This function requires LENGTH > 0 .