iPXE
sha1.h
Go to the documentation of this file.
00001 #ifndef _IPXE_SHA1_H
00002 #define _IPXE_SHA1_H
00003 
00004 /** @file
00005  *
00006  * SHA-1 algorithm
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/crypto.h>
00014 
00015 /** An SHA-1 digest */
00016 struct sha1_digest {
00017         /** Hash output */
00018         uint32_t h[5];
00019 };
00020 
00021 /** An SHA-1 data block */
00022 union sha1_block {
00023         /** Raw bytes */
00024         uint8_t byte[64];
00025         /** Raw dwords */
00026         uint32_t dword[16];
00027         /** Final block structure */
00028         struct {
00029                 /** Padding */
00030                 uint8_t pad[56];
00031                 /** Length in bits */
00032                 uint64_t len;
00033         } final;
00034 };
00035 
00036 /** SHA-1 digest and data block
00037  *
00038  * The order of fields within this structure is designed to minimise
00039  * code size.
00040  */
00041 struct sha1_digest_data {
00042         /** Digest of data already processed */
00043         struct sha1_digest digest;
00044         /** Accumulated data */
00045         union sha1_block data;
00046 } __attribute__ (( packed ));
00047 
00048 /** SHA-1 digest and data block */
00049 union sha1_digest_data_dwords {
00050         /** Digest and data block */
00051         struct sha1_digest_data dd;
00052         /** Raw dwords */
00053         uint32_t dword[ sizeof ( struct sha1_digest_data ) /
00054                         sizeof ( uint32_t ) ];
00055 };
00056 
00057 /** An SHA-1 context */
00058 struct sha1_context {
00059         /** Amount of accumulated data */
00060         size_t len;
00061         /** Digest and accumulated data */
00062         union sha1_digest_data_dwords ddd;
00063 } __attribute__ (( packed ));
00064 
00065 /** SHA-1 context size */
00066 #define SHA1_CTX_SIZE sizeof ( struct sha1_context )
00067 
00068 /** SHA-1 digest size */
00069 #define SHA1_DIGEST_SIZE sizeof ( struct sha1_digest )
00070 
00071 extern struct digest_algorithm sha1_algorithm;
00072 
00073 extern void prf_sha1 ( const void *key, size_t key_len, const char *label,
00074                        const void *data, size_t data_len, void *prf,
00075                        size_t prf_len );
00076 extern void pbkdf2_sha1 ( const void *passphrase, size_t pass_len,
00077                           const void *salt, size_t salt_len,
00078                           int iterations, void *key, size_t key_len );
00079 
00080 #endif /* _IPXE_SHA1_H */