iPXE
md5_sha1.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27/** @file
28 *
29 * Hybrid MD5+SHA1 hash as used by TLSv1.1 and earlier
30 *
31 */
32
33#include <ipxe/crypto.h>
34#include <ipxe/rsa.h>
35#include <ipxe/md5_sha1.h>
36
37/** Sentinel used to avoid explicit symbol references */
39
40/**
41 * Initialise MD5+SHA1 algorithm
42 *
43 * @v digest Digest algorithm
44 * @v ctx MD5+SHA1 context
45 */
46static void md5_sha1_init ( struct digest_algorithm *digest __unused,
47 void *ctx ) {
48 struct md5_sha1_context *context = ctx;
49
50 digest_init ( &md5_algorithm, context->md5 );
51 digest_init ( &sha1_algorithm, context->sha1 );
52}
53
54/**
55 * Accumulate data with MD5+SHA1 algorithm
56 *
57 * @v digest Digest algorithm
58 * @v ctx MD5+SHA1 context
59 * @v data Data
60 * @v len Length of data
61 */
62static void md5_sha1_update ( struct digest_algorithm *digest __unused,
63 void *ctx, const void *data, size_t len ) {
64 struct md5_sha1_context *context = ctx;
65
66 digest_update ( &md5_algorithm, context->md5, data, len );
67 digest_update ( &sha1_algorithm, context->sha1, data, len );
68}
69
70/**
71 * Generate MD5+SHA1 digest
72 *
73 * @v digest Digest algorithm
74 * @v ctx MD5+SHA1 context
75 * @v out Output buffer
76 */
77static void md5_sha1_final ( struct digest_algorithm *digest __unused,
78 void *ctx, void *out ) {
79 struct md5_sha1_context *context = ctx;
80 struct md5_sha1_digest *output = out;
81
82 digest_final ( &md5_algorithm, context->md5, output->md5 );
83 digest_final ( &sha1_algorithm, context->sha1, output->sha1 );
84}
85
86/** Hybrid MD5+SHA1 digest algorithm */
88 .name = "md5+sha1",
89 .ctxsize = sizeof ( struct md5_sha1_context ),
90 .blocksize = sizeof ( union md5_sha1_block ),
91 .digestsize = sizeof ( struct md5_sha1_digest ),
92 .init = md5_sha1_init,
93 .update = md5_sha1_update,
94 .final = md5_sha1_final,
95 .priv = md5_sha1_sentinel,
96};
97
98/* Sanity checks */
99static_assert ( MD5_SHA1_BLOCK_SIZE == MD5_BLOCK_SIZE );
100static_assert ( MD5_SHA1_BLOCK_SIZE == SHA1_BLOCK_SIZE );
struct golan_eq_context ctx
Definition CIB_PRM.h:0
__be32 out[4]
Definition CIB_PRM.h:8
#define SHA1_BLOCK_SIZE
Definition Tpm20.h:26
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:598
#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
Cryptographic API.
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition crypto.h:294
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition crypto.h:305
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition crypto.h:299
#define MD5_BLOCK_SIZE
MD5 block size.
Definition md5.h:54
struct digest_algorithm md5_algorithm
static void md5_sha1_init(struct digest_algorithm *digest __unused, void *ctx)
Initialise MD5+SHA1 algorithm.
Definition md5_sha1.c:46
static void md5_sha1_update(struct digest_algorithm *digest __unused, void *ctx, const void *data, size_t len)
Accumulate data with MD5+SHA1 algorithm.
Definition md5_sha1.c:62
static void md5_sha1_final(struct digest_algorithm *digest __unused, void *ctx, void *out)
Generate MD5+SHA1 digest.
Definition md5_sha1.c:77
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
Hybrid MD5+SHA1 hash as used by TLSv1.1 and earlier.
#define MD5_SHA1_BLOCK_SIZE
MD5+SHA1 block size.
Definition md5_sha1.h:49
uint32_t digestsize
Digest size (i.e.
Definition pccrr.h:1
RSA public-key cryptography.
struct digest_algorithm sha1_algorithm
A message digest algorithm.
Definition crypto.h:19
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
An MD5+SHA1 data block.
Definition md5_sha1.h:41