Beispiel #1
0
static NORX_INLINE void norx_encrypt_lastblock(norx_state_t state, uint8_t *out, const uint8_t * in, size_t inlen)
{
    uint8_t lastblock[BYTES(RATE)];
    norx_pad(lastblock, in, inlen);
    norx_encrypt_block(state, lastblock, lastblock);
    memcpy(out, lastblock, inlen);
}
Beispiel #2
0
void norx_encrypt_msg(norx_state_t state, unsigned char *out, const unsigned char * in, size_t inlen)
{
    if(inlen > 0)
    {
        norx_state_t lane[NORX_D];
        uint8_t emptyblock[BYTES(RATE)];
        size_t i, j;

        /* Initialize states + branch */
        for(i = 0; i < NORX_D; ++i)
        {
            memcpy(lane[i], state, sizeof lane[i]);
            norx_branch(lane[i], i);
        }

        /* parallel payload processing */
        for(i = 0; inlen >= BYTES(RATE); ++i)
        {
            norx_encrypt_block(lane[i%NORX_D], out, in);
            inlen -= BYTES(RATE);
            out   += BYTES(RATE);
            in    += BYTES(RATE);
        }
        norx_encrypt_lastblock(lane[i++%NORX_D], out, in, inlen);

        /* Pad remaining blocks */
        norx_pad(emptyblock, emptyblock, 0);
        for(j = 0; j < (NORX_D-1); ++j, ++i)
        {
            norx_absorb(lane[i%NORX_D], emptyblock, PAYLOAD_TAG);
        }

        /* Merge */
        memset(state, 0, sizeof(norx_state_t));
        for(i = 0; i < NORX_D; ++i)
        {
#if defined(NORX_DEBUG)
            printf("End of payload processing (lane %lu) \n", i);
            norx_print_state(lane[i]);
#endif
            norx_merge(state, lane[i]);
            burn(lane[i], 0, sizeof(norx_state_t));
        }

#if defined(NORX_DEBUG)
        printf("End of merging:\n");
        norx_print_state(state);
#endif
    }
}
Beispiel #3
0
void norx_process_trailer(norx_state_t state, const unsigned char * in, size_t inlen)
{
    if(inlen > 0)
    {
        uint8_t lastblock[BYTES(RATE)];

        while (inlen >= BYTES(RATE))
        {
            norx_absorb(state, in, TRAILER_TAG);
            inlen -= BYTES(RATE);
            in    += BYTES(RATE);
        }

        norx_pad(lastblock, in, inlen);
        norx_absorb(state, lastblock, TRAILER_TAG);
    }
}
Beispiel #4
0
void norx_decrypt_msg(norx_state_t state, unsigned char *out, const unsigned char * in, size_t inlen)
{
    if(inlen > 0)
    {
        uint8_t emptyblock[BYTES(RATE)];
        norx_state_t sum;
        norx_state_t state2;
        size_t lane = 0;

        norx_pad(emptyblock, emptyblock, 0);
        memset(sum, 0, sizeof(norx_state_t));

        while (inlen >= BYTES(RATE))
        {
            /* branch */
            memcpy(state2, state, sizeof(norx_state_t));
            norx_branch(state2, lane++);
            /* decrypt */
            norx_decrypt_block(state2, out, in);
            /* empty padding */
            norx_absorb(state2, emptyblock, PAYLOAD_TAG);
            /* merge */
            norx_merge(sum, state2);

            inlen -= BYTES(RATE);
            in    += BYTES(RATE);
            out   += BYTES(RATE);
        }
        /* last block, 0 < inlen < BYTES(RATE) */
        if(inlen > 0)
        {
            /* branch */
            memcpy(state2, state, sizeof(norx_state_t));
            norx_branch(state2, lane++);
            /* decrypt */
            norx_decrypt_lastblock(state2, out, in, inlen);
            /* merge */
            norx_merge(sum, state2);
        }
        memcpy(state, sum, sizeof(norx_state_t));
    }
}
Beispiel #5
0
static NORX_INLINE void norx_absorb_lastblock(norx_state_t state, const uint8_t * in, size_t inlen, tag_t tag)
{
    uint8_t lastblock[BYTES(NORX_R)];
    norx_pad(lastblock, in, inlen);
    norx_absorb_block(state, lastblock, tag);
}