2005-03-28

build + the Poly1305-AES library

When just doinking around with some new API, I'll usually just throw together a rudimentary Makefile and go about my business. My intermediate-and-up programming environment is the vi editor plus build, which can create a variety of objects based on scripts you create as objectname.do files.

This works pretty well most of the time. But what happens when you want to use the Poly1305-AES library? The poly1305aes.a library already uses .do files. What is a programmer to do?

After a couple of aborted attempts at trying to make the two play nice, I put it down and went on with my life. Nowadays, my mornings consist of waiting for a bowl of chicken broth to cool to room temperature and debating whether or not I should risk opiod addiction or stick to the OTC Advil for another day. I need things to occupy my time: I watch a movie a day, dick around on the Internet quite a bit, and catch up on bills and other light reading.

So I decided I wanted to tackle the problem again.

It's so easy, once you realize what you need to do. The fastest way to get your Poly1305-AES-compliant software up and running is to create an extra object in your source tree that makes the library for you. Here is how I did it:

Make your project.

$ build-project myprojectname
$ cd myprojectname/src

Prepare your source tree for two things: the script that will create the poly1305aes.a library and the program that will use it.

$ cd ..
$ echo "make-poly1305aes-lib" > ./it=d
$ echo "test" >> ./it=d
$ echo "poly1305aes.a" > ./test=x

At this point, you can write something that will one day resemble your program. In this case, my program is called "test", and is contained in the file "test.c". Now add the Poly1305-AES software to your source. I started with the Poly1305-AES library in /usr/local/src, but you can keep it just about anywhere you're comfortable putting source code.

$ wget -nd http://cr.yp.to/mac/poly1305aes-20050218.tar.gz
$ gunzip < poly1305aes-20050218.tar.gz | (cd /usr/local/src; tar -xf -)
$ cd /usr/local/src/poly1305aes-20050218
$ env CC='gcc -O2' make
$ cp `cat FILES.lib` myprojectname

Add the make-poly1305aes-lib script to your source. This is distilled from /usr/local/src/poly1305aes-20050218/Makefile.lib.

$ cd myprojectname/src
$ cat make-poly1305aes-lib
dependon aes.h.do
dependon aes_aix.h
dependon aes_aix.s
dependon aes_aix_constants.s
dependon aes_athlon.h
dependon aes_athlon.s
dependon aes_athlon_constants.s
dependon aes_big.c
dependon aes_big.h
dependon aes_big_constants.c
dependon aes_macos.h
dependon aes_macos.s
dependon aes_macos_constants.s
dependon aes_ppro.h
dependon aes_ppro.s
dependon aes_ppro_constants.s
dependon aes_sparc.h
dependon aes_sparc.s
dependon aes_sparc_constants.c
dependon poly1305.h.do
dependon poly1305_53.c
dependon poly1305_53.h
dependon poly1305_53_constants.c
dependon poly1305_aix.h
dependon poly1305_aix.s
dependon poly1305_aix_constants.c
dependon poly1305_athlon.h
dependon poly1305_athlon.s
dependon poly1305_athlon_constants.s
dependon poly1305_macos.h
dependon poly1305_macos.s
dependon poly1305_macos_constants.s
dependon poly1305_ppro.h
dependon poly1305_ppro.s
dependon poly1305_ppro_constants.s
dependon poly1305_sparc.h
dependon poly1305_sparc.s
dependon poly1305_sparc_constants.c
dependon poly1305aes.a.do
dependon poly1305aes.h.do
dependon poly1305aes.impl.check.c
dependon poly1305aes.impl.do
dependon poly1305aes_53.h
dependon poly1305aes_53_authenticate.c
dependon poly1305aes_53_clamp.c
dependon poly1305aes_53_isequal.c
dependon poly1305aes_53_verify.c
dependon poly1305aes_aix.h
dependon poly1305aes_aix_authenticate.c
dependon poly1305aes_aix_clamp.c
dependon poly1305aes_aix_isequal.s
dependon poly1305aes_aix_verify.c
dependon poly1305aes_athlon.h
dependon poly1305aes_athlon_authenticate.c
dependon poly1305aes_athlon_clamp.c
dependon poly1305aes_athlon_isequal.s
dependon poly1305aes_athlon_verify.c
dependon poly1305aes_macos.h
dependon poly1305aes_macos_authenticate.c
dependon poly1305aes_macos_clamp.c
dependon poly1305aes_macos_isequal.s
dependon poly1305aes_macos_verify.c
dependon poly1305aes_ppro.h
dependon poly1305aes_ppro_authenticate.c
dependon poly1305aes_ppro_clamp.c
dependon poly1305aes_ppro_isequal.s
dependon poly1305aes_ppro_verify.c
dependon poly1305aes_sparc.h
dependon poly1305aes_sparc_authenticate.c
dependon poly1305aes_sparc_clamp.s
dependon poly1305aes_sparc_fsr.s
dependon poly1305aes_sparc_isequal.s
dependon poly1305aes_sparc_verify.c
dependon x86cpuid.c

CC=`head -1 conf-cc`
sh -e poly1305aes.impl.do $CC > poly1305aes.impl.new
mv poly1305aes.impl.new poly1305aes.impl
formake "sh -e poly1305aes.impl.do $CC > poly1305aes.impl.new"
formake "mv poly1305aes.impl.new poly1305aes.impl"

sh -e aes.h.do > aes.h.new
mv aes.h.new aes.h
formake "sh -e aes.h.do > aes.h.new"
formake "mv aes.h.new aes.h"

sh -e poly1305.h.do > poly1305.h.new
mv poly1305.h.new poly1305.h
formake "sh -e poly1305.h.do > poly1305.h.new"
formake "mv poly1305.h.new poly1305.h"

sh -e poly1305aes.a.do $CC > poly1305aes.a.new
mv poly1305aes.a.new poly1305aes.a
formake "sh -e poly1305aes.a.do $CC > poly1305aes.a.new"
formake "mv poly1305aes.a.new poly1305aes.a"

sh -e poly1305aes.h.do > poly1305aes.h.new
mv poly1305aes.h.new poly1305aes.h

exit 0
$

This version of "make-poly1305aes-lib" has the following checksums:
MD5 = c7f2a7ad6484ee39fa1c1331ff98a5ba
SHA1 = 3fe448c71629e886c4f132dab37192851f1e5e88

At this point, build will make poly1305aes.a for you, and so you can spend your time worrying about how your software will work instead of worrying if your software is even going to compile.

Up next? I find out if this solution is even remotely portable.

No comments: