Skip to content

Commit 86db958

Browse files
James Muirt8m
James Muir
authored andcommitted
demos: tidy up makefiles, fix warnings
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 openssl#17806 Testing: $ cd demo $ make test Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#22698)
1 parent 56aa3e8 commit 86db958

37 files changed

+314
-202
lines changed

demos/Makefile

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
MODULES=bio digest encode encrypt kdf keyexch mac pkey signature sslecho
1+
MODULES = bio \
2+
cipher \
3+
cms \
4+
digest \
5+
encode \
6+
encrypt \
7+
guide \
8+
http3 \
9+
kdf \
10+
keyexch \
11+
mac \
12+
pkey \
13+
signature \
14+
smime \
15+
sslecho
216

317
all:
418
@set -e; for i in $(MODULES); do \

demos/bio/Makefile

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
# Quick instruction:
2-
# To build against an OpenSSL built in the source tree, do this:
31
#
4-
# make OPENSSL_INCS_LOCATION=-I../../include OPENSSL_LIBS_LOCATION=-L../..
5-
#
6-
# To run the demos when linked with a shared library (default):
2+
# To run the demos when linked with a shared library (default) ensure that
3+
# libcrypto and libssl are on the library path. For example:
74
#
85
# LD_LIBRARY_PATH=../.. ./server-arg
9-
# LD_LIBRARY_PATH=../.. ./server-cmod
10-
# LD_LIBRARY_PATH=../.. ./server-conf
11-
# LD_LIBRARY_PATH=../.. ./client-arg
12-
# LD_LIBRARY_PATH=../.. ./client-conf
13-
# LD_LIBRARY_PATH=../.. ./saccept
14-
# LD_LIBRARY_PATH=../.. ./sconnect
156

16-
CFLAGS = $(OPENSSL_INCS_LOCATION)
17-
LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto $(EX_LIBS)
7+
TESTS = client-arg \
8+
client-conf \
9+
saccept \
10+
sconnect \
11+
server-arg \
12+
server-cmod \
13+
server-conf
1814

19-
all: client-arg client-conf saccept sconnect server-arg server-cmod server-conf
15+
CFLAGS = -I../../include -g -Wall
16+
LDFLAGS = -L../..
17+
LDLIBS = -lssl -lcrypto
2018

21-
test:
19+
all: $(TESTS)
2220

2321
client-arg: client-arg.o
2422
client-conf: client-conf.o
@@ -28,8 +26,12 @@ server-arg: server-arg.o
2826
server-cmod: server-cmod.o
2927
server-conf: server-conf.o
3028

31-
client-arg client-conf saccept sconnect server-arg server-cmod server-conf:
32-
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
29+
$(TESTS):
30+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
3331

3432
clean:
35-
$(RM) *.o client-arg client-conf saccept sconnect server-arg server-cmod server-conf
33+
$(RM) $(TESTS) *.o
34+
35+
test: all
36+
@echo "\nBIO tests:"
37+
@echo "skipped"

demos/bio/sconnect.c

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ int main(int argc, char *argv[])
3030
const char *hostport = HOSTPORT;
3131
const char *CAfile = CAFILE;
3232
const char *hostname;
33-
char *cp;
3433
BIO *out = NULL;
3534
char buf[1024 * 10], *p;
3635
SSL_CTX *ssl_ctx = NULL;

demos/cipher/Makefile

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
# Quick instruction:
2-
# To build against an OpenSSL built in the source tree, do this:
31
#
4-
# make OPENSSL_INCS_LOCATION=-I../../include OPENSSL_LIBS_LOCATION=-L../..
5-
#
6-
# To run the demos when linked with a shared library (default):
2+
# To run the demos when linked with a shared library (default) ensure that
3+
# libcrypto is on the library path. For example:
74
#
85
# LD_LIBRARY_PATH=../.. ./aesccm
9-
# LD_LIBRARY_PATH=../.. ./aesgcm
10-
# LD_LIBRARY_PATH=../.. ./aeskeywrap
11-
# LD_LIBRARY_PATH=../.. ./ariacbc
126

13-
CFLAGS = $(OPENSSL_INCS_LOCATION)
14-
LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto
7+
TESTS = aesccm \
8+
aesgcm \
9+
aeskeywrap \
10+
ariacbc
1511

