Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / examples / rsa-sign.c
blobc1894c36ec55c144b4e1892fcdfacf1003e0133b
1 /* rsa-sign.c
3 */
5 /* nettle, low-level cryptographics library
7 * Copyright (C) 2002 Niels Möller
8 *
9 * The nettle library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or (at your
12 * option) any later version.
14 * The nettle library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the nettle library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * MA 02111-1301, USA.
25 #if HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
34 /* string.h must be included before gmp.h */
35 #include "rsa.h"
36 #include "io.h"
38 int
39 main(int argc, char **argv)
41 struct rsa_private_key key;
42 struct sha1_ctx hash;
43 mpz_t s;
45 if (argc != 2)
47 werror("Usage: rsa-sign PRIVATE-KEY < file\n");
48 return EXIT_FAILURE;
51 rsa_private_key_init(&key);
53 if (!read_rsa_key(argv[1], NULL, &key))
55 werror("Invalid key\n");
56 return EXIT_FAILURE;
59 sha1_init(&hash);
60 if (!hash_file(&nettle_sha1, &hash, stdin))
62 werror("Failed reading stdin: %s\n",
63 strerror(errno));
64 return 0;
67 mpz_init(s);
68 if (!rsa_sha1_sign(&key, &hash, s))
70 werror("RSA key too small\n");
71 return 0;
74 if (!mpz_out_str(stdout, 16, s))
76 werror("Failed writing signature: %s\n",
77 strerror(errno));
78 return 0;
81 putchar('\n');
83 mpz_clear(s);
84 rsa_private_key_clear(&key);
86 return EXIT_SUCCESS;