isl_archive.c
来自「Next BIOS Source code : Extensible Firmw」· C语言 代码 · 共 1,134 行 · 第 1/3 页
C
1,134 行
/*-----------------------------------------------------------------------
* File: archive.c
*
Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
*-----------------------------------------------------------------------
*/
/*
* INTEL CONFIDENTIAL
* This file, software, or program is supplied under the terms of a
* license agreement or nondisclosure agreement with Intel Corporation
* and may not be copied or disclosed except in accordance with the
* terms of that agreement. This file, software, or program contains
* copyrighted material and/or trade secret information of Intel
* Corporation, and must be treated as such. Intel reserves all rights
* in this material, except as the license agreement or nondisclosure
* agreement specifically indicate.
*/
/*
* WARNING: EXPORT RESTRICTED.
* This software is subject to the U.S. Export Administration Regulations
* and other U.S. law, and may not be exported or re-exported to certain
* countries (currently Afghanistan (Taliban-controlled areas), Cuba, Iran,
* Iraq, Libya, North Korea, Serbia (except Kosovo), Sudan and Syria) or to
* persons or entities prohibited from receiving U.S. exports (including Denied
* Parties, Specially Designated Nationals, and entities on the Bureau of
* Export Administration Entity List or involved with missile technology or
* nuclear, chemical or biological weapons).
*/
/*
** Implementation of ISL_ARCHIVE_CONTEXT class
*/
#include "isl_internal.h"
#include "islutil.h"
#include "isl_parse.h"
extern ISL_STATUS isl_VerifyManSectWithAllDigestValues(ISL_SIG_SECTION_PTR pSigSect);
/* internal routines */
/*-----------------------------------------------------------------------------
* Name: isl_CopyMemory
*
* Description:
* Allocates memory and copies a buffer into that allocated memory
*
* Parameters:
* Context (input)
* Buffer (input)
* Size (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
void *isl_CopyMemory(ISL_MEMORY_CONTEXT *Context, const void *Buffer, ISL_SIZE Size)
{
struct isl_memory_buffer *item;
ISL_MEMORY_METHODS *MemoryMethods;
void * AllocRef;
if (!Context) return NULL;
MemoryMethods = Context->MemoryMethods;
AllocRef = Context->AllocRef;
if (Buffer == NULL) {
return NULL;
}
item = MemoryMethods->malloc_func(sizeof(struct isl_memory_buffer), AllocRef);
if (item == NULL) {
ISL_SetError(CSSM_MEMORY_ERROR);
return 0;
}
item->Buffer = MemoryMethods->malloc_func((uint32)Size, AllocRef);
if (item->Buffer == NULL) {
MemoryMethods->free_func(item, AllocRef);
ISL_SetError(CSSM_MEMORY_ERROR);
return 0;
}
item->Next = Context->Buffers;
Context->Buffers = item;
cssm_memcpy(item->Buffer, Buffer, (uint32)Size);
return item->Buffer;
}
/*-----------------------------------------------------------------------------
* Name: isl_AllocateMemory
*
* Description:
* This function will allocate memory from a memory context
*
* Parameters:
* Context (input)
* size (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
void *isl_AllocateMemory(ISL_MEMORY_CONTEXT *Context, ISL_SIZE size)
{
ISL_MEMORY_METHODS *MemoryMethods;
void *AllocRef;
struct isl_memory_buffer *item;
if (Context == NULL) return NULL;
MemoryMethods = Context->MemoryMethods;
AllocRef = Context->AllocRef;
item = MemoryMethods->malloc_func(
sizeof(struct isl_memory_buffer),
AllocRef);
if (item == NULL)
{
ISL_SetError(CSSM_MEMORY_ERROR);
return 0;
}
item->Buffer = MemoryMethods->malloc_func((uint32)size, AllocRef);
if (item->Buffer == NULL) {
MemoryMethods->free_func(item, AllocRef);
ISL_SetError(CSSM_MEMORY_ERROR);
return 0;
}
item->Next = Context->Buffers;
Context->Buffers = item;
cssm_memset(item->Buffer, 0, (uint32)size);
return item->Buffer;
}
/*-----------------------------------------------------------------------------
* Name: isl_FreeMemory
*
* Description:
* Frees memory associated with a memory context
*
* Parameters:
* Context (input)
* Buffer (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
void isl_FreeMemory(ISL_MEMORY_CONTEXT *Context, const void *Buffer)
{
ISL_MEMORY_METHODS *MemoryMethods;
void * AllocRef;
ISL_MEMORY_BUFFER_PTR Curr = NULL;
ISL_MEMORY_BUFFER_PTR Prev = NULL;
if (Context == NULL ||
Buffer == NULL) return;
MemoryMethods = Context->MemoryMethods;
AllocRef = Context->AllocRef;
for(Curr = Context->Buffers; /* looping through all buffers */
Curr; /* exit condition */
Curr = Curr->Next) /* getting next buffer */
{
if (Buffer == Curr->Buffer) /* match pointers */
{
if (!Prev) /* testing for head of list */
Context->Buffers = Curr->Next; /* head of list is next buffer */
else
Prev->Next = Curr->Next; /* pointer previous bufffer to next buffer */
MemoryMethods->free_func((void*) Buffer, AllocRef); /* free buffer */
MemoryMethods->free_func((void*) Curr, AllocRef); /* free book keeping */
return;
}
Prev = Curr; /* save current pointer */
}
return;
}
/*-----------------------------------------------------------------------------
* Name: isl_RecycleMemoryContext
*
* Description:
* This function will free ALL memory associated with the memory context
*
* Parameters:
* Context (input)
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
ISL_STATUS
isl_RecycleMemoryContext(ISL_MEMORY_CONTEXT *Context)
{
ISL_MEMORY_BUFFER_PTR item;
ISL_MEMORY_BUFFER_PTR temp;
if (Context == NULL ||
Context->MemoryMethods == NULL)
return ISL_FAIL;
item = Context->Buffers;
while(item)
{
Context->MemoryMethods->free_func(
item->Buffer,
Context->AllocRef);
temp = item; /* temp pointer to node */
item = item->Next; /* get next node pointer */
Context->MemoryMethods->free_func(
temp,
Context->AllocRef);
}
return ISL_OK;
}
/* class methods */
/*-----------------------------------------------------------------------------
* Name: SizeofObject
*
* Description:
*
* Parameters:
*
* Return value:
*
* Error Codes:
*---------------------------------------------------------------------------*/
static ISL_SIZE ArchiveSizeofObject() /* returns sizeof object */
{
return sizeof(ISL_ARCHIVE_CONTEXT);
}
/* object methods */
#pragma warning (disable : 4102)
/*-----------------------------------------------------------------------------
* Class: Archive
* Name: AddOldSignature
*
* Description:
* This will attempt to instantiate a signature object from its external
* representation and add the signature object to the archives signature object
* list
*
* Parameters:
* Context (input/output) : this pointer
* Name (input) : archive specific name of signature object
* SignatureMethods (input) : signature specific methods
* InMemoryImage (input) : memory image of external representation
*
* Return value:
* status of operation
*
* Error Codes:
*
* Notes:
* InMemoryImage is assumed to be persistent for the life of the signature object
*---------------------------------------------------------------------------*/
static
ISL_STATUS
AddOldSignature(
ISL_ARCHIVE_CONTEXT_PTR Context,
ISL_CONST_DATA Name,
ISL_SIGNATURE_METHODS *SignatureMethods,
ISL_CONST_DATA InMemoryImage)
{
ISL_CONFIG *SigConfig;
ISL_SIGNATURE_CONTEXT *SigContext;
ISL_LIST_PTR SignatureList;
ISL_SIGNATURE_INFO_PTR SignatureInfoPtr;
if (SignatureMethods == NULL ||
SignatureMethods->ServiceMethods.Class == NULL) {
return ISL_FAIL;
}
SigConfig = (ISL_CONFIG_PTR)SignatureMethods->ServiceMethods.Class->ClassContext;
if (SigConfig == NULL) {
return ISL_FAIL;
}
SigContext= isl_AllocateMemory(
Context->Memory,
SignatureMethods->SizeofObject());
if (SigContext == NULL) {
return ISL_FAIL;
}
if (ISL_OK != SignatureMethods->InitializeFromImage(
SigContext,
SigConfig,
Context->Memory,
Name,
InMemoryImage))
{
return ISL_FAIL;
}
/* parse SignedObjectList */
SignatureList = isl_AllocateMemory(Context->Memory, sizeof(ISL_LIST));
if (SignatureList == NULL) {
return ISL_FAIL;
}
SignatureInfoPtr = isl_AllocateMemory(
Context->Memory,
sizeof(ISL_SIGNATURE_INFO));
if (SignatureInfoPtr == NULL) {
return ISL_FAIL;
}
SignatureList->Node = SignatureInfoPtr;
// SignatureInfoPtr->Parent = Context;
SignatureInfoPtr->SignaturePtr = SigContext;
SignatureInfoPtr->SignedListPtr = isl_AllocateMemory(
Context->Memory,
SignedListMethods.SizeofObject());
if (SignatureInfoPtr->SignedListPtr == NULL)
{
return ISL_FAIL;
}
if (ISL_OK != isl_InitializeSignedListFromImage(
SignatureInfoPtr->SignedListPtr,
Context,
Name,
SigContext->SignedImage))
{
return ISL_FAIL;
}
SignatureList->Next = Context->Signatures;
SignatureInfoPtr->Name.Length = Name.Length;
SignatureInfoPtr->Name.Data = isl_CopyMemory(
Context->Memory,
Name.Data,
Name.Length);
if (SignatureInfoPtr->Name.Data == NULL){
return ISL_FAIL;
}
Context->Signatures = SignatureList;
return ISL_OK;
}
/*-----------------------------------------------------------------------------
* Class: Archive
* Name: AddOldCertificate
*
* Description:
* Constructor for existing in-memory archive
*
* Parameters:
* Context (input/output) : this pointer
* configContext (input) : algorithm<->code extension
* InMemoryImage (input) : memory image of external representation
*
* Return value:
* status of operation
*
* Error Codes:
*
* Notes:
* InMemoryImage is assumed to be persistent for the life of the archive object
*---------------------------------------------------------------------------*/
static
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?