16-
TESTS=aesccm aesgcm aeskeywrap ariacbc
12+
CFLAGS = -I../../include -g -Wall
13+
LDFLAGS = -L../..
14+
LDLIBS = -lcrypto
1715

1816
all: $(TESTS)
1917

@@ -22,11 +20,11 @@ aesgcm: aesgcm.o
2220
aeskeywrap: aeskeywrap.o
2321
ariacbc: ariacbc.o
2422

25-
aesccm aesgcm aeskeywrap ariacbc:
26-
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
23+
$(TESTS):
24+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
2725

2826
clean:
29-
$(RM) aesccm aesgcm aeskeywrap ariacbc *.o
27+
$(RM) $(TESTS) *.o
3028

3129
.PHONY: test
3230
test: all

demos/cipher/ariacbc.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ int aria_cbc_encrypt(void)
5858
EVP_CIPHER_CTX *ctx;
5959
EVP_CIPHER *cipher = NULL;
6060
int outlen, tmplen;
61-
size_t cbc_ivlen = sizeof(cbc_iv);
6261
unsigned char outbuf[1024];
63-
unsigned char outtag[16];
6462

6563
printf("ARIA CBC Encrypt:\n");
6664
printf("Plaintext:\n");
@@ -115,8 +113,7 @@ int aria_cbc_decrypt(void)
115113
int ret = 0;
116114
EVP_CIPHER_CTX *ctx;
117115
EVP_CIPHER *cipher = NULL;
118-
int outlen, tmplen, rv;
119-
size_t cbc_ivlen = sizeof(cbc_iv);
116+
int outlen, tmplen;
120117
unsigned char outbuf[1024];
121118

122119
printf("ARIA CBC Decrypt:\n");

demos/cms/Makefile

+14-4
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,28 @@ TESTS = cms_comp \
1515
cms_uncomp \
1616
cms_ver
1717

18-
CFLAGS = -I../../include -g
18+
CFLAGS = -I../../include -g -Wall
1919
LDFLAGS = -L../..
2020
LDLIBS = -lcrypto
2121

2222
all: $(TESTS)
2323

24+
cms_comp: cms_comp.o
25+
cms_ddec: cms_ddec.o
26+
cms_dec: cms_dec.o
27+
cms_denc: cms_denc.o
28+
cms_enc: cms_enc.o
29+
cms_sign: cms_sign.o
30+
cms_sign2: cms_sign2.o
31+
cms_uncomp: cms_uncomp.o
32+
cms_ver: cms_ver.o
33+
34+
$(TESTS):
35+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
36+
2437
clean:
2538
$(RM) $(TESTS) *.o
2639

27-
cms_%: cms_%.c
28-
$(CC) $(CFLAGS) $(LDFLAGS) -o "$@" "$<" $(LDLIBS)
29-
3040
test: all
3141
@echo "\nCMS tests:"
3242
LD_LIBRARY_PATH=../.. ./cms_enc

demos/cms/cms_ddec.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ int main(int argc, char **argv)
3434

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

37-
BIO_reset(tbio);
37+
if (BIO_reset(tbio) < 0)
38+
goto err;
3839

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

demos/cms/cms_dec.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ int main(int argc, char **argv)
3131

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

34-
BIO_reset(tbio);
34+
if (BIO_reset(tbio) < 0)
35+
goto err;
3536

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

demos/cms/cms_sign.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ int main(int argc, char **argv)
3838

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

41-
BIO_reset(tbio);
41+
if (BIO_reset(tbio) < 0)
42+
goto err;
4243

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

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

65-
if (!(flags & CMS_STREAM))
66-
BIO_reset(in);
66+
if (!(flags & CMS_STREAM)) {
67+
if (BIO_reset(in) < 0)
68+
goto err;
69+
}
6770

6871
/* Write out S/MIME message */
6972
if (!SMIME_write_CMS(out, cms, in, flags))

demos/cms/cms_sign2.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ int main(int argc, char **argv)
3030

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

33-
BIO_reset(tbio);
33+
if (BIO_reset(tbio) < 0)
34+
goto err;
3435

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

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

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

46-
BIO_reset(tbio);
47+
if (BIO_reset(tbio) < 0)
48+
goto err;
4749

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

demos/digest/Makefile

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
#
2-
# To run the demos when linked with a shared library (default):
2+
# To run the demos when linked with a shared library (default) ensure
3+
# that libcrypto is on the library path. For example:
34
#
45
# LD_LIBRARY_PATH=../.. ./EVP_MD_demo
56

