⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cryptlib.asn

📁 老外写的加密库cryptlib(版本3.1)
💻 ASN
📖 第 1 页 / 共 2 页
字号:
-/ This specification makes one slight deviation from standard ASN.1 syntax
   to overcome an annoyance in ASN.1 which requires a separate -- at the
   start of each and every line of comment.  Instead, this specification uses
   -//- comment delimiters (which work like C's /**/) in place of standard
   ASN.1 delimiters /-

cryptlib DEFINITIONS ::=
BEGIN

------------------------------------------------------------------------------
--																			--
--								PKCS #7 Data Formats						--
--																			--
------------------------------------------------------------------------------

-/ There are several variants of the PKCS #7/S/MIME/CMS format which gradually
   get more flexible (but not necessarily better) over time.  The initial
   format was PKCS #7 1.5 and earlier, 1.6 was a quick update which changed a
   number of SETs to SEQUENCEs (which don't require sorting of the encoded
   components), this doesn't appear to have been used by anything.  S/MIME 3/
   CMS was an extended form of S/MIME 2 which fiddled with some of the inner
   fields but was mostly the same as PKCS #7 1.5.  1.5 is a significant
   improvement on most of its successors /-

ContentInfo ::= SEQUENCE {
	contentType			OBJECT IDENTIFIER,
	content			[0]	EXPLICIT ANY DEFINED BY contentType OPTIONAL
	}

-/ Raw data /-

Data ::= OCTET STRING						-- PKCS #7 1

-/ Authenticated data: Digested, signed, MAC'd data /-

DigestedData ::= SEQUENCE {					-- PKCS #7 5
	version				INTEGER (0),		-- PKCS #7 v1.5
	digestAlgorithm		AlgorithmIdentifier,-- v=2 for non id-Data
	encapContentInfo	SEQUENCE {
		contentType		OBJECT IDENTIFIER id-Data/Sig/Encr/Env,
		content		[0]	EXPLICIT OCTET STRING
		},
	digest				OCTET STRING
	}

SignedData ::= SEQUENCE {					-- PKCS #7 2
	version				INTEGER (1),		-- PKCS #7 v1.5
	digestAlgorithms	SET OF AlgorithmIdentifier,
	encapContentInfo	SEQUENCE {
		contentType		OBJECT IDENTIFIER id-Data/Sig/Encr/Env,
		content		[0]	EXPLICIT OCTET STRING
		}
	certificates	[0]	SET OF Certificate,
	signerInfos			SET OF SignerInfo
	}

AuthenticatedData ::= SEQUENCE {			-- PKCS #9 16 1 2
	version				INTEGER (0),		-- S/MIME v3
	recipientInfos		SET OF RecipientInfo,
	macAlgorithm		AlgorithmIdentifier,
	encapContentInfo	SEQUENCE {
		contentType		OBJECT IDENTIFIER id-Data/Sig/Encr/Env,
		content		[0]	EXPLICIT OCTET STRING
		}
	mac					OCTET STRING
	}

-/ Encrypted data: Raw encrypted, enveloped /-

EncryptedData ::= SEQUENCE {				-- PKCS #7 6
	version				INTEGER (0),		-- PKCS #7 v1.5
	encrContentInfo		SEQUENCE {
		contentType		OBJECT IDENTIFIER id-Data/Sig/Encr/Env,
		contentEncrAlgo	AlgorithmIdentifier,
		content		[0]	OCTET STRING
		}
	}

EnvelopedData ::= SEQUENCE {				-- PKCS #7 3
	version				INTEGER (0),		-- PKCS #7 v1.5, v=2 for origInfo
	originatorInfo	[0]	SEQUENCE { [0] SET OF Certificate } OPTIONAL,
	recipientInfos		SET OF RecipientInfo,
	encrContentInfo		SEQUENCE {
		contentType		OBJECT IDENTIFIER id-Data/Sig/Encr/Env,
		contentEncrAlgo	AlgorithmIdentifier,
		content		[0]	OCTET STRING
		},
	unprotectedAttrs
					[1]	UnprotectedAttributes OPTIONAL
	}

------------------------------------------------------------------------------
--																			--
--								Key Management								--
--																			--
------------------------------------------------------------------------------

-/ The parameters used to derive the conventional encryption key from the
   user key.  Usually we use the key directly, but sometimes it may have
   been derived from a longer user key, which is encoded in this record /-

PBKDF2 ::= SEQUENCE {						-- PKCS #5v2 key setup parameters
	algorithm		AlgorithmIdentifier (pkcs-5 12),
	params			SEQUENCE {
		salt		OCTET STRING,			-- Key setup salt
		iterationCount						-- Key setup iterations
					INTEGER (1..MAX),
		}
	}

