Beispiel #1
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 #2
0
void norx_init(norx_state_t state, const unsigned char *k, const unsigned char *n)
{
    norx_setup(state, k, n);
#if defined(NORX_DEBUG)
    printf("Basic setup:\n");
    norx_print_state(state);
#endif
    norx_inject_params(state);
}
Beispiel #3
0
static NORX_INLINE void norx_finalize(norx_state_t state)
{
    norx_inject_tag(state, FINAL_TAG);
    norx_permutation(state);
    norx_permutation(state);
#if defined(NORX_DEBUG) && NORX_D == 1
    printf("End of payload processing\n");
    norx_print_state(state);
#endif
}
Beispiel #4
0
    /* Undo padding */
    S[inlen / BYTES(NORX_W)] ^= 0x01ULL << ((inlen % BYTES(NORX_W)) * 8);
    S[WORDS(RATE) - 1]  ^= 0x80ULL << (((BYTES(RATE) - 1) % BYTES(NORX_W)) * 8);

    for(i = 0; inlen >= BYTES(NORX_W); ++i)
    {
        norx_word_t c = LOAD(in);
        STORE(out, S[i] ^ c);
        S[i] = c;

        inlen -= BYTES(NORX_W);
        in    += BYTES(NORX_W);
        out   += BYTES(NORX_W);
    }

    STORE(b, S[i]);
    for(j = 0; j < inlen; ++j)
    {
        uint8_t c = in[j];
        out[j] = b[j] ^ c;
        b[j]   = c;
    }
    S[i] = LOAD(b);
}

#if NORX_D != 1 /* only required in parallel modes */
static NORX_INLINE void norx_branch(norx_state_t state, uint64_t lane)
{
    norx_inject_tag(state, BRANCH_TAG);
    norx_permutation(state);
#if defined(NORX_DEBUG)
    if (lane == 0)
    {
      printf("End of header processing:\n");
      norx_print_state(state);
    }
#endif
    norx_inject_lane(state, lane);
}
Beispiel #5
0
static void norx_debug(norx_state_t state, const uint8_t *in, size_t inlen, const uint8_t *out, size_t outlen)
{
    if (in != NULL && inlen > 0) {
        printf("In:\n");
        print_bytes(in, inlen);
    }
    if (out != NULL && outlen > 0) {
        printf("Out:\n");
        print_bytes(out, outlen);
    }
    printf("State:\n");
    norx_print_state(state);
}
Beispiel #6
0
static NORX_INLINE void norx_absorb(norx_state_t state, const uint8_t * in, tag_t tag)
{
    norx_word_t * S = state->S;
    size_t i;

    norx_inject_tag(state, tag);
    norx_permutation(state);
#if defined(NORX_DEBUG)
    if (tag == HEADER_TAG)
    {
      printf("End of initialisation:\n");
      norx_print_state(state);
    }
#endif

    for (i = 0; i < WORDS(RATE); ++i)
        S[i] ^= LOAD(in + i * BYTES(NORX_W));
}
Beispiel #7
0
static NORX_INLINE void norx_encrypt_block(norx_state_t state, uint8_t *out, const uint8_t * in)
{
    norx_word_t * S = state->S;
    size_t i;

    norx_inject_tag(state, PAYLOAD_TAG);
    norx_permutation(state);

#if defined(NORX_DEBUG) && NORX_D == 1
    printf("End of header processing \n");
    norx_print_state(state);
#endif

    for (i = 0; i < WORDS(RATE); ++i)
    {
        S[i] ^= LOAD(in + i * BYTES(NORX_W));
        STORE(out + i * BYTES(NORX_W), S[i]);
    }
}