a458c16742bb5940403bf7be35e59d80b446ee97
[strongswan.git] / src / libstrongswan / fips / fips_signer.c
1 /*
2 * Copyright (C) 2007 Bruno Krieg, Daniel Wydler
3 * Hochschule fuer Technik Rapperswil, Switzerland
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include <stdio.h>
19
20 #include <crypto/hashers/hasher.h>
21 #include "fips.h"
22
23 int main(int argc, char* argv[])
24 {
25 FILE *f;
26 char *hmac_key = "strongSwan Version " VERSION;
27 char hmac_signature[BUF_LEN];
28
29 /* initialize library */
30 library_init(STRONGSWAN_CONF);
31 lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, "libstrongswan-");
32
33 if (!fips_compute_hmac_signature(hmac_key, hmac_signature))
34 {
35 exit(1);
36 }
37
38 /**
39 * write computed HMAC signature to fips_signature.h
40 */
41 f = fopen("fips_signature.h", "wt");
42
43 if (f == NULL)
44 {
45 exit(1);
46 }
47 fprintf(f, "/* SHA-1 HMAC signature computed over TEXT and RODATA of libstrongswan\n");
48 fprintf(f, " *\n");
49 fprintf(f, " * This file has been automatically generated by fips_signer\n");
50 fprintf(f, " * Do not edit manually!\n");
51 fprintf(f, " */\n");
52 fprintf(f, "\n");
53 fprintf(f, "#ifndef FIPS_SIGNATURE_H_\n");
54 fprintf(f, "#define FIPS_SIGNATURE_H_\n");
55 fprintf(f, "\n");
56 fprintf(f, "const char *hmac_key = \"%s\";\n", hmac_key);
57 fprintf(f, "const char *hmac_signature = \"%s\";\n", hmac_signature);
58 fprintf(f, "\n");
59 fprintf(f, "#endif /* FIPS_SIGNATURE_H_ @} */\n");
60 fclose(f);
61
62 library_deinit();
63 exit(0);
64 }