Linux C SHA256 (内核态)

/* sha256.h  sha256算法 */
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/time.h>

#define SHA256_BLOCK_SIZE 32

typedef unsigned char BYTE;
typedef unsigned int  WORD;

typedef struct {
	BYTE ctxdata[64];
	WORD datalen;
	unsigned long long bitlen;
	WORD state[8];
} SHA256_CTX;

void SHA256_Init(SHA256_CTX *ctx);
void SHA256_Update(SHA256_CTX *ctx, const BYTE data[], WORD len);
void SHA256_Final(SHA256_CTX *ctx, BYTE hash[]);
int sha256_test(void);
/* sha256.c  算法实现以及测试函数 */
#include "sha256.h"

#define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b))))
#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))

#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z)))
#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define EP0(x) (

猜你喜欢

转载自blog.csdn.net/afk_02/article/details/121492060