demos: tidy up makefiles, fix warnings
authorJames Muir <james@openssl.org>
Fri, 10 Nov 2023 19:02:00 +0000 (14:02 -0500)
committerTomas Mraz <tomas@openssl.org>
Wed, 15 Nov 2023 07:43:23 +0000 (08:43 +0100)
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 https://github.com/openssl/openssl/pull/22698)

37 files changed:
demos/Makefile
demos/bio/Makefile
demos/bio/sconnect.c
demos/cipher/Makefile
demos/cipher/ariacbc.c
demos/cms/Makefile
demos/cms/cms_ddec.c
demos/cms/cms_dec.c
demos/cms/cms_sign.c
demos/cms/cms_sign2.c
demos/digest/Makefile
demos/encode/Makefile
demos/encrypt/Makefile
demos/encrypt/rsa_encrypt.c
demos/guide/Makefile
demos/http3/Makefile
demos/kdf/Makefile
demos/kdf/argon2.c
demos/kdf/hkdf.c
demos/kdf/pbkdf2.c
demos/kdf/scrypt.c
demos/keyexch/Makefile
demos/mac/Makefile
demos/pkey/EVP_PKEY_RSA_keygen.c
demos/pkey/Makefile
demos/signature/Makefile
demos/signature/rsa_pss_direct.c
demos/signature/rsa_pss_hash.c
demos/smime/Makefile [new file with mode: 0644]
demos/smime/smdec.c
demos/smime/smenc.c
demos/smime/smsign.c
demos/smime/smsign2.c
demos/smime/smver.c
demos/sslecho/Makefile [new file with mode: 0644]
demos/sslecho/main.c
demos/sslecho/makefile [deleted file]

index 4c807a0561a8381e887470d179936c4fd2aaf1b8..208249e0fd2cffeefa3f23073c1178de5e4c3158 100644 (file)
@@ -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 \
index ca4dee851fa68d219f3b45d3d6d07775b3987805..5171e75e5981d543c3eb175353e85dfce86e2e14 100644 (file)
@@ -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
@@ -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"
index 18f7007ce708725273bc14acca33ca4bd2ca12c9..ef0787c30e80bf71a4a3f920ce07ecf789ba9c80 100644 (file)
@@ -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;
index df6ebeb3b66c56946ce6a3f458c348f854cdedd4..cdd7736758f9c861e653bc350a90f2857da38c05 100644 (file)
@@ -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)
 
@@ -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
index f9898e12c798577633c269292ac94a5224a7218a..de84d995ec928381f2a6349dc55c535525475d90 100644 (file)
@@ -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");
@@ -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");
index 7c8f30d63207a3f89a82755918eb72633c964f5b..3d4cb90750622effd0ebc18b67345474e5e10fdf 100644 (file)
@@ -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
index f65a77e129dc2ef06b1362b75b2be595d7c106e2..d119e9722226fa88cab8c5f1d1aea57241cb8f29 100644 (file)
@@ -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);
 
index f64a68ab42bc8100a1ef3ef9bdf1165dc7f19ba6..b15885eb18fa894c380ac652b9e40e30d7eed5ce 100644 (file)
@@ -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);
 
index 35fc889f8001fab8c0c4641e1fc0c53d54bae9c1..31e71e8b636c93028c50803f8f789bd5666adb9f 100644 (file)
@@ -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);
 
@@ -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))
index 61d9f8bbe83ed83bad60aac582766b3a8c5ef045..af3386eb7634736e214fc0acd11c73fe6ec87c5a 100644 (file)
@@ -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);
 
@@ -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);
 
index d72a9d095b5fc74215c449f596eaea59129da5f6..05fb299cc3d62be7cce9a761c2b525a373c6d835 100644 (file)
@@ -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)
index 9be11794b0082acdb92e97956d3e2630191c2709..dc556a524a0ce8b94fd85f4650bfbae4dc7f3868 100644 (file)
@@ -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"
index 6d4e0606685ed0ada46afe209b8a08d5f1100c14..378d277d21c80d93f59ceb49a733c9425f52d4d9 100644 (file)
@@ -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)
 
index e3d8981e413eaf3372a5dd1fd6fb6b20a156ec52..d95b98551158ef976261f4ae6b13190bd0e82b23 100644 (file)
@@ -151,7 +151,7 @@ cleanup:
     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;