6-
CFLAGS = -I../../include -g -Wall
7-
LDFLAGS = -L../..
8-
LDLIBS = -lcrypto
7+
TESTS = EVP_MD_demo \
8+
EVP_MD_stdin \
9+
EVP_MD_xof \
10+
BIO_f_md
911

10-
TESTS=EVP_MD_demo EVP_MD_stdin EVP_MD_xof BIO_f_md
12+
CFLAGS = -I../../include -g -Wall
13+
LDFLAGS = -L../..
14+
LDLIBS = -lcrypto
1115

1216
all: $(TESTS)
1317

14-
%.o: %.c
15-
$(CC) $(CFLAGS) -c $<
16-
1718
EVP_MD_demo: EVP_MD_demo.o
1819
EVP_MD_stdin: EVP_MD_stdin.o
1920
EVP_MD_xof: EVP_MD_xof.o
2021
BIO_f_md: BIO_f_md.o
2122

23+
$(TESTS):
24+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
25+
26+
clean:
27+
$(RM) *.o $(TESTS)
28+
2229
.PHONY: test
23-
# Since some of these tests use stdin we use the source file as stdin when running the exes
30+
# Since some of these tests use stdin, we use the source file as stdin
31+
# when running the tests
2432
test: all
2533
@echo "\nDigest tests:"
2634
@set -e; for tst in $(TESTS); do \
2735
echo "\n"$$tst; \
2836
cat $$tst.c | ./$$tst; \
2937
done
30-
31-
clean:
32-
$(RM) *.o $(TESTS)

demos/encode/Makefile

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
#
2-
# To run the demos when linked with a shared library (default):
2+
# To run the demos when linked with a shared library (default) ensure
3+
# that libcrypto is on the library path. For example:
34
#
45
# LD_LIBRARY_PATH=../.. ./rsa_encode
56

6-
CFLAGS = -I../../include -g -Wall
7-
LDFLAGS = -L../..
8-
LDLIBS = -lcrypto
7+
TESTS = ec_encode \
8+
rsa_encode
99

10-
TESTS=ec_encode rsa_encode
10+
CFLAGS = -I../../include -g -Wall
11+
LDFLAGS = -L../..
12+
LDLIBS = -lcrypto
1113

1214
all: $(TESTS)
1315

14-
%.o: %.c
15-
$(CC) $(CFLAGS) -c $<
16+
ec_encode: ec_encode.o
17+
rsa_encode: rsa_encode.o
1618

17-
%_encode: %_encode.o
18-
19-
test:
19+
$(TESTS):
20+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
2021

2122
clean:
2223
$(RM) *.o $(TESTS)
24+
25+
.PHONY: test
26+
test: all
27+
@echo "\nencode tests:"
28+
@echo "skipped"

demos/encrypt/Makefile

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#
2-
# To run the demos when linked with a shared library (default):
2+
# To run the demos when linked with a shared library (default) ensure
3+
# that libcrypto is on the library path. For example:
34
#
45
# LD_LIBRARY_PATH=../.. ./rsa_encrypt
56

6-
CFLAGS = -I../../include -g
7-
LDFLAGS = -L../..
8-
LDLIBS = -lcrypto
7+
TESTS = rsa_encrypt
98

10-
TESTS=rsa_encrypt
9+
CFLAGS = -I../../include -g -Wall
10+
LDFLAGS = -L../..
11+
LDLIBS = -lcrypto
1112

1213
all: $(TESTS)
1314

14-
%.o: %.c
15-
$(CC) $(CFLAGS) -c $<
16-
1715
rsa_encrypt: rsa_encrypt.o
1816

17+
$(TESTS):
18+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
19+
1920
clean:
2021
$(RM) *.o $(TESTS)
2122

demos/encrypt/rsa_encrypt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int do_encrypt(OSSL_LIB_CTX *libctx,
151151
return ret;
152152
}
153153

154-
static int do_decrypt(OSSL_LIB_CTX *libctx, const char *in, size_t in_len,
154+
static int do_decrypt(OSSL_LIB_CTX *libctx, const unsigned char *in, size_t in_len,
155155
unsigned char **out, size_t *out_len)
156156
{
157157
int ret = 0, public = 0;

0 commit comments

Comments
 (0)