Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0dc80d20d3 | ||
|
|
8f6a9399b3 | ||
|
|
a881a26061 | ||
|
|
b234226dbc | ||
|
|
8e2469c861 | ||
|
|
989dbe0bc4 | ||
|
|
6f70e8be83 | ||
|
|
17135c83fb | ||
|
|
27398f1360 | ||
|
|
de8a0821c7 | ||
|
|
2eea04c02c | ||
|
|
908174ec7e | ||
|
|
bac13ba1f6 | ||
|
|
13e390d54e | ||
|
|
26d3ef062b | ||
|
|
4b7d9a6af0 | ||
|
|
6d29415c89 | ||
|
|
6ca597eee9 | ||
|
|
e66552eeed | ||
|
|
08fcb0e8fb | ||
|
|
c6226f104e | ||
|
|
0abb3e85e5 | ||
|
|
4ed7a5718f | ||
|
|
fa62213231 | ||
|
|
119c415ee4 | ||
|
|
9e92c39894 | ||
|
|
3fc1b407d2 | ||
|
|
0958e01463 | ||
|
|
337880deaa | ||
|
|
f22879ca99 | ||
|
|
98dd25a3bb | ||
|
|
a147245f1a | ||
|
|
c3dd3168c9 | ||
|
|
b829b1750d | ||
|
|
03ff1bb99a | ||
|
|
18582a05fc | ||
|
|
6714b20ea2 | ||
|
|
b37d89db90 | ||
|
|
cc858acd32 | ||
|
|
b30a0987e2 | ||
|
|
3d8a614657 | ||
|
|
a9e89787d0 | ||
|
|
678a60f61d | ||
|
|
8c8ead2530 | ||
|
|
77b07ea4fd | ||
|
|
d8f9c221ed | ||
|
|
595b1796f6 | ||
|
|
1bd01b761f | ||
|
|
5524bb9832 | ||
|
|
36e1a559a2 | ||
|
|
1f3a37e342 | ||
|
|
74ec00a9f3 | ||
|
|
f883203132 | ||
|
|
115707c0ed | ||
|
|
ff0f860483 | ||
|
|
8b14652e50 | ||
|
|
56cc61a168 | ||
|
|
cac3a584dc | ||
|
|
8cbf248198 | ||
|
|
8b1d34badf | ||
|
|
cc1e27e525 | ||
|
|
ae4e85bde9 | ||
|
|
eeb7cd56e5 | ||
|
|
0aa2e4ec96 | ||
|
|
9e99a55b31 | ||
|
|
c1834f323f | ||
|
|
d5c08f78bd | ||
|
|
c30b71ee9c | ||
|
|
f3036fc213 | ||
|
|
59d065c9ac | ||
|
|
48ae5d5361 | ||
|
|
6701d91c50 | ||
|
|
b5b60ea33d | ||
|
|
8244410690 | ||
|
|
daa9e54ab8 | ||
|
|
3ef4f7e2ef | ||
|
|
cc07ed7c7e | ||
|
|
6f57d91935 | ||
|
|
e17568ad06 | ||
|
|
2524a60550 | ||
|
|
280942a92a | ||
|
|
6d98e0ca47 | ||
|
|
0c67a3632d | ||
|
|
c57887bfc8 | ||
|
|
18af669701 | ||
|
|
cfe65aa826 |
@@ -46,11 +46,19 @@ def create_snapshot(region, description, image):
|
||||
return snapshot_id
|
||||
|
||||
|
||||
def import_image(region, name, architecture, image, public):
|
||||
def import_image(region, name, architecture, image, public, overwrite):
|
||||
"""Import an AMI image"""
|
||||
client = boto3.client('ec2', region_name=region)
|
||||
resource = boto3.resource('ec2', region_name=region)
|
||||
description = '%s (%s)' % (name, architecture)
|
||||
images = client.describe_images(Filters=[{'Name': 'name',
|
||||
'Values': [description]}])
|
||||
if overwrite and images['Images']:
|
||||
images = images['Images'][0]
|
||||
image_id = images['ImageId']
|
||||
snapshot_id = images['BlockDeviceMappings'][0]['Ebs']['SnapshotId']
|
||||
resource.Image(image_id).deregister()
|
||||
resource.Snapshot(snapshot_id).delete()
|
||||
snapshot_id = create_snapshot(region=region, description=description,
|
||||
image=image)
|
||||
client.get_waiter('snapshot_completed').wait(SnapshotIds=[snapshot_id])
|
||||
@@ -88,6 +96,8 @@ parser.add_argument('--name', '-n',
|
||||
help="Image name")
|
||||
parser.add_argument('--public', '-p', action='store_true',
|
||||
help="Make image public")
|
||||
parser.add_argument('--overwrite', action='store_true',
|
||||
help="Overwrite any existing image with same name")
|
||||
parser.add_argument('--region', '-r', action='append',
|
||||
help="AWS region(s)")
|
||||
parser.add_argument('--wiki', '-w', metavar='FILE',
|
||||
@@ -115,7 +125,8 @@ with ThreadPoolExecutor(max_workers=len(imports)) as executor:
|
||||
name=args.name,
|
||||
architecture=architectures[image],
|
||||
image=image,
|
||||
public=args.public): (region, image)
|
||||
public=args.public,
|
||||
overwrite=args.overwrite): (region, image)
|
||||
for region, image in imports}
|
||||
results = {futures[future]: future.result()
|
||||
for future in as_completed(futures)}
|
||||
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
|
||||
import boto3
|
||||
|
||||
BLOCKSIZE = 512 * 1024
|
||||
|
||||
IPXELOG_OFFSET = 16 * 1024
|
||||
|
||||
IPXELOG_MAGIC = b'iPXE LOG'
|
||||
|
||||
|
||||
def create_snapshot(region, instance_id):
|
||||
"""Create root volume snapshot"""
|
||||
client = boto3.client('ec2', region_name=region)
|
||||
resource = boto3.resource('ec2', region_name=region)
|
||||
instance = resource.Instance(instance_id)
|
||||
volumes = list(instance.volumes.all())
|
||||
snapshot = volumes[0].create_snapshot()
|
||||
snapshot.wait_until_completed()
|
||||
return snapshot.id
|
||||
|
||||
|
||||
def get_snapshot_block(region, snapshot_id, index):
|
||||
"""Get block content from snapshot"""
|
||||
client = boto3.client('ebs', region_name=region)
|
||||
blocks = client.list_snapshot_blocks(SnapshotId=snapshot_id,
|
||||
StartingBlockIndex=index)
|
||||
token = blocks['Blocks'][0]['BlockToken']
|
||||
block = client.get_snapshot_block(SnapshotId=snapshot_id,
|
||||
BlockIndex=index,
|
||||
BlockToken=token)
|
||||
return block['BlockData'].read()
|
||||
|
||||
|
||||
def get_block0_content(region, instance_id):
|
||||
"""Get content of root volume block zero from instance"""
|
||||
client = boto3.client('ec2', region_name=region)
|
||||
resource = boto3.resource('ec2', region_name=region)
|
||||
snapshot_id = create_snapshot(region, instance_id)
|
||||
block = get_snapshot_block(region, snapshot_id, 0)
|
||||
resource.Snapshot(snapshot_id).delete()
|
||||
return block
|
||||
|
||||
|
||||
def get_int13con_output(region, instance_id):
|
||||
"""Get INT13 console output"""
|
||||
block = get_block0_content(region, instance_id)
|
||||
logpart = block[IPXELOG_OFFSET:]
|
||||
magic = logpart[:len(IPXELOG_MAGIC)]
|
||||
if magic != IPXELOG_MAGIC:
|
||||
raise ValueError("Invalid log magic signature")
|
||||
log = logpart[len(IPXELOG_MAGIC):].split(b'\0')[0]
|
||||
return log.decode()
|
||||
|
||||
|
||||
# Parse command-line arguments
|
||||
parser = argparse.ArgumentParser(description="Get AWS INT13 console output")
|
||||
parser.add_argument('--region', '-r', help="AWS region")
|
||||
parser.add_argument('id', help="Instance ID")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get console output from INT13CON partition
|
||||
output = get_int13con_output(args.region, args.id)
|
||||
|
||||
# Print console output
|
||||
print(output)
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
.toolcheck
|
||||
.echocheck
|
||||
TAGS*
|
||||
bin*
|
||||
bin-*
|
||||
|
||||
+5
-1
@@ -50,6 +50,10 @@ $(BIN)/efidrv.cab : $(BIN)/alldrv.efis # $(ALL_drv.efi) is not yet defined
|
||||
$(QM)$(ECHO) " [CAB] $@"
|
||||
$(Q)$(LCAB) -n -q $(ALL_drv.efi) $@
|
||||
|
||||
$(BIN)/%.iso $(BIN)/%.usb : $(BIN)/%.efi util/genfsimg
|
||||
$(BIN)/%.iso : $(BIN)/%.efi util/genfsimg
|
||||
$(QM)$(ECHO) " [GENFSIMG] $@"
|
||||
$(Q)util/genfsimg -o $@ $<
|
||||
|
||||
$(BIN)/%.usb : $(BIN)/%.efi util/genfsimg
|
||||
$(QM)$(ECHO) " [GENFSIMG] $@"
|
||||
$(Q)util/genfsimg -o $@ $<
|
||||
|
||||
@@ -502,6 +502,13 @@ LDFLAGS += --gc-sections
|
||||
#
|
||||
LDFLAGS += -static
|
||||
|
||||
# Use separate code segment if supported by linker
|
||||
#
|
||||
ZSC_TEST = $(LD) -z separate-code --version 2>&1 > /dev/null
|
||||
ZSC_FLAGS := $(shell [ -z "`$(ZSC_TEST)`" ] && \
|
||||
$(ECHO) '-z separate-code -z max-page-size=4096')
|
||||
LDFLAGS += $(ZSC_FLAGS)
|
||||
|
||||
# compiler.h is needed for our linking and debugging system
|
||||
#
|
||||
CFLAGS += -include include/compiler.h
|
||||
@@ -1002,6 +1009,7 @@ endif
|
||||
# Device ID tables (using IDs from ROM definition file)
|
||||
#
|
||||
define obj_pci_id_asm
|
||||
.section ".note.GNU-stack", "", $(ASM_TCHAR)progbits
|
||||
.section ".pci_devlist.$(1)", "a", $(ASM_TCHAR)progbits
|
||||
.globl pci_devlist_$(1)
|
||||
pci_devlist_$(1):
|
||||
@@ -1171,7 +1179,7 @@ BLIB = $(BIN)/blib.a
|
||||
$(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
|
||||
$(Q)$(RM) $(BLIB)
|
||||
$(QM)$(ECHO) " [AR] $@"
|
||||
$(Q)$(AR) rD $@ $(sort $(BLIB_OBJS))
|
||||
$(Q)$(AR) rcD $@ $(sort $(BLIB_OBJS))
|
||||
$(Q)$(OBJCOPY) --enable-deterministic-archives \
|
||||
--prefix-symbols=$(SYMBOL_PREFIX) $@
|
||||
$(Q)$(RANLIB) -D $@
|
||||
|
||||
@@ -9,4 +9,5 @@ INCDIRS += arch/arm/include
|
||||
|
||||
# ARM-specific directories containing source files
|
||||
#
|
||||
SRCDIRS += arch/arm/core
|
||||
SRCDIRS += arch/arm/interface/efi
|
||||
|
||||
@@ -46,7 +46,7 @@ union arm32_io_qword {
|
||||
*
|
||||
* This is not atomic for ARM32.
|
||||
*/
|
||||
static uint64_t arm32_readq ( volatile uint64_t *io_addr ) {
|
||||
static __unused uint64_t arm32_readq ( volatile uint64_t *io_addr ) {
|
||||
volatile union arm32_io_qword *ptr =
|
||||
container_of ( io_addr, union arm32_io_qword, qword );
|
||||
union arm32_io_qword tmp;
|
||||
@@ -64,7 +64,8 @@ static uint64_t arm32_readq ( volatile uint64_t *io_addr ) {
|
||||
*
|
||||
* This is not atomic for ARM32.
|
||||
*/
|
||||
static void arm32_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
|
||||
static __unused void arm32_writeq ( uint64_t data,
|
||||
volatile uint64_t *io_addr ) {
|
||||
volatile union arm32_io_qword *ptr =
|
||||
container_of ( io_addr, union arm32_io_qword, qword );
|
||||
union arm32_io_qword tmp;
|
||||
@@ -82,7 +83,6 @@ PROVIDE_IOAPI_INLINE ( arm, readl );
|
||||
PROVIDE_IOAPI_INLINE ( arm, writeb );
|
||||
PROVIDE_IOAPI_INLINE ( arm, writew );
|
||||
PROVIDE_IOAPI_INLINE ( arm, writel );
|
||||
PROVIDE_IOAPI_INLINE ( arm, iodelay );
|
||||
PROVIDE_IOAPI_INLINE ( arm, mb );
|
||||
#ifdef __aarch64__
|
||||
PROVIDE_IOAPI_INLINE ( arm, readq );
|
||||
@@ -91,3 +91,4 @@ PROVIDE_IOAPI_INLINE ( arm, writeq );
|
||||
PROVIDE_IOAPI ( arm, readq, arm32_readq );
|
||||
PROVIDE_IOAPI ( arm, writeq, arm32_writeq );
|
||||
#endif
|
||||
PROVIDE_DUMMY_PIO ( arm );
|
||||
|
||||
@@ -9,6 +9,4 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <ipxe/io.h>
|
||||
|
||||
#endif /* _BITS_PCI_IO_H */
|
||||
|
||||
@@ -15,6 +15,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#define IOAPI_PREFIX_arm __arm_
|
||||
#endif
|
||||
|
||||
#include <ipxe/dummy_pio.h>
|
||||
|
||||
/*
|
||||
* Memory space mappings
|
||||
*
|
||||
@@ -77,55 +79,6 @@ ARM_WRITEX ( w, uint16_t, "h", "" );
|
||||
ARM_WRITEX ( l, uint32_t, "", "" );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy PIO reads and writes up to 32 bits
|
||||
*
|
||||
* There is no common standard for I/O-space access for ARM, and
|
||||
* non-MMIO peripherals are vanishingly rare. Provide dummy
|
||||
* implementations that will allow code to link and should cause
|
||||
* drivers to simply fail to detect hardware at runtime.
|
||||
*
|
||||
*/
|
||||
|
||||
#define ARM_INX( _suffix, _type ) \
|
||||
static inline __always_inline _type \
|
||||
IOAPI_INLINE ( arm, in ## _suffix ) ( volatile _type *io_addr __unused) { \
|
||||
return ~( (_type) 0 ); \
|
||||
} \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( arm, ins ## _suffix ) ( volatile _type *io_addr __unused, \
|
||||
_type *data, unsigned int count ) { \
|
||||
memset ( data, 0xff, count * sizeof ( *data ) ); \
|
||||
}
|
||||
ARM_INX ( b, uint8_t );
|
||||
ARM_INX ( w, uint16_t );
|
||||
ARM_INX ( l, uint32_t );
|
||||
|
||||
#define ARM_OUTX( _suffix, _type ) \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( arm, out ## _suffix ) ( _type data __unused, \
|
||||
volatile _type *io_addr __unused ) { \
|
||||
/* Do nothing */ \
|
||||
} \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( arm, outs ## _suffix ) ( volatile _type *io_addr __unused, \
|
||||
const _type *data __unused, \
|
||||
unsigned int count __unused ) { \
|
||||
/* Do nothing */ \
|
||||
}
|
||||
ARM_OUTX ( b, uint8_t );
|
||||
ARM_OUTX ( w, uint16_t );
|
||||
ARM_OUTX ( l, uint32_t );
|
||||
|
||||
/*
|
||||
* Slow down I/O
|
||||
*
|
||||
*/
|
||||
static inline __always_inline void
|
||||
IOAPI_INLINE ( arm, iodelay ) ( void ) {
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory barrier
|
||||
*
|
||||
@@ -140,4 +93,7 @@ IOAPI_INLINE ( arm, mb ) ( void ) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Dummy PIO */
|
||||
DUMMY_PIO ( arm );
|
||||
|
||||
#endif /* _IPXE_ARM_IO_H */
|
||||
|
||||
@@ -36,19 +36,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
* Multiply big integers
|
||||
*
|
||||
* @v multiplicand0 Element 0 of big integer to be multiplied
|
||||
* @v multiplicand_size Number of elements in multiplicand
|
||||
* @v multiplier0 Element 0 of big integer to be multiplied
|
||||
* @v multiplier_size Number of elements in multiplier
|
||||
* @v result0 Element 0 of big integer to hold result
|
||||
* @v size Number of elements
|
||||
*/
|
||||
void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint32_t *multiplier0,
|
||||
uint32_t *result0, unsigned int size ) {
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand =
|
||||
( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier =
|
||||
( ( const void * ) multiplier0 );
|
||||
bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result =
|
||||
( ( void * ) result0 );
|
||||
unsigned int multiplier_size,
|
||||
uint32_t *result0 ) {
|
||||
unsigned int result_size = ( multiplicand_size + multiplier_size );
|
||||
const bigint_t ( multiplicand_size ) __attribute__ (( may_alias ))
|
||||
*multiplicand = ( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( multiplier_size ) __attribute__ (( may_alias ))
|
||||
*multiplier = ( ( const void * ) multiplier0 );
|
||||
bigint_t ( result_size ) __attribute__ (( may_alias ))
|
||||
*result = ( ( void * ) result0 );
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
uint32_t multiplicand_element;
|
||||
@@ -62,9 +66,9 @@ void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
memset ( result, 0, sizeof ( *result ) );
|
||||
|
||||
/* Multiply integers one element at a time */
|
||||
for ( i = 0 ; i < size ; i++ ) {
|
||||
for ( i = 0 ; i < multiplicand_size ; i++ ) {
|
||||
multiplicand_element = multiplicand->element[i];
|
||||
for ( j = 0 ; j < size ; j++ ) {
|
||||
for ( j = 0 ; j < multiplier_size ; j++ ) {
|
||||
multiplier_element = multiplier->element[j];
|
||||
result_elements = &result->element[ i + j ];
|
||||
/* Perform a single multiply, and add the
|
||||
@@ -73,7 +77,7 @@ void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
* never overflow beyond the end of the
|
||||
* result, since:
|
||||
*
|
||||
* a < 2^{n}, b < 2^{n} => ab < 2^{2n}
|
||||
* a < 2^{n}, b < 2^{m} => ab < 2^{n+m}
|
||||
*/
|
||||
__asm__ __volatile__ ( "umull %1, %2, %5, %6\n\t"
|
||||
"ldr %3, [%0]\n\t"
|
||||
|
||||
@@ -310,7 +310,9 @@ bigint_done_raw ( const uint32_t *value0, unsigned int size __unused,
|
||||
}
|
||||
|
||||
extern void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint32_t *multiplier0,
|
||||
uint32_t *value0, unsigned int size );
|
||||
unsigned int multiplier_size,
|
||||
uint32_t *value0 );
|
||||
|
||||
#endif /* _BITS_BIGINT_H */
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.section ".note.GNU-stack", "", %progbits
|
||||
.text
|
||||
.thumb
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.section ".note.GNU-stack", "", %progbits
|
||||
.text
|
||||
.arm
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,19 +36,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
* Multiply big integers
|
||||
*
|
||||
* @v multiplicand0 Element 0 of big integer to be multiplied
|
||||
* @v multiplicand_size Number of elements in multiplicand
|
||||
* @v multiplier0 Element 0 of big integer to be multiplied
|
||||
* @v multiplier_size Number of elements in multiplier
|
||||
* @v result0 Element 0 of big integer to hold result
|
||||
* @v size Number of elements
|
||||
*/
|
||||
void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint64_t *multiplier0,
|
||||
uint64_t *result0, unsigned int size ) {
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand =
|
||||
( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier =
|
||||
( ( const void * ) multiplier0 );
|
||||
bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result =
|
||||
( ( void * ) result0 );
|
||||
unsigned int multiplier_size,
|
||||
uint64_t *result0 ) {
|
||||
unsigned int result_size = ( multiplicand_size + multiplier_size );
|
||||
const bigint_t ( multiplicand_size ) __attribute__ (( may_alias ))
|
||||
*multiplicand = ( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( multiplier_size ) __attribute__ (( may_alias ))
|
||||
*multiplier = ( ( const void * ) multiplier0 );
|
||||
bigint_t ( result_size ) __attribute__ (( may_alias ))
|
||||
*result = ( ( void * ) result0 );
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
uint64_t multiplicand_element;
|
||||
@@ -63,9 +67,9 @@ void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
memset ( result, 0, sizeof ( *result ) );
|
||||
|
||||
/* Multiply integers one element at a time */
|
||||
for ( i = 0 ; i < size ; i++ ) {
|
||||
for ( i = 0 ; i < multiplicand_size ; i++ ) {
|
||||
multiplicand_element = multiplicand->element[i];
|
||||
for ( j = 0 ; j < size ; j++ ) {
|
||||
for ( j = 0 ; j < multiplier_size ; j++ ) {
|
||||
multiplier_element = multiplier->element[j];
|
||||
result_elements = &result->element[ i + j ];
|
||||
/* Perform a single multiply, and add the
|
||||
@@ -74,7 +78,7 @@ void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
* never overflow beyond the end of the
|
||||
* result, since:
|
||||
*
|
||||
* a < 2^{n}, b < 2^{n} => ab < 2^{2n}
|
||||
* a < 2^{n}, b < 2^{m} => ab < 2^{n+m}
|
||||
*/
|
||||
__asm__ __volatile__ ( "mul %1, %6, %7\n\t"
|
||||
"umulh %2, %6, %7\n\t"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.section ".note.GNU-stack", "", %progbits
|
||||
.text
|
||||
|
||||
/* Must match jmp_buf structure layout */
|
||||
|
||||
@@ -311,7 +311,9 @@ bigint_done_raw ( const uint64_t *value0, unsigned int size __unused,
|
||||
}
|
||||
|
||||
extern void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint64_t *multiplier0,
|
||||
uint64_t *value0, unsigned int size );
|
||||
unsigned int multiplier_size,
|
||||
uint64_t *value0 );
|
||||
|
||||
#endif /* _BITS_BIGINT_H */
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* Interrupt handlers
|
||||
****************************************************************************
|
||||
*/
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.section ".text", "ax", @progbits
|
||||
.code32
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.text
|
||||
.arch i386
|
||||
.code32
|
||||
.arch i386
|
||||
|
||||
/* Must match jmp_buf structure layout */
|
||||
.struct 0
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code32
|
||||
.arch i386
|
||||
|
||||
.section ".data", "aw", @progbits
|
||||
|
||||
@@ -20,6 +20,7 @@ CFLAGS += -fshort-wchar
|
||||
|
||||
# LoongArch64-specific directories containing source files
|
||||
SRCDIRS += arch/loong64/core
|
||||
SRCDIRS += arch/loong64/interface/efi
|
||||
|
||||
# Include platform-specific Makefile
|
||||
MAKEDEPS += arch/loong64/Makefile.$(PLATFORM)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# -*- makefile -*- : Force emacs to use Makefile mode
|
||||
|
||||
# Specify EFI image builder
|
||||
#
|
||||
ELF2EFI = $(ELF2EFI64)
|
||||
|
||||
# Specify EFI boot file
|
||||
#
|
||||
EFI_BOOT_FILE = bootloongarch64.efi
|
||||
|
||||
# Include generic EFI Makefile
|
||||
#
|
||||
MAKEDEPS += Makefile.efi
|
||||
include Makefile.efi
|
||||
@@ -37,19 +37,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
* Multiply big integers
|
||||
*
|
||||
* @v multiplicand0 Element 0 of big integer to be multiplied
|
||||
* @v multiplicand_size Number of elements in multiplicand
|
||||
* @v multiplier0 Element 0 of big integer to be multiplied
|
||||
* @v multiplier_size Number of elements in multiplier
|
||||
* @v result0 Element 0 of big integer to hold result
|
||||
* @v size Number of elements
|
||||
*/
|
||||
void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint64_t *multiplier0,
|
||||
uint64_t *result0, unsigned int size ) {
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand =
|
||||
( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier =
|
||||
( ( const void * ) multiplier0 );
|
||||
bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result =
|
||||
( ( void * ) result0 );
|
||||
unsigned int multiplier_size,
|
||||
uint64_t *result0 ) {
|
||||
unsigned int result_size = ( multiplicand_size + multiplier_size );
|
||||
const bigint_t ( multiplicand_size ) __attribute__ (( may_alias ))
|
||||
*multiplicand = ( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( multiplier_size ) __attribute__ (( may_alias ))
|
||||
*multiplier = ( ( const void * ) multiplier0 );
|
||||
bigint_t ( result_size ) __attribute__ (( may_alias ))
|
||||
*result = ( ( void * ) result0 );
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
uint64_t multiplicand_element;
|
||||
@@ -64,9 +68,9 @@ void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
memset ( result, 0, sizeof ( *result ) );
|
||||
|
||||
/* Multiply integers one element at a time */
|
||||
for ( i = 0 ; i < size ; i++ ) {
|
||||
for ( i = 0 ; i < multiplicand_size ; i++ ) {
|
||||
multiplicand_element = multiplicand->element[i];
|
||||
for ( j = 0 ; j < size ; j++ ) {
|
||||
for ( j = 0 ; j < multiplier_size ; j++ ) {
|
||||
multiplier_element = multiplier->element[j];
|
||||
result_elements = &result->element[ i + j ];
|
||||
/* Perform a single multiply, and add the
|
||||
@@ -75,7 +79,7 @@ void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
* never overflow beyond the end of the
|
||||
* result, since:
|
||||
*
|
||||
* a < 2^{n}, b < 2^{n} => ab < 2^{2n}
|
||||
* a < 2^{n}, b < 2^{m} => ab < 2^{n+m}
|
||||
*/
|
||||
__asm__ __volatile__ ( "mul.d %1, %6, %7\n\t"
|
||||
"mulh.du %2, %6, %7\n\t"
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Xiaotian Wu <wuxiaotian@loongson.cn>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <ipxe/io.h>
|
||||
#include <ipxe/loong64_io.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* iPXE I/O API for LoongArch64
|
||||
*
|
||||
*/
|
||||
|
||||
PROVIDE_IOAPI_INLINE ( loong64, phys_to_bus );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, bus_to_phys );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, readb );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, readw );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, readl );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, readq );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, writeb );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, writew );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, writel );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, writeq );
|
||||
PROVIDE_IOAPI_INLINE ( loong64, mb );
|
||||
PROVIDE_DUMMY_PIO ( loong64 );
|
||||
@@ -53,34 +53,37 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0,
|
||||
uint64_t *discard_value;
|
||||
uint64_t discard_addend_i;
|
||||
uint64_t discard_value_i;
|
||||
uint64_t discard_carry;
|
||||
uint64_t discard_temp;
|
||||
unsigned int discard_size;
|
||||
__asm__ __volatile__ ( "move $t0, $zero\n"
|
||||
"1:\n\t"
|
||||
"ld.d %3, %0, 0\n\t"
|
||||
|
||||
__asm__ __volatile__ ( "\n1:\n\t"
|
||||
/* Load addend[i] and value[i] */
|
||||
"ld.d %3, %0, 0\n\t"
|
||||
"ld.d %4, %1, 0\n\t"
|
||||
/* Add carry flag and addend */
|
||||
"add.d %4, %4, %5\n\t"
|
||||
"sltu %6, %4, %5\n\t"
|
||||
"add.d %4, %4, %3\n\t"
|
||||
"sltu %5, %4, %3\n\t"
|
||||
"or %5, %5, %6\n\t"
|
||||
/* Store value[i] */
|
||||
"st.d %4, %1, 0\n\t"
|
||||
/* Loop */
|
||||
"addi.d %0, %0, 8\n\t"
|
||||
"ld.d %4, %1, 0\n\t"
|
||||
|
||||
"add.d %4, %4, $t0\n\t"
|
||||
"sltu $t0, %4, $t0\n\t"
|
||||
|
||||
"add.d %4, %4, %3\n\t"
|
||||
"sltu $t1, %4, %3\n\t"
|
||||
|
||||
"or $t0, $t0, $t1\n\t"
|
||||
"st.d %4, %1, 0\n\t"
|
||||
"addi.d %1, %1, 8\n\t"
|
||||
"addi.w %2, %2, -1\n\t"
|
||||
"bnez %2, 1b"
|
||||
"bnez %2, 1b\n\t"
|
||||
: "=r" ( discard_addend ),
|
||||
"=r" ( discard_value ),
|
||||
"=r" ( discard_size ),
|
||||
"=r" ( discard_addend_i ),
|
||||
"=r" ( discard_value_i ),
|
||||
"=r" ( discard_carry ),
|
||||
"=r" ( discard_temp ),
|
||||
"+m" ( *value )
|
||||
: "0" ( addend0 ),
|
||||
"1" ( value0 ),
|
||||
"2" ( size )
|
||||
: "t0", "t1" );
|
||||
: "0" ( addend0 ), "1" ( value0 ),
|
||||
"2" ( size ), "5" ( 0 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,35 +96,43 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0,
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0,
|
||||
unsigned int size ) {
|
||||
bigint_t ( size ) __attribute__ (( may_alias )) *value =
|
||||
( ( void * ) value0 );
|
||||
uint64_t *discard_subtrahend;
|
||||
uint64_t *discard_value;
|
||||
uint64_t discard_subtrahend_i;
|
||||
uint64_t discard_value_i;
|
||||
uint64_t discard_carry;
|
||||
uint64_t discard_temp;
|
||||
unsigned int discard_size;
|
||||
unsigned int flag = 0;
|
||||
|
||||
discard_subtrahend = (uint64_t*) subtrahend0;
|
||||
discard_value = value0;
|
||||
discard_size = size;
|
||||
|
||||
do {
|
||||
discard_subtrahend_i = *discard_subtrahend;
|
||||
discard_subtrahend++;
|
||||
discard_value_i = *discard_value;
|
||||
|
||||
discard_value_i = discard_value_i - discard_subtrahend_i - flag;
|
||||
|
||||
if ( *discard_value < (discard_subtrahend_i + flag)) {
|
||||
flag = 1;
|
||||
} else {
|
||||
flag = 0;
|
||||
}
|
||||
|
||||
*discard_value = discard_value_i;
|
||||
|
||||
discard_value++;
|
||||
discard_size -= 1;
|
||||
} while (discard_size != 0);
|
||||
__asm__ __volatile__ ( "\n1:\n\t"
|
||||
/* Load subtrahend[i] and value[i] */
|
||||
"ld.d %3, %0, 0\n\t"
|
||||
"ld.d %4, %1, 0\n\t"
|
||||
/* Subtract carry flag and subtrahend */
|
||||
"sltu %6, %4, %5\n\t"
|
||||
"sub.d %4, %4, %5\n\t"
|
||||
"sltu %5, %4, %3\n\t"
|
||||
"sub.d %4, %4, %3\n\t"
|
||||
"or %5, %5, %6\n\t"
|
||||
/* Store value[i] */
|
||||
"st.d %4, %1, 0\n\t"
|
||||
/* Loop */
|
||||
"addi.d %0, %0, 8\n\t"
|
||||
"addi.d %1, %1, 8\n\t"
|
||||
"addi.w %2, %2, -1\n\t"
|
||||
"bnez %2, 1b\n\t"
|
||||
: "=r" ( discard_subtrahend ),
|
||||
"=r" ( discard_value ),
|
||||
"=r" ( discard_size ),
|
||||
"=r" ( discard_subtrahend_i ),
|
||||
"=r" ( discard_value_i ),
|
||||
"=r" ( discard_carry ),
|
||||
"=r" ( discard_temp ),
|
||||
"+m" ( *value )
|
||||
: "0" ( subtrahend0 ), "1" ( value0 ),
|
||||
"2" ( size ), "5" ( 0 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,30 +143,37 @@ bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0,
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
bigint_rol_raw ( uint64_t *value0, unsigned int size ) {
|
||||
bigint_t ( size ) __attribute__ (( may_alias )) *value =
|
||||
( ( void * ) value0 );
|
||||
uint64_t *discard_value;
|
||||
uint64_t discard_value_i;
|
||||
uint64_t discard_carry;
|
||||
uint64_t discard_temp;
|
||||
unsigned int discard_size;
|
||||
uint64_t current_value_i;
|
||||
unsigned int flag = 0;
|
||||
|
||||
discard_value = value0;
|
||||
discard_size = size;
|
||||
do {
|
||||
discard_value_i = *discard_value;
|
||||
current_value_i = discard_value_i;
|
||||
|
||||
discard_value_i += discard_value_i + flag;
|
||||
|
||||
if (discard_value_i < current_value_i) {
|
||||
flag = 1;
|
||||
} else {
|
||||
flag = 0;
|
||||
}
|
||||
|
||||
*discard_value = discard_value_i;
|
||||
discard_value++;
|
||||
discard_size -= 1;
|
||||
} while ( discard_size != 0 );
|
||||
__asm__ __volatile__ ( "\n1:\n\t"
|
||||
/* Load value[i] */
|
||||
"ld.d %2, %0, 0\n\t"
|
||||
/* Shift left */
|
||||
"rotri.d %2, %2, 63\n\t"
|
||||
"andi %4, %2, 1\n\t"
|
||||
"xor %2, %2, %4\n\t"
|
||||
"or %2, %2, %3\n\t"
|
||||
"move %3, %4\n\t"
|
||||
/* Store value[i] */
|
||||
"st.d %2, %0, 0\n\t"
|
||||
/* Loop */
|
||||
"addi.d %0, %0, 8\n\t"
|
||||
"addi.w %1, %1, -1\n\t"
|
||||
"bnez %1, 1b\n\t"
|
||||
: "=r" ( discard_value ),
|
||||
"=r" ( discard_size ),
|
||||
"=r" ( discard_value_i ),
|
||||
"=r" ( discard_carry ),
|
||||
"=r" ( discard_temp ),
|
||||
"+m" ( *value )
|
||||
: "0" ( value0 ), "1" ( size ), "3" ( 0 )
|
||||
: "cc" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,27 +184,37 @@ bigint_rol_raw ( uint64_t *value0, unsigned int size ) {
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
bigint_ror_raw ( uint64_t *value0, unsigned int size ) {
|
||||
bigint_t ( size ) __attribute__ (( may_alias )) *value =
|
||||
( ( void * ) value0 );
|
||||
uint64_t *discard_value;
|
||||
uint64_t discard_value_i;
|
||||
uint64_t discard_value_j;
|
||||
uint64_t discard_carry;
|
||||
uint64_t discard_temp;
|
||||
unsigned int discard_size;
|
||||
|
||||
discard_value = value0;
|
||||
discard_size = size;
|
||||
|
||||
discard_value_j = 0;
|
||||
|
||||
do {
|
||||
discard_size -= 1;
|
||||
|
||||
discard_value_i = *(discard_value + discard_size);
|
||||
|
||||
discard_value_j = (discard_value_j << 63) | (discard_value_i >> 1);
|
||||
|
||||
*(discard_value + discard_size) = discard_value_j;
|
||||
|
||||
discard_value_j = discard_value_i;
|
||||
} while ( discard_size > 0 );
|
||||
__asm__ __volatile__ ( "\n1:\n\t"
|
||||
/* Load value[i] */
|
||||
"ld.d %2, %0, -8\n\t"
|
||||
/* Shift right */
|
||||
"andi %4, %2, 1\n\t"
|
||||
"xor %2, %2, %4\n\t"
|
||||
"or %2, %2, %3\n\t"
|
||||
"move %3, %4\n\t"
|
||||
"rotri.d %2, %2, 1\n\t"
|
||||
/* Store value[i] */
|
||||
"st.d %2, %0, -8\n\t"
|
||||
/* Loop */
|
||||
"addi.d %0, %0, -8\n\t"
|
||||
"addi.w %1, %1, -1\n\t"
|
||||
"bnez %1, 1b\n\t"
|
||||
: "=r" ( discard_value ),
|
||||
"=r" ( discard_size ),
|
||||
"=r" ( discard_value_i ),
|
||||
"=r" ( discard_carry ),
|
||||
"=r" ( discard_temp ),
|
||||
"+m" ( *value )
|
||||
: "0" ( value0 + size ), "1" ( size ), "3" ( 0 )
|
||||
: "cc" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +358,9 @@ bigint_done_raw ( const uint64_t *value0, unsigned int size __unused,
|
||||
}
|
||||
|
||||
extern void bigint_multiply_raw ( const uint64_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint64_t *multiplier0,
|
||||
uint64_t *value0, unsigned int size );
|
||||
unsigned int multiplier_size,
|
||||
uint64_t *value0 );
|
||||
|
||||
#endif /* _BITS_BIGINT_H */
|
||||
|
||||
@@ -12,4 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
/** Page shift */
|
||||
#define PAGE_SHIFT 12
|
||||
|
||||
#include <ipxe/loong64_io.h>
|
||||
|
||||
#endif /* _BITS_IO_H */
|
||||
|
||||
@@ -9,4 +9,6 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#endif /* _BITS_MAP_H */
|
||||
#include <ipxe/efi/efiloong64_nap.h>
|
||||
|
||||
#endif /* _BITS_NAP_H */
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef _IPXE_EFILOONG64_NAP_H
|
||||
#define _IPXE_EFILOONG64_NAP_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* EFI CPU sleeping
|
||||
*
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#ifdef NAP_EFILOONG64
|
||||
#define NAP_PREFIX_efiloong64
|
||||
#else
|
||||
#define NAP_PREFIX_efiloong64 __efiloong64_
|
||||
#endif
|
||||
|
||||
#endif /* _IPXE_EFILOONG64_NAP_H */
|
||||
@@ -0,0 +1,82 @@
|
||||
#ifndef _IPXE_LOONG64_IO_H
|
||||
#define _IPXE_LOONG64_IO_H
|
||||
|
||||
/** @file
|
||||
*
|
||||
* iPXE I/O API for LoongArch64
|
||||
*
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#ifdef IOAPI_LOONG64
|
||||
#define IOAPI_PREFIX_loong64
|
||||
#else
|
||||
#define IOAPI_PREFIX_loong64 __loong64_
|
||||
#endif
|
||||
|
||||
#include <ipxe/dummy_pio.h>
|
||||
|
||||
/*
|
||||
* Memory space mappings
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Physical<->Bus address mappings
|
||||
*
|
||||
*/
|
||||
|
||||
static inline __always_inline unsigned long
|
||||
IOAPI_INLINE ( loong64, phys_to_bus ) ( unsigned long phys_addr ) {
|
||||
return phys_addr;
|
||||
}
|
||||
|
||||
static inline __always_inline unsigned long
|
||||
IOAPI_INLINE ( loong64, bus_to_phys ) ( unsigned long bus_addr ) {
|
||||
return bus_addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* MMIO reads and writes up to native word size
|
||||
*
|
||||
*/
|
||||
|
||||
#define LOONG64_READX( _suffix, _type, _insn_suffix ) \
|
||||
static inline __always_inline _type \
|
||||
IOAPI_INLINE ( loong64, read ## _suffix ) ( volatile _type *io_addr ) { \
|
||||
_type data; \
|
||||
__asm__ __volatile__ ( "ld." _insn_suffix " %0, %1" \
|
||||
: "=r" ( data ) : "m" ( *io_addr ) ); \
|
||||
return data; \
|
||||
}
|
||||
LOONG64_READX ( b, uint8_t, "bu");
|
||||
LOONG64_READX ( w, uint16_t, "hu");
|
||||
LOONG64_READX ( l, uint32_t, "wu");
|
||||
LOONG64_READX ( q, uint64_t, "d");
|
||||
|
||||
#define LOONG64_WRITEX( _suffix, _type, _insn_suffix ) \
|
||||
static inline __always_inline void \
|
||||
IOAPI_INLINE ( loong64, write ## _suffix ) ( _type data, \
|
||||
volatile _type *io_addr ) { \
|
||||
__asm__ __volatile__ ( "st." _insn_suffix " %0, %1" \
|
||||
: : "r" ( data ), "m" ( *io_addr ) ); \
|
||||
}
|
||||
LOONG64_WRITEX ( b, uint8_t, "b");
|
||||
LOONG64_WRITEX ( w, uint16_t, "h");
|
||||
LOONG64_WRITEX ( l, uint32_t, "w" );
|
||||
LOONG64_WRITEX ( q, uint64_t, "d");
|
||||
|
||||
/*
|
||||
* Memory barrier
|
||||
*
|
||||
*/
|
||||
static inline __always_inline void
|
||||
IOAPI_INLINE ( loong64, mb ) ( void ) {
|
||||
__asm__ __volatile__ ( "dbar 0" );
|
||||
}
|
||||
|
||||
/* Dummy PIO */
|
||||
DUMMY_PIO ( loong64 );
|
||||
|
||||
#endif /* _IPXE_LOONG64_IO_H */
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Xiaotian Wu <wuxiaotian@loongson.cn>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <ipxe/nap.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* iPXE CPU sleeping API for EFI
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sleep until next interrupt
|
||||
*
|
||||
*/
|
||||
static void efiloong64_cpu_nap ( void ) {
|
||||
/*
|
||||
* I can't find any EFI API that allows us to put the CPU to
|
||||
* sleep. The CpuSleep() function is defined in CpuLib.h, but
|
||||
* isn't part of any exposed protocol so we have no way to
|
||||
* call it.
|
||||
*
|
||||
* The EFI shell doesn't seem to bother sleeping the CPU; it
|
||||
* just sits there idly burning power.
|
||||
*
|
||||
*/
|
||||
__asm__ __volatile__ ( "idle 0" );
|
||||
}
|
||||
|
||||
PROVIDE_NAP ( efiloong64, cpu_nap, efiloong64_cpu_nap );
|
||||
@@ -13,6 +13,13 @@ LDSCRIPT_PREFIX = arch/x86/scripts/prefixonly.lds
|
||||
#
|
||||
LDFLAGS += -N --no-check-sections
|
||||
|
||||
# Do not warn about RWX segments (required by most prefixes)
|
||||
#
|
||||
WRWX_TEST = $(LD) --warn-rwx-segments --version 2>&1 > /dev/null
|
||||
WRWX_FLAGS := $(shell [ -z "`$(WRWX_TEST)`" ] && \
|
||||
$(ECHO) '--no-warn-rwx-segments')
|
||||
LDFLAGS += $(WRWX_FLAGS)
|
||||
|
||||
# Media types.
|
||||
#
|
||||
MEDIA += rom
|
||||
@@ -54,9 +61,15 @@ LIST_NAME_mrom := ROMS
|
||||
LIST_NAME_pcirom := ROMS
|
||||
LIST_NAME_isarom := ROMS
|
||||
|
||||
# ISO or FAT filesystem images
|
||||
# ISO images
|
||||
NON_AUTO_MEDIA += iso
|
||||
$(BIN)/%.iso $(BIN)/%.sdsk: $(BIN)/%.lkrn util/genfsimg
|
||||
$(BIN)/%.iso : $(BIN)/%.lkrn util/genfsimg
|
||||
$(QM)$(ECHO) " [GENFSIMG] $@"
|
||||
$(Q)util/genfsimg -o $@ $<
|
||||
|
||||
# FAT filesystem images (via syslinux)
|
||||
NON_AUTO_MEDIA += sdsk
|
||||
$(BIN)/%.sdsk : $(BIN)/%.lkrn util/genfsimg
|
||||
$(QM)$(ECHO) " [GENFSIMG] $@"
|
||||
$(Q)util/genfsimg -o $@ $<
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
/****************************************************************************
|
||||
* Set/clear CF on the stack as appropriate, assumes stack is as it should
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define STACK_SIZE 8192
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
|
||||
/****************************************************************************
|
||||
* Internal stack
|
||||
|
||||
@@ -36,19 +36,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
* Multiply big integers
|
||||
*
|
||||
* @v multiplicand0 Element 0 of big integer to be multiplied
|
||||
* @v multiplicand_size Number of elements in multiplicand
|
||||
* @v multiplier0 Element 0 of big integer to be multiplied
|
||||
* @v multiplier_size Number of elements in multiplier
|
||||
* @v result0 Element 0 of big integer to hold result
|
||||
* @v size Number of elements
|
||||
*/
|
||||
void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint32_t *multiplier0,
|
||||
uint32_t *result0, unsigned int size ) {
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand =
|
||||
( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier =
|
||||
( ( const void * ) multiplier0 );
|
||||
bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result =
|
||||
( ( void * ) result0 );
|
||||
unsigned int multiplier_size,
|
||||
uint32_t *result0 ) {
|
||||
unsigned int result_size = ( multiplicand_size + multiplier_size );
|
||||
const bigint_t ( multiplicand_size ) __attribute__ (( may_alias ))
|
||||
*multiplicand = ( ( const void * ) multiplicand0 );
|
||||
const bigint_t ( multiplier_size ) __attribute__ (( may_alias ))
|
||||
*multiplier = ( ( const void * ) multiplier0 );
|
||||
bigint_t ( result_size ) __attribute__ (( may_alias ))
|
||||
*result = ( ( void * ) result0 );
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
uint32_t multiplicand_element;
|
||||
@@ -62,9 +66,9 @@ void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
memset ( result, 0, sizeof ( *result ) );
|
||||
|
||||
/* Multiply integers one element at a time */
|
||||
for ( i = 0 ; i < size ; i++ ) {
|
||||
for ( i = 0 ; i < multiplicand_size ; i++ ) {
|
||||
multiplicand_element = multiplicand->element[i];
|
||||
for ( j = 0 ; j < size ; j++ ) {
|
||||
for ( j = 0 ; j < multiplier_size ; j++ ) {
|
||||
multiplier_element = multiplier->element[j];
|
||||
result_elements = &result->element[ i + j ];
|
||||
/* Perform a single multiply, and add the
|
||||
@@ -73,7 +77,7 @@ void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
* never overflow beyond the end of the
|
||||
* result, since:
|
||||
*
|
||||
* a < 2^{n}, b < 2^{n} => ab < 2^{2n}
|
||||
* a < 2^{n}, b < 2^{m} => ab < 2^{n+m}
|
||||
*/
|
||||
__asm__ __volatile__ ( "mull %5\n\t"
|
||||
"addl %%eax, (%6,%2,4)\n\t"
|
||||
|
||||
@@ -10,9 +10,9 @@ FILE_LICENCE ( GPL2_OR_LATER )
|
||||
#define PIC1_ICR 0x20
|
||||
#define PIC2_ICR 0xa0
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
.section ".text16", "ax", @progbits
|
||||
.globl undiisr
|
||||
|
||||
@@ -323,7 +323,9 @@ bigint_done_raw ( const uint32_t *value0, unsigned int size __unused,
|
||||
}
|
||||
|
||||
extern void bigint_multiply_raw ( const uint32_t *multiplicand0,
|
||||
unsigned int multiplicand_size,
|
||||
const uint32_t *multiplier0,
|
||||
uint32_t *value0, unsigned int size );
|
||||
unsigned int multiplier_size,
|
||||
uint32_t *value0 );
|
||||
|
||||
#endif /* _BITS_BIGINT_H */
|
||||
|
||||
@@ -250,8 +250,10 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
|
||||
/* CODE_DEFAULT: restore default .code32/.code64 directive */
|
||||
#ifdef __x86_64__
|
||||
#define CODE_DEFAULT ".code64"
|
||||
#define STACK_DEFAULT "q"
|
||||
#else
|
||||
#define CODE_DEFAULT ".code32"
|
||||
#define STACK_DEFAULT "l"
|
||||
#endif
|
||||
|
||||
/* LINE_SYMBOL: declare a symbol for the current source code line */
|
||||
@@ -268,7 +270,7 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
|
||||
|
||||
/* REAL_CODE: declare a fragment of code that executes in real mode */
|
||||
#define REAL_CODE( asm_code_str ) \
|
||||
"push $1f\n\t" \
|
||||
"push" STACK_DEFAULT " $1f\n\t" \
|
||||
"call real_call\n\t" \
|
||||
TEXT16_CODE ( "\n1:\n\t" \
|
||||
asm_code_str \
|
||||
@@ -277,7 +279,7 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
|
||||
|
||||
/* PHYS_CODE: declare a fragment of code that executes in flat physical mode */
|
||||
#define PHYS_CODE( asm_code_str ) \
|
||||
"push $1f\n\t" \
|
||||
"push" STACK_DEFAULT " $1f\n\t" \
|
||||
"call phys_call\n\t" \
|
||||
".section \".text.phys\", \"ax\", @progbits\n\t"\
|
||||
"\n" LINE_SYMBOL "\n\t" \
|
||||
|
||||
@@ -290,29 +290,38 @@ static const char *bios_ansi_input = "";
|
||||
struct bios_key {
|
||||
/** Scancode */
|
||||
uint8_t scancode;
|
||||
/** Key code */
|
||||
uint16_t key;
|
||||
/** Relative key value */
|
||||
uint16_t rkey;
|
||||
} __attribute__ (( packed ));
|
||||
|
||||
/**
|
||||
* Define a BIOS key mapping
|
||||
*
|
||||
* @v scancode Scancode
|
||||
* @v key iPXE key code
|
||||
* @v bioskey BIOS key mapping
|
||||
*/
|
||||
#define BIOS_KEY( scancode, key ) { scancode, KEY_REL ( key ) }
|
||||
|
||||
/** Mapping from BIOS scan codes to iPXE key codes */
|
||||
static const struct bios_key bios_keys[] = {
|
||||
{ 0x53, KEY_DC },
|
||||
{ 0x48, KEY_UP },
|
||||
{ 0x50, KEY_DOWN },
|
||||
{ 0x4b, KEY_LEFT },
|
||||
{ 0x4d, KEY_RIGHT },
|
||||
{ 0x47, KEY_HOME },
|
||||
{ 0x4f, KEY_END },
|
||||
{ 0x49, KEY_PPAGE },
|
||||
{ 0x51, KEY_NPAGE },
|
||||
{ 0x3f, KEY_F5 },
|
||||
{ 0x40, KEY_F6 },
|
||||
{ 0x41, KEY_F7 },
|
||||
{ 0x42, KEY_F8 },
|
||||
{ 0x43, KEY_F9 },
|
||||
{ 0x44, KEY_F10 },
|
||||
{ 0x85, KEY_F11 },
|
||||
{ 0x86, KEY_F12 },
|
||||
BIOS_KEY ( 0x53, KEY_DC ),
|
||||
BIOS_KEY ( 0x48, KEY_UP ),
|
||||
BIOS_KEY ( 0x50, KEY_DOWN ),
|
||||
BIOS_KEY ( 0x4b, KEY_LEFT ),
|
||||
BIOS_KEY ( 0x4d, KEY_RIGHT ),
|
||||
BIOS_KEY ( 0x47, KEY_HOME ),
|
||||
BIOS_KEY ( 0x4f, KEY_END ),
|
||||
BIOS_KEY ( 0x49, KEY_PPAGE ),
|
||||
BIOS_KEY ( 0x51, KEY_NPAGE ),
|
||||
BIOS_KEY ( 0x3f, KEY_F5 ),
|
||||
BIOS_KEY ( 0x40, KEY_F6 ),
|
||||
BIOS_KEY ( 0x41, KEY_F7 ),
|
||||
BIOS_KEY ( 0x42, KEY_F8 ),
|
||||
BIOS_KEY ( 0x43, KEY_F9 ),
|
||||
BIOS_KEY ( 0x44, KEY_F10 ),
|
||||
BIOS_KEY ( 0x85, KEY_F11 ),
|
||||
BIOS_KEY ( 0x86, KEY_F12 ),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -323,7 +332,7 @@ static const struct bios_key bios_keys[] = {
|
||||
*/
|
||||
static const char * bios_ansi_seq ( unsigned int scancode ) {
|
||||
static char buf[ 5 /* "[" + two digits + terminator + NUL */ ];
|
||||
unsigned int key;
|
||||
unsigned int rkey;
|
||||
unsigned int terminator;
|
||||
unsigned int n;
|
||||
unsigned int i;
|
||||
@@ -338,9 +347,9 @@ static const char * bios_ansi_seq ( unsigned int scancode ) {
|
||||
continue;
|
||||
|
||||
/* Construct escape sequence */
|
||||
key = bios_keys[i].key;
|
||||
n = KEY_ANSI_N ( key );
|
||||
terminator = KEY_ANSI_TERMINATOR ( key );
|
||||
rkey = bios_keys[i].rkey;
|
||||
n = KEY_ANSI_N ( rkey );
|
||||
terminator = KEY_ANSI_TERMINATOR ( rkey );
|
||||
*(tmp++) = '[';
|
||||
if ( n )
|
||||
tmp += sprintf ( tmp, "%d", n );
|
||||
@@ -479,6 +488,7 @@ struct console_driver bios_console __console_driver = {
|
||||
static __asmcall __used void bios_inject ( struct i386_all_regs *ix86 ) {
|
||||
unsigned int discard_a;
|
||||
unsigned int scancode;
|
||||
unsigned int rkey;
|
||||
unsigned int i;
|
||||
uint16_t keypress;
|
||||
int key;
|
||||
@@ -521,9 +531,10 @@ static __asmcall __used void bios_inject ( struct i386_all_regs *ix86 ) {
|
||||
|
||||
/* Handle special keys */
|
||||
if ( key >= KEY_MIN ) {
|
||||
rkey = KEY_REL ( key );
|
||||
for ( i = 0 ; i < ( sizeof ( bios_keys ) /
|
||||
sizeof ( bios_keys[0] ) ) ; i++ ) {
|
||||
if ( bios_keys[i].key == key ) {
|
||||
if ( bios_keys[i].rkey == rkey ) {
|
||||
scancode = bios_keys[i].scancode;
|
||||
keypress = ( scancode << 8 );
|
||||
break;
|
||||
|
||||
@@ -44,11 +44,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
* @v smbios SMBIOS entry point descriptor structure to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int bios_find_smbios ( struct smbios *smbios ) {
|
||||
static int bios_find_smbios2 ( struct smbios *smbios ) {
|
||||
struct smbios_entry entry;
|
||||
int rc;
|
||||
|
||||
/* Scan through BIOS segment to find SMBIOS entry point */
|
||||
/* Scan through BIOS segment to find SMBIOS 32-bit entry point */
|
||||
if ( ( rc = find_smbios_entry ( real_to_user ( BIOS_SEG, 0 ), 0x10000,
|
||||
&entry ) ) != 0 )
|
||||
return rc;
|
||||
@@ -62,4 +62,55 @@ static int bios_find_smbios ( struct smbios *smbios ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find SMBIOS
|
||||
*
|
||||
* @v smbios SMBIOS entry point descriptor structure to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int bios_find_smbios3 ( struct smbios *smbios ) {
|
||||
struct smbios3_entry entry;
|
||||
int rc;
|
||||
|
||||
/* Scan through BIOS segment to find SMBIOS 64-bit entry point */
|
||||
if ( ( rc = find_smbios3_entry ( real_to_user ( BIOS_SEG, 0 ), 0x10000,
|
||||
&entry ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Check that address is accessible */
|
||||
if ( entry.smbios_address > ~( ( physaddr_t ) 0 ) ) {
|
||||
DBG ( "SMBIOS3 at %08llx is inaccessible\n",
|
||||
( ( unsigned long long ) entry.smbios_address ) );
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/* Fill in entry point descriptor structure */
|
||||
smbios->address = phys_to_user ( entry.smbios_address );
|
||||
smbios->len = entry.smbios_len;
|
||||
smbios->count = 0;
|
||||
smbios->version = SMBIOS_VERSION ( entry.major, entry.minor );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find SMBIOS
|
||||
*
|
||||
* @v smbios SMBIOS entry point descriptor structure to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int bios_find_smbios ( struct smbios *smbios ) {
|
||||
int rc;
|
||||
|
||||
/* Use 32-bit table if present */
|
||||
if ( ( rc = bios_find_smbios2 ( smbios ) ) == 0 )
|
||||
return 0;
|
||||
|
||||
/* Otherwise, use 64-bit table if present and accessible */
|
||||
if ( ( rc = bios_find_smbios3 ( smbios ) ) == 0 )
|
||||
return 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
PROVIDE_SMBIOS ( pcbios, find_smbios, bios_find_smbios );
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
#define SMAP 0x534d4150
|
||||
|
||||
|
||||
@@ -165,24 +165,27 @@ static void pcicloud_init ( void ) {
|
||||
static struct pci_api *apis[] = {
|
||||
&ecam_api, &pcibios_api, &pcidirect_api
|
||||
};
|
||||
struct pci_range range;
|
||||
struct pci_device pci;
|
||||
uint32_t busdevfn;
|
||||
unsigned int i;
|
||||
int rc;
|
||||
|
||||
/* Select first API that successfully discovers an address range */
|
||||
/* Select first API that successfully discovers a PCI device */
|
||||
for ( i = 0 ; i < ( sizeof ( apis ) / sizeof ( apis[0] ) ) ; i++ ) {
|
||||
pcicloud = apis[i];
|
||||
pcicloud_discover ( 0, &range );
|
||||
if ( range.count != 0 ) {
|
||||
DBGC ( pcicloud, "PCICLOUD selected %s API\n",
|
||||
pcicloud->name );
|
||||
break;
|
||||
busdevfn = 0;
|
||||
if ( ( rc = pci_find_next ( &pci, &busdevfn ) ) == 0 ) {
|
||||
DBGC ( pcicloud, "PCICLOUD selected %s API (found "
|
||||
PCI_FMT ")\n", pcicloud->name,
|
||||
PCI_ARGS ( &pci ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* The PCI direct API can never fail discovery since the range
|
||||
* is hardcoded.
|
||||
*/
|
||||
assert ( range.count != 0 );
|
||||
/* Fall back to using final attempted API if no devices found */
|
||||
pcicloud = apis[ i - 1 ];
|
||||
DBGC ( pcicloud, "PCICLOUD selected %s API (nothing detected)\n",
|
||||
pcicloud->name );
|
||||
}
|
||||
|
||||
/** Cloud VM PCI configuration space access initialisation function */
|
||||
|
||||
@@ -375,9 +375,10 @@ int pxe_start_nbp ( void ) {
|
||||
* Notify BIOS of existence of network device
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v priv Private data
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int pxe_notify ( struct net_device *netdev ) {
|
||||
static int pxe_notify ( struct net_device *netdev, void *priv __unused ) {
|
||||
|
||||
/* Do nothing if we already have a network device */
|
||||
if ( pxe_netdev )
|
||||
|
||||
@@ -26,6 +26,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER )
|
||||
|
||||
#include "librm.h"
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.text
|
||||
|
||||
.code32
|
||||
|
||||
@@ -207,65 +207,35 @@ struct init_fn guestinfo_init_fn __init_fn ( INIT_NORMAL ) = {
|
||||
* Create per-netdevice GuestInfo settings
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v priv Private data
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int guestinfo_net_probe ( struct net_device *netdev ) {
|
||||
struct settings *settings;
|
||||
static int guestinfo_net_probe ( struct net_device *netdev, void *priv ) {
|
||||
struct settings *settings = priv;
|
||||
int rc;
|
||||
|
||||
/* Do nothing unless we have a GuestInfo channel available */
|
||||
if ( guestinfo_channel < 0 )
|
||||
return 0;
|
||||
|
||||
/* Allocate and initialise settings block */
|
||||
settings = zalloc ( sizeof ( *settings ) );
|
||||
if ( ! settings ) {
|
||||
rc = -ENOMEM;
|
||||
goto err_alloc;
|
||||
}
|
||||
settings_init ( settings, &guestinfo_settings_operations, NULL, NULL );
|
||||
|
||||
/* Register settings */
|
||||
/* Initialise and register settings */
|
||||
settings_init ( settings, &guestinfo_settings_operations,
|
||||
&netdev->refcnt, NULL );
|
||||
if ( ( rc = register_settings ( settings, netdev_settings ( netdev ),
|
||||
"vmware" ) ) != 0 ) {
|
||||
DBGC ( settings, "GuestInfo %p could not register for %s: %s\n",
|
||||
settings, netdev->name, strerror ( rc ) );
|
||||
goto err_register;
|
||||
return rc;
|
||||
}
|
||||
DBGC ( settings, "GuestInfo %p registered for %s\n",
|
||||
settings, netdev->name );
|
||||
|
||||
return 0;
|
||||
|
||||
err_register:
|
||||
free ( settings );
|
||||
err_alloc:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove per-netdevice GuestInfo settings
|
||||
*
|
||||
* @v netdev Network device
|
||||
*/
|
||||
static void guestinfo_net_remove ( struct net_device *netdev ) {
|
||||
struct settings *parent = netdev_settings ( netdev );
|
||||
struct settings *settings;
|
||||
|
||||
list_for_each_entry ( settings, &parent->children, siblings ) {
|
||||
if ( settings->op == &guestinfo_settings_operations ) {
|
||||
DBGC ( settings, "GuestInfo %p unregistered for %s\n",
|
||||
settings, netdev->name );
|
||||
unregister_settings ( settings );
|
||||
free ( settings );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** GuestInfo per-netdevice driver */
|
||||
struct net_driver guestinfo_net_driver __net_driver = {
|
||||
.name = "GuestInfo",
|
||||
.priv_len = sizeof ( struct settings ),
|
||||
.probe = guestinfo_net_probe,
|
||||
.remove = guestinfo_net_remove,
|
||||
};
|
||||
|
||||
@@ -5,10 +5,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
#define STACK_SEG 0x0200
|
||||
#define STACK_SIZE 0x2000
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "awx", @progbits
|
||||
.code16
|
||||
|
||||
/*
|
||||
* Find active partition
|
||||
|
||||
@@ -24,11 +24,11 @@ FILE_LICENCE ( GPL2_ONLY )
|
||||
|
||||
.equ SYSSEG, 0x1000 /* system loaded at SYSSEG<<4 */
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.org 0
|
||||
.arch i386
|
||||
.text
|
||||
.section ".prefix", "ax", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "ax", @progbits
|
||||
.globl _dsk_start
|
||||
_dsk_start:
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
#define PSP_CMDLINE_LEN 0x80
|
||||
#define PSP_CMDLINE_START 0x81
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.org 0
|
||||
.code16
|
||||
.section ".prefix", "awx", @progbits
|
||||
|
||||
signature:
|
||||
|
||||
@@ -2,10 +2,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "awx", @progbits
|
||||
.code16
|
||||
.org 0
|
||||
.globl _hd_start
|
||||
_hd_start:
|
||||
|
||||
@@ -26,6 +26,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
/* Image compression enabled */
|
||||
|
||||
@@ -4,9 +4,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#define BZI_LOAD_HIGH_ADDR 0x100000
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "ax", @progbits
|
||||
.globl _lkrn_start
|
||||
_lkrn_start:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "awx", @progbits
|
||||
.code16
|
||||
.org 0
|
||||
|
||||
.globl mbr
|
||||
|
||||
@@ -41,9 +41,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
#define _pcirom_start _mrom_start
|
||||
#include "pciromprefix.S"
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
/* Obtain access to payload by exposing the expansion ROM BAR at the
|
||||
* address currently used by a suitably large memory BAR on the same
|
||||
|
||||
@@ -2,9 +2,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
.text
|
||||
.arch i386
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "ax", @progbits
|
||||
.org 0
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.org 0
|
||||
.text
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
.section ".prefix", "ax", @progbits
|
||||
.code16
|
||||
_prefix:
|
||||
|
||||
.section ".text16", "ax", @progbits
|
||||
|
||||
@@ -11,10 +11,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#define PXE_HACK_EB54 0x0001
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.org 0
|
||||
.code16
|
||||
|
||||
#include <librm.h>
|
||||
#include <undi.h>
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.org 0
|
||||
.code16
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
#define BUSTYPE "PCIR"
|
||||
#endif
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "ax", @progbits
|
||||
|
||||
@@ -2,7 +2,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#include <librm.h>
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "ax", @progbits
|
||||
|
||||
@@ -43,7 +43,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code32
|
||||
.arch i486
|
||||
.section ".prefix.lib", "ax", @progbits
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
#include <config/console.h>
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".prefix", "awx", @progbits
|
||||
.code16
|
||||
.org 0
|
||||
|
||||
#include "mbr.S"
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -31,10 +31,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
/* Breakpoint for when debugging under bochs */
|
||||
#define BOCHSBP xchgw %bx, %bx
|
||||
|
||||
.text
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.code16
|
||||
.arch i386
|
||||
.section ".text16", "awx", @progbits
|
||||
.code16
|
||||
|
||||
/****************************************************************************
|
||||
* init_libkir (real-mode or 16:xx protected-mode far call)
|
||||
|
||||
@@ -83,6 +83,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
#define if64 if 0
|
||||
#endif
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
|
||||
/****************************************************************************
|
||||
* Global descriptor table
|
||||
*
|
||||
|
||||
@@ -38,6 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#define SIGFPE 8
|
||||
#define SIGSTKFLT 16
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.section ".text.gdbmach_interrupt", "ax", @progbits
|
||||
.code64
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
|
||||
|
||||
.section ".note.GNU-stack", "", @progbits
|
||||
.text
|
||||
.code64
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
|
||||
@@ -83,6 +83,11 @@ REQUIRE_OBJECT ( oid_sha512_224 );
|
||||
REQUIRE_OBJECT ( oid_sha512_256 );
|
||||
#endif
|
||||
|
||||
/* X25519 */
|
||||
#if defined ( CRYPTO_CURVE_X25519 )
|
||||
REQUIRE_OBJECT ( oid_x25519 );
|
||||
#endif
|
||||
|
||||
/* RSA and MD5 */
|
||||
#if defined ( CRYPTO_PUBKEY_RSA ) && defined ( CRYPTO_DIGEST_MD5 )
|
||||
REQUIRE_OBJECT ( rsa_md5 );
|
||||
@@ -114,25 +119,79 @@ REQUIRE_OBJECT ( rsa_sha512 );
|
||||
#endif
|
||||
|
||||
/* RSA, AES-CBC, and SHA-1 */
|
||||
#if defined ( CRYPTO_PUBKEY_RSA ) && defined ( CRYPTO_CIPHER_AES_CBC ) && \
|
||||
defined ( CRYPTO_DIGEST_SHA1 )
|
||||
#if defined ( CRYPTO_EXCHANGE_PUBKEY ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_CBC ) && defined ( CRYPTO_DIGEST_SHA1 )
|
||||
REQUIRE_OBJECT ( rsa_aes_cbc_sha1 );
|
||||
#endif
|
||||
|
||||
/* RSA, AES-CBC, and SHA-256 */
|
||||
#if defined ( CRYPTO_PUBKEY_RSA ) && defined ( CRYPTO_CIPHER_AES_CBC ) && \
|
||||
defined ( CRYPTO_DIGEST_SHA256 )
|
||||
#if defined ( CRYPTO_EXCHANGE_PUBKEY ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_CBC ) && defined ( CRYPTO_DIGEST_SHA256 )
|
||||
REQUIRE_OBJECT ( rsa_aes_cbc_sha256 );
|
||||
#endif
|
||||
|
||||
/* RSA, AES-GCM, and SHA-256 */
|
||||
#if defined ( CRYPTO_PUBKEY_RSA ) && defined ( CRYPTO_CIPHER_AES_GCM ) && \
|
||||
defined ( CRYPTO_DIGEST_SHA256 )
|
||||
#if defined ( CRYPTO_EXCHANGE_PUBKEY ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_GCM ) && defined ( CRYPTO_DIGEST_SHA256 )
|
||||
REQUIRE_OBJECT ( rsa_aes_gcm_sha256 );
|
||||
#endif
|
||||
|
||||
/* RSA, AES-GCM, and SHA-384 */
|
||||
#if defined ( CRYPTO_PUBKEY_RSA ) && defined ( CRYPTO_CIPHER_AES_GCM ) && \
|
||||
defined ( CRYPTO_DIGEST_SHA384 )
|
||||
#if defined ( CRYPTO_EXCHANGE_PUBKEY ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_GCM ) && defined ( CRYPTO_DIGEST_SHA384 )
|
||||
REQUIRE_OBJECT ( rsa_aes_gcm_sha384 );
|
||||
#endif
|
||||
|
||||
/* DHE, RSA, AES-CBC, and SHA-1 */
|
||||
#if defined ( CRYPTO_EXCHANGE_DHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_CBC ) && defined ( CRYPTO_DIGEST_SHA1 )
|
||||
REQUIRE_OBJECT ( dhe_rsa_aes_cbc_sha1 );
|
||||
#endif
|
||||
|
||||
/* DHE, RSA, AES-CBC, and SHA-256 */
|
||||
#if defined ( CRYPTO_EXCHANGE_DHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_CBC ) && defined ( CRYPTO_DIGEST_SHA256 )
|
||||
REQUIRE_OBJECT ( dhe_rsa_aes_cbc_sha256 );
|
||||
#endif
|
||||
|
||||
/* DHE, RSA, AES-GCM, and SHA-256 */
|
||||
#if defined ( CRYPTO_EXCHANGE_DHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_GCM ) && defined ( CRYPTO_DIGEST_SHA256 )
|
||||
REQUIRE_OBJECT ( dhe_rsa_aes_gcm_sha256 );
|
||||
#endif
|
||||
|
||||
/* DHE, RSA, AES-GCM, and SHA-384 */
|
||||
#if defined ( CRYPTO_EXCHANGE_DHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_GCM ) && defined ( CRYPTO_DIGEST_SHA384 )
|
||||
REQUIRE_OBJECT ( dhe_rsa_aes_gcm_sha384 );
|
||||
#endif
|
||||
|
||||
/* ECDHE, RSA, AES-CBC, and SHA-1 */
|
||||
#if defined ( CRYPTO_EXCHANGE_ECDHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_CBC ) && defined ( CRYPTO_DIGEST_SHA1 )
|
||||
REQUIRE_OBJECT ( ecdhe_rsa_aes_cbc_sha1 );
|
||||
#endif
|
||||
|
||||
/* ECDHE, RSA, AES-CBC, and SHA-256 */
|
||||
#if defined ( CRYPTO_EXCHANGE_ECDHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_CBC ) && defined ( CRYPTO_DIGEST_SHA256 )
|
||||
REQUIRE_OBJECT ( ecdhe_rsa_aes_cbc_sha256 );
|
||||
#endif
|
||||
|
||||
/* ECDHE, RSA, AES-CBC, and SHA-384 */
|
||||
#if defined ( CRYPTO_EXCHANGE_ECDHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_CBC ) && defined ( CRYPTO_DIGEST_SHA384 )
|
||||
REQUIRE_OBJECT ( ecdhe_rsa_aes_cbc_sha384 );
|
||||
#endif
|
||||
|
||||
/* ECDHE, RSA, AES-GCM, and SHA-256 */
|
||||
#if defined ( CRYPTO_EXCHANGE_ECDHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_GCM ) && defined ( CRYPTO_DIGEST_SHA256 )
|
||||
REQUIRE_OBJECT ( ecdhe_rsa_aes_gcm_sha256 );
|
||||
#endif
|
||||
|
||||
/* ECDHE, RSA, AES-GCM, and SHA-384 */
|
||||
#if defined ( CRYPTO_EXCHANGE_ECDHE ) && defined ( CRYPTO_PUBKEY_RSA ) && \
|
||||
defined ( CRYPTO_CIPHER_AES_GCM ) && defined ( CRYPTO_DIGEST_SHA384 )
|
||||
REQUIRE_OBJECT ( ecdhe_rsa_aes_gcm_sha384 );
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
/** Minimum TLS version */
|
||||
#define TLS_VERSION_MIN TLS_VERSION_TLS_1_1
|
||||
|
||||
/** Public-key exchange algorithm */
|
||||
#define CRYPTO_EXCHANGE_PUBKEY
|
||||
|
||||
/** DHE key exchange algorithm */
|
||||
#define CRYPTO_EXCHANGE_DHE
|
||||
|
||||
/** ECDHE key exchange algorithm */
|
||||
#define CRYPTO_EXCHANGE_ECDHE
|
||||
|
||||
/** RSA public-key algorithm */
|
||||
#define CRYPTO_PUBKEY_RSA
|
||||
|
||||
@@ -48,6 +57,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
/** SHA-512/256 digest algorithm */
|
||||
//#define CRYPTO_DIGEST_SHA512_256
|
||||
|
||||
/** X25519 elliptic curve */
|
||||
#define CRYPTO_CURVE_X25519
|
||||
|
||||
/** Margin of error (in seconds) allowed in signed timestamps
|
||||
*
|
||||
* We default to allowing a reasonable margin of error: 12 hours to
|
||||
|
||||
@@ -67,4 +67,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#define IMAGE_GZIP /* GZIP image support */
|
||||
#endif
|
||||
|
||||
#if defined ( __loongarch__ )
|
||||
#define IOAPI_LOONG64
|
||||
#define NAP_EFILOONG64
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_DEFAULTS_EFI_H */
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
|
||||
@@ -295,9 +295,10 @@ struct startup_fn cachedhcp_startup_fn __startup_fn ( STARTUP_LATE ) = {
|
||||
* Apply cached DHCPACK to network device, if applicable
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v priv Private data
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int cachedhcp_probe ( struct net_device *netdev ) {
|
||||
static int cachedhcp_probe ( struct net_device *netdev, void *priv __unused ) {
|
||||
|
||||
/* Apply cached DHCPACK to network device, if applicable */
|
||||
return cachedhcp_apply ( &cached_dhcpack, netdev );
|
||||
|
||||
@@ -285,6 +285,7 @@ void intf_shutdown ( struct interface *intf, int rc ) {
|
||||
intf_nullify ( intf );
|
||||
|
||||
/* Transfer destination to temporary interface */
|
||||
intf_temp_init ( &tmp, intf );
|
||||
tmp.dest = intf->dest;
|
||||
intf->dest = &null_intf;
|
||||
|
||||
|
||||
+14
-1
@@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <ipxe/netdevice.h>
|
||||
@@ -35,6 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <ipxe/settings.h>
|
||||
#include <ipxe/params.h>
|
||||
#include <ipxe/timer.h>
|
||||
#include <ipxe/keys.h>
|
||||
#include <ipxe/parseopt.h>
|
||||
#include <config/branding.h>
|
||||
|
||||
@@ -213,6 +215,7 @@ int parse_flag ( char *text __unused, int *flag ) {
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int parse_key ( char *text, unsigned int *key ) {
|
||||
int rc;
|
||||
|
||||
/* Interpret single characters as being a literal key character */
|
||||
if ( text[0] && ! text[1] ) {
|
||||
@@ -221,7 +224,17 @@ int parse_key ( char *text, unsigned int *key ) {
|
||||
}
|
||||
|
||||
/* Otherwise, interpret as an integer */
|
||||
return parse_integer ( text, key );
|
||||
if ( ( rc = parse_integer ( text, key ) ) < 0 )
|
||||
return rc;
|
||||
|
||||
/* For backwards compatibility with existing scripts, treat
|
||||
* integers between the ASCII range and special key range as
|
||||
* being relative special key values.
|
||||
*/
|
||||
if ( ( ! isascii ( *key ) ) && ( *key < KEY_MIN ) )
|
||||
*key += KEY_MIN;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+5
-3
@@ -6,8 +6,9 @@
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <ipxe/timer.h>
|
||||
#include <time.h>
|
||||
|
||||
static int32_t rnd_seed = 0;
|
||||
|
||||
@@ -30,8 +31,9 @@ void srandom ( unsigned int seed ) {
|
||||
long int random ( void ) {
|
||||
int32_t q;
|
||||
|
||||
if ( ! rnd_seed ) /* Initialize linear congruential generator */
|
||||
srandom ( currticks() );
|
||||
/* Initialize linear congruential generator */
|
||||
if ( ! rnd_seed )
|
||||
srandom ( time ( NULL ) );
|
||||
|
||||
/* simplified version of the LCG given in Bruce Schneier's
|
||||
"Applied Cryptography" */
|
||||
|
||||
+2
-1
@@ -60,7 +60,7 @@ static struct xfer_metadata dummy_metadata;
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int xfer_vredirect ( struct interface *intf, int type, va_list args ) {
|
||||
struct interface tmp = INTF_INIT ( null_intf_desc );
|
||||
struct interface tmp;
|
||||
struct interface *dest;
|
||||
xfer_vredirect_TYPE ( void * ) *op =
|
||||
intf_get_dest_op_no_passthru ( intf, xfer_vredirect, &dest );
|
||||
@@ -85,6 +85,7 @@ int xfer_vredirect ( struct interface *intf, int type, va_list args ) {
|
||||
* If redirection fails, then send intf_close() to the
|
||||
* parent interface.
|
||||
*/
|
||||
intf_temp_init ( &tmp, intf );
|
||||
intf_plug ( &tmp, dest );
|
||||
rc = xfer_vreopen ( dest, type, args );
|
||||
if ( rc == 0 ) {
|
||||
|
||||
@@ -50,6 +50,31 @@ static struct profiler bigint_mod_multiply_rescale_profiler __profiler =
|
||||
static struct profiler bigint_mod_multiply_subtract_profiler __profiler =
|
||||
{ .name = "bigint_mod_multiply.subtract" };
|
||||
|
||||
/**
|
||||
* Conditionally swap big integers (in constant time)
|
||||
*
|
||||
* @v first0 Element 0 of big integer to be conditionally swapped
|
||||
* @v second0 Element 0 of big integer to be conditionally swapped
|
||||
* @v size Number of elements in big integers
|
||||
* @v swap Swap first and second big integers
|
||||
*/
|
||||
void bigint_swap_raw ( bigint_element_t *first0, bigint_element_t *second0,
|
||||
unsigned int size, int swap ) {
|
||||
bigint_element_t mask;
|
||||
bigint_element_t xor;
|
||||
unsigned int i;
|
||||
|
||||
/* Construct mask */
|
||||
mask = ( ( bigint_element_t ) ( ! swap ) - 1 );
|
||||
|
||||
/* Conditionally swap elements */
|
||||
for ( i = 0 ; i < size ; i++ ) {
|
||||
xor = ( mask & ( first0[i] ^ second0[i] ) );
|
||||
first0[i] ^= xor;
|
||||
second0[i] ^= xor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform modular multiplication of big integers
|
||||
*
|
||||
|
||||
+4
-4
@@ -472,10 +472,10 @@ void gcm_setiv ( struct gcm_context *context, const void *iv, size_t ivlen ) {
|
||||
union gcm_block *check = ( ( void * ) context );
|
||||
|
||||
/* Sanity checks */
|
||||
linker_assert ( &context->hash == check, gcm_bad_layout );
|
||||
linker_assert ( &context->len == check + 1, gcm_bad_layout );
|
||||
linker_assert ( &context->ctr == check + 2, gcm_bad_layout );
|
||||
linker_assert ( &context->key == check + 3, gcm_bad_layout );
|
||||
build_assert ( &context->hash == check );
|
||||
build_assert ( &context->len == check + 1 );
|
||||
build_assert ( &context->ctr == check + 2 );
|
||||
build_assert ( &context->key == check + 3 );
|
||||
|
||||
/* Reset non-key state */
|
||||
memset ( context, 0, offsetof ( typeof ( *context ), key ) );
|
||||
|
||||
+5
-5
@@ -155,11 +155,11 @@ static void md4_digest ( struct md4_context *context ) {
|
||||
|
||||
/* Sanity checks */
|
||||
assert ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 );
|
||||
linker_assert ( &u.ddd.dd.digest.h[0] == a, md4_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[1] == b, md4_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[2] == c, md4_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[3] == d, md4_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.data.dword[0] == w, md4_bad_layout );
|
||||
build_assert ( &u.ddd.dd.digest.h[0] == a );
|
||||
build_assert ( &u.ddd.dd.digest.h[1] == b );
|
||||
build_assert ( &u.ddd.dd.digest.h[2] == c );
|
||||
build_assert ( &u.ddd.dd.digest.h[3] == d );
|
||||
build_assert ( &u.ddd.dd.data.dword[0] == w );
|
||||
|
||||
DBGC ( context, "MD4 digesting:\n" );
|
||||
DBGC_HDA ( context, 0, &context->ddd.dd.digest,
|
||||
|
||||
+5
-5
@@ -178,11 +178,11 @@ static void md5_digest ( struct md5_context *context ) {
|
||||
|
||||
/* Sanity checks */
|
||||
assert ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 );
|
||||
linker_assert ( &u.ddd.dd.digest.h[0] == a, md5_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[1] == b, md5_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[2] == c, md5_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[3] == d, md5_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.data.dword[0] == w, md5_bad_layout );
|
||||
build_assert ( &u.ddd.dd.digest.h[0] == a );
|
||||
build_assert ( &u.ddd.dd.digest.h[1] == b );
|
||||
build_assert ( &u.ddd.dd.digest.h[2] == c );
|
||||
build_assert ( &u.ddd.dd.digest.h[3] == d );
|
||||
build_assert ( &u.ddd.dd.data.dword[0] == w );
|
||||
|
||||
DBGC ( context, "MD5 digesting:\n" );
|
||||
DBGC_HDA ( context, 0, &context->ddd.dd.digest,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha1.h>
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_128_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_128_cbc_sha __tls_cipher_suite ( 15 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_128_CBC_SHA ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA1_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha1_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_256_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_256_cbc_sha __tls_cipher_suite ( 16 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_256_CBC_SHA ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA1_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha1_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_128_cbc_sha256 __tls_cipher_suite ( 13 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA256_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_256_cbc_sha256 __tls_cipher_suite ( 14 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA256_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_128_gcm_sha256 __tls_cipher_suite ( 11 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
.record_iv_len = 8,
|
||||
.mac_len = 0,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_gcm_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha512.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_256_gcm_sha384 __tls_cipher_suite ( 12 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
.record_iv_len = 8,
|
||||
.mac_len = 0,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_gcm_algorithm,
|
||||
.digest = &sha384_algorithm,
|
||||
.handshake = &sha384_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha1.h>
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_ecdhe_rsa_with_aes_128_cbc_sha __tls_cipher_suite ( 05 ) = {
|
||||
.code = htons ( TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA1_DIGEST_SIZE,
|
||||
.exchange = &tls_ecdhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha1_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_ecdhe_rsa_with_aes_256_cbc_sha __tls_cipher_suite ( 06 ) = {
|
||||
.code = htons ( TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA1_DIGEST_SIZE,
|
||||
.exchange = &tls_ecdhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha1_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_ecdhe_rsa_with_aes_128_cbc_sha256 __tls_cipher_suite ( 03 ) = {
|
||||
.code = htons ( TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA256_DIGEST_SIZE,
|
||||
.exchange = &tls_ecdhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha512.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_ecdhe_rsa_with_aes_256_cbc_sha384 __tls_cipher_suite ( 04 ) = {
|
||||
.code = htons ( TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA384_DIGEST_SIZE,
|
||||
.exchange = &tls_ecdhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha384_algorithm,
|
||||
.handshake = &sha384_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_ecdhe_rsa_with_aes_128_gcm_sha256 __tls_cipher_suite ( 01 ) = {
|
||||
.code = htons ( TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
.record_iv_len = 8,
|
||||
.mac_len = 0,
|
||||
.exchange = &tls_ecdhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_gcm_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/rsa.h>
|
||||
#include <ipxe/aes.h>
|
||||
#include <ipxe/sha512.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_ecdhe_rsa_with_aes_256_gcm_sha384 __tls_cipher_suite ( 02 ) = {
|
||||
.code = htons ( TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
.record_iv_len = 8,
|
||||
.mac_len = 0,
|
||||
.exchange = &tls_ecdhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_gcm_algorithm,
|
||||
.digest = &sha384_algorithm,
|
||||
.handshake = &sha384_algorithm,
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#include <byteswap.h>
|
||||
#include <ipxe/x25519.h>
|
||||
#include <ipxe/asn1.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** "x25519" object identifier */
|
||||
static uint8_t oid_x25519[] = { ASN1_OID_X25519 };
|
||||
|
||||
/** "x25519" OID-identified algorithm */
|
||||
struct asn1_algorithm x25519_algorithm __asn1_algorithm = {
|
||||
.name = "x25519",
|
||||
.curve = &x25519_curve,
|
||||
.oid = ASN1_CURSOR ( oid_x25519 ),
|
||||
};
|
||||
|
||||
/** X25519 named curve */
|
||||
struct tls_named_curve tls_x25519_named_curve __tls_named_curve ( 01 ) = {
|
||||
.curve = &x25519_curve,
|
||||
.code = htons ( TLS_NAMED_CURVE_X25519 ),
|
||||
};
|
||||
@@ -30,39 +30,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_128_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_128_cbc_sha __tls_cipher_suite ( 05 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_128_CBC_SHA ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA1_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha1_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_256_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_256_cbc_sha __tls_cipher_suite ( 06 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_256_CBC_SHA ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA1_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha1_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_RSA_WITH_AES_128_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_rsa_with_aes_128_cbc_sha __tls_cipher_suite ( 15 ) = {
|
||||
tls_rsa_with_aes_128_cbc_sha __tls_cipher_suite ( 25 ) = {
|
||||
.code = htons ( TLS_RSA_WITH_AES_128_CBC_SHA ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
@@ -77,7 +47,7 @@ tls_rsa_with_aes_128_cbc_sha __tls_cipher_suite ( 15 ) = {
|
||||
|
||||
/** TLS_RSA_WITH_AES_256_CBC_SHA cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_rsa_with_aes_256_cbc_sha __tls_cipher_suite ( 16 ) = {
|
||||
tls_rsa_with_aes_256_cbc_sha __tls_cipher_suite ( 26 ) = {
|
||||
.code = htons ( TLS_RSA_WITH_AES_256_CBC_SHA ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
|
||||
@@ -29,39 +29,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_128_cbc_sha256 __tls_cipher_suite ( 03 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA256_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_256_cbc_sha256 __tls_cipher_suite ( 04 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
.record_iv_len = AES_BLOCKSIZE,
|
||||
.mac_len = SHA256_DIGEST_SIZE,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_cbc_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_RSA_WITH_AES_128_CBC_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_rsa_with_aes_128_cbc_sha256 __tls_cipher_suite ( 13 ) = {
|
||||
tls_rsa_with_aes_128_cbc_sha256 __tls_cipher_suite ( 23 ) = {
|
||||
.code = htons ( TLS_RSA_WITH_AES_128_CBC_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
@@ -76,7 +46,7 @@ tls_rsa_with_aes_128_cbc_sha256 __tls_cipher_suite ( 13 ) = {
|
||||
|
||||
/** TLS_RSA_WITH_AES_256_CBC_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_rsa_with_aes_256_cbc_sha256 __tls_cipher_suite ( 14 ) = {
|
||||
tls_rsa_with_aes_256_cbc_sha256 __tls_cipher_suite ( 24 ) = {
|
||||
.code = htons ( TLS_RSA_WITH_AES_256_CBC_SHA256 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 0,
|
||||
|
||||
@@ -29,24 +29,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <ipxe/sha256.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_128_gcm_sha256 __tls_cipher_suite ( 01 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
.record_iv_len = 8,
|
||||
.mac_len = 0,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_gcm_algorithm,
|
||||
.digest = &sha256_algorithm,
|
||||
.handshake = &sha256_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_RSA_WITH_AES_128_GCM_SHA256 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_rsa_with_aes_128_gcm_sha256 __tls_cipher_suite ( 11 ) = {
|
||||
tls_rsa_with_aes_128_gcm_sha256 __tls_cipher_suite ( 21 ) = {
|
||||
.code = htons ( TLS_RSA_WITH_AES_128_GCM_SHA256 ),
|
||||
.key_len = ( 128 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
|
||||
@@ -29,24 +29,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <ipxe/sha512.h>
|
||||
#include <ipxe/tls.h>
|
||||
|
||||
/** TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_dhe_rsa_with_aes_256_gcm_sha384 __tls_cipher_suite ( 02 ) = {
|
||||
.code = htons ( TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
.record_iv_len = 8,
|
||||
.mac_len = 0,
|
||||
.exchange = &tls_dhe_exchange_algorithm,
|
||||
.pubkey = &rsa_algorithm,
|
||||
.cipher = &aes_gcm_algorithm,
|
||||
.digest = &sha384_algorithm,
|
||||
.handshake = &sha384_algorithm,
|
||||
};
|
||||
|
||||
/** TLS_RSA_WITH_AES_256_GCM_SHA384 cipher suite */
|
||||
struct tls_cipher_suite
|
||||
tls_rsa_with_aes_256_gcm_sha384 __tls_cipher_suite ( 12 ) = {
|
||||
tls_rsa_with_aes_256_gcm_sha384 __tls_cipher_suite ( 22 ) = {
|
||||
.code = htons ( TLS_RSA_WITH_AES_256_GCM_SHA384 ),
|
||||
.key_len = ( 256 / 8 ),
|
||||
.fixed_iv_len = 4,
|
||||
|
||||
+6
-6
@@ -145,12 +145,12 @@ static void sha1_digest ( struct sha1_context *context ) {
|
||||
|
||||
/* Sanity checks */
|
||||
assert ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 );
|
||||
linker_assert ( &u.ddd.dd.digest.h[0] == a, sha1_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[1] == b, sha1_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[2] == c, sha1_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[3] == d, sha1_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[4] == e, sha1_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.data.dword[0] == w, sha1_bad_layout );
|
||||
build_assert ( &u.ddd.dd.digest.h[0] == a );
|
||||
build_assert ( &u.ddd.dd.digest.h[1] == b );
|
||||
build_assert ( &u.ddd.dd.digest.h[2] == c );
|
||||
build_assert ( &u.ddd.dd.digest.h[3] == d );
|
||||
build_assert ( &u.ddd.dd.digest.h[4] == e );
|
||||
build_assert ( &u.ddd.dd.data.dword[0] == w );
|
||||
|
||||
DBGC ( context, "SHA1 digesting:\n" );
|
||||
DBGC_HDA ( context, 0, &context->ddd.dd.digest,
|
||||
|
||||
+9
-9
@@ -140,15 +140,15 @@ static void sha256_digest ( struct sha256_context *context ) {
|
||||
|
||||
/* Sanity checks */
|
||||
assert ( ( context->len % sizeof ( context->ddd.dd.data ) ) == 0 );
|
||||
linker_assert ( &u.ddd.dd.digest.h[0] == a, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[1] == b, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[2] == c, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[3] == d, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[4] == e, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[5] == f, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[6] == g, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.digest.h[7] == h, sha256_bad_layout );
|
||||
linker_assert ( &u.ddd.dd.data.dword[0] == w, sha256_bad_layout );
|
||||
build_assert ( &u.ddd.dd.digest.h[0] == a );
|
||||
build_assert ( &u.ddd.dd.digest.h[1] == b );
|
||||
build_assert ( &u.ddd.dd.digest.h[2] == c );
|
||||
build_assert ( &u.ddd.dd.digest.h[3] == d );
|
||||
build_assert ( &u.ddd.dd.digest.h[4] == e );
|
||||
build_assert ( &u.ddd.dd.digest.h[5] == f );
|
||||
build_assert ( &u.ddd.dd.digest.h[6] == g );
|
||||
build_assert ( &u.ddd.dd.digest.h[7] == h );
|
||||
build_assert ( &u.ddd.dd.data.dword[0] == w );
|
||||
|
||||
DBGC ( context, "SHA256 digesting:\n" );
|
||||
DBGC_HDA ( context, 0, &context->ddd.dd.digest,
|
||||
|
||||
+9
-9
@@ -156,15 +156,15 @@ static void sha512_digest ( struct sha512_context *context ) {
|
||||
|
||||
/* Sanity checks */
|
||||
assert ( ( context->len % sizeof ( context->ddq.dd.data ) ) == 0 );
|
||||
linker_assert ( &u.ddq.dd.digest.h[0] == a, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.digest.h[1] == b, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.digest.h[2] == c, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.digest.h[3] == d, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.digest.h[4] == e, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.digest.h[5] == f, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.digest.h[6] == g, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.digest.h[7] == h, sha512_bad_layout );
|
||||
linker_assert ( &u.ddq.dd.data.qword[0] == w, sha512_bad_layout );
|
||||
build_assert ( &u.ddq.dd.digest.h[0] == a );
|
||||
build_assert ( &u.ddq.dd.digest.h[1] == b );
|
||||
build_assert ( &u.ddq.dd.digest.h[2] == c );
|
||||
build_assert ( &u.ddq.dd.digest.h[3] == d );
|
||||
build_assert ( &u.ddq.dd.digest.h[4] == e );
|
||||
build_assert ( &u.ddq.dd.digest.h[5] == f );
|
||||
build_assert ( &u.ddq.dd.digest.h[6] == g );
|
||||
build_assert ( &u.ddq.dd.digest.h[7] == h );
|
||||
build_assert ( &u.ddq.dd.data.qword[0] == w );
|
||||
|
||||
DBGC ( context, "SHA512 digesting:\n" );
|
||||
DBGC_HDA ( context, 0, &context->ddq.dd.digest,
|
||||
|
||||
@@ -0,0 +1,844 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*
|
||||
* You can also choose to distribute this program under the terms of
|
||||
* the Unmodified Binary Distribution Licence (as given in the file
|
||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
||||
*/
|
||||
|
||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
/** @file
|
||||
*
|
||||
* X25519 key exchange
|
||||
*
|
||||
* This implementation is inspired by and partially based upon the
|
||||
* paper "Implementing Curve25519/X25519: A Tutorial on Elliptic Curve
|
||||
* Cryptography" by Martin Kleppmann, available for download from
|
||||
* https://www.cl.cam.ac.uk/teaching/2122/Crypto/curve25519.pdf
|
||||
*
|
||||
* The underlying modular addition, subtraction, and multiplication
|
||||
* operations are completely redesigned for substantially improved
|
||||
* efficiency compared to the TweetNaCl implementation studied in that
|
||||
* paper.
|
||||
*
|
||||
* TweetNaCl iPXE
|
||||
* --------- ----
|
||||
*
|
||||
* Storage size of each big integer 128 40
|
||||
* (in bytes)
|
||||
*
|
||||
* Stack usage for key exchange 1144 360
|
||||
* (in bytes, large objects only)
|
||||
*
|
||||
* Cost of big integer addition 16 5
|
||||
* (in number of 64-bit additions)
|
||||
*
|
||||
* Cost of big integer multiplication 273 31
|
||||
* (in number of 64-bit multiplications)
|
||||
*
|
||||
* The implementation is constant-time (provided that the underlying
|
||||
* big integer operations are also constant-time).
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <ipxe/init.h>
|
||||
#include <ipxe/crypto.h>
|
||||
#include <ipxe/x25519.h>
|
||||
|
||||
/** X25519 reduction constant
|
||||
*
|
||||
* The X25519 field prime is p=2^255-19. This gives us:
|
||||
*
|
||||
* p = 2^255 - 19
|
||||
* 2^255 = p + 19
|
||||
* 2^255 = 19 (mod p)
|
||||
* k * 2^255 = k * 19 (mod p)
|
||||
*
|
||||
* We can therefore reduce a value modulo p by taking the high-order
|
||||
* bits of the value from bit 255 and above, multiplying by 19, and
|
||||
* adding this to the low-order 255 bits of the value.
|
||||
*
|
||||
* This would be cumbersome to do in practice since it would require
|
||||
* partitioning the value at a 255-bit boundary (and hence would
|
||||
* require some shifting and masking operations). However, we can
|
||||
* note that:
|
||||
*
|
||||
* k * 2^255 = k * 19 (mod p)
|
||||
* k * 2 * 2^255 = k * 2 * 19 (mod p)
|
||||
* k * 2^256 = k * 38 (mod p)
|
||||
*
|
||||
* We can therefore simplify the reduction to taking the high order
|
||||
* bits of the value from bit 256 and above, multiplying by 38, and
|
||||
* adding this to the low-order 256 bits of the value.
|
||||
*
|
||||
* Since 256 will inevitably be a multiple of the big integer element
|
||||
* size (typically 32 or 64 bits), this avoids the need to perform any
|
||||
* shifting or masking operations.
|
||||
*/
|
||||
#define X25519_REDUCE_256 38
|
||||
|
||||
/** X25519 multiplication step 1 result
|
||||
*
|
||||
* Step 1 of X25519 multiplication is to compute the product of two
|
||||
* X25519 unsigned 258-bit integers.
|
||||
*
|
||||
* Both multiplication inputs are limited to 258 bits, and so the
|
||||
* product will have at most 516 bits.
|
||||
*/
|
||||
union x25519_multiply_step1 {
|
||||
/** Raw product
|
||||
*
|
||||
* Big integer multiplication produces a result with a number
|
||||
* of elements equal to the sum of the number of elements in
|
||||
* each input.
|
||||
*/
|
||||
bigint_t ( X25519_SIZE + X25519_SIZE ) product;
|
||||
/** Partition into low-order and high-order bits
|
||||
*
|
||||
* Reduction modulo p requires separating the low-order 256
|
||||
* bits from the remaining high-order bits.
|
||||
*
|
||||
* Since the value will never exceed 516 bits (see above),
|
||||
* there will be at most 260 high-order bits.
|
||||
*/
|
||||
struct {
|
||||
/** Low-order 256 bits */
|
||||
bigint_t ( bigint_required_size ( ( 256 /* bits */ + 7 ) / 8 ) )
|
||||
low_256bit;
|
||||
/** High-order 260 bits */
|
||||
bigint_t ( bigint_required_size ( ( 260 /* bits */ + 7 ) / 8 ) )
|
||||
high_260bit;
|
||||
} __attribute__ (( packed )) parts;
|
||||
};
|
||||
|
||||
/** X25519 multiplication step 2 result
|
||||
*
|
||||
* Step 2 of X25519 multiplication is to multiply the high-order 260
|
||||
* bits from step 1 with the 6-bit reduction constant 38, and to add
|
||||
* this to the low-order 256 bits from step 1.
|
||||
*
|
||||
* The multiplication inputs are limited to 260 and 6 bits
|
||||
* respectively, and so the product will have at most 266 bits. After
|
||||
* adding the low-order 256 bits from step 1, the result will have at
|
||||
* most 267 bits.
|
||||
*/
|
||||
union x25519_multiply_step2 {
|
||||
/** Raw product
|
||||
*
|
||||
* Big integer multiplication produces a result with a number
|
||||
* of elements equal to the sum of the number of elements in
|
||||
* each input.
|
||||
*/
|
||||
bigint_t ( bigint_required_size ( ( 260 /* bits */ + 7 ) / 8 ) +
|
||||
bigint_required_size ( ( 6 /* bits */ + 7 ) / 8 ) ) product;
|
||||
/** Big integer value
|
||||
*
|
||||
* The value will never exceed 267 bits (see above), and so
|
||||
* may be consumed as a normal X25519 big integer.
|
||||
*/
|
||||
x25519_t value;
|
||||
/** Partition into low-order and high-order bits
|
||||
*
|
||||
* Reduction modulo p requires separating the low-order 256
|
||||
* bits from the remaining high-order bits.
|
||||
*
|
||||
* Since the value will never exceed 267 bits (see above),
|
||||
* there will be at most 11 high-order bits.
|
||||
*/
|
||||
struct {
|
||||
/** Low-order 256 bits */
|
||||
bigint_t ( bigint_required_size ( ( 256 /* bits */ + 7 ) / 8 ) )
|
||||
low_256bit;
|
||||
/** High-order 11 bits */
|
||||
bigint_t ( bigint_required_size ( ( 11 /* bits */ + 7 ) / 8 ) )
|
||||
high_11bit;
|
||||
} __attribute__ (( packed )) parts;
|
||||
};
|
||||
|
||||
/** X25519 multiplication step 3 result
|
||||
*
|
||||
* Step 3 of X25519 multiplication is to multiply the high-order 11
|
||||
* bits from step 2 with the 6-bit reduction constant 38, and to add
|
||||
* this to the low-order 256 bits from step 2.
|
||||
*
|
||||
* The multiplication inputs are limited to 11 and 6 bits
|
||||
* respectively, and so the product will have at most 17 bits. After
|
||||
* adding the low-order 256 bits from step 2, the result will have at
|
||||
* most 257 bits.
|
||||
*/
|
||||
union x25519_multiply_step3 {
|
||||
/** Raw product
|
||||
*
|
||||
* Big integer multiplication produces a result with a number
|
||||
* of elements equal to the sum of the number of elements in
|
||||
* each input.
|
||||
*/
|
||||
bigint_t ( bigint_required_size ( ( 11 /* bits */ + 7 ) / 8 ) +
|
||||
bigint_required_size ( ( 6 /* bits */ + 7 ) / 8 ) ) product;
|
||||
/** Big integer value
|
||||
*
|
||||
* The value will never exceed 267 bits (see above), and so
|
||||
* may be consumed as a normal X25519 big integer.
|
||||
*/
|
||||
x25519_t value;
|
||||
};
|
||||
|
||||
/** X25519 multiplication temporary working space
|
||||
*
|
||||
* We overlap the buffers used by each step of the multiplication
|
||||
* calculation to reduce the total stack space required:
|
||||
*
|
||||
* |--------------------------------------------------------|
|
||||
* | <- pad -> | <------------ step 1 result -------------> |
|
||||
* | | <- low 256 bits -> | <-- high 260 bits --> |
|
||||
* | <------- step 2 result ------> | <-- step 3 result --> |
|
||||
* |--------------------------------------------------------|
|
||||
*/
|
||||
union x25519_multiply_workspace {
|
||||
/** Step 1 result */
|
||||
struct {
|
||||
/** Padding to avoid collision between steps 1 and 2
|
||||
*
|
||||
* The step 2 multiplication consumes the high 260
|
||||
* bits of step 1, and so the step 2 multiplication
|
||||
* result must not overlap this portion of the step 1
|
||||
* result.
|
||||
*/
|
||||
uint8_t pad[ sizeof ( union x25519_multiply_step2 ) -
|
||||
offsetof ( union x25519_multiply_step1,
|
||||
parts.high_260bit ) ];
|
||||
/** Step 1 result */
|
||||
union x25519_multiply_step1 step1;
|
||||
} __attribute__ (( packed ));
|
||||
/** Steps 2 and 3 results */
|
||||
struct {
|
||||
/** Step 2 result */
|
||||
union x25519_multiply_step2 step2;
|
||||
/** Step 3 result */
|
||||
union x25519_multiply_step3 step3;
|
||||
} __attribute__ (( packed ));
|
||||
};
|
||||
|
||||
/** An X25519 elliptic curve point in projective coordinates
|
||||
*
|
||||
* A point (x,y) on the Montgomery curve used in X25519 is represented
|
||||
* using projective coordinates (X/Z,Y/Z) so that intermediate
|
||||
* calculations may be performed on both numerator and denominator
|
||||
* separately, with the division step performed only once at the end
|
||||
* of the calculation.
|
||||
*
|
||||
* The group operation calculation is performed using a Montgomery
|
||||
* ladder as:
|
||||
*
|
||||
* X[2i] = ( X[i]^2 - Z[i]^2 )^2
|
||||
* X[2i+1] = ( X[i] * X[i+1] - Z[i] * Z[i+1] )^2
|
||||
* Z[2i] = 4 * X[i] * Z[i] * ( X[i]^2 + A * X[i] * Z[i] + Z[i]^2 )
|
||||
* Z[2i+1] = X[0] * ( X[i] * Z[i+1] - X[i+1] * Z[i] ) ^ 2
|
||||
*
|
||||
* It is therefore not necessary to store (or use) the value of Y.
|
||||
*/
|
||||
struct x25519_projective {
|
||||
/** X coordinate */
|
||||
union x25519_quad257 X;
|
||||
/** Z coordinate */
|
||||
union x25519_quad257 Z;
|
||||
};
|
||||
|
||||
/** An X25519 Montgomery ladder step */
|
||||
struct x25519_step {
|
||||
/** X[n]/Z[n] */
|
||||
struct x25519_projective x_n;
|
||||
/** X[n+1]/Z[n+1] */
|
||||
struct x25519_projective x_n1;
|
||||
};
|
||||
|
||||
/** Constant p=2^255-19 (the finite field prime) */
|
||||
static const uint8_t x25519_p_raw[] = {
|
||||
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xed
|
||||
};
|
||||
|
||||
/** Constant p=2^255-19 (the finite field prime) */
|
||||
static x25519_t x25519_p;
|
||||
|
||||
/** Constant 2p=2^256-38 */
|
||||
static x25519_t x25519_2p;
|
||||
|
||||
/** Constant 4p=2^257-76 */
|
||||
static x25519_t x25519_4p;
|
||||
|
||||
/** Reduction constant (used during multiplication) */
|
||||
static const uint8_t x25519_reduce_256_raw[] = { X25519_REDUCE_256 };
|
||||
|
||||
/** Reduction constant (used during multiplication) */
|
||||
static bigint_t ( bigint_required_size ( sizeof ( x25519_reduce_256_raw ) ) )
|
||||
x25519_reduce_256;
|
||||
|
||||
/** Constant 121665 (used in the Montgomery ladder) */
|
||||
static const uint8_t x25519_121665_raw[] = { 0x01, 0xdb, 0x41 };
|
||||
|
||||
/** Constant 121665 (used in the Montgomery ladder) */
|
||||
static union x25519_oct258 x25519_121665;
|
||||
|
||||
/** Constant g=9 (the group generator) */
|
||||
static struct x25519_value x25519_generator = {
|
||||
.raw = { 9, }
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise constants
|
||||
*
|
||||
*/
|
||||
static void x25519_init_constants ( void ) {
|
||||
|
||||
/* Construct constant p */
|
||||
bigint_init ( &x25519_p, x25519_p_raw, sizeof ( x25519_p_raw ) );
|
||||
|
||||
/* Construct constant 2p */
|
||||
bigint_copy ( &x25519_p, &x25519_2p );
|
||||
bigint_add ( &x25519_p, &x25519_2p );
|
||||
|
||||
/* Construct constant 4p */
|
||||
bigint_copy ( &x25519_2p, &x25519_4p );
|
||||
bigint_add ( &x25519_2p, &x25519_4p );
|
||||
|
||||
/* Construct reduction constant */
|
||||
bigint_init ( &x25519_reduce_256, x25519_reduce_256_raw,
|
||||
sizeof ( x25519_reduce_256_raw ) );
|
||||
|
||||
/* Construct constant 121665 */
|
||||
bigint_init ( &x25519_121665.value, x25519_121665_raw,
|
||||
sizeof ( x25519_121665_raw ) );
|
||||
}
|
||||
|
||||
/** Initialisation function */
|
||||
struct init_fn x25519_init_fn __init_fn ( INIT_NORMAL ) = {
|
||||
.initialise = x25519_init_constants,
|
||||
};
|
||||
|
||||
/**
|
||||
* Add big integers modulo field prime
|
||||
*
|
||||
* @v augend Big integer to add
|
||||
* @v addend Big integer to add
|
||||
* @v result Big integer to hold result (may overlap augend)
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
x25519_add ( const union x25519_quad257 *augend,
|
||||
const union x25519_quad257 *addend,
|
||||
union x25519_oct258 *result ) {
|
||||
int copy;
|
||||
|
||||
/* Copy augend if necessary */
|
||||
copy = ( result != &augend->oct258 );
|
||||
build_assert ( __builtin_constant_p ( copy ) );
|
||||
if ( copy ) {
|
||||
build_assert ( result != &addend->oct258 );
|
||||
bigint_copy ( &augend->oct258.value, &result->value );
|
||||
}
|
||||
|
||||
/* Perform addition
|
||||
*
|
||||
* Both inputs are in the range [0,4p-1] and the resulting
|
||||
* sum is therefore in the range [0,8p-2].
|
||||
*
|
||||
* This range lies within the range [0,8p-1] and the result is
|
||||
* therefore a valid X25519 unsigned 258-bit integer, as
|
||||
* required.
|
||||
*/
|
||||
bigint_add ( &addend->value, &result->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract big integers modulo field prime
|
||||
*
|
||||
* @v minuend Big integer from which to subtract
|
||||
* @v subtrahend Big integer to subtract
|
||||
* @v result Big integer to hold result (may overlap minuend)
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
x25519_subtract ( const union x25519_quad257 *minuend,
|
||||
const union x25519_quad257 *subtrahend,
|
||||
union x25519_oct258 *result ) {
|
||||
int copy;
|
||||
|
||||
/* Copy minuend if necessary */
|
||||
copy = ( result != &minuend->oct258 );
|
||||
build_assert ( __builtin_constant_p ( copy ) );
|
||||
if ( copy ) {
|
||||
build_assert ( result != &subtrahend->oct258 );
|
||||
bigint_copy ( &minuend->oct258.value, &result->value );
|
||||
}
|
||||
|
||||
/* Perform subtraction
|
||||
*
|
||||
* Both inputs are in the range [0,4p-1] and the resulting
|
||||
* difference is therefore in the range [1-4p,4p-1].
|
||||
*
|
||||
* This range lies partially outside the range [0,8p-1] and
|
||||
* the result is therefore not yet a valid X25519 unsigned
|
||||
* 258-bit integer.
|
||||
*/
|
||||
bigint_subtract ( &subtrahend->value, &result->value );
|
||||
|
||||
/* Add constant multiple of field prime p
|
||||
*
|
||||
* Add the constant 4p to the result. This brings the result
|
||||
* within the range [1,8p-1] (without changing the value
|
||||
* modulo p).
|
||||
*
|
||||
* This range lies within the range [0,8p-1] and the result is
|
||||
* therefore now a valid X25519 unsigned 258-bit integer, as
|
||||
* required.
|
||||
*/
|
||||
bigint_add ( &x25519_4p, &result->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply big integers modulo field prime
|
||||
*
|
||||
* @v multiplicand Big integer to be multiplied
|
||||
* @v multiplier Big integer to be multiplied
|
||||
* @v result Big integer to hold result (may overlap either input)
|
||||
*/
|
||||
void x25519_multiply ( const union x25519_oct258 *multiplicand,
|
||||
const union x25519_oct258 *multiplier,
|
||||
union x25519_quad257 *result ) {
|
||||
union x25519_multiply_workspace tmp;
|
||||
union x25519_multiply_step1 *step1 = &tmp.step1;
|
||||
union x25519_multiply_step2 *step2 = &tmp.step2;
|
||||
union x25519_multiply_step3 *step3 = &tmp.step3;
|
||||
|
||||
/* Step 1: perform raw multiplication
|
||||
*
|
||||
* step1 = multiplicand * multiplier
|
||||
*
|
||||
* Both inputs are 258-bit numbers and the step 1 result is
|
||||
* therefore 258+258=516 bits.
|
||||
*/
|
||||
static_assert ( sizeof ( step1->product ) >= sizeof ( step1->parts ) );
|
||||
bigint_multiply ( &multiplicand->value, &multiplier->value,
|
||||
&step1->product );
|
||||
|
||||
/* Step 2: reduce high-order 516-256=260 bits of step 1 result
|
||||
*
|
||||
* Use the identity 2^256=38 (mod p) to reduce the high-order
|
||||
* bits of the step 1 result. We split the 516-bit result
|
||||
* from step 1 into its low-order 256 bits and high-order 260
|
||||
* bits:
|
||||
*
|
||||
* step1 = step1(low 256 bits) + step1(high 260 bits) * 2^256
|
||||
*
|
||||
* and then perform the calculation:
|
||||
*
|
||||
* step2 = step1 (mod p)
|
||||
* = step1(low 256 bits) + step1(high 260 bits) * 2^256 (mod p)
|
||||
* = step1(low 256 bits) + step1(high 260 bits) * 38 (mod p)
|
||||
*
|
||||
* There are 6 bits in the constant value 38. The step 2
|
||||
* multiplication product will therefore have 260+6=266 bits,
|
||||
* and the step 2 result (after the addition) will therefore
|
||||
* have 267 bits.
|
||||
*/
|
||||
static_assert ( sizeof ( step2->product ) >= sizeof ( step2->value ) );
|
||||
static_assert ( sizeof ( step2->product ) >= sizeof ( step2->parts ) );
|
||||
bigint_grow ( &step1->parts.low_256bit, &result->value );
|
||||
bigint_multiply ( &step1->parts.high_260bit, &x25519_reduce_256,
|
||||
&step2->product );
|
||||
bigint_add ( &result->value, &step2->value );
|
||||
|
||||
/* Step 3: reduce high-order 267-256=11 bits of step 2 result
|
||||
*
|
||||
* Use the identity 2^256=38 (mod p) again to reduce the
|
||||
* high-order bits of the step 2 result. As before, we split
|
||||
* the 267-bit result from step 2 into its low-order 256 bits
|
||||
* and high-order 11 bits:
|
||||
*
|
||||
* step2 = step2(low 256 bits) + step2(high 11 bits) * 2^256
|
||||
*
|
||||
* and then perform the calculation:
|
||||
*
|
||||
* step3 = step2 (mod p)
|
||||
* = step2(low 256 bits) + step2(high 11 bits) * 2^256 (mod p)
|
||||
* = step2(low 256 bits) + step2(high 11 bits) * 38 (mod p)
|
||||
*
|
||||
* There are 6 bits in the constant value 38. The step 3
|
||||
* multiplication product will therefore have 11+6=19 bits,
|
||||
* and the step 3 result (after the addition) will therefore
|
||||
* have 257 bits.
|
||||
*
|
||||
* A loose upper bound for the step 3 result (after the
|
||||
* addition) is given by:
|
||||
*
|
||||
* step3 < ( 2^256 - 1 ) + ( 2^19 - 1 )
|
||||
* < ( 2^257 - 2^256 - 1 ) + ( 2^19 - 1 )
|
||||
* < ( 2^257 - 76 ) - 2^256 + 2^19 + 74
|
||||
* < 4 * ( 2^255 - 19 ) - 2^256 + 2^19 + 74
|
||||
* < 4p - 2^256 + 2^19 + 74
|
||||
*
|
||||
* and so the step 3 result is strictly less than 4p, and
|
||||
* therefore lies within the range [0,4p-1].
|
||||
*/
|
||||
memset ( &step3->value, 0, sizeof ( step3->value ) );
|
||||
bigint_grow ( &step2->parts.low_256bit, &result->value );
|
||||
bigint_multiply ( &step2->parts.high_11bit, &x25519_reduce_256,
|
||||
&step3->product );
|
||||
bigint_add ( &step3->value, &result->value );
|
||||
|
||||
/* Step 1 calculates the product of the input operands, and
|
||||
* each subsequent step reduces the number of bits in the
|
||||
* result while preserving this value (modulo p). The final
|
||||
* result is therefore equal to the product of the input
|
||||
* operands (modulo p), as required.
|
||||
*
|
||||
* The step 3 result lies within the range [0,4p-1] and the
|
||||
* final result is therefore a valid X25519 unsigned 257-bit
|
||||
* integer, as required.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute multiplicative inverse
|
||||
*
|
||||
* @v invertend Big integer to be inverted
|
||||
* @v result Big integer to hold result (may not overlap input)
|
||||
*/
|
||||
void x25519_invert ( const union x25519_oct258 *invertend,
|
||||
union x25519_quad257 *result ) {
|
||||
int i;
|
||||
|
||||
/* Sanity check */
|
||||
assert ( invertend != &result->oct258 );
|
||||
|
||||
/* Calculate inverse as x^(-1)=x^(p-2) where p is the field prime
|
||||
*
|
||||
* The field prime is p=2^255-19 and so:
|
||||
*
|
||||
* p - 2 = 2^255 - 21
|
||||
* = (2^255 - 1) - 2^4 - 2^2
|
||||
*
|
||||
* i.e. p-2 is a 254-bit number in which all bits are set
|
||||
* apart from bit 2 and bit 4.
|
||||
*
|
||||
* We use the square-and-multiply method to compute x^(p-2).
|
||||
*/
|
||||
bigint_copy ( &invertend->value, &result->value );
|
||||
for ( i = 253 ; i >= 0 ; i-- ) {
|
||||
|
||||
/* Square running total */
|
||||
x25519_multiply ( &result->oct258, &result->oct258, result );
|
||||
|
||||
/* For each set bit in the exponent, multiply by invertend */
|
||||
if ( ( i != 2 ) && ( i != 4 ) ) {
|
||||
x25519_multiply ( invertend, &result->oct258, result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce big integer via conditional subtraction
|
||||
*
|
||||
* @v subtrahend Big integer to subtract
|
||||
* @v value Big integer to be subtracted from, if possible
|
||||
*/
|
||||
static void x25519_reduce_by ( const x25519_t *subtrahend, x25519_t *value ) {
|
||||
unsigned int max_bit = ( ( 8 * sizeof ( *value ) ) - 1 );
|
||||
x25519_t tmp;
|
||||
|
||||
/* Conditionally subtract subtrahend
|
||||
*
|
||||
* Subtract the subtrahend, discarding the result (in constant
|
||||
* time) if the subtraction underflows.
|
||||
*/
|
||||
bigint_copy ( value, &tmp );
|
||||
bigint_subtract ( subtrahend, value );
|
||||
bigint_swap ( value, &tmp, bigint_bit_is_set ( value, max_bit ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce big integer to canonical range
|
||||
*
|
||||
* @v value Big integer to be reduced
|
||||
*/
|
||||
void x25519_reduce ( union x25519_quad257 *value ) {
|
||||
|
||||
/* Conditionally subtract 2p
|
||||
*
|
||||
* Subtract twice the field prime, discarding the result (in
|
||||
* constant time) if the subtraction underflows.
|
||||
*
|
||||
* The input value is in the range [0,4p-1]. After this
|
||||
* conditional subtraction, the value is in the range
|
||||
* [0,2p-1].
|
||||
*/
|
||||
x25519_reduce_by ( &x25519_2p, &value->value );
|
||||
|
||||
/* Conditionally subtract p
|
||||
*
|
||||
* Subtract the field prime, discarding the result (in
|
||||
* constant time) if the subtraction underflows.
|
||||
*
|
||||
* The value is already in the range [0,2p-1]. After this
|
||||
* conditional subtraction, the value is in the range [0,p-1]
|
||||
* and is therefore the canonical representation.
|
||||
*/
|
||||
x25519_reduce_by ( &x25519_p, &value->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute next step of the Montgomery ladder
|
||||
*
|
||||
* @v base Base point
|
||||
* @v bit Bit value
|
||||
* @v step Ladder step
|
||||
*/
|
||||
static void x25519_step ( const union x25519_quad257 *base, int bit,
|
||||
struct x25519_step *step ) {
|
||||
union x25519_quad257 *a = &step->x_n.X;
|
||||
union x25519_quad257 *b = &step->x_n1.X;
|
||||
union x25519_quad257 *c = &step->x_n.Z;
|
||||
union x25519_quad257 *d = &step->x_n1.Z;
|
||||
union x25519_oct258 e;
|
||||
union x25519_quad257 f;
|
||||
union x25519_oct258 *v1_e;
|
||||
union x25519_oct258 *v2_a;
|
||||
union x25519_oct258 *v3_c;
|
||||
union x25519_oct258 *v4_b;
|
||||
union x25519_quad257 *v5_d;
|
||||
union x25519_quad257 *v6_f;
|
||||
union x25519_quad257 *v7_a;
|
||||
union x25519_quad257 *v8_c;
|
||||
union x25519_oct258 *v9_e;
|
||||
union x25519_oct258 *v10_a;
|
||||
union x25519_quad257 *v11_b;
|
||||
union x25519_oct258 *v12_c;
|
||||
union x25519_quad257 *v13_a;
|
||||
union x25519_oct258 *v14_a;
|
||||
union x25519_quad257 *v15_c;
|
||||
union x25519_quad257 *v16_a;
|
||||
union x25519_quad257 *v17_d;
|
||||
union x25519_quad257 *v18_b;
|
||||
|
||||
/* See the referenced paper "Implementing Curve25519/X25519: A
|
||||
* Tutorial on Elliptic Curve Cryptography" for the reasoning
|
||||
* behind this calculation.
|
||||
*/
|
||||
|
||||
/* Reuse storage locations for intermediate results where possible */
|
||||
v1_e = &e;
|
||||
v2_a = container_of ( &a->value, union x25519_oct258, value );
|
||||
v3_c = container_of ( &c->value, union x25519_oct258, value );
|
||||
v4_b = container_of ( &b->value, union x25519_oct258, value );
|
||||
v5_d = d;
|
||||
v6_f = &f;
|
||||
v7_a = a;
|
||||
v8_c = c;
|
||||
v9_e = &e;
|
||||
v10_a = container_of ( &a->value, union x25519_oct258, value );
|
||||
v11_b = b;
|
||||
v12_c = container_of ( &c->value, union x25519_oct258, value );
|
||||
v13_a = a;
|
||||
v14_a = container_of ( &a->value, union x25519_oct258, value );
|
||||
v15_c = c;
|
||||
v16_a = a;
|
||||
v17_d = d;
|
||||
v18_b = b;
|
||||
|
||||
/* Select inputs */
|
||||
bigint_swap ( &a->value, &b->value, bit );
|
||||
bigint_swap ( &c->value, &d->value, bit );
|
||||
|
||||
/* v1 = a + c */
|
||||
x25519_add ( a, c, v1_e );
|
||||
|
||||
/* v2 = a - c */
|
||||
x25519_subtract ( a, c, v2_a );
|
||||
|
||||
/* v3 = b + d */
|
||||
x25519_add ( b, d, v3_c );
|
||||
|
||||
/* v4 = b - d */
|
||||
x25519_subtract ( b, d, v4_b );
|
||||
|
||||
/* v5 = v1^2 = (a + c)^2 = a^2 + 2ac + c^2 */
|
||||
x25519_multiply ( v1_e, v1_e, v5_d );
|
||||
|
||||
/* v6 = v2^2 = (a - c)^2 = a^2 - 2ac + c^2 */
|
||||
x25519_multiply ( v2_a, v2_a, v6_f );
|
||||
|
||||
/* v7 = v3 * v2 = (b + d) * (a - c) = ab - bc + ad - cd */
|
||||
x25519_multiply ( v3_c, v2_a, v7_a );
|
||||
|
||||
/* v8 = v4 * v1 = (b - d) * (a + c) = ab + bc - ad - cd */
|
||||
x25519_multiply ( v4_b, v1_e, v8_c );
|
||||
|
||||
/* v9 = v7 + v8 = 2 * (ab - cd) */
|
||||
x25519_add ( v7_a, v8_c, v9_e );
|
||||
|
||||
/* v10 = v7 - v8 = 2 * (ad - bc) */
|
||||
x25519_subtract ( v7_a, v8_c, v10_a );
|
||||
|
||||
/* v11 = v10^2 = 4 * (ad - bc)^2 */
|
||||
x25519_multiply ( v10_a, v10_a, v11_b );
|
||||
|
||||
/* v12 = v5 - v6 = (a + c)^2 - (a - c)^2 = 4ac */
|
||||
x25519_subtract ( v5_d, v6_f, v12_c );
|
||||
|
||||
/* v13 = v12 * 121665 = 486660ac = (A-2) * ac */
|
||||
x25519_multiply ( v12_c, &x25519_121665, v13_a );
|
||||
|
||||
/* v14 = v13 + v5 = (A-2) * ac + a^2 + 2ac + c^2 = a^2 + A * ac + c^2 */
|
||||
x25519_add ( v13_a, v5_d, v14_a );
|
||||
|
||||
/* v15 = v12 * v14 = 4ac * (a^2 + A * ac + c^2) */
|
||||
x25519_multiply ( v12_c, v14_a, v15_c );
|
||||
|
||||
/* v16 = v5 * v6 = (a + c)^2 * (a - c)^2 = (a^2 - c^2)^2 */
|
||||
x25519_multiply ( &v5_d->oct258, &v6_f->oct258, v16_a );
|
||||
|
||||
/* v17 = v11 * base = 4 * base * (ad - bc)^2 */
|
||||
x25519_multiply ( &v11_b->oct258, &base->oct258, v17_d );
|
||||
|
||||
/* v18 = v9^2 = 4 * (ab - cd)^2 */
|
||||
x25519_multiply ( v9_e, v9_e, v18_b );
|
||||
|
||||
/* Select outputs */
|
||||
bigint_swap ( &a->value, &b->value, bit );
|
||||
bigint_swap ( &c->value, &d->value, bit );
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply X25519 elliptic curve point
|
||||
*
|
||||
* @v base Base point
|
||||
* @v scalar Scalar multiple
|
||||
* @v result Point to hold result (may overlap base point)
|
||||
*/
|
||||
static void x25519_ladder ( const union x25519_quad257 *base,
|
||||
struct x25519_value *scalar,
|
||||
union x25519_quad257 *result ) {
|
||||
static const uint8_t zero[] = { 0 };
|
||||
static const uint8_t one[] = { 1 };
|
||||
struct x25519_step step;
|
||||
union x25519_quad257 *tmp;
|
||||
int bit;
|
||||
int i;
|
||||
|
||||
/* Initialise ladder */
|
||||
bigint_init ( &step.x_n.X.value, one, sizeof ( one ) );
|
||||
bigint_init ( &step.x_n.Z.value, zero, sizeof ( zero ) );
|
||||
bigint_copy ( &base->value, &step.x_n1.X.value );
|
||||
bigint_init ( &step.x_n1.Z.value, one, sizeof ( one ) );
|
||||
|
||||
/* Use ladder */
|
||||
for ( i = 254 ; i >= 0 ; i-- ) {
|
||||
bit = ( ( scalar->raw[ i / 8 ] >> ( i % 8 ) ) & 1 );
|
||||
x25519_step ( base, bit, &step );
|
||||
}
|
||||
|
||||
/* Convert back to affine coordinate */
|
||||
tmp = &step.x_n1.X;
|
||||
x25519_invert ( &step.x_n.Z.oct258, tmp );
|
||||
x25519_multiply ( &step.x_n.X.oct258, &tmp->oct258, result );
|
||||
x25519_reduce ( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse X25519 value endianness
|
||||
*
|
||||
* @v value Value to reverse
|
||||
*/
|
||||
static void x25519_reverse ( struct x25519_value *value ) {
|
||||
uint8_t *low = value->raw;
|
||||
uint8_t *high = &value->raw[ sizeof ( value->raw ) - 1 ];
|
||||
uint8_t tmp;
|
||||
|
||||
/* Reverse bytes */
|
||||
do {
|
||||
tmp = *low;
|
||||
*low = *high;
|
||||
*high = tmp;
|
||||
} while ( ++low < --high );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate X25519 key
|
||||
*
|
||||
* @v base Base point
|
||||
* @v scalar Scalar multiple
|
||||
* @v result Point to hold result (may overlap base point)
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int x25519_key ( const struct x25519_value *base,
|
||||
const struct x25519_value *scalar,
|
||||
struct x25519_value *result ) {
|
||||
struct x25519_value *tmp = result;
|
||||
union x25519_quad257 point;
|
||||
|
||||
/* Reverse base point and clear high bit as required by RFC7748 */
|
||||
memcpy ( tmp, base, sizeof ( *tmp ) );
|
||||
x25519_reverse ( tmp );
|
||||
tmp->raw[0] &= 0x7f;
|
||||
bigint_init ( &point.value, tmp->raw, sizeof ( tmp->raw ) );
|
||||
|
||||
/* Clamp scalar as required by RFC7748 */
|
||||
memcpy ( tmp, scalar, sizeof ( *tmp ) );
|
||||
tmp->raw[0] &= 0xf8;
|
||||
tmp->raw[31] |= 0x40;
|
||||
|
||||
/* Multiply elliptic curve point */
|
||||
x25519_ladder ( &point, tmp, &point );
|
||||
|
||||
/* Reverse result */
|
||||
bigint_done ( &point.value, result->raw, sizeof ( result->raw ) );
|
||||
x25519_reverse ( result );
|
||||
|
||||
/* Fail if result was all zeros (as required by RFC8422) */
|
||||
return ( bigint_is_zero ( &point.value ) ? -EPERM : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply scalar by curve point
|
||||
*
|
||||
* @v base Base point (or NULL to use generator)
|
||||
* @v scalar Scalar multiple
|
||||
* @v result Result point to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int x25519_curve_multiply ( const void *base, const void *scalar,
|
||||
void *result ) {
|
||||
|
||||
/* Use base point if applicable */
|
||||
if ( ! base )
|
||||
base = &x25519_generator;
|
||||
|
||||
return x25519_key ( base, scalar, result );
|
||||
}
|
||||
|
||||
/** X25519 elliptic curve */
|
||||
struct elliptic_curve x25519_curve = {
|
||||
.name = "x25519",
|
||||
.keysize = sizeof ( struct x25519_value ),
|
||||
.multiply = x25519_curve_multiply,
|
||||
};
|
||||
+24
-3
@@ -127,7 +127,7 @@ static int ecam_access ( struct pci_device *pci ) {
|
||||
|
||||
/* Reuse mapping if possible */
|
||||
if ( ( pci->busdevfn - ecam.range.start ) < ecam.range.count )
|
||||
return 0;
|
||||
return ecam.rc;
|
||||
|
||||
/* Clear any existing mapping */
|
||||
if ( ecam.regs ) {
|
||||
@@ -145,12 +145,22 @@ static int ecam_access ( struct pci_device *pci ) {
|
||||
if ( ecam.range.start > pci->busdevfn ) {
|
||||
DBGC ( &ecam, "ECAM found no allocation for " PCI_FMT "\n",
|
||||
PCI_ARGS ( pci ) );
|
||||
rc = -ENOENT;
|
||||
goto err_find;
|
||||
}
|
||||
|
||||
/* Map configuration space for this allocation */
|
||||
base = le64_to_cpu ( ecam.alloc.base );
|
||||
base += ( ecam.alloc.start * ECAM_SIZE * PCI_BUSDEVFN ( 0, 1, 0, 0 ) );
|
||||
len = ( ecam.range.count * ECAM_SIZE );
|
||||
if ( base != ( ( unsigned long ) base ) ) {
|
||||
DBGC ( &ecam, "ECAM %04x:[%02x-%02x] could not map "
|
||||
"[%08llx,%08llx) outside CPU range\n",
|
||||
le16_to_cpu ( ecam.alloc.segment ), ecam.alloc.start,
|
||||
ecam.alloc.end, base, ( base + len ) );
|
||||
rc = -ERANGE;
|
||||
goto err_range;
|
||||
}
|
||||
ecam.regs = ioremap ( base, len );
|
||||
if ( ! ecam.regs ) {
|
||||
DBGC ( &ecam, "ECAM %04x:[%02x-%02x] could not map "
|
||||
@@ -164,12 +174,14 @@ static int ecam_access ( struct pci_device *pci ) {
|
||||
DBGC ( &ecam, "ECAM %04x:[%02x-%02x] mapped [%08llx,%08llx) -> %p\n",
|
||||
le16_to_cpu ( ecam.alloc.segment ), ecam.alloc.start,
|
||||
ecam.alloc.end, base, ( base + len ), ecam.regs );
|
||||
ecam.rc = 0;
|
||||
return 0;
|
||||
|
||||
iounmap ( ecam.regs );
|
||||
err_ioremap:
|
||||
err_range:
|
||||
err_find:
|
||||
ecam.range.count = 0;
|
||||
ecam.rc = rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -235,7 +247,7 @@ int ecam_write ( struct pci_device *pci, unsigned int location,
|
||||
if ( ( rc = ecam_access ( pci ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Read from address */
|
||||
/* Write to address */
|
||||
index = ( pci->busdevfn - ecam.range.start );
|
||||
addr = ( ecam.regs + ( index * ECAM_SIZE ) + where );
|
||||
switch ( len ) {
|
||||
@@ -252,6 +264,15 @@ int ecam_write ( struct pci_device *pci, unsigned int location,
|
||||
assert ( 0 );
|
||||
}
|
||||
|
||||
/* Read from address, to guarantee completion of the write
|
||||
*
|
||||
* PCIe configuration space registers may not have read side
|
||||
* effects. Reading back is therefore always safe to do, and
|
||||
* guarantees that the write has reached the device.
|
||||
*/
|
||||
mb();
|
||||
ecam_read ( pci, location, &value );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -230,10 +230,10 @@ u32 vpm_ioread32(struct virtio_pci_modern_device *vdev,
|
||||
uint32_t data;
|
||||
switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) {
|
||||
case VIRTIO_PCI_REGION_MEMORY:
|
||||
data = readw(region->base + offset);
|
||||
data = readl(region->base + offset);
|
||||
break;
|
||||
case VIRTIO_PCI_REGION_PORT:
|
||||
data = inw(region->base + offset);
|
||||
data = inl(region->base + offset);
|
||||
break;
|
||||
case VIRTIO_PCI_REGION_PCI_CONFIG:
|
||||
prep_pci_cfg_cap(vdev, region, offset, 4);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user