From ba5e2c39e216fffb4495d9afd190c14134be6c0c Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Fri, 9 Nov 2012 09:23:46 +0100
Subject: [PATCH] New package: libtomcrypt-1.17.

---
 common/shlibs                                 |   1 +
 srcpkgs/libtomcrypt-devel                     |   1 +
 .../libtomcrypt/libtomcrypt-devel.template    |  15 ++
 srcpkgs/libtomcrypt/libtomcrypt.rshlibs       |   1 +
 .../patches/libtomcrypt_1.17-2.diff           | 143 ++++++++++++++++++
 srcpkgs/libtomcrypt/template                  |  21 +++
 6 files changed, 182 insertions(+)
 create mode 120000 srcpkgs/libtomcrypt-devel
 create mode 100644 srcpkgs/libtomcrypt/libtomcrypt-devel.template
 create mode 100644 srcpkgs/libtomcrypt/libtomcrypt.rshlibs
 create mode 100644 srcpkgs/libtomcrypt/patches/libtomcrypt_1.17-2.diff
 create mode 100644 srcpkgs/libtomcrypt/template

diff --git a/common/shlibs b/common/shlibs
index b6bd6d1f21..164ba040a3 100644
--- a/common/shlibs
+++ b/common/shlibs
@@ -1105,3 +1105,4 @@ libqrencode.so.3 libqrencode-3.4.1_1
 libwayland-server.so.0 wayland-1.0.0_1
 libwayland-client.so.0 wayland-1.0.0_1
 libwayland-cursor.so.0 wayland-1.0.0_1
