diff --git a/examples/rsa-sign.c b/examples/rsa-sign.c index 2645af4404b92de6a8671f25c9f2905485bd547d..a96d3b1e6f9d56a718f5a55fba663849d351619d 100644 --- a/examples/rsa-sign.c +++ b/examples/rsa-sign.c @@ -22,26 +22,12 @@ * MA 02111-1307, USA. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif /* HAVE_CONFIG_H */ - -#if !WITH_PUBLIC_KEY -int -main(int argc, char **argv) -{ - fprintf(stderr, - "You need to install GMP somewhere where Nettle can find it,\n" - "and recompile Nettle\n"); - return EXIT_FAILURE; -} -#else /* WITH_PUBLIC_KEY */ - #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +/* string.h must be included before gmp.h */ #include "rsa.h" #include "io.h" @@ -54,7 +40,7 @@ main(int argc, char **argv) if (argc != 2) { - fprintf(stderr, "Usage: rsa-sign PRIVATE-KEY < file\n"); + werror("Usage: rsa-sign PRIVATE-KEY < file\n"); return EXIT_FAILURE; } @@ -62,14 +48,14 @@ main(int argc, char **argv) if (!read_rsa_key(argv[1], NULL, &key)) { - fprintf(stderr, "Invalid key\n"); + werror("Invalid key\n"); return EXIT_FAILURE; } sha1_init(&hash); if (!hash_file(&nettle_sha1, &hash, stdin)) { - fprintf(stderr, "Failed reading stdin: %s\n", + werror("Failed reading stdin: %s\n", strerror(errno)); return 0; } @@ -79,7 +65,7 @@ main(int argc, char **argv) if (!mpz_out_str(stdout, 16, s)) { - fprintf(stderr, "Failed writing signature: %s\n", + werror("Failed writing signature: %s\n", strerror(errno)); return 0; } @@ -91,4 +77,3 @@ main(int argc, char **argv) return EXIT_SUCCESS; } -#endif /* WITH_PUBLIC_KEY */ diff --git a/examples/rsa-verify.c b/examples/rsa-verify.c index 77e25694c5b8912f2ee7fbdc03cd266a1e1a1027..5dcd90b248965d441ecf7fa5343f23a93190783c 100644 --- a/examples/rsa-verify.c +++ b/examples/rsa-verify.c @@ -22,29 +22,15 @@ * MA 02111-1307, USA. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif /* HAVE_CONFIG_H */ -#if !WITH_PUBLIC_KEY -int -main(int argc, char **argv) -{ - fprintf(stderr, - "You need to install GMP somewhere where Nettle can find it,\n" - "and recompile Nettle\n"); - return EXIT_FAILURE; -} -#else /* WITH_PUBLIC_KEY */ +#include "rsa.h" +#include "io.h" #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> -#include "rsa.h" -#include "io.h" - static int read_signature(const char *name, mpz_t s) { @@ -71,7 +57,7 @@ main(int argc, char **argv) if (argc != 3) { - fprintf(stderr, "Usage: rsa-sign PUBLIC-KEY SIGNATURE-FILE < file\n"); + werror("Usage: rsa-sign PUBLIC-KEY SIGNATURE-FILE < file\n"); return EXIT_FAILURE; } @@ -79,7 +65,7 @@ main(int argc, char **argv) if (!read_rsa_key(argv[1], &key, NULL)) { - fprintf(stderr, "Invalid key\n"); + werror("Invalid key\n"); return EXIT_FAILURE; } @@ -87,7 +73,7 @@ main(int argc, char **argv) if (!read_signature(argv[2], s)) { - fprintf(stderr, "Failed to read signature file `%s'\n", + werror("Failed to read signature file `%s'\n", argv[2]); return EXIT_FAILURE; } @@ -95,14 +81,14 @@ main(int argc, char **argv) sha1_init(&hash); if (!hash_file(&nettle_sha1, &hash, stdin)) { - fprintf(stderr, "Failed reading stdin: %s\n", + werror("Failed reading stdin: %s\n", strerror(errno)); return 0; } if (!rsa_sha1_verify(&key, &hash, s)) { - fprintf(stderr, "Invalid signature!\n"); + werror("Invalid signature!\n"); return EXIT_FAILURE; } @@ -111,4 +97,3 @@ main(int argc, char **argv) return EXIT_SUCCESS; } -#endif /* WITH_PUBLIC_KEY */