rsa.h

来自「Dr.Sec高速密码算法库Windows版」· C头文件 代码 · 共 51 行

H
51
字号
#ifndef __DRSEC_RSA_H
#define __DRSEC_RSA_H

#if defined(__cplusplus)
extern "C"
{
#endif

#ifndef u8
#define u8 unsigned char
#endif 

#ifndef u32
#define u32 unsigned long
#endif

#define MIN_RSA_MODULUS_BITS 508
#define MAX_RSA_MODULUS_BITS 2048
#define MAX_RSA_MODULUS_LEN ((MAX_RSA_MODULUS_BITS + 7) / 8)
#define MAX_RSA_PRIME_BITS ((MAX_RSA_MODULUS_BITS + 1) / 2)
#define MAX_RSA_PRIME_LEN ((MAX_RSA_PRIME_BITS + 7) / 8)

typedef struct {
  u32 bits;                           /* length in bits of modulus */
  u8  modulus[MAX_RSA_MODULUS_LEN];                    /* modulus */
  u8  exponent[MAX_RSA_MODULUS_LEN];           /* public exponent */
}rsaPublicKey;

typedef struct {
  u32 bits;                           /* length in bits of modulus */
  u8  modulus[MAX_RSA_MODULUS_LEN];                    /* modulus */
  u8  publicExponent[MAX_RSA_MODULUS_LEN];     /* public exponent */
  u8  exponent[MAX_RSA_MODULUS_LEN];          /* private exponent */
  u8  prime[2][MAX_RSA_PRIME_LEN];               /* prime factors */
  u8  primeExponent[2][MAX_RSA_PRIME_LEN];   /* exponents for CRT */
  u8  coefficient[MAX_RSA_PRIME_LEN];          /* CRT coefficient */
}rsaPrivateKey;

/*	PKCS#1	*/
int ds_rsaGenerateKeyPair(rsaPublicKey *pbKey, rsaPrivateKey *pvKey, u32 bits, u32 useFermat4);
int ds_rsaPublicEncrypt  (u8 *out, u32 *outLen, u8 *in, u32 inLen, rsaPublicKey  *pbKey, u8 *random, u32 randomLen);
int ds_rsaPrivateEncrypt (u8 *out, u32 *outLen, u8 *in, u32 inLen, rsaPrivateKey *pvKey);
int ds_rsaPublicDecrypt  (u8 *out, u32 *outLen, u8 *in, u32 inLen, rsaPublicKey  *pbKey);
int ds_rsaPrivateDecrypt (u8 *out, u32 *outLen, u8 *in, u32 inLen, rsaPrivateKey *pvKey);

#if defined(__cplusplus)
}
#endif

#endif /* __DRSEC_RSA_H */

⌨️ 快捷键说明

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