asn1.h File Reference

ASN.1 (Abstract Syntax Notation One) More...

#include "core/crypto.h"
#include "mpi/mpi.h"

Go to the source code of this file.

Data Structures

struct  Asn1Tag
 ASN.1 tag. More...
 

Macros

#define ASN1_TAG_NUMBER_MASK   0x1F
 
#define ASN1_ENCODING_MASK   0x20
 
#define ASN1_ENCODING_PRIMITIVE   0x00
 
#define ASN1_ENCODING_CONSTRUCTED   0x20
 
#define ASN1_CLASS_MASK   0xC0
 
#define ASN1_CLASS_UNIVERSAL   0x00
 
#define ASN1_CLASS_APPLICATION   0x40
 
#define ASN1_CLASS_CONTEXT_SPECIFIC   0x80
 
#define ASN1_CLASS_PRIVATE   0xC0
 

Enumerations

enum  Asn1Type {
  ASN1_TYPE_BOOLEAN = 1, ASN1_TYPE_INTEGER = 2, ASN1_TYPE_BIT_STRING = 3, ASN1_TYPE_OCTET_STRING = 4,
  ASN1_TYPE_NULL = 5, ASN1_TYPE_OBJECT_IDENTIFIER = 6, ASN1_TYPE_OBJECT_DESCRIPTOR = 7, ASN1_TYPE_EXTERNAL = 8,
  ASN1_TYPE_REAL = 9, ASN1_TYPE_ENUMERATED = 10, ASN1_TYPE_UTF8_STRING = 12, ASN1_TYPE_SEQUENCE = 16,
  ASN1_TYPE_SET = 17, ASN1_TYPE_NUMERIC_STRING = 18, ASN1_TYPE_PRINTABLE_STRING = 19, ASN1_TYPE_TELETEX_STRING = 20,
  ASN1_TYPE_VIDEOTEX_STRING = 21, ASN1_TYPE_IA5_STRING = 22, ASN1_TYPE_UTC_TIME = 23, ASN1_TYPE_GENERALIZED_TIME = 24,
  ASN1_TYPE_GRAPHIC_STRING = 25, ASN1_TYPE_VISIBLE_STRING = 26, ASN1_TYPE_GENERAL_STRING = 27, ASN1_TYPE_UNIVERSAL_STRING = 28,
  ASN1_TYPE_BMP_STRING = 30
}
 ASN.1 data types. More...
 

Functions

error_t asn1ReadTag (const uint8_t *data, size_t length, Asn1Tag *tag)
 Read an ASN.1 tag from the input stream. More...
 
error_t asn1ReadSequence (const uint8_t *data, size_t length, Asn1Tag *tag)
 Read an ASN.1 sequence from the input stream. More...
 
error_t asn1ReadOctetString (const uint8_t *data, size_t length, Asn1Tag *tag)
 Read an octet string from the input stream. More...
 
error_t asn1ReadOid (const uint8_t *data, size_t length, Asn1Tag *tag)
 Read an object identifier from the input stream. More...
 
error_t asn1ReadBoolean (const uint8_t *data, size_t length, Asn1Tag *tag, bool_t *value)
 Read a boolean from the input stream. More...
 
error_t asn1ReadInt32 (const uint8_t *data, size_t length, Asn1Tag *tag, int32_t *value)
 Read a 32-bit integer from the input stream. More...
 
error_t asn1WriteTag (Asn1Tag *tag, bool_t reverse, uint8_t *data, size_t *written)
 Write an ASN.1 tag. More...
 
error_t asn1WriteInt32 (int32_t value, bool_t reverse, uint8_t *data, size_t *written)
 Write a 32-bit integer to the output stream. More...
 
error_t asn1ReadMpi (const uint8_t *data, size_t length, Asn1Tag *tag, Mpi *value)
 Read a multiple-precision integer from the input stream. More...
 
error_t asn1WriteMpi (const Mpi *value, bool_t reverse, uint8_t *data, size_t *written)
 Write a multiple-precision integer from the output stream. More...
 
error_t asn1CheckTag (const Asn1Tag *tag, bool_t constructed, uint_t objClass, uint_t objType)
 Enforce the type of a specified tag. More...
 
error_t asn1CheckOid (const Asn1Tag *tag, const uint8_t *oid, size_t length)
 Check ASN.1 tag against a specified OID. More...
 
