TrustCore SDK NanoCert API reference  version 7.0
asn1cert.h File Reference

Header file for ASN.1 Certificate Encoding methods. More...

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS ASN1CERT_AddExtensions (DER_ITEMPTR pExtensionTag, const certExtensions *pExtensions, DER_ITEMPTR *ppExtsItem)
 Writes the extensions to a certificate in the process of being generated. More...
 
MOC_EXTERN MSTATUS ASN1CERT_generateCertificate (MOC_ASYM(hwAccelDescr hwAccelCtx) AsymmetricKey *pCertKey, const certDistinguishedName *pSubjectInfo, const AsymmetricKey *pSignKey, const ASN1_ITEM *pIssuerInfo, CStream cs, ubyte signAlgo, const certExtensions *pExtensions, RNGFun rngFun, void *rngFunArg, ubyte **ppRetCertificate, ubyte4 *pRetCertLength)
 Generate a certificate with the given input key, signing key, name, issuer, and extensions. More...
 
MOC_EXTERN MSTATUS ASN1CERT_generateCertificateEx (MOC_ASYM(hwAccelDescr hwAccelCtx) const AsymmetricKey *pCertKey, const certDistinguishedName *pSubjectInfo, const AsymmetricKey *pSignKey, const ASN1_ITEM *pIssuerInfo, CStream cs, const ubyte *serialNumber, ubyte4 serialNumberLen, ubyte signAlgo, const certExtensions *pExtensions, RNGFun rngFun, void *rngFunArg, ubyte **ppRetCertificate, ubyte4 *pRetCertLength)
 Generate a certificate with the given input key, signing key, name, issuer, and extensions. More...
 
MOC_EXTERN MSTATUS ASN1CERT_generateSelfSignedCertificate (MOC_ASYM(hwAccelDescr hwAccelCtx) AsymmetricKey *pCertKey, const certDistinguishedName *pSubjectInfo, ubyte signAlgo, const certExtensions *pExtensions, RNGFun rngFun, void *rngFunArg, ubyte **ppRetCertificate, ubyte4 *pRetCertLength)
 Generate a self-signed certificate with the given key, name, and extensions. More...
 
MOC_EXTERN MSTATUS ASN1CERT_Sign (MOC_ASYM(hwAccelDescr hwAccelCtx) DER_ITEMPTR pSignedHead, const AsymmetricKey *pSignKey, ubyte signAlgo, RNGFun rngFun, void *rngFunArg, ubyte **ppRetDEREncoding, ubyte4 *pRetDEREncodingLen)
 Signs a certificate with a given asymmetric key. More...
 
MOC_EXTERN MSTATUS ASN1CERT_StoreDistinguishedName (DER_ITEMPTR pRoot, const certDistinguishedName *pCertInfo)
 Writes the distinguished name components to a certificate in the process of being generated. More...
 
MOC_EXTERN MSTATUS ASN1CERT_storePublicKeyInfo (MOC_ASYM(hwAccelDescr hwAccelCtx) const AsymmetricKey *pPublicKey, DER_ITEMPTR pCertificate)
 Writes the public key information to a certificate in the process of being generated. More...
 

Detailed Description

Header file for ASN.1 Certificate Encoding methods.

asn1cert.h

Function Documentation

◆ ASN1CERT_AddExtensions()

MOC_EXTERN MSTATUS ASN1CERT_AddExtensions ( DER_ITEMPTR  pExtensionTag,
const certExtensions pExtensions,
DER_ITEMPTR *  ppExtsItem 
)

Writes the extensions to a certificate in the process of being generated. This method should be used as a substep in certificate generation and should not be used on an already generated certificate. This method will NOT overwrite previously existing extensions.

Parameters
pExtensionTagPointer to the item (ie place) in the certificate for where the extensions should be added.
pExtensionsPointer to the certificate extensions data structure. The definition of this structure can be found in ca_mgmt.h.
ppExtsItemContents will be set to the location of the new extensions item within the certificate.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ ASN1CERT_generateCertificate()

