diff options
| author | Michael Brown | 2012-03-21 14:57:32 +0100 |
|---|---|---|
| committer | Michael Brown | 2012-03-22 01:31:22 +0100 |
| commit | 38b7e43f7d88a35b23b2d44a72d07d2ee589d31e (patch) | |
| tree | 1e8a9472a0b433e1f0e25f694b49301f850c1c17 /src/include | |
| parent | [test] Add X.509 self-tests (diff) | |
| download | ipxe-38b7e43f7d88a35b23b2d44a72d07d2ee589d31e.tar.gz ipxe-38b7e43f7d88a35b23b2d44a72d07d2ee589d31e.tar.xz ipxe-38b7e43f7d88a35b23b2d44a72d07d2ee589d31e.zip | |
[crypto] Generalise X.509 OID-identified algorithm to asn1.c
The concept of an OID-identified algorithm as defined in X.509 is used
in some other standards (e.g. PKCS#7). Generalise this functionality
and provide it as part of the ASN.1 core.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/ipxe/asn1.h | 23 | ||||
| -rw-r--r-- | src/include/ipxe/x509.h | 29 |
2 files changed, 26 insertions, 26 deletions
diff --git a/src/include/ipxe/asn1.h b/src/include/ipxe/asn1.h index f912f5f57..553a8f3c3 100644 --- a/src/include/ipxe/asn1.h +++ b/src/include/ipxe/asn1.h @@ -9,6 +9,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); +#include <stdint.h> +#include <ipxe/tables.h> + /** An ASN.1 object cursor */ struct asn1_cursor { /** Start of data */ @@ -143,6 +146,24 @@ struct asn1_cursor { .len = sizeof ( oid_value ), \ } +/** An ASN.1 OID-identified algorithm */ +struct asn1_algorithm { + /** Name */ + const char *name; + /** Object identifier */ + struct asn1_cursor oid; + /** Public-key algorithm (if applicable) */ + struct pubkey_algorithm *pubkey; + /** Digest algorithm (if applicable) */ + struct digest_algorithm *digest; +}; + +/** ASN.1 OID-identified algorithms */ +#define ASN1_ALGORITHMS __table ( struct asn1_algorithm, "asn1_algorithms" ) + +/** Declare an ASN.1 OID-identified algorithm */ +#define __asn1_algorithm __table_entry ( ASN1_ALGORITHMS, 01 ) + /** An ASN.1 boolean */ struct asn1_boolean { /** Value */ @@ -181,5 +202,7 @@ extern int asn1_boolean ( const struct asn1_cursor *cursor ); extern int asn1_integer ( const struct asn1_cursor *cursor, int *value ); extern int asn1_compare ( const struct asn1_cursor *cursor1, const struct asn1_cursor *cursor2 ); +extern struct asn1_algorithm * +asn1_algorithm ( const struct asn1_cursor *cursor ); #endif /* _IPXE_ASN1_H */ diff --git a/src/include/ipxe/x509.h b/src/include/ipxe/x509.h index 89f90b844..45f738cd7 100644 --- a/src/include/ipxe/x509.h +++ b/src/include/ipxe/x509.h @@ -14,29 +14,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <time.h> #include <ipxe/asn1.h> -/** An X.509 algorithm */ -struct x509_algorithm { - /** Name */ - const char *name; - /** Object identifier */ - struct asn1_cursor oid; - /** Public-key algorithm */ - struct pubkey_algorithm *pubkey; - /** Digest algorithm (if applicable) */ - struct digest_algorithm *digest; -}; - -/** - * Test if X.509 algorithm is a signature algorithm - * - * @v algorithm Algorithm - * @ret is_signature Algorithm is a signature algorithm - */ -static inline __attribute__ (( always_inline )) int -x509_is_signature_algorithm ( struct x509_algorithm *algorithm ) { - return ( algorithm->digest != NULL ); -} - /** An X.509 bit string */ struct x509_bit_string { /** Data */ @@ -80,7 +57,7 @@ struct x509_public_key { /** Raw public key */ struct asn1_cursor raw; /** Public key algorithm */ - struct x509_algorithm *algorithm; + struct asn1_algorithm *algorithm; }; /** An X.509 certificate subject */ @@ -96,7 +73,7 @@ struct x509_subject { /** An X.509 certificate signature */ struct x509_signature { /** Signature algorithm */ - struct x509_algorithm *algorithm; + struct asn1_algorithm *algorithm; /** Signature value */ struct x509_bit_string value; }; @@ -147,7 +124,7 @@ struct x509_certificate { /** Raw tbsCertificate */ struct asn1_cursor tbs; /** Signature algorithm */ - struct x509_algorithm *signature_algorithm; + struct asn1_algorithm *signature_algorithm; /** Issuer */ struct x509_issuer issuer; /** Validity */ |