-/ CMS key transport information /-

KeyTransRecipientInfo ::= SEQUENCE {		-- CMS - S/MIME
	version			INTEGER (0),			-- CMS
	issuerAndSerial	IssuerAndSerialNumber,	-- Encrypting certificate
	algorithm		AlgorithmIdentifier,	-- Encryption algorithm
	encryptedKey	OCTET STRING			-- Encryped key
	}
KeyTransRecipientInfo ::= SEQUENCE {		-- CMS - cryptlib
	version			INTEGER (2),			-- CMS
	keyID		[0]	SubjectKeyIdentifier,	-- Key ID of encrypting key
	algorithm		AlgorithmIdentifier,	-- Encryption algorithm
	encryptedKey	OCTET STRING			-- Encrypted key
	}

-/ CMS key agreement information, which is officially called
   KeyAgreeRecipientInfo but in order for it to make sense it really needs
   to be named FortezzaRecipientInfo /-

FortezzaRecipientInfo ::= SEQUENCE {		-- CMS - S/MIME
	version			INTEGER (3),			-- CMS
	originator	[0]	EXPLICIT [ 0 ] SubjectKeyIdentifier,-- Originator pub.key
	ukm			[1]	EXPLICIT OCTET STRING,	-- Nonce, Ra
	algorithm		AlgorithmIdentifier,	-- Fortezza key wrap OID
	recipientKeys	SEQUENCE OF SEQUENCE {
		rKeyId	[0]	SEQUENCE { SubjectKeyIdentifier }, -- Recip.pubk
		encryptedKey OCTET STRING			-- Encr.key info, TEK( MEK )
		}
	}

-/ CMS conventional key transport information.  This structure is somewhat
   misnamed since it's really just a kludge to work with pre-distributed
   shared RC2 or 3DES keys for S/MIME-based mailing lists and not a general-
   purpose KEK object, however by using the PWRI AlgorithmIdentifier for
   KEKRI we can turn it into a general-purpose key transport mechanism /-

KEKRecipientInfo ::= SEQUENCE {
	version			INTEGER (4),			-- CMS
	kekid			SEQUENCE {
		keyIdent	OCTET STRING			-- Magic ID for KEK
		},
	keyEncAlgo		AlgorithmIdentifier,	-- Key wrap algorithm
	encryptedKey	OCTET STRING			-- Encrypted key
	}

-/ CMS password-based key transport information.  This is also misnamed since
   it's actually general-purpose and does what KEKRecipientInfo should do /-

PasswordRecipientInfo ::= SEQUENCE {
	version			INTEGER (0),			-- CMS
	keyDerivationAlgorithm					-- KEK derivation algorithm,
				[0]	AlgorithmIdentifier OPTIONAL,	-- PBKDF2 if present
	keyEncryptionAlgorithm					-- KEK algorithm
					AlgorithmIdentifier,	-- PWRI-KEK
	encryptedKey	OCTET STRING
	}

-/ CMS key management /-

RecipientInfo ::= CHOICE {
	ktri			KeyTransRecipientInfo,	-- Public-key encrypted key
	kari		[1] FortezzaRecipientInfo,	-- Fortezza key-agreement info
	kekri		[2] KEKRecipientInfo,		-- Conventionally encrypted key
	pwri		[3]	PasswordRecipientInfo	-- Password-encrypted key
	}

------------------------------------------------------------------------------
--																			--
--									Signatures								--
--																			--
------------------------------------------------------------------------------

-/ CMS signature information /-

SignerInfo ::= SEQUENCE {					-- CMS - S/MIME
	version			INTEGER (1),			-- CMS
	issuerAndSerial	IssuerAndSerialNumber,	-- Signing certificate
	hashAlgorithm	AlgorithmIdentifier,	-- Hash algorithm type
	signedAttributes						-- Authenticated attributes
				[0]	SET OF Attribute OPTIONAL,
	signatureAlgorithm						-- Signature algorithm type
					AlgorithmIdentifier,
	signature		OCTET STRING			-- The signature itself
	unsignedAttrs							-- Countersignature
				[1]	SET OF Attribute OPTIONAL
	}
SignerInfo ::= SEQUENCE {					-- CMS - cryptlib
	version			INTEGER (3),			-- CMS
	keyID		[0]	SubjectKeyIdentifier,	-- Key ID of signing key
	hashAlgorithm	AlgorithmIdentifier,	-- Hash algorithm type
	signatureAlgorithm						-- Signature algorithm type
					AlgorithmIdentifier,
	signature		OCTET STRING			-- The signature itself
	}

------------------------------------------------------------------------------
--																			--
--								Public/Private Keys							--
--																			--
------------------------------------------------------------------------------

