Skip to content

Commit 3c9f3b6

Browse files
minipli-osszx2c4
authored andcommitted
crypto: curve25519-x86_64: solve register constraints with reserved registers
The register constraints for the inline assembly in fsqr() and fsqr2() are pretty tight on what the compiler may assign to the remaining three register variables. The clobber list only allows the following to be used: RDI, RSI, RBP and R12. With RAP reserving R12 and a kernel having CONFIG_FRAME_POINTER=y, claiming RBP, there are only two registers left so the compiler rightfully complains about impossible constraints. Provide alternatives that'll allow a memory reference for 'out' to solve the allocation constraint dilemma for this configuration. Also make 'out' an input-only operand as it is only used as such. This not only allows gcc to optimize its usage further, but also works around older gcc versions, apparently failing to handle multiple alternatives correctly, as in failing to initialize the 'out' operand with its input value. Signed-off-by: Mathias Krause <minipli@grsecurity.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 8e40dd6 commit 3c9f3b6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/crypto/zinc/curve25519/curve25519-x86_64.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ static inline void fsqr(u64 *out, const u64 *f, u64 *tmp)
581581
" cmovc %%rdx, %%rax;"
582582
" add %%rax, %%r8;"
583583
" movq %%r8, 0(%0);"
584-
: "+&r" (tmp), "+&r" (f), "+&r" (out)
585-
:
584+
: "+&r,&r" (tmp), "+&r,&r" (f)
585+
: "r,m" (out)
586586
: "%rax", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r11", "%rbx", "%r13", "%r14", "%r15", "memory", "cc"
587587
);
588588
}
@@ -743,8 +743,8 @@ static inline void fsqr2(u64 *out, const u64 *f, u64 *tmp)
743743
" cmovc %%rdx, %%rax;"
744744
" add %%rax, %%r8;"
745745
" movq %%r8, 32(%0);"
746-
: "+&r" (tmp), "+&r" (f), "+&r" (out)
747-
:
746+
: "+&r,&r" (tmp), "+&r,&r" (f)
747+
: "r,m" (out)
748748
: "%rax", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r11", "%rbx", "%r13", "%r14", "%r15", "memory", "cc"
749749
);
750750
}

0 commit comments

Comments
 (0)