AKASHI Takahiro | e2c04fa | 2019-11-13 09:44:56 +0900 | [diff] [blame] | 1 | ASN1 |
| 2 | ==== |
| 3 | |
| 4 | Abstract Syntax Notation One (or ASN1) is a standard by ITU-T and ISO/IEC |
| 5 | and used as a description language for defining data structure in |
| 6 | an independent manner. |
| 7 | Any data described in ASN1 notation can be serialized (or encoded) and |
| 8 | de-serialized (or decoded) with well-defined encoding rules. |
| 9 | |
| 10 | A combination of ASN1 compiler and ASN1 decoder library function will |
| 11 | provide a function interface for parsing encoded binary into specific |
| 12 | data structure: |
| 13 | 1) define data structure in a text file (*.asn1) |
| 14 | 2) define "action" routines for specific "tags" defined in (1) |
| 15 | 3) generate bytecode as a C file (*.asn1.[ch]) from *.asn1 file |
| 16 | with ASN1 compiler (tools/asn1_compiler) |
| 17 | 4) call a ASN1 decoder (asn1_ber_decoder()) with bytecode and data |
| 18 | |
| 19 | Usage of ASN1 compiler |
| 20 | ---------------------- |
| 21 | asn1_compiler [-v] [-d] <grammar-file> <c-file> <hdr-file> |
| 22 | |
| 23 | <grammar-file>: ASN1 input file |
| 24 | <c-file>: generated C file |
| 25 | <hdr-file>: generated include file |
| 26 | |
| 27 | Usage of ASN1 decoder |
| 28 | --------------------- |
| 29 | int asn1_ber_decoder(const struct asn1_decoder *decoder, void *context, |
| 30 | const unsigned char *data, size_t datalen); |
| 31 | |
| 32 | @decoder: bytecode binary |
| 33 | @context: context for decoder |
| 34 | @data: data to be parsed |
| 35 | @datalen: size of data |
| 36 | |
| 37 | |
| 38 | As of writing this, ASN1 compiler and decoder are used to implement |
| 39 | X509 certificate parser, pcks7 message parser and RSA public key parser |
| 40 | for UEFI secure boot. |