index d12d6c0cad9445adc16a0c97c78ffabf21cb5358..29a0fd56e407280581bcc0701a7227dff94c561c 100644 (file)
@@ -1,32 +1,34 @@
 #
 # To run the demos when linked with a shared library (default) ensure that
-# libcrypto and libssl are on the library path. For example to run the
-# tls-client-block demo:
+# libcrypto and libssl are on the library path. For example:
 #
-#    LD_LIBRARY_PATH=../.. ./tls-client-block
+#    LD_LIBRARY_PATH=../.. ./tls-client-block www.example.com 443
 
-CFLAGS = -I../../include -g
-LDFLAGS = -L../..
-LDLIBS = -lcrypto -lssl
-
-all: tls-client-block quic-client-block quic-multi-stream tls-client-non-block \
-     quic-client-non-block
+TESTS = tls-client-block \
+        quic-client-block \
+        quic-multi-stream \
+        tls-client-non-block \
+        quic-client-non-block
 
-tls-client-block: tls-client-block.c
-       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
-
-quic-client-block: quic-client-block.c
-       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lcrypto -lssl
 
-quic-multi-stream: quic-multi-stream.c
-       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+all: $(TESTS)
 
-tls-client-non-block: tls-client-non-block.c
-       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+tls-client-block: tls-client-block.o
+quic-client-block: quic-client-block.o
+quic-multi-stream: quic-multi-stream.o
+tls-client-non-block: tls-client-non-block.o
+quic-client-non-block: quic-client-non-block.o
 
-quic-client-non-block: quic-client-non-block.c
+$(TESTS):
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
 
 clean:
-       $(RM) *.o tls-client-block quic-client-block quic-multi-stream \
-             tls-client-non-block quic-client-non-block
+       $(RM) $(TESTS) *.o
+
+.PHONY: test
+test: all
+       @echo "\nTLS and QUIC tests:"
+       @echo "skipped"
index 9d8212ff0a87b6470df73eede14aa3a65184de26..aeff1e9e4f70e55128317939ea471d0561bfbd06 100644 (file)
@@ -10,11 +10,13 @@ LDLIBS  = -lcrypto -lssl -lnghttp3
 
 all: ossl-nghttp3-demo
 
+ossl-nghttp3-demo: ossl-nghttp3-demo.o ossl-nghttp3.o
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
 clean:
        $(RM) ossl-nghttp3-demo *.o
 
-ossl-nghttp3-demo: ossl-nghttp3-demo.o ossl-nghttp3.o
-       $(CC) $(CFLAGS) -o "$@" $^ $(LDFLAGS) $(LDLIBS)
-
-%.o: %.c
-       $(CC) $(CFLAGS) -c -o "$@" "$<"
+.PHONY: test
+test: all
+       @echo "\nHTTP/3 tests:"
+       @echo "skipped"
index 28ad7209b10cb18cb1b9010b0d67a27d37bbfbb6..81efbeeff7b93cf765691a2b12310c125b56f08a 100644 (file)
@@ -1,24 +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=../.. ./hkdf
 
-CFLAGS = -I../../include -g
-LDFLAGS = -L../..
-LDLIBS = -lcrypto
+TESTS = hkdf \
+        pbkdf2 \
+        scrypt \
+        argon2
 
-TESTS=hkdf pbkdf2 scrypt argon2
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lcrypto
 
 all: $(TESTS)
 
-%.o: %.c
-       $(CC) $(CFLAGS) -c $<
-
 hkdf: hkdf.o
 pbkdf2: pbkdf2.o
 scrypt: scrypt.o
 argon2: argon2.o
 
+$(TESTS):
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+
 clean:
        $(RM) *.o $(TESTS)
 
index b6a15903287623f13ba1302346910f9191b0b721..6c542d54edcbd98d7309fe4b12d73d98a3fafd7b 100644 (file)
@@ -145,6 +145,8 @@ int main(int argc, char **argv)
         goto end;
     }
 
+    printf("Success\n");
+
     rv = EXIT_SUCCESS;
 end:
     EVP_KDF_CTX_free(kctx);
index 8d7c436575fd6bc25c451d93358b7db3fe430538..9818d61afe6b8384ac20b99c75583eb8403128f6 100644 (file)
@@ -95,6 +95,8 @@ int main(int argc, char **argv)
         goto end;
     }
 
