PBC庫傳入引數檔案問題
阿新 • • 發佈:2018-11-07
配置不同型別的橢圓曲線,需要修改配對型別。
PBC的param目錄下有好多種:
PBC手冊是這樣寫的
Chapter 5. Param functions
Pairings are initialized from pairing parameters, which are objects of type pbc_param_t. Some applications can ignore this data type because pairing_init_set_str() handles it behind the scenes:it reads a string as a pbc_param_t, then initializes a pairing with these parameters.- int pbc_param_init_set_str(pbc_param_t par, const char *s)
- int pbc_param_init_set_buf(pbc_param_t par, const char *s, size_t len)
Same, but read at most len bytes. If len is 0, it behaves as the previous function. Returns 0 if successful,
- void pbc_param_out_str(FILE *stream, pbc_param_t p)
- void pbc_param_clear(pbc_param_t p)
可以使用的有以下三種:
(1)Windows下直接呼叫的只有A,D,F三種類型的曲線
pairing_t pairing; a_param_input(pairing);
(2)產生動態配引數
pairing_t pairing;
a_param_t w;
a_param_init(w);
a_param_gen(w,160,512);//取160bit,512bit最佳
pairing_init_a_param(pairing,w);
(3)自己寫的一個pbc_new.h標頭檔案
#include <stdio.h>
#include "pbc.h"
static inline void pbc_demo_pairing_init(pairing_t pairing, char* filename) {
char s[16384];
FILE *fp;
unsigned int count;
fp = fopen(filename, "r");
if (!fp){
printf("error opening %s", filename);
}
count = fread(s, 1, 16384, fp);
if (!count){
printf("input error");
}
fclose(fp);
pairing_init_inp_buf(pairing, s, count); }
主函式main()裡的呼叫程式碼:
#define F_PATH "d:\\a.param" 我放在D盤根目錄下
//char* c_filepath = "d:\\a.param";
pbc_demo_pairing_init(pairing, F_PATH); //pbc_new.h