⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsarefcl.h

📁 各种加密算法的集合
💻 H
字号:
#ifndef RSAREFCL_H 
#define RSAREFCL_H 

#include "cryptlib.h" 

#ifdef USE_RSAREF 

#ifdef USE_BIGNUM_WITH_RSAREF 
#include "bignum.h" 
#endif 

#include "misc.h" 

extern "C" { 
#include <global.h> 
#include <rsaref.h> 
#include <rsa.h> 
} 

class RSAREFPrivateKey; 

class RSAREFPublicKey 
{ 
public: 
#ifdef USE_BIGNUM_WITH_RSAREF 
RSAREFPublicKey(const bignum &amt;n, const bignum &amt;e); 
#endif 
RSAREFPublicKey(const RSAREFPrivateKey &amt;); 
RSAREFPublicKey(BufferedTransformation &amt;bt); 

void DEREncode(BufferedTransformation &amt;bt) const; 

// encrypt and decrypt in PKCS #1 format 
void Encrypt(RandomNumberGenerator &amt;rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText); 
unsigned int Decrypt(const byte *cipherText, byte *plainText); 

boolean Verify(const byte *message, unsigned int messageLen, const byte *signature); 

unsigned int MaxPlainTextLength() const {return CipherTextLength()-11;} 
unsigned int CipherTextLength() const {return (key->bits + 7) / 8;} 
unsigned int MaxMessageLength() const {return MaxPlainTextLength();} 
unsigned int SignatureLength() const {return CipherTextLength();} 

#ifdef USE_BIGNUM_WITH_RSAREF 
bignum Exponent() const {return bignum(key->exponent, MAX_RSA_MODULUS_LEN);} 
bignum Modulus() const {return bignum(key->modulus, MAX_RSA_MODULUS_LEN);} 
#endif 

private: 
SecBlock<R_RSA_PUBLIC_KEY> keyBlock; 
R_RSA_PUBLIC_KEY *const key; 
}; 

class RSAREFPrivateKey 
{ 
public: 
#ifdef USE_BIGNUM_WITH_RSAREF 
RSAREFPrivateKey(const bignum &amt;n, const bignum &amt;e, const bignum &amt;d, 
const bignum &amt;p, const bignum &amt;q, const bignum &amt;dp, const bignum &amt;dq, const bignum &amt;u); 
#endif 
// generate a random private key 
RSAREFPrivateKey(RandomNumberGenerator &amt;rng, int keybits, boolean useFermat4=FALSE); 
RSAREFPrivateKey(BufferedTransformation &amt;bt); 

void DEREncode(BufferedTransformation &amt;bt) const; 

// encrypt and decrypt in PKCS #1 format 
void Encrypt(const byte *plainText, unsigned int plainTextLength, byte *cipherText); 
unsigned int Decrypt(const byte *cipherText, byte *plainText); 

void Encrypt(RandomNumberGenerator &amt;, const byte *plainText, unsigned int plainTextLength, byte *cipherText) 
{Encrypt(plainText, plainTextLength, cipherText);} 

void Sign(const byte *message, unsigned int messageLen, byte *signature) 
{Encrypt(message, messageLen, signature);} 

void Sign(RandomNumberGenerator &amt;, const byte *message, unsigned int messageLen, byte *signature) 
{Encrypt(message, messageLen, signature);} 

unsigned int MaxPlainTextLength() const {return CipherTextLength()-11;} 
unsigned int CipherTextLength() const {return (key->bits + 7) / 8;} 
unsigned int MaxMessageLength() const {return MaxPlainTextLength();} 
unsigned int SignatureLength() const {return CipherTextLength();} 

friend RSAREFPublicKey; // allow RSAREFPublicKey to grab n and e 

private: 
SecBlock<R_RSA_PRIVATE_KEY> keyBlock; 
R_RSA_PRIVATE_KEY *const key; 
}; 

class RSAREF_DH 
{ 
public: 
#ifdef USE_BIGNUM_WITH_RSAREF 
RSAREF_DH(const bignum &amt;p, const bignum &amt;g); 
#endif 
// generate random parameters, pbits is length of prime, qbits is length 
// of subprime 
RSAREF_DH(RandomNumberGenerator &amt;rng, unsigned int pbits, unsigned int qbits); 
RSAREF_DH(BufferedTransformation &amt;bt); 
~RSAREF_DH(); 

void DEREncode(BufferedTransformation &amt;bt) const; 

// this is the length of both publicValue and agreedKey 
unsigned int OutputLength() const {return params.primeLen;} 

void Setup(RandomNumberGenerator &amt;rng, byte *publicValue); 
void Agree(const byte *otherPublicValue, byte *agreedKey); 

private: 
unsigned int BERDecode(BufferedTransformation &amt;bt); 
R_DH_PARAMS params; 
SecByteBlock privateValue; 
}; 

#endif // USE_RSAREF 

#endif // RSAREFCL_H 








⌨️ 快捷键说明

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