From 2d101f80f8a893c6fce63bf1cb5225219e9d82c1 Mon Sep 17 00:00:00 2001
From: Alexander Sulfrian <alexander@sulfrian.net>
Date: Tue, 6 Mar 2012 23:21:19 +0100
Subject: games-util/wbfs_file: added patch to remove openssl deps

---
 games-util/wbfs_file/Manifest                |   3 +-
 games-util/wbfs_file/files/no-openssl.patch  | 169 +++++++++++++++++++++++++++
 games-util/wbfs_file/wbfs_file-2.9-r1.ebuild |  37 ------
 games-util/wbfs_file/wbfs_file-2.9-r2.ebuild |  38 ++++++
 4 files changed, 209 insertions(+), 38 deletions(-)
 create mode 100644 games-util/wbfs_file/files/no-openssl.patch
 delete mode 100644 games-util/wbfs_file/wbfs_file-2.9-r1.ebuild
 create mode 100644 games-util/wbfs_file/wbfs_file-2.9-r2.ebuild

diff --git a/games-util/wbfs_file/Manifest b/games-util/wbfs_file/Manifest
index 99feb55..7146d08 100644
--- a/games-util/wbfs_file/Manifest
+++ b/games-util/wbfs_file/Manifest
@@ -1,3 +1,4 @@
 AUX 64bit_fix.patch 1079 RMD160 90b6221cd765bb229e7b85dd4fab019872111d73 SHA1 5afb50176e10b2704afa4094b321bf6a90a7385c SHA256 e1eeaa04229447eefe44c71decf75a4d88c7423adee4248f06442cb9a9137d1c
+AUX no-openssl.patch 4011 RMD160 0c26944e6f19374dbd6f6e4412402d982f8aa704 SHA1 548163964592b2d21a944e658dd41aa419619f92 SHA256 48a1d37c8598633fe5b93538fe72aeeeee00a430c7ab0dbd8c70f70d998d9983
 DIST wbfs_file_2.9.zip 687419 RMD160 50aac97941e27917ac3ada763eb3b30b5924118e SHA1 e7b0c9ffe577cb920d3b43f2e7f0134d5e5556d9 SHA256 2a3973c907dc35398047dbf748863191514f4d2c64423449729c7d36f1b8b838