MOC_EXTERN MSTATUS ASN1CERT_generateCertificate ( MOC_ASYM(hwAccelDescr hwAccelCtx) AsymmetricKey *  pCertKey,
const certDistinguishedName pSubjectInfo,
const AsymmetricKey *  pSignKey,
const ASN1_ITEM *  pIssuerInfo,
CStream  cs,
ubyte  signAlgo,
const certExtensions pExtensions,
RNGFun  rngFun,
void *  rngFunArg,
ubyte **  ppRetCertificate,
ubyte4 *  pRetCertLength 
)

Generate a certificate with the given input key, signing key, name, issuer, and extensions. The certificate will be in DER form. Memory will be allocated for the buffer holding the generated certificate. Please be sure to free this buffer when done with it.

Parameters
pCertKeyThe input key to associate with the certificate.
pSubjectInfoPointer to the certificate distinguished name structure. The definition of this structure can be found in ca_mgmt.h.
pSignKeyThe signing key. The signing algorithm will coincide with the key type.
pIssuerInfoOptional. Pointer to the issuer of the certificate in ASN1_ITEM form. Please see parseasn1.h for a description of this form. This may be ommitted for self signed certificates.
csContent stream to be used for the pIssuerInfo. This is required if pIssuerInfo is non-null.
signAlgoIf needed, the hashing algorithm to be used in the signature algorithm. This is one of the hash enum's found in crypto.h, for example ht_sha256. Pass ht_none if the signing algorithm is EdDSA.
pExtensionsPointer to the certificate extensions data structure. The definition of this structure can be found in ca_mgmt.h.
rngFunIf needed by the signing algorithm, function pointer to a method that will output random data. Please see the RNGFun definition in random.h.
rngFunArgOptional argument, such as a random context, that may be needed by the rngFun.
ppRetCertificatePointer to the location of the newly allocated buffer holding the generated certificate. This will be a DER form certicicate.
pRetCertLengthThe length of the generated certificate in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ ASN1CERT_generateCertificateEx()

MOC_EXTERN MSTATUS ASN1CERT_generateCertificateEx ( MOC_ASYM(hwAccelDescr hwAccelCtx) const AsymmetricKey *  pCertKey,
const certDistinguishedName pSubjectInfo,
const AsymmetricKey *  pSignKey,
const ASN1_ITEM *  pIssuerInfo,
CStream  cs,
const ubyte *  serialNumber,
ubyte4  serialNumberLen,
ubyte  signAlgo,
const certExtensions pExtensions,
RNGFun  rngFun,
void *  rngFunArg,
ubyte **  ppRetCertificate,
ubyte4 *  pRetCertLength 
)

Generate a certificate with the given input key, signing key, name, issuer, and extensions. The certificate will be in DER form. Memory will be allocated for the buffer holding the generated certificate. Please be sure to free this buffer when done with it.

Parameters
pCertKeyThe input key to associate with the certificate.
pSubjectInfoPointer to the certificate distinguished name structure. The definition of this structure can be found in ca_mgmt.h.
pSignKeyThe signing key. The signing algorithm will coincide with the key type.
pIssuerInfoOptional. Pointer to the issuer of the certificate in ASN1_ITEM form. Please see parseasn1.h for a description of this form. This may be ommitted for self signed certificates.
csContent stream to be used for the pIssuerInfo. This is required if pIssuerInfo is non-null.
serialNumberOptional. Serial number to be used in the certificate. If not provided then it will be generated by a SHA1 hashing of the public key.
serialNumberLenThe length of the serial number in bytes.
signAlgoIf needed, the hashing algorithm to be used in the signature algorithm. This is one of the hash enum's found in crypto.h, for example ht_sha256. Pass ht_none if the signing algorithm is EdDSA.
pExtensionsPointer to the certificate extensions data structure. The definition of this structure can be found in ca_mgmt.h.
rngFunIf needed by the signing algorithm, function pointer to a method that will output random data. Please see the RNGFun definition in random.h.
rngFunArgOptional argument, such as a random context, that may be needed by the rngFun.
ppRetCertificatePointer to the location of the newly allocated buffer holding the generated certificate. This will be a DER form certicicate.
pRetCertLengthThe length of the generated certificate in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ ASN1CERT_generateSelfSignedCertificate()

