OpenSSL中对称加密算法的统一接口详解
http://tech.ddvip.com 2007年04月25日 社区交流
本文详细介绍OpenSSL中对称加密算法的统一接口详解
#define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid,
block_size, key_len, iv_len, cbits,
flags, init_key,
cleanup, set_asn1, get_asn1, ctrl)
BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched)
BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len,
cbits, flags, init_key, cleanup, set_asn1,
get_asn1, ctrl)1) 宏BLOCK_CIPHER_all_funcs用来定义加解密函数,定义为:
#define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched)
BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched)
BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched)
BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched)
BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
其中BLOCK_CIPHER_func_cbc定义为:
#define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched)
static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)
{
cprefix##_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);
return 1;
}此处注意一个#define的技巧:可以用#define替换变量或函数名,参数在打头或结尾处时,可分别在参数后或参数前用##;参数在中间, 参数开头结尾都用##;
这样对于blowfish定义来说,上面这个宏实际定义这样一个函数:
static int bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)
{
bf_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);
return 1;
}其他几个宏定义类似,定义不同模式的bf加密算法,包括cbc,cfb,ecb,ofb。
责编:豆豆技术应用
正在加载评论...
- Linux/Unix 新闻
- Linux/Unix 入门
- Linux/Unix 命令
- Linux/Unix 安装
- Linux 嵌入式系统
- Linux/Unix 编程
- Linux/Unix 管理
- Linux/Unix 桌面
- Linux/Unix 内核
- Linux/Unix 软件
- SCO Unix
- NetBSD
- OpenBSD
- Redhat/Fedora Linux
- 手机
- Linux/Unix find 搜索命令
- Linux/Unix vi 命令
- Linux/Unix kde 桌面环境
- Linux/Unix GNOME 桌面环境
- Linux/Unix Make 命令
- Linux/Unix crontab 命令
- Linux/Unix ext3 文件系统
- Linux/Unix 文件系统详解
- Linux/Unix ADSL 拨号设置
- Linux/Unix GRUB 配置及应用
- Linux/Unix nfs配置
- Linux/Unix 硬件信息查看及管理
- Linux/Unix 优化
- Linux/Unix 交换分区Swap管理及应用
- Linux/Unix 用户管理
- Linux/Unix Ramdisk
- Linux/Unix 密码恢复管理
- Linux/Unix 文件删除恢复
- Linux/Unix fdisk分区
- Linux/Unix lvs负载均衡管理
- Linux/Unix root用户
- Linux/Unix 集群
- Linux/Unix 日志
- 更多Linux/Unix专题……