diff --git a/inc/mesa_sts.h b/inc/mesa_sts.h index 2c0a8f5..ee56102 100644 --- a/inc/mesa_sts.h +++ b/inc/mesa_sts.h @@ -1,6 +1,31 @@ #ifndef _MESA_STS_H_ #define _MESA_STS_H_ +#define STS_RANDOM_JUDGE_NUM 15 + +#define STS_SET_FLAG(flag, idx) (flag |= (1 << idx)) +#define STS_TEST_FLAG(flag, idx) (flag & (1 << idx)) + +enum sts_random_judge_list_idx +{ + STS_FREQUENCY = 0, + STS_BLOCK_FREQUENCY, + STS_CUMULATIVE_SUMS, + STS_RUNS, + STS_LONGEST_RUN, + STS_RANK, + STS_NON_OVERLAPPING_TEMPLATE_MATCHING, + STS_OVERLAPPING_TEMPLATE_MATCHING, + STS_UNIVERSAL, + STS_RANDOM_EXCURSIONS, + STS_RANDOM_EXCURSIONS_VARIANT, + STS_POKER_DETECT, + STS_RUNS_DISTRIBUTION, + STS_SELF_CORRELATION, + STS_BINARY_DERIVATE, + STS_RANDOM_IDX_MAX +}; + struct sts_result { unsigned char frequency; unsigned char block_frequency; @@ -23,10 +48,10 @@ struct sts_result { extern "C" { #endif -int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result); +int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result, unsigned int random_judge_switch_flag); #ifdef __cplusplus } #endif -#endif /* _MESA_STS_H_ */ \ No newline at end of file +#endif /* _MESA_STS_H_ */ diff --git a/src/mesa_sts.c b/src/mesa_sts.c index 5a13d2b..f95ac89 100644 --- a/src/mesa_sts.c +++ b/src/mesa_sts.c @@ -3,7 +3,7 @@ #include "include/stat_fncs.h" #include "mesa_sts.h" -int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result) +int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_result* result, unsigned int random_judge_switch_flag) { TP tp; tp.n = datalen; @@ -25,25 +25,87 @@ int mesa_statistical_test_suite(void* data,unsigned int datalen, struct sts_resu bitsRead = 0; done = 0; done = convertToBits((BYTE*)data,datalen,tp.n,&num_0s,&num_1s,&bitsRead,epsilon); - result->frequency = Frequency(tp.n,epsilon); - result->block_frequency = BlockFrequency(tp.blockFrequencyBlockLength, tp.n,epsilon); - result->cumulative_sums = CumulativeSums(tp.n,epsilon); - result->runs = Runs(tp.n,epsilon); - result->longest_run = LongestRunOfOnes(tp.n,epsilon); - result->rank = Rank(tp.n,epsilon); + if (STS_TEST_FLAG(random_judge_switch_flag, STS_FREQUENCY)) + { + result->frequency = Frequency(tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_BLOCK_FREQUENCY)) + { + result->block_frequency = BlockFrequency(tp.blockFrequencyBlockLength, tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_CUMULATIVE_SUMS)) + { + result->cumulative_sums = CumulativeSums(tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_RUNS)) + { + result->runs = Runs(tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_LONGEST_RUN)) + { + result->longest_run = LongestRunOfOnes(tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_RANK)) + { + result->rank = Rank(tp.n,epsilon); + } + //result->discrete_fourier_transform = DiscreteFourierTransform(tp.n,epsilon);//cost too much time - result->non_overlapping_template_matching = NonOverlappingTemplateMatchings(tp.nonOverlappingTemplateBlockLength, tp.n,epsilon); - result->overlapping_template_matching = OverlappingTemplateMatchings(tp.overlappingTemplateBlockLength, tp.n,epsilon); - result->universal = Universal(tp.n,epsilon); + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_NON_OVERLAPPING_TEMPLATE_MATCHING)) + { + result->non_overlapping_template_matching = NonOverlappingTemplateMatchings(tp.nonOverlappingTemplateBlockLength, tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_OVERLAPPING_TEMPLATE_MATCHING)) + { + result->overlapping_template_matching = OverlappingTemplateMatchings(tp.overlappingTemplateBlockLength, tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_UNIVERSAL)) + { + result->universal = Universal(tp.n,epsilon); + } + //result->approximate_entropy = ApproximateEntropy(tp.approximateEntropyBlockLength, tp.n,epsilon);//cost too much time - result->random_excursions = RandomExcursions(tp.n,epsilon); - result->random_excursions_variant = RandomExcursionsVariant(tp.n,epsilon); + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_RANDOM_EXCURSIONS)) + { + result->random_excursions = RandomExcursions(tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_RANDOM_EXCURSIONS_VARIANT)) + { + result->random_excursions_variant = RandomExcursionsVariant(tp.n,epsilon); + } + //result->serial = Serial(tp.serialBlockLength,tp.n,epsilon);//cost too much time //sresult->linear_complexity = LinearComplexity(tp.linearComplexitySequenceLength, tp.n,epsilon);//cost too much time - result->poker_detect = PokerDetect(tp.PokerDetectMLength,tp.n,epsilon); - result->runs_distribution = RunsDistribution(tp.n,epsilon); - result->self_correlation = SelfCorrelation(tp.SelfCorrelationDLength,tp.n,epsilon); - result->binary_derivative = BinaryDerivate(tp.BinaryDerivateKLength,tp.n,epsilon,tp.n);//this function will change the value of epsilon, must be the last one + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_POKER_DETECT)) + { + result->poker_detect = PokerDetect(tp.PokerDetectMLength,tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_RUNS_DISTRIBUTION)) + { + result->runs_distribution = RunsDistribution(tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_SELF_CORRELATION)) + { + result->self_correlation = SelfCorrelation(tp.SelfCorrelationDLength,tp.n,epsilon); + } + + if (STS_TEST_FLAG(random_judge_switch_flag, STS_BINARY_DERIVATE)) + { + result->binary_derivative = BinaryDerivate(tp.BinaryDerivateKLength,tp.n,epsilon,tp.n);//this function will change the value of epsilon, must be the last one + } free(epsilon); epsilon = NULL;