Is there any interest in getting pseudo random number generation using preprocessor at compile time into the Preprocessor library?

The complete code, approach and efficiency proofs I described in my blog: http://alexander-stoyan.blogspot.com/2012/07/getting-pseudo-random-numbers-a t.html Need your opinion regarding the relevance and the approach correctness of the feature. Thank you in advance.

AMDG On 07/12/2012 06:27 AM, Alexander Stoyan wrote:
The complete code, approach and efficiency proofs I described in my blog: http://alexander-stoyan.blogspot.com/2012/07/getting-pseudo-random-numbers-a t.html
Need your opinion regarding the relevance and the approach correctness of the feature.
While this is interesting, I'm not sure when I would ever need such a feature. In Christ, Steven Watanabe

For example, a protected code has to be surrounded by PROTECTION_START(level) ... PROTECTION_END() macros, where 'level' is a good candidate for being random at compile time. In general, this feature is very useful for many code obfuscation mechanisms. This is similar to __COUNTER__, though not everybody use __COUNTER__ but it doesn't make it useless. Thanks. -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Thursday, July 12, 2012 9:32 PM To: boost@lists.boost.org Subject: Re: [boost] Is there any interest in getting pseudo random number generation using preprocessor at compile time into the Preprocessor library? AMDG On 07/12/2012 06:27 AM, Alexander Stoyan wrote:
The complete code, approach and efficiency proofs I described in my blog:
http://alexander-stoyan.blogspot.com/2012/07/getting-pseudo-random-numbers-a
t.html
Need your opinion regarding the relevance and the approach correctness of the feature.
While this is interesting, I'm not sure when I would ever need such a feature. In Christ, Steven Watanabe _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

AMDG On 07/12/2012 01:02 PM, Alexander Stoyan wrote:
For example, a protected code has to be surrounded by PROTECTION_START(level) ... PROTECTION_END() macros, where 'level' is a good candidate for being random at compile time.
I don't have a clue what this macro does.
In general, this feature is very useful for many code obfuscation mechanisms.
Like what? Is the preprocessor really the best tool for obfuscating code?
This is similar to __COUNTER__, though not everybody use __COUNTER__ but it doesn't make it useless.
In preprocessor programming it's not uncommon to need /unique/ variable names, for which __COUNTER__ works quite well. I just don't really understand the need for a full PRNG. In Christ, Steven Watanabe

