Пример #1
0
static bool update(RCrypto *cry, const ut8 *buf, int len) {
	ut8 *obuf = calloc (1, len);
	if (!obuf) {
		return false;
	}
	xor_crypt (&st, buf, obuf, len);
	r_crypto_append (cry, obuf, len);
	free (obuf);
	return true;
}
Пример #2
0
static int update(RCrypto *cry, const ut8 *buf, int len) {
	if (flag) {
		eprintf ("Use ROR\n");
		return false;
	}
	ut8 *obuf = calloc (1, len);
	if (!obuf) return false;
	rol_crypt (&st, buf, obuf, len);
	r_crypto_append (cry, obuf, len);
	free (obuf);
	return 0;
}
Пример #3
0
static int update(RCrypto *cry, const ut8 *buf, int len) {
	if (!iv_set) {
		eprintf ("IV not set. Use -I [iv]\n");
		return false;
	}
	const int diff = (BLOCK_SIZE - (len % BLOCK_SIZE)) % BLOCK_SIZE;
	const int size = len + diff;
	const int blocks = size / BLOCK_SIZE;

	ut8 *const obuf = calloc (1, size);
	if (!obuf) return false;

	ut8 *const ibuf = calloc (1, size);
	if (!ibuf) {
		free (obuf);
		return false;
	}

	memset (ibuf, 0, size);
	memcpy (ibuf, buf, len);

	if (diff) {
		ibuf[len] = 0b1000;
	}

	int i, j;
	if (flag == 0) {
		for (i = 0; i < blocks; i++) {
			for (j = 0; j < BLOCK_SIZE; j++) {
				ibuf[i * BLOCK_SIZE + j] ^= iv[j];
			}
			aes_encrypt (&st, ibuf + BLOCK_SIZE * i, obuf + BLOCK_SIZE * i);
			memcpy (iv, obuf + BLOCK_SIZE * i, BLOCK_SIZE);
		}
	} else if (flag == 1) {
		for (i = 0; i < blocks; i++) {
			aes_decrypt (&st, ibuf + BLOCK_SIZE * i, obuf + BLOCK_SIZE * i);
			for (j = 0; j < BLOCK_SIZE; j++) {
				obuf[i * BLOCK_SIZE + j] ^= iv[j];
			}
			memcpy(iv, buf + BLOCK_SIZE * i, BLOCK_SIZE);
		}
	}

	r_crypto_append (cry, obuf, size);
	free (obuf);
	free (ibuf);
	return 0;
}
Пример #4
0
static int update(RCrypto *cry, const ut8 *buf, int len, bool to_encode) {
	int olen;
	ut8 *obuf;
	if (to_encode) {
		olen = ((len + 2) / 3 ) * 4;
		obuf = malloc (olen + 1);
		r_base64_encode (obuf, buf, len);
	} else {
		olen = (len / 4) * 3;
		if (len > 0)					//to prevent invalid access of memory
			olen -= (buf[len-1] == '=') ? ((buf[len-2] == '=') ? 2 : 1) : 0;
		obuf = malloc (olen + 1);
		olen = r_base64_decode (obuf, buf, len);
	}
	r_crypto_append (cry, obuf, olen);
	free (obuf);
	return 0;
}
Пример #5
0
static bool update (RCrypto *cry, const ut8 *buf, int len) {
	// Pad to the block size, do not append dummy block
	const int diff = (BLOCK_SIZE - (len % BLOCK_SIZE)) % BLOCK_SIZE;
	const int size = len + diff;
	const int blocks = size / BLOCK_SIZE;
	int i;

	ut8 *const obuf = calloc (1, size);
	if (!obuf) {
		return false;
	}
	ut8 *const ibuf = calloc (1, size);
	if (!ibuf) {
		free (obuf);
		return false;
	}

	memset (ibuf, 0, size);
	memcpy (ibuf, buf, len);
	// Padding should start like 100000...
	if (diff) {
		ibuf[len] = 8; //0b1000;
	}

	if (cry->dir == 0) {
		for (i = 0; i < blocks; i++) {
			const int delta = BLOCK_SIZE * i;
			aes_encrypt (&st, ibuf + delta, obuf + delta);
		}
	} else if (cry->dir > 0) {
		for (i = 0; i < blocks; i++) {
			const int delta = BLOCK_SIZE * i;
			aes_decrypt (&st, ibuf + delta, obuf + delta);
		}
	}

	// printf("%128s\n", obuf);

	r_crypto_append (cry, obuf, size);
	free (obuf);
	free (ibuf);
	return true;
}
Пример #6
0
static int update (RCrypto *cry, const ut8 *buf, int len) {
	// Pad to the block size, do not append dummy block
	const int diff = (BLOCK_SIZE - (len % BLOCK_SIZE)) % BLOCK_SIZE;
	const int size = len + diff;
	const int blocks = size / st.key_size;

	ut8 *const obuf = calloc (1, size);
	if (!obuf) return false;

	ut8 *const ibuf = calloc (1, size);
	if (!ibuf) {
		free (obuf);
		return false;
	}

	memset(ibuf, 0, size);
	memcpy (ibuf, buf, len);
	// Padding should start like 100000...
	if (diff) {
		ibuf[len] = 0b1000;
	}

	// printf("*** State:\n
	//         Key: %s\n
	//         key_size: %d\n
	//         columns: %d\n
	//         rounds: %d\n", st.key, st.key_size, st.columns, st.rounds);
	int i;
	for (i = 0; i < blocks; i++) {
		// printf("Block: %d\n", i);
		aes_encrypt (&st, ibuf + BLOCK_SIZE * i, obuf + BLOCK_SIZE * i);
		// printf("Block finished: %d\n", i);
	}

	// printf("%128s\n", obuf);

	r_crypto_append (cry, obuf, size);
	free (obuf);
	free (ibuf);
	return 0;
}