-EBUILD wbfs_file-2.9-r1.ebuild 723 RMD160 00af920a2e6c377ae3e5d10f0366b1fca56c00fc SHA1 edc4bbfe900104684ca78d4ac45ca723b80a5486 SHA256 718b621be1c7c6f9d7e2eae6f1aa90568b50c75046d30fdddd89a0d3eb6b199d
+EBUILD wbfs_file-2.9-r2.ebuild 758 RMD160 8d00c5a8bc636699b709c1d88d765f1c3b41f15f SHA1 4f57bf0f6bba8ba3b41f06a9940608661035d970 SHA256 8fcfab5f0b625f6211a5579fdebfdfe19680d17a0f9bd109c4ee5c99084c9e6e
diff --git a/games-util/wbfs_file/files/no-openssl.patch b/games-util/wbfs_file/files/no-openssl.patch
new file mode 100644
index 0000000..cecbb97
--- /dev/null
+++ b/games-util/wbfs_file/files/no-openssl.patch
@@ -0,0 +1,169 @@
+diff -r -u source/tools.c wbfs_file_2.9_no_openssl//source/tools.c
+--- source/tools.c	2010-01-12 13:52:20.000000000 +0100
++++ wbfs_file_2.9_no_openssl//source/tools.c	2012-03-06 23:14:55.000000000 +0100
+@@ -5,9 +5,6 @@
+ #include "tools.h"
+ 
+ #include <stddef.h>	// to accommodate certain broken versions of openssl
+-#include <openssl/md5.h>
+-#include <openssl/aes.h>
+-#include <openssl/sha.h>
+ #include <stdarg.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -61,16 +58,6 @@
+ // crypto
+ //
+ 
+-void md5(u8 *data, u32 len, u8 *hash)
+-{
+-	MD5(data, len, hash);
+-}
+-
+-void sha(u8 *data, u32 len, u8 *hash)
+-{
+-	SHA1(data, len, hash);
+-}
+-
+ void get_key(const char *name, u8 *key, u32 len)
+ {
+ 	char path[256];
+@@ -90,35 +77,6 @@
+ 	fclose(fp);
+ }
+ 
+-void aes_cbc_dec(u8 *key, u8 *iv, u8 *in, u32 len, u8 *out)
+-{
+-	AES_KEY aes_key;
+-
+-	AES_set_decrypt_key(key, 128, &aes_key);
+-	AES_cbc_encrypt(in, out, len, &aes_key, iv, AES_DECRYPT);
+-}
+-
+-void aes_cbc_enc(u8 *key, u8 *iv, u8 *in, u32 len, u8 *out)
+-{
+-	AES_KEY aes_key;
+-
+-	AES_set_encrypt_key(key, 128, &aes_key);
+-	AES_cbc_encrypt(in, out, len, &aes_key, iv, AES_ENCRYPT);
+-}
+-
+-void decrypt_title_key(u8 *tik, u8 *title_key)
+-{
+-	u8 common_key[16];
+-	u8 iv[16];
+-
+-	get_key("common-key", common_key, 16);
+-
+-	memset(iv, 0, sizeof iv);
+-	memcpy(iv, tik + 0x01dc, 8);
+-	aes_cbc_dec(common_key, iv, tik + 0x01bf, 16, title_key);
+-        printf("title key: %02x %02x %02x\n",title_key[0],title_key[1],title_key[2]);
+-}
+-
+ static u8 root_key[0x204];
+ static u8 *get_root_key(void)
+ {
+@@ -166,26 +124,6 @@
+ 	return 0;
+ }
+ 
+-int check_ec(u8 *ng, u8 *ap, u8 *sig, u8 *sig_hash)
+-{
+-	u8 ap_hash[20];
+-	u8 *ng_Q, *ap_R, *ap_S;
+-	u8 *ap_Q, *sig_R, *sig_S;
+-
+-	ng_Q = ng + 0x0108;
+-	ap_R = ap + 0x04;
+-	ap_S = ap + 0x22;
+-
+-	SHA1(ap + 0x80, 0x100, ap_hash);
+-
+-	ap_Q = ap + 0x0108;
+-	sig_R = sig;
+-	sig_S = sig + 30;
+-
+-	return check_ecdsa(ng_Q, ap_R, ap_S, ap_hash)
+-	       && check_ecdsa(ap_Q, sig_R, sig_S, sig_hash);
+-}
+-
+ static int check_rsa(u8 *h, u8 *sig, u8 *key, u32 n)
+ {
+ 	u8 correct[0x200];
+@@ -268,57 +206,6 @@
+ 	return 0;
+ }
+ 
+-int check_cert_chain(u8 *data, u32 data_len, u8 *cert, u32 cert_len)
+-{
+-	u8 *sig;
+-	u8 *sub;
+-	u32 sig_len;
+-	u32 sub_len;
+-	u8 h[20];
+-	u8 *key_cert;
+-	u8 *key;
+-	int ret;
+-	sig = data;
+-	sig_len = get_sig_len(sig);
+-	if (sig_len == 0)
+-		return -1;
+-	sub = data + sig_len;
+-	sub_len = data_len - sig_len;
+-	if (sub_len == 0)
+-		return -2;
+-
+-	for (;;) {
+-                printf(">>>>>> checking sig by %s...\n", sub);
+-                if (strcmp((char*)sub, "Root") == 0) {
+-			key = get_root_key();
+-			sha(sub, sub_len, h);
+-			if (be32(sig) != 0x10000)
+-				return -8;
+-			return check_rsa(h, sig + 4, key, 0x200);
+-		}
+-
+-		key_cert = find_cert_in_chain(sub, cert, cert_len);
+-		if (key_cert == 0)
+-			return -3;
+-
+-		key = key_cert + get_sig_len(key_cert);
+-
+-		sha(sub, sub_len, h);
+-		ret = check_hash(h, sig, key);
+-		if (ret)
+-			return ret;
+-
+-		sig = key_cert;
+-		sig_len = get_sig_len(sig);
+-		if (sig_len == 0)
+-			return -4;
+-		sub = sig + sig_len;
+-		sub_len = get_sub_len(sub);
+-		if (sub_len == 0)
+-			return -5;
+-	}
+-}
+-
+ //
+ // compression
+ //
+diff -r -u source/tools.h wbfs_file_2.9_no_openssl//source/tools.h
+--- source/tools.h	2009-03-18 17:17:38.000000000 +0100
++++ wbfs_file_2.9_no_openssl//source/tools.h	2012-03-06 23:15:03.000000000 +0100
+@@ -32,14 +32,7 @@
+ void bn_exp(u8 *d, u8 *a, u8 *N, u32 n, u8 *e, u32 en);
+ 
+ // crypto
+-void md5(u8 *data, u32 len, u8 *hash);
+-void sha(u8 *data, u32 len, u8 *hash);
+ void get_key(const char *name, u8 *key, u32 len);
+-void aes_cbc_dec(u8 *key, u8 *iv, u8 *in, u32 len, u8 *out);
+-void aes_cbc_enc(u8 *key, u8 *iv, u8 *in, u32 len, u8 *out);
+-void decrypt_title_key(u8 *tik, u8 *title_key);
+-int check_cert_chain(u8 *data, u32 data_len, u8 *cert, u32 cert_len);
+-int check_ec(u8 *ng, u8 *ap, u8 *sig, u8 *sig_hash);
+ void generate_ecdsa(u8 *R, u8 *S, u8 *k, u8 *hash);
+ int check_ecdsa(u8 *Q, u8 *R, u8 *S, u8 *hash);
+ void ec_priv_to_pub(u8 *k, u8 *Q);
diff --git a/games-util/wbfs_file/wbfs_file-2.9-r1.ebuild b/games-util/wbfs_file/wbfs_file-2.9-r1.ebuild
deleted file mode 100644
index 158cd24..0000000
--- a/games-util/wbfs_file/wbfs_file-2.9-r1.ebuild
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright 1999-2010 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: $
-
-EAPI=2
-
-inherit eutils
-
-DESCRIPTION="wbfs_file binary for working with wbfs files or partitions"
-HOMEPAGE="http://cfg-loader.googlecode.com"
-LICENSE="GPL-2"
-SLOT="0"
-
-MY_P="${PN}_${PV}"
-SRC_URI="http://cfg-loader.googlecode.com/files/${MY_P}.zip"
-
-KEYWORDS="~amd64"
-
-IUSE="-static"
-
-DEPEND="dev-libs/openssl
-	static? ( dev-libs/openssl[static-libs] )"
-
-RDEPEND="${DEPEND}"
-
-S="${WORKDIR}/${MY_P}/source"
-
-src_prepare() {
-	use static || sed -i '/ADD_LF = -static/d' ${S}/Makefile
-	epatch "${FILESDIR}/64bit_fix.patch"
-}
-
-src_install() {
-	dobin wbfs_file
-	dodoc ../readme.txt
-	dodoc ../readme_orig.txt
-}
diff --git a/games-util/wbfs_file/wbfs_file-2.9-r2.ebuild b/games-util/wbfs_file/wbfs_file-2.9-r2.ebuild
new file mode 100644
index 0000000..bc48d39
--- /dev/null
+++ b/games-util/wbfs_file/wbfs_file-2.9-r2.ebuild
@@ -0,0 +1,38 @@
+# Copyright 1999-2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+EAPI=2
+
+inherit eutils
+
+DESCRIPTION="wbfs_file binary for working with wbfs files or partitions"
+HOMEPAGE="http://cfg-loader.googlecode.com"
+LICENSE="GPL-2"
+SLOT="0"
+
+MY_P="${PN}_${PV}"
+SRC_URI="http://cfg-loader.googlecode.com/files/${MY_P}.zip"
+
+KEYWORDS="~x86 ~amd64"
+
+IUSE="-static"
+
+DEPEND=""
+RDEPEND="${DEPEND}"
+
+S="${WORKDIR}/${MY_P}/source"
+
+src_prepare() {
+	use static || sed -i '/ADD_LF = -static/d' ${S}/Makefile
+	use amd64 && epatch "${FILESDIR}/64bit_fix.patch"
+
+	sed -i 's/-lcrypto//' ${S}/Makefile
+	epatch "${FILESDIR}/no-openssl.patch"
+}
+
+src_install() {
+	dobin wbfs_file
+	dodoc ../readme.txt
+	dodoc ../readme_orig.txt
+}
-- 
cgit v1.2.3