45 #include "../cap/capdecl.h" 47 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE__ 48 #include "../crypto_interface/crypto_interface_rsa_priv.h" 56 typedef struct MRsaKeyTemplate *MRsaKeyTemplatePtr;
60 #define NUM_RSA_VLONG (7) 61 #define NUM_RSA_MODEXP (2) 63 #if !defined( __DISABLE_MOCANA_RSA_DECRYPTION__) && !defined(__PSOS_RTOS__) 64 typedef struct BlindingHelper
66 RTOS_MUTEX blindingMutex;
77 #ifdef __ENABLE_MOCANA_HW_SECURITY_MODULE__ 83 intBoolean privateKey;
84 vlong* v[NUM_RSA_VLONG];
85 ModExpHelper modExp[NUM_RSA_MODEXP];
86 #if !defined(__DISABLE_MOCANA_RSA_DECRYPTION__) && !defined( __PSOS_RTOS__) 87 BlindingHelper blinding;
89 #ifdef __ENABLE_MOCANA_HW_SECURITY_MODULE__ 90 struct HSMRSAInfo* hsmInfo;
92 MocAsymKey pPrivateKey;
93 MocAsymKey pPublicKey;
98 #define RSA_E(k) ((k)->v[0]) 100 #define RSA_N(k) ((k)->v[1]) 102 #define RSA_P(k) ((k)->v[2]) 104 #define RSA_Q(k) ((k)->v[3]) 106 #define RSA_DP(k) ((k)->v[4]) 108 #define RSA_DQ(k) ((k)->v[5]) 110 #define RSA_QINV(k) ((k)->v[6]) 112 #define RSA_MODEXP_P(k) ((k)->modExp[0]) 114 #define RSA_MODEXP_Q(k) ((k)->modExp[1]) 117 #define RSA_KEYSIZE(k) (VLONG_bitLength(RSA_N(k))) 124 #if !defined(__DISABLE_MOCANA_RSA_DECRYPTION__) 125 MOC_EXTERN MSTATUS RSA_RSADP(MOC_RSA(hwAccelDescr hwAccelCtx)
const RSAKey *pRSAKey,
const vlong *pCipherText, vlong **ppMessage, vlong **ppVlongQueue);
127 MOC_EXTERN MSTATUS RSA_RSAEP(MOC_RSA(hwAccelDescr hwAccelCtx)
const RSAKey *pPublicRSAKey,
const vlong *pMessage, vlong **ppRetCipherText, vlong **ppVlongQueue);
129 #if (!defined(__DISABLE_MOCANA_RSA_DECRYPTION__) && defined(__RSAINT_HARDWARE__) && defined(__ENABLE_MOCANA_PKCS11_CRYPTO__)) 130 #define RSA_RSASP1 RSAINT_decrypt 131 #elif (!defined(__DISABLE_MOCANA_RSA_DECRYPTION__)) 132 MOC_EXTERN MSTATUS RSA_RSASP1(MOC_RSA(hwAccelDescr hwAccelCtx)
const RSAKey *pRSAKey,
const vlong *pMessage,
RNGFun rngFun,
void* rngFunArg, vlong **ppRetSignature, vlong **ppVlongQueue);
134 MOC_EXTERN MSTATUS RSA_RSAVP1(MOC_RSA(hwAccelDescr hwAccelCtx)
const RSAKey *pPublicRSAKey,
const vlong *pSignature, vlong **ppRetMessage, vlong **ppVlongQueue);
143 typedef MSTATUS (*RSADecryptFunc)(MOC_RSA(hwAccelDescr hwAccelCtx)
144 const RSAKey *pRSAKey,
146 vlong **ppRetDecrypt,
147 vlong **ppVlongQueue);
149 typedef MSTATUS (*CustomBlindingFunc)( MOC_RSA(hwAccelDescr hwAccelCtx)
150 const RSAKey* pRSAKeyInt,
151 const vlong* pCipher,
152 RNGFun rngFun,
void* rngFunArg,
153 RSADecryptFunc rsaDecryptPrimitive,
154 vlong** ppRetDecrypt,
155 vlong** ppVlongQueue);
170 RSA_generateKeyFipsSteps(MOC_RSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext,
171 ubyte4 nLen, vlong *e,
const vlong *pDebugX, ubyte4 length1, ubyte4 length2,
172 vlong **ppRetP1, vlong **ppRetP2, vlong **ppRetXp, vlong **ppRetPrime,
173 ubyte *pInputSeed, ubyte4 inputSeedLength,
174 ubyte *pRetPrimeSeed1, ubyte *pRetPrimeSeed2,
175 intBoolean *pRetFail,
176 MSTATUS (*completeDigest)(MOC_HASH(hwAccelDescr hwAccelCtx)
const ubyte *pData, ubyte4 dataLen, ubyte *pDigestOutput),
177 ubyte4 hashResultSize,
178 vlong **ppVlongQueue);
260 MOC_EXTERN MSTATUS
RSA_freeKey(RSAKey **ppFreeRSAKey, vlong **ppVlongQueue);
299 MOC_EXTERN MSTATUS
RSA_cloneKey(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey **ppNew,
const RSAKey *pSrc, vlong **ppVlongQueue);
337 MOC_EXTERN MSTATUS
RSA_equalKey(MOC_RSA(hwAccelDescr hwAccelCtx)
const RSAKey *pKey1,
const RSAKey *pKey2, byteBoolean *pResult);
387 const ubyte* modulus,
389 vlong **ppVlongQueue);
415 MOC_RSA(hwAccelDescr hwAccelCtx)
419 const ubyte *pModulus,
475 MOC_RSA(hwAccelDescr hwAccelCtx)
478 const ubyte *modulus,
484 vlong **ppVlongQueue);
518 MOC_RSA(hwAccelDescr hwAccelCtx)
522 const ubyte *pModulus,
524 const ubyte *pPrime1,
526 const ubyte *pPrime2,
559 MOC_RSA(hwAccelDescr hwAccelCtx)
561 MRsaKeyTemplatePtr pTemplate,
582 MRsaKeyTemplatePtr pTemplate
620 MOC_EXTERN MSTATUS
RSA_getCipherTextLength(MOC_RSA(hwAccelDescr hwAccelCtx)
const RSAKey *pKey, sbyte4 *pCipherTextLen);
684 MOC_EXTERN MSTATUS
RSA_encrypt(MOC_RSA(hwAccelDescr hwAccelCtx)
686 const ubyte* plainText,
691 vlong **ppVlongQueue);
693 #ifndef __DISABLE_MOCANA_RSA_DECRYPTION__ 753 MOC_EXTERN MSTATUS
RSA_decrypt(MOC_RSA(hwAccelDescr hwAccelCtx)
755 const ubyte* cipherText,
757 ubyte4* plainTextLen,
760 vlong **ppVlongQueue);
816 const ubyte* cipherText,
818 ubyte4* plainTextLen,
819 vlong **ppVlongQueue);
861 intBoolean *pIsValid,
862 vlong **ppVlongQueue);
916 const ubyte* plainText,
919 vlong **ppVlongQueue);
926 MOC_EXTERN MSTATUS RSA_generateKeyFIPS(MOC_RSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext,
927 RSAKey *p_rsaKey, ubyte4 keySize, vlong **Xp, vlong **Xp1, vlong **Xp2,
928 vlong **Xq, vlong **Xq1, vlong **Xq2, vlong **ppVlongQueue);
979 randomContext *pRandomContext,
982 vlong **ppVlongQueue);
1022 MOC_EXTERN MSTATUS
RSA_prepareKey(MOC_RSA(hwAccelDescr hwAccelCtx)
1023 RSAKey *pRSAKey, vlong** ppVlongQueue);
1071 const ubyte* byteString,
1073 vlong **ppVlongQueue);
1120 const RSAKey *pKey, ubyte *pBuffer,
1126 MOC_EXTERN MSTATUS RSA_getPrivateExponent (
1127 MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pRSAKey,
1129 vlong **ppVlongQueue
1153 MOC_RSA(hwAccelDescr hwAccelCtx)
1158 vlong **ppVlongQueue
1186 MOC_RSA(hwAccelDescr hwAccelCtx)
1187 RSAKey *pPrivateKey,
1193 vlong **ppVlongQueue
MOC_EXTERN MSTATUS RSA_verifyDigest(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte *pMsgDigest, ubyte4 digestLen, ubyte *pSignature, ubyte4 sigLen, intBoolean *pIsValid, vlong **ppVlongQueue)
Verify the digest of a message.
MOC_EXTERN MSTATUS RSA_verifySignature(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *cipherText, ubyte *plainText, ubyte4 *plainTextLen, vlong **ppVlongQueue)
Verify decrypted buffer's signature.
MOC_EXTERN MSTATUS RSA_freeKey(RSAKey **ppFreeRSAKey, vlong **ppVlongQueue)
Free (delete) an RSA key.
MOC_EXTERN MSTATUS RSA_freeKeyTemplate(RSAKey *pKey, MRsaKeyTemplatePtr pTemplate)
Free the RSA standard key template structure previouslly allocated by RSA_getKeyParametersAlloc.
MOC_EXTERN MSTATUS RSA_decrypt(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *cipherText, ubyte *plainText, ubyte4 *plainTextLen, RNGFun rngFun, void *rngFunArg, vlong **ppVlongQueue)
Decrypt ciphertext using PKCS #1.
MOC_EXTERN MSTATUS RSA_setAllKeyParameters(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte4 exponent, const ubyte *modulus, ubyte4 modulusLen, const ubyte *prime1, ubyte4 prime1Len, const ubyte *prime2, ubyte4 prime2Len, vlong **ppVlongQueue)
Set RSA public key parameters.
MOC_EXTERN MSTATUS RSA_signMessage(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *plainText, ubyte4 plainTextLen, ubyte *cipherText, vlong **ppVlongQueue)
Generate signature for plaintext buffer, using provided RSA private key and PKCS #1.
MOC_EXTERN MSTATUS RSA_encrypt(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *plainText, ubyte4 plainTextLen, ubyte *cipherText, RNGFun rngFun, void *rngFunArg, vlong **ppVlongQueue)
Encrypt plaintext using PKCS #1.
MOC_EXTERN MSTATUS RSA_cloneKey(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey **ppNew, const RSAKey *pSrc, vlong **ppVlongQueue)
Clone (copy) an RSA key.
MOC_EXTERN MSTATUS RSA_equalKey(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey1, const RSAKey *pKey2, byteBoolean *pResult)
Determine whether two RSA keys are equal.
MOC_EXTERN MSTATUS RSA_applyPrivateKey(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pPrivateKey, RNGFun rngFun, void *rngFunArg, ubyte *pInput, ubyte4 inputLen, ubyte **ppOutput, vlong **ppVlongQueue)
This function performs an RSA private key operation with no padding.
MOC_EXTERN MSTATUS RSA_generateKey(MOC_RSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, RSAKey *p_rsaKey, ubyte4 keySize, vlong **ppVlongQueue)
Generate RSA key pair (private and public keys).
MOC_EXTERN MSTATUS RSA_setPublicKeyParameters(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte4 exponent, const ubyte *modulus, ubyte4 modulusLen, vlong **ppVlongQueue)
Set RSA public key parameters: exponent and modulus.
sbyte4(* RNGFun)(void *rngFunArg, ubyte4 length, ubyte *buffer)
Function pointer type for a method that produces (pseudo) random bytes.
Definition: random.h:98
MOC_EXTERN MSTATUS RSA_setAllKeyData(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte *pPubExpo, ubyte4 pubExpoLen, const ubyte *pModulus, ubyte4 modulusLen, const ubyte *pPrime1, ubyte4 prime1Len, const ubyte *pPrime2, ubyte4 prime2Len, vlong **ppVlongQueue)
This is the same as RSA_setAllKeyParameters, except the public exponent is passed in as a canonical i...
MOC_EXTERN MSTATUS RSA_createKey(RSAKey **pp_RetRSAKey)
Create memory storage for an RSA key pair.
MOC_EXTERN MSTATUS RSA_getCipherTextLength(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, sbyte4 *pCipherTextLen)
Get an RSA public key's ciphertext length.
MOC_EXTERN MSTATUS RSA_applyPublicKey(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pPublicKey, ubyte *pInput, ubyte4 inputLen, ubyte **ppOutput, vlong **ppVlongQueue)
This function performs an RSA public key operation with no padding.
MOC_EXTERN MSTATUS RSA_getKeyParametersAlloc(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, MRsaKeyTemplatePtr pTemplate, ubyte keyType)
Retrieve the following components from an RSA key as byte string buffers:
MOC_EXTERN MSTATUS RSA_byteStringFromKey(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, ubyte *pBuffer, ubyte4 *pRetLen)
Convert RSA key to a string of (PKCS #1) bytes.
MOC_EXTERN MSTATUS RSA_prepareKey(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pRSAKey, vlong **ppVlongQueue)
Compute RSA private key.
MOC_EXTERN MSTATUS RSA_setPublicKeyData(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte *pPubExpo, ubyte4 pubExpoLen, const ubyte *pModulus, ubyte4 modulusLen, vlong **ppVlongQueue)
This is the same as RSA_setPublicKeyParameters, except the public exponent is passed in as a canonica...
MOC_EXTERN MSTATUS RSA_keyFromByteString(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey **ppKey, const ubyte *byteString, ubyte4 len, vlong **ppVlongQueue)
Convert byte string to RSA key, using PKCS #1.