error_t asn1DumpObject (const uint8_t *data, size_t length, uint_t level)
 Display an ASN.1 data object. More...
 

Detailed Description

ASN.1 (Abstract Syntax Notation One)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file asn1.h.

Macro Definition Documentation

◆ ASN1_CLASS_APPLICATION

#define ASN1_CLASS_APPLICATION   0x40

Definition at line 53 of file asn1.h.

◆ ASN1_CLASS_CONTEXT_SPECIFIC

#define ASN1_CLASS_CONTEXT_SPECIFIC   0x80

Definition at line 54 of file asn1.h.

◆ ASN1_CLASS_MASK

#define ASN1_CLASS_MASK   0xC0

Definition at line 51 of file asn1.h.

◆ ASN1_CLASS_PRIVATE

#define ASN1_CLASS_PRIVATE   0xC0

Definition at line 55 of file asn1.h.

◆ ASN1_CLASS_UNIVERSAL

#define ASN1_CLASS_UNIVERSAL   0x00

Definition at line 52 of file asn1.h.

◆ ASN1_ENCODING_CONSTRUCTED

#define ASN1_ENCODING_CONSTRUCTED   0x20

Definition at line 48 of file asn1.h.

◆ ASN1_ENCODING_MASK

#define ASN1_ENCODING_MASK   0x20

Definition at line 46 of file asn1.h.

◆ ASN1_ENCODING_PRIMITIVE

#define ASN1_ENCODING_PRIMITIVE   0x00

Definition at line 47 of file asn1.h.

◆ ASN1_TAG_NUMBER_MASK

#define ASN1_TAG_NUMBER_MASK   0x1F

Definition at line 43 of file asn1.h.

Enumeration Type Documentation

◆ Asn1Type

enum Asn1Type

ASN.1 data types.

Enumerator
ASN1_TYPE_BOOLEAN 
ASN1_TYPE_INTEGER 
ASN1_TYPE_BIT_STRING 
ASN1_TYPE_OCTET_STRING 
ASN1_TYPE_NULL 
ASN1_TYPE_OBJECT_IDENTIFIER 
ASN1_TYPE_OBJECT_DESCRIPTOR 
ASN1_TYPE_EXTERNAL 
ASN1_TYPE_REAL 
ASN1_TYPE_ENUMERATED 
ASN1_TYPE_UTF8_STRING 
ASN1_TYPE_SEQUENCE 
ASN1_TYPE_SET 
ASN1_TYPE_NUMERIC_STRING 
ASN1_TYPE_PRINTABLE_STRING 
ASN1_TYPE_TELETEX_STRING 
ASN1_TYPE_VIDEOTEX_STRING 
ASN1_TYPE_IA5_STRING 
ASN1_TYPE_UTC_TIME 
ASN1_TYPE_GENERALIZED_TIME 
ASN1_TYPE_GRAPHIC_STRING 
ASN1_TYPE_VISIBLE_STRING 
ASN1_TYPE_GENERAL_STRING 
ASN1_TYPE_UNIVERSAL_STRING 
ASN1_TYPE_BMP_STRING 

Definition at line 67 of file asn1.h.

Function Documentation

◆ asn1CheckOid()

error_t asn1CheckOid ( const Asn1Tag tag,
const uint8_t *  oid,
size_t  length 
)

Check ASN.1 tag against a specified OID.

Parameters
[in]tagPointer to an ASN.1 tag
[in]oidExpected object identifier (OID)
[in]lengthLength of the OID
Returns
Error code

Definition at line 679 of file asn1.c.

◆ asn1CheckTag()

error_t asn1CheckTag ( const Asn1Tag tag,
bool_t  constructed,
uint_t  objClass,
uint_t  objType 
)

Enforce the type of a specified tag.

Parameters
[in]tagPointer to an ASN.1 tag
[in]constructedExpected encoding (TRUE for constructed, FALSE for primitive)
[in]objClassExpected tag class
[in]objTypeExpected tag type
Returns
Error code

Definition at line 653 of file asn1.c.

◆ asn1DumpObject()

error_t asn1DumpObject ( const uint8_t *  data,
size_t  length,
uint_t  level 
)

Display an ASN.1 data object.

Parameters
[in]dataPointer to the ASN.1 object to dump
[in]lengthLength of the ASN.1 object
[in]levelCurrent level of recursion (this parameter shall be set to 0)
Returns
Error code

Definition at line 706 of file asn1.c.

