[crypto] Add SHA-224 algorithm

SHA-224 is almost identical to SHA-256, with differing initial hash
values and a truncated output length.

This implementation has been verified using the NIST SHA-224 test
vectors.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2015-04-12 14:50:18 +01:00
parent a9da129122
commit 4dbc44348c
5 changed files with 167 additions and 16 deletions

View File

@@ -160,6 +160,13 @@ struct asn1_builder_header {
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 1 )
/** ASN.1 OID for id-sha224 (2.16.840.1.101.3.4.2.4) */
#define ASN1_OID_SHA224 \
ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 4 )
/** ASN.1 OID for commonName (2.5.4.3) */
#define ASN1_OID_COMMON_NAME \
ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 4 ), \

View File

@@ -58,6 +58,8 @@ union sha256_digest_data_dwords {
struct sha256_context {
/** Amount of accumulated data */
size_t len;
/** Digest size */
size_t digestsize;
/** Digest and accumulated data */
union sha256_digest_data_dwords ddd;
} __attribute__ (( packed ));
@@ -68,6 +70,16 @@ struct sha256_context {
/** SHA-256 digest size */
#define SHA256_DIGEST_SIZE sizeof ( struct sha256_digest )
/** SHA-224 digest size */
#define SHA224_DIGEST_SIZE ( SHA256_DIGEST_SIZE * 224 / 256 )
extern void sha256_family_init ( struct sha256_context *context,
const struct sha256_digest *init,
size_t digestsize );
extern void sha256_update ( void *ctx, const void *data, size_t len );
extern void sha256_final ( void *ctx, void *out );
extern struct digest_algorithm sha256_algorithm;
extern struct digest_algorithm sha224_algorithm;
#endif /* _IPXE_SHA256_H */