MOC_EXTERN MSTATUS ASN1CERT_generateSelfSignedCertificate ( MOC_ASYM(hwAccelDescr hwAccelCtx) AsymmetricKey *  pCertKey,
const certDistinguishedName pSubjectInfo,
ubyte  signAlgo,
const certExtensions pExtensions,
RNGFun  rngFun,
void *  rngFunArg,
ubyte **  ppRetCertificate,
ubyte4 *  pRetCertLength 
)

Generate a self-signed certificate with the given key, name, and extensions. The certificate will be in DER form. Memory will be allocated for the buffer holding the generated certificate. Please be sure to free this buffer when done with it.

Parameters
pCertKeyThe input key to associate with the certificate and the signing key. The signing algorithm will coincide with the key type.
pSubjectInfoPointer to the certificate distinguished name structure. The definition of this structure can be found in ca_mgmt.h.
signAlgoIf needed, the hashing algorithm to be used in the signature algorithm. This is one of the hash enum's found in crypto.h, for example ht_sha256. Pass ht_none if the signing algorithm is EdDSA.
pExtensionsPointer to the certificate extensions data structure. The definition of this structure can be found in ca_mgmt.h.
rngFunIf needed by the signing algorithm, function pointer to a method that will output random data. Please see the RNGFun definition in random.h.
rngFunArgOptional argument, such as a random context, that may be needed by the rngFun.
ppRetCertificatePointer to the location of the newly allocated buffer holding the generated certificate. This will be a DER form certicicate.
pRetCertLengthThe length of the generated certificate in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ ASN1CERT_Sign()

MOC_EXTERN MSTATUS ASN1CERT_Sign ( MOC_ASYM(hwAccelDescr hwAccelCtx) DER_ITEMPTR  pSignedHead,
const AsymmetricKey *  pSignKey,
ubyte  signAlgo,
RNGFun  rngFun,
void *  rngFunArg,
ubyte **  ppRetDEREncoding,
ubyte4 *  pRetDEREncodingLen 
)

Signs a certificate with a given asymmetric key. The input certificate is a DER_ITEMPTR pointing to the root of what will be the signed certificate. The output will be the full signed certificate in DER form. Memory will be allocated for the buffer holding output certificate. Please be sure to free this buffer when done with it.

Parameters
pSignedHeadPointer to the root of what will be the signed certificate.
pSignKeyThe signing key. The signing algorithm will coincide with the key type.
signAlgoIf needed, the hashing algorithm to be used in the signature algorithm. This is one of the hash enum's found in crypto.h, for example ht_sha256. Pass ht_none if the signing algorithm is EdDSA.
rngFunIf needed by the signing algorithm, function pointer to a method that will output random data. Please see the RNGFun definition in random.h.
rngFunArgOptional argument, such as a random context, that may be needed by the rngFun.
ppRetDEREncodingPointer to the location of the newly allocated buffer holding the signed certificate. This will be a DER form certicicate.
pRetDEREncodingLenThe length of the signed certificate in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ ASN1CERT_StoreDistinguishedName()

MOC_EXTERN MSTATUS ASN1CERT_StoreDistinguishedName ( DER_ITEMPTR  pRoot,
const certDistinguishedName pCertInfo 
)

Writes all the distinguished name components to a certificate in the process of being generated. This method should be used as a substep in certificate generation and should not be used on an already generated certificate. This method will NOT overwrite previously existing distinguished name components.

Parameters
pRootPointer to the root of the certificate. This is the root of the certificate before it is signed and before it has any distinguished name components.
pCertInfoThe certificate distinguished name structure. The definition of this structure can be found in ca_mgmt.h.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ ASN1CERT_storePublicKeyInfo()

MOC_EXTERN MSTATUS ASN1CERT_storePublicKeyInfo ( MOC_ASYM(hwAccelDescr hwAccelCtx) const AsymmetricKey *  pPublicKey,
DER_ITEMPTR  pCertificate 
)

Writes the public key information to a certificate in the process of being generated. This method should be used as a substep in certificate generation and should not be used on an already generated certificate. This method will NOT overwrite previously existing public key information.

Parameters
pPublicKeyPointer to the public key to be written.
pCertificatePointer to the certificate to which we are generating. This is the root of the certificate before it is signed and before it has any public key information.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.