◆ asn1ReadBoolean()

error_t asn1ReadBoolean ( const uint8_t *  data,
size_t  length,
Asn1Tag tag,
bool_t value 
)

Read a boolean from the input stream.

Parameters
[in]dataInput stream where to read the tag
[in]lengthNumber of bytes available in the input stream
[out]tagStructure describing the ASN.1 tag
[out]valueBoolean value
Returns
Error code

Definition at line 247 of file asn1.c.

◆ asn1ReadInt32()

error_t asn1ReadInt32 ( const uint8_t *  data,
size_t  length,
Asn1Tag tag,
int32_t *  value 
)

Read a 32-bit integer from the input stream.

Parameters
[in]dataInput stream where to read the tag
[in]lengthNumber of bytes available in the input stream
[out]tagStructure describing the ASN.1 tag
[out]valueInteger value
Returns
Error code

Definition at line 285 of file asn1.c.

◆ asn1ReadMpi()

error_t asn1ReadMpi ( const uint8_t *  data,
size_t  length,
Asn1Tag tag,
Mpi value 
)

Read a multiple-precision integer from the input stream.

Parameters
[in]dataInput stream where to read the tag
[in]lengthNumber of bytes available in the input stream
[out]tagStructure describing the ASN.1 tag
[out]valueInteger value
Returns
Error code

Definition at line 553 of file asn1.c.

◆ asn1ReadOctetString()

error_t asn1ReadOctetString ( const uint8_t *  data,
size_t  length,
Asn1Tag tag 
)

Read an octet string from the input stream.

Parameters
[in]dataInput stream where to read the tag
[in]lengthNumber of bytes available in the input stream
[out]tagStructure describing the ASN.1 tag
Returns
Error code

Definition at line 190 of file asn1.c.

◆ asn1ReadOid()

error_t asn1ReadOid ( const uint8_t *  data,
size_t  length,
Asn1Tag tag 
)

Read an object identifier from the input stream.

Parameters
[in]dataInput stream where to read the tag
[in]lengthNumber of bytes available in the input stream
[out]tagStructure describing the ASN.1 tag
Returns
Error code

Definition at line 218 of file asn1.c.

◆ asn1ReadSequence()

error_t asn1ReadSequence ( const uint8_t *  data,
size_t  length,
Asn1Tag tag 
)

Read an ASN.1 sequence from the input stream.

Parameters
[in]dataInput stream where to read the tag
[in]lengthNumber of bytes available in the input stream
[out]tagStructure describing the ASN.1 tag
Returns
Error code

Definition at line 163 of file asn1.c.

◆ asn1ReadTag()

error_t asn1ReadTag ( const uint8_t *  data,
size_t  length,
Asn1Tag tag 
)

Read an ASN.1 tag from the input stream.

Parameters
[in]dataInput stream where to read the tag
[in]lengthNumber of bytes available in the input stream
[out]tagStructure describing the ASN.1 tag
Returns
Error code

Definition at line 52 of file asn1.c.

◆ asn1WriteInt32()

error_t asn1WriteInt32 ( int32_t  value,
bool_t  reverse,
uint8_t *  data,
size_t *  written 
)

Write a 32-bit integer to the output stream.

Parameters
[in]valueInteger value
[in]reverseUse reverse encoding
[out]dataOutput stream where to write the tag (optional parameter)
[out]writtenNumber of bytes written to the output stream
Returns
Error code

Definition at line 495 of file asn1.c.

◆ asn1WriteMpi()

error_t asn1WriteMpi ( const Mpi value,
bool_t  reverse,
uint8_t *  data,
size_t *  written 
)

Write a multiple-precision integer from the output stream.

Parameters
[in]valueInteger value
[in]reverseUse reverse encoding
[out]dataOutput stream where to write the tag (optional parameter)
[out]writtenNumber of bytes written to the output stream
Returns
Error code

Definition at line 591 of file asn1.c.

◆ asn1WriteTag()

error_t asn1WriteTag ( Asn1Tag tag,
bool_t  reverse,
uint8_t *  data,
size_t *  written 
)

Write an ASN.1 tag.

Parameters
[in]tagStructure describing the ASN.1 tag
[in]reverseUse reverse encoding
[out]dataOutput stream where to write the tag (optional parameter)
[out]writtenNumber of bytes written to the output stream (optional parameter)
Returns
Error code

Definition at line 334 of file asn1.c.