+    printf("Success\n");
+
     ret = EXIT_SUCCESS;
 end:
     EVP_KDF_CTX_free(kctx);
index ae9a9d726c1252bf662ded10c9f3d1eaf48ce9e9..28a075513c251ade562993ec1770236fb68f79fa 100644 (file)
@@ -108,6 +108,8 @@ int main(int argc, char **argv)
         goto end;
     }
 
+    printf("Success\n");
+
     ret = EXIT_SUCCESS;
 end:
     EVP_KDF_CTX_free(kctx);
index 5c07ebffbdddb48e6413a5b85591ca535a2c2faf..a1c33f59638b4562509b6e2900aa86842b93b79c 100644 (file)
@@ -111,6 +111,8 @@ int main(int argc, char **argv)
         goto end;
     }
 
+    printf("Success\n");
+
     ret = EXIT_SUCCESS;
 end:
     EVP_KDF_CTX_free(kctx);
index 24243e13a4a62a1df329a73163785af4426c79a4..f8018a13df2296e97976a2df207fb063e8ae0668 100644 (file)
@@ -1,20 +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=../.. ./x25519
 
-CFLAGS = -I../../include -g -Wall
-LDFLAGS = -L../..
-LDLIBS = -lcrypto
+TESTS = x25519
 
-TESTS=x25519
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lcrypto
 
 all: $(TESTS)
 
-%.o: %.c
-       $(CC) $(CFLAGS) -c $<
+x25519: x25519.o
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-%x25519: %x25519.o
+clean:
+       $(RM) *.o $(TESTS)
 
 .PHONY: test
 test: all
@@ -23,6 +25,3 @@ test: all
                echo "\n"$$tst; \
                LD_LIBRARY_PATH=../.. ./$$tst; \
        done
-
-clean:
-       $(RM) *.o $(TESTS)
index 629e77dfc2da4c1b72ed9c69b08be59f3ef4e964..6c870a3d4562e00ab91864e5aafb683e6737929c 100644 (file)
@@ -1,17 +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=../.. ./gmac
-#    LD_LIBRARY_PATH=../.. ./poly1305
 
-CFLAGS = $(OPENSSL_INCS_LOCATION) -Wall
-LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto
+TESTS = gmac \
+        hmac-sha512 \
+        cmac-aes256 \
+        poly1305
 
-TESTS=gmac hmac-sha512 cmac-aes256 poly1305
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lcrypto
 
 all: $(TESTS)
 
@@ -20,8 +20,8 @@ hmac-sha512: hmac-sha512.o
 cmac-aes256: cmac-aes256.o
 poly1305: poly1305.o
 
-gmac hmac-sha512 cmac-aes256 poly1305:
-       $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+$(TESTS):
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
 
 clean:
        $(RM) *.o $(TESTS)
index 353c08152c04800f45792dfa86b187987aaf58d1..62dd8405e77be20ad4c048d75780e48526fe2750 100644 (file)
@@ -83,7 +83,7 @@ static EVP_PKEY *generate_rsa_key_long(OSSL_LIB_CTX *libctx, unsigned int bits)
      * you can set a progress callback using EVP_PKEY_set_cb; see the example in
      * EVP_PKEY_generate(3).
      */
