ENCODEX provides support for encoding, decoding, and parsing to and from multiple encoding schemes.
- Anthony Cagliano
- Adam Beckingham
- ASN.1 (Abstract Syntax Notation One)
- A data encoding format common to cryptography in which data is represented as a series of one or more tag, size, data groups. The most commonly occurring serialization format for ASN.1 is DER, which stands for Distinguished Encoding Rules.
- Base 64
- A data encoding format also common to cryptography in which data is expressed in six (6) bit groups of data (sextets) which are then mapped to one of 64 plaintext characters (A-Z,a-z,+/) and padding = characters. Base 64 is the encoding format used by PEM keyfiles.
- BPP (Bits-Per-Pixel)
- A data encoding format in which a bytewise data value that can be expressed within 4 bits or less is compressed such that multiple values fit within the same byte. This discards any higher, unused bits and makes the data smaller.
- Octet Encoding
- The standard encoding format in which each byte expresses 8 bits of information.
Defines possible ASN.1 basic tag types.
ASN1_UNIVERSAL,
ASN1_APPLICATION,
ASN1_CONTEXTSPEC,
ASN1_PRIVATE
};
Defines possible class types for ASN.1-encoded objects.
ASN1_PRIMITIVE,
ASN1_CONSTRUCTED
};
Defines possible forms for ASN.1-encoded objects.
Defines a structure for the decoding of ASN.1-encoded objects.
void *asn1_data, size_t len,
struct cryptx_asn1_obj* objs,
size_t iter_count);
Decodes an ASN.1 encoded data stream, returning object metadata into an array of cryptx_asn1_obj structs.
asn1_data: Pointer to ASN.1-encoded data.
len: Length of the data.
objs: Pointer to an array of cryptx_asn1_obj structs to decode objects into.
iter_count: Maximum number of ASN.1 objects to decode before returning
output: The number of objects successfully decoded.
The function will automatically recurse for any object with the ASN1_CONSTRUCTED bit set.
An object that starts with ASN1_RESVD (0x00) is assumed to have a padding byte prepended. That byte is skipped by the parser prior to the start of decoding.
In some keyfile formats, there is a BIT STRING object that is a constructed type but does not have the ASN1_CONSTRUCTED bit set. You will need to call this function again on that object to further parse it.
Object sizes greater than 24 bits (3 bytes) are unsupported due to device limitations. Encountering an unsupported size will cause the parser to quit, returning any objects it has already decoded.
Encodes an octet-encoded byte stream into a sextet encoded byte stream.
dest: Pointer to buffer to write sextet-encoded (output) data to.
src: Pointer to data to encode.
len: Length of data to encode.
output: The length of the output encoded data.
Decodes a sextet encoded byte stream and returns octet-encoded bytes.
dest: Pointer to buffer to write decoded (output) data to.
src: Pointer to data to decode.
len: Length of data to decode.
output: The length of the output decoded data.
Encodes an octet-encoded byte stream into bits-per-pixel encoding.
dest: Pointer to buffer to write bpp-encoded data to.
src: Pointer to data to encode/compress.
len: Length of the encoded (output) data stream.
bpp: Number of bits-per-pixel to encode into.
Decodes a bpp-encoded byte stream into octet-encoded bytes.
dest: Pointer to buffer to write decoded data to.
src: Pointer to data to decode/decompress.
len: Length of the encoded (input) data stream.
bpp: Number of bits-per-pixel to decode from.