Well, just for example you're working on a secure app and you want to wrap each function with anti-debugging tricks, and let's say you have 10 inline functions that implement different anti-debugging tricks, and you want a random calls would be inserted with each new release of the app. Will you change calls manually with each new build all across the code manually, or it'll be easier to change PP_RAND_SEED value? VC example: //-------------------------------------------------------------------------- ------ // main.cpp #define PP_RAND_SEED 34523 inline void PreventDebugging_1() { puts(__FUNCTION__); } inline void PreventDebugging_2() { puts(__FUNCTION__); } inline void PreventDebugging_3() { puts(__FUNCTION__); } inline void PreventDebugging_4() { puts(__FUNCTION__); } inline void PreventDebugging_5() { puts(__FUNCTION__); } inline void PreventDebugging_6() { puts(__FUNCTION__); } inline void PreventDebugging_7() { puts(__FUNCTION__); } inline void PreventDebugging_8() { puts(__FUNCTION__); } inline void PreventDebugging_9() { puts(__FUNCTION__); } inline void PreventDebugging_10() { puts(__FUNCTION__); } class SecretLogic { public: void DoStuff1() { #include "abdg.h" // ... #include "abdg.h" } void DoStuff2() { #include "abdg.h" // ... #include "abdg.h" } void DoStuff3() { #include "abdg.h" // ... #include "abdg.h" } void DoStuff4() { #include "abdg.h" // ... #include "abdg.h" } }; int _tmain(int argc, _TCHAR* argv[]) { SecretLogic logic; logic.DoStuff1(); logic.DoStuff2(); logic.DoStuff3(); logic.DoStuff4(); return 0; } //-------------------------------------------------------------------------- ------ // adbg.h #pragma push_macro("PP_RAND_MIN") #pragma push_macro("PP_RAND_MAX") #ifdef PP_RAND_MIN #undef PP_RAND_MIN #endif #ifdef PP_RAND_MAX #undef PP_RAND_MAX #endif #define PP_RAND_MIN 1 #define PP_RAND_MAX 10 #include "pprand.h" #define PREVENT_DEBUGGING_(n) PreventDebugging_ ## n() #define PREVENT_DEBUGGING(n) PREVENT_DEBUGGING_(n) PREVENT_DEBUGGING(PP_RAND); #undef PP_RAND_MIN #undef PP_RAND_MAX #pragma pop_macro("PP_RAND_MAX") #pragma pop_macro("PP_RAND_MIN") //-------------------------------------------------------------------------- ------ // Output for PP_RAND_SEED=34523 //-------------------------------------------------------------------------- ------ PreventDebugging_6 PreventDebugging_3 PreventDebugging_7 PreventDebugging_4 PreventDebugging_9 PreventDebugging_8 PreventDebugging_4 PreventDebugging_5 //-------------------------------------------------------------------------- ------ // Output for PP_RAND_SEED=876 //-------------------------------------------------------------------------- ------ PreventDebugging_4 PreventDebugging_5 PreventDebugging_9 PreventDebugging_6 PreventDebugging_2 PreventDebugging_6 PreventDebugging_6 PreventDebugging_2 //-------------------------------------------------------------------------- ------ // Output for PP_RAND_SEED=9879 //-------------------------------------------------------------------------- ------ PreventDebugging_4 PreventDebugging_3 PreventDebugging_7 PreventDebugging_1 PreventDebugging_6 PreventDebugging_2 PreventDebugging_4 PreventDebugging_4 In fact, it is possible to create a simple shell script for C++ compiler response file generation where PP_RAND_SEED would take new random value prior to each new build. Thanks. -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Thursday, July 12, 2012 11:46 PM To: boost@lists.boost.org Subject: Re: [boost] Is there any interest in getting pseudo random number generation using preprocessor at compile time into the Preprocessor library? AMDG On 07/12/2012 01:02 PM, Alexander Stoyan wrote:
For example, a protected code has to be surrounded by PROTECTION_START(level) ... PROTECTION_END() macros, where 'level' is a good candidate for being random at compile time.
I don't have a clue what this macro does.
In general, this feature is very useful for many code obfuscation mechanisms.
Like what? Is the preprocessor really the best tool for obfuscating code?
This is similar to __COUNTER__, though not everybody use __COUNTER__ but it doesn't make it useless.
In preprocessor programming it's not uncommon to need /unique/ variable names, for which __COUNTER__ works quite well. I just don't really understand the need for a full PRNG. In Christ, Steven Watanabe _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi all, Does anyone else have any thoughts of the proposed feature or it the question can be considered closed? Thanks in advance. -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Thursday, July 12, 2012 11:46 PM To: boost@lists.boost.org Subject: Re: [boost] Is there any interest in getting pseudo random number generation using preprocessor at compile time into the Preprocessor library? AMDG On 07/12/2012 01:02 PM, Alexander Stoyan wrote:
For example, a protected code has to be surrounded by PROTECTION_START(level) ... PROTECTION_END() macros, where 'level' is a good candidate for being random at compile time.
I don't have a clue what this macro does.
In general, this feature is very useful for many code obfuscation mechanisms.
Like what? Is the preprocessor really the best tool for obfuscating code?
This is similar to __COUNTER__, though not everybody use __COUNTER__ but it doesn't make it useless.
In preprocessor programming it's not uncommon to need /unique/ variable names, for which __COUNTER__ works quite well. I just don't really understand the need for a full PRNG. In Christ, Steven Watanabe _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi Alexander, On Aug 17, 2012, at 5:35 AM, "Alexander Stoyan" <alexander.stoyan@gmail.com> wrote:
Does anyone else have any thoughts of the proposed feature or it the question can be considered closed?
I have a need for pseudorandom numbers at compile time to test compile-time graph algorithms; however I guess a template metaprogram rather than preprocessor metaprogram is sufficient for what I'm trying to do. Cheers, Gordon

Hi, Gordon.
On Aug 17, 2012, at 5:35 AM, "Alexander Stoyan" <alexander.stoyan@gmail.com> wrote: I have a need for pseudorandom numbers at compile time to test compile-time graph algorithms; however I guess a template metaprogram rather than preprocessor metaprogram is sufficient for what I'm trying to do.
If you need the compile-time pseudo-random numbers (rather than preprocess-time), constexpr is good for you want to do. Sprout.Random library provides a constexpr pseudo-random numbers and probability distributions. https://github.com/bolero-MURAKAMI/Sprout/tree/master/sprout/random For example: #include <sprout/random.hpp> using namespace sprout; constexpr auto prng = minstd_rand0(SPROUT_UNIQUE_SEED); constexpr auto dist = uniform_smallint<int>(1, 6); constexpr auto n0 = dist(prng); // returns pair of generated number and next generator. constexpr auto n1 = n0(); // call new generator. constexpr auto n2 = n1(); // call new generator. /*...*/ constexpr int v[] = { n0.result(), n1.result(), n2.result() /*, ...*/ }; You can also make a list of pseudo-random numbers in this way. :) #include <sprout/array.hpp> #include <sprout/algorithm.hpp> constexpr auto v2 = sprout::copy( random::begin(prng, dist), random::end(prng, dist), array<int, N>{{}} ); (I tested this on gcc4.7.1) I'm sorry if my English is hard to understand. Best regards.
participants (4)
-
Alexander Stoyan
-
Gordon Woodhull
-
MURAKAMI Genya
-
Steven Watanabe