5 /* nettle, low-level cryptographics library
7 * Copyright (C) 2002 Niels Möller
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,
38 read_signature(const char *name
, mpz_t s
)
44 length
= read_file(name
, 0, &buffer
);
48 res
= (mpz_set_str(s
, buffer
, 16) == 0);
55 main(int argc
, char **argv
)
57 struct rsa_public_key key
;
63 werror("Usage: rsa-verify PUBLIC-KEY SIGNATURE-FILE < FILE\n");
67 rsa_public_key_init(&key
);
69 if (!read_rsa_key(argv
[1], &key
, NULL
))
71 werror("Invalid key\n");
77 if (!read_signature(argv
[2], s
))
79 werror("Failed to read signature file `%s'\n",
85 if (!hash_file(&nettle_sha1
, &hash
, stdin
))
87 werror("Failed reading stdin: %s\n",
92 if (!rsa_sha1_verify(&key
, &hash
, s
))
94 werror("Invalid signature!\n");
99 rsa_public_key_clear(&key
);