예제 #1
0
파일: buffalo-enc.c 프로젝트: whble/trunk
static int encrypt_file(void)
{
	struct enc_param ep;
	ssize_t src_len;
	unsigned char *buf;
	uint32_t hdrlen;
	ssize_t totlen = 0;
	int err;
	int ret = -1;

	src_len = get_file_size(ifname);
	if (src_len < 0) {
		ERR("unable to get size of '%s'", ifname);
		goto out;
	}

	totlen = enc_compute_buf_len(product, version, src_len);
	hdrlen = enc_compute_header_len(product, version);

	buf = malloc(totlen);
	if (buf == NULL) {
		ERR("no memory for the buffer");
		goto out;
	}

	err = read_file_to_buf(ifname, &buf[hdrlen], src_len);
	if (err) {
		ERR("unable to read from file '%s'", ofname);
		goto free_buf;
	}

	memset(&ep, '\0', sizeof(ep));
	ep.key = (unsigned char *) crypt_key;
	ep.seed = seed;
	ep.longstate = longstate;
	ep.csum = buffalo_csum(src_len, &buf[hdrlen], src_len);
	ep.datalen = src_len;
	strcpy((char *) ep.magic, magic);
	strcpy((char *) ep.product, product);
	strcpy((char *) ep.version, version);

	err = encrypt_buf(&ep, buf, &buf[hdrlen]);
	if (err) {
		ERR("invalid input file");
		goto free_buf;
	}

	err = write_buf_to_file(ofname, buf, totlen);
	if (err) {
		ERR("unable to write to file '%s'", ofname);
		goto free_buf;
	}

	ret = 0;

free_buf:
 	free(buf);
out:
 	return ret;
}
예제 #2
0
int sceDrmBBMacUpdate(MAC_KEY *mkey, u8 *buf, int size)
{
	int retv = 0, ksize, p, type;
	u8 *kbuf;

	if (mkey->pad_size > 16) {
		retv = 0x80510302;
		goto _exit;
	}

	if (mkey->pad_size + size <= 16) {
		memcpy(mkey->pad + mkey->pad_size, buf, size);
		mkey->pad_size += size;
		retv = 0;
	} else {
		kbuf = kirk_buf + 0x14;
		memcpy(kbuf, mkey->pad, mkey->pad_size);

		p = mkey->pad_size;

		mkey->pad_size += size;
		mkey->pad_size &= 0x0f;
		if (mkey->pad_size == 0)
			mkey->pad_size = 16;

		size -= mkey->pad_size;
		memcpy(mkey->pad, buf + size, mkey->pad_size);

		type = (mkey->type == 2) ? 0x3A : 0x38;

		while (size)
		{
			ksize = (size + p >= 0x0800) ? 0x0800 : size + p;
			memcpy(kbuf + p, buf, ksize - p);
			retv = encrypt_buf(kirk_buf, ksize, mkey->key, type);
			
			if (retv)
				goto _exit;
			
			size -= (ksize - p);
			buf += ksize - p;
			p = 0;
		}
	}

_exit:
	return retv;

}
예제 #3
0
int send_encrypt(struct encryption_ctx *ctx, int sock, unsigned char *buf, size_t *len, int flags) {
    unsigned char mybuf[4096];
    memcpy(mybuf, buf, *len);
    encrypt_buf(ctx, mybuf, len);
    return send(sock, mybuf, *len, flags);
}