TrustCore SDK NanoCrypto API reference  version 7.0
dsa.h
Go to the documentation of this file.
1 /*
2  * dsa.h
3  *
4  * DSA Factory Header
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
23 /*------------------------------------------------------------------*/
24 
25 
26 #ifndef __DSA_HEADER__
27 #define __DSA_HEADER__
28 
29 #include "../cap/capdecl.h"
30 
31 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE__
32 #include "../crypto_interface/crypto_interface_dsa_priv.h"
33 #endif
34 
35 #include "../crypto/ffc.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /*------------------------------------------------------------------*/
42 
43 #define DSA_CONTEXT(X) (X)->p_dsaDescr
44 #define PRIVATE_KEY_BYTE_SIZE (20) /* To be deleted in the future. Should no longer be used. */
45 
46 
47 /*------------------------------------------------------------------*/
48 
49 struct vlong;
50 
51 #define NUM_DSA_VLONG (5)
52 #define NUM_DSA_MODEXP (2)
53 
54 typedef struct DSAKey
55 {
56  vlong* dsaVlong[NUM_DSA_VLONG];
57 
58  MocAsymKey pPrivateKey;
59  MocAsymKey pPublicKey;
60  ubyte4 enabled;
61 } DSAKey;
62 
63 typedef enum
64 {
65  DSA_sha1 = FFC_sha1,
66  DSA_sha224 = FFC_sha224,
67  DSA_sha256 = FFC_sha256,
68  DSA_sha384 = FFC_sha384,
69  DSA_sha512 = FFC_sha512
70 
71 } DSAHashType;
72 
73 typedef enum
74 {
75  DSA_186_2,
76  DSA_186_4
77 } DSAKeyType;
78 
79 #define DSA_P(k) ((k)->dsaVlong[0])
80 #define DSA_Q(k) ((k)->dsaVlong[1])
81 #define DSA_G(k) ((k)->dsaVlong[2])
82 #define DSA_Y(k) ((k)->dsaVlong[3])
83 #define DSA_X(k) ((k)->dsaVlong[4])
84 
85 typedef struct MDsaKeyTemplate *MDsaKeyTemplatePtr;
86 
87 /*------------------------------------------------------------------*/
88 
129 MOC_EXTERN MSTATUS DSA_createKey(DSAKey **pp_dsaDescr);
130 
131 
169 MOC_EXTERN MSTATUS DSA_cloneKey(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey** ppNew, const DSAKey* pSrc);
170 
171 
213 MOC_EXTERN MSTATUS DSA_freeKey(DSAKey **pp_dsaDescr, vlong **ppVlongQueue);
214 
215 
285 MOC_EXTERN MSTATUS DSA_generateKey(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize, ubyte4 *pRetC, ubyte *pRetSeed, vlong **ppRetH, vlong **ppVlongQueue);
286 
287 
335 MOC_EXTERN MSTATUS DSA_generateKeyEx(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize, ubyte4 qSize, DSAHashType hashType, ubyte4 *pRetC, ubyte *pRetSeed, vlong **ppRetH, vlong **ppVlongQueue);
336 
337 
389 MOC_EXTERN MSTATUS DSA_computeKeyPair(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, DSAKey *p_dsaDescr, vlong **ppVlongQueue);
390 
391 
429 MOC_EXTERN MSTATUS DSA_computeKeyPairEx(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 Lin, ubyte4 Nin, vlong **ppVlongQueue);
430 
431 
479 MOC_EXTERN MSTATUS DSA_computeSignature(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, const DSAKey *p_dsaDescr,
480  vlong* m, intBoolean *pVerifySignature, vlong **ppR, vlong **ppS, vlong **ppVlongQueue);
481 
482 
532 MOC_EXTERN MSTATUS DSA_computeSignatureEx(MOC_DSA(hwAccelDescr hwAccelCtx)
533  RNGFun rngfun, void* rngArg,
534  const DSAKey *p_dsaDescr, vlong* m,
535  intBoolean *pVerifySignature,
536  vlong **ppR, vlong **ppS, vlong **ppVlongQueue);
537 
538 
586 MOC_EXTERN MSTATUS DSA_verifySignature(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *p_dsaDescr,
587  vlong *m, vlong *pR, vlong *pS, intBoolean *isGoodSignature, vlong **ppVlongQueue);
588 
589 
627 MOC_EXTERN MSTATUS DSA_verifyKeys(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, ubyte *pSeed, const DSAKey *p_dsaDescr, ubyte4 C, vlong *pH, intBoolean *isGoodKeys, vlong **ppVlongQueue);
628 
629 
682 MOC_EXTERN MSTATUS DSA_verifyKeysEx(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, ubyte *pSeed, ubyte4 seedSize, const DSAKey *p_dsaDescr, DSAHashType hashType, DSAKeyType keyType, ubyte4 C, vlong *pH, intBoolean *isGoodKeys, vlong **ppVlongQueue);
683 
684 
716 MOC_EXTERN MSTATUS DSA_verifyPQ(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx,
717  DSAKey *p_dsaDescr, ubyte4 L, ubyte4 Nin, DSAHashType hashType, DSAKeyType keyType, ubyte4 C,
718  ubyte *pSeed, ubyte4 seedSize, intBoolean *pIsPrimePQ, vlong **ppVlongQueue);
719 
743 MOC_EXTERN MSTATUS DSA_verifyG(MOC_DSA(hwAccelDescr hwAccelCtx) vlong *pP, vlong *pQ, vlong *pG, intBoolean *isValid, vlong **ppVlongQueue);
744 
745 
792 MOC_EXTERN MSTATUS DSA_makeKeyBlob(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *p_dsaDescr, ubyte *pKeyBlob, ubyte4 *pRetKeyBlobLength);
793 
794 
834 MOC_EXTERN MSTATUS DSA_extractKeyBlob(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey **pp_RetNewDsaDescr, const ubyte *pKeyBlob, ubyte4 keyBlobLength);
835 
836 
875 MOC_EXTERN MSTATUS DSA_equalKey(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *pKey1, const DSAKey *pKey2, byteBoolean* pResult);
876 
877 
909 MOC_EXTERN MSTATUS DSA_setAllKeyParameters(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey* pKey, const ubyte* p, ubyte4 pLen,
910  const ubyte* q, ubyte4 qLen,
911  const ubyte* g, ubyte4 gLen,
912  const ubyte* x, ubyte4 xLen,
913  vlong **ppVlongQueue);
914 
946 MOC_EXTERN MSTATUS DSA_setPublicKeyParameters(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey* pKey, const ubyte* p, ubyte4 pLen,
947  const ubyte* q, ubyte4 qLen,
948  const ubyte* g, ubyte4 gLen,
949  const ubyte* y, ubyte4 yLen,
950  vlong **ppVlongQueue);
951 
981 MOC_EXTERN MSTATUS DSA_setKeyParameters (MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, const ubyte* p, ubyte4 pLen,
982  const ubyte* q, ubyte4 qLen,
983  const ubyte* g, ubyte4 gLen,
984  vlong **ppVlongQueue);
985 
1004 MOC_EXTERN MSTATUS DSA_getCipherTextLength(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *pKey, sbyte4* cipherTextLen);
1005 
1006 
1027 MOC_EXTERN MSTATUS DSA_getSignatureLength (MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, ubyte4 *pSigLen);
1028 
1072 MOC_EXTERN MSTATUS generatePQ(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx,
1073  DSAKey *p_dsaDescr, ubyte4 L,
1074  ubyte4 Nin, DSAHashType hashType,
1075  ubyte4 *pRetC, ubyte *pRetSeed,
1076  vlong **ppVlongQueue);
1077 
1108 MOC_EXTERN MSTATUS generateG(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *p_dsaDescr,
1109  vlong **ppRetH, vlong **ppVlongQueue);
1110 
1142 MOC_EXTERN MSTATUS DSA_generateRandomG (MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *p_dsaDescr,
1143  randomContext *pRandomContext, vlong **ppRetH, vlong **ppVlongQueue);
1144 
1175 MOC_EXTERN MSTATUS DSA_generateRandomGAux (MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *p_dsaDescr,
1176  randomContext *pRandomContext, ubyte **ppH, ubyte4 *pHLen, vlong **ppVlongQueue);
1177 
1210 MOC_EXTERN MSTATUS DSA_generateKeyAux(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize, vlong **ppVlongQueue);
1211 
1253 MOC_EXTERN MSTATUS DSA_generateKeyAux2(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize,
1254  ubyte4 qSize, DSAHashType hashType, vlong **ppVlongQueue);
1255 
1291 MOC_EXTERN MSTATUS DSA_computeSignatureAux(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pRngCtx, DSAKey *pKey, ubyte *pM, ubyte4 mLen, intBoolean *pVerify, ubyte **ppR, ubyte4 *pRLen, ubyte **ppS, ubyte4 *pSLen, vlong **ppVlongQueue);
1292 
1293 
1328 MOC_EXTERN MSTATUS DSA_verifySignatureAux(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, ubyte *pM, ubyte4 mLen, ubyte *pR, ubyte4 rLen, ubyte *pS, ubyte4 sLen, intBoolean *pIsGoodSignature, vlong **ppVlongQueue);
1329 
1349 MOC_EXTERN MSTATUS DSA_setKeyParametersAux(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, MDsaKeyTemplatePtr pTemplate);
1350 
1373 MOC_EXTERN MSTATUS DSA_getKeyParametersAlloc(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, MDsaKeyTemplatePtr pTemplate, ubyte keyType);
1374 
1393 MOC_EXTERN MSTATUS DSA_freeKeyTemplate(DSAKey *pKey, MDsaKeyTemplatePtr pTemplate);
1394 
1395 #ifdef __cplusplus
1396 }
1397 #endif
1398 
1399 #endif /* __DSA_HEADER__ */
MOC_EXTERN MSTATUS DSA_generateRandomGAux(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *p_dsaDescr, randomContext *pRandomContext, ubyte **ppH, ubyte4 *pHLen, vlong **ppVlongQueue)
Randomly computes a generator g of the cyclic group of order q.
MOC_EXTERN MSTATUS DSA_verifyKeysEx(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, ubyte *pSeed, ubyte4 seedSize, const DSAKey *p_dsaDescr, DSAHashType hashType, DSAKeyType keyType, ubyte4 C, vlong *pH, intBoolean *isGoodKeys, vlong **ppVlongQueue)
Verify DSA key.
MOC_EXTERN MSTATUS DSA_cloneKey(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey **ppNew, const DSAKey *pSrc)
Clone (copy) a DSA key.
MOC_EXTERN MSTATUS DSA_verifyPQ(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 L, ubyte4 Nin, DSAHashType hashType, DSAKeyType keyType, ubyte4 C, ubyte *pSeed, ubyte4 seedSize, intBoolean *pIsPrimePQ, vlong **ppVlongQueue)
Verifies that the parameters p and q come from seed and initial domain parameters passed in...
MOC_EXTERN MSTATUS DSA_generateRandomG(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *p_dsaDescr, randomContext *pRandomContext, vlong **ppRetH, vlong **ppVlongQueue)
Randomly computes a generator g of the cyclic group of order q.
MOC_EXTERN MSTATUS generatePQ(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 L, ubyte4 Nin, DSAHashType hashType, ubyte4 *pRetC, ubyte *pRetSeed, vlong **ppVlongQueue)
Generates the DSA domain parameters p and q.
MOC_EXTERN MSTATUS DSA_setKeyParametersAux(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, MDsaKeyTemplatePtr pTemplate)
Sets DSA key and domain parameters.
MOC_EXTERN MSTATUS DSA_computeSignature(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, const DSAKey *p_dsaDescr, vlong *m, intBoolean *pVerifySignature, vlong **ppR, vlong **ppS, vlong **ppVlongQueue)
Generate DSA signature.
MOC_EXTERN MSTATUS DSA_generateKeyEx(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize, ubyte4 qSize, DSAHashType hashType, ubyte4 *pRetC, ubyte *pRetSeed, vlong **ppRetH, vlong **ppVlongQueue)
Generate DSA key pair (private and public keys).
MOC_EXTERN MSTATUS DSA_generateKeyAux2(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize, ubyte4 qSize, DSAHashType hashType, vlong **ppVlongQueue)
Generate DSA key pair (private and public keys) and associated parameters with flexibility to set the...
MOC_EXTERN MSTATUS DSA_freeKeyTemplate(DSAKey *pKey, MDsaKeyTemplatePtr pTemplate)
Frees the fields within a key template.
MOC_EXTERN MSTATUS DSA_freeKey(DSAKey **pp_dsaDescr, vlong **ppVlongQueue)
Free (delete) a DSA key.
MOC_EXTERN MSTATUS DSA_makeKeyBlob(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *p_dsaDescr, ubyte *pKeyBlob, ubyte4 *pRetKeyBlobLength)
Get DSA key blob converted from DSA key data structure.
MOC_EXTERN MSTATUS DSA_computeKeyPairEx(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 Lin, ubyte4 Nin, vlong **ppVlongQueue)
Generate DSA key pair (but not their associated parameters).
MOC_EXTERN MSTATUS DSA_setAllKeyParameters(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, const ubyte *p, ubyte4 pLen, const ubyte *q, ubyte4 qLen, const ubyte *g, ubyte4 gLen, const ubyte *x, ubyte4 xLen, vlong **ppVlongQueue)
Sets all the DSA domain and key parameters in a DSA key.
MOC_EXTERN MSTATUS DSA_equalKey(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *pKey1, const DSAKey *pKey2, byteBoolean *pResult)
Determine whether two DSA keys are equal.
MOC_EXTERN MSTATUS DSA_getKeyParametersAlloc(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, MDsaKeyTemplatePtr pTemplate, ubyte keyType)
Gets DSA key and domain parameters.
MOC_EXTERN MSTATUS DSA_verifySignature(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *p_dsaDescr, vlong *m, vlong *pR, vlong *pS, intBoolean *isGoodSignature, vlong **ppVlongQueue)
Verify message's DSA signature.
MOC_EXTERN MSTATUS DSA_extractKeyBlob(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey **pp_RetNewDsaDescr, const ubyte *pKeyBlob, ubyte4 keyBlobLength)
Get DSA key data structure converted from DSA key blob.
MOC_EXTERN MSTATUS DSA_computeKeyPair(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, vlong **ppVlongQueue)
Generate DSA key pair (but not their associated parameters).
MOC_EXTERN MSTATUS DSA_verifySignatureAux(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, ubyte *pM, ubyte4 mLen, ubyte *pR, ubyte4 rLen, ubyte *pS, ubyte4 sLen, intBoolean *pIsGoodSignature, vlong **ppVlongQueue)
Verifies a DSA signature.
MOC_EXTERN MSTATUS DSA_computeSignatureEx(MOC_DSA(hwAccelDescr hwAccelCtx) RNGFun rngfun, void *rngArg, const DSAKey *p_dsaDescr, vlong *m, intBoolean *pVerifySignature, vlong **ppR, vlong **ppS, vlong **ppVlongQueue)
This is the same as DSAComputeSignature, except that it uses an RNGFun and rngArg to generate the ran...
MOC_EXTERN MSTATUS DSA_getCipherTextLength(MOC_DSA(hwAccelDescr hwAccelCtx) const DSAKey *pKey, sbyte4 *cipherTextLen)
Gets the length in bytes of the DSA prime p.
MOC_EXTERN MSTATUS DSA_setPublicKeyParameters(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, const ubyte *p, ubyte4 pLen, const ubyte *q, ubyte4 qLen, const ubyte *g, ubyte4 gLen, const ubyte *y, ubyte4 yLen, vlong **ppVlongQueue)
Sets all the DSA domain and public key parameters in a DSA key.
MOC_EXTERN MSTATUS DSA_verifyG(MOC_DSA(hwAccelDescr hwAccelCtx) vlong *pP, vlong *pQ, vlong *pG, intBoolean *isValid, vlong **ppVlongQueue)
Verifies that g generates a cyclic group of prime order q.
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 DSA_createKey(DSAKey **pp_dsaDescr)
Create memory storage for a DSA key.
MOC_EXTERN MSTATUS generateG(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *p_dsaDescr, vlong **ppRetH, vlong **ppVlongQueue)
Deterministically computes a generator g of the cyclic group of order q.
MOC_EXTERN MSTATUS DSA_computeSignatureAux(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pRngCtx, DSAKey *pKey, ubyte *pM, ubyte4 mLen, intBoolean *pVerify, ubyte **ppR, ubyte4 *pRLen, ubyte **ppS, ubyte4 *pSLen, vlong **ppVlongQueue)
Computes the DSA signature.
MOC_EXTERN MSTATUS DSA_generateKeyAux(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize, vlong **ppVlongQueue)
Generate DSA key pair (private and public keys) and associated parameters.
MOC_EXTERN MSTATUS DSA_generateKey(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, DSAKey *p_dsaDescr, ubyte4 keySize, ubyte4 *pRetC, ubyte *pRetSeed, vlong **ppRetH, vlong **ppVlongQueue)
Generate DSA key pair (private and public keys) and associated parameters.
MOC_EXTERN MSTATUS DSA_verifyKeys(MOC_DSA(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, ubyte *pSeed, const DSAKey *p_dsaDescr, ubyte4 C, vlong *pH, intBoolean *isGoodKeys, vlong **ppVlongQueue)
Verify DSA key.
MOC_EXTERN MSTATUS DSA_setKeyParameters(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, const ubyte *p, ubyte4 pLen, const ubyte *q, ubyte4 qLen, const ubyte *g, ubyte4 gLen, vlong **ppVlongQueue)
Sets the DSA domain parameters in a DSA key.
MOC_EXTERN MSTATUS DSA_getSignatureLength(MOC_DSA(hwAccelDescr hwAccelCtx) DSAKey *pKey, ubyte4 *pSigLen)
Gets the length in bytes of the DSA prime q and therefore the signature components r and s...