-/ PKCS #15 uses a very object-oriented design which follows PKCS #11 and
   uses a lot of the expressive power of ASN.1 in the specification of its
   PDUs.  The basic PKCS #15 object is defined as follows:

	PKCS15Object( ClassAttributes, SubclassAttributes, TypeAttributes ) ->
		SEQUENCE {
			commonAttr		CommonObjectAttributes,
			classAttr		ClassAttributes,
			subclassAttr[0]	SubclassAttributes OPTIONAL,
			typeAttr	[1]	TypeAttributes
			}

   with the attributes being filled in on a per-object basis.  Every object
   contains common object attributes, and every key or certificate object
   contains common key or cert class attributes.  In addition the public and
   private key subclasses contain subclass-specific attributes, but they
   don't contain anything which isn't present elsewhere so they're omitted:

					Key									Cert
	SEQUENCE {
		SEQUENCE {											-- CommonObjectAttr
			label		UTF8String,
			...
			},
		SEQUENCE {							SEQUENCE {		-- ClassAttr
			iD			OCTET STRING,			iD			OCTET STRING,
			usage		BIT STRING,				authority	BOOLEAN DEF FALSE,
			accessFlags	BIT STRING OPTIONAL,	trusted	[1] SEQUENCE { usage BIT STR },
			...									keyID	[2] SEQUENCE OF KeyID,
			},									impTrust[3]	BOOLEAN DEFAULT FALSE,
												...
												},
		[0] EXPLICIT SEQUENCE {} OPTIONAL,					-- SubclassAttr
		[1] EXPLICIT SEQUENCE {								-- TypeAttr
			<data>
			}
		}
				cryptlib config/user data
	SEQUENCE {
		SEQUENCE {											-- CommonObjectAttr
			label		UTF8String,
			...
			},
		SEQUENCE {							SEQUENCE {		-- ClassAttr
			...									appOID		OBJECT IDENTIFIER (cryptlib),
			},									...
												},
		[1] EXPLICIT SEQUENCE {
			<data>
			}
		} /-

PKCS15CommonObjectAttributes ::= SEQUENCE {
	label			UTF8String OPTIONAL,	-- Object label
	...
	}

-/ Class attributes /-

PKCS15CommonKeyAttributes ::= SEQUENCE {
	iD				OCTET STRING,			-- Cross-reference to cert
	usage			BIT STRING,				-- PKCS #11 usage flags
	accessFlags		BIT STRING b'01101' OPT,-- PKCS #11 access flags
	validFrom		GeneralisedTime OPTIONAL,
	validTo		[0]	GeneralisedTime OPTIONAL,
	...
	}

PKCS15CommonCertificateAttributes ::= SEQUENCE {
	iD				OCTET STRING,			-- Cross-reference to key
	authority		BOOLEAN DEFAULT FALSE,	-- CA flag
	dummy			SEQUENCE {} OPTIONAL,	-- Not used
	dummy		[0]	SEQUENCE {} OPTIONAL,	-- Not used
	trusted		[1]	SEQUENCE {
		keyUsage	BIT STRING,				-- Key usage cert is trusted for
		...
		} OPTIONAL,
	keyID		[2]	SEQUENCE OF KeyID OPTIONAL,
	impTrust	[3]	BOOLEAN OPTIONAL,
	validFrom		GeneralisedTime OPTIONAL,
	validTo		[4] GeneralisedTime OPTIONAL,
	...
	}

PKCS15CommonSecretKeyAttributes ::= SEQUENCE {
	...
	}

PKCS15CommonDataObjectAttributes ::= SEQUENCE {
	applicationName	UTF8String OPTIONAL,	-- One or both must be present
	applicationOID	OBJECT IDENTIFIER OPTIONAL,
	iD				OCTET STRING OPTIONAL,
	...
	}

-/ Key identifiers /-

PKCS15KeyIdentifier ::= TYPED CHOICE {
	iAndS			SEQUENCE {				-- Not written, conv.to iAndSHash on rd
		id			INTEGER (1),
		value		IssuerAndSerialNumber
		},
	subjectKeyID	SEQUENCE {				-- Only used if different from iD
		id			INTEGER (2),
		value		OCTET STRING
		},
	iAndSHash		SEQUENCE {				-- Written and read
		id			INTEGER (3),
		value		OCTET STRING SIZE(20)
		},
	iHash			SEQUENCE {				-- Written and read
		id			INTEGER (6),
		value		OCTET STRING SIZE(20)
		},
	sHash			SEQUENCE {				-- Written and read
		id			INTEGER (7),
		value		OCTET STRING SIZE(20)
		},
	pgp				SEQUENCE {				-- Written and read
		id			INTEGER (8),
		value		OCTET STRING SIZE(8)
		},
	openPGP			SEQUENCE {				-- Written and read
		id			INTEGER (9),
		value		OCTET STRING SIZE(8)
		},
	...
	}

