mirror of https://github.com/ipxe/ipxe.git
[crypto] Use linker tables for RSA digestInfo prefixes
Allow external code to specify RSA digestInfo prefixes for additional digest algorithms. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/6/head
parent
7869f71ae7
commit
05c13716f9
|
@ -39,45 +39,37 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
* RSA is documented in RFC 3447.
|
* RSA is documented in RFC 3447.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** An RSA digestInfo prefix */
|
/** MD5 digestInfo prefix */
|
||||||
struct rsa_digestinfo_prefix {
|
static const uint8_t rsa_md5_prefix_data[] =
|
||||||
/** Digest algorithm */
|
|
||||||
struct digest_algorithm *digest;
|
|
||||||
/** Prefix */
|
|
||||||
const void *data;
|
|
||||||
/** Length of prefix */
|
|
||||||
size_t len;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** "id-md5" object identifier */
|
|
||||||
static const uint8_t rsa_md5_prefix[] =
|
|
||||||
{ RSA_DIGESTINFO_PREFIX ( MD5_DIGEST_SIZE, ASN1_OID_MD5 ) };
|
{ RSA_DIGESTINFO_PREFIX ( MD5_DIGEST_SIZE, ASN1_OID_MD5 ) };
|
||||||
|
|
||||||
/** "id-sha1" object identifier */
|
/** SHA-1 digestInfo prefix */
|
||||||
static const uint8_t rsa_sha1_prefix[] =
|
static const uint8_t rsa_sha1_prefix_data[] =
|
||||||
{ RSA_DIGESTINFO_PREFIX ( SHA1_DIGEST_SIZE, ASN1_OID_SHA1 ) };
|
{ RSA_DIGESTINFO_PREFIX ( SHA1_DIGEST_SIZE, ASN1_OID_SHA1 ) };
|
||||||
|
|
||||||
/** "id-sha256" object identifier */
|
/** SHA-256 digestInfo prefix */
|
||||||
static const uint8_t rsa_sha256_prefix[] =
|
static const uint8_t rsa_sha256_prefix_data[] =
|
||||||
{ RSA_DIGESTINFO_PREFIX ( SHA256_DIGEST_SIZE, ASN1_OID_SHA256 ) };
|
{ RSA_DIGESTINFO_PREFIX ( SHA256_DIGEST_SIZE, ASN1_OID_SHA256 ) };
|
||||||
|
|
||||||
/** RSA digestInfo prefixes */
|
/** MD5 digestInfo prefix */
|
||||||
static struct rsa_digestinfo_prefix rsa_digestinfo_prefixes[] = {
|
struct rsa_digestinfo_prefix rsa_md5_prefix __rsa_digestinfo_prefix = {
|
||||||
{
|
.digest = &md5_algorithm,
|
||||||
.digest = &md5_algorithm,
|
.data = rsa_md5_prefix_data,
|
||||||
.data = rsa_md5_prefix,
|
.len = sizeof ( rsa_md5_prefix_data ),
|
||||||
.len = sizeof ( rsa_md5_prefix ),
|
};
|
||||||
},
|
|
||||||
{
|
/** SHA-1 digestInfo prefix */
|
||||||
.digest = &sha1_algorithm,
|
struct rsa_digestinfo_prefix rsa_sha1_prefix __rsa_digestinfo_prefix = {
|
||||||
.data = rsa_sha1_prefix,
|
.digest = &sha1_algorithm,
|
||||||
.len = sizeof ( rsa_sha1_prefix ),
|
.data = rsa_sha1_prefix_data,
|
||||||
},
|
.len = sizeof ( rsa_sha1_prefix_data ),
|
||||||
{
|
};
|
||||||
.digest = &sha256_algorithm,
|
|
||||||
.data = rsa_sha256_prefix,
|
/** SHA-256 digestInfo prefix */
|
||||||
.len = sizeof ( rsa_sha256_prefix ),
|
struct rsa_digestinfo_prefix rsa_sha256_prefix __rsa_digestinfo_prefix = {
|
||||||
},
|
.digest = &sha256_algorithm,
|
||||||
|
.data = rsa_sha256_prefix_data,
|
||||||
|
.len = sizeof ( rsa_sha256_prefix_data ),
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,11 +81,8 @@ static struct rsa_digestinfo_prefix rsa_digestinfo_prefixes[] = {
|
||||||
static struct rsa_digestinfo_prefix *
|
static struct rsa_digestinfo_prefix *
|
||||||
rsa_find_prefix ( struct digest_algorithm *digest ) {
|
rsa_find_prefix ( struct digest_algorithm *digest ) {
|
||||||
struct rsa_digestinfo_prefix *prefix;
|
struct rsa_digestinfo_prefix *prefix;
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
for ( i = 0 ; i < ( sizeof ( rsa_digestinfo_prefixes ) /
|
for_each_table_entry ( prefix, RSA_DIGESTINFO_PREFIXES ) {
|
||||||
sizeof ( rsa_digestinfo_prefixes[0] ) ) ; i++ ) {
|
|
||||||
prefix = &rsa_digestinfo_prefixes[i];
|
|
||||||
if ( prefix->digest == digest )
|
if ( prefix->digest == digest )
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <ipxe/crypto.h>
|
#include <ipxe/crypto.h>
|
||||||
#include <ipxe/bigint.h>
|
#include <ipxe/bigint.h>
|
||||||
#include <ipxe/asn1.h>
|
#include <ipxe/asn1.h>
|
||||||
|
#include <ipxe/tables.h>
|
||||||
|
|
||||||
/** ASN.1 OID for iso(1) member-body(2) us(840) */
|
/** ASN.1 OID for iso(1) member-body(2) us(840) */
|
||||||
#define ASN1_OID_ISO_US ASN1_OID_ISO_MEMBERBODY, ASN1_OID_DOUBLE ( 840 )
|
#define ASN1_OID_ISO_US ASN1_OID_ISO_MEMBERBODY, ASN1_OID_DOUBLE ( 840 )
|
||||||
|
@ -111,6 +112,23 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
RSA_DIGESTALGORITHM ( __VA_ARGS__ ), \
|
RSA_DIGESTALGORITHM ( __VA_ARGS__ ), \
|
||||||
RSA_DIGEST_PREFIX ( digest_size )
|
RSA_DIGEST_PREFIX ( digest_size )
|
||||||
|
|
||||||
|
/** An RSA digestInfo prefix */
|
||||||
|
struct rsa_digestinfo_prefix {
|
||||||
|
/** Digest algorithm */
|
||||||
|
struct digest_algorithm *digest;
|
||||||
|
/** Prefix */
|
||||||
|
const void *data;
|
||||||
|
/** Length of prefix */
|
||||||
|
size_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** RSA digestInfo prefix table */
|
||||||
|
#define RSA_DIGESTINFO_PREFIXES \
|
||||||
|
__table ( struct rsa_digestinfo_prefix, "rsa_digestinfo_prefixes" )
|
||||||
|
|
||||||
|
/** Declare an RSA digestInfo prefix */
|
||||||
|
#define __rsa_digestinfo_prefix __table_entry ( RSA_DIGESTINFO_PREFIXES, 01 )
|
||||||
|
|
||||||
/** An RSA context */
|
/** An RSA context */
|
||||||
struct rsa_context {
|
struct rsa_context {
|
||||||
/** Allocated memory */
|
/** Allocated memory */
|
||||||
|
|
Loading…
Reference in New Issue