15#include "hal/library/cryptlib.h"
37 if (Sha256Ctx !=
NULL) {
52libspdm_sha256_duplicate (
53 const void *Sha256Context,
54 void *NewSha256Context
61libspdm_sha256_update (
80libspdm_sha256_hash_all (
109 if (Sha384Ctx !=
NULL) {
124libspdm_sha384_duplicate (
125 const void *sha384_context,
126 void *new_sha384_context
133libspdm_sha384_update (
134 void *sha384_context,
143libspdm_sha384_final (
144 void *sha384_context,
152libspdm_sha384_hash_all (
162libspdm_hmac_sha256_new (
170libspdm_hmac_sha256_free (
171 void *hmac_sha256_ctx
178libspdm_hmac_sha256_set_key (
179 void *hmac_sha256_ctx,
188libspdm_hmac_sha256_duplicate (
189 const void *hmac_sha256_ctx,
190 void *new_hmac_sha256_ctx
197libspdm_hmac_sha256_update (
198 void *hmac_sha256_ctx,
207libspdm_hmac_sha256_final (
208 void *hmac_sha256_ctx,
216libspdm_hmac_sha256_all (
224 return HmacSha256All (data, data_size, key, key_size, hmac_value);
228libspdm_hmac_sha384_new (
236libspdm_hmac_sha384_free (
237 void *hmac_sha384_ctx
244libspdm_hmac_sha384_set_key (
245 void *hmac_sha384_ctx,
254libspdm_hmac_sha384_duplicate (
255 const void *hmac_sha384_ctx,
256 void *new_hmac_sha384_ctx
263libspdm_hmac_sha384_update (
264 void *hmac_sha384_ctx,
273libspdm_hmac_sha384_final (
274 void *hmac_sha384_ctx,
282libspdm_hmac_sha384_all (
290 return HmacSha384All (data, data_size, key, key_size, hmac_value);
294libspdm_aead_aes_gcm_encrypt (
299 const uint8_t *a_data,
301 const uint8_t *data_in,
306 size_t *data_out_size
326libspdm_aead_aes_gcm_decrypt (
331 const uint8_t *a_data,
333 const uint8_t *data_in,
338 size_t *data_out_size
366libspdm_rsa_pkcs1_sign_with_nid (
369 const uint8_t *message_hash,
376 case CRYPTO_NID_SHA256:
383 case CRYPTO_NID_SHA384:
390 case CRYPTO_NID_SHA512:
411libspdm_rsa_pkcs1_verify_with_nid (
414 const uint8_t *message_hash,
416 const uint8_t *signature,
421 case CRYPTO_NID_SHA256:
428 case CRYPTO_NID_SHA384:
435 case CRYPTO_NID_SHA512:
456libspdm_rsa_get_private_key_from_pem (
457 const uint8_t *pem_data,
459 const char *password,
467libspdm_rsa_get_public_key_from_x509 (
477libspdm_ec_get_public_key_from_der (
478 const uint8_t *der_data,
487libspdm_rsa_get_public_key_from_der (
488 const uint8_t *der_data,
497libspdm_ec_get_private_key_from_pem (
498 const uint8_t *pem_data,
500 const char *password,
508libspdm_ec_get_public_key_from_x509 (
518libspdm_asn1_get_tag (
529libspdm_x509_get_subject_name (
532 uint8_t *cert_subject,
540libspdm_x509_get_common_name (
544 size_t *common_name_size
550 if (EFI_ERROR (Status)) {
558libspdm_x509_get_organization_name (
562 size_t *name_buffer_size
568 if (EFI_ERROR (Status)) {
576libspdm_x509_get_version (
586libspdm_x509_get_serial_number (
589 uint8_t *serial_number,
590 size_t *serial_number_size
597libspdm_x509_get_issuer_name (
600 uint8_t *cert_issuer,
608libspdm_x509_get_signature_algorithm (
619libspdm_x509_get_extension_data (
624 uint8_t *extension_data,
625 size_t *extension_data_size
639libspdm_x509_get_validity (
648 return X509GetValidity (cert, cert_size, from, from_size, to, to_size);
652libspdm_x509_set_date_time (
653 const char *date_time_str,
655 size_t *date_time_size
662libspdm_x509_compare_date_time (
663 const void *date_time1,
664 const void *date_time2
671libspdm_x509_get_key_usage (
681libspdm_x509_get_extended_key_usage (
692libspdm_x509_verify_cert (
695 const uint8_t *ca_cert,
703libspdm_x509_verify_cert_chain (
704 const uint8_t *root_cert,
705 size_t root_cert_length,
706 const uint8_t *cert_chain,
707 size_t cert_chain_length
714libspdm_x509_get_cert_from_cert_chain (
715 const uint8_t *cert_chain,
716 size_t cert_chain_length,
717 const int32_t cert_index,
718 const uint8_t **cert,
732libspdm_x509_construct_certificate (
735 uint8_t **single_x509_cert
742libspdm_x509_get_extended_basic_constraints (
745 uint8_t *basic_constraints,
746 size_t *basic_constraints_size
753 basic_constraints_size
758libspdm_ec_new_by_nid (
774libspdm_ec_generate_key (
776 uint8_t *public_data,
784libspdm_ec_compute_key (
786 const uint8_t *peer_public,
787 size_t peer_public_size,
792 return EcDhComputeKey (ec_context, peer_public, peer_public_size,
NULL, key, key_size);
799 const uint8_t *message_hash,
816libspdm_ecdsa_verify (
819 const uint8_t *message_hash,
821 const uint8_t *signature,
836libspdm_random_bytes (
845libspdm_hkdf_sha256_extract_and_expand (
869libspdm_hkdf_sha256_extract (
889libspdm_hkdf_sha256_expand (
909libspdm_hkdf_sha384_extract_and_expand (
933libspdm_hkdf_sha384_extract (
953libspdm_hkdf_sha384_expand (
BOOLEAN EFIAPI X509GetSerialNumber(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINT8 *SerialNumber, OPTIONAL IN OUT UINTN *SerialNumberSize)
BOOLEAN EFIAPI HmacSha384Update(IN OUT VOID *HmacSha384Context, IN CONST VOID *Data, IN UINTN DataSize)
INT32 EFIAPI X509CompareDateTime(IN CONST VOID *DateTime1, IN CONST VOID *DateTime2)
UINTN EFIAPI Sha256GetContextSize(VOID)
BOOLEAN EFIAPI HmacSha384SetKey(OUT VOID *HmacSha384Context, IN CONST UINT8 *Key, IN UINTN KeySize)
BOOLEAN EFIAPI HkdfSha256Extract(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, OUT UINT8 *PrkOut, UINTN PrkOutSize)
BOOLEAN EFIAPI EcGenerateKey(IN OUT VOID *EcContext, OUT UINT8 *PublicKey, IN OUT UINTN *PublicKeySize)
VOID *EFIAPI HmacSha256New(VOID)
UINTN EFIAPI Sha384GetContextSize(VOID)
BOOLEAN EFIAPI HmacSha256Duplicate(IN CONST VOID *HmacSha256Context, OUT VOID *NewHmacSha256Context)
VOID *EFIAPI HmacSha384New(VOID)
BOOLEAN EFIAPI X509GetVersion(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINTN *Version)
BOOLEAN EFIAPI X509GetExtensionData(IN CONST UINT8 *Cert, IN UINTN CertSize, IN CONST UINT8 *Oid, IN UINTN OidSize, OUT UINT8 *ExtensionData, IN OUT UINTN *ExtensionDataSize)
BOOLEAN EFIAPI Sha384Duplicate(IN CONST VOID *Sha384Context, OUT VOID *NewSha384Context)
BOOLEAN EFIAPI HmacSha384All(IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
BOOLEAN EFIAPI X509GetIssuerName(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINT8 *CertIssuer, IN OUT UINTN *CertIssuerSize)
BOOLEAN EFIAPI AeadAesGcmDecrypt(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Iv, IN UINTN IvSize, IN CONST UINT8 *AData, IN UINTN ADataSize, IN CONST UINT8 *DataIn, IN UINTN DataInSize, IN CONST UINT8 *Tag, IN UINTN TagSize, OUT UINT8 *DataOut, OUT UINTN *DataOutSize)
BOOLEAN EFIAPI RsaGetPrivateKeyFromPem(IN CONST UINT8 *PemData, IN UINTN PemSize, IN CONST CHAR8 *Password, OUT VOID **RsaContext)
BOOLEAN EFIAPI EcDsaSign(IN VOID *EcContext, IN UINTN HashNid, IN CONST UINT8 *MessageHash, IN UINTN HashSize, OUT UINT8 *Signature, IN OUT UINTN *SigSize)
VOID EFIAPI HmacSha384Free(IN VOID *HmacSha384Ctx)
BOOLEAN EFIAPI X509FormatDateTime(IN CONST CHAR8 *DateTimeStr, OUT VOID *DateTime, IN OUT UINTN *DateTimeSize)
BOOLEAN EFIAPI X509VerifyCert(IN CONST UINT8 *Cert, IN UINTN CertSize, IN CONST UINT8 *CACert, IN UINTN CACertSize)
VOID EFIAPI HmacSha256Free(IN VOID *HmacSha256Ctx)
BOOLEAN EFIAPI HmacSha384Duplicate(IN CONST VOID *HmacSha384Context, OUT VOID *NewHmacSha384Context)
BOOLEAN EFIAPI RandomBytes(OUT UINT8 *Output, IN UINTN Size)
#define SHA512_DIGEST_SIZE
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
BOOLEAN EFIAPI X509GetSignatureAlgorithm(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINT8 *Oid, OPTIONAL IN OUT UINTN *OidSize)
BOOLEAN EFIAPI RsaGetPublicKeyFromX509(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT VOID **RsaContext)
RETURN_STATUS EFIAPI X509GetOrganizationName(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT CHAR8 *NameBuffer OPTIONAL, IN OUT UINTN *NameBufferSize)
BOOLEAN EFIAPI X509GetExtendedKeyUsage(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINT8 *Usage, IN OUT UINTN *UsageSize)
BOOLEAN EFIAPI Sha384HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
VOID *EFIAPI EcNewByNid(IN UINTN Nid)
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
#define SHA256_DIGEST_SIZE
BOOLEAN EFIAPI HkdfSha384ExtractAndExpand(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
BOOLEAN EFIAPI X509GetValidity(IN CONST UINT8 *Cert, IN UINTN CertSize, IN UINT8 *From, IN OUT UINTN *FromSize, IN UINT8 *To, IN OUT UINTN *ToSize)
BOOLEAN EFIAPI HmacSha384Final(IN OUT VOID *HmacSha384Context, OUT UINT8 *HmacValue)
BOOLEAN EFIAPI Sha384Update(IN OUT VOID *Sha384Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI Sha256Duplicate(IN CONST VOID *Sha256Context, OUT VOID *NewSha256Context)
BOOLEAN EFIAPI HmacSha256SetKey(OUT VOID *HmacSha256Context, IN CONST UINT8 *Key, IN UINTN KeySize)
BOOLEAN EFIAPI EcGetPrivateKeyFromPem(IN CONST UINT8 *PemData, IN UINTN PemSize, IN CONST CHAR8 *Password, OUT VOID **EcContext)
BOOLEAN EFIAPI HmacSha256Update(IN OUT VOID *HmacSha256Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI HkdfSha384Extract(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, OUT UINT8 *PrkOut, UINTN PrkOutSize)
BOOLEAN EFIAPI Sha256HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Asn1GetTag(IN OUT UINT8 **Ptr, IN CONST UINT8 *End, OUT UINTN *Length, IN UINT32 Tag)
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI HmacSha256All(IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
BOOLEAN EFIAPI EcGetPublicKeyFromX509(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT VOID **EcContext)
BOOLEAN EFIAPI HkdfSha256Expand(IN CONST UINT8 *Prk, IN UINTN PrkSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
VOID EFIAPI RsaFree(IN VOID *RsaContext)
BOOLEAN EFIAPI HkdfSha256ExtractAndExpand(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
BOOLEAN EFIAPI EcDsaVerify(IN VOID *EcContext, IN UINTN HashNid, IN CONST UINT8 *MessageHash, IN UINTN HashSize, IN CONST UINT8 *Signature, IN UINTN SigSize)
BOOLEAN EFIAPI Sha384Final(IN OUT VOID *Sha384Context, OUT UINT8 *HashValue)
BOOLEAN EFIAPI X509GetCertFromCertChain(IN CONST UINT8 *CertChain, IN UINTN CertChainLength, IN CONST INT32 CertIndex, OUT CONST UINT8 **Cert, OUT UINTN *CertLength)
BOOLEAN EFIAPI X509GetSubjectName(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINT8 *CertSubject, IN OUT UINTN *SubjectSize)
BOOLEAN EFIAPI AeadAesGcmEncrypt(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Iv, IN UINTN IvSize, IN CONST UINT8 *AData, IN UINTN ADataSize, IN CONST UINT8 *DataIn, IN UINTN DataInSize, OUT UINT8 *TagOut, IN UINTN TagSize, OUT UINT8 *DataOut, OUT UINTN *DataOutSize)
BOOLEAN EFIAPI EcDhComputeKey(IN OUT VOID *EcContext, IN CONST UINT8 *PeerPublic, IN UINTN PeerPublicSize, IN CONST INT32 *CompressFlag, OUT UINT8 *Key, IN OUT UINTN *KeySize)
BOOLEAN EFIAPI Sha384Init(OUT VOID *Sha384Context)
BOOLEAN EFIAPI X509GetKeyUsage(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINTN *Usage)
BOOLEAN EFIAPI RsaPkcs1Verify(IN VOID *RsaContext, IN CONST UINT8 *MessageHash, IN UINTN HashSize, IN CONST UINT8 *Signature, IN UINTN SigSize)
BOOLEAN EFIAPI X509GetExtendedBasicConstraints(CONST UINT8 *Cert, UINTN CertSize, UINT8 *BasicConstraints, UINTN *BasicConstraintsSize)
RETURN_STATUS EFIAPI X509GetCommonName(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT CHAR8 *CommonName OPTIONAL, IN OUT UINTN *CommonNameSize)
BOOLEAN EFIAPI HmacSha256Final(IN OUT VOID *HmacSha256Context, OUT UINT8 *HmacValue)
BOOLEAN EFIAPI HkdfSha384Expand(IN CONST UINT8 *Prk, IN UINTN PrkSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
#define SHA384_DIGEST_SIZE
BOOLEAN EFIAPI X509VerifyCertChain(IN CONST UINT8 *RootCert, IN UINTN RootCertLength, IN CONST UINT8 *CertChain, IN UINTN CertChainLength)
BOOLEAN EFIAPI X509ConstructCertificate(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINT8 **SingleX509Cert)
BOOLEAN EFIAPI RsaPkcs1Sign(IN VOID *RsaContext, IN CONST UINT8 *MessageHash, IN UINTN HashSize, OUT UINT8 *Signature, IN OUT UINTN *SigSize)
VOID EFIAPI EcFree(IN VOID *EcContext)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)