Skip to content

Commit

Permalink
demos: tidy up makefiles, fix warnings
Browse files Browse the repository at this point in the history
Update makefiles so that consistent patterns are used.  Object files
are compiled from source using an implicit rule (but using our
CFLAGS); for linking, we give an explicit rule.  Ensure that "make
test" works in each subdirectory (even if it does not actually run any
applications).  The top-level demo makefile now works.

The makefiles are not make-agnostic.  e.g. they use the variable $(RM)
in "clean" recipes, which is defined in gnu-make but may not be
defined in others.

Part of #17806

Testing:

  $ cd demo
  $ make test

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #22698)
  • Loading branch information
James Muir authored and t8m committed Nov 15, 2023
1 parent 56aa3e8 commit 86db958
Show file tree
Hide file tree
Showing 37 changed files with 314 additions and 202 deletions.
16 changes: 15 additions & 1 deletion demos/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
MODULES=bio digest encode encrypt kdf keyexch mac pkey signature sslecho
MODULES = bio \
cipher \
cms \
digest \
encode \
encrypt \
guide \
http3 \
kdf \
keyexch \
mac \
pkey \
signature \
smime \
sslecho

all:
@set -e; for i in $(MODULES); do \
Expand Down
38 changes: 20 additions & 18 deletions demos/bio/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# Quick instruction:
# To build against an OpenSSL built in the source tree, do this:
#
# make OPENSSL_INCS_LOCATION=-I../../include OPENSSL_LIBS_LOCATION=-L../..
#
# To run the demos when linked with a shared library (default):
# To run the demos when linked with a shared library (default) ensure that
# libcrypto and libssl are on the library path. For example:
#
# LD_LIBRARY_PATH=../.. ./server-arg
# LD_LIBRARY_PATH=../.. ./server-cmod
# LD_LIBRARY_PATH=../.. ./server-conf
# LD_LIBRARY_PATH=../.. ./client-arg
# LD_LIBRARY_PATH=../.. ./client-conf
# LD_LIBRARY_PATH=../.. ./saccept
# LD_LIBRARY_PATH=../.. ./sconnect

CFLAGS = $(OPENSSL_INCS_LOCATION)
LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto $(EX_LIBS)
TESTS = client-arg \
client-conf \
saccept \
sconnect \
server-arg \
server-cmod \
server-conf

all: client-arg client-conf saccept sconnect server-arg server-cmod server-conf
CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lssl -lcrypto

test:
all: $(TESTS)

client-arg: client-arg.o
client-conf: client-conf.o
Expand All @@ -28,8 +26,12 @@ server-arg: server-arg.o
server-cmod: server-cmod.o
server-conf: server-conf.o

client-arg client-conf saccept sconnect server-arg server-cmod server-conf:
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
$(TESTS):
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

clean:
$(RM) *.o client-arg client-conf saccept sconnect server-arg server-cmod server-conf
$(RM) $(TESTS) *.o

test: all
@echo "\nBIO tests:"
@echo "skipped"
1 change: 0 additions & 1 deletion demos/bio/sconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ int main(int argc, char *argv[])
const char *hostport = HOSTPORT;
const char *CAfile = CAFILE;
const char *hostname;
char *cp;
BIO *out = NULL;
char buf[1024 * 10], *p;
SSL_CTX *ssl_ctx = NULL;
Expand Down
26 changes: 12 additions & 14 deletions demos/cipher/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Quick instruction:
# To build against an OpenSSL built in the source tree, do this:
#
# make OPENSSL_INCS_LOCATION=-I../../include OPENSSL_LIBS_LOCATION=-L../..
#
# To run the demos when linked with a shared library (default):
# To run the demos when linked with a shared library (default) ensure that
# libcrypto is on the library path. For example:
#
# LD_LIBRARY_PATH=../.. ./aesccm
# LD_LIBRARY_PATH=../.. ./aesgcm
# LD_LIBRARY_PATH=../.. ./aeskeywrap
# LD_LIBRARY_PATH=../.. ./ariacbc

CFLAGS = $(OPENSSL_INCS_LOCATION)
LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto
TESTS = aesccm \
aesgcm \
aeskeywrap \
ariacbc

TESTS=aesccm aesgcm aeskeywrap ariacbc
CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lcrypto

all: $(TESTS)

Expand All @@ -22,11 +20,11 @@ aesgcm: aesgcm.o
aeskeywrap: aeskeywrap.o
ariacbc: ariacbc.o

aesccm aesgcm aeskeywrap ariacbc:
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
$(TESTS):
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

clean:
$(RM) aesccm aesgcm aeskeywrap ariacbc *.o
$(RM) $(TESTS) *.o

.PHONY: test
test: all
Expand Down
5 changes: 1 addition & 4 deletions demos/cipher/ariacbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ int aria_cbc_encrypt(void)
EVP_CIPHER_CTX *ctx;
EVP_CIPHER *cipher = NULL;
int outlen, tmplen;
size_t cbc_ivlen = sizeof(cbc_iv);
unsigned char outbuf[1024];
unsigned char outtag[16];

printf("ARIA CBC Encrypt:\n");
printf("Plaintext:\n");
Expand Down Expand Up @@ -115,8 +113,7 @@ int aria_cbc_decrypt(void)
int ret = 0;
EVP_CIPHER_CTX *ctx;
EVP_CIPHER *cipher = NULL;
int outlen, tmplen, rv;
size_t cbc_ivlen = sizeof(cbc_iv);
int outlen, tmplen;
unsigned char outbuf[1024];

printf("ARIA CBC Decrypt:\n");
Expand Down
18 changes: 14 additions & 4 deletions demos/cms/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@ TESTS = cms_comp \
cms_uncomp \
cms_ver

