Sign a line in open source

Suppose I have a program that generates a string. I want this string to be signed with the private key, so 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 to HIDE the line 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 (using C ++)?

(For C ++, I was thinking of some kind of preprocessor directive that generates some key at compile time.)

+4
source share
1 answer

Well, you can use the precompiler constant, which can be passed to your compiler with the -D flag in your Makefile .

Combined with this, you can use the configure script to generate the Makefile to compute and set this constant.

-D name = definition The contents of the definition are marked and processed as if they appeared during the third phase of translation in the '#define' directive. In particular, the definition will be truncated by inline newline characters. If you call the preprocessor from a shell or shell, you may need to use shell quotation syntax to protect characters such as spaces that make sense in shell syntax.

If you want to define a functionally similar macro on the command line, write its argument list with surrounding parentheses before the equal sign (if any). Brackets make sense for most shells, so you'll need to specify an option. With sh and csh, -D'name (args ...) = definition works.

http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html

+3
source

Source: https://habr.com/ru/post/1498586/


All Articles