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