sqecb.c

来自「一些加密解密的源代码」· C语言 代码 · 共 59 行

C
59
字号
/*---------------------------*//* Electronic Code Book Mode *//*---------------------------*/#include <assert.h>#include <stdlib.h>#include <string.h>#include "square.h"#include "sqecb.h"#define D(p) ((word32 *)(p))void squareEcbInit (squareEcbContext *ctxEcb, const squareBlock key){	assert (ctxEcb != NULL);	assert (key != NULL);	memset (ctxEcb, 0, sizeof (squareEcbContext));	squareGenerateRoundKeys (key, ctxEcb->roundKeys_e, ctxEcb->roundKeys_d);} /* squareEcbInit */void squareEcbEncrypt (squareEcbContext *ctxEcb, byte *buffer, unsigned length){	assert (ctxEcb != NULL);	assert (buffer != NULL);	while (length >= SQUARE_BLOCKSIZE) {		/* encrypt this block: */		squareEncrypt (D(buffer), ctxEcb->roundKeys_e);		/* proceed to the next block, if any: */		buffer += SQUARE_BLOCKSIZE;		length -= SQUARE_BLOCKSIZE;	}	assert (length == 0);} /* squareEcbEncrypt */void squareEcbDecrypt (squareEcbContext *ctxEcb, byte *buffer, unsigned length){	assert (ctxEcb != NULL);	assert (buffer != NULL);	while (length >= SQUARE_BLOCKSIZE) {		/* decrypt this block: */		squareDecrypt (D(buffer), ctxEcb->roundKeys_d);		/* proceed to the next block, if any: */		buffer += SQUARE_BLOCKSIZE;		length -= SQUARE_BLOCKSIZE;	}	assert (length == 0);} /* squareEcbDecrypt */void squareEcbFinal (squareEcbContext *ctxEcb){	assert (ctxEcb != NULL);	memset (ctxEcb, 0, sizeof (squareEcbContext));} /* squareEcbFinal */

⌨️ 快捷键说明

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