ber_der.h

来自「Next BIOS Source code : Extensible Firmw」· C头文件 代码 · 共 403 行 · 第 1/2 页

H
403
字号
/* SCCSID: inc/ber_der.h, dss_cdsa_fwk, fwk_rel2, dss_971010 1.5 10/23/97 17:53:30 */
/*-----------------------------------------------------------------------
 *      File:   ber_der.h
 *
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.

 *-----------------------------------------------------------------------
 */
/* 
 * 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).
 */ 
/*
 * This is the header file for some Basic Encoding Rules and Distinguished
 * Encoding Rules (BER/DER) routines.
 */
/*
 * (C) COPYRIGHT International Business Machines Corp. 1996, 1997
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
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.

 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 */

#ifndef BER_DER_H
#define BER_DER_H

#if defined (WIN32)
#pragma warning (disable:4201 4514 4214 4115)
#include <windows.h>
#pragma warning (default:4201 4214 4115)
#endif


#ifdef EFI64
/* Basic Types */
typedef unsigned __int8  uint8;
typedef unsigned __int16 uint16;
typedef          __int16 sint16;
typedef unsigned __int32 uint32;
typedef          __int32 sint32;

#else
/* Basic Types */
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef short sint16;
typedef unsigned int uint32;
typedef int sint32;
#endif

#ifndef CSSMAPI
	#if defined (WIN32)
		#define CSSMAPI __stdcall
	
	#elif defined (WIN31)
		#ifndef PASCAL
			#define PASCAL __stdcall
		#endif
		#define CSSMAPI PASCAL
	
	#elif defined (UNIX) 
		#define CSSMAPI

	#elif defined (OASIS) 
		#define CSSMAPI
	#endif
#endif

#ifndef CALLBACK
	#if defined (UNIX)
		#define CALLBACK
	#endif
#endif

typedef void *	BER_HANDLE;
typedef struct ber_memory_funcs {
    void *(CSSMAPI *malloc_func) (BER_HANDLE AddInHandle, uint32 Size);
    void (CSSMAPI *free_func) (BER_HANDLE AddInHandle, void *MemPtr);
    void *(CSSMAPI *realloc_func) (BER_HANDLE AddInHandle, void *MemPtr, uint32 Size);
    void *(CSSMAPI *calloc_func) (BER_HANDLE AddInHandle, uint32 Num, uint32 Size);
} BER_MEMORY_FUNCS, *BER_MEMORY_FUNCS_PTR;


#define BER_BOOLEAN					1 
#define BER_INTEGER                 2
#define BER_BIT_STRING              3
#define BER_OCTET_STRING            4
#define BER_NULL                    5
#define BER_OBJECT_IDENTIFIER       6
#define BER_SEQUENCE                16
#define BER_SET                     17
#define BER_PRINTABLE_STRING        19
#define BER_T61STRING               20
#define BER_IA5STRING               22
#define BER_UTCTIME                 23
#define BER_GENTIME                 24

#define BER_CLASS_MASK              0xc0
#define BER_CLASS_UNIVERSAL         0x00
#define BER_CLASS_APPLICATION       0x40
#define BER_CLASS_CONTEXTSPECIFIC   0x80
#define BER_CLASS_PRIVATE           0xc0

#define BER_CONSTRUCTED             0x20

#define BER_CONSTRUCTED_SEQUENCE    (BER_CONSTRUCTED | BER_SEQUENCE)
#define BER_CONSTRUCTED_SET         (BER_CONSTRUCTED | BER_SET)

#define BER_UNIVERSAL_TAG_LENGTH    1

#define ALL_TAG_VALUES_MASK      0x1F
#define IS_LONG_TAG(a)           ((a & 0x1F) == 0x1F) ? 1 : 0
#define IS_LAST_LONG_TAG_BYTE(a) ((a & 0x80) == 0x00) ? 1 : 0

#define LONG_LEN_INDICATOR    0x80
#define LONG_LEN_REQD         LONG_LEN_INDICATOR
#define IS_SHORT_FORM_LEN(a)  ((a & LONG_LEN_INDICATOR) == 0) ? 1 : 0
#define NUM_LENGTH_BYTES(a)   (a & ~LONG_LEN_INDICATOR)

#define INDEF_END_OF_CONTENTS_NUM_BYTES 2
#define INDEF_END_OF_CONTENTS_MARKER    0x00


/* the following structure is the same as CSSM SPI, but we don't depend on cssm */
typedef struct ber_parsed_item {
    const uint8  *Tag;
          uint32 ContentLength;
    const uint8  *Content;
} BER_PARSED_ITEM, *BER_PARSED_ITEM_PTR;

/* compare two tags per DER rules */
sint32 
BER_TagCompare(const uint8 *A, const uint8 *B);

/* get length of BER length field */
uint32 
BER_LengthOfLength(uint32 Length);

/* get length of BER tag */
uint32 
BER_LengthOfTag(const uint8 *Tag);

/* copy a BER tag to the output and return its length */
uint32 
BER_OutputTag(            /* return length of copied tag */
    const uint8 *Source,          /* input BER/DER tag */
          uint8 *Octets);         /* output buffer */

/* DER encode a length and return its length */
uint32 
BER_OutputLength(         /* return number of bytes it took to store the length */
    uint32 Value,           /* length as binary integer */
    uint8 *Octets);         /* output buffer */

/* given a pointer to a BER object, return its length in octets */
uint32 
BER_SizeofObject(const uint8 *Octets);

/* decode a small BER integer to a C unsigned long value */
uint32 
BER_BerToUnlong(const uint8 *Octets);

/* encode an unsigned long into a DER integer at the given memory, return length in octets */
uint32 
DER_UnlongToDer(
    uint32 Value, 
    uint8 *Octets);

/* 
 * Function to decode a primitive BER bit string into an array of bytes. 
 * The function returns -2 if the input is not a valid primitive bit string.
 * The function result is the length of the decoded bit string in *BITS*. 
 * If the target buffer (Bytes) is not sufficiently large to hold the result,
 * the function returns -1 and does not alter the output buffer. 
 * Any odd bits are in the most significant bits of the last byte.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?