📄 rsa.h
字号:
/* Copyright 2005-2006, Voltage Security, all rights reserved.
*/
#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "paramobj.h"
#include "algobj.h"
#include "keyobj.h"
#include "mpint.h"
#include "surrender.h"
#ifndef _RSA_H
#define _RSA_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
unsigned int modLenBits;
unsigned int usageFlag;
VtItem pubExpo;
} VoltRSAKeyPairGenInfo;
typedef struct
{
VtMpIntCtx mpCtx;
unsigned int modBits;
unsigned int usageFlag;
unsigned int prime1Bits;
unsigned int prime2Bits;
VtItem prime1;
VtItem prime2;
VtItem expo1;
VtItem expo2;
VtItem coeff;
VtItem modulus;
VtItem priExpo;
VtItem pubExpo;
} VoltRsaKeyGenCtx;
/* This is called by VtKeyParamRSAPublicVerify or
* VtKeyParamRSAPublicEncrypt. It's just like a KeyParam except it has
* the usageFlag arg.
* <p>The usageFlag arg must be either
* <pre>
* <code>
* VT_RSA_KEY_USAGE_SIGN_VERIFY
* VT_RSA_KEY_USAGE_ENCRYPT_DECRYPT
* </code>
* </pre>
*/
int VOLT_CALLING_CONV VoltKeyParamRSAPublic VOLT_PROTO_LIST ((
VtKeyObject object,
Pointer info,
unsigned int flag,
unsigned int usageFlag
));
/* This is called by VtKeyParamRSAPrivateSign or
* VtKeyParamRSAPrivateDecrypt. It's just like a KeyParam except it has
* the usageFlag arg.
* <p>The usageFlag arg must be either
* <pre>
* <code>
* VT_RSA_KEY_USAGE_SIGN_VERIFY
* VT_RSA_KEY_USAGE_ENCRYPT_DECRYPT
* </code>
* </pre>
*/
int VOLT_CALLING_CONV VoltKeyParamRSAPrivate VOLT_PROTO_LIST ((
VtKeyObject object,
Pointer info,
unsigned int flag,
unsigned int usageFlag
));
/* Implements VGenerateKey.
*/
int VOLT_CALLING_CONV RSAGenerateKeyPair VOLT_PROTO_LIST ((
VtKeyObject priKey,
VtKeyObject pubKey,
VtRandomObject random
));
/* This is how RSA keys are stored internally.
* Each of the types, public, private and key pair, must begin with the
* keyType field, a flag so we can know what the struct is. It will be
* set to one of the following values.
*
* VOLT_KEY_TYPE_PUBLIC
* VOLT_KEY_TYPE_PRIVATE
* VOLT_KEY_TYPE_PAIR
*
* The public and private key types must look alike from the top down
* to where the private key adds the private exponent and CRT info.
* They can both be dereferenced as a public key and the keyItems will
* be in the same place.
*/
typedef struct
{
UInt32 type;
VtRSAPriKeyInfo *keyItems;
VoltMpInt *modulus;
VoltMpInt *pubExpo;
VoltMpInt *priExpo;
VoltMpInt *prime1;
VoltMpInt *prime2;
VoltMpInt *expo1;
VoltMpInt *expo2;
VoltMpInt *coeff;
} VoltRsaPrivateKey;
typedef struct
{
UInt32 type;
VtRSAPubKeyInfo *keyItems;
VoltMpInt *modulus;
VoltMpInt *pubExpo;
} VoltRsaPublicKey;
typedef struct
{
unsigned int type;
VtKeyObject pubKey;
VtKeyObject priKey;
} VoltRsaKeyPair;
/* The tempKey is for when the actual key object passed in is not a
* regular toolkit RSA private key, but one in which the data is
* available. We'll build a temp key object to build the required key
* data.
* <p>The digester is created by the DER decoder. An RSA signing algID
* will be for "RSA with SHA-1" or "RSA with SHA256" or so on. When we
* create the algorithm object, we'll create the digester as well. This
* is so VtAlgorithmParamSigDigestAlgObj will be able to return an
* object.
*/
typedef struct
{
VoltRsaPrivateKey *priKeyData;
VoltRsaPublicKey *pubKeyData;
VtKeyObject tempKey;
VtAlgorithmObject digester;
} VoltRsaSignCtx;
/* Encrypt and decrypt using RSA. This determines if a pub and pri key
* are indeed RSA partners. The data to encrypt and the encrypted data
* are "thrown away", this function only determines if the keys are
* indeed partners.
* <p>If the two are partners, this function will return 0. If the keys
* are not, the function will return an error code.
* <p>This routine assumes that the random object is valid.
*
* @param libCtx The libCtx to use.
* @param surrCtx If not NULL, pass it on to signing and verifying
* objects.
* @param usageFlag SIGN_VERIFY or ENCRYPT_DECRYPT.
* @param pubKey The alleged public key.
* @param priKey The alleged private key.
* @param random A random object to use as a source of any random bytes
* if needed.
* @return an int, 0 if the function completed successfully or a
* non-zero error code.
*/
int VOLT_CALLING_CONV VoltTestRsaKeyPair VOLT_PROTO_LIST ((
VoltLibCtx *libCtx,
VoltSurrenderCtx *surrCtx,
unsigned int usageFlag,
VtKeyObject pubKey,
VtKeyObject priKey,
VtRandomObject random
));
/* Implements VCloneObject.
*/
int VOLT_CALLING_CONV VoltCloneRsaPubKey VOLT_PROTO_LIST ((
Pointer sourceObject,
Pointer *destObject
));
/* Implements VCloneObject.
*/
int VOLT_CALLING_CONV VoltCloneRsaPriKey VOLT_PROTO_LIST ((
Pointer sourceObject,
Pointer *destObject
));
/* Implements VCtxDestroy.
*/
void VOLT_CALLING_CONV RSAKeyPairDataDestroy VOLT_PROTO_LIST ((
Pointer obj,
Pointer ctx
));
/* Implements VCtxDestroy.
*/
void VOLT_CALLING_CONV RSAKeyDataDestroy VOLT_PROTO_LIST ((
Pointer obj,
Pointer ctx
));
/* Implements VGetOutputSize.
*/
int VOLT_CALLING_CONV RSAEncryptGetOutputSize VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj,
unsigned int callFlag,
unsigned char *input,
unsigned int inputLen,
unsigned int *outputSize,
unsigned int *leftovers,
VtRandomObject random
));
/* Implements VEncryptInit.
*/
int VOLT_CALLING_CONV RSAEncryptInit VOLT_PROTO_LIST ((
VoltAlgorithmObject *algObj,
VoltKeyObject *keyObj
));
/* Implements VEncryptUpdate.
*/
int VOLT_CALLING_CONV RSAEncryptUpdate VOLT_PROTO_LIST ((
VoltAlgorithmObject *algObj,
VtRandomObject random,
unsigned char *dataToEncrypt,
unsigned int dataToEncryptLen,
unsigned char *encryptedData
));
/* Implements VWrapKey.
*/
int VOLT_CALLING_CONV RSAWrapKey VOLT_PROTO_LIST ((
VoltAlgorithmObject *algObj,
VtRandomObject random,
VoltKeyObject *keyToWrap,
unsigned char *encryptedKey,
unsigned int bufferSize,
unsigned int *encryptedKeyLen
));
/* Implements VDecryptInit.
*/
int VOLT_CALLING_CONV RSADecryptInit VOLT_PROTO_LIST ((
VoltAlgorithmObject *algObj,
VoltKeyObject *keyObj
));
/* Implements VDecryptUpdate.
*/
int VOLT_CALLING_CONV RSADecryptUpdate VOLT_PROTO_LIST ((
VoltAlgorithmObject *algObj,
VtRandomObject random,
unsigned char *dataToDecrypt,
unsigned int dataToDecryptLen,
unsigned char *decryptedData
));
/* Implements VUnwrapKey.
*/
int VOLT_CALLING_CONV RSAUnwrapKey VOLT_PROTO_LIST ((
VoltAlgorithmObject *algObj,
VtRandomObject random,
unsigned char *encryptedKey,
unsigned int encryptedKeyLen,
VtKeyParam KeyParam,
VtKeyObject unwrappedKey
));
/* Implements VCtxDestroy.
*/
void VOLT_CALLING_CONV RSACipherClassCtxDestroy VOLT_PROTO_LIST ((
Pointer obj,
Pointer ctx
));
/* Implements VCheckSignatureInput.
*/
int VOLT_CALLING_CONV RSACheckSignatureInput VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj,
VoltKeyObject *key,
VtRandomObject random,
unsigned char *dataToSign,
unsigned int dataToSignLen,
unsigned int *signatureSize
));
/* Implements VSignData.
*/
int VOLT_CALLING_CONV RSASignData VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj,
VoltKeyObject *key,
VtRandomObject random,
unsigned char *dataToSign,
unsigned int dataToSignLen,
unsigned char *signature,
unsigned int *sigLen
));
/* Implements VVerifyData.
*/
int VOLT_CALLING_CONV RSAVerifyData VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj,
VoltKeyObject *key,
VtRandomObject random,
unsigned char *dataToVerify,
unsigned int dataToVerifyLen,
unsigned char *signature,
unsigned int sigLen,
unsigned int *verifyResult
));
/* Implements VCtxDestroy.
*/
void VOLT_CALLING_CONV RSASignCtxDestroy VOLT_PROTO_LIST ((
Pointer obj,
Pointer ctx
));
/* Implements VGetDigestObject.
*/
int VOLT_CALLING_CONV RSAGetDigestObject VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj,
VtAlgorithmObject *digestObj
));
/* How long is the digest length for the given digestAlg?
* <p>If the digestAlg is a flag for an unknown digest, return an error.
* <p>This function also returns the X9.31 identifier byte, just in
* case the caller needs it. The caller can pass a NULL pointer for the
* X9.31 byte if that info is not needed.
*/
int VOLT_CALLING_CONV VoltGetDigestLenFromAlg VOLT_PROTO_LIST ((
VoltLibCtx *libCtx,
unsigned int digestAlg,
unsigned int *digestLen,
unsigned int *x931Byte
));
#ifdef __cplusplus
}
#endif
#endif /* _RSA_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -