summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe
diff options
context:
space:
mode:
authorMichael Brown2012-03-05 11:19:40 +0100
committerMichael Brown2012-03-05 11:25:58 +0100
commitfba2310562214eecd5c1fcdba86fccd95e292fa7 (patch)
treebf79c8b1aeb7823d6194184bcd082b7a1b4bb995 /src/include/ipxe
parent[802.11] Avoid using struct md5_ctx directly (diff)
downloadipxe-fba2310562214eecd5c1fcdba86fccd95e292fa7.tar.gz
ipxe-fba2310562214eecd5c1fcdba86fccd95e292fa7.tar.xz
ipxe-fba2310562214eecd5c1fcdba86fccd95e292fa7.zip
[crypto] Replace MD5 implementation
Replace MD5 implementation with one which is around 20% smaller. This implementation has been verified using the existing MD5 self-tests. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe')
-rw-r--r--src/include/ipxe/md5.h69
1 files changed, 59 insertions, 10 deletions
diff --git a/src/include/ipxe/md5.h b/src/include/ipxe/md5.h
index c3dfeb7e0..860bc4769 100644
--- a/src/include/ipxe/md5.h
+++ b/src/include/ipxe/md5.h
@@ -1,23 +1,72 @@
#ifndef _IPXE_MD5_H
#define _IPXE_MD5_H
-FILE_LICENCE ( GPL2_OR_LATER );
+/** @file
+ *
+ * MD5 algorithm
+ *
+ */
-struct digest_algorithm;
+FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
+#include <ipxe/crypto.h>
+
+/** An MD5 digest */
+struct md5_digest {
+ /** Hash output */
+ uint32_t h[4];
+};
-#define MD5_DIGEST_SIZE 16
-#define MD5_BLOCK_WORDS 16
-#define MD5_HASH_WORDS 4
+/** An MD5 data block */
+union md5_block {
+ /** Raw bytes */
+ uint8_t byte[64];
+ /** Raw dwords */
+ uint32_t dword[16];
+ /** Final block structure */
+ struct {
+ /** Padding */
+ uint8_t pad[56];
+ /** Length in bits */
+ uint64_t len;
+ } final;
+};
+
+/** MD5 digest and data block
+ *
+ * The order of fields within this structure is designed to minimise
+ * code size.
+ */
+struct md5_digest_data {
+ /** Digest of data already processed */
+ struct md5_digest digest;
+ /** Accumulated data */
+ union md5_block data;
+} __attribute__ (( packed ));
-struct md5_ctx {
- u32 hash[MD5_HASH_WORDS];
- u32 block[MD5_BLOCK_WORDS];
- u64 byte_count;
+/** MD5 digest and data block */
+union md5_digest_data_dwords {
+ /** Digest and data block */
+ struct md5_digest_data dd;
+ /** Raw dwords */
+ uint32_t dword[ sizeof ( struct md5_digest_data ) /
+ sizeof ( uint32_t ) ];
};
-#define MD5_CTX_SIZE sizeof ( struct md5_ctx )
+/** An MD5 context */
+struct md5_context {
+ /** Amount of accumulated data */
+ size_t len;
+ /** Digest and accumulated data */
+ union md5_digest_data_dwords ddd;
+} __attribute__ (( packed ));
+
+/** MD5 context size */
+#define MD5_CTX_SIZE sizeof ( struct md5_context )
+
+/** MD5 digest size */
+#define MD5_DIGEST_SIZE sizeof ( struct md5_digest )
extern struct digest_algorithm md5_algorithm;