Skip to content

Commit 02b01e0

Browse files
authored
Merge pull request #1663 from briansmith/b/merge-boringssl-17
Merge BoringSSL through a905bbb
2 parents 3a77fe1 + 00da1cb commit 02b01e0

18 files changed

+1411
-244
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ include = [
110110
"examples/**/*.rs",
111111
"include/ring-core/aes.h",
112112
"include/ring-core/arm_arch.h",
113+
"include/ring-core/asm_base.h",
113114
"include/ring-core/base.h",
114115
"include/ring-core/check.h",
115116
"include/ring-core/mem.h",
116117
"include/ring-core/poly1305.h",
118+
"include/ring-core/target.h",
117119
"include/ring-core/type_check.h",
118120
"src/**/*.rs",
119121
"src/aead/poly1305_test.txt",

crypto/curve25519/asm/x25519-asm-arm.S

+3-13
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,9 @@
1717
* domain licensed but the standard ISC license is included above to keep
1818
* licensing simple. */
1919

20-
#if defined(__has_feature)
21-
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
22-
#define OPENSSL_NO_ASM
23-
#endif
24-
#endif
20+
#include <ring-core/asm_base.h>
2521

26-
#if !defined(OPENSSL_NO_ASM) && defined(__ARMEL__) && defined(__ELF__)
27-
28-
#include "ring_core_generated/prefix_symbols_asm.h"
22+
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__ELF__)
2923

3024
.fpu neon
3125
.text
@@ -2127,8 +2121,4 @@ mov sp,r12
21272121
vpop {q4,q5,q6,q7}
21282122
bx lr
21292123

2130-
#endif /* !OPENSSL_NO_ASM && __ARMEL__ && __ELF__ */
2131-
2132-
#if defined(__ELF__)
2133-
.section .note.GNU-stack,"",%progbits
2134-
#endif
2124+
#endif /* !OPENSSL_NO_ASM && OPENSSL_ARM && __ELF__ */

crypto/curve25519/curve25519.c

+12
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,18 @@ static void table_select(ge_precomp *t, const int pos, const signed char b) {
778778
// Preconditions:
779779
// a[31] <= 127
780780
void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
781+
#if defined(BORINGSSL_FE25519_ADX)
782+
if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
783+
CRYPTO_is_ADX_capable()) {
784+
uint8_t t[4][32];
785+
x25519_ge_scalarmult_base_adx(t, a);
786+
fiat_25519_from_bytes(h->X.v, t[0]);
787+
fiat_25519_from_bytes(h->Y.v, t[1]);
788+
fiat_25519_from_bytes(h->Z.v, t[2]);
789+
fiat_25519_from_bytes(h->T.v, t[3]);
790+
return;
791+
}
792+
#endif
781793
signed char e[64];
782794
signed char carry;
783795
ge_p1p1 r;

crypto/curve25519/curve25519_64_adx.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Copyright (c) 2023, Google Inc.
2+
*
3+
* Permission to use, copy, modify, and/or distribute this software for any
4+
* purpose with or without fee is hereby granted, provided that the above
5+
* copyright notice and this permission notice appear in all copies.
6+
*
7+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10+
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12+
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14+
15+
#include "internal.h"
16+
#if defined(BORINGSSL_FE25519_ADX)
17+
#include "../../third_party/fiat/curve25519_64_adx.h"
18+
#endif

crypto/internal.h

-16
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,6 @@ static inline crypto_word_t value_barrier_w(crypto_word_t a) {
223223
return a;
224224
}
225225

226-
// value_barrier_u32 behaves like |value_barrier_w| but takes a |uint32_t|.
227-
static inline uint32_t value_barrier_u32(uint32_t a) {
228-
#if defined(__GNUC__) || defined(__clang__)
229-
__asm__("" : "+r"(a) : /* no inputs */);
230-
#endif
231-
return a;
232-
}
233-
234-
// value_barrier_u64 behaves like |value_barrier_w| but takes a |uint64_t|.
235-
static inline uint64_t value_barrier_u64(uint64_t a) {
236-
#if defined(__GNUC__) || defined(__clang__)
237-
__asm__("" : "+r"(a) : /* no inputs */);
238-
#endif
239-
return a;
240-
}
241-
242226
// |value_barrier_u8| could be defined as above, but compilers other than
243227
// clang seem to still materialize 0x00..00MM instead of reusing 0x??..??MM.
244228

