diff options
author | Michael Brown <mcb30@ipxe.org> | 2015-04-12 14:50:18 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2015-04-12 17:01:10 +0100 |
commit | 4dbc44348ca9011465c3bce38757173c059309ec (patch) | |
tree | c5f0790a71bc74fe3083a18e164416b0ecf3ed4b /src/include/ipxe | |
parent | a9da1291227735fdae475e21b02b2a5fa29dd956 (diff) | |
download | ipxe-4dbc44348ca9011465c3bce38757173c059309ec.tar.gz |
[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>
Diffstat (limited to 'src/include/ipxe')
-rw-r--r-- | src/include/ipxe/asn1.h | 7 | ||||
-rw-r--r-- | src/include/ipxe/sha256.h | 12 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/include/ipxe/asn1.h b/src/include/ipxe/asn1.h index 3302c8053..4e8605fe3 100644 --- a/src/include/ipxe/asn1.h +++ b/src/include/ipxe/asn1.h @@ -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 ), \ diff --git a/src/include/ipxe/sha256.h b/src/include/ipxe/sha256.h index 1e4dceceb..811279a64 100644 --- a/src/include/ipxe/sha256.h +++ b/src/include/ipxe/sha256.h @@ -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 */ |