Skip to content

Commit b918bad

Browse files
briansmithBoringssl LUCI CQ
authored andcommitted
bn: Change return type of bn_mul_mont_* internals to void.
Change-Id: Id8be6697df6a6f6613105c67c96250cc084595b2 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75647 Reviewed-by: Bob Beck <[email protected]> Commit-Queue: David Benjamin <[email protected]>
1 parent 6df79a6 commit b918bad

16 files changed

+130
-165
lines changed

crypto/fipsmodule/bn/asm/armv4-mont.pl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,9 @@
121121
bn_mul_mont_nohw:
122122
ldr ip,[sp,#4] @ load num
123123
stmdb sp!,{r0,r2} @ sp points at argument block
124-
cmp ip,#2
124+
@ No return value. Instead, the caller must ensure num >= 2
125125
mov $num,ip @ load num
126-
#ifdef __thumb2__
127-
ittt lt
128-
#endif
129-
movlt r0,#0
130-
addlt sp,sp,#2*4
131-
blt .Labrt
126+
@ No return value
132127
133128
stmdb sp!,{r4-r12,lr} @ save 10 registers
134129
@@ -262,8 +257,7 @@
262257
add sp,sp,#4 @ skip over tp[num+1]
263258
ldmia sp!,{r4-r12,lr} @ restore registers
264259
add sp,sp,#2*4 @ skip over {r0,r2}
265-
mov r0,#1
266-
.Labrt:
260+
@ No return value
267261
#if __ARM_ARCH>=5
268262
ret @ bx lr
269263
#else
@@ -717,6 +711,7 @@
717711
mov sp,ip
718712
vldmia sp!,{d8-d15}
719713
ldmia sp!,{r4-r11}
714+
@ No return value
720715
ret @ bx lr
721716
.size bn_mul8x_mont_neon,.-bn_mul8x_mont_neon
722717
#endif

crypto/fipsmodule/bn/asm/armv8-mont.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
$lo1,$hi1,$nj,$m1,$nlo,$nhi,
6161
$ovf, $i,$j,$tp,$tj) = map("x$_",6..17,19..24);
6262

