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/**
38 * Initialise MD5+SHA1 algorithm
39 *
40 * @v digest Digest algorithm
41 * @v ctx MD5+SHA1 context
42 */
43static void md5_sha1_init ( struct digest_algorithm *digest __unused,
44 void *ctx ) {
45 struct md5_sha1_context *context = ctx;
46
47 digest_init ( &md5_algorithm, context->md5 );
48 digest_init ( &sha1_algorithm, context->sha1 );
49}
50
51/**
52 * Accumulate data with MD5+SHA1 algorithm
53 *
54 * @v digest Digest algorithm
55 * @v ctx MD5+SHA1 context
56 * @v data Data
57 * @v len Length of data
58 */
59static void md5_sha1_update ( struct digest_algorithm *digest __unused,
60 void *ctx, const void *data, size_t len ) {
61 struct md5_sha1_context *context = ctx;
62
63 digest_update ( &md5_algorithm, context->md5, data, len );
64 digest_update ( &sha1_algorithm, context->sha1, data, len );
65}
66
67/**
68 * Generate MD5+SHA1 digest
69 *
70 * @v digest Digest algorithm
71 * @v ctx MD5+SHA1 context
72 * @v out Output buffer
73 */
74static void md5_sha1_final ( struct digest_algorithm *digest __unused,
75 void *ctx, void *out ) {
76 struct md5_sha1_context *context = ctx;
77 struct md5_sha1_digest *output = out;
78
79 digest_final ( &md5_algorithm, context->md5, output->md5 );
80 digest_final ( &sha1_algorithm, context->sha1, output->sha1 );
81}
82
83/** Hybrid MD5+SHA1 digest algorithm */
85 .name = "md5+sha1",
86 .ctxsize = sizeof ( struct md5_sha1_context ),
87 .blocksize = sizeof ( union md5_sha1_block ),
88 .digestsize = sizeof ( struct md5_sha1_digest ),
89 .init = md5_sha1_init,
90 .update = md5_sha1_update,
91 .final = md5_sha1_final,
92};
93
94/** RSA digestInfo prefix for MD5+SHA1 algorithm */
95struct rsa_digestinfo_prefix rsa_md5_sha1_prefix __rsa_digestinfo_prefix = {
96 .digest = &md5_sha1_algorithm,
97 .data = NULL, /* MD5+SHA1 signatures have no digestInfo */
98 .len = 0,
99};
100
101/* Sanity checks */
102static_assert ( MD5_SHA1_BLOCK_SIZE == MD5_BLOCK_SIZE );
103static_assert ( MD5_SHA1_BLOCK_SIZE == SHA1_BLOCK_SIZE );
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
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:43
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:59
static void md5_sha1_final(struct digest_algorithm *digest __unused, void *ctx, void *out)
Generate MD5+SHA1 digest.
Definition md5_sha1.c:74
struct digest_algorithm md5_sha1_algorithm
Hybrid MD5+SHA1 digest algorithm.
Definition md5_sha1.c:84
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.
#define __rsa_digestinfo_prefix
Declare an RSA digestInfo prefix.
Definition rsa.h:57
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 RSA digestInfo prefix.
Definition rsa.h:43
An MD5+SHA1 data block.
Definition md5_sha1.h:41