TrustCore SDK Crypto Interface API reference  version 2.0
crypto_interface_rsa.h
Go to the documentation of this file.
1 /*
2  * crypto_interface_rsa.h
3  *
4  * Cryptographic Interface header file for declaring RSA functions
5  * for the Crypto Interface.
6  *
7  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
8  * Proprietary and Confidential Material.
9  *
10  */
11 
19 #ifndef __CRYPTO_INTERFACE_RSA_HEADER__
20 #define __CRYPTO_INTERFACE_RSA_HEADER__
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
37 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_createKey(
38  void** ppNewKey,
39  ubyte4 keyType,
40  void *pKeyAttributes
41  );
42 
43 /* Generate a new RSA keypair */
44 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_generateKeyAlloc(
45  MOC_RSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext,
46  void **ppNewKey,
47  ubyte4 keySize,
48  vlong **ppVlongQueue,
49  ubyte4 keyType,
50  void *pKeyAttributes
51  );
52 
62 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_createKeyAux(
63  RSAKey **ppNewKey
64  );
65 
75 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_freeKeyAux(
76  RSAKey **ppRsaKey,
77  vlong **ppVlongQueue
78  );
79 
92 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_signMessageAux(
93  MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey,
94  const ubyte *pPlainText,
95  ubyte4 plainTextLen,
96  ubyte *pCipherText,
97  vlong **ppVlongQueue
98  );
99 
112 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_verifySignatureAux(
113  MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey,
114  const ubyte *pCipherText,
115  ubyte *pPlainText,
116  ubyte4 *pPlainTextLen,
117  vlong **ppVlongQueue
118  );
119 
148 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_verifyDigest(MOC_RSA(hwAccelDescr hwAccelCtx)
149  RSAKey *pKey,
150  ubyte *pMsgDigest,
151  ubyte4 digestLen,
152  ubyte* pSignature,
153  ubyte4 sigLen,
154  intBoolean *pIsValid,
155  vlong **ppVlongQueue);
156 
167  MOC_RSA(hwAccelDescr hwAccelCtx)
168  const RSAKey *pKey,
169  sbyte4 *pCipherTextLen
170  );
171 
186  MOC_RSA(hwAccelDescr hwAccelCtx)
187  RSAKey *pKey,
188  ubyte4 exponent,
189  const ubyte *pModulus,
190  ubyte4 modulusLen,
191  vlong **ppVlongQueue
192  );
193 
208 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_setPublicKeyData(
209  MOC_RSA(hwAccelDescr hwAccelCtx)
210  RSAKey *pKey,
211  ubyte *pPubExpo,
212  ubyte4 pubExpoLen,
213  const ubyte *pModulus,
214  ubyte4 modulusLen,
215  vlong **ppVlongQueue
216  );
217 
218 
236 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_setAllKeyParameters (
237  MOC_RSA(hwAccelDescr hwAccelCtx)
238  RSAKey *pKey,
239  ubyte4 exponent,
240  const ubyte *modulus,
241  ubyte4 modulusLen,
242  const ubyte *prime1,
243  ubyte4 prime1Len,
244  const ubyte *prime2,
245  ubyte4 prime2Len,
246  vlong **ppVlongQueue
247  );
248 
267 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_setAllKeyDataAux(
268  MOC_RSA(hwAccelDescr hwAccelCtx)
269  RSAKey *pKey,
270  ubyte *pPubExpo,
271  ubyte4 pubExpoLen,
272  const ubyte *pModulus,
273  ubyte4 modulusLen,
274  const ubyte *pPrime1,
275  ubyte4 prime1Len,
276  const ubyte *pPrime2,
277  ubyte4 prime2Len,
278  vlong **ppVlongQueue
279  );
280 
305  MOC_RSA(hwAccelDescr hwAccelCtx)
306  RSAKey *pKey,
307  MRsaKeyTemplate *pTemplate,
308  ubyte keyType
309  );
310 
321 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_freeKeyTemplateAux(
322  RSAKey *pKey,
323  MRsaKeyTemplate *pTemplate
324  );
325 
343 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_applyPublicKeyAux(
344  MOC_RSA(hwAccelDescr hwAccelCtx)
345  RSAKey *pKey,
346  ubyte *pInput,
347  ubyte4 inputLen,
348  ubyte **ppOutput,
349  vlong **ppVlongQueue
350  );
351 
373 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_applyPrivateKeyAux(
374  MOC_RSA(hwAccelDescr hwAccelCtx)
375  RSAKey *pKey,
376  RNGFun rngFun,
377  void *rngFunArg,
378  ubyte *pInput,
379  ubyte4 inputLen,
380  ubyte **ppOutput,
381  vlong **ppVlongQueue
382  );
383 
407 MOC_EXTERN MSTATUS
409  MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey,
410  const ubyte *pPlainText,
411  ubyte4 plainTextLen,
412  ubyte *pCipherText,
413  RNGFun rngFun,
414  void *pRngFunArg,
415  vlong **ppVlongQueue
416  );
417 
441 MOC_EXTERN MSTATUS
443  MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey,
444  const ubyte *pCipherText,
445  ubyte *pPlainText,
446  ubyte4 *pPlainTextLen,
447  RNGFun rngFun,
448  void *pRngFunArg,
449  vlong **ppVlongQueue
450  );
451 
470 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_keyFromByteString (
471  MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey **ppKey,
472  const ubyte* pByteString,
473  ubyte4 len,
474  vlong** ppVlongQueue
475  );
476 
494 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_generateKey (
495  MOC_RSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext,
496  RSAKey *pRsaKey,
497  ubyte4 keySize,
498  vlong **ppVlongQueue
499  );
500 
518 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_byteStringFromKey (
519  MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey,
520  ubyte *pBuffer,
521  ubyte4 *pRetLen
522  );
523 
540 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_cloneKey (
541  MOC_RSA(hwAccelDescr hwAccelCtx)
542  RSAKey **ppNewKey,
543  const RSAKey *pSrc,
544  vlong **ppVlongQueue
545  );
546 
563 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_equalKey (
564  MOC_RSA(hwAccelDescr hwAccelCtx)
565  const RSAKey *pKey1,
566  const RSAKey *pKey2,
567  byteBoolean *pRes
568  );
569 
587  MOC_RSA(hwAccelDescr hwAccelCtx)
588  RSAKey *pKey,
589  MRsaKeyTemplate *pTemplate,
590  ubyte keyType
591  );
592 
614 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_pkcs15Pad(
615  MOC_RSA(hwAccelDescr hwAccelCtx)
616  RSAKey *pKey,
617  ubyte4 operation,
618  RNGFun rngFun,
619  void *pRngFunArg,
620  ubyte *pM,
621  ubyte4 mLen,
622  ubyte **ppRetPaddedMsg,
623  ubyte4 *pRetPaddedMsgLen
624  );
625 
635 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_getKeyBitLen(
636  MOC_RSA(hwAccelDescr hwAccelCtx)
637  RSAKey *pKey,
638  ubyte4 *pBitLen
639 );
640 
641 #ifdef __cplusplus
642 }
643 #endif
644 
645 #endif /* __CRYPTO_INTERFACE_RSA_HEADER__ */
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_verifySignatureAux(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *pCipherText, ubyte *pPlainText, ubyte4 *pPlainTextLen, vlong **ppVlongQueue)
Uses an RSA key to verify the signature and write to pCipherText.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_cloneKey(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey **ppNewKey, const RSAKey *pSrc, vlong **ppVlongQueue)
Clone (copy) an RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_keyFromByteString(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey **ppKey, const ubyte *pByteString, ubyte4 len, vlong **ppVlongQueue)
Make an RSAKey object from a byte string.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_equalKey(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey1, const RSAKey *pKey2, byteBoolean *pRes)
Determine whether two RSA keys are equal.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_applyPrivateKeyAux(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, RNGFun rngFun, void *rngFunArg, ubyte *pInput, ubyte4 inputLen, ubyte **ppOutput, vlong **ppVlongQueue)
Apply the private key to the input data.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_setPublicKeyParametersAux(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte4 exponent, const ubyte *pModulus, ubyte4 modulusLen, vlong **ppVlongQueue)
Set the public parameters of an RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_pkcs15Pad(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte4 operation, RNGFun rngFun, void *pRngFunArg, ubyte *pM, ubyte4 mLen, ubyte **ppRetPaddedMsg, ubyte4 *pRetPaddedMsgLen)
Used to generated PKCS 1.5 padded data.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_applyPublicKeyAux(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte *pInput, ubyte4 inputLen, ubyte **ppOutput, vlong **ppVlongQueue)
Apply the public key to the input data.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_encryptAux(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *pPlainText, ubyte4 plainTextLen, ubyte *pCipherText, RNGFun rngFun, void *pRngFunArg, vlong **ppVlongQueue)
Creates RSA encryption.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_freeKeyAux(RSAKey **ppRsaKey, vlong **ppVlongQueue)
Free an RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_setPublicKeyData(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte *pPubExpo, ubyte4 pubExpoLen, const ubyte *pModulus, ubyte4 modulusLen, vlong **ppVlongQueue)
Set the public parameters of an RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_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 CRYPTO_INTERFACE_RSA_setAllKeyDataAux(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)
Set all the parameters in a RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_decryptAux(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *pCipherText, ubyte *pPlainText, ubyte4 *pPlainTextLen, RNGFun rngFun, void *pRngFunArg, vlong **ppVlongQueue)
Decrypts the given cipher text using RSA decryption.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_getKeyParametersAllocAux(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, MRsaKeyTemplate *pTemplate, ubyte keyType)
Allocates and sets the appropriate key parameters of pTemplate with the data in the key...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_generateKey(MOC_RSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, RSAKey *pRsaKey, ubyte4 keySize, vlong **ppVlongQueue)
Generate a key pair for pRsaKey using pRandomContext for entropy.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_freeKeyTemplateAux(RSAKey *pKey, MRsaKeyTemplate *pTemplate)
Free the RSA key template.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_createKey(void **ppNewKey, ubyte4 keyType, void *pKeyAttributes)
Create a new RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_getKeyBitLen(MOC_RSA(hwAccelDescr hwAccelCtx) RSAKey *pKey, ubyte4 *pBitLen)
Gets the bitlength of an RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_getCipherTextLengthAux(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, sbyte4 *pCipherTextLen)
Get length of cipher text associated with RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_RSA_signMessageAux(MOC_RSA(hwAccelDescr hwAccelCtx) const RSAKey *pKey, const ubyte *pPlainText, ubyte4 plainTextLen, ubyte *pCipherText, vlong **ppVlongQueue)
Uses an RSA key to sign the plain text and write to pCipherText.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_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 all the parameters in a RSA key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_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 CRYPTO_INTERFACE_RSA_createKeyAux(RSAKey **ppNewKey)
Create a new RSA key.