-    fprintf(stderr, "Generating RSA key, this may take some time...\n");
+    fprintf(stdout, "Generating RSA key, this may take some time...\n");
     if (EVP_PKEY_generate(genctx, &pkey) <= 0) {
         fprintf(stderr, "EVP_PKEY_generate() failed\n");
         goto cleanup;
@@ -109,7 +109,7 @@ static EVP_PKEY *generate_rsa_key_short(OSSL_LIB_CTX *libctx, unsigned int bits)
 {
     EVP_PKEY *pkey = NULL;
 
-    fprintf(stderr, "Generating RSA key, this may take some time...\n");
+    fprintf(stdout, "Generating RSA key, this may take some time...\n");
     pkey = EVP_PKEY_Q_keygen(libctx, propq, "RSA", (size_t)bits);
 
     if (pkey == NULL)
@@ -189,7 +189,7 @@ static int dump_key(const EVP_PKEY *pkey)
 
     /* Output hexadecimal representations of the BIGNUM objects. */
     fprintf(stdout, "\nNumber of bits: %d\n\n", bits);
-    fprintf(stderr, "Public values:\n");
+    fprintf(stdout, "Public values:\n");
     fprintf(stdout, "  n = 0x");
     BN_print_fp(stdout, n);
     fprintf(stdout, "\n");
index d84fcd634f6ff63f6b8e34e005c30d6e7a7000e6..e7859641870ad043fd0c416607fe3adb63f0259b 100644 (file)
@@ -1,37 +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_PKEY_EC_keygen
-#    LD_LIBRARY_PATH=../.. ./EVP_PKEY_RSA_keygen
-#    LD_LIBRARY_PATH=../.. ./EVP_PKEY_DSA_keygen
-#    LD_LIBRARY_PATH=../.. ./EVP_PKEY_DSA_paramgen
-#    LD_LIBRARY_PATH=../.. ./EVP_PKEY_DSA_paramvalidate
-#    LD_LIBRARY_PATH=../.. ./EVP_PKEY_DSA_paramfromdata
 
-CFLAGS = -I../../include -g -Wall
-LDFLAGS = -L../..
-LDLIBS = -lcrypto
+TESTS = EVP_PKEY_EC_keygen \
+        EVP_PKEY_RSA_keygen \
+        EVP_PKEY_DSA_keygen \
+        EVP_PKEY_DSA_paramgen \
+        EVP_PKEY_DSA_paramvalidate \
+        EVP_PKEY_DSA_paramfromdata
 
-TESTS=EVP_PKEY_EC_keygen EVP_PKEY_RSA_keygen EVP_PKEY_DSA_keygen \
-EVP_PKEY_DSA_paramgen EVP_PKEY_DSA_paramvalidate EVP_PKEY_DSA_paramfromdata
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lcrypto
 
 all: $(TESTS)
 
-%.o: %.c dsa.inc
-       $(CC) $(CFLAGS) -c $<
+EVP_PKEY_DSA_keygen.o: EVP_PKEY_DSA_keygen.c dsa.inc
+EVP_PKEY_DSA_paramgen.o: EVP_PKEY_DSA_paramgen.c dsa.inc
+EVP_PKEY_DSA_paramvalidate.o: EVP_PKEY_DSA_paramvalidate.c dsa.inc
+EVP_PKEY_DSA_paramfromdata.o: EVP_PKEY_DSA_paramfromdata.c dsa.inc
 
 EVP_PKEY_EC_keygen: EVP_PKEY_EC_keygen.o
-
 EVP_PKEY_RSA_keygen: EVP_PKEY_RSA_keygen.o
-
 EVP_PKEY_DSA_keygen: EVP_PKEY_DSA_keygen.o
-
 EVP_PKEY_DSA_paramgen: EVP_PKEY_DSA_paramgen.o
-
 EVP_PKEY_DSA_paramvalidate: EVP_PKEY_DSA_paramvalidate.o
-
 EVP_PKEY_DSA_paramfromdata: EVP_PKEY_DSA_paramfromdata.o
 
+$(TESTS):
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+
 clean:
        $(RM) *.o $(TESTS)
 
index 50f1c3452d4dbc8eac7f2e37d72aa3f9744716c8..4f02b07d73791c9d87ea123e148cf8232eec5064 100644 (file)
@@ -1,29 +1,30 @@
 #
-# 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_EC_Signature_demo
-#    LD_LIBRARY_PATH=../.. ./EVP_DSA_Signature_demo
-#    LD_LIBRARY_PATH=../.. ./EVP_ED_Signature_demo
-#    LD_LIBRARY_PATH=../.. ./rsa_pss_direct
-#    LD_LIBRARY_PATH=../.. ./rsa_pss_hash
 
-CFLAGS = -I../../include -g -Wall
-LDFLAGS = -L../..
-LDLIBS = -lcrypto
+TESTS = EVP_EC_Signature_demo \
+        EVP_DSA_Signature_demo \
+        EVP_ED_Signature_demo \
+        rsa_pss_direct \
+        rsa_pss_hash
 
-TESTS=EVP_EC_Signature_demo EVP_DSA_Signature_demo EVP_ED_Signature_demo rsa_pss_direct rsa_pss_hash
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lcrypto
 
 all: $(TESTS)
 
-%.o: %.c
-       $(CC) $(CFLAGS) -c $<
-
 EVP_EC_Signature_demo: EVP_EC_Signature_demo.o
 EVP_DSA_Signature_demo: EVP_DSA_Signature_demo.o
 EVP_ED_Signature_demo: EVP_ED_Signature_demo.o
 rsa_pss_direct: rsa_pss_direct.o
 rsa_pss_hash: rsa_pss_hash.o
 
+$(TESTS):
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+
 clean:
        $(RM) *.o $(TESTS)
 
index 41d8c2211df360b8a979b490b287fdd398a8e58b..097ad69f24b611ca4e700f1f2222d5808f1859f1 100644 (file)
@@ -196,6 +196,8 @@ int main(int argc, char **argv)
     if (verify(libctx, sig, sig_len) == 0)
         goto end;
 
+    printf("Success\n");
+
     ret = EXIT_SUCCESS;
 end:
     OPENSSL_free(sig);
index a84df8ab626d82b8b8fdf5a2bdda81c8d7818339..57d5c5ae195cc4d066e5b5c12ee1ed4727d4a933 100644 (file)
@@ -181,6 +181,8 @@ int main(int argc, char **argv)
     if (verify(libctx, sig, sig_len) == 0)
         goto end;
 
+    printf("Success\n");
+
     ret = EXIT_SUCCESS;
 end:
     OPENSSL_free(sig);
diff --git a/demos/smime/Makefile b/demos/smime/Makefile
new file mode 100644 (file)
index 0000000..449efd6
--- /dev/null
@@ -0,0 +1,37 @@
+#
+# To run the demos when linked with a shared library (default) ensure that
+# libcrypto is on the library path. For example, to run the
+# sm_enc demo:
+#
+#    LD_LIBRARY_PATH=../.. ./sms_enc
+
+TESTS = smenc \
+        smdec \
+        smsign \
+        smsign2 \
+        smver
+
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lcrypto
+
+all: $(TESTS)
+
+smenc: smenc.o
+smdec: smdec.o
+smsign: smsign.o
+smsign2: smsign2.o
+smver: smver.o
+
+$(TESTS):
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+
+clean:
+       $(RM) $(TESTS) *.o
+
+test: all
+       @echo "\nS/MIME tests:"
+       LD_LIBRARY_PATH=../.. ./smenc
+       LD_LIBRARY_PATH=../.. ./smdec
+       LD_LIBRARY_PATH=../.. ./smsign2
+       LD_LIBRARY_PATH=../.. ./smver
index 7cf66f1dcd8133af27631454b44f0de6ca9a5143..f27c353f4046e27d8ba6f29b46cd78a955ad64bf 100644 (file)
@@ -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);
 
@@ -59,8 +60,9 @@ int main(int argc, char **argv)
     if (!PKCS7_decrypt(p7, rkey, rcert, out, 0))
         goto err;
 
-    ret = EXIT_SUCCESS;
+    printf("Success\n");
 
+    ret = EXIT_SUCCESS;
  err:
     if (ret != EXIT_SUCCESS) {
         fprintf(stderr, "Error Signing Data\n");
@@ -74,5 +76,4 @@ int main(int argc, char **argv)
     BIO_free(tbio);
 
     return ret;
-
 }
index 3e3f34d1cf354b65b1022aa6cd524a929bd92790..2113e12d1cdaf2de1e2414173c8329a4b4fc5e4c 100644 (file)
@@ -21,7 +21,6 @@ int main(int argc, char **argv)
     int ret = EXIT_FAILURE;
 
     /*
-     * On OpenSSL 0.9.9 only:
      * for streaming set PKCS7_STREAM
      */
     int flags = PKCS7_STREAM;
@@ -73,8 +72,9 @@ int main(int argc, char **argv)
     if (!SMIME_write_PKCS7(out, p7, in, flags))
         goto err;
 
-    ret = EXIT_SUCCESS;
+    printf("Success\n");
 
+    ret = EXIT_SUCCESS;
  err:
     if (ret != EXIT_SUCCESS) {
         fprintf(stderr, "Error Encrypting Data\n");
@@ -87,5 +87,4 @@ int main(int argc, char **argv)
     BIO_free(out);
     BIO_free(tbio);
     return ret;
-
 }
index 4ce671d05ceeb88b290cd04b46824e563b2d3179..3e27c931f6be1b129d9640c404ee1b6fa2c7b68d 100644 (file)
@@ -21,7 +21,7 @@ int main(int argc, char **argv)
     int ret = EXIT_FAILURE;
 
     /*
-     * For simple S/MIME signing use PKCS7_DETACHED. On OpenSSL 0.9.9 only:
+     * For simple S/MIME signing use PKCS7_DETACHED.
      * for streaming detached set PKCS7_DETACHED|PKCS7_STREAM for streaming
      * non-detached set PKCS7_STREAM
      */
@@ -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);
 
