首页
社区
课程
招聘
[旧帖] [原创]常见密码算法总结--(3)加密模式的openssl代码分析 0.00雪花
发表于: 2010-5-30 23:16 4340

[旧帖] [原创]常见密码算法总结--(3)加密模式的openssl代码分析 0.00雪花

2010-5-30 23:16
4340

《常见密码算法总结--(1)分组对称密码》见
http://bbs.pediy.com/showthread.php?t=113921
http://blog.csdn.net/NJZhuJinhua/archive/2010/05/27/5629455.aspx

《常见密码算法总结--(2)分组密码加密模式》见
http://bbs.pediy.com/showthread.php?t=114169
http://blog.csdn.net/NJZhuJinhua/archive/2010/05/30/5635313.aspx

NJZhuJinhua@csdn May.30, 2010
http://bbs.pediy.com/showthread.php?t=114170
http://blog.csdn.net/NJZhuJinhua/archive/2010/05/30/5635343.aspx
转载请注明出处。

(三)加密模式的openssl代码分析
openssl(本文所用openssl代码为1.0.0版本,2010.03.29发布。http://www.openssl.org 本文所用的内容最近几年应该未有更新,因而版本似乎也没多少关系)代码中crypto\modes目录下提供了cbc128,cfb128,ctr128,cts128,ofb128模式的实现。modes.h提供接口声明,其余诸文件分别提供了各种模式。

typedef void (*block128_f)(const unsigned char in[16],
                           unsigned char out[16],
                           const void *key);

typedef void (*cbc128_f)(const unsigned char *in, unsigned char *out,
                         size_t len, const void *key,
                         unsigned char ivec[16], int enc);

//cbc128的加密与解密
void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
                           size_t len, const void *key,
                           unsigned char ivec[16], block128_f block);
void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
                           size_t len, const void *key,
                           unsigned char ivec[16], block128_f block);

//ctr128的加密与解密
void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
                           size_t len, const void *key,
                           unsigned char ivec[16], unsigned char ecount_buf[16],
                           unsigned int *num, block128_f block);


//ofb128的加密与解密
void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
                           size_t len, const void *key,
                           unsigned char ivec[16], int *num,
                           block128_f block);


//cfb128的加密与解密
void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
                           size_t len, const void *key,
                           unsigned char ivec[16], int *num,
                           int enc, block128_f block);
void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
                             size_t length, const void *key,
                             unsigned char ivec[16], int *num,
                             int enc, block128_f block);
void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
                             size_t bits, const void *key,
                             unsigned char ivec[16], int *num,
                             int enc, block128_f block);


//cts128模式
size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, unsigned char *out,
                                   size_t len, const void *key,
                                   unsigned char ivec[16], block128_f block);
size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
                             size_t len, const void *key,
                             unsigned char ivec[16], cbc128_f cbc);
size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,
                                   size_t len, const void *key,
                                   unsigned char ivec[16], block128_f block);
size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
                             size_t len, const void *key,
                             unsigned char ivec[16], cbc128_f cbc);
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
		     size_t len, const AES_KEY *key,
		     unsigned char *ivec, const int enc) {

	if (enc)
		CRYPTO_cbc128_encrypt(in,out,len,key,ivec,(block128_f)AES_encrypt);
	else
		CRYPTO_cbc128_decrypt(in,out,len,key,ivec,(block128_f)AES_decrypt);
}

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 7
支持
分享
最新回复 (5)
雪    币: 13
活跃值: (26)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
顶下 站个沙发
2010-6-2 10:49
0
雪    币: 126
活跃值: (12)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
挺好的学习材料,来看一下
2010-6-15 11:35
0
雪    币: 427
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
好东西,收藏了
2010-6-15 17:08
0
雪    币: 114
活跃值: (70)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
5
【原创】常见密码算法总结--(4)加密模式的openssl代码分析之cfb模式
http://bbs.pediy.com/showthread.php?t=115184
2010-6-16 12:40
0
雪    币: 217
活跃值: (45)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
6
no offence,but....这样也变成精华??
2010-6-17 09:16
0
游客
登录 | 注册 方可回帖
返回
//