📄 pgpchecksum.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
Checksum16 is the sum mod 2^16 of bytes of the stream. Internally used
in Secret Key Packet checksum calculation
$Id: pgpChecksum.c,v 1.1 2002/10/22 02:39:50 ajivsov Exp $
____________________________________________________________________________*/
#include "pgpConfig.h"
#include <string.h>
#include "pgpHash.h"
#include "pgpChecksum.h"
#include "pgpDebug.h"
typedef struct pgpChecksum16Context_
{
PGPUInt16 state;
PGPByte out[2];
} pgpChecksum16Context;
static void
pgpChecksum16Init(void *priv)
{
pgpChecksum16Context *ctx = (pgpChecksum16Context *)priv;
ctx->state = 0;
ctx->out[0] = ctx->out[1] = '\0';
}
static void
pgpChecksum16Update( void *priv, void const *bufIn, PGPSize len)
{
pgpChecksum16Context *ctx = (pgpChecksum16Context *)priv;
while( len-- )
ctx->state += (PGPUInt16)(((PGPByte*)bufIn)[len]);
}
static void const *
pgpChecksum16Finalize(void *priv)
{
pgpChecksum16Context *ctx = (pgpChecksum16Context *)priv;
ctx->out[0] = (PGPByte)(ctx->state >> 8);
ctx->out[1] = (PGPByte)(ctx->state & 0xff);
return ctx->out;
}
PGPHashVTBL const HashChecksum16 = {
"Checksum16", kPGPHashAlgorithm_Checksum16,
"", 0, /* don't need OID for sum mod 2^16 */
2,
1,
sizeof(pgpChecksum16Context),
sizeof(struct{char _a; pgpChecksum16Context _b;}) -
sizeof(pgpChecksum16Context),
pgpChecksum16Init, pgpChecksum16Update, pgpChecksum16Finalize
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -