Esempio n. 1
0
void rc6DecryptBlock(Rc6Context *context, const uint8_t *input, uint8_t *output)
{
    uint_t i;
    uint32_t t;
    uint32_t u;

    //Load the 4 working registers with the ciphertext
    uint32_t a = LOAD32LE(input + 0);
    uint32_t b = LOAD32LE(input + 4);
    uint32_t c = LOAD32LE(input + 8);
    uint32_t d = LOAD32LE(input + 12);

    //First, update C and A
    c -= context->s[2 * RC6_NB_ROUNDS + 3];
    a -= context->s[2 * RC6_NB_ROUNDS + 2];

    //Apply 20 rounds
    for(i = RC6_NB_ROUNDS; i > 0; i--)
    {
        t = d;
        d = c;
        c = b;
        b = a;
        a = t;

        u = (d * (2 * d + 1));
        u = ROL32(u, 5);

        t = (b * (2 * b + 1));
        t = ROL32(t, 5);

        c -= context->s[2 * i + 1];
        c = ROR32(c, t % 32) ^ u;

        a -= context->s[2 * i];
        a = ROR32(a, u % 32) ^ t;
    }

    //Update D and B
    d -= context->s[1];
    b -= context->s[0];

    //The resulting value is the plaintext
    STORE32LE(a, output + 0);
    STORE32LE(b, output + 4);
    STORE32LE(c, output + 8);
    STORE32LE(d, output + 12);
}
Esempio n. 2
0
void rc6EncryptBlock(Rc6Context *context, const uint8_t *input, uint8_t *output)
{
    uint_t i;
    uint32_t t;
    uint32_t u;

    //Load the 4 working registers with the plaintext
    uint32_t a = LOAD32LE(input + 0);
    uint32_t b = LOAD32LE(input + 4);
    uint32_t c = LOAD32LE(input + 8);
    uint32_t d = LOAD32LE(input + 12);

    //First, update B and D
    b += context->s[0];
    d += context->s[1];

    //Apply 20 rounds
    for(i = 1; i <= RC6_NB_ROUNDS; i++)
    {
        t = (b * (2 * b + 1));
        t = ROL32(t, 5);

        u = (d * (2 * d + 1));
        u = ROL32(u, 5);

        a ^= t;
        a = ROL32(a, u % 32) + context->s[2 * i];

        c ^= u;
        c = ROL32(c, t % 32) + context->s[2 * i + 1];

        t = a;
        a = b;
        b = c;
        c = d;
        d = t;
    }

    //Update A and C
    a += context->s[2 * RC6_NB_ROUNDS + 2];
    c += context->s[2 * RC6_NB_ROUNDS + 3];

    //The resulting value is the ciphertext
    STORE32LE(a, output + 0);
    STORE32LE(b, output + 4);
    STORE32LE(c, output + 8);
    STORE32LE(d, output + 12);
}
Esempio n. 3
0
File: 9p.c Progetto: strake/l9fb
size_t vsscan9p1 (uint8_t *msg, char fmt, void *p) {
	size_t l;
	switch (fmt) {
	case '0':
		*(uint8_t *)p = msg[0];
		return 1;
	case '1':
		LOAD16LE(*(uint16_t *)p, msg);
		return 2;
	case '2':
		LOAD32LE(*(uint32_t *)p, msg);
		return 4;
	case '3':
		LOAD64LE(*(uint64_t *)p, msg);
		return 8;
	case 'd':
		return loadDir (p, msg);
	case 'q':
		return loadQid (p, msg);
	case 's':
		LOAD16LE(l, msg);
		*(char **)p = xstrndup (msg + 2, l);
		return (2 + l);
	}
}
Esempio n. 4
0
static NOINLINE int Read32(tiff* p)
{
	int v;
	if (p->BigEndian)
		v = LOAD32BE(p->Ptr);
	else
		v = LOAD32LE(p->Ptr);
	p->Ptr += 4;
	return v;
}
Esempio n. 5
0
File: 9p.c Progetto: strake/l9fb
ssize_t write9pmsg (int fd, uint8_t *msg) {
	size_t size;
	
	LOAD32LE(size, msg);
	switch (msg[4] /* type */) {
	case RRead:
		if (write (fd, msg, 11) < 11) return (-1);
		return 11;
	case TWrite:
		if (write (fd, msg, 23) < 23) return (-1);
		return 23;
	default:
		if (write (fd, msg, size) < size) return (-1);
		return size;
	}
}
Esempio n. 6
0
File: 9p.c Progetto: strake/l9fb
ssize_t read9pmsg (int fd, uint8_t *msg, size_t n) {
	ssize_t m, size;
	
	if (n < 7) return (-1);
	m = read (fd, msg, 7);
	if (m == 0) return 0;
	if (m <  0) return (-1);
	LOAD32LE(size, msg);
	if (size < 7) return (-1);
	switch (msg[4] /* type */) {
	// Special case for TWrite and RRead, lest we copy huge data
	case RRead:
		if (n < 11 || read (fd, msg + 7, 4) < 4) return (-1);
		return 11;
	case TWrite:
		if (n < 24 || read (fd, msg + 7, 16) < 16) return (-1);
		return 23;
	default:
		if (n < size) return (-1);
		if (read (fd, msg + 7, size - 7) + 7 < size) return (-1);
		return size;
	}
}
Esempio n. 7
0
File: 9p.c Progetto: strake/l9fb
size_t loadQid (Qid *p_qid, uint8_t *msg) {
	p_qid -> type = msg[0];
	LOAD32LE(p_qid -> vers, msg + 1);
	LOAD64LE(p_qid -> path, msg + 5);
	return 13;
}