Ejemplo n.º 1
0
static
void step(rabbit_ctx_t* ctx){
	uint32_t g[8];
	uint8_t i=0;
	update_c(ctx);
	gen_g(g, ctx);
	memcpy(ctx->x, g, 8*4);
	do{
		ctx->x[i] += ROT16(g[(i+8-1)%8]) + ROT16(g[(i+8-2)%8]);
		++i;
		ctx->x[i] += ROT8(g[(i+8-1)%8]) + g[(i+8-2)%8];
	}while(++i<8);
}
Ejemplo n.º 2
0
int seal(seal_ctx *key, unsigned long in, unsigned long *out)
{
    int i, j, l;         
    unsigned long a, b, c, d, n1, n2, n3, n4, *wp;
    unsigned short p, q;

    wp = out;
    for (l = 0; l < 4; l++) {
        a = in ^ key->r[4*l];
        b = ROT8(in) ^ key->r[4*l+1];
        c = ROT16(in) ^ key->r[4*l+2];
        d = ROT24(in) ^ key->r[4*l+3];
    }

    for (j = 0; j < 2; j++) {
        p = a & 0x7fc;
        b += key->t[p/4];
        a = ROT9(a);
         
        p = b & 0x7fc;
        c += key->t[p/4];
        b = ROT9(b);
         
        p = c & 0x7fc;
        d += key->t[p/4];
        c = ROT9(c);
         
        p = d & 0x7fc;
        a += key->t[p/4];
        d = ROT9(d);
         
        n1 = d; n2 = b; n3 = a; n4 = c;
         
        p = a & 0x7fc;
        b += key->t[p/4];
        a = ROT9(a);
         
        p = b & 0x7fc;
        c += key->t[p/4];
        b = ROT9(b);
         
        p = c & 0x7fc;
        d += key->t[p/4];
        c = ROT9(c);
         
        p = d & 0x7fc;
        a += key->t[p/4];
        d = ROT9(d);
         
        /* This generates 64 32-bit words, or 256 bytes of keystream. */
        for (i = 0; i < 64; i++) {
            p = a & 0x7fc;
	    b += key->t[p/4];
            a = ROT9(a);
            b ^= a;
         
            q = b & 0x7fc;
            c ^= key->t[q/4];
            b = ROT9(b);
            c += b;
         
            p = (p+c) & 0x7fc;
            d += key->t[p/4];
            c = ROT9(c);
            d ^= c;
         
            q = (q+d) & 0x7fc;
            a ^= key->t[q/4];
            d = ROT9(d);
            a += d;
         
            p = (p+a) & 0x7fc;
            b ^= key->t[p/4];
            a = ROT9(a);
         
            q = (q+b) & 0x7fc;
            c += key->t[q/4];
            b = ROT9(b);
         
            p = (p+c) & 0x7fc;
            d ^= key->t[p/4];
            c = ROT9(c);
         
            q = (q+d) & 0x7fc;
            a += key->t[q/4];
            d = ROT9(d);

            *wp = b + key->s[4*i]; wp++;
            *wp = c ^ key->s[4*i+1]; wp++;
            *wp = d + key->s[4*i+2]; wp++;
            *wp = a ^ key->s[4*i+3]; wp++;

            if (i & 1) {
                a += n3;
                c += n4;
            } else {
                a += n1;
                c += n2;
            }
        }
    }    

    return (ALG_OK);
}