📄 rsaref.txt
字号:
generating a public value and a private value from the Diffie-Hellmanparameters. It stores the resulting public value in publicValue andthe resulting private value in private value.The private value is a random number x whose length in bytes isprivateValueLen, and the public value is the number y such that y = g^x mod p,where p and g are the prime and generator in params. (Typically, oneselects privateValueLen according to the length in bits of the"subprime" q.)publicValue and privateValue will be represented most significantbyte first, with no leading zero bytes. publicValue will have thesame length as the prime.randomStruct must have been seeded.Return value: 0 success RE_NEED_RANDOM randomStruct is not seededR_ComputeDHAgreedKeyint R_ComputeDHAgreedKey ( unsigned char *agreedKey, /* new agreed-upon key */ unsigned char *otherPublicValue, /* other's public value */ unsigned char *privateValue, /* private value */ unsigned int privateValueLen, /* length of private value */ R_DH_PARAMS *params /* Diffie-Hellman parameters */);R_ComputeDHAgreedKey computes an agreed-upon key from the otherparty's public value, a private value, and the Diffie-Hellmanparameters. It stores the resulting agreed key in agreedKey.The agreed key is the number z such that z = (y')^x mod p,where y' is the other party's public value, x is the private value,and p is the prime in params.The other party's private value y' should be between 0 and p-1.agreedKey will be represented most significant byte first, with noleading zero bytes. agreedKey will have the same length as the prime.Return value: 0 success RE_DATA other party's private value out of range7. VERSION 1.0 ROUTINESThe following procedures are retained for backward compatibility withRSAREF 1.0: R_SignPEMBlock, R_SignBlock, R_VerifyPEMSignature,R_VerifyBlockSignature, R_SealPEMBlock, R_OpenPEMBlock, andR_DigestBlock.The procedures are typically called by message-processingapplications. R_SignBlock is also typically called by key-generationapplications when constructing a PEM or PKCS certification request,and by certification applications when signing a certificate.R_DigestBlock has no particular PEM application, but may be useful inPKCS #7.To sign a message, an application calls R_SignPEMBlock, giving thesearguments: - a pointer to the message content, and the message length - an integer identifying which message-digest algorithm to apply (see Appendix D) - a flag indicating whether to encode the message in printable ASCII according to RFC 1421 - the signer's RSA private keyR_SignPEMBlock signs the message with the signer's private key andthe specified message-digest algorithm, and optionally encodes themessage in printable ASCII. It returns the signature and possibly theencoded message. The signature is encoded according to RFC 1421.To sign a block of data such as a certificate where the signature isnot encoded in printable ASCII, an application calls R_SignBlock,giving these arguments: - a pointer to the block, and the block length - an integer identifying which message-digest algorithm to apply (see Appendix D) - the signer's RSA private keyR_SignBlock signs the message with the signer's private key and thespecified message-digest algorithm. It returns the signature.To verify a signature on a message, an application callsR_VerifyPEMSignature, giving these arguments: - a pointer to the (possibly encoded) message, and the message length - a pointer to the signature, and the signature length - an integer identifying which message-digest algorithm was applied (see Appendix D) - a flag indicating whether the message was encoded in printable ASCII - the signer's RSA public keyR_VerifyPEMSignature decodes the message if it was encoded andverifies the signature on the message with the signer's public keyand the specified message-digest algorithm. It returns the messagecontent if the message was encoded.To verify a signature on a block of data such as a certificate wherethe signature is not encoded in printable ASCII, an application callsR_VerifyBlockSignature, giving these arguments: - a pointer to the block, and the block length - a pointer to the signature, and the signature length - an integer identifying which message-digest algorithm was applied (see Appendix D) - the signer's RSA public keyR_VerifyBlockSignature verifies the signature on the message with thesigner's public key and the specified message-digest algorithm.To sign and encrypt a message, an application calls R_SealPEMBlock,giving these arguments: - a pointer to the message content, and the message length - an integer identifying which message-digest algorithm to apply (see Appendix D) - the signer's RSA private key - the recipient's RSA public key - a random structureR_SealPEMBlock signs the message with the signer's private key andthe specified message-digest algorithm, encrypts the message and thesignature with a random DES key, and encrypts the DES key with therecipient's public key. It returns the encrypted message, theencrypted key, the encrypted signature, and the DES initializationvector. The encrypted message, key, and signature are encodedaccording to RFC 1421.To open a message (decrypt it and verify its signature), anapplication calls R_OpenPEMBlock, giving these arguments: - a pointer to the encrypted message, and the encrypted message length - a pointer to the encrypted key, and the encrypted key length - a pointer to the encrypted signature, and the encrypted signature length - a DES initialization vector - an integer identifying which message-digest algorithm was applied (see Appendix D) - the signer's RSA public key - the recipient's RSA private keyR_OpenPEMBlock decrypts the encrypted DES key with the recipient'sprivate key, decrypts the encrypted message and the encryptedsignature with the DES key, and verifies the signature on the messagewith the signer's public key and the specified message-digestalgorithm. It returns the message content.To digest a block of data such as a prototype certificate, anapplication calls R_DigestBlock, giving these arguments: - a pointer to the block, and the block length - an integer identifying which message-digest algorithm to apply (see Appendix D)R_DigestBlock digests the block with the specified message-digestalgorithm. It returns the message digest.ENCODED_CONTENT_LEN, DECODED_CONTENT_LEN, ENCRYPTED_CONTENT_LEN, andDECRYPTED_CONTENT_LEN are macros that assist in determining themaximum lengths of the results of cryptographic enhancements.R_SignPEMBlockint R_SignPEMBlock ( unsigned char *encodedContent, /* encoded content */ unsigned int *encodedContentLen, /* length of encoded content */ unsigned char *encodedSignature, /* encoded signature */ unsigned int *encodedSignatureLen, /* length of encoded signature */ unsigned char *content, /* content */ unsigned int contentLen, /* length of content */ int recode, /* recoding flag */ int digestAlgorithm, /* message-digest algorithm */ R_RSA_PRIVATE_KEY *privateKey /* signer's RSA private key */);R_SignPEMBlock computes a digital signature on content. Specifically,R_SignPEMBlock performs the following steps: 1. It digests content with digestAlgorithm, giving a message digest. 2. It encrypts the message digest with privateKey, giving a digital signature, and encodes the result in printable ASCII according to RFC 1421, storing the encoding in encodedSignature. 3. If recode is nonzero, it encodes content in printable ASCII, storing the encoding in encodedContent.If recode is nonzero, encodedContent will be an ASCII string, encodedaccording to RFC 1421. (It will not contain any line delimiters; theapplication must break the string into 64-character lines.)encodedContentLen will not be greater thanENCODED_CONTENT_LEN(contentLen). If recode is zero, encodedContent isignored.encodedSignature will be an ASCII string, encoded according to RFC1421. encodedSignatureLen will not be greater thanMAX_PEM_SIGNATURE_LEN.digestAlgorithm is the algorithm with which the message content isdigested, and must be one of the values listed in Appendix D.Return value: 0 success RE_DIGEST_ALGORITHM digestAlgorithm is invalid RE_PRIVATE_KEY privateKey cannot encrypt message digestR_SignBlockint R_SignBlock ( unsigned char *signature, /* encoded signature */ unsigned int *signatureLen, /* length of encoded signature */ unsigned char *block, /* block */ unsigned int blockLen, /* length of block */ int digestAlgorithm, /* message-digest algorithm */ R_RSA_PRIVATE_KEY *privateKey /* signer's RSA private key */);R_SignBlock computes a digital signature on block of data such as acertificate. Its operation is similar to R_SignPEMBlock, except thatthe resulting signature is an arbitrary byte string, rather than anRFC 1421-encoded string.signatureLen will not be greater than MAX_SIGNATURE_LEN.Return value: 0 success RE_DIGEST_ALGORITHM digestAlgorithm is invalid RE_PRIVATE_KEY privateKey cannot encrypt message digestR_VerifyPEMSignatureint R_VerifyPEMSignature ( unsigned char *content, /* content */ unsigned int *contentLen, /* length of content */ unsigned char *encodedContent, /* (possibly) encoded content */ unsigned int encodedContentLen, /* length of encoded content */ unsigned char *encodedSignature, /* encoded signature */ unsigned int encodedSignatureLen, /* length of encoded signature */ int recode, /* recoding flag */ int digestAlgorithm, /* message-digest algorithm */ R_RSA_PUBLIC_KEY *publicKey /* signer's RSA public key */);R_VerifyPEMSignature verifies a digital signature on a message. Itsoperation is the inverse of R_SignPEMBlock. R_VerifyPEMSignatureoperates on encodedSignature and encodedContent. If recode isnonzero, it first decodes encodedContent according to RFC 1421, andstores the result in content. If recode is zero, content is ignored.If recode is nonzero, contentLen will not be greater thanDECODED_CONTENT_LEN(encodedContentLen).Return value: 0 success RE_CONTENT_ENCODING encodedContent has RFC 1421 encoding errorRE_SIGNATURE_ENCODING encodedSignature has RFC 1421 encoding error RE_DIGEST_ALGORITHM digestAlgorithm is invalid RE_PUBLIC_KEY publicKey cannot decrypt signature RE_SIGNATURE signature on content is incorrectR_VerifyBlockSignatureint R_VerifyBlockSignature ( unsigned char *block, /* block */ unsigned int blockLen, /* length of block */ unsigned char *signature, /* signature */ unsigned int signatureLen, /* length of signature */ int digestAlgorithm, /* message-digest algorithm */ R_RSA_PUBLIC_KEY *publicKey /* signer's RSA public key */);R_VerifyBlockSignature verifies a digital signature on a block ofdata such as a certificate. Its operation is similar toR_VerifyPEMSignature, except that the block and signature arearbitrary byte strings, rather than RFC 1421-encoded strings.Return value: 0 success RE_DIGEST_ALGORITHM digestAlgorithm is invalid RE_PUBLIC_KEY publicKey cannot decrypt signature RE_SIGNATURE signature on block is incorrectR_SealPEMBlockint R_SealPEMBlock ( unsigned char *encryptedContent, /* encoded, encrypted content */ unsigned int *encryptedContentLen, /* length of encoded, encrypted content */ unsigned char *encryptedKey, /* encoded, encrypted DES key */ unsigned int *encryptedKeyLen, /* length of encoded, encrypted DES key */ unsigned char *encryptedSignature,/* encoded, encrypted signature */ unsigned int *encryptedSignatureLen, /* length of encoded, encrypted signature */ unsigned char iv[8], /* DES initialization vector */ unsigned char *content, /* content */ unsigned int contentLen, /* length of content */ int digestAlgorithm, /* message-digest algorithm */ R_RSA_PUBLIC_KEY *publicKey, /* recipient's RSA public key */ R_RSA_PRIVATE_KEY *privateKey, /* signer's RSA private key */ R_RANDOM_STRUCT *randomStruct /* random structure */);R_SealPEMBlock computes a digital signature on content then encryptsthe content and the signature. Specifically, R_SealPEMBlock performsthe following steps: 1. It digests content with digestAlgorithm, giving a message digest. 2. It encrypts the message digest with privateKey, giving a digital signature. 3. It generates a random DES key and initialization vector, storing the initialization vector in iv. 4. It encrypts content with the DES key and initialization vector in cipher-block chaining mode, and encodes the result in printable ASCII according to RFC 1421, storing the encoding in encryptedContent. 5. It encrypts the DES key with publicKey and encodes the result in printable ASCII, storing the encoding in encryptedKey. 6. It encrypts the digital signature with the DES key and initialization vector, and encodes the result in printable ASCII, storing the encoding in encryptedSignature.encryptedContent will be an ASCII string, encoded according to RFC1421. (It will not contain any line delimiters; the application mustbreak the string into 64-character lines.) encryptedContentLen willnot be greater than ENCRYPTED_CONTENT_LEN(contentLen).encryptedKey and encryptedSignature will be ASCII strings, encodedaccording to RFC 1421. encryptedKeyLen will not be greater thanMAX_PEM_ENCRYPTED_KEY_LEN. encryptedSignatureLen will not be greaterthan MAX_PEM_ENCRYPTED_SIGNATURE_LEN.digestAlgorithm is the algorithm with which the message content isdigested, and must be one of the values listed in Appendix D.randomStruct must have been seeded.Return value: 0 success RE_DIGEST_ALGORITHM digestAlgorithm is invalid RE_PRIVATE_KEY privateKey cannot encrypt message digest RE_PUBLIC_KEY publicKey cannot encrypt DES key RE_NEED_RANDOM randomStruct is not seededR_OpenPEMBlockint R_OpenPEMBlock ( unsigned char *content, /* content */ unsigned int *contentLen, /* length of content */ unsigned char *encryptedContent, /* encoded, encrypted content */ unsigned int encryptedContentLen, /* length of encoded, encrypted content */ unsigned char *encryptedKey, /* encoded, encrypted DES key */ unsigned int encryptedKeyLen, /* length of encoded, encrypted DES key */ unsigned char *encryptedSignature,/* encoded, encrypted signature */ unsigned int encryptedSignatureLen, /* length of encoded, encrypted signature */ unsigned char iv[8], /* DES initialization vector */ int digestAlgorithm, /* message-digest algorithm */ R_RSA_PRIVATE_KEY *privateKey, /* recipient's RSA private key */ R_RSA_PUBLIC_KEY *publicKey /* signer's RSA public key */);R_OpenPEMBlock decrypts an encrypted message and verifies a digitalsignature. Its operation is the inverse of R_SealPEMBlock.contentLen will not be greater thanDECRYPTED_CONTENT_LEN(encryptedContentLen).Return value: 0 success RE_CONTENT_ENCODING encryptedContent has RFC 1421 encoding error RE_KEY_ENCODING encryptedKey has RFC 1421 encoding errorRE_SIGNATURE_ENCODING encryptedSignature has RFC 1421 encoding error RE_PUBLIC_KEY publicKey cannot decrypt signature
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -