iPXE
tlsclassic.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 * Classic TLS static RSA pre-master secret
30 *
31 * With classic static RSA key transport, the client unilaterally
32 * constructs the shared pre-master secret and then encrypts it using
33 * the server's public key.
34 *
35 * We model key transport as a key exchange algorithm that is
36 * incapable of generating public keys and where the public key size
37 * is zero (implying that the shared secret must be communicated via a
38 * means other than key exchange).
39 *
40 * This RSA pre-master secret structure could in principle have been
41 * used with any public-key algorithm that supports encryption and
42 * decryption (rather than only signing and verification), but no
43 * non-RSA cipher suites were ever defined to use this exact same
44 * structure of the pre-master secret.
45 *
46 * Key transport provides no forward secrecy since a compromise of the
47 * server's long-term private key provides the ability to decrypt all
48 * pre-master secrets that were encrypted using that key. Almost all
49 * servers will prefer to use ephemeral key exhange (which does
50 * provide forward secrecy). We retain support for key transport only
51 * for the sake of backwards compatibility with older servers.
52 *
53 */
54
55#include <string.h>
56#include <byteswap.h>
57#include <ipxe/tls.h>
58#include <ipxe/crypto.h>
59#include <config/crypto.h>
60
61/** A classic pre-master private key */
63 /** Random bytes */
65} __attribute__ (( packed ));
66
67/** A classic pre-master shared secret */
69 /** Highest supported protocol version */
71 /** Private key */
73} __attribute__ (( packed ));
74
75/**
76 * Agree classic pre-master secret
77 *
78 * @v exchange Key exchange algorithm
79 * @v private Private key
80 * @v partner Partner public key
81 * @v shared Shared secret to fill in
82 * @ret rc Return status code
83 */
84static int
86 const void *private,
87 const void *partner __unused, void *shared ) {
88 struct tls_classic_pre_master_shared *premaster = shared;
89
90 /* We model the classic pre-master secret as a key exchange
91 * algorithm in which we unilaterally construct the shared
92 * secret (with no partner public key input).
93 */
94 premaster->version = htons ( TLS_VERSION_MAX );
95 memcpy ( &premaster->private, private, sizeof ( premaster->private ) );
96
97 return 0;
98}
99
100/** Classic pre-master secret key exchange algorithm */
102 .name = "classic pre-master",
103 .privsize = sizeof ( struct tls_classic_pre_master_private ),
104 .pubsize = 0,
105 .sharedsize = sizeof ( struct tls_classic_pre_master_shared ),
106 .share = exchange_null_share,
108};
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
Cryptographic configuration.
#define TLS_VERSION_MAX
Maximum TLS version.
Definition crypto.h:17
int exchange_null_share(struct exchange_algorithm *exchange __unused, const void *private __unused, void *public __unused)
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5
#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
#define htons(value)
Definition byteswap.h:136
#define __attribute__(x)
Definition compiler.h:10
Cryptographic API.
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A key exchange algorithm.
Definition crypto.h:210
A classic pre-master private key.
Definition tlsclassic.c:62
uint8_t random[46]
Random bytes.
Definition tlsclassic.c:64
A classic pre-master shared secret.
Definition tlsclassic.c:68
uint16_t version
Highest supported protocol version.
Definition tlsclassic.c:70
struct tls_classic_pre_master_private private
Private key.
Definition tlsclassic.c:72
Transport Layer Security Protocol.
static int tls_classic_pre_master_agree(struct exchange_algorithm *exchange __unused, const void *private, const void *partner __unused, void *shared)
Agree classic pre-master secret.
Definition tlsclassic.c:85
struct exchange_algorithm tls_classic_pre_master_algorithm
Classic pre-master secret key exchange algorithm.
Definition tlsclassic.c:101