diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_local.h | 124 |
1 files changed, 2 insertions, 122 deletions
diff --git a/src/lib/libcrypto/bn/bn_local.h b/src/lib/libcrypto/bn/bn_local.h index 4ea54d2320..1830264fa2 100644 --- a/src/lib/libcrypto/bn/bn_local.h +++ b/src/lib/libcrypto/bn/bn_local.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_local.h,v 1.8 2023/02/09 09:16:26 jsing Exp $ */ | 1 | /* $OpenBSD: bn_local.h,v 1.9 2023/02/14 18:45:39 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -327,68 +327,7 @@ struct bn_gencb_st { | |||
| 327 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) | 327 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) |
| 328 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) | 328 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) |
| 329 | 329 | ||
| 330 | #ifdef BN_LLONG | 330 | #ifndef BN_LLONG |
| 331 | #define mul_add(r,a,w,c) { \ | ||
| 332 | BN_ULLONG t; \ | ||
| 333 | t=(BN_ULLONG)w * (a) + (r) + (c); \ | ||
| 334 | (r)= Lw(t); \ | ||
| 335 | (c)= Hw(t); \ | ||
| 336 | } | ||
| 337 | |||
| 338 | #define mul(r,a,w,c) { \ | ||
| 339 | BN_ULLONG t; \ | ||
| 340 | t=(BN_ULLONG)w * (a) + (c); \ | ||
| 341 | (r)= Lw(t); \ | ||
| 342 | (c)= Hw(t); \ | ||
| 343 | } | ||
| 344 | |||
| 345 | #elif defined(BN_UMULT_LOHI) | ||
| 346 | #define mul_add(r,a,w,c) { \ | ||
| 347 | BN_ULONG high,low,ret,tmp=(a); \ | ||
| 348 | ret = (r); \ | ||
| 349 | BN_UMULT_LOHI(low,high,w,tmp); \ | ||
| 350 | ret += (c); \ | ||
| 351 | (c) = (ret<(c))?1:0; \ | ||
| 352 | (c) += high; \ | ||
| 353 | ret += low; \ | ||
| 354 | (c) += (ret<low)?1:0; \ | ||
| 355 | (r) = ret; \ | ||
| 356 | } | ||
| 357 | |||
| 358 | #define mul(r,a,w,c) { \ | ||
| 359 | BN_ULONG high,low,ret,ta=(a); \ | ||
| 360 | BN_UMULT_LOHI(low,high,w,ta); \ | ||
| 361 | ret = low + (c); \ | ||
| 362 | (c) = high; \ | ||
| 363 | (c) += (ret<low)?1:0; \ | ||
| 364 | (r) = ret; \ | ||
| 365 | } | ||
| 366 | |||
| 367 | #elif defined(BN_UMULT_HIGH) | ||
| 368 | #define mul_add(r,a,w,c) { \ | ||
| 369 | BN_ULONG high,low,ret,tmp=(a); \ | ||
| 370 | ret = (r); \ | ||
| 371 | high= BN_UMULT_HIGH(w,tmp); \ | ||
| 372 | ret += (c); \ | ||
| 373 | low = (w) * tmp; \ | ||
| 374 | (c) = (ret<(c))?1:0; \ | ||
| 375 | (c) += high; \ | ||
| 376 | ret += low; \ | ||
| 377 | (c) += (ret<low)?1:0; \ | ||
| 378 | (r) = ret; \ | ||
| 379 | } | ||
| 380 | |||
| 381 | #define mul(r,a,w,c) { \ | ||
| 382 | BN_ULONG high,low,ret,ta=(a); \ | ||
| 383 | low = (w) * ta; \ | ||
| 384 | high= BN_UMULT_HIGH(w,ta); \ | ||
| 385 | ret = low + (c); \ | ||
| 386 | (c) = high; \ | ||
| 387 | (c) += (ret<low)?1:0; \ | ||
| 388 | (r) = ret; \ | ||
| 389 | } | ||
| 390 | |||
| 391 | #else | ||
| 392 | /************************************************************* | 331 | /************************************************************* |
| 393 | * No long long type | 332 | * No long long type |
| 394 | */ | 333 | */ |
| @@ -432,38 +371,8 @@ struct bn_gencb_st { | |||
| 432 | (ho)=h; \ | 371 | (ho)=h; \ |
| 433 | } | 372 | } |
| 434 | 373 | ||
| 435 | #define mul_add(r,a,bl,bh,c) { \ | ||
| 436 | BN_ULONG l,h; \ | ||
| 437 | \ | ||
| 438 | h= (a); \ | ||
| 439 | l=LBITS(h); \ | ||
| 440 | h=HBITS(h); \ | ||
| 441 | mul64(l,h,(bl),(bh)); \ | ||
| 442 | \ | ||
| 443 | /* non-multiply part */ \ | ||
| 444 | l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ | ||
| 445 | (c)=(r); \ | ||
| 446 | l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ | ||
| 447 | (c)=h&BN_MASK2; \ | ||
| 448 | (r)=l; \ | ||
| 449 | } | ||
| 450 | |||
| 451 | #define mul(r,a,bl,bh,c) { \ | ||
| 452 | BN_ULONG l,h; \ | ||
| 453 | \ | ||
| 454 | h= (a); \ | ||
| 455 | l=LBITS(h); \ | ||
| 456 | h=HBITS(h); \ | ||
| 457 | mul64(l,h,(bl),(bh)); \ | ||
| 458 | \ | ||
| 459 | /* non-multiply part */ \ | ||
| 460 | l+=(c); if ((l&BN_MASK2) < (c)) h++; \ | ||
| 461 | (c)=h&BN_MASK2; \ | ||
| 462 | (r)=l&BN_MASK2; \ | ||
| 463 | } | ||
| 464 | #endif /* !BN_LLONG */ | 374 | #endif /* !BN_LLONG */ |
| 465 | 375 | ||
| 466 | /* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */ | ||
| 467 | /* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */ | 376 | /* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */ |
| 468 | /* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */ | 377 | /* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */ |
| 469 | /* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */ | 378 | /* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */ |
| @@ -473,14 +382,6 @@ struct bn_gencb_st { | |||
| 473 | * Keep in mind that additions to multiplication result can not | 382 | * Keep in mind that additions to multiplication result can not |
| 474 | * overflow, because its high half cannot be all-ones. | 383 | * overflow, because its high half cannot be all-ones. |
| 475 | */ | 384 | */ |
| 476 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
| 477 | BN_ULONG hi; \ | ||
| 478 | BN_ULLONG t = (BN_ULLONG)(a)*(b); \ | ||
| 479 | t += c0; /* no carry */ \ | ||
| 480 | c0 = (BN_ULONG)Lw(t); \ | ||
| 481 | hi = (BN_ULONG)Hw(t); \ | ||
| 482 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
| 483 | } while(0) | ||
| 484 | 385 | ||
| 485 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | 386 | #define mul_add_c2(a,b,c0,c1,c2) do { \ |
| 486 | BN_ULONG hi; \ | 387 | BN_ULONG hi; \ |
| @@ -512,13 +413,6 @@ struct bn_gencb_st { | |||
| 512 | * Keep in mind that additions to hi can not overflow, because | 413 | * Keep in mind that additions to hi can not overflow, because |
| 513 | * the high word of a multiplication result cannot be all-ones. | 414 | * the high word of a multiplication result cannot be all-ones. |
| 514 | */ | 415 | */ |
| 515 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
| 516 | BN_ULONG ta = (a), tb = (b); \ | ||
| 517 | BN_ULONG lo, hi; \ | ||
| 518 | BN_UMULT_LOHI(lo,hi,ta,tb); \ | ||
| 519 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
| 520 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
| 521 | } while(0) | ||
| 522 | 416 | ||
| 523 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | 417 | #define mul_add_c2(a,b,c0,c1,c2) do { \ |
| 524 | BN_ULONG ta = (a), tb = (b); \ | 418 | BN_ULONG ta = (a), tb = (b); \ |
| @@ -546,13 +440,6 @@ struct bn_gencb_st { | |||
| 546 | * Keep in mind that additions to hi can not overflow, because | 440 | * Keep in mind that additions to hi can not overflow, because |
| 547 | * the high word of a multiplication result cannot be all-ones. | 441 | * the high word of a multiplication result cannot be all-ones. |
| 548 | */ | 442 | */ |
| 549 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
| 550 | BN_ULONG ta = (a), tb = (b); \ | ||
| 551 | BN_ULONG lo = ta * tb; \ | ||
| 552 | BN_ULONG hi = BN_UMULT_HIGH(ta,tb); \ | ||
| 553 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
| 554 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
| 555 | } while(0) | ||
| 556 | 443 | ||
| 557 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | 444 | #define mul_add_c2(a,b,c0,c1,c2) do { \ |
| 558 | BN_ULONG ta = (a), tb = (b), tt; \ | 445 | BN_ULONG ta = (a), tb = (b), tt; \ |
| @@ -580,13 +467,6 @@ struct bn_gencb_st { | |||
| 580 | * Keep in mind that additions to hi can not overflow, because | 467 | * Keep in mind that additions to hi can not overflow, because |
| 581 | * the high word of a multiplication result cannot be all-ones. | 468 | * the high word of a multiplication result cannot be all-ones. |
| 582 | */ | 469 | */ |
| 583 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
| 584 | BN_ULONG lo = LBITS(a), hi = HBITS(a); \ | ||
| 585 | BN_ULONG bl = LBITS(b), bh = HBITS(b); \ | ||
| 586 | mul64(lo,hi,bl,bh); \ | ||
| 587 | c0 = (c0+lo)&BN_MASK2; if (c0<lo) hi++; \ | ||
| 588 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
| 589 | } while(0) | ||
| 590 | 470 | ||
| 591 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | 471 | #define mul_add_c2(a,b,c0,c1,c2) do { \ |
| 592 | BN_ULONG tt; \ | 472 | BN_ULONG tt; \ |
