des3ecb.c

来自「这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易」· C语言 代码 · 共 49 行

C
49
字号
#include "os.h"#include <mp.h>#include <libsec.h>// I wasn't sure what to do when the buffer was not// a multiple of 8.  I did what lacy's cryptolib did// to be compatible, but it looks dangerous to me// since its encrypting plain text with the key. -- presottovoiddes3ECBencrypt(uchar *p, int len, DES3state *s){	int i;	uchar tmp[8];	for(; len >= 8; len -= 8){		triple_block_cipher(s->expanded, p, DES3EDE);		p += 8;	}		if(len > 0){		for (i=0; i<8; i++)			tmp[i] = i;		triple_block_cipher(s->expanded, tmp, DES3EDE);		for (i = 0; i < len; i++)			p[i] ^= tmp[i];	}}voiddes3ECBdecrypt(uchar *p, int len, DES3state *s){	int i;	uchar tmp[8];	for(; len >= 8; len -= 8){		triple_block_cipher(s->expanded, p, DES3DED);		p += 8;	}		if(len > 0){		for (i=0; i<8; i++)			tmp[i] = i;		triple_block_cipher(s->expanded, tmp, DES3EDE);		for (i = 0; i < len; i++)			p[i] ^= tmp[i];	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?