Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions arm/curve25519/curve25519_x25519base_byte.S
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,10 @@ S2N_BN_SYMBOL(curve25519_x25519base_byte):
ldr x0, [scalar]
ands xzr, x0, #8

adr x10, curve25519_x25519base_byte_edwards25519_0g
adr x11, curve25519_x25519base_byte_edwards25519_8g
adrp x10, curve25519_x25519base_byte_edwards25519_0g
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUI page-level relocations for mach-o require @PAGE on the end of this, and @PAGEOFF on the end of the add operand (which also needs to lose the ELF-specific :lo12: relocation designation.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other possibility is just requiring these to be page-aligned, which means we can lose the add adjustments and only need to support one kind of relocation specifier. That's what I did over here (macro def for reference).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed Mach-O is a bit different. I think, after a bit of testing, that the following works with both Linux generating ELF and Mac OS generating Mach-O. (I just use ..._data since I think it will simplify the proof if we just have a single relocated symbol for the start of the data.) I'm confident we can prove this since I've prototyped something similar. But I suspect it needs a bit more refinement for other platforms. I'm hoping that if we delete the linux part of the ifdef it would work on OpenBSD and indeed other BSDs - does that look reasonable? (tab is just cpp'd to a register).

#if defined(__linux__) && defined(__ELF__)
        adrp    tab, curve25519_x25519base_byte_data
        add     tab, tab, :lo12:curve25519_x25519base_byte_data
#else
        adrp    tab, curve25519_x25519base_byte_data@PAGE
        add     tab, tab, curve25519_x25519base_byte_data@PAGEOFF
#endif


add x10, x10, :lo12:curve25519_x25519base_byte_edwards25519_0g
adrp x11, curve25519_x25519base_byte_edwards25519_8g
add x11, x11, :lo12:curve25519_x25519base_byte_edwards25519_8g
ldp x0, x1, [x10]
ldp x2, x3, [x11]
csel x0, x0, x2, eq
Expand Down Expand Up @@ -651,7 +653,8 @@ S2N_BN_SYMBOL(curve25519_x25519base_byte):
// l >= 9 case cannot arise on the last iteration.

mov i, 4
adr tab, curve25519_x25519base_byte_edwards25519_gtable
adrp tab, curve25519_x25519base_byte_edwards25519_gtable
add tab, tab, :lo12:curve25519_x25519base_byte_edwards25519_gtable
mov bias, xzr

// Start of the main loop, repeated 63 times for i = 4, 8, ..., 252
Expand Down