CFLAGS = -I../../include -g
CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lcrypto

all: $(TESTS)

cms_comp: cms_comp.o
cms_ddec: cms_ddec.o
cms_dec: cms_dec.o
cms_denc: cms_denc.o
cms_enc: cms_enc.o
cms_sign: cms_sign.o
cms_sign2: cms_sign2.o
cms_uncomp: cms_uncomp.o
cms_ver: cms_ver.o

$(TESTS):
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

clean:
$(RM) $(TESTS) *.o

cms_%: cms_%.c
$(CC) $(CFLAGS) $(LDFLAGS) -o "$@" "$<" $(LDLIBS)

test: all
@echo "\nCMS tests:"
LD_LIBRARY_PATH=../.. ./cms_enc
Expand Down
3 changes: 2 additions & 1 deletion demos/cms/cms_ddec.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ int main(int argc, char **argv)

rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);

BIO_reset(tbio);
if (BIO_reset(tbio) < 0)
goto err;

rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);

Expand Down
3 changes: 2 additions & 1 deletion demos/cms/cms_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ int main(int argc, char **argv)

rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);

BIO_reset(tbio);
if (BIO_reset(tbio) < 0)
goto err;

rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);

Expand Down
9 changes: 6 additions & 3 deletions demos/cms/cms_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ int main(int argc, char **argv)

scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);

BIO_reset(tbio);
if (BIO_reset(tbio) < 0)
goto err;

skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);

Expand All @@ -62,8 +63,10 @@ int main(int argc, char **argv)
if (!out)
goto err;

if (!(flags & CMS_STREAM))
BIO_reset(in);
if (!(flags & CMS_STREAM)) {
if (BIO_reset(in) < 0)
goto err;
}

/* Write out S/MIME message */
if (!SMIME_write_CMS(out, cms, in, flags))
Expand Down
6 changes: 4 additions & 2 deletions demos/cms/cms_sign2.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ int main(int argc, char **argv)

scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);

BIO_reset(tbio);
if (BIO_reset(tbio) < 0)
goto err;

skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);

Expand All @@ -43,7 +44,8 @@ int main(int argc, char **argv)

scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL);

BIO_reset(tbio);
if (BIO_reset(tbio) < 0)
goto err;

skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);

Expand Down
29 changes: 17 additions & 12 deletions demos/digest/Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
#
# To run the demos when linked with a shared library (default):
# To run the demos when linked with a shared library (default) ensure
# that libcrypto is on the library path. For example:
#
# LD_LIBRARY_PATH=../.. ./EVP_MD_demo

CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lcrypto
TESTS = EVP_MD_demo \
EVP_MD_stdin \
EVP_MD_xof \
BIO_f_md

TESTS=EVP_MD_demo EVP_MD_stdin EVP_MD_xof BIO_f_md
CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lcrypto

all: $(TESTS)

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

EVP_MD_demo: EVP_MD_demo.o
EVP_MD_stdin: EVP_MD_stdin.o
EVP_MD_xof: EVP_MD_xof.o
BIO_f_md: BIO_f_md.o

$(TESTS):
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

clean:
$(RM) *.o $(TESTS)

.PHONY: test
# Since some of these tests use stdin we use the source file as stdin when running the exes
# Since some of these tests use stdin, we use the source file as stdin
# when running the tests
test: all
@echo "\nDigest tests:"
@set -e; for tst in $(TESTS); do \
echo "\n"$$tst; \
cat $$tst.c | ./$$tst; \
done

clean:
$(RM) *.o $(TESTS)
26 changes: 16 additions & 10 deletions demos/encode/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#
# To run the demos when linked with a shared library (default):
# To run the demos when linked with a shared library (default) ensure
# that libcrypto is on the library path. For example:
#
# LD_LIBRARY_PATH=../.. ./rsa_encode

CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lcrypto
TESTS = ec_encode \
rsa_encode

TESTS=ec_encode rsa_encode
CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lcrypto

all: $(TESTS)

%.o: %.c
$(CC) $(CFLAGS) -c $<
ec_encode: ec_encode.o
rsa_encode: rsa_encode.o

%_encode: %_encode.o

test:
$(TESTS):
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

clean:
$(RM) *.o $(TESTS)

.PHONY: test
test: all
@echo "\nencode tests:"
@echo "skipped"
17 changes: 9 additions & 8 deletions demos/encrypt/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#
# To run the demos when linked with a shared library (default):
# To run the demos when linked with a shared library (default) ensure
# that libcrypto is on the library path. For example:
#
# LD_LIBRARY_PATH=../.. ./rsa_encrypt

CFLAGS = -I../../include -g
LDFLAGS = -L../..
LDLIBS = -lcrypto
TESTS = rsa_encrypt

TESTS=rsa_encrypt
CFLAGS = -I../../include -g -Wall
LDFLAGS = -L../..
LDLIBS = -lcrypto

all: $(TESTS)

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

rsa_encrypt: rsa_encrypt.o

$(TESTS):
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

clean:
$(RM) *.o $(TESTS)

Expand Down
2 changes: 1 addition & 1 deletion demos/encrypt/rsa_encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int do_encrypt(OSSL_LIB_CTX *libctx,
return ret;
}

static int do_decrypt(OSSL_LIB_CTX *libctx, const char *in, size_t in_len,
static int do_decrypt(OSSL_LIB_CTX *libctx, const unsigned char *in, size_t in_len,
unsigned char **out, size_t *out_len)
{
int ret = 0, public = 0;
Expand Down

0 comments on commit 86db958

Please sign in to comment.