PBC库传入参数文件问题

来源:互联网 发布:iwatch3蜂窝网络 编辑:程序博客网 时间:2024/05/20 05:55

配置不同类型的椭圆曲线,需要修改配对类型。

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)
Initializes pairing parameters from the string s. Returns 0 if successful, 1 otherwise.

  • 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)
Write pairing parameters to ’stream’ in a text format.
  • void pbc_param_clear(pbc_param_t p)
Clear p. Call after p is no longer needed.



可以使用的有以下三种:

(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




0 0
原创粉丝点击