没有合适的资源?快使用搜索试试~ 我知道了~
首页OpenSSL接口说明文档
OpenSSL接口说明文档
需积分: 46 135 下载量 54 浏览量
更新于2023-03-16
6
收藏 2.93MB DOCX 举报
详细介绍了openssl各个接口的参数,返回值,方便使用者了解openssl函数的用法。
资源详情
资源推荐
Openssl 函数接口介绍
本文的 opessl 接口函数可能不齐全
后续补充
By shaw
2018.9.19
1. BN 函数
1.1.openssl 之 BN 系列之 1---初始化函数
BIGNUM *BN_new(void); 新生成一个 BIGNUM 结构。
void BN_free(BIGNUM *a); 释放一个 BIGNUM 结构,释放完后 a=NULL。
void BN_init(BIGNUM *); 初始化所有项均为 0,一般为 BN_ init(&c) 。
void BN_clear(BIGNUM *a); 将 a 中所有项均赋值为 0,但是内存并没有释放。
void BN_clear_free(BIGNUM *a); 相当与将 BN_free 和 BN_clear 综合,要不就赋值
0,要不就释放空间。
1.2.openssl 之 BN 系列之 2---情景函数
上下文情景函数,存储计算中的中间过程。
BN_CTX *BN_CTX_new(void);申请一个新的上下文结构。
void BN_CTX_init(BN_CTX *c);将所有的项赋值为 0,一般 BN_CTX_init(&c)。
void BN_CTX_free(BN_CTX *c);释放上下文结构,释放完后 c=NULL。
1.3.openssl 之 BN 系列之 3---复制以及交换函数
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);将 b 复制给 a,正确返回 a,错
误返回 NULL。
BIGNUM *BN_dup(const BIGNUM *a);新建一个 BIGNUM 结构,将 a 复制给新建结构
返回,错误返回 NULL。
BIGNUM *BN_swap(BIGNUM *a, BIGNUM *b);交换 a,b。
1.4.openssl 之 BN 系列之 4---取位函数
int BN_num_bytes(const BIGNUM *a);返回 a 的位数,大量使用。
int BN_num_bits(const BIGNUM *a);
int BN_num_bits_word(BN_ULONG w); 他 返 回 有 意 义 比 特 的 位 数 , 例 如
0x00000432 为 11。
1.5.openssl 之 BN 系列之 5---基本计算函数
int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); r=a+b。
int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); r=a-b。
int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); r=a*b。
int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx); r=a*a, 效 率 高 于
bn_mul(r,a,a)。
int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a,const BIGNUM
*d, BN_CTX *ctx); d=a/b,r=a%b。
int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX
*ctx); r=a%b。
int BN_nnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m,
BN_CTX *ctx); r=abs(a%b)。
int BN_mod_add(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
BN_CTX *ctx); r=abs((a+b)%m))。
int BN_mod_sub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
BN_CTX *ctx); r=abs((a-b)%m))。
int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
BN_CTX *ctx); r=abs((a*b)%m))。
int BN_mod_sqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BN_CTX
*ctx); r=abs((a*a)%m))。
int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx); r=pow(a,p)。
int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,const BIGNUM
*m, BN_CTX *ctx); r=pow(a,p)%M。
int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); r=a,b 最 大 公
约数。
int BN_add_word(BIGNUM *a, BN_ULONG w);
int BN_sub_word(BIGNUM *a, BN_ULONG w);
int BN_mul_word(BIGNUM *a, BN_ULONG w);
BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
BIGNUM *BN_mod_inverse( BIGNUM *r, BIGNUM *a, const BIGNUM *n,
BN_CTX *ctx); 模逆,((a*r)%n==1)。
1.6.openssl 之 BN 系列之 6---比较函数
int BN_cmp(BIGNUM *a, BIGNUM *b); -1 if a < b, 0 if a == b and 1 if a
> b。
int BN_ucmp(BIGNUM *a, BIGNUM *b); 比较 a,b 觉得值,返回值和上同。
int BN_is_zero(BIGNUM *a);
int BN_is_one(BIGNUM *a);
int BN_is_word(BIGNUM *a, BN_ULONG w);
int BN_is_odd(BIGNUM *a); 上面四个返回 1,假如条件成立,否则将返回 0。
1.7.openssl 之 BN 系列之 7---设置函数
int BN_zero(BIGNUM *a); 设置 a 为 0。
int BN_one(BIGNUM *a); 设置 a 为 1。
const BIGNUM *BN_value_one(void); 返回一个为 1 的大数。
int BN_set_word(BIGNUM *a, unsigned long w); 设置 a 为 w。
unsigned long BN_get_word(BIGNUM *a); 假如 a 能表示为 long 型,那么返回一个
long 型数。
1.8.openssl 之 BN 系列之 8---随机数函数
int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); 产 生一 个 加密 用的 强
bits 的伪随机数,若 top=-1,最高位为 0,top=0, 最高位为 1,top=1,最高位和次高位为
1,bottom 为真,随机数为偶数。
int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); 产生一个伪随
机数,应用于某些目的。
int BN_rand_range(BIGNUM *rnd, BIGNUM *range); 产生的 0<rnd<range。
int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);同上面道理。
1.9.openssl 之 BN 系列之 9---产生素数函数
BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, BIGNUM
*add, BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg); 产生一个
bits 位的素数,后面几个参数都可以为 NULL。
int BN_is_prime(const BIGNUM *p, int nchecks , void (*callback)(int, int,
void *), BN_CTX *ctx, void *cb_arg); 判断是否为素数,返回 0 表示成功,1 表示错
误概率小于 0。25,-1 表示错误。
1.10.openssl 之 BN 系列之 10---位数函数
int BN_set_bit(BIGNUM *a, int n);将 a 中的第 n 位设置为 1,假如 a 小于 n 位将扩展。
int BN_clear_bit(BIGNUM *a, int n);将 a 中的第 n 为设置为 0,假如 a 小于 n 位将出
错。
int BN_is_bit_set(const BIGNUM *a, int n);测试是否已经设置,1 表示已设置。
int BN_mask_bits(BIGNUM *a, int n);将 a 截断至 n 位,假如 a 小于 n 位将出错。
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);a 左移 n 位,结果存于 r。
int BN_lshift1(BIGNUM *r, BIGNUM *a); a 左移 1 位,结果存于 r。
int BN_rshift(BIGNUM *r, BIGNUM *a, int n); a 右移 n 位,结果存于 r。
int BN_rshift1(BIGNUM *r, BIGNUM *a); a 左移 1 位,结果存于 r。
1.11.openssl 之 BN 系列之 11---与字符串的转换函数
int BN_bn2bin(const BIGNUM *a, unsigned char *to);将 abs(a)转化为字符串
存入 to,to 的空间必须大于 BN_num_bytes(a)。
BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret); 将 s 中 的
len 位的正整数转化为大数。
char *BN_bn2hex(const BIGNUM *a);转化为 16 进制字符串。
char *BN_bn2dec(const BIGNUM *a);转化为 10 进制字符串。
int BN_hex2bn(BIGNUM **a, const char *str);同上理。
int BN_dec2bn(BIGNUM **a, const char *str);同上理。
int BN_print(BIO *fp, const BIGNUM *a);将大数 16 进制形式写入内存中。
int BN_print_fp(FILE *fp, const BIGNUM *a); 将大数 16 进制形式写入文件。
int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
1.12. openssl 之 BN 系列之 12---其他函数
下面函数可以进行更有效率的模乘和模除,假如在重复在同一模下重复进行模乘和模除计
算,计算 r=(a*b)%m 利用了 recp=1/m。
BN_RECP_CTX *BN_RECP_CTX_new(void);
void BN_RECP_CTX_init(BN_RECP_CTX *recp);
void BN_RECP_CTX_free(BN_RECP_CTX *recp);
int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX
*ctx);
int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
BN_RECP_CTX *recp, BN_CTX *ctx);
下面函数采用蒙哥马利算法进行模幂计算,可以提高效率,他也主要应用于在同一模下进行
多次幂运算。
BN_MONT_CTX *BN_MONT_CTX_new(void);
void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
void BN_MONT_CTX_free(BN_MONT_CTX *mont);
int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX
剩余44页未读,继续阅读
离歌漠
- 粉丝: 209
- 资源: 69
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功