summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe
diff options
context:
space:
mode:
authorMichael Brown2012-03-04 16:13:54 +0100
committerMichael Brown2012-03-04 18:42:29 +0100
commit76f59397369571093eab3d810f1a004d35f6195d (patch)
tree73d93f754f75d98727802a9a671aaf3e16d96fdd /src/include/ipxe
parent[802.11] Eliminate use of AXTLS-specific SHA1_SIZE constant (diff)
downloadipxe-76f59397369571093eab3d810f1a004d35f6195d.tar.gz
ipxe-76f59397369571093eab3d810f1a004d35f6195d.tar.xz
ipxe-76f59397369571093eab3d810f1a004d35f6195d.zip
[crypto] Replace SHA-1 implementation
Replace SHA-1 implementation from AXTLS with a dedicated iPXE implementation which is around 40% smaller. This implementation has been verified using the existing SHA-1 self-tests (including the NIST SHA-1 test vectors). Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe')
-rw-r--r--src/include/ipxe/sha1.h78
1 files changed, 67 insertions, 11 deletions
diff --git a/src/include/ipxe/sha1.h b/src/include/ipxe/sha1.h
index 9b6f55147..a97035ec7 100644
--- a/src/include/ipxe/sha1.h
+++ b/src/include/ipxe/sha1.h
@@ -1,24 +1,80 @@
#ifndef _IPXE_SHA1_H
#define _IPXE_SHA1_H
+/** @file
+ *
+ * SHA-1 algorithm
+ *
+ */
+
FILE_LICENCE ( GPL2_OR_LATER );
-#include "crypto/axtls/crypto.h"
+#include <stdint.h>
+#include <ipxe/crypto.h>
-struct digest_algorithm;
+/** An SHA-1 digest */
+struct sha1_digest {
+ /** Hash output */
+ uint32_t h[5];
+};
-#define SHA1_CTX_SIZE sizeof ( SHA1_CTX )
-#define SHA1_DIGEST_SIZE SHA1_SIZE
+/** An SHA-1 data block */
+union sha1_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;
+};
-extern struct digest_algorithm sha1_algorithm;
+/** SHA-1 digest and data block
+ *
+ * The order of fields within this structure is designed to minimise
+ * code size.
+ */
+struct sha1_digest_data {
+ /** Digest of data already processed */
+ struct sha1_digest digest;
+ /** Accumulated data */
+ union sha1_block data;
+} __attribute__ (( packed ));
+
+/** SHA-1 digest and data block */
+union sha1_digest_data_dwords {
+ /** Digest and data block */
+ struct sha1_digest_data dd;
+ /** Raw dwords */
+ uint32_t dword[ sizeof ( struct sha1_digest_data ) /
+ sizeof ( uint32_t ) ];
+};
-/* SHA1-wrapping functions defined in sha1extra.c: */
+/** An SHA-1 context */
+struct sha1_context {
+ /** Amount of accumulated data */
+ size_t len;
+ /** Digest and accumulated data */
+ union sha1_digest_data_dwords ddd;
+} __attribute__ (( packed ));
-void prf_sha1 ( const void *key, size_t key_len, const char *label,
- const void *data, size_t data_len, void *prf, size_t prf_len );
+/** SHA-1 context size */
+#define SHA1_CTX_SIZE sizeof ( struct sha1_context )
+
+/** SHA-1 digest size */
+#define SHA1_DIGEST_SIZE sizeof ( struct sha1_digest )
+
+extern struct digest_algorithm sha1_algorithm;
-void pbkdf2_sha1 ( const void *passphrase, size_t pass_len,
- const void *salt, size_t salt_len,
- int iterations, void *key, size_t key_len );
+extern void prf_sha1 ( const void *key, size_t key_len, const char *label,
+ const void *data, size_t data_len, void *prf,
+ size_t prf_len );
+extern void pbkdf2_sha1 ( const void *passphrase, size_t pass_len,
+ const void *salt, size_t salt_len,
+ int iterations, void *key, size_t key_len );
#endif /* _IPXE_SHA1_H */