diff options
Diffstat (limited to '3rd_party/libsrp6a-sha512/t_math.c')
-rw-r--r-- | 3rd_party/libsrp6a-sha512/t_math.c | 103 |
1 files changed, 26 insertions, 77 deletions
diff --git a/3rd_party/libsrp6a-sha512/t_math.c b/3rd_party/libsrp6a-sha512/t_math.c index e655daa..166ee4c 100644 --- a/3rd_party/libsrp6a-sha512/t_math.c +++ b/3rd_party/libsrp6a-sha512/t_math.c | |||
@@ -99,8 +99,7 @@ typedef void * BigIntegerModAccel; | |||
99 | /* Math library interface stubs */ | 99 | /* Math library interface stubs */ |
100 | 100 | ||
101 | BigInteger | 101 | BigInteger |
102 | BigIntegerFromInt(n) | 102 | BigIntegerFromInt(unsigned int n) |
103 | unsigned int n; | ||
104 | { | 103 | { |
105 | #ifdef OPENSSL | 104 | #ifdef OPENSSL |
106 | BIGNUM * a = BN_new(); | 105 | BIGNUM * a = BN_new(); |
@@ -136,9 +135,7 @@ BigIntegerFromInt(n) | |||
136 | } | 135 | } |
137 | 136 | ||
138 | BigInteger | 137 | BigInteger |
139 | BigIntegerFromBytes(bytes, length) | 138 | BigIntegerFromBytes(const unsigned char *bytes, int length) |
140 | const unsigned char * bytes; | ||
141 | int length; | ||
142 | { | 139 | { |
143 | #ifdef OPENSSL | 140 | #ifdef OPENSSL |
144 | BIGNUM * a = BN_new(); | 141 | BIGNUM * a = BN_new(); |
@@ -206,10 +203,7 @@ BigIntegerFromBytes(bytes, length) | |||
206 | } | 203 | } |
207 | 204 | ||
208 | int | 205 | int |
209 | BigIntegerToBytes(src, dest, destlen) | 206 | BigIntegerToBytes(BigInteger src, unsigned char *dest, int destlen) |
210 | BigInteger src; | ||
211 | unsigned char * dest; | ||
212 | int destlen; | ||
213 | { | 207 | { |
214 | #ifdef OPENSSL | 208 | #ifdef OPENSSL |
215 | return BN_bn2bin(src, dest); | 209 | return BN_bn2bin(src, dest); |
@@ -290,10 +284,7 @@ BigIntegerToCstrEx(BigInteger x, cstr * out, int len) | |||
290 | } | 284 | } |
291 | 285 | ||
292 | BigIntegerResult | 286 | BigIntegerResult |
293 | BigIntegerToHex(src, dest, destlen) | 287 | BigIntegerToHex(BigInteger src, char *dest, int destlen) |
294 | BigInteger src; | ||
295 | char * dest; | ||
296 | int destlen; | ||
297 | { | 288 | { |
298 | #ifdef OPENSSL | 289 | #ifdef OPENSSL |
299 | strncpy(dest, BN_bn2hex(src), destlen); | 290 | strncpy(dest, BN_bn2hex(src), destlen); |
@@ -317,11 +308,7 @@ static char b64table[] = | |||
317 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./"; | 308 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./"; |
318 | 309 | ||
319 | BigIntegerResult | 310 | BigIntegerResult |
320 | BigIntegerToString(src, dest, destlen, radix) | 311 | BigIntegerToString(BigInteger src, char *dest, int destlen, unsigned int radix) |
321 | BigInteger src; | ||
322 | char * dest; | ||
323 | int destlen; | ||
324 | unsigned int radix; | ||
325 | { | 312 | { |
326 | BigInteger t = BigIntegerFromInt(0); | 313 | BigInteger t = BigIntegerFromInt(0); |
327 | char * p = dest; | 314 | char * p = dest; |
@@ -345,8 +332,7 @@ BigIntegerToString(src, dest, destlen, radix) | |||
345 | } | 332 | } |
346 | 333 | ||
347 | int | 334 | int |
348 | BigIntegerBitLen(b) | 335 | BigIntegerBitLen(BigInteger b) |
349 | BigInteger b; | ||
350 | { | 336 | { |
351 | #ifdef OPENSSL | 337 | #ifdef OPENSSL |
352 | return BN_num_bits(b); | 338 | return BN_num_bits(b); |
@@ -364,8 +350,7 @@ BigIntegerBitLen(b) | |||
364 | } | 350 | } |
365 | 351 | ||
366 | int | 352 | int |
367 | BigIntegerCmp(c1, c2) | 353 | BigIntegerCmp(BigInteger c1, BigInteger c2) |
368 | BigInteger c1, c2; | ||
369 | { | 354 | { |
370 | #ifdef OPENSSL | 355 | #ifdef OPENSSL |
371 | return BN_cmp(c1, c2); | 356 | return BN_cmp(c1, c2); |
@@ -383,9 +368,7 @@ BigIntegerCmp(c1, c2) | |||
383 | } | 368 | } |
384 | 369 | ||
385 | int | 370 | int |
386 | BigIntegerCmpInt(c1, c2) | 371 | BigIntegerCmpInt(BigInteger c1, unsigned int c2) |
387 | BigInteger c1; | ||
388 | unsigned int c2; | ||
389 | { | 372 | { |
390 | #ifdef OPENSSL | 373 | #ifdef OPENSSL |
391 | BigInteger bc2 = BigIntegerFromInt(c2); | 374 | BigInteger bc2 = BigIntegerFromInt(c2); |
@@ -414,9 +397,7 @@ BigIntegerCmpInt(c1, c2) | |||
414 | } | 397 | } |
415 | 398 | ||
416 | BigIntegerResult | 399 | BigIntegerResult |
417 | BigIntegerLShift(result, x, bits) | 400 | BigIntegerLShift(BigInteger result, BigInteger x, unsigned int bits) |
418 | BigInteger result, x; | ||
419 | unsigned int bits; | ||
420 | { | 401 | { |
421 | #ifdef OPENSSL | 402 | #ifdef OPENSSL |
422 | BN_lshift(result, x, bits); | 403 | BN_lshift(result, x, bits); |
@@ -436,8 +417,7 @@ BigIntegerLShift(result, x, bits) | |||
436 | } | 417 | } |
437 | 418 | ||
438 | BigIntegerResult | 419 | BigIntegerResult |
439 | BigIntegerAdd(result, a1, a2) | 420 | BigIntegerAdd(BigInteger result, BigInteger a1, BigInteger a2) |
440 | BigInteger result, a1, a2; | ||
441 | { | 421 | { |
442 | #ifdef OPENSSL | 422 | #ifdef OPENSSL |
443 | BN_add(result, a1, a2); | 423 | BN_add(result, a1, a2); |
@@ -456,9 +436,7 @@ BigIntegerAdd(result, a1, a2) | |||
456 | } | 436 | } |
457 | 437 | ||
458 | BigIntegerResult | 438 | BigIntegerResult |
459 | BigIntegerAddInt(result, a1, a2) | 439 | BigIntegerAddInt(BigInteger result, BigInteger a1, unsigned int a2) |
460 | BigInteger result, a1; | ||
461 | unsigned int a2; | ||
462 | { | 440 | { |
463 | #ifdef OPENSSL | 441 | #ifdef OPENSSL |
464 | if(result != a1) | 442 | if(result != a1) |
@@ -483,8 +461,7 @@ BigIntegerAddInt(result, a1, a2) | |||
483 | } | 461 | } |
484 | 462 | ||
485 | BigIntegerResult | 463 | BigIntegerResult |
486 | BigIntegerSub(result, s1, s2) | 464 | BigIntegerSub(BigInteger result, BigInteger s1, BigInteger s2) |
487 | BigInteger result, s1, s2; | ||
488 | { | 465 | { |
489 | #ifdef OPENSSL | 466 | #ifdef OPENSSL |
490 | BN_sub(result, s1, s2); | 467 | BN_sub(result, s1, s2); |
@@ -503,9 +480,7 @@ BigIntegerSub(result, s1, s2) | |||
503 | } | 480 | } |
504 | 481 | ||
505 | BigIntegerResult | 482 | BigIntegerResult |
506 | BigIntegerSubInt(result, s1, s2) | 483 | BigIntegerSubInt(BigInteger result, BigInteger s1, unsigned int s2) |
507 | BigInteger result, s1; | ||
508 | unsigned int s2; | ||
509 | { | 484 | { |
510 | #ifdef OPENSSL | 485 | #ifdef OPENSSL |
511 | if(result != s1) | 486 | if(result != s1) |
@@ -530,9 +505,7 @@ BigIntegerSubInt(result, s1, s2) | |||
530 | } | 505 | } |
531 | 506 | ||
532 | BigIntegerResult | 507 | BigIntegerResult |
533 | BigIntegerMul(result, m1, m2, c) | 508 | BigIntegerMul(BigInteger result, BigInteger m1, BigInteger m2, BigIntegerCtx c) |
534 | BigInteger result, m1, m2; | ||
535 | BigIntegerCtx c; | ||
536 | { | 509 | { |
537 | #ifdef OPENSSL | 510 | #ifdef OPENSSL |
538 | BN_CTX * ctx = NULL; | 511 | BN_CTX * ctx = NULL; |
@@ -556,10 +529,7 @@ BigIntegerMul(result, m1, m2, c) | |||
556 | } | 529 | } |
557 | 530 | ||
558 | BigIntegerResult | 531 | BigIntegerResult |
559 | BigIntegerMulInt(result, m1, m2, c) | 532 | BigIntegerMulInt(BigInteger result, BigInteger m1, unsigned int m2, BigIntegerCtx c) |
560 | BigInteger result, m1; | ||
561 | unsigned int m2; | ||
562 | BigIntegerCtx c; | ||
563 | { | 533 | { |
564 | #ifdef OPENSSL | 534 | #ifdef OPENSSL |
565 | if(result != m1) | 535 | if(result != m1) |
@@ -584,10 +554,7 @@ BigIntegerMulInt(result, m1, m2, c) | |||
584 | } | 554 | } |
585 | 555 | ||
586 | BigIntegerResult | 556 | BigIntegerResult |
587 | BigIntegerDivInt(result, d, m, c) | 557 | BigIntegerDivInt(BigInteger result, BigInteger d, unsigned int m, BigIntegerCtx c) |
588 | BigInteger result, d; | ||
589 | unsigned int m; | ||
590 | BigIntegerCtx c; | ||
591 | { | 558 | { |
592 | #ifdef OPENSSL | 559 | #ifdef OPENSSL |
593 | if(result != d) | 560 | if(result != d) |
@@ -624,9 +591,7 @@ BigIntegerDivInt(result, d, m, c) | |||
624 | } | 591 | } |
625 | 592 | ||
626 | BigIntegerResult | 593 | BigIntegerResult |
627 | BigIntegerMod(result, d, m, c) | 594 | BigIntegerMod(BigInteger result, BigInteger d, BigInteger m, BigIntegerCtx c) |
628 | BigInteger result, d, m; | ||
629 | BigIntegerCtx c; | ||
630 | { | 595 | { |
631 | #ifdef OPENSSL | 596 | #ifdef OPENSSL |
632 | BN_CTX * ctx = NULL; | 597 | BN_CTX * ctx = NULL; |
@@ -650,10 +615,7 @@ BigIntegerMod(result, d, m, c) | |||
650 | } | 615 | } |
651 | 616 | ||
652 | unsigned int | 617 | unsigned int |
653 | BigIntegerModInt(d, m, c) | 618 | BigIntegerModInt(BigInteger d, unsigned int m, BigIntegerCtx c) |
654 | BigInteger d; | ||
655 | unsigned int m; | ||
656 | BigIntegerCtx c; | ||
657 | { | 619 | { |
658 | #ifdef OPENSSL | 620 | #ifdef OPENSSL |
659 | return BN_mod_word(d, m); | 621 | return BN_mod_word(d, m); |
@@ -711,9 +673,7 @@ BigIntegerModInt(d, m, c) | |||
711 | } | 673 | } |
712 | 674 | ||
713 | BigIntegerResult | 675 | BigIntegerResult |
714 | BigIntegerModMul(r, m1, m2, modulus, c) | 676 | BigIntegerModMul(BigInteger r, BigInteger m1, BigInteger m2, BigInteger modulus, BigIntegerCtx c) |
715 | BigInteger r, m1, m2, modulus; | ||
716 | BigIntegerCtx c; | ||
717 | { | 677 | { |
718 | #ifdef OPENSSL | 678 | #ifdef OPENSSL |
719 | BN_CTX * ctx = NULL; | 679 | BN_CTX * ctx = NULL; |
@@ -743,10 +703,7 @@ BigIntegerModMul(r, m1, m2, modulus, c) | |||
743 | } | 703 | } |
744 | 704 | ||
745 | BigIntegerResult | 705 | BigIntegerResult |
746 | BigIntegerModExp(r, b, e, m, c, a) | 706 | BigIntegerModExp(BigInteger r, BigInteger b, BigInteger e, BigInteger m, BigIntegerCtx c, BigIntegerModAccel a) |
747 | BigInteger r, b, e, m; | ||
748 | BigIntegerCtx c; | ||
749 | BigIntegerModAccel a; | ||
750 | { | 707 | { |
751 | #ifdef OPENSSL | 708 | #ifdef OPENSSL |
752 | #if OPENSSL_VERSION_NUMBER >= 0x00906000 | 709 | #if OPENSSL_VERSION_NUMBER >= 0x00906000 |
@@ -793,9 +750,7 @@ int _mbedtls_f_rng(void* unused, unsigned char *buf, size_t size) | |||
793 | #endif | 750 | #endif |
794 | 751 | ||
795 | int | 752 | int |
796 | BigIntegerCheckPrime(n, c) | 753 | BigIntegerCheckPrime(BigInteger n, BigIntegerCtx c) |
797 | BigInteger n; | ||
798 | BigIntegerCtx c; | ||
799 | { | 754 | { |
800 | #ifdef OPENSSL | 755 | #ifdef OPENSSL |
801 | int rv; | 756 | int rv; |
@@ -846,8 +801,7 @@ BigIntegerCheckPrime(n, c) | |||
846 | } | 801 | } |
847 | 802 | ||
848 | BigIntegerResult | 803 | BigIntegerResult |
849 | BigIntegerFree(b) | 804 | BigIntegerFree(BigInteger b) |
850 | BigInteger b; | ||
851 | { | 805 | { |
852 | #ifdef OPENSSL | 806 | #ifdef OPENSSL |
853 | BN_free(b); | 807 | BN_free(b); |
@@ -869,8 +823,7 @@ BigIntegerFree(b) | |||
869 | } | 823 | } |
870 | 824 | ||
871 | BigIntegerResult | 825 | BigIntegerResult |
872 | BigIntegerClearFree(b) | 826 | BigIntegerClearFree(BigInteger b) |
873 | BigInteger b; | ||
874 | { | 827 | { |
875 | #ifdef OPENSSL | 828 | #ifdef OPENSSL |
876 | BN_clear_free(b); | 829 | BN_clear_free(b); |
@@ -906,8 +859,7 @@ BigIntegerCtxNew() | |||
906 | } | 859 | } |
907 | 860 | ||
908 | BigIntegerResult | 861 | BigIntegerResult |
909 | BigIntegerCtxFree(ctx) | 862 | BigIntegerCtxFree(BigIntegerCtx ctx) |
910 | BigIntegerCtx ctx; | ||
911 | { | 863 | { |
912 | #ifdef OPENSSL | 864 | #ifdef OPENSSL |
913 | if(ctx) | 865 | if(ctx) |
@@ -917,9 +869,7 @@ BigIntegerCtxFree(ctx) | |||
917 | } | 869 | } |
918 | 870 | ||
919 | BigIntegerModAccel | 871 | BigIntegerModAccel |
920 | BigIntegerModAccelNew(m, c) | 872 | BigIntegerModAccelNew(BigInteger m, BigIntegerCtx c) |
921 | BigInteger m; | ||
922 | BigIntegerCtx c; | ||
923 | { | 873 | { |
924 | #ifdef OPENSSL | 874 | #ifdef OPENSSL |
925 | BN_CTX * ctx = NULL; | 875 | BN_CTX * ctx = NULL; |
@@ -939,8 +889,7 @@ BigIntegerModAccelNew(m, c) | |||
939 | } | 889 | } |
940 | 890 | ||
941 | BigIntegerResult | 891 | BigIntegerResult |
942 | BigIntegerModAccelFree(accel) | 892 | BigIntegerModAccelFree(BigIntegerModAccel accel) |
943 | BigIntegerModAccel accel; | ||
944 | { | 893 | { |
945 | #ifdef OPENSSL | 894 | #ifdef OPENSSL |
946 | if(accel) | 895 | if(accel) |