Commit 66396ea3 authored by Niels Möller's avatar Niels Möller

* examples/rsa-sign.c: No need to include config.h. Use werror

instead of fprintf.
* examples/rsa-verify.c: Likewise.

Rev: src/nettle/examples/rsa-sign.c:1.3
Rev: src/nettle/examples/rsa-verify.c:1.2
parent 9ee93765
......@@ -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 */
......@@ -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 */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment