CPU JITTER数据采集

2021-08-02  本文已影响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;
    
    
}

上一篇下一篇

猜你喜欢

热点阅读