Sign a string in an open source code
Suppose I have a program that generate a string. I want this string to be signed with a private key, such that I can be sure that the string was actually generated by the program and not in any other way.
The only way I can do this is by HIDING the string inside the code, but in the case of open source programs you need a way to insert this key only at compile time.
What is the best/easier way to achieve this task (using C++)?
(For C++ I was thinking at some preprocessor directive that generate some key at compile time.)
Well, you can use precompiler constant which could be passed to your compiler with -D flag in your Makefile.
In conjunction with this, you can use configure script to generate Makefile, to calculate and set this constant.
-D name=definition The contents of definition are tokenized and processed as if they appeared during translation phase three in a ‘#define’ directive. In particular, the definition will be truncated by embedded newline characters. If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax.
If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you will need to quote the option. With sh and csh, -D'name(args...)=definition' works.