~aritra1911/openssl_madness

5466b12b630f02b320afc80bb8b0fb30bfaceba2 — Aritra Sarkar 2 years ago dfde0d9
Separate Makefiles for GNU make on Linux and BSD make on FreeBSD
6 files changed, 63 insertions(+), 35 deletions(-)

D Makefile
A Makefile.fbsd_amd64
A Makefile.linux_x86_64
M aes.c
A common.mk
M madness.c
D Makefile => Makefile +0 -30
@@ 1,30 0,0 @@
CFLAGS = -Wall -Wextra -pedantic -std=c99
CPPFLAGS = -DPURIFY
LIBS = -lcrypto
LDFLAGS = $(LIBS)

ifdef OPENSSLDIR
	CFLAGS += -I$(OPENSSLDIR)/include
	LDFLAGS += -L$(OPENSSLDIR)/lib \
		-Wl,--enable-new-dtags,-rpath,$(OPENSSLDIR)/lib
endif

ifneq ($(strip $(DEBUG)),0)
	CFLAGS += -g -O0
endif

.PHONY: all clean

all: madness aes

madness: madness.o
	$(CC) $(LDFLAGS) -o $@ $^

aes: aes.o driver.o
	$(CC) $(LDFLAGS) -o $@ $^

%.o: %.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

clean:
	$(RM) *.o madness aes

A Makefile.fbsd_amd64 => Makefile.fbsd_amd64 +19 -0
@@ 0,0 1,19 @@
CFLAGS=		-std=iso9899:1999 -pedantic -pedantic-errors \
		-Weverything -Wno-missing-prototypes \
		-m64 -fno-fast-math -fno-builtin

.if !empty(OPENSSLDIR)
CFLAGS:=	-I$(OPENSSLDIR)/include $(CFLAGS)
LDFLAGS=	-L$(OPENSSLDIR)/lib \
		-Wl,--enable-new-dtags,-rpath,$(OPENSSLDIR)/lib
.endif

.if "${DEBUG}" != "0"
CFLAGS+=	-g -O0
.endif

.if !defined(RM)
RM=		rm -f
.endif

.include "common.mk"

A Makefile.linux_x86_64 => Makefile.linux_x86_64 +19 -0
@@ 0,0 1,19 @@
CFLAGS=		-std=iso9899:1999 -m64 -fno-builtin \
		-pedantic -pedantic-errors \
		-march=k8 -mtune=k8 -mieee-fp -mhard-float -mpc80 \
		-fno-fast-math -malign-double \
		-m128bit-long-double -mlong-double-80 \
		-mstackrealign -mpreferred-stack-boundary=4 -mno-mmx \
		-Wall -Wextra

ifdef OPENSSLDIR
CFLAGS+=	-I$(OPENSSLDIR)/include
LDFLAGS+=	-L$(OPENSSLDIR)/lib \
		-Wl,--enable-new-dtags,-rpath,$(OPENSSLDIR)/lib
endif

ifneq ($(strip $(DEBUG)),0)
CFLAGS+=	-g -O0
endif

include common.mk

M aes.c => aes.c +5 -4
@@ 9,7 9,7 @@ int do_crypt(FILE *in, FILE *out, int do_encrypt)
{
    /* Allow enough space in output buffer for additional block */
    unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];
    int inlen, outlen;
    size_t inlen, outlen;
    EVP_CIPHER_CTX *ctx;
    /*
     * Bogus key and IV: we'd normally set these from


@@ 42,16 42,17 @@ int do_crypt(FILE *in, FILE *out, int do_encrypt)

    for (;;) {
        inlen = fread(inbuf, 1, 1024, in);
        if (inlen <= 0)
        if ( !inlen )
            break;
        if (!EVP_CipherUpdate(ctx, outbuf, &outlen, inbuf, inlen)) {
        if (!EVP_CipherUpdate(ctx, outbuf, (int *) &outlen,
                                    inbuf,   (int)   inlen)) {
            /* Error */
            EVP_CIPHER_CTX_free(ctx);
            return 0;
        }
        fwrite(outbuf, 1, outlen, out);
    }
    if (!EVP_CipherFinal_ex(ctx, outbuf, &outlen)) {
    if (!EVP_CipherFinal_ex(ctx, outbuf, (int *) &outlen)) {
        /* Error */
        EVP_CIPHER_CTX_free(ctx);
        return 0;

A common.mk => common.mk +19 -0
@@ 0,0 1,19 @@
CPPFLAGS=	-DPURIFY
LIBS=		-lcrypto
LDFLAGS+=	$(LIBS)

.PHONY: all clean

all: madness aes

madness: madness.o
	$(CC) $(LDFLAGS) -o $@ madness.o

aes: aes.o driver.o
	$(CC) $(LDFLAGS) -o aes aes.o driver.o

.c.o:
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

clean:
	$(RM) *.o madness aes

M madness.c => madness.c +1 -1
@@ 41,7 41,7 @@ void print_usage(const char *bin)

int main(int argc, char **argv)
{
    EVP_PKEY *private_key, *public_key;
    EVP_PKEY *private_key = NULL, *public_key = NULL;
    FILE *fp, *fpin, *fpout;
    char *input_filename = NULL, *key_filename = NULL, *output_filename = NULL;
    int decrypt = -1, verbose = 0;