@@ -62,15 +63,18 @@ int main(int argc, char **argv)
     if (!out)
         goto err;
 
-    if (!(flags & PKCS7_STREAM))
-        BIO_reset(in);
+    if (!(flags & PKCS7_STREAM)) {
+        if (BIO_reset(in) < 0)
+            goto err;
+    }
 
     /* Write out S/MIME message */
     if (!SMIME_write_PKCS7(out, p7, in, flags))
         goto err;
 
-    ret = EXIT_SUCCESS;
+    printf("Success\n");
 
+    ret = EXIT_SUCCESS;
  err:
     if (ret != EXIT_SUCCESS) {
         fprintf(stderr, "Error Signing Data\n");
@@ -84,5 +88,4 @@ int main(int argc, char **argv)
     BIO_free(tbio);
 
     return ret;
-
 }
index 4e62c6b82cc8c1b3d46d5177a5579f85618a7607..5ad86f15f86e1a018505e3812ef5aa353b9a6440 100644 (file)
@@ -7,7 +7,7 @@
  * https://www.openssl.org/source/license.html
  */
 
-/* S/MIME signing example: 2 signers. OpenSSL 0.9.9 only */
+/* S/MIME signing example: 2 signers */
 #include <openssl/pem.h>
 #include <openssl/pkcs7.h>
 #include <openssl/err.h>
