美文网首页
CPU JITTER数据采集

CPU JITTER数据采集

作者: 遇银 | 来源:发表于2021-08-02 19:49 被阅读0次

    CPU JITTER v2.1.0

    #include<stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    #include "jitterentropy.h"
    
    #define SAMBLE_LENGTH  (1024*1024)
    
    
    int main(int argc, char**argv)
    {
        int ret = 0;
        FILE *fp = NULL;
        char fileName[100] = {0}; 
        struct rand_data *ec_nostir;
        int samble_size = 1;                /* 样本个数,默认1 */
        int samble_length = SAMBLE_LENGTH;  /* 样本长度 */
    
        if (argc == 3 )
        {
            samble_size = atoi(argv[1]);
            samble_length = atoi(argv[2]);
            
            printf("samble_size = %d, samble_length = %d\n", samble_size, samble_length);
        }
        
        /* 初始化 */
        ret = jent_entropy_init();
        if (ret) 
        {
            printf("The initialization failed with error code %d\n", ret);
            return ret;
        }
        
        /* 创建entropy_collect对象 */
        ec_nostir = jent_entropy_collector_alloc(1, 0);
        if(!ec_nostir)
        {
            printf("jent_entropy_collector_alloc failed \n");
            return 1;
        }
        
        /* 读取熵源,写入文件 */
        int i = 0;
        char tmp[samble_length];
        for(i = 0; i< samble_size; i++)
        {
            memset(tmp, 0, sizeof(tmp));
            jent_read_entropy(ec_nostir, tmp, sizeof(tmp));
            
            snprintf(fileName, sizeof(fileName), "cpujitter_samble_%d.bin", i);
            printf("filename = %s\n", fileName);
            fp = fopen(fileName, "w");
            fwrite(&tmp, sizeof(tmp), 1, fp);
            fclose(fp);
        }
        
        jent_entropy_collector_free(ec_nostir);
        
        
        
        return 0;
        
        
    }
    
    

    相关文章

      网友评论

          本文标题:CPU JITTER数据采集

          本文链接:https://www.haomeiwen.com/subject/femjvltx.html