-/ Private key information (DLP = DSA/DH/KEA/etc) /-

PKCS15PrivateRSAKeyAttributes ::= SEQUENCE {
	value			[2]	EnvelopedData {
						SEQUENCE {
		modulus		[0]	INTEGER OPTIONAL,	-- n, not written
		publicExp	[1]	INTEGER OPTIONAL,	-- e, not written
		privateExp	[2]	INTEGER OPTIONAL,	-- d, not written
		prime1		[3]	INTEGER OPTIONAL,	-- p
		prime2		[4]	INTEGER OPTIONAL,	-- q
		exponent1	[5]	INTEGER OPTIONAL,	-- d mod p-1
		exponent2	[6]	INTEGER OPTIONAL,	-- d mod q-1
		coefficient	[7]	INTEGER OPTIONAL	-- q^-1 mod p
						}
		},
	modulusLength		INTEGER,
	...
	}

PKCS15PrivateDLPKeyAttributes ::= SEQUENCE {
	value			[2] EnvelopedData {
						INTEGER				-- DSA x value
						},
	...
	}

PKCS15PrivateKey ::= CHOICE {
	privateRSAKey		PKCS15Object{ PKCS15CommonKeyAttributes,
									  PKCS15CommonPrivateKeyAttributes,
									  PKCS15PrivateRSAKeyAttributes },
	privateDSAKey	[2]	PKCS15Object{ PKCS15CommonKeyAttributes,
									  PKCS15CommonPrivateKeyAttributes,
									  PKCS15PrivateDSAKeyAttributes }
	}

-/ Public key information (DLP = DSA/DH/KEA/etc) /-

PKCS15PublicRSAKeyAttributes ::= SEQUENCE {
	value			[0]	EXPLICIT {
					[1]	SubjectPublicKeyInfo
						},
	modulusLength		INTEGER,
	...
	}

PKCS15PublicDLPKeyAttributes ::= SEQUENCE {
	value			[0]	EXPLICIT SubjectPublicKeyInfo,
	...
	}

PKCS15PublicKey ::= CHOICE {
	publicRSAKey		PKCS15Object{ PKCS15CommonKeyAttributes,
									  PKCS15CommonPublicKeyAttributes,
									  PKCS15PublicRSAKeyAttributes },
	publicDSAKey	[2]	PKCS15Object{ PKCS15CommonKeyAttributes,
									  PKCS15CommonPublicKeyAttributes,
									  PKCS15PublicDSAKeyAttributes }
	}

-/ Certificate information /-

PKCS15X509CertificateAttributes ::= SEQUENCE {
	value			[0]	Certificate,
	...
	}

PKCS15Certificate ::= CHOICE {
	x509Certificate		PKCS15Object{ PKCS15CommonCertificateAttributes,
									  NULL,
									  PKCS15X509CertificateAttributes }
	}

-/ Secret key information /-

PKCS15GenericSecretKeyAttributes ::= {
	value			[2] EnvelopedData {
						OCTET STRING		-- Raw secret key
						}
	}

PKCS15SecretKey ::= CHOICE {
	des3Key			[4] PKCS15Object{ PKCS15CommonKeyAttributes,
									  PKCS15CommonSecretKeyAttributes,
									  PKCS15GenericSecretKeyAttributes },
	}

-/ Data information /-

ConfigOption ::= SEQUENCE {
	type				INTEGER,			-- CRYPT_PROPERTY_xxx
	value				ANY DEFINED BY type	-- BOOLEAN, INTEGER, UTF8String
	}

ConfigOptions ::= SEQUENCE OF ConfigOption

UserIndexEntry ::= SEQUENCE {
	iD					OCTET STRING SIZE(16),	-- User ID
	creatorID			OCTET STRING SIZE(16),	-- Creating SO's ID
	name				UTF8String,				-- User name
	fileReference		INTEGER					-- Reference to user file
	}

UserIndex ::= SEQUENCE OF UserIndexEntry

UserInfo ::= SEQUENCE {
	role				ENUMERATED,				-- SO/user/CA
	iD					OCTET STRING SIZE(16),	-- User ID
	creatorID			OCTET STRING SIZE(16),	-- Creating SO's ID
	name				UTF8String,				-- User name
	}

// Other user data, has to be stored elsewhere
//	state				ENUMERATED,				-- SO inited/user inited/locked
//	encSecKey			EncryptedData OPTIONAL	-- (Used for CAs)

PKCS15OidDO ::= SEQUENCE {

⌨️ 快捷键说明

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