コード例 #1
0
ファイル: norx.c プロジェクト: 0x64616E69656C/supercop
void norx_decrypt_data(norx_state_t state, unsigned char *out, const unsigned char * in, size_t inlen)
{
    if (inlen > 0)
    {
        size_t lane = 0;
        norx_state_t sum;
        norx_state_t state2;

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

        while (inlen >= BYTES(NORX_R))
        {
            /* branch */
            memcpy(state2, state, sizeof(norx_state_t));
            norx_branch(state2, lane++);
            /* decrypt */
            norx_decrypt_block(state2, out, in);

            #if defined(NORX_DEBUG)
            printf("Decrypt block (lane: %lu)\n", lane - 1);
            norx_debug(state2, in, BYTES(NORX_R), out, BYTES(NORX_R));
            #endif

            /* merge */
            norx_merge(sum, state2);

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

        /* last block, 0 <= inlen < BYTES(NORX_R) */

        /* branch */
        memcpy(state2, state, sizeof(norx_state_t));
        norx_branch(state2, lane++);

        /* decrypt */
        norx_decrypt_lastblock(state2, out, in, inlen);

        #if defined(NORX_DEBUG)
        printf("Decrypt lastblock (lane: %lu)\n", lane - 1);
        norx_debug(state2, in, inlen, out, inlen);
        #endif

        /* merge */
        norx_merge(sum, state2);

        memcpy(state, sum, sizeof(norx_state_t));
        burn(state2, 0, sizeof(norx_state_t));
        burn(sum, 0, sizeof(norx_state_t));

        #if defined(NORX_DEBUG)
        printf("Decryption finalised\n");
        norx_debug(state, NULL, 0, NULL, 0);
        #endif
    }
}
コード例 #2
0
ファイル: norx3261v1_norx.cpp プロジェクト: Vieteg/EACirc
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));
    }
}
コード例 #3
0
ファイル: norx3261v1_norx.cpp プロジェクト: Vieteg/EACirc
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
    }
}
コード例 #4
0
ファイル: norx.c プロジェクト: 0x64616E69656C/supercop
void norx_decrypt_data(norx_state_t state, unsigned char *out, const unsigned char * in, size_t inlen)
{
    if (inlen > 0)
    {
        size_t i;
        norx_state_t lane[NORX_P];

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

        /* Parallel payload processing */
        for (i = 0; inlen >= BYTES(NORX_R); ++i) {
            norx_decrypt_block(lane[i%NORX_P], out, in);
            #if defined(NORX_DEBUG)
            printf("Decrypt block (lane: %lu)\n", i%NORX_P);
            norx_debug(lane[i%NORX_P], in, BYTES(NORX_R), out, BYTES(NORX_R));
            #endif
            inlen -= BYTES(NORX_R);
            out   += BYTES(NORX_R);
            in    += BYTES(NORX_R);
        }
        norx_decrypt_lastblock(lane[i%NORX_P], out, in, inlen);
        #if defined(NORX_DEBUG)
        printf("Decrypt lastblock (lane: %lu)\n", i%NORX_P);
        norx_debug(lane[i%NORX_P], in, inlen, out, inlen);
        #endif

        /* Merge */
        memset(state, 0, sizeof(norx_state_t));
        for (i = 0; i < NORX_P; ++i) {
            norx_merge(state, lane[i]);
            burn(lane[i], 0, sizeof(norx_state_t));
        }

        #if defined(NORX_DEBUG)
        printf("Decryption finalised\n");
        norx_debug(state, NULL, 0, NULL, 0);
        #endif
    }
}