@@ -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);
 
@@ -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);
 
@@ -77,8 +79,9 @@ int main(int argc, char **argv)
     if (!SMIME_write_PKCS7(out, p7, in, PKCS7_STREAM))
         goto err;
 
-    ret = EXIT_SUCCESS;
+    printf("Success\n");
 
+    ret = EXIT_SUCCESS;
  err:
     if (ret != EXIT_SUCCESS) {
         fprintf(stderr, "Error Signing Data\n");
index 2e55c72584e26dc52605298e02e9d8f2a045ab13..caa9ed304ff05cc2d271b624fe46d12ff348cd79 100644 (file)
@@ -66,10 +66,9 @@ int main(int argc, char **argv)
         goto err;
     }
 
-    fprintf(stderr, "Verification Successful\n");
+    printf("Verification Successful\n");
 
     ret = EXIT_SUCCESS;
-
  err:
     if (ret != EXIT_SUCCESS) {
         fprintf(stderr, "Error Verifying Data\n");
diff --git a/demos/sslecho/Makefile b/demos/sslecho/Makefile
new file mode 100644 (file)
index 0000000..defb159
--- /dev/null
@@ -0,0 +1,25 @@
+#
+# 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=../.. ./sslecho
+
+TESTS = sslecho
+
+CFLAGS  = -I../../include -g -Wall
+LDFLAGS = -L../..
+LDLIBS  = -lssl -lcrypto
+
+all: $(TESTS)
+
+sslecho: main.o
+
+$(TESTS):
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
+
+clean:
+       $(RM) $(TESTS) *.o
+
+test: all
+       @echo "\nSSL Echo tests:"
+       @echo "skipped"
index 8cf774450171cc5305b6436cd1e5cf23f282fd6c..20b018c7a1c9709f45c78187e2c2af9f3e055321 100644 (file)
@@ -156,7 +156,7 @@ int main(int argc, char **argv)
     signal(SIGPIPE, SIG_IGN);
 
     /* Splash */
-    printf("\nsslecho : Simple Echo Client/Server (OpenSSL 3.0.1-dev) : %s : %s\n\n", __DATE__,
+    printf("\nsslecho : Simple Echo Client/Server : %s : %s\n\n", __DATE__,
     __TIME__);
 
     /* Need to know if client or server */
diff --git a/demos/sslecho/makefile b/demos/sslecho/makefile
deleted file mode 100644 (file)
index 1e91567..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-PROG ?= sslecho
-
-all: $(PROG)
-
-# Debug version.
-#
-$(PROG): main.c
-
-       $(CC) -O0 -g3 -W -Wall -I../../include -L../../ -o $(PROG) main.c -lssl -lcrypto
-
-test:
-
-clean:
-       rm -rf $(PROG) *.o *.obj