1、流程图中用到的符号说明如下:m 未加密的原始数据(明文)c 加密后数据(密文)e 随机选取的加密密钥,与(p - 1) (q - 1)互素。 (p、q 是两个大素数)n n=p*qdP p 的指数dQ q 的指数qInv 系数数据流程图引用到源程序中的类型定义如下:typedef unsigned long int UINT4;typedef unsigned short int UINT2;typedef UINT4 NN_DIGIT;typedef UINT2 NN_HALF_DIGIT;typedef struct unsigned int bits; /* length in bits
2、 of modulus */unsigned char modulusMAX_RSA_MODULUS_LEN; /* modulus */unsigned char exponentMAX_RSA_MODULUS_LEN; /* public exponent */ R_RSA_PUBLIC_KEY; / 公钥typedef struct unsigned int bits; /* length in bits of modulus */unsigned char modulusMAX_RSA_MODULUS_LEN; /* modulus */unsigned char publicExpo
3、nentMAX_RSA_MODULUS_LEN; /* public exponent */unsigned char exponentMAX_RSA_MODULUS_LEN; /* private exponent */unsigned char prime2MAX_RSA_PRIME_LEN; /* prime factors */unsigned char primeExponent2MAX_RSA_PRIME_LEN; /* exponents for CRT */unsigned char coefficientMAX_RSA_PRIME_LEN; /* CRT coefficien
4、t */ R_RSA_PRIVATE_KEY; / 私钥引用到的宏定义说明如下:#define NN_DIGIT_BITS 32#define NN_HALF_DIGIT_BITS 16#define NN_DIGIT_LEN (NN_DIGIT_BITS / 8)#define MAX_NN_DIGITS (MAX_RSA_MODULUS_LEN + NN_DIGIT_LEN - 1) / NN_DIGIT_LEN + 1)#define MAX_NN_DIGIT 0xffffffff#define MAX_NN_HALF_DIGIT 0xffff#define MAX_RSA_MODULU
5、S_BITS 2048#define MAX_RSA_MODULUS_LEN (MAX_RSA_MODULUS_BITS + 7) / 8)RSA 公钥加密算法流程图:RSA 私钥解密算法流程图:赋值算法流程图:/*Assigns a = b.Lengths: adigits, bdigits.*/函数名:void NN_Assign (NN_DIGIT *a, NN_DIGIT * b, unsigned int digits)赋0值算法流程图:/* Assigns a = 0.Lengths: adigits.*/函数名:void NN_AssignZero (NN_DIGIT *a, u
6、nsigned int digits)返回数组有效长度的算法流程图:/*Lengths: adigits.*/函数名:unsigned int NN_Digits (NN_DIGIT *a, unsigned int digits)计算两个阿拉伯数字相乘的算法流程图:/* Computes a = b * c, where b and c are digits.Lengths: a2.*/函数名:void NN_DigitMult (NN_DIGIT a2, NN_DIGIT b, NN_DIGIT c)C C H LB B H LC B L LC B H LC B L HC B H HC X
7、 Y B H L计算a = b + c*d的算法流程图:/*Computes a = b + c*d, where c is a digit. Returns carry.Lengths: adigits, bdigits, ddigits.*/函数名:static NN_DIGIT NN_AddDigitMult (NN_DIGIT * a, NN_DIGIT * b, NN_DIGIT c, NN_DIGIT * d, unsigned int digits)计算a = b * c的算法流程图:/* Computes a = b * c.Lengths: a2*digits, bdigit
8、s, cdigits.Assumes digits MAX_NN_DIGITS.*/函数名:void NN_Mult (NN_DIGIT * a, NN_DIGIT * b, NN_DIGIT * c, unsigned int digits)计算a = b * 2c的算法流程图:/*Computes a = b * 2c (i.e., shifts left c bits), returning carry.Lengths: adigits, bdigits.Requires c NN_DIGIT_BITS.*/函数名:NN_DIGIT NN_LShift (NN_DIGIT * a, NN_DIGIT * b, unsigned int c, unsigned int digits)返回NN_DIGIT类型变量有效位数的算法流程图:函数名:static unsigned int NN_DigitBits (NN_DIGIT a)