All pastes #445092 Raw Edit

Something

public text v1 · immutable
·published 2007-04-17 18:16 UTC
rendered paste body
static inline translate_bytes(void *target, const void *source,
                                unsigned int len, const void *table)
{
      asm ("tr %0,%1,%2,%3"
            : "=Q" (*target)
            : "Q" (*source), "m" (*table), "r" (len)
}

void aes_encrypt_256(u128 *context, u128 *key)
{
        u128 t[2] cachealigned;
        u64 x[10] cachealigned;
        unsigned int i;

        for (i = 0; i < 13; i++) {
                /* do sbox and multiply */
                translate_bytes(&t[0], context, 16, aes_sbox);
                translate_bytes(&t[1], context, 16, aes_sbox2);
                /* do shift and add */
                translate_bytes(x, aes_perm, 80, t);
                context->u64[0] = x[0] ^ x[1] ^ x[2] ^ x[3] ^ x[4] ^ key[i].u64[0];
                context->u64[1] = x[5] ^ x[6] ^ x[7] ^ x[8] ^ x[9] ^ key[i].u64[1];
        }

        /* final round is simpler */
        translate_bytes(&t[0], context, 16, aes_sbox);
        translate_bytes(x, aes_perm, 16, context);
        context->u64[0] ^= key[13].u64[0];
        context->u64[1] ^= key[13].u64[1];
}