crypto/perlasm/arm-xlate.pl

+3-14
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ sub expand_line {
153153

154154
my ($arch_defines, $target_defines);
155155
if ($flavour =~ /32/) {
156-
$arch_defines = "defined(__ARMEL__)";
156+
$arch_defines = "defined(OPENSSL_ARM)";
157157
} elsif ($flavour =~ /64/) {
158-
$arch_defines = "defined(__AARCH64EL__)";
158+
$arch_defines = "defined(OPENSSL_AARCH64)";
159159
} else {
160160
die "unknown architecture: $flavour";
161161
}
@@ -177,18 +177,11 @@ sub expand_line {
177177
// This file is generated from a similarly-named Perl script in the BoringSSL
178178
// source tree. Do not edit by hand.
179179
180-
#if !defined(__has_feature)
181-
#define __has_feature(x) 0
182-
#endif
183-
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
184-
#define OPENSSL_NO_ASM
185-
#endif
180+
#include <ring-core/asm_base.h>
186181
187182
#if !defined(OPENSSL_NO_ASM) && $arch_defines && $target_defines
188183
___
189184

190-
print "#include \"ring_core_generated/prefix_symbols_asm.h\"\n";
191-
192185
while(my $line=<>) {
193186

194187
if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
@@ -258,10 +251,6 @@ sub expand_line {
258251

259252
print <<___;
260253
#endif // !OPENSSL_NO_ASM && $arch_defines && $target_defines
261-
#if defined(__ELF__)
262-
// See https://www.airs.com/blog/archives/518.
263-
.section .note.GNU-stack,"",\%progbits
264-
#endif
265254
___
266255

267256
close STDOUT or die "error closing STDOUT: $!";

crypto/perlasm/x86_64-xlate.pl

+4-15
Original file line numberDiff line numberDiff line change
@@ -1520,14 +1520,9 @@ sub rxb {
15201520
die "unknown target: $flavour";
15211521
}
15221522
print <<___;
1523-
#if defined(__has_feature)
1524-
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
1525-
#define OPENSSL_NO_ASM
1526-
#endif
1527-
#endif
1528-
1529-
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && $target
1530-
#include "ring_core_generated/prefix_symbols_asm.h"
1523+
#include <ring-core/asm_base.h>
1524+
1525+
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && $target
15311526
___
15321527
}
15331528
@@ -1623,13 +1618,7 @@ sub process_line {
16231618
if ($masm) {
16241619
print "END\n";
16251620
} elsif ($gas) {
1626-
print <<___;
1627-
#endif
1628-
#if defined(__ELF__)
1629-
// See https://www.airs.com/blog/archives/518.
1630-
.section .note.GNU-stack,"",\%progbits
1631-
#endif
1632-
___
1621+
print "#endif\n";
16331622
} elsif ($nasm) {
16341623
print <<___;
16351624
\%else

crypto/perlasm/x86asm.pl

+4-13
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,13 @@ sub ::asm_finish
305305
}
306306

307307
print <<___;
308-
#if defined(__has_feature)
309-
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
310-
#define OPENSSL_NO_ASM
311-
#endif
312-
#endif
313-
314-
#if !defined(OPENSSL_NO_ASM) && defined(__i386__) && $target
315-
#include "ring_core_generated/prefix_symbols_asm.h"
308+
#include <ring-core/asm_base.h>
309+
310+
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && $target
316311
___
317312
print @out;
318313
print <<___;
319-
#endif // !defined(OPENSSL_NO_ASM) && defined(__i386__) && $target
320-
#if defined(__ELF__)
321-
// See https://www.airs.com/blog/archives/518.
322-
.section .note.GNU-stack,"",\%progbits
323-
#endif
314+
#endif // !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && $target
324315
___
325316
}
326317
}

crypto/poly1305/poly1305_arm_asm.S

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
#if defined(__has_feature)
2-
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
3-
#define OPENSSL_NO_ASM
4-
#endif
5-
#endif
1+
#include <ring-core/asm_base.h>
62

7-
#if defined(__ARMEL__) && !defined(OPENSSL_NO_ASM) && defined(__ELF__)
3+
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__ELF__)
84

95
#pragma GCC diagnostic ignored "-Wlanguage-extension-token"
106

11-
#include "ring_core_generated/prefix_symbols_asm.h"
12-
137
# This implementation was taken from the public domain, neon2 version in
148
# SUPERCOP by D. J. Bernstein and Peter Schwabe.
159

@@ -2022,8 +2016,4 @@ vst1.8 d4,[r0,: 64]
20222016
add sp,sp,#0
20232017
bx lr
20242018

2025-
#endif /* __ARMEL__ && !OPENSSL_NO_ASM && __ELF__ */
2026-
2027-
#if defined(__ELF__)
2028-
.section .note.GNU-stack,"",%progbits
2029-
#endif
2019+
#endif /* !OPENSSL_NO_ASM && OPENSSL_ARM && __ELF__ */

include/ring-core/arm_arch.h

+4-119
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@
5353
#ifndef OPENSSL_HEADER_ARM_ARCH_H
5454
#define OPENSSL_HEADER_ARM_ARCH_H
5555

56+
#include <ring-core/target.h>
57+
5658
// arm_arch.h contains symbols used by ARM assembly, and the C code that calls
5759
// it. It is included as a public header to simplify the build, but is not
5860
// intended for external use.
5961

60-
#if defined(__ARMEL__) || defined(_M_ARM) || defined(__AARCH64EL__) || \
61-
defined(_M_ARM64)
62+
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
6263

6364
// ARMV7_NEON is true when a NEON unit is present in the current CPU.
6465
#define ARMV7_NEON (1 << 0)
@@ -91,124 +92,8 @@
9192
// will be included.
9293
#define __ARM_MAX_ARCH__ 8
9394

94-
// Support macros for
95-
// - Armv8.3-A Pointer Authentication and
96-
// - Armv8.5-A Branch Target Identification
97-
// features which require emitting a .note.gnu.property section with the
98-
// appropriate architecture-dependent feature bits set.
99-
//
100-
// |AARCH64_SIGN_LINK_REGISTER| and |AARCH64_VALIDATE_LINK_REGISTER| expand to
101-
// PACIxSP and AUTIxSP, respectively. |AARCH64_SIGN_LINK_REGISTER| should be
102-
// used immediately before saving the LR register (x30) to the stack.
103-
// |AARCH64_VALIDATE_LINK_REGISTER| should be used immediately after restoring
104-
// it. Note |AARCH64_SIGN_LINK_REGISTER|'s modifications to LR must be undone
105-
// with |AARCH64_VALIDATE_LINK_REGISTER| before RET. The SP register must also
106-
// have the same value at the two points. For example:
107-
//
108-
// .global f
109-
// f:
110-
// AARCH64_SIGN_LINK_REGISTER
111-
// stp x29, x30, [sp, #-96]!
112-
// mov x29, sp
113-
// ...
114-
// ldp x29, x30, [sp], #96
115-
// AARCH64_VALIDATE_LINK_REGISTER
116-
// ret
117-
//
118-
// |AARCH64_VALID_CALL_TARGET| expands to BTI 'c'. Either it, or
119-
// |AARCH64_SIGN_LINK_REGISTER|, must be used at every point that may be an
120-
// indirect call target. In particular, all symbols exported from a file must
121-
// begin with one of these macros. For example, a leaf function that does not
122-
// save LR can instead use |AARCH64_VALID_CALL_TARGET|:
123-
//
124-
// .globl return_zero
125-
// return_zero:
126-
// AARCH64_VALID_CALL_TARGET
127-
// mov x0, #0
128-
// ret
129-
//
130-
// A non-leaf function which does not immediately save LR may need both macros
131-
// because |AARCH64_SIGN_LINK_REGISTER| appears late. For example, the function
132-
// may jump to an alternate implementation before setting up the stack:
133-
//
134-
// .globl with_early_jump
135-
// with_early_jump:
136-
// AARCH64_VALID_CALL_TARGET
137-
// cmp x0, #128
138-
// b.lt .Lwith_early_jump_128
139-
// AARCH64_SIGN_LINK_REGISTER
140-
// stp x29, x30, [sp, #-96]!
141-
// mov x29, sp
142-
// ...
143-
// ldp x29, x30, [sp], #96
144-
// AARCH64_VALIDATE_LINK_REGISTER
145-
// ret
146-
//
147-
// .Lwith_early_jump_128:
148-
// ...
149-
// ret
150-
//
151-
// These annotations are only required with indirect calls. Private symbols that
152-
// are only the target of direct calls do not require annotations. Also note
153-
// that |AARCH64_VALID_CALL_TARGET| is only valid for indirect calls (BLR), not
154-
// indirect jumps (BR). Indirect jumps in assembly are currently not supported
155-
// and would require a macro for BTI 'j'.
156-
//
157-
// Although not necessary, it is safe to use these macros in 32-bit ARM
158-
// assembly. This may be used to simplify dual 32-bit and 64-bit files.
159-
//
160-
// References:
161-
// - "ELF for the Arm® 64-bit Architecture"
162-
// https://github.com/ARM-software/abi-aa/blob/master/aaelf64/aaelf64.rst
163-
// - "Providing protection for complex software"
164-
// https://developer.arm.com/architectures/learn-the-architecture/providing-protection-for-complex-software
165-
166-
#if defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
167-
#define GNU_PROPERTY_AARCH64_BTI (1 << 0) // Has Branch Target Identification
168-
#define AARCH64_VALID_CALL_TARGET hint #34 // BTI 'c'
169-
#else
170-
#define GNU_PROPERTY_AARCH64_BTI 0 // No Branch Target Identification
171-
#define AARCH64_VALID_CALL_TARGET
172-
#endif
173-
174-
#if defined(__ARM_FEATURE_PAC_DEFAULT) && \
175-
(__ARM_FEATURE_PAC_DEFAULT & 1) == 1 // Signed with A-key
176-
#define GNU_PROPERTY_AARCH64_POINTER_AUTH \
177-
(1 << 1) // Has Pointer Authentication
178-
#define AARCH64_SIGN_LINK_REGISTER hint #25 // PACIASP
179-
#define AARCH64_VALIDATE_LINK_REGISTER hint #29 // AUTIASP
180-
#elif defined(__ARM_FEATURE_PAC_DEFAULT) && \
181-
(__ARM_FEATURE_PAC_DEFAULT & 2) == 2 // Signed with B-key
182-
#define GNU_PROPERTY_AARCH64_POINTER_AUTH \
183-
(1 << 1) // Has Pointer Authentication
184-
#define AARCH64_SIGN_LINK_REGISTER hint #27 // PACIBSP
185-
#define AARCH64_VALIDATE_LINK_REGISTER hint #31 // AUTIBSP
186-
#else
187-
#define GNU_PROPERTY_AARCH64_POINTER_AUTH 0 // No Pointer Authentication
188-
#if GNU_PROPERTY_AARCH64_BTI != 0
189-
#define AARCH64_SIGN_LINK_REGISTER AARCH64_VALID_CALL_TARGET
190-
#else
191-
#define AARCH64_SIGN_LINK_REGISTER
192-
#endif
193-
#define AARCH64_VALIDATE_LINK_REGISTER
194-
#endif
195-
196-
#if GNU_PROPERTY_AARCH64_POINTER_AUTH != 0 || GNU_PROPERTY_AARCH64_BTI != 0
197-
.pushsection .note.gnu.property, "a";
198-
.balign 8;
199-
.long 4;
200-
.long 0x10;
201-
.long 0x5;
202-
.asciz "GNU";
203-
.long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
204-
.long 4;
205-
.long (GNU_PROPERTY_AARCH64_POINTER_AUTH | GNU_PROPERTY_AARCH64_BTI);
206-
.long 0;
207-
.popsection;
208-
#endif
209-
21095
#endif // __ASSEMBLER__
21196

212-
#endif // __ARMEL__ || _M_ARM || __AARCH64EL__ || _M_ARM64
97+
#endif // ARM || AARCH64
21398

21499
#endif // OPENSSL_HEADER_ARM_ARCH_H

0 commit comments

Comments
 (0)