63-
# int bn_mul_mont(
63+
# void bn_mul_mont(
6464
$rp="x0"; # BN_ULONG *rp,
6565
$ap="x1"; # const BN_ULONG *ap,
6666
$bp="x2"; # const BN_ULONG *bp,
@@ -270,7 +270,7 @@
270270
ldp x19,x20,[x29,#16]
271271
mov sp,x29
272272
ldp x21,x22,[x29,#32]
273-
mov x0,#1
273+
// No return value
274274
ldp x23,x24,[x29,#48]
275275
ldr x29,[sp],#64
276276
AARCH64_VALIDATE_LINK_REGISTER
@@ -1044,7 +1044,7 @@
10441044
ldp x19,x20,[x29,#16]
10451045
mov sp,x29
10461046
ldp x21,x22,[x29,#32]
1047-
mov x0,#1
1047+
// No return value
10481048
ldp x23,x24,[x29,#48]
10491049
ldp x25,x26,[x29,#64]
10501050
ldp x27,x28,[x29,#80]
@@ -1505,7 +1505,7 @@
15051505
ldp x19,x20,[x29,#16]
15061506
mov sp,x29
15071507
ldp x21,x22,[x29,#32]
1508-
mov x0,#1
1508+
// No return value
15091509
ldp x23,x24,[x29,#48]
15101510
ldp x25,x26,[x29,#64]
15111511
ldp x27,x28,[x29,#80]

crypto/fipsmodule/bn/asm/x86-mont.pl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@
6868
$_bpend=&DWP(4*7,"esp");
6969
$frame=32; # size of above frame rounded up to 16n
7070

71-
&xor ("eax","eax");
71+
# No return value. Instead, the caller must ensure num >= 4
7272
&mov ("edi",&wparam(5)); # int num
73-
&cmp ("edi",4);
74-
&jl (&label("just_leave"));
75-
73+
# No return value.
7674
&lea ("esi",&wparam(0)); # put aside pointer to argument block
7775
&lea ("edx",&wparam(1)); # load ap
7876
&add ("edi",2); # extra two words on top of tp
@@ -326,8 +324,7 @@
326324
&jge (&label("copy"));
327325

328326
&mov ("esp",$_sp); # pull saved stack pointer
329-
&mov ("eax",1);
330-
&set_label("just_leave");
327+
# No return value
331328
&function_end("bn_mul_mont");
332329

333330
&asciz("Montgomery Multiplication for x86, CRYPTOGAMS by <appro\@openssl.org>");

crypto/fipsmodule/bn/asm/x86_64-mont.pl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
# output, so this isn't useful anyway.
7171
$addx = 1;
7272

73-
# int bn_mul_mont_nohw(
73+
# void bn_mul_mont_nohw(
7474
$rp="%rdi"; # BN_ULONG *rp,
7575
$ap="%rsi"; # const BN_ULONG *ap,
7676
$bp="%rdx"; # const BN_ULONG *bp,
@@ -315,7 +315,7 @@
315315
316316
mov 8(%rsp,$num,8),%rsi # restore %rsp
317317
.cfi_def_cfa %rsi,8
318-
mov \$1,%rax
318+
# No return value
319319
mov -48(%rsi),%r15
320320
.cfi_restore %r15
321321
mov -40(%rsi),%r14
@@ -762,7 +762,7 @@
762762
$code.=<<___;
763763
mov 8(%rsp,$num,8),%rsi # restore %rsp
764764
.cfi_def_cfa %rsi, 8
765-
mov \$1,%rax
765+
# No return value
766766
mov -48(%rsi),%r15
767767
.cfi_restore %r15
768768
mov -40(%rsi),%r14
@@ -785,7 +785,7 @@
785785
}}}
786786
{{{
787787
######################################################################
788-
# int bn_sqr8x_mont(
788+
# void bn_sqr8x_mont(
789789
my $rptr="%rdi"; # const BN_ULONG *rptr,
790790
my $aptr="%rsi"; # const BN_ULONG *aptr,
791791
my $mulx_adx_capable="%rdx"; # Different than upstream!
@@ -976,7 +976,7 @@
976976
add \$32,$num
977977
jnz .Lsqr8x_cond_copy
978978
979-
mov \$1,%rax
979+
# No return value
980980
mov -48(%rsi),%r15
981981
.cfi_restore %r15
982982
mov -40(%rsi),%r14
@@ -1345,7 +1345,7 @@
13451345
13461346
mov %rdx,($tptr)
13471347
1348-
mov \$1,%rax
1348+
# No return value
13491349
mov -48(%rsi),%r15
13501350
.cfi_restore %r15
13511351
mov -40(%rsi),%r14

crypto/fipsmodule/bn/internal.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,14 @@ int bn_rand_secret_range(BIGNUM *r, int *out_is_uniform, BN_ULONG min_inclusive,
275275
#define OPENSSL_BN_ASM_MONT
276276
// bn_mul_mont writes |ap| * |bp| mod |np| to |rp|, each |num| words
277277
// long. Inputs and outputs are in Montgomery form. |n0| is a pointer to the
278-
// corresponding field in |BN_MONT_CTX|. It returns one if |bn_mul_mont| handles
279-
// inputs of this size and zero otherwise.
278+
// corresponding field in |BN_MONT_CTX|.
280279
//
281280
// If at least one of |ap| or |bp| is fully reduced, |rp| will be fully reduced.
282281
// If neither is fully-reduced, the output may not be either.
283282
//
284283
// This function allocates |num| words on the stack, so |num| should be at most
285-
// |BN_MONTGOMERY_MAX_WORDS|.
284+
// |BN_MONTGOMERY_MAX_WORDS|. Additionally, |num| must be at least 128 /
285+
// |BN_BITS2|.
286286
//
287287
// TODO(davidben): The x86_64 implementation expects a 32-bit input and masks
288288
// off upper bits. The aarch64 implementation expects a 64-bit input and does
@@ -291,39 +291,39 @@ int bn_rand_secret_range(BIGNUM *r, int *out_is_uniform, BN_ULONG min_inclusive,
291291
//
292292
// See also discussion in |ToWord| in abi_test.h for notes on smaller-than-word
293293
// inputs.
294-
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
295-
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
294+
void bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
295+
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
296296

297297
#if defined(OPENSSL_X86_64)
298298
inline int bn_mulx_adx_capable(void) {
299299
// MULX is in BMI2.
300300
return CRYPTO_is_BMI2_capable() && CRYPTO_is_ADX_capable();
301301
}
302-
int bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
303-
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
302+
void bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
303+
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
304304
inline int bn_mul4x_mont_capable(size_t num) {
305305
return num >= 8 && (num & 3) == 0;
306306
}
307-
int bn_mul4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
308-
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
307+
void bn_mul4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
308+
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
309309
inline int bn_mulx4x_mont_capable(size_t num) {
310310
return bn_mul4x_mont_capable(num) && bn_mulx_adx_capable();
311311
}
312-
int bn_mulx4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
313-
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
312+
void bn_mulx4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
313+
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
314314
inline int bn_sqr8x_mont_capable(size_t num) {
315315
return num >= 8 && (num & 7) == 0;
316316
}
317-
int bn_sqr8x_mont(BN_ULONG *rp, const BN_ULONG *ap, BN_ULONG mulx_adx_capable,
318-
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
317+
void bn_sqr8x_mont(BN_ULONG *rp, const BN_ULONG *ap, BN_ULONG mulx_adx_capable,
318+
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
319319
#elif defined(OPENSSL_ARM)
320320
inline int bn_mul8x_mont_neon_capable(size_t num) {
321321
return (num & 7) == 0 && CRYPTO_is_NEON_capable();
322322
}
323-
int bn_mul8x_mont_neon(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
324-
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
325-
int bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
326-
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
323+
void bn_mul8x_mont_neon(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
324+
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
325+
void bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
326+
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
327327
#endif
328328

329329
#endif // OPENSSL_BN_ASM_MONT

crypto/fipsmodule/bn/montgomery.cc.inc

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
324324
}
325325

326326
#if defined(OPENSSL_BN_ASM_MONT)
327-
// |bn_mul_mont| requires at least 128 bits of limbs, at least for x86.
327+
// |bn_mul_mont| requires at least 128 bits of limbs.
328328
int num = mont->N.width;
329329
if (num >= (128 / BN_BITS2) && a->width == num && b->width == num) {
330330
if (!bn_wexpand(r, num)) {
@@ -333,12 +333,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
333333
// This bound is implied by |bn_mont_ctx_set_N_and_n0|. |bn_mul_mont|
334334
// allocates |num| words on the stack, so |num| cannot be too large.
335335
assert((size_t)num <= BN_MONTGOMERY_MAX_WORDS);
336-
if (!bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {
337-
// The check above ensures this won't happen.
338-
assert(0);
339-
OPENSSL_PUT_ERROR(BN, ERR_R_INTERNAL_ERROR);
340-
return 0;
341-
}
336+
bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num);
342337
r->neg = 0;
343338
r->width = num;
344339
return 1;
@@ -379,11 +374,9 @@ void bn_mod_mul_montgomery_small(BN_ULONG *r, const BN_ULONG *a,
379374
}
380375

381376
#if defined(OPENSSL_BN_ASM_MONT)
382-
// |bn_mul_mont| requires at least 128 bits of limbs, at least for x86.
377+
// |bn_mul_mont| requires at least 128 bits of limbs.
383378
if (num >= (128 / BN_BITS2)) {
384-
if (!bn_mul_mont(r, a, b, mont->N.d, mont->n0, num)) {
385-
abort(); // The check above ensures this won't happen.
386-
}
379+
bn_mul_mont(r, a, b, mont->N.d, mont->n0, num);
387380
return;
388381
}
389382
#endif
@@ -404,27 +397,27 @@ void bn_mod_mul_montgomery_small(BN_ULONG *r, const BN_ULONG *a,
404397
}
405398

406399
#if defined(OPENSSL_BN_ASM_MONT) && defined(OPENSSL_X86_64)
407-
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
400+
void bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
408401
const BN_ULONG *np, const BN_ULONG *n0, size_t num) {
409402
if (ap == bp && bn_sqr8x_mont_capable(num)) {
410-
return bn_sqr8x_mont(rp, ap, bn_mulx_adx_capable(), np, n0, num);
411-
}
412-
if (bn_mulx4x_mont_capable(num)) {
413-
return bn_mulx4x_mont(rp, ap, bp, np, n0, num);
414-
}
415-
if (bn_mul4x_mont_capable(num)) {
416-
return bn_mul4x_mont(rp, ap, bp, np, n0, num);
403+
bn_sqr8x_mont(rp, ap, bn_mulx_adx_capable(), np, n0, num);
404+
} else if (bn_mulx4x_mont_capable(num)) {
405+
bn_mulx4x_mont(rp, ap, bp, np, n0, num);
406+
} else if (bn_mul4x_mont_capable(num)) {
407+
bn_mul4x_mont(rp, ap, bp, np, n0, num);
408+
} else {
409+
bn_mul_mont_nohw(rp, ap, bp, np, n0, num);
417410
}
418-
return bn_mul_mont_nohw(rp, ap, bp, np, n0, num);
419411
}
420412
#endif
421413

422414
#if defined(OPENSSL_BN_ASM_MONT) && defined(OPENSSL_ARM)
423-
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
424-
const BN_ULONG *np, const BN_ULONG *n0, size_t num) {
415+
void bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
416+
const BN_ULONG *np, const BN_ULONG *n0, size_t num) {
425417
if (bn_mul8x_mont_neon_capable(num)) {
426-
return bn_mul8x_mont_neon(rp, ap, bp, np, n0, num);
418+
bn_mul8x_mont_neon(rp, ap, bp, np, n0, num);
419+
} else {
420+
bn_mul_mont_nohw(rp, ap, bp, np, n0, num);
427421
}
428-
return bn_mul_mont_nohw(rp, ap, bp, np, n0, num);
429422
}
430423
#endif

gen/bcm/armv4-mont-linux.S

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
bn_mul_mont_nohw:
2525
ldr ip,[sp,#4] @ load num
2626
stmdb sp!,{r0,r2} @ sp points at argument block
27-
cmp ip,#2
27+
@ No return value. Instead, the caller must ensure num >= 2
2828
mov r0,ip @ load num
29-
#ifdef __thumb2__
30-
ittt lt
31-
#endif
32-
movlt r0,#0
33-
addlt sp,sp,#2*4
34-
blt .Labrt
29+
@ No return value
3530

3631
stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr} @ save 10 registers
3732

@@ -165,8 +160,7 @@ bn_mul_mont_nohw:
165160
add sp,sp,#4 @ skip over tp[num+1]
166161
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr} @ restore registers
167162
add sp,sp,#2*4 @ skip over {r0,r2}
168-
mov r0,#1
169-
.Labrt:
163+
@ No return value
170164
#if __ARM_ARCH>=5
171165
bx lr @ bx lr
172166
#else
@@ -929,6 +923,7 @@ bn_mul8x_mont_neon:
929923
mov sp,ip
930924
vldmia sp!,{d8,d9,d10,d11,d12,d13,d14,d15}
931925
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11}
926+
@ No return value
932927
bx lr @ bx lr
933928
.size bn_mul8x_mont_neon,.-bn_mul8x_mont_neon
934929
#endif

gen/bcm/armv8-mont-apple.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Lcond_copy:
206206
ldp x19,x20,[x29,#16]
207207
mov sp,x29
208208
ldp x21,x22,[x29,#32]
209-
mov x0,#1
209+
// No return value
210210
ldp x23,x24,[x29,#48]
211211
ldr x29,[sp],#64
212212
AARCH64_VALIDATE_LINK_REGISTER
@@ -965,7 +965,7 @@ Lsqr8x_done:
965965
ldp x19,x20,[x29,#16]
966966
mov sp,x29
967967
ldp x21,x22,[x29,#32]
968-
mov x0,#1
968+
// No return value
969969
ldp x23,x24,[x29,#48]
970970
ldp x25,x26,[x29,#64]
971971
ldp x27,x28,[x29,#80]
@@ -1408,7 +1408,7 @@ Lmul4x_done:
14081408
ldp x19,x20,[x29,#16]
14091409
mov sp,x29
14101410
ldp x21,x22,[x29,#32]
1411-
mov x0,#1
1411+
// No return value
14121412
ldp x23,x24,[x29,#48]
14131413
ldp x25,x26,[x29,#64]
14141414
ldp x27,x28,[x29,#80]

gen/bcm/armv8-mont-linux.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ bn_mul_mont:
206206
ldp x19,x20,[x29,#16]
207207
mov sp,x29
208208
ldp x21,x22,[x29,#32]
209-
mov x0,#1
209+
// No return value
210210
ldp x23,x24,[x29,#48]
211211
ldr x29,[sp],#64
212212
AARCH64_VALIDATE_LINK_REGISTER
@@ -965,7 +965,7 @@ __bn_sqr8x_mont:
965965
ldp x19,x20,[x29,#16]
966966
mov sp,x29
967967
ldp x21,x22,[x29,#32]
968-
mov x0,#1
968+
// No return value
969969
ldp x23,x24,[x29,#48]
970970
ldp x25,x26,[x29,#64]
971971
ldp x27,x28,[x29,#80]
@@ -1408,7 +1408,7 @@ __bn_mul4x_mont:
14081408
ldp x19,x20,[x29,#16]
14091409
mov sp,x29
14101410
ldp x21,x22,[x29,#32]
1411-
mov x0,#1
1411+
// No return value
14121412
ldp x23,x24,[x29,#48]
14131413
ldp x25,x26,[x29,#64]
14141414
ldp x27,x28,[x29,#80]

0 commit comments

Comments
 (0)