+libtomcrypt.so.0 libtomcrypt-1.117_1
diff --git a/srcpkgs/libtomcrypt-devel b/srcpkgs/libtomcrypt-devel
new file mode 120000
index 0000000000..9943ec0e3f
--- /dev/null
+++ b/srcpkgs/libtomcrypt-devel
@@ -0,0 +1 @@
+libtomcrypt
\ No newline at end of file
diff --git a/srcpkgs/libtomcrypt/libtomcrypt-devel.template b/srcpkgs/libtomcrypt/libtomcrypt-devel.template
new file mode 100644
index 0000000000..e15a0634a7
--- /dev/null
+++ b/srcpkgs/libtomcrypt/libtomcrypt-devel.template
@@ -0,0 +1,15 @@
+# Template file for 'libtomcrypt-devel'.
+#
+depends="${sourcepkg}-${version}_${revision}"
+short_desc="${short_desc} -- development files"
+long_desc="${long_desc}
+
+ This package contains files for development, headers, static libs, etc."
+
+do_install() {
+	vmove usr/include usr
+	vmove usr/lib/pkgconfig usr/lib
+	vmove "usr/lib/*.a" usr/lib
+
+	vinstall ${sourcepkg}.3 644 usr/share/man/man3
+}
diff --git a/srcpkgs/libtomcrypt/libtomcrypt.rshlibs b/srcpkgs/libtomcrypt/libtomcrypt.rshlibs
new file mode 100644
index 0000000000..631aa1dda4
--- /dev/null
+++ b/srcpkgs/libtomcrypt/libtomcrypt.rshlibs
@@ -0,0 +1 @@
+libc.so.6
diff --git a/srcpkgs/libtomcrypt/patches/libtomcrypt_1.17-2.diff b/srcpkgs/libtomcrypt/patches/libtomcrypt_1.17-2.diff
new file mode 100644
index 0000000000..a362e2eae8
--- /dev/null
+++ b/srcpkgs/libtomcrypt/patches/libtomcrypt_1.17-2.diff
@@ -0,0 +1,143 @@
+--- libtomcrypt-1.17.orig/libtomcrypt.pc
++++ libtomcrypt-1.17/libtomcrypt.pc
+@@ -0,0 +1,10 @@
++prefix=/usr
++exec_prefix=${prefix}
++libdir=${exec_prefix}/lib
++includedir=${prefix}/include
++
++Name: LibTomCrypt
++Description: public domain open source cryptographic toolkit
++Version: 1.17
++Libs: -L${libdir} -ltomcrypt
++Cflags: -I${includedir}
+--- libtomcrypt-1.17.orig/makefile
++++ libtomcrypt-1.17/makefile
+@@ -340,7 +340,6 @@
+ 	rm -f crypt.aux  crypt.dvi  crypt.idx  crypt.ilg  crypt.ind  crypt.log crypt.toc
+ 	rm -f $(TV) $(PROF) $(SMALL) $(CRYPT) $(HASHSUM) $(MULTI) $(TIMING) $(TEST)
+ 	rm -rf doc/doxygen
+-	rm -f doc/*.pdf
+ 	rm -f *.txt
+ 
+ #build the doxy files (requires Doxygen, tetex and patience)
+--- libtomcrypt-1.17.orig/makefile.shared
++++ libtomcrypt-1.17/makefile.shared
+@@ -248,15 +248,16 @@
+ 
+ objs: $(OBJECTS)
+ 
+-$(LIBNAME): $(OBJECTS) testprof/$(LIBTEST)
++$(LIBNAME): $(OBJECTS)
+ 	libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]lo" | grep "src/" | xargs` $(EXTRALIBS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION)
+ 
+ install: $(LIBNAME)
+ 	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
+-	cd testprof ; CFLAGS="$(CFLAGS)" GROUP=$(GROUP) USER=$(USER) VERSION=$(VERSION) LIBPATH=$(LIBPATH) LIBTEST=$(LIBTEST) LIBTEST_S=$(LIBTEST_S) DESTDIR=$(DESTDIR) make -f makefile.shared install
+ 	libtool --silent --mode=install install -c libtomcrypt.la $(DESTDIR)$(LIBPATH)/libtomcrypt.la
+ 	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
+ 	install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
++	install -d $(DESTDIR)$(LIBPATH)/pkgconfig
++	install -m 0644 -g $(GROUP) -o $(USER) libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
+ 
+ #This rule makes the hash program included with libtomcrypt
+ hashsum: library
+--- libtomcrypt-1.17.orig/libtomcrypt.3
++++ libtomcrypt-1.17/libtomcrypt.3
+@@ -0,0 +1,96 @@
++.\"                                      Hey, EMACS: -*- nroff -*-
++.\" First parameter, NAME, should be all caps
++.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
++.\" other parameters are allowed: see man(7), man(1)
++.TH LIBTOMCRYPT 3 "June 2009"
++.\" Please adjust this date whenever revising the manpage.
++.\"
++.\" Some roff macros, for reference:
++.\" .nh        disable hyphenation
++.\" .hy        enable hyphenation
++.\" .ad l      left justify
++.\" .ad b      justify to both left and right margins
++.\" .nf        disable filling
++.\" .fi        enable filling
++.\" .br        insert line break
++.\" .sp <n>    insert n+1 empty lines
++.\" for manpage-specific macros, see man(7)
++.SH NAME
++libtomcrypt \- public domain open source crypthographic toolkit
++.SH SYNOPSIS
++#include <tomcrypt.h>
++
++Link with \-ltomcrypt (use pkg-config --libs libtomcrypt)
++
++.SH DESCRIPTION
++.B libtomcrypt
++is documented in /usr/share/doc/libtomcrypt-dev/crypt.pdf. To give you a very
++brief introduction, the following example is provided.
++
++.SH EXAMPLE
++.nf
++  /* AES-XTS example for libtomcrypt. (c) 2008 Michael Stapelberg, Public Domain */
++  #include <stdint.h>
++  #include <string.h>
++  #include <tomcrypt.h>
++
++  static symmetric_xts xts;
++
++  /*
++   * Initializes AES-XTS for use with encrypt(). Key must be at least 32 bytes long, only
++   * the first 32 bytes will be used.
++   *
++   */
++  void initialize_xts(unsigned char *key) {
++    int idx, err;
++    unsigned char aeskey1[16], aeskey2[16];
++
++    /* You can use 32 different ciphers simultaneously. Before using a cipher, you must register it. */
++    register_cipher(&aes_desc);
++
++    /* Get the index of the cipher registered before */
++    if ((idx = find_cipher("aes")) == \-1) {
++            fprintf(stderr, "ERROR: AES not available in libtomcrypt. Please upgrade/fix libtomcrypt.\\n");
++            exit(EXIT_FAILURE);
++    }
++   
++    /* Set up the two private keys required by AES-XTS (see 3.4.10 of crypt.pdf) */
++    strncpy((char*)aeskey1, key, 16);
++    strncpy((char*)aeskey2, key+16, 16);
++    
++    printf("Initializing with keys \\"%.16s\\" and \\"%.16s\\" (AES-XTS)\\n", aeskey1, aeskey2);
++   
++    /* Initialize AES-XTS */
++    if ((err = xts_start(idx, aeskey1, aeskey2, 16, 0, &xts)) != CRYPT_OK) {
++            fprintf(stderr, "ERROR starting XTS: %s\\n", error_to_string(err));
++            exit(EXIT_FAILURE);
++    }
++  }
++ 
++  /*
++   * Encrypts the input (of input_size) and stores the result in output. The piece index
++   * is required because XTS wants a tweak for each block so that it doesn't generate
++   * patterns which would be visible in the encrypted output.
++   *
++   */
++  void encrypt(const uint8_t *input, uint8_t *output, int input_size, int piece_idx) {
++    unsigned char tweak[256];
++    int err;
++
++    memset(tweak, '\\0', 256);
++    snprintf((char*)tweak, 256, "%d", piece_idx);
++    
++    if ((err = xts_encrypt(input, input_size, output, tweak, &xts)) != CRYPT_OK) {
++            fprintf(stderr, "ERROR in AES encryption: %d: %s\\n", err, error_to_string(err));
++            exit(EXIT_FAILURE);
++    }
++  }
++.fi
++
++.SH SEE ALSO
++.BR pkg-config (1)
++.SH AUTHOR
++libtomcrypt was written by Tom St Denis.
++.PP
++This manual page was written by Michael Stapelberg <michael@stapelberg.de>,
++for the Debian project (and may be used by others).
diff --git a/srcpkgs/libtomcrypt/template b/srcpkgs/libtomcrypt/template
new file mode 100644
index 0000000000..615dd72f2e
--- /dev/null
+++ b/srcpkgs/libtomcrypt/template
@@ -0,0 +1,21 @@
+# Template file for 'libtomcrypt'
+pkgname=libtomcrypt
+version=1.17
+revision=1
+patch_args="-Np1"
+subpackages="${pkgname}-devel"
+build_style=gnu-makefile
+makedepends="libtool"
+make_build_args="-f makefile.shared"
+make_install_args="-f makefile.shared NODOCS=1"
+short_desc="Fairly comprehensive, modular and portable cryptographic toolkit"
+maintainer="Juan RP <xtraeme@gmail.com>"
+license="Public domain"
+homepage="http://www.libtom.org/?page=features&newsitems=5&whatfile=crypt"
+distfiles="http://www.libtom.org/files/crypt-${version}.tar.bz2"
+checksum=e33b47d77a495091c8703175a25c8228aff043140b2554c08a3c3cd71f79d116
+long_desc="
+ LibTomCrypt is a fairly comprehensive, modular and portable cryptographic
+ toolkit that provides developers with a vast array of well known published
+ block ciphers, one-way hash functions, chaining modes, pseudo-random number
+ generators, public key cryptography and a plethora of other routines."