Skip to content

Commit f4857f4

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: arm64/sha - avoid non-standard inline asm tricks
Replace the inline asm which exports struct offsets as ELF symbols with proper const variables exposing the same values. This works around an issue with Clang which does not interpret the "i" (or "I") constraints in the same way as GCC. Signed-off-by: Ard Biesheuvel <[email protected]> Tested-by: Matthias Kaehlcke <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent ac50b78 commit f4857f4

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

arch/arm64/crypto/sha1-ce-core.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ ENTRY(sha1_ce_transform)
8282
ldr dgb, [x0, #16]
8383

8484
/* load sha1_ce_state::finalize */
85-
ldr w4, [x0, #:lo12:sha1_ce_offsetof_finalize]
85+
ldr_l w4, sha1_ce_offsetof_finalize, x4
86+
ldr w4, [x0, x4]
8687

8788
/* load input */
8889
0: ld1 {v8.4s-v11.4s}, [x1], #64
@@ -132,7 +133,8 @@ CPU_LE( rev32 v11.16b, v11.16b )
132133
* the padding is handled by the C code in that case.
133134
*/
134135
cbz x4, 3f
135-
ldr x4, [x0, #:lo12:sha1_ce_offsetof_count]
136+
ldr_l w4, sha1_ce_offsetof_count, x4
137+
ldr x4, [x0, x4]
136138
movi v9.2d, #0
137139
mov x8, #0x80000000
138140
movi v10.2d, #0

arch/arm64/crypto/sha1-ce-glue.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include <linux/crypto.h>
1818
#include <linux/module.h>
1919

20-
#define ASM_EXPORT(sym, val) \
21-
asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
22-
2320
MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
2421
MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
2522
MODULE_LICENSE("GPL v2");
@@ -32,6 +29,9 @@ struct sha1_ce_state {
3229
asmlinkage void sha1_ce_transform(struct sha1_ce_state *sst, u8 const *src,
3330
int blocks);
3431

32+
const u32 sha1_ce_offsetof_count = offsetof(struct sha1_ce_state, sst.count);
33+
const u32 sha1_ce_offsetof_finalize = offsetof(struct sha1_ce_state, finalize);
34+
3535
static int sha1_ce_update(struct shash_desc *desc, const u8 *data,
3636
unsigned int len)
3737
{
@@ -52,11 +52,6 @@ static int sha1_ce_finup(struct shash_desc *desc, const u8 *data,
5252
struct sha1_ce_state *sctx = shash_desc_ctx(desc);
5353
bool finalize = !sctx->sst.count && !(len % SHA1_BLOCK_SIZE);
5454

55-
ASM_EXPORT(sha1_ce_offsetof_count,
56-
offsetof(struct sha1_ce_state, sst.count));
57-
ASM_EXPORT(sha1_ce_offsetof_finalize,
58-
offsetof(struct sha1_ce_state, finalize));
59-
6055
/*
6156
* Allow the asm code to perform the finalization if there is no
6257
* partial data and the input is a round multiple of the block size.

arch/arm64/crypto/sha2-ce-core.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ ENTRY(sha2_ce_transform)
8888
ld1 {dgav.4s, dgbv.4s}, [x0]
8989

9090
/* load sha256_ce_state::finalize */
91-
ldr w4, [x0, #:lo12:sha256_ce_offsetof_finalize]
91+
ldr_l w4, sha256_ce_offsetof_finalize, x4
92+
ldr w4, [x0, x4]
9293

9394
/* load input */
9495
0: ld1 {v16.4s-v19.4s}, [x1], #64
@@ -136,7 +137,8 @@ CPU_LE( rev32 v19.16b, v19.16b )
136137
* the padding is handled by the C code in that case.
137138
*/
138139
cbz x4, 3f
139-
ldr x4, [x0, #:lo12:sha256_ce_offsetof_count]
140+
ldr_l w4, sha256_ce_offsetof_count, x4
141+
ldr x4, [x0, x4]
140142
movi v17.2d, #0
141143
mov x8, #0x80000000
142144
movi v18.2d, #0

arch/arm64/crypto/sha2-ce-glue.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include <linux/crypto.h>
1818
#include <linux/module.h>
1919

20-
#define ASM_EXPORT(sym, val) \
21-
asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
22-
2320
MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
2421
MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
2522
MODULE_LICENSE("GPL v2");
@@ -32,6 +29,11 @@ struct sha256_ce_state {
3229
asmlinkage void sha2_ce_transform(struct sha256_ce_state *sst, u8 const *src,
3330
int blocks);
3431

32+
const u32 sha256_ce_offsetof_count = offsetof(struct sha256_ce_state,
33+
sst.count);
34+
const u32 sha256_ce_offsetof_finalize = offsetof(struct sha256_ce_state,
35+
finalize);
36+
3537
static int sha256_ce_update(struct shash_desc *desc, const u8 *data,
3638
unsigned int len)
3739
{
@@ -52,11 +54,6 @@ static int sha256_ce_finup(struct shash_desc *desc, const u8 *data,
5254
struct sha256_ce_state *sctx = shash_desc_ctx(desc);
5355
bool finalize = !sctx->sst.count && !(len % SHA256_BLOCK_SIZE);
5456

55-
ASM_EXPORT(sha256_ce_offsetof_count,
56-
offsetof(struct sha256_ce_state, sst.count));
57-
ASM_EXPORT(sha256_ce_offsetof_finalize,
58-
offsetof(struct sha256_ce_state, finalize));
59-
6057
/*
6158
* Allow the asm code to perform the finalization if there is no
6259
* partial data and the input is a round multiple of the block size.

0 commit comments

Comments
 (0)