📄 rsax931type.c
字号:
/* Copyright 2005-2006, Voltage Security, all rights reserved.
*/
#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "algobj.h"
#include "sign.h"
#include "rsa.h"
#include "rsax931.h"
#include "mpint.h"
#include "errorctx.h"
int VtAlgorithmImplRSASignVerifyX931 (
VtAlgorithmObject *object,
Pointer info,
unsigned int flag
)
{
int status;
#if VOLT_ALIGNMENT != 1
unsigned int pad;
#endif
unsigned int bufferSize, offset;
VoltAlgorithmObject *obj = (VoltAlgorithmObject *)(*object);
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
unsigned char *buffer = (unsigned char *)0;
VoltSignClassCtx *ctx;
VoltRsaSignCtx *rsaCtx;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Check the flag, it should be VOLT_ALG_SET_TYPE_FLAG.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_ALG_SET_TYPE_FLAG)
break;
/* Check the class of the object. It should be 0 (not yet set).
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (obj->algClass != 0)
break;
/* The associated info should be a NULL pointer.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info != (Pointer)0)
break;
/* Allocate space for the VoltSignClassCtx and the localCtx.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = sizeof (VoltSignClassCtx) + sizeof (VoltRsaSignCtx);
#if VOLT_ALIGNMENT != 1
/* If the alignment is 1, there's no need to pad. If not, compute
* the pad length.
*/
VOLT_COMPUTE_ALIGN_PAD (VOLT_ALIGNMENT, sizeof (VoltSignClassCtx), pad)
bufferSize += pad;
#endif
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
ctx = (VoltSignClassCtx *)buffer;
offset = sizeof (VoltSignClassCtx);
#if VOLT_ALIGNMENT != 1
offset += pad;
#endif
rsaCtx = (VoltRsaSignCtx *)(buffer + offset);
ctx->GetDigestObject = RSAGetDigestObject;
ctx->Pad = X931Pad;
ctx->Unpad = X931Unpad;
ctx->CheckSignatureInput = RSACheckSignatureInput;
ctx->SignData = X931RSASignData;
ctx->VerifyData = X931RSAVerifyData;
ctx->algorithm |= VOLT_SIGNATURE_ALG_RSA;
ctx->localSignCtx = (Pointer)rsaCtx;
ctx->LocalSignCtxDestroy = RSASignCtxDestroy;
obj->algClass = VOLT_CLASS_SIGNATURE | VOLT_CLASS_VERIFY;
obj->classCtx = (Pointer)ctx;
obj->ClassCtxDestroy = VoltSignCtxDestroy;
status = 0;
} while (0);
if (status == 0)
return (0);
/* If there was an error, destroy what we created but did not return.
*/
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VOLT_LOG_ERROR_INFO (
0, *object, status, 0, errorType,
(char *)0, "VtAlgorithmImplRSASignVerifyX931", fnctLine, (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -