aboutsummaryrefslogtreecommitdiffstats
path: root/src/arch/arm64/include/bits/bigint.h
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2024-11-26 12:53:01 +0000
committerMichael Brown <mcb30@ipxe.org>2024-11-26 12:55:13 +0000
commit167a08f08928c7e469f50d5d364287abb784e99c (patch)
tree039a60c76e5da50dfe17cffb41c4491087c2c74f /src/arch/arm64/include/bits/bigint.h
parentda6da6eb3b83fe92002e9c8e245933498ba19a48 (diff)
downloadipxe-167a08f08928c7e469f50d5d364287abb784e99c.tar.gz
[crypto] Expose carry flag from big integer addition and subtraction
Expose the effective carry (or borrow) out flag from big integer addition and subtraction, and use this to elide an explicit bit test when performing x25519 reduction. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/arm64/include/bits/bigint.h')
-rw-r--r--src/arch/arm64/include/bits/bigint.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/arch/arm64/include/bits/bigint.h b/src/arch/arm64/include/bits/bigint.h
index 50493499e..5f79dc0c3 100644
--- a/src/arch/arm64/include/bits/bigint.h
+++ b/src/arch/arm64/include/bits/bigint.h
@@ -43,8 +43,9 @@ bigint_init_raw ( uint64_t *value0, unsigned int size,
* @v addend0 Element 0 of big integer to add
* @v value0 Element 0 of big integer to be added to
* @v size Number of elements
+ * @ret carry Carry out
*/
-static inline __attribute__ (( always_inline )) void
+static inline __attribute__ (( always_inline )) int
bigint_add_raw ( const uint64_t *addend0, uint64_t *value0,
unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
@@ -54,6 +55,7 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0,
uint64_t discard_addend_i;
uint64_t discard_value_i;
unsigned int discard_size;
+ int carry;
__asm__ __volatile__ ( "cmn xzr, xzr\n\t" /* clear CF */
"\n1:\n\t"
@@ -68,9 +70,11 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0,
"=r" ( discard_size ),
"=r" ( discard_addend_i ),
"=r" ( discard_value_i ),
+ "=@cccs" ( carry ),
"+m" ( *value )
- : "0" ( addend0 ), "1" ( value0 ), "2" ( size )
- : "cc" );
+ : "0" ( addend0 ), "1" ( value0 ),
+ "2" ( size ) );
+ return carry;
}
/**
@@ -79,8 +83,9 @@ bigint_add_raw ( const uint64_t *addend0, uint64_t *value0,
* @v subtrahend0 Element 0 of big integer to subtract
* @v value0 Element 0 of big integer to be subtracted from
* @v size Number of elements
+ * @ret borrow Borrow out
*/
-static inline __attribute__ (( always_inline )) void
+static inline __attribute__ (( always_inline )) int
bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0,
unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
@@ -90,6 +95,7 @@ bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0,
uint64_t discard_subtrahend_i;
uint64_t discard_value_i;
unsigned int discard_size;
+ int borrow;
__asm__ __volatile__ ( "cmp xzr, xzr\n\t" /* set CF */
"\n1:\n\t"
@@ -104,10 +110,11 @@ bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0,
"=r" ( discard_size ),
"=r" ( discard_subtrahend_i ),
"=r" ( discard_value_i ),
+ "=@cccc" ( borrow ),
"+m" ( *value )
: "0" ( subtrahend0 ), "1" ( value0 ),
- "2" ( size )
- : "cc" );
+ "2" ( size ) );
+ return borrow;
}
/**