iPXE
md5_sha1.h
Go to the documentation of this file.
1#ifndef _IPXE_MD5_SHA1_H
2#define _IPXE_MD5_SHA1_H
3
4/** @file
5 *
6 * Hybrid MD5+SHA1 hash as used by TLSv1.1 and earlier
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/crypto.h>
15#include <ipxe/md5.h>
16#include <ipxe/sha1.h>
17
18/** An MD5+SHA1 context */
20 /** MD5 context */
22 /** SHA-1 context */
24} __attribute__ (( packed ));
25
26/** MD5+SHA1 context size */
27#define MD5_SHA1_CTX_SIZE sizeof ( struct md5_sha1_context )
28
29/** An MD5+SHA1 digest */
31 /** MD5 digest */
33 /** SHA-1 digest */
35} __attribute__ (( packed ));
36
37/** MD5+SHA1 digest size */
38#define MD5_SHA1_DIGEST_SIZE sizeof ( struct md5_sha1_digest )
39
40/** An MD5+SHA1 data block */
42 /** MD5 data block */
44 /** SHA-1 data block */
46};
47
48/** MD5+SHA1 block size */
49#define MD5_SHA1_BLOCK_SIZE sizeof ( union md5_sha1_block )
50
51/** An MD5+SHA1 HMAC key block
52 *
53 * The hybrid PRF used in TLS version 1.1 and earlier does not use
54 * HMAC with the hybrid MD5+SHA1 algorithm: it uses separate
55 * invocations of HMAC-MD5 and HMAC-SHA1.
56 */
58 /** MD5 HMAC key */
60 /** SHA-1 HMAC key */
62};
63
64extern char md5_sha1_sentinel[1];
66
67/**
68 * Check if a digest algorithm is MD5+SHA1
69 *
70 * @v digest Digest algorithm
71 * @v is_md5_sha1 Digest algorithm is MD5+SHA1
72 */
73static inline __attribute__ (( always_inline )) int
74is_md5_sha1 ( struct digest_algorithm *digest ) {
75
76 /* The MD5+SHA1 algorithm is hardcoded into various parts of
77 * the TLS specifications prior to TLSv1.2, which has knock-on
78 * effects on non-TLS code such as the RSA algorithm (which
79 * needs to be able to identify the PKCS#1 digestInfo prefix).
80 *
81 * Allow a digest algorithm to be tested to see if it is the
82 * MD5+SHA1 algorithm without creating an explicit symbol
83 * reference that will drag the algorithm into a build that
84 * otherwise does not need it.
85 */
86 return ( digest->priv == md5_sha1_sentinel );
87}
88
89#endif /* _IPXE_MD5_SHA1_H */
#define SHA1_DIGEST_SIZE
Definition Tpm20.h:25
#define SHA1_BLOCK_SIZE
Definition Tpm20.h:26
unsigned char uint8_t
Definition stdint.h:10
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define __attribute__(x)
Definition compiler.h:10
Cryptographic API.
MD5 algorithm.
#define MD5_CTX_SIZE
MD5 context size.
Definition md5.h:51
#define MD5_BLOCK_SIZE
MD5 block size.
Definition md5.h:54
#define MD5_DIGEST_SIZE
MD5 digest size.
Definition md5.h:57
char md5_sha1_sentinel[1]
Sentinel used to avoid explicit symbol references.
Definition md5_sha1.c:38
struct digest_algorithm md5_sha1_algorithm
Hybrid MD5+SHA1 digest algorithm.
Definition md5_sha1.c:87
static int is_md5_sha1(struct digest_algorithm *digest)
Check if a digest algorithm is MD5+SHA1.
Definition md5_sha1.h:74
SHA-1 algorithm.
#define SHA1_CTX_SIZE
SHA-1 context size.
Definition sha1.h:51
A message digest algorithm.
Definition crypto.h:19
void * priv
Algorithm private data.
Definition crypto.h:54
An MD5+SHA1 context.
Definition md5_sha1.h:19
uint8_t sha1[SHA1_CTX_SIZE]
SHA-1 context.
Definition md5_sha1.h:23
uint8_t md5[MD5_CTX_SIZE]
MD5 context.
Definition md5_sha1.h:21
An MD5+SHA1 digest.
Definition md5_sha1.h:30
uint8_t md5[MD5_DIGEST_SIZE]
MD5 digest.
Definition md5_sha1.h:32
uint8_t sha1[SHA1_DIGEST_SIZE]
SHA-1 digest.
Definition md5_sha1.h:34
An MD5+SHA1 HMAC key block.
Definition md5_sha1.h:57
uint8_t md5[MD5_BLOCK_SIZE]
MD5 HMAC key.
Definition md5_sha1.h:59
uint8_t sha1[SHA1_BLOCK_SIZE]
SHA-1 HMAC key.
Definition md5_sha1.h:61
An MD5+SHA1 data block.
Definition md5_sha1.h:41
uint8_t sha1[SHA1_BLOCK_SIZE]
SHA-1 data block.
Definition md5_sha1.h:45
uint8_t md5[MD5_BLOCK_SIZE]
MD5 data block.
Definition md5_sha1.h:43