comparison pre_gen/mpi.c @ 386:97db060d0ef5 libtommath-orig libtommath-0.40

Update to LibTomMath 0.40
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 03:11:15 +0000
parents 91fbc376f010
children
comparison
equal deleted inserted replaced
282:91fbc376f010 386:97db060d0ef5
11 * additional optimizations in place. 11 * additional optimizations in place.
12 * 12 *
13 * The library is free for all purposes without any express 13 * The library is free for all purposes without any express
14 * guarantee it works. 14 * guarantee it works.
15 * 15 *
16 * Tom St Denis, [email protected], http://math.libtomcrypt.org 16 * Tom St Denis, [email protected], http://math.libtomcrypt.com
17 */ 17 */
18 18
19 static const struct { 19 static const struct {
20 int code; 20 int code;
21 char *msg; 21 char *msg;
41 return "Invalid error code"; 41 return "Invalid error code";
42 } 42 }
43 43
44 #endif 44 #endif
45 45
46 /* $Source: /cvs/libtom/libtommath/bn_error.c,v $ */
47 /* $Revision: 1.3 $ */
48 /* $Date: 2006/03/31 14:18:44 $ */
49
46 /* End: bn_error.c */ 50 /* End: bn_error.c */
47 51
48 /* Start: bn_fast_mp_invmod.c */ 52 /* Start: bn_fast_mp_invmod.c */
49 #include <tommath.h> 53 #include <tommath.h>
50 #ifdef BN_FAST_MP_INVMOD_C 54 #ifdef BN_FAST_MP_INVMOD_C
58 * additional optimizations in place. 62 * additional optimizations in place.
59 * 63 *
60 * The library is free for all purposes without any express 64 * The library is free for all purposes without any express
61 * guarantee it works. 65 * guarantee it works.
62 * 66 *
63 * Tom St Denis, [email protected], http://math.libtomcrypt.org 67 * Tom St Denis, [email protected], http://math.libtomcrypt.com
64 */ 68 */
65 69
66 /* computes the modular inverse via binary extended euclidean algorithm, 70 /* computes the modular inverse via binary extended euclidean algorithm,
67 * that is c = 1/a mod b 71 * that is c = 1/a mod b
68 * 72 *
189 LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL); 193 LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
190 return res; 194 return res;
191 } 195 }
192 #endif 196 #endif
193 197
198 /* $Source: /cvs/libtom/libtommath/bn_fast_mp_invmod.c,v $ */
199 /* $Revision: 1.3 $ */
200 /* $Date: 2006/03/31 14:18:44 $ */
201
194 /* End: bn_fast_mp_invmod.c */ 202 /* End: bn_fast_mp_invmod.c */
195 203
196 /* Start: bn_fast_mp_montgomery_reduce.c */ 204 /* Start: bn_fast_mp_montgomery_reduce.c */
197 #include <tommath.h> 205 #include <tommath.h>
198 #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C 206 #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
206 * additional optimizations in place. 214 * additional optimizations in place.
207 * 215 *
208 * The library is free for all purposes without any express 216 * The library is free for all purposes without any express
209 * guarantee it works. 217 * guarantee it works.
210 * 218 *
211 * Tom St Denis, [email protected], http://math.libtomcrypt.org 219 * Tom St Denis, [email protected], http://math.libtomcrypt.com
212 */ 220 */
213 221
214 /* computes xR**-1 == x (mod N) via Montgomery Reduction 222 /* computes xR**-1 == x (mod N) via Montgomery Reduction
215 * 223 *
216 * This is an optimized implementation of montgomery_reduce 224 * This is an optimized implementation of montgomery_reduce
361 } 369 }
362 return MP_OKAY; 370 return MP_OKAY;
363 } 371 }
364 #endif 372 #endif
365 373
374 /* $Source: /cvs/libtom/libtommath/bn_fast_mp_montgomery_reduce.c,v $ */
375 /* $Revision: 1.3 $ */
376 /* $Date: 2006/03/31 14:18:44 $ */
377
366 /* End: bn_fast_mp_montgomery_reduce.c */ 378 /* End: bn_fast_mp_montgomery_reduce.c */
367 379
368 /* Start: bn_fast_s_mp_mul_digs.c */ 380 /* Start: bn_fast_s_mp_mul_digs.c */
369 #include <tommath.h> 381 #include <tommath.h>
370 #ifdef BN_FAST_S_MP_MUL_DIGS_C 382 #ifdef BN_FAST_S_MP_MUL_DIGS_C
378 * additional optimizations in place. 390 * additional optimizations in place.
379 * 391 *
380 * The library is free for all purposes without any express 392 * The library is free for all purposes without any express
381 * guarantee it works. 393 * guarantee it works.
382 * 394 *
383 * Tom St Denis, [email protected], http://math.libtomcrypt.org 395 * Tom St Denis, [email protected], http://math.libtomcrypt.com
384 */ 396 */
385 397
386 /* Fast (comba) multiplier 398 /* Fast (comba) multiplier
387 * 399 *
388 * This is the fast column-array [comba] multiplier. It is 400 * This is the fast column-array [comba] multiplier. It is
436 iy = MIN(a->used-tx, ty+1); 448 iy = MIN(a->used-tx, ty+1);
437 449
438 /* execute loop */ 450 /* execute loop */
439 for (iz = 0; iz < iy; ++iz) { 451 for (iz = 0; iz < iy; ++iz) {
440 _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--); 452 _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
453
441 } 454 }
442 455
443 /* store term */ 456 /* store term */
444 W[ix] = ((mp_digit)_W) & MP_MASK; 457 W[ix] = ((mp_digit)_W) & MP_MASK;
445 458
446 /* make next carry */ 459 /* make next carry */
447 _W = _W >> ((mp_word)DIGIT_BIT); 460 _W = _W >> ((mp_word)DIGIT_BIT);
448 } 461 }
449
450 /* store final carry */
451 W[ix] = (mp_digit)(_W & MP_MASK);
452 462
453 /* setup dest */ 463 /* setup dest */
454 olduse = c->used; 464 olduse = c->used;
455 c->used = pa; 465 c->used = pa;
456 466
470 mp_clamp (c); 480 mp_clamp (c);
471 return MP_OKAY; 481 return MP_OKAY;
472 } 482 }
473 #endif 483 #endif
474 484
485 /* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_digs.c,v $ */
486 /* $Revision: 1.7 $ */
487 /* $Date: 2006/03/31 14:18:44 $ */
488
475 /* End: bn_fast_s_mp_mul_digs.c */ 489 /* End: bn_fast_s_mp_mul_digs.c */
476 490
477 /* Start: bn_fast_s_mp_mul_high_digs.c */ 491 /* Start: bn_fast_s_mp_mul_high_digs.c */
478 #include <tommath.h> 492 #include <tommath.h>
479 #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C 493 #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
487 * additional optimizations in place. 501 * additional optimizations in place.
488 * 502 *
489 * The library is free for all purposes without any express 503 * The library is free for all purposes without any express
490 * guarantee it works. 504 * guarantee it works.
491 * 505 *
492 * Tom St Denis, [email protected], http://math.libtomcrypt.org 506 * Tom St Denis, [email protected], http://math.libtomcrypt.com
493 */ 507 */
494 508
495 /* this is a modified version of fast_s_mul_digs that only produces 509 /* this is a modified version of fast_s_mul_digs that only produces
496 * output digits *above* digs. See the comments for fast_s_mul_digs 510 * output digits *above* digs. See the comments for fast_s_mul_digs
497 * to see how it works. 511 * to see how it works.
545 559
546 /* make next carry */ 560 /* make next carry */
547 _W = _W >> ((mp_word)DIGIT_BIT); 561 _W = _W >> ((mp_word)DIGIT_BIT);
548 } 562 }
549 563
550 /* store final carry */
551 W[ix] = (mp_digit)(_W & MP_MASK);
552
553 /* setup dest */ 564 /* setup dest */
554 olduse = c->used; 565 olduse = c->used;
555 c->used = pa; 566 c->used = pa;
556 567
557 { 568 {
558 register mp_digit *tmpc; 569 register mp_digit *tmpc;
559 570
560 tmpc = c->dp + digs; 571 tmpc = c->dp + digs;
561 for (ix = digs; ix <= pa; ix++) { 572 for (ix = digs; ix < pa; ix++) {
562 /* now extract the previous digit [below the carry] */ 573 /* now extract the previous digit [below the carry] */
563 *tmpc++ = W[ix]; 574 *tmpc++ = W[ix];
564 } 575 }
565 576
566 /* clear unused digits [that existed in the old copy of c] */ 577 /* clear unused digits [that existed in the old copy of c] */
571 mp_clamp (c); 582 mp_clamp (c);
572 return MP_OKAY; 583 return MP_OKAY;
573 } 584 }
574 #endif 585 #endif
575 586
587 /* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_high_digs.c,v $ */
588 /* $Revision: 1.5 $ */
589 /* $Date: 2006/11/14 03:46:25 $ */
590
576 /* End: bn_fast_s_mp_mul_high_digs.c */ 591 /* End: bn_fast_s_mp_mul_high_digs.c */
577 592
578 /* Start: bn_fast_s_mp_sqr.c */ 593 /* Start: bn_fast_s_mp_sqr.c */
579 #include <tommath.h> 594 #include <tommath.h>
580 #ifdef BN_FAST_S_MP_SQR_C 595 #ifdef BN_FAST_S_MP_SQR_C
588 * additional optimizations in place. 603 * additional optimizations in place.
589 * 604 *
590 * The library is free for all purposes without any express 605 * The library is free for all purposes without any express
591 * guarantee it works. 606 * guarantee it works.
592 * 607 *
593 * Tom St Denis, [email protected], http://math.libtomcrypt.org 608 * Tom St Denis, [email protected], http://math.libtomcrypt.com
594 */ 609 */
595 610
596 /* the jist of squaring... 611 /* the jist of squaring...
597 * you do like mult except the offset of the tmpx [one that 612 * you do like mult except the offset of the tmpx [one that
598 * starts closer to zero] can't equal the offset of tmpy. 613 * starts closer to zero] can't equal the offset of tmpy.
685 mp_clamp (b); 700 mp_clamp (b);
686 return MP_OKAY; 701 return MP_OKAY;
687 } 702 }
688 #endif 703 #endif
689 704
705 /* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_sqr.c,v $ */
706 /* $Revision: 1.3 $ */
707 /* $Date: 2006/03/31 14:18:44 $ */
708
690 /* End: bn_fast_s_mp_sqr.c */ 709 /* End: bn_fast_s_mp_sqr.c */
691 710
692 /* Start: bn_mp_2expt.c */ 711 /* Start: bn_mp_2expt.c */
693 #include <tommath.h> 712 #include <tommath.h>
694 #ifdef BN_MP_2EXPT_C 713 #ifdef BN_MP_2EXPT_C
702 * additional optimizations in place. 721 * additional optimizations in place.
703 * 722 *
704 * The library is free for all purposes without any express 723 * The library is free for all purposes without any express
705 * guarantee it works. 724 * guarantee it works.
706 * 725 *
707 * Tom St Denis, [email protected], http://math.libtomcrypt.org 726 * Tom St Denis, [email protected], http://math.libtomcrypt.com
708 */ 727 */
709 728
710 /* computes a = 2**b 729 /* computes a = 2**b
711 * 730 *
712 * Simple algorithm which zeroes the int, grows it then just sets one bit 731 * Simple algorithm which zeroes the int, grows it then just sets one bit
733 752
734 return MP_OKAY; 753 return MP_OKAY;
735 } 754 }
736 #endif 755 #endif
737 756
757 /* $Source: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */
758 /* $Revision: 1.3 $ */
759 /* $Date: 2006/03/31 14:18:44 $ */
760
738 /* End: bn_mp_2expt.c */ 761 /* End: bn_mp_2expt.c */
739 762
740 /* Start: bn_mp_abs.c */ 763 /* Start: bn_mp_abs.c */
741 #include <tommath.h> 764 #include <tommath.h>
742 #ifdef BN_MP_ABS_C 765 #ifdef BN_MP_ABS_C
750 * additional optimizations in place. 773 * additional optimizations in place.
751 * 774 *
752 * The library is free for all purposes without any express 775 * The library is free for all purposes without any express
753 * guarantee it works. 776 * guarantee it works.
754 * 777 *
755 * Tom St Denis, [email protected], http://math.libtomcrypt.org 778 * Tom St Denis, [email protected], http://math.libtomcrypt.com
756 */ 779 */
757 780
758 /* b = |a| 781 /* b = |a|
759 * 782 *
760 * Simple function copies the input and fixes the sign to positive 783 * Simple function copies the input and fixes the sign to positive
776 799
777 return MP_OKAY; 800 return MP_OKAY;
778 } 801 }
779 #endif 802 #endif
780 803
804 /* $Source: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */
805 /* $Revision: 1.3 $ */
806 /* $Date: 2006/03/31 14:18:44 $ */
807
781 /* End: bn_mp_abs.c */ 808 /* End: bn_mp_abs.c */
782 809
783 /* Start: bn_mp_add.c */ 810 /* Start: bn_mp_add.c */
784 #include <tommath.h> 811 #include <tommath.h>
785 #ifdef BN_MP_ADD_C 812 #ifdef BN_MP_ADD_C
793 * additional optimizations in place. 820 * additional optimizations in place.
794 * 821 *
795 * The library is free for all purposes without any express 822 * The library is free for all purposes without any express
796 * guarantee it works. 823 * guarantee it works.
797 * 824 *
798 * Tom St Denis, [email protected], http://math.libtomcrypt.org 825 * Tom St Denis, [email protected], http://math.libtomcrypt.com
799 */ 826 */
800 827
801 /* high level addition (handles signs) */ 828 /* high level addition (handles signs) */
802 int mp_add (mp_int * a, mp_int * b, mp_int * c) 829 int mp_add (mp_int * a, mp_int * b, mp_int * c)
803 { 830 {
829 return res; 856 return res;
830 } 857 }
831 858
832 #endif 859 #endif
833 860
861 /* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */
862 /* $Revision: 1.3 $ */
863 /* $Date: 2006/03/31 14:18:44 $ */
864
834 /* End: bn_mp_add.c */ 865 /* End: bn_mp_add.c */
835 866
836 /* Start: bn_mp_add_d.c */ 867 /* Start: bn_mp_add_d.c */
837 #include <tommath.h> 868 #include <tommath.h>
838 #ifdef BN_MP_ADD_D_C 869 #ifdef BN_MP_ADD_D_C
846 * additional optimizations in place. 877 * additional optimizations in place.
847 * 878 *
848 * The library is free for all purposes without any express 879 * The library is free for all purposes without any express
849 * guarantee it works. 880 * guarantee it works.
850 * 881 *
851 * Tom St Denis, [email protected], http://math.libtomcrypt.org 882 * Tom St Denis, [email protected], http://math.libtomcrypt.com
852 */ 883 */
853 884
854 /* single digit addition */ 885 /* single digit addition */
855 int 886 int
856 mp_add_d (mp_int * a, mp_digit b, mp_int * c) 887 mp_add_d (mp_int * a, mp_digit b, mp_int * c)
873 /* c = |a| - b */ 904 /* c = |a| - b */
874 res = mp_sub_d(a, b, c); 905 res = mp_sub_d(a, b, c);
875 906
876 /* fix sign */ 907 /* fix sign */
877 a->sign = c->sign = MP_NEG; 908 a->sign = c->sign = MP_NEG;
909
910 /* clamp */
911 mp_clamp(c);
878 912
879 return res; 913 return res;
880 } 914 }
881 915
882 /* old number of used digits in c */ 916 /* old number of used digits in c */
938 return MP_OKAY; 972 return MP_OKAY;
939 } 973 }
940 974
941 #endif 975 #endif
942 976
977 /* $Source: /cvs/libtom/libtommath/bn_mp_add_d.c,v $ */
978 /* $Revision: 1.4 $ */
979 /* $Date: 2006/03/31 14:18:44 $ */
980
943 /* End: bn_mp_add_d.c */ 981 /* End: bn_mp_add_d.c */
944 982
945 /* Start: bn_mp_addmod.c */ 983 /* Start: bn_mp_addmod.c */
946 #include <tommath.h> 984 #include <tommath.h>
947 #ifdef BN_MP_ADDMOD_C 985 #ifdef BN_MP_ADDMOD_C
955 * additional optimizations in place. 993 * additional optimizations in place.
956 * 994 *
957 * The library is free for all purposes without any express 995 * The library is free for all purposes without any express
958 * guarantee it works. 996 * guarantee it works.
959 * 997 *
960 * Tom St Denis, [email protected], http://math.libtomcrypt.org 998 * Tom St Denis, [email protected], http://math.libtomcrypt.com
961 */ 999 */
962 1000
963 /* d = a + b (mod c) */ 1001 /* d = a + b (mod c) */
964 int 1002 int
965 mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 1003 mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
979 mp_clear (&t); 1017 mp_clear (&t);
980 return res; 1018 return res;
981 } 1019 }
982 #endif 1020 #endif
983 1021
1022 /* $Source: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */
1023 /* $Revision: 1.3 $ */
1024 /* $Date: 2006/03/31 14:18:44 $ */
1025
984 /* End: bn_mp_addmod.c */ 1026 /* End: bn_mp_addmod.c */
985 1027
986 /* Start: bn_mp_and.c */ 1028 /* Start: bn_mp_and.c */
987 #include <tommath.h> 1029 #include <tommath.h>
988 #ifdef BN_MP_AND_C 1030 #ifdef BN_MP_AND_C
996 * additional optimizations in place. 1038 * additional optimizations in place.
997 * 1039 *
998 * The library is free for all purposes without any express 1040 * The library is free for all purposes without any express
999 * guarantee it works. 1041 * guarantee it works.
1000 * 1042 *
1001 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1043 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1002 */ 1044 */
1003 1045
1004 /* AND two ints together */ 1046 /* AND two ints together */
1005 int 1047 int
1006 mp_and (mp_int * a, mp_int * b, mp_int * c) 1048 mp_and (mp_int * a, mp_int * b, mp_int * c)
1036 mp_clear (&t); 1078 mp_clear (&t);
1037 return MP_OKAY; 1079 return MP_OKAY;
1038 } 1080 }
1039 #endif 1081 #endif
1040 1082
1083 /* $Source: /cvs/libtom/libtommath/bn_mp_and.c,v $ */
1084 /* $Revision: 1.3 $ */
1085 /* $Date: 2006/03/31 14:18:44 $ */
1086
1041 /* End: bn_mp_and.c */ 1087 /* End: bn_mp_and.c */
1042 1088
1043 /* Start: bn_mp_clamp.c */ 1089 /* Start: bn_mp_clamp.c */
1044 #include <tommath.h> 1090 #include <tommath.h>
1045 #ifdef BN_MP_CLAMP_C 1091 #ifdef BN_MP_CLAMP_C
1053 * additional optimizations in place. 1099 * additional optimizations in place.
1054 * 1100 *
1055 * The library is free for all purposes without any express 1101 * The library is free for all purposes without any express
1056 * guarantee it works. 1102 * guarantee it works.
1057 * 1103 *
1058 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1104 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1059 */ 1105 */
1060 1106
1061 /* trim unused digits 1107 /* trim unused digits
1062 * 1108 *
1063 * This is used to ensure that leading zero digits are 1109 * This is used to ensure that leading zero digits are
1080 a->sign = MP_ZPOS; 1126 a->sign = MP_ZPOS;
1081 } 1127 }
1082 } 1128 }
1083 #endif 1129 #endif
1084 1130
1131 /* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */
1132 /* $Revision: 1.3 $ */
1133 /* $Date: 2006/03/31 14:18:44 $ */
1134
1085 /* End: bn_mp_clamp.c */ 1135 /* End: bn_mp_clamp.c */
1086 1136
1087 /* Start: bn_mp_clear.c */ 1137 /* Start: bn_mp_clear.c */
1088 #include <tommath.h> 1138 #include <tommath.h>
1089 #ifdef BN_MP_CLEAR_C 1139 #ifdef BN_MP_CLEAR_C
1097 * additional optimizations in place. 1147 * additional optimizations in place.
1098 * 1148 *
1099 * The library is free for all purposes without any express 1149 * The library is free for all purposes without any express
1100 * guarantee it works. 1150 * guarantee it works.
1101 * 1151 *
1102 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1152 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1103 */ 1153 */
1104 1154
1105 /* clear one (frees) */ 1155 /* clear one (frees) */
1106 void 1156 void
1107 mp_clear (mp_int * a) 1157 mp_clear (mp_int * a)
1124 a->sign = MP_ZPOS; 1174 a->sign = MP_ZPOS;
1125 } 1175 }
1126 } 1176 }
1127 #endif 1177 #endif
1128 1178
1179 /* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */
1180 /* $Revision: 1.3 $ */
1181 /* $Date: 2006/03/31 14:18:44 $ */
1182
1129 /* End: bn_mp_clear.c */ 1183 /* End: bn_mp_clear.c */
1130 1184
1131 /* Start: bn_mp_clear_multi.c */ 1185 /* Start: bn_mp_clear_multi.c */
1132 #include <tommath.h> 1186 #include <tommath.h>
1133 #ifdef BN_MP_CLEAR_MULTI_C 1187 #ifdef BN_MP_CLEAR_MULTI_C
1141 * additional optimizations in place. 1195 * additional optimizations in place.
1142 * 1196 *
1143 * The library is free for all purposes without any express 1197 * The library is free for all purposes without any express
1144 * guarantee it works. 1198 * guarantee it works.
1145 * 1199 *
1146 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1200 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1147 */ 1201 */
1148 #include <stdarg.h> 1202 #include <stdarg.h>
1149 1203
1150 void mp_clear_multi(mp_int *mp, ...) 1204 void mp_clear_multi(mp_int *mp, ...)
1151 { 1205 {
1158 } 1212 }
1159 va_end(args); 1213 va_end(args);
1160 } 1214 }
1161 #endif 1215 #endif
1162 1216
1217 /* $Source: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */
1218 /* $Revision: 1.3 $ */
1219 /* $Date: 2006/03/31 14:18:44 $ */
1220
1163 /* End: bn_mp_clear_multi.c */ 1221 /* End: bn_mp_clear_multi.c */
1164 1222
1165 /* Start: bn_mp_cmp.c */ 1223 /* Start: bn_mp_cmp.c */
1166 #include <tommath.h> 1224 #include <tommath.h>
1167 #ifdef BN_MP_CMP_C 1225 #ifdef BN_MP_CMP_C
1175 * additional optimizations in place. 1233 * additional optimizations in place.
1176 * 1234 *
1177 * The library is free for all purposes without any express 1235 * The library is free for all purposes without any express
1178 * guarantee it works. 1236 * guarantee it works.
1179 * 1237 *
1180 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1238 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1181 */ 1239 */
1182 1240
1183 /* compare two ints (signed)*/ 1241 /* compare two ints (signed)*/
1184 int 1242 int
1185 mp_cmp (mp_int * a, mp_int * b) 1243 mp_cmp (mp_int * a, mp_int * b)
1201 return mp_cmp_mag(a, b); 1259 return mp_cmp_mag(a, b);
1202 } 1260 }
1203 } 1261 }
1204 #endif 1262 #endif
1205 1263
1264 /* $Source: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */
1265 /* $Revision: 1.3 $ */
1266 /* $Date: 2006/03/31 14:18:44 $ */
1267
1206 /* End: bn_mp_cmp.c */ 1268 /* End: bn_mp_cmp.c */
1207 1269
1208 /* Start: bn_mp_cmp_d.c */ 1270 /* Start: bn_mp_cmp_d.c */
1209 #include <tommath.h> 1271 #include <tommath.h>
1210 #ifdef BN_MP_CMP_D_C 1272 #ifdef BN_MP_CMP_D_C
1218 * additional optimizations in place. 1280 * additional optimizations in place.
1219 * 1281 *
1220 * The library is free for all purposes without any express 1282 * The library is free for all purposes without any express
1221 * guarantee it works. 1283 * guarantee it works.
1222 * 1284 *
1223 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1285 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1224 */ 1286 */
1225 1287
1226 /* compare a digit */ 1288 /* compare a digit */
1227 int mp_cmp_d(mp_int * a, mp_digit b) 1289 int mp_cmp_d(mp_int * a, mp_digit b)
1228 { 1290 {
1245 return MP_EQ; 1307 return MP_EQ;
1246 } 1308 }
1247 } 1309 }
1248 #endif 1310 #endif
1249 1311
1312 /* $Source: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v $ */
1313 /* $Revision: 1.3 $ */
1314 /* $Date: 2006/03/31 14:18:44 $ */
1315
1250 /* End: bn_mp_cmp_d.c */ 1316 /* End: bn_mp_cmp_d.c */
1251 1317
1252 /* Start: bn_mp_cmp_mag.c */ 1318 /* Start: bn_mp_cmp_mag.c */
1253 #include <tommath.h> 1319 #include <tommath.h>
1254 #ifdef BN_MP_CMP_MAG_C 1320 #ifdef BN_MP_CMP_MAG_C
1262 * additional optimizations in place. 1328 * additional optimizations in place.
1263 * 1329 *
1264 * The library is free for all purposes without any express 1330 * The library is free for all purposes without any express
1265 * guarantee it works. 1331 * guarantee it works.
1266 * 1332 *
1267 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1333 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1268 */ 1334 */
1269 1335
1270 /* compare maginitude of two ints (unsigned) */ 1336 /* compare maginitude of two ints (unsigned) */
1271 int mp_cmp_mag (mp_int * a, mp_int * b) 1337 int mp_cmp_mag (mp_int * a, mp_int * b)
1272 { 1338 {
1300 } 1366 }
1301 return MP_EQ; 1367 return MP_EQ;
1302 } 1368 }
1303 #endif 1369 #endif
1304 1370
1371 /* $Source: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */
1372 /* $Revision: 1.3 $ */
1373 /* $Date: 2006/03/31 14:18:44 $ */
1374
1305 /* End: bn_mp_cmp_mag.c */ 1375 /* End: bn_mp_cmp_mag.c */
1306 1376
1307 /* Start: bn_mp_cnt_lsb.c */ 1377 /* Start: bn_mp_cnt_lsb.c */
1308 #include <tommath.h> 1378 #include <tommath.h>
1309 #ifdef BN_MP_CNT_LSB_C 1379 #ifdef BN_MP_CNT_LSB_C
1317 * additional optimizations in place. 1387 * additional optimizations in place.
1318 * 1388 *
1319 * The library is free for all purposes without any express 1389 * The library is free for all purposes without any express
1320 * guarantee it works. 1390 * guarantee it works.
1321 * 1391 *
1322 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1392 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1323 */ 1393 */
1324 1394
1325 static const int lnz[16] = { 1395 static const int lnz[16] = {
1326 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 1396 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
1327 }; 1397 };
1353 return x; 1423 return x;
1354 } 1424 }
1355 1425
1356 #endif 1426 #endif
1357 1427
1428 /* $Source: /cvs/libtom/libtommath/bn_mp_cnt_lsb.c,v $ */
1429 /* $Revision: 1.3 $ */
1430 /* $Date: 2006/03/31 14:18:44 $ */
1431
1358 /* End: bn_mp_cnt_lsb.c */ 1432 /* End: bn_mp_cnt_lsb.c */
1359 1433
1360 /* Start: bn_mp_copy.c */ 1434 /* Start: bn_mp_copy.c */
1361 #include <tommath.h> 1435 #include <tommath.h>
1362 #ifdef BN_MP_COPY_C 1436 #ifdef BN_MP_COPY_C
1370 * additional optimizations in place. 1444 * additional optimizations in place.
1371 * 1445 *
1372 * The library is free for all purposes without any express 1446 * The library is free for all purposes without any express
1373 * guarantee it works. 1447 * guarantee it works.
1374 * 1448 *
1375 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1449 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1376 */ 1450 */
1377 1451
1378 /* copy, b = a */ 1452 /* copy, b = a */
1379 int 1453 int
1380 mp_copy (mp_int * a, mp_int * b) 1454 mp_copy (mp_int * a, mp_int * b)
1421 b->sign = a->sign; 1495 b->sign = a->sign;
1422 return MP_OKAY; 1496 return MP_OKAY;
1423 } 1497 }
1424 #endif 1498 #endif
1425 1499
1500 /* $Source: /cvs/libtom/libtommath/bn_mp_copy.c,v $ */
1501 /* $Revision: 1.3 $ */
1502 /* $Date: 2006/03/31 14:18:44 $ */
1503
1426 /* End: bn_mp_copy.c */ 1504 /* End: bn_mp_copy.c */
1427 1505
1428 /* Start: bn_mp_count_bits.c */ 1506 /* Start: bn_mp_count_bits.c */
1429 #include <tommath.h> 1507 #include <tommath.h>
1430 #ifdef BN_MP_COUNT_BITS_C 1508 #ifdef BN_MP_COUNT_BITS_C
1438 * additional optimizations in place. 1516 * additional optimizations in place.
1439 * 1517 *
1440 * The library is free for all purposes without any express 1518 * The library is free for all purposes without any express
1441 * guarantee it works. 1519 * guarantee it works.
1442 * 1520 *
1443 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1521 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1444 */ 1522 */
1445 1523
1446 /* returns the number of bits in an int */ 1524 /* returns the number of bits in an int */
1447 int 1525 int
1448 mp_count_bits (mp_int * a) 1526 mp_count_bits (mp_int * a)
1466 } 1544 }
1467 return r; 1545 return r;
1468 } 1546 }
1469 #endif 1547 #endif
1470 1548
1549 /* $Source: /cvs/libtom/libtommath/bn_mp_count_bits.c,v $ */
1550 /* $Revision: 1.3 $ */
1551 /* $Date: 2006/03/31 14:18:44 $ */
1552
1471 /* End: bn_mp_count_bits.c */ 1553 /* End: bn_mp_count_bits.c */
1472 1554
1473 /* Start: bn_mp_div.c */ 1555 /* Start: bn_mp_div.c */
1474 #include <tommath.h> 1556 #include <tommath.h>
1475 #ifdef BN_MP_DIV_C 1557 #ifdef BN_MP_DIV_C
1483 * additional optimizations in place. 1565 * additional optimizations in place.
1484 * 1566 *
1485 * The library is free for all purposes without any express 1567 * The library is free for all purposes without any express
1486 * guarantee it works. 1568 * guarantee it works.
1487 * 1569 *
1488 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1570 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1489 */ 1571 */
1490 1572
1491 #ifdef BN_MP_DIV_SMALL 1573 #ifdef BN_MP_DIV_SMALL
1492 1574
1493 /* slower bit-bang division... also smaller */ 1575 /* slower bit-bang division... also smaller */
1758 1840
1759 #endif 1841 #endif
1760 1842
1761 #endif 1843 #endif
1762 1844
1845 /* $Source: /cvs/libtom/libtommath/bn_mp_div.c,v $ */
1846 /* $Revision: 1.3 $ */
1847 /* $Date: 2006/03/31 14:18:44 $ */
1848
1763 /* End: bn_mp_div.c */ 1849 /* End: bn_mp_div.c */
1764 1850
1765 /* Start: bn_mp_div_2.c */ 1851 /* Start: bn_mp_div_2.c */
1766 #include <tommath.h> 1852 #include <tommath.h>
1767 #ifdef BN_MP_DIV_2_C 1853 #ifdef BN_MP_DIV_2_C
1775 * additional optimizations in place. 1861 * additional optimizations in place.
1776 * 1862 *
1777 * The library is free for all purposes without any express 1863 * The library is free for all purposes without any express
1778 * guarantee it works. 1864 * guarantee it works.
1779 * 1865 *
1780 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1866 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1781 */ 1867 */
1782 1868
1783 /* b = a/2 */ 1869 /* b = a/2 */
1784 int mp_div_2(mp_int * a, mp_int * b) 1870 int mp_div_2(mp_int * a, mp_int * b)
1785 { 1871 {
1826 mp_clamp (b); 1912 mp_clamp (b);
1827 return MP_OKAY; 1913 return MP_OKAY;
1828 } 1914 }
1829 #endif 1915 #endif
1830 1916
1917 /* $Source: /cvs/libtom/libtommath/bn_mp_div_2.c,v $ */
1918 /* $Revision: 1.3 $ */
1919 /* $Date: 2006/03/31 14:18:44 $ */
1920
1831 /* End: bn_mp_div_2.c */ 1921 /* End: bn_mp_div_2.c */
1832 1922
1833 /* Start: bn_mp_div_2d.c */ 1923 /* Start: bn_mp_div_2d.c */
1834 #include <tommath.h> 1924 #include <tommath.h>
1835 #ifdef BN_MP_DIV_2D_C 1925 #ifdef BN_MP_DIV_2D_C
1843 * additional optimizations in place. 1933 * additional optimizations in place.
1844 * 1934 *
1845 * The library is free for all purposes without any express 1935 * The library is free for all purposes without any express
1846 * guarantee it works. 1936 * guarantee it works.
1847 * 1937 *
1848 * Tom St Denis, [email protected], http://math.libtomcrypt.org 1938 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1849 */ 1939 */
1850 1940
1851 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ 1941 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */
1852 int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) 1942 int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
1853 { 1943 {
1923 mp_clear (&t); 2013 mp_clear (&t);
1924 return MP_OKAY; 2014 return MP_OKAY;
1925 } 2015 }
1926 #endif 2016 #endif
1927 2017
2018 /* $Source: /cvs/libtom/libtommath/bn_mp_div_2d.c,v $ */
2019 /* $Revision: 1.3 $ */
2020 /* $Date: 2006/03/31 14:18:44 $ */
2021
1928 /* End: bn_mp_div_2d.c */ 2022 /* End: bn_mp_div_2d.c */
1929 2023
1930 /* Start: bn_mp_div_3.c */ 2024 /* Start: bn_mp_div_3.c */
1931 #include <tommath.h> 2025 #include <tommath.h>
1932 #ifdef BN_MP_DIV_3_C 2026 #ifdef BN_MP_DIV_3_C
1940 * additional optimizations in place. 2034 * additional optimizations in place.
1941 * 2035 *
1942 * The library is free for all purposes without any express 2036 * The library is free for all purposes without any express
1943 * guarantee it works. 2037 * guarantee it works.
1944 * 2038 *
1945 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2039 * Tom St Denis, [email protected], http://math.libtomcrypt.com
1946 */ 2040 */
1947 2041
1948 /* divide by three (based on routine from MPI and the GMP manual) */ 2042 /* divide by three (based on routine from MPI and the GMP manual) */
1949 int 2043 int
1950 mp_div_3 (mp_int * a, mp_int *c, mp_digit * d) 2044 mp_div_3 (mp_int * a, mp_int *c, mp_digit * d)
2002 return res; 2096 return res;
2003 } 2097 }
2004 2098
2005 #endif 2099 #endif
2006 2100
2101 /* $Source: /cvs/libtom/libtommath/bn_mp_div_3.c,v $ */
2102 /* $Revision: 1.3 $ */
2103 /* $Date: 2006/03/31 14:18:44 $ */
2104
2007 /* End: bn_mp_div_3.c */ 2105 /* End: bn_mp_div_3.c */
2008 2106
2009 /* Start: bn_mp_div_d.c */ 2107 /* Start: bn_mp_div_d.c */
2010 #include <tommath.h> 2108 #include <tommath.h>
2011 #ifdef BN_MP_DIV_D_C 2109 #ifdef BN_MP_DIV_D_C
2019 * additional optimizations in place. 2117 * additional optimizations in place.
2020 * 2118 *
2021 * The library is free for all purposes without any express 2119 * The library is free for all purposes without any express
2022 * guarantee it works. 2120 * guarantee it works.
2023 * 2121 *
2024 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2122 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2025 */ 2123 */
2026 2124
2027 static int s_is_power_of_two(mp_digit b, int *p) 2125 static int s_is_power_of_two(mp_digit b, int *p)
2028 { 2126 {
2029 int x; 2127 int x;
2112 return res; 2210 return res;
2113 } 2211 }
2114 2212
2115 #endif 2213 #endif
2116 2214
2215 /* $Source: /cvs/libtom/libtommath/bn_mp_div_d.c,v $ */
2216 /* $Revision: 1.3 $ */
2217 /* $Date: 2006/03/31 14:18:44 $ */
2218
2117 /* End: bn_mp_div_d.c */ 2219 /* End: bn_mp_div_d.c */
2118 2220
2119 /* Start: bn_mp_dr_is_modulus.c */ 2221 /* Start: bn_mp_dr_is_modulus.c */
2120 #include <tommath.h> 2222 #include <tommath.h>
2121 #ifdef BN_MP_DR_IS_MODULUS_C 2223 #ifdef BN_MP_DR_IS_MODULUS_C
2129 * additional optimizations in place. 2231 * additional optimizations in place.
2130 * 2232 *
2131 * The library is free for all purposes without any express 2233 * The library is free for all purposes without any express
2132 * guarantee it works. 2234 * guarantee it works.
2133 * 2235 *
2134 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2236 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2135 */ 2237 */
2136 2238
2137 /* determines if a number is a valid DR modulus */ 2239 /* determines if a number is a valid DR modulus */
2138 int mp_dr_is_modulus(mp_int *a) 2240 int mp_dr_is_modulus(mp_int *a)
2139 { 2241 {
2155 return 1; 2257 return 1;
2156 } 2258 }
2157 2259
2158 #endif 2260 #endif
2159 2261
2262 /* $Source: /cvs/libtom/libtommath/bn_mp_dr_is_modulus.c,v $ */
2263 /* $Revision: 1.3 $ */
2264 /* $Date: 2006/03/31 14:18:44 $ */
2265
2160 /* End: bn_mp_dr_is_modulus.c */ 2266 /* End: bn_mp_dr_is_modulus.c */
2161 2267
2162 /* Start: bn_mp_dr_reduce.c */ 2268 /* Start: bn_mp_dr_reduce.c */
2163 #include <tommath.h> 2269 #include <tommath.h>
2164 #ifdef BN_MP_DR_REDUCE_C 2270 #ifdef BN_MP_DR_REDUCE_C
2172 * additional optimizations in place. 2278 * additional optimizations in place.
2173 * 2279 *
2174 * The library is free for all purposes without any express 2280 * The library is free for all purposes without any express
2175 * guarantee it works. 2281 * guarantee it works.
2176 * 2282 *
2177 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2283 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2178 */ 2284 */
2179 2285
2180 /* reduce "x" in place modulo "n" using the Diminished Radix algorithm. 2286 /* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
2181 * 2287 *
2182 * Based on algorithm from the paper 2288 * Based on algorithm from the paper
2249 } 2355 }
2250 return MP_OKAY; 2356 return MP_OKAY;
2251 } 2357 }
2252 #endif 2358 #endif
2253 2359
2360 /* $Source: /cvs/libtom/libtommath/bn_mp_dr_reduce.c,v $ */
2361 /* $Revision: 1.3 $ */
2362 /* $Date: 2006/03/31 14:18:44 $ */
2363
2254 /* End: bn_mp_dr_reduce.c */ 2364 /* End: bn_mp_dr_reduce.c */
2255 2365
2256 /* Start: bn_mp_dr_setup.c */ 2366 /* Start: bn_mp_dr_setup.c */
2257 #include <tommath.h> 2367 #include <tommath.h>
2258 #ifdef BN_MP_DR_SETUP_C 2368 #ifdef BN_MP_DR_SETUP_C
2266 * additional optimizations in place. 2376 * additional optimizations in place.
2267 * 2377 *
2268 * The library is free for all purposes without any express 2378 * The library is free for all purposes without any express
2269 * guarantee it works. 2379 * guarantee it works.
2270 * 2380 *
2271 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2381 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2272 */ 2382 */
2273 2383
2274 /* determines the setup value */ 2384 /* determines the setup value */
2275 void mp_dr_setup(mp_int *a, mp_digit *d) 2385 void mp_dr_setup(mp_int *a, mp_digit *d)
2276 { 2386 {
2281 ((mp_word)a->dp[0])); 2391 ((mp_word)a->dp[0]));
2282 } 2392 }
2283 2393
2284 #endif 2394 #endif
2285 2395
2396 /* $Source: /cvs/libtom/libtommath/bn_mp_dr_setup.c,v $ */
2397 /* $Revision: 1.3 $ */
2398 /* $Date: 2006/03/31 14:18:44 $ */
2399
2286 /* End: bn_mp_dr_setup.c */ 2400 /* End: bn_mp_dr_setup.c */
2287 2401
2288 /* Start: bn_mp_exch.c */ 2402 /* Start: bn_mp_exch.c */
2289 #include <tommath.h> 2403 #include <tommath.h>
2290 #ifdef BN_MP_EXCH_C 2404 #ifdef BN_MP_EXCH_C
2298 * additional optimizations in place. 2412 * additional optimizations in place.
2299 * 2413 *
2300 * The library is free for all purposes without any express 2414 * The library is free for all purposes without any express
2301 * guarantee it works. 2415 * guarantee it works.
2302 * 2416 *
2303 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2417 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2304 */ 2418 */
2305 2419
2306 /* swap the elements of two integers, for cases where you can't simply swap the 2420 /* swap the elements of two integers, for cases where you can't simply swap the
2307 * mp_int pointers around 2421 * mp_int pointers around
2308 */ 2422 */
2315 *a = *b; 2429 *a = *b;
2316 *b = t; 2430 *b = t;
2317 } 2431 }
2318 #endif 2432 #endif
2319 2433
2434 /* $Source: /cvs/libtom/libtommath/bn_mp_exch.c,v $ */
2435 /* $Revision: 1.3 $ */
2436 /* $Date: 2006/03/31 14:18:44 $ */
2437
2320 /* End: bn_mp_exch.c */ 2438 /* End: bn_mp_exch.c */
2321 2439
2322 /* Start: bn_mp_expt_d.c */ 2440 /* Start: bn_mp_expt_d.c */
2323 #include <tommath.h> 2441 #include <tommath.h>
2324 #ifdef BN_MP_EXPT_D_C 2442 #ifdef BN_MP_EXPT_D_C
2332 * additional optimizations in place. 2450 * additional optimizations in place.
2333 * 2451 *
2334 * The library is free for all purposes without any express 2452 * The library is free for all purposes without any express
2335 * guarantee it works. 2453 * guarantee it works.
2336 * 2454 *
2337 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2455 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2338 */ 2456 */
2339 2457
2340 /* calculate c = a**b using a square-multiply algorithm */ 2458 /* calculate c = a**b using a square-multiply algorithm */
2341 int mp_expt_d (mp_int * a, mp_digit b, mp_int * c) 2459 int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
2342 { 2460 {
2372 mp_clear (&g); 2490 mp_clear (&g);
2373 return MP_OKAY; 2491 return MP_OKAY;
2374 } 2492 }
2375 #endif 2493 #endif
2376 2494
2495 /* $Source: /cvs/libtom/libtommath/bn_mp_expt_d.c,v $ */
2496 /* $Revision: 1.3 $ */
2497 /* $Date: 2006/03/31 14:18:44 $ */
2498
2377 /* End: bn_mp_expt_d.c */ 2499 /* End: bn_mp_expt_d.c */
2378 2500
2379 /* Start: bn_mp_exptmod.c */ 2501 /* Start: bn_mp_exptmod.c */
2380 #include <tommath.h> 2502 #include <tommath.h>
2381 #ifdef BN_MP_EXPTMOD_C 2503 #ifdef BN_MP_EXPTMOD_C
2389 * additional optimizations in place. 2511 * additional optimizations in place.
2390 * 2512 *
2391 * The library is free for all purposes without any express 2513 * The library is free for all purposes without any express
2392 * guarantee it works. 2514 * guarantee it works.
2393 * 2515 *
2394 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2516 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2395 */ 2517 */
2396 2518
2397 2519
2398 /* this is a shell function that calls either the normal or Montgomery 2520 /* this is a shell function that calls either the normal or Montgomery
2399 * exptmod functions. Originally the call to the montgomery code was 2521 * exptmod functions. Originally the call to the montgomery code was
2443 return MP_VAL; 2565 return MP_VAL;
2444 #endif 2566 #endif
2445 } 2567 }
2446 2568
2447 /* modified diminished radix reduction */ 2569 /* modified diminished radix reduction */
2448 #if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) 2570 #if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) && defined(BN_S_MP_EXPTMOD_C)
2449 if (mp_reduce_is_2k_l(P) == MP_YES) { 2571 if (mp_reduce_is_2k_l(P) == MP_YES) {
2450 return s_mp_exptmod(G, X, P, Y, 1); 2572 return s_mp_exptmod(G, X, P, Y, 1);
2451 } 2573 }
2452 #endif 2574 #endif
2453 2575
2484 #endif 2606 #endif
2485 } 2607 }
2486 2608
2487 #endif 2609 #endif
2488 2610
2611 /* $Source: /cvs/libtom/libtommath/bn_mp_exptmod.c,v $ */
2612 /* $Revision: 1.4 $ */
2613 /* $Date: 2006/03/31 14:18:44 $ */
2614
2489 /* End: bn_mp_exptmod.c */ 2615 /* End: bn_mp_exptmod.c */
2490 2616
2491 /* Start: bn_mp_exptmod_fast.c */ 2617 /* Start: bn_mp_exptmod_fast.c */
2492 #include <tommath.h> 2618 #include <tommath.h>
2493 #ifdef BN_MP_EXPTMOD_FAST_C 2619 #ifdef BN_MP_EXPTMOD_FAST_C
2501 * additional optimizations in place. 2627 * additional optimizations in place.
2502 * 2628 *
2503 * The library is free for all purposes without any express 2629 * The library is free for all purposes without any express
2504 * guarantee it works. 2630 * guarantee it works.
2505 * 2631 *
2506 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2632 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2507 */ 2633 */
2508 2634
2509 /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85 2635 /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
2510 * 2636 *
2511 * Uses a left-to-right k-ary sliding window to compute the modular exponentiation. 2637 * Uses a left-to-right k-ary sliding window to compute the modular exponentiation.
2805 return err; 2931 return err;
2806 } 2932 }
2807 #endif 2933 #endif
2808 2934
2809 2935
2936 /* $Source: /cvs/libtom/libtommath/bn_mp_exptmod_fast.c,v $ */
2937 /* $Revision: 1.3 $ */
2938 /* $Date: 2006/03/31 14:18:44 $ */
2939
2810 /* End: bn_mp_exptmod_fast.c */ 2940 /* End: bn_mp_exptmod_fast.c */
2811 2941
2812 /* Start: bn_mp_exteuclid.c */ 2942 /* Start: bn_mp_exteuclid.c */
2813 #include <tommath.h> 2943 #include <tommath.h>
2814 #ifdef BN_MP_EXTEUCLID_C 2944 #ifdef BN_MP_EXTEUCLID_C
2822 * additional optimizations in place. 2952 * additional optimizations in place.
2823 * 2953 *
2824 * The library is free for all purposes without any express 2954 * The library is free for all purposes without any express
2825 * guarantee it works. 2955 * guarantee it works.
2826 * 2956 *
2827 * Tom St Denis, [email protected], http://math.libtomcrypt.org 2957 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2828 */ 2958 */
2829 2959
2830 /* Extended euclidean algorithm of (a, b) produces 2960 /* Extended euclidean algorithm of (a, b) produces
2831 a*u1 + b*u2 = u3 2961 a*u1 + b*u2 = u3
2832 */ 2962 */
2887 _ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL); 3017 _ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
2888 return err; 3018 return err;
2889 } 3019 }
2890 #endif 3020 #endif
2891 3021
3022 /* $Source: /cvs/libtom/libtommath/bn_mp_exteuclid.c,v $ */
3023 /* $Revision: 1.3 $ */
3024 /* $Date: 2006/03/31 14:18:44 $ */
3025
2892 /* End: bn_mp_exteuclid.c */ 3026 /* End: bn_mp_exteuclid.c */
2893 3027
2894 /* Start: bn_mp_fread.c */ 3028 /* Start: bn_mp_fread.c */
2895 #include <tommath.h> 3029 #include <tommath.h>
2896 #ifdef BN_MP_FREAD_C 3030 #ifdef BN_MP_FREAD_C
2904 * additional optimizations in place. 3038 * additional optimizations in place.
2905 * 3039 *
2906 * The library is free for all purposes without any express 3040 * The library is free for all purposes without any express
2907 * guarantee it works. 3041 * guarantee it works.
2908 * 3042 *
2909 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3043 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2910 */ 3044 */
2911 3045
2912 /* read a bigint from a file stream in ASCII */ 3046 /* read a bigint from a file stream in ASCII */
2913 int mp_fread(mp_int *a, int radix, FILE *stream) 3047 int mp_fread(mp_int *a, int radix, FILE *stream)
2914 { 3048 {
2954 return MP_OKAY; 3088 return MP_OKAY;
2955 } 3089 }
2956 3090
2957 #endif 3091 #endif
2958 3092
3093 /* $Source: /cvs/libtom/libtommath/bn_mp_fread.c,v $ */
3094 /* $Revision: 1.3 $ */
3095 /* $Date: 2006/03/31 14:18:44 $ */
3096
2959 /* End: bn_mp_fread.c */ 3097 /* End: bn_mp_fread.c */
2960 3098
2961 /* Start: bn_mp_fwrite.c */ 3099 /* Start: bn_mp_fwrite.c */
2962 #include <tommath.h> 3100 #include <tommath.h>
2963 #ifdef BN_MP_FWRITE_C 3101 #ifdef BN_MP_FWRITE_C
2971 * additional optimizations in place. 3109 * additional optimizations in place.
2972 * 3110 *
2973 * The library is free for all purposes without any express 3111 * The library is free for all purposes without any express
2974 * guarantee it works. 3112 * guarantee it works.
2975 * 3113 *
2976 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3114 * Tom St Denis, [email protected], http://math.libtomcrypt.com
2977 */ 3115 */
2978 3116
2979 int mp_fwrite(mp_int *a, int radix, FILE *stream) 3117 int mp_fwrite(mp_int *a, int radix, FILE *stream)
2980 { 3118 {
2981 char *buf; 3119 char *buf;
3006 return MP_OKAY; 3144 return MP_OKAY;
3007 } 3145 }
3008 3146
3009 #endif 3147 #endif
3010 3148
3149 /* $Source: /cvs/libtom/libtommath/bn_mp_fwrite.c,v $ */
3150 /* $Revision: 1.3 $ */
3151 /* $Date: 2006/03/31 14:18:44 $ */
3152
3011 /* End: bn_mp_fwrite.c */ 3153 /* End: bn_mp_fwrite.c */
3012 3154
3013 /* Start: bn_mp_gcd.c */ 3155 /* Start: bn_mp_gcd.c */
3014 #include <tommath.h> 3156 #include <tommath.h>
3015 #ifdef BN_MP_GCD_C 3157 #ifdef BN_MP_GCD_C
3023 * additional optimizations in place. 3165 * additional optimizations in place.
3024 * 3166 *
3025 * The library is free for all purposes without any express 3167 * The library is free for all purposes without any express
3026 * guarantee it works. 3168 * guarantee it works.
3027 * 3169 *
3028 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3170 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3029 */ 3171 */
3030 3172
3031 /* Greatest Common Divisor using the binary method */ 3173 /* Greatest Common Divisor using the binary method */
3032 int mp_gcd (mp_int * a, mp_int * b, mp_int * c) 3174 int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
3033 { 3175 {
3034 mp_int u, v; 3176 mp_int u, v;
3035 int k, u_lsb, v_lsb, res; 3177 int k, u_lsb, v_lsb, res;
3036 3178
3037 /* either zero than gcd is the largest */ 3179 /* either zero than gcd is the largest */
3038 if (mp_iszero (a) == 1 && mp_iszero (b) == 0) { 3180 if (mp_iszero (a) == MP_YES) {
3039 return mp_abs (b, c); 3181 return mp_abs (b, c);
3040 } 3182 }
3041 if (mp_iszero (a) == 0 && mp_iszero (b) == 1) { 3183 if (mp_iszero (b) == MP_YES) {
3042 return mp_abs (a, c); 3184 return mp_abs (a, c);
3043 }
3044
3045 /* optimized. At this point if a == 0 then
3046 * b must equal zero too
3047 */
3048 if (mp_iszero (a) == 1) {
3049 mp_zero(c);
3050 return MP_OKAY;
3051 } 3185 }
3052 3186
3053 /* get copies of a and b we can modify */ 3187 /* get copies of a and b we can modify */
3054 if ((res = mp_init_copy (&u, a)) != MP_OKAY) { 3188 if ((res = mp_init_copy (&u, a)) != MP_OKAY) {
3055 return res; 3189 return res;
3119 LBL_U:mp_clear (&v); 3253 LBL_U:mp_clear (&v);
3120 return res; 3254 return res;
3121 } 3255 }
3122 #endif 3256 #endif
3123 3257
3258 /* $Source: /cvs/libtom/libtommath/bn_mp_gcd.c,v $ */
3259 /* $Revision: 1.4 $ */
3260 /* $Date: 2006/03/31 14:18:44 $ */
3261
3124 /* End: bn_mp_gcd.c */ 3262 /* End: bn_mp_gcd.c */
3125 3263
3126 /* Start: bn_mp_get_int.c */ 3264 /* Start: bn_mp_get_int.c */
3127 #include <tommath.h> 3265 #include <tommath.h>
3128 #ifdef BN_MP_GET_INT_C 3266 #ifdef BN_MP_GET_INT_C
3136 * additional optimizations in place. 3274 * additional optimizations in place.
3137 * 3275 *
3138 * The library is free for all purposes without any express 3276 * The library is free for all purposes without any express
3139 * guarantee it works. 3277 * guarantee it works.
3140 * 3278 *
3141 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3279 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3142 */ 3280 */
3143 3281
3144 /* get the lower 32-bits of an mp_int */ 3282 /* get the lower 32-bits of an mp_int */
3145 unsigned long mp_get_int(mp_int * a) 3283 unsigned long mp_get_int(mp_int * a)
3146 { 3284 {
3164 /* force result to 32-bits always so it is consistent on non 32-bit platforms */ 3302 /* force result to 32-bits always so it is consistent on non 32-bit platforms */
3165 return res & 0xFFFFFFFFUL; 3303 return res & 0xFFFFFFFFUL;
3166 } 3304 }
3167 #endif 3305 #endif
3168 3306
3307 /* $Source: /cvs/libtom/libtommath/bn_mp_get_int.c,v $ */
3308 /* $Revision: 1.3 $ */
3309 /* $Date: 2006/03/31 14:18:44 $ */
3310
3169 /* End: bn_mp_get_int.c */ 3311 /* End: bn_mp_get_int.c */
3170 3312
3171 /* Start: bn_mp_grow.c */ 3313 /* Start: bn_mp_grow.c */
3172 #include <tommath.h> 3314 #include <tommath.h>
3173 #ifdef BN_MP_GROW_C 3315 #ifdef BN_MP_GROW_C
3181 * additional optimizations in place. 3323 * additional optimizations in place.
3182 * 3324 *
3183 * The library is free for all purposes without any express 3325 * The library is free for all purposes without any express
3184 * guarantee it works. 3326 * guarantee it works.
3185 * 3327 *
3186 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3328 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3187 */ 3329 */
3188 3330
3189 /* grow as required */ 3331 /* grow as required */
3190 int mp_grow (mp_int * a, int size) 3332 int mp_grow (mp_int * a, int size)
3191 { 3333 {
3221 } 3363 }
3222 return MP_OKAY; 3364 return MP_OKAY;
3223 } 3365 }
3224 #endif 3366 #endif
3225 3367
3368 /* $Source: /cvs/libtom/libtommath/bn_mp_grow.c,v $ */
3369 /* $Revision: 1.3 $ */
3370 /* $Date: 2006/03/31 14:18:44 $ */
3371
3226 /* End: bn_mp_grow.c */ 3372 /* End: bn_mp_grow.c */
3227 3373
3228 /* Start: bn_mp_init.c */ 3374 /* Start: bn_mp_init.c */
3229 #include <tommath.h> 3375 #include <tommath.h>
3230 #ifdef BN_MP_INIT_C 3376 #ifdef BN_MP_INIT_C
3238 * additional optimizations in place. 3384 * additional optimizations in place.
3239 * 3385 *
3240 * The library is free for all purposes without any express 3386 * The library is free for all purposes without any express
3241 * guarantee it works. 3387 * guarantee it works.
3242 * 3388 *
3243 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3389 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3244 */ 3390 */
3245 3391
3246 /* init a new mp_int */ 3392 /* init a new mp_int */
3247 int mp_init (mp_int * a) 3393 int mp_init (mp_int * a)
3248 { 3394 {
3267 3413
3268 return MP_OKAY; 3414 return MP_OKAY;
3269 } 3415 }
3270 #endif 3416 #endif
3271 3417
3418 /* $Source: /cvs/libtom/libtommath/bn_mp_init.c,v $ */
3419 /* $Revision: 1.3 $ */
3420 /* $Date: 2006/03/31 14:18:44 $ */
3421
3272 /* End: bn_mp_init.c */ 3422 /* End: bn_mp_init.c */
3273 3423
3274 /* Start: bn_mp_init_copy.c */ 3424 /* Start: bn_mp_init_copy.c */
3275 #include <tommath.h> 3425 #include <tommath.h>
3276 #ifdef BN_MP_INIT_COPY_C 3426 #ifdef BN_MP_INIT_COPY_C
3284 * additional optimizations in place. 3434 * additional optimizations in place.
3285 * 3435 *
3286 * The library is free for all purposes without any express 3436 * The library is free for all purposes without any express
3287 * guarantee it works. 3437 * guarantee it works.
3288 * 3438 *
3289 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3439 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3290 */ 3440 */
3291 3441
3292 /* creates "a" then copies b into it */ 3442 /* creates "a" then copies b into it */
3293 int mp_init_copy (mp_int * a, mp_int * b) 3443 int mp_init_copy (mp_int * a, mp_int * b)
3294 { 3444 {
3299 } 3449 }
3300 return mp_copy (b, a); 3450 return mp_copy (b, a);
3301 } 3451 }
3302 #endif 3452 #endif
3303 3453
3454 /* $Source: /cvs/libtom/libtommath/bn_mp_init_copy.c,v $ */
3455 /* $Revision: 1.3 $ */
3456 /* $Date: 2006/03/31 14:18:44 $ */
3457
3304 /* End: bn_mp_init_copy.c */ 3458 /* End: bn_mp_init_copy.c */
3305 3459
3306 /* Start: bn_mp_init_multi.c */ 3460 /* Start: bn_mp_init_multi.c */
3307 #include <tommath.h> 3461 #include <tommath.h>
3308 #ifdef BN_MP_INIT_MULTI_C 3462 #ifdef BN_MP_INIT_MULTI_C
3316 * additional optimizations in place. 3470 * additional optimizations in place.
3317 * 3471 *
3318 * The library is free for all purposes without any express 3472 * The library is free for all purposes without any express
3319 * guarantee it works. 3473 * guarantee it works.
3320 * 3474 *
3321 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3475 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3322 */ 3476 */
3323 #include <stdarg.h> 3477 #include <stdarg.h>
3324 3478
3325 int mp_init_multi(mp_int *mp, ...) 3479 int mp_init_multi(mp_int *mp, ...)
3326 { 3480 {
3358 return res; /* Assumed ok, if error flagged above. */ 3512 return res; /* Assumed ok, if error flagged above. */
3359 } 3513 }
3360 3514
3361 #endif 3515 #endif
3362 3516
3517 /* $Source: /cvs/libtom/libtommath/bn_mp_init_multi.c,v $ */
3518 /* $Revision: 1.3 $ */
3519 /* $Date: 2006/03/31 14:18:44 $ */
3520
3363 /* End: bn_mp_init_multi.c */ 3521 /* End: bn_mp_init_multi.c */
3364 3522
3365 /* Start: bn_mp_init_set.c */ 3523 /* Start: bn_mp_init_set.c */
3366 #include <tommath.h> 3524 #include <tommath.h>
3367 #ifdef BN_MP_INIT_SET_C 3525 #ifdef BN_MP_INIT_SET_C
3375 * additional optimizations in place. 3533 * additional optimizations in place.
3376 * 3534 *
3377 * The library is free for all purposes without any express 3535 * The library is free for all purposes without any express
3378 * guarantee it works. 3536 * guarantee it works.
3379 * 3537 *
3380 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3538 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3381 */ 3539 */
3382 3540
3383 /* initialize and set a digit */ 3541 /* initialize and set a digit */
3384 int mp_init_set (mp_int * a, mp_digit b) 3542 int mp_init_set (mp_int * a, mp_digit b)
3385 { 3543 {
3390 mp_set(a, b); 3548 mp_set(a, b);
3391 return err; 3549 return err;
3392 } 3550 }
3393 #endif 3551 #endif
3394 3552
3553 /* $Source: /cvs/libtom/libtommath/bn_mp_init_set.c,v $ */
3554 /* $Revision: 1.3 $ */
3555 /* $Date: 2006/03/31 14:18:44 $ */
3556
3395 /* End: bn_mp_init_set.c */ 3557 /* End: bn_mp_init_set.c */
3396 3558
3397 /* Start: bn_mp_init_set_int.c */ 3559 /* Start: bn_mp_init_set_int.c */
3398 #include <tommath.h> 3560 #include <tommath.h>
3399 #ifdef BN_MP_INIT_SET_INT_C 3561 #ifdef BN_MP_INIT_SET_INT_C
3407 * additional optimizations in place. 3569 * additional optimizations in place.
3408 * 3570 *
3409 * The library is free for all purposes without any express 3571 * The library is free for all purposes without any express
3410 * guarantee it works. 3572 * guarantee it works.
3411 * 3573 *
3412 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3574 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3413 */ 3575 */
3414 3576
3415 /* initialize and set a digit */ 3577 /* initialize and set a digit */
3416 int mp_init_set_int (mp_int * a, unsigned long b) 3578 int mp_init_set_int (mp_int * a, unsigned long b)
3417 { 3579 {
3421 } 3583 }
3422 return mp_set_int(a, b); 3584 return mp_set_int(a, b);
3423 } 3585 }
3424 #endif 3586 #endif
3425 3587
3588 /* $Source: /cvs/libtom/libtommath/bn_mp_init_set_int.c,v $ */
3589 /* $Revision: 1.3 $ */
3590 /* $Date: 2006/03/31 14:18:44 $ */
3591
3426 /* End: bn_mp_init_set_int.c */ 3592 /* End: bn_mp_init_set_int.c */
3427 3593
3428 /* Start: bn_mp_init_size.c */ 3594 /* Start: bn_mp_init_size.c */
3429 #include <tommath.h> 3595 #include <tommath.h>
3430 #ifdef BN_MP_INIT_SIZE_C 3596 #ifdef BN_MP_INIT_SIZE_C
3438 * additional optimizations in place. 3604 * additional optimizations in place.
3439 * 3605 *
3440 * The library is free for all purposes without any express 3606 * The library is free for all purposes without any express
3441 * guarantee it works. 3607 * guarantee it works.
3442 * 3608 *
3443 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3609 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3444 */ 3610 */
3445 3611
3446 /* init an mp_init for a given size */ 3612 /* init an mp_init for a given size */
3447 int mp_init_size (mp_int * a, int size) 3613 int mp_init_size (mp_int * a, int size)
3448 { 3614 {
3469 3635
3470 return MP_OKAY; 3636 return MP_OKAY;
3471 } 3637 }
3472 #endif 3638 #endif
3473 3639
3640 /* $Source: /cvs/libtom/libtommath/bn_mp_init_size.c,v $ */
3641 /* $Revision: 1.3 $ */
3642 /* $Date: 2006/03/31 14:18:44 $ */
3643
3474 /* End: bn_mp_init_size.c */ 3644 /* End: bn_mp_init_size.c */
3475 3645
3476 /* Start: bn_mp_invmod.c */ 3646 /* Start: bn_mp_invmod.c */
3477 #include <tommath.h> 3647 #include <tommath.h>
3478 #ifdef BN_MP_INVMOD_C 3648 #ifdef BN_MP_INVMOD_C
3486 * additional optimizations in place. 3656 * additional optimizations in place.
3487 * 3657 *
3488 * The library is free for all purposes without any express 3658 * The library is free for all purposes without any express
3489 * guarantee it works. 3659 * guarantee it works.
3490 * 3660 *
3491 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3661 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3492 */ 3662 */
3493 3663
3494 /* hac 14.61, pp608 */ 3664 /* hac 14.61, pp608 */
3495 int mp_invmod (mp_int * a, mp_int * b, mp_int * c) 3665 int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
3496 { 3666 {
3512 3682
3513 return MP_VAL; 3683 return MP_VAL;
3514 } 3684 }
3515 #endif 3685 #endif
3516 3686
3687 /* $Source: /cvs/libtom/libtommath/bn_mp_invmod.c,v $ */
3688 /* $Revision: 1.3 $ */
3689 /* $Date: 2006/03/31 14:18:44 $ */
3690
3517 /* End: bn_mp_invmod.c */ 3691 /* End: bn_mp_invmod.c */
3518 3692
3519 /* Start: bn_mp_invmod_slow.c */ 3693 /* Start: bn_mp_invmod_slow.c */
3520 #include <tommath.h> 3694 #include <tommath.h>
3521 #ifdef BN_MP_INVMOD_SLOW_C 3695 #ifdef BN_MP_INVMOD_SLOW_C
3529 * additional optimizations in place. 3703 * additional optimizations in place.
3530 * 3704 *
3531 * The library is free for all purposes without any express 3705 * The library is free for all purposes without any express
3532 * guarantee it works. 3706 * guarantee it works.
3533 * 3707 *
3534 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3708 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3535 */ 3709 */
3536 3710
3537 /* hac 14.61, pp608 */ 3711 /* hac 14.61, pp608 */
3538 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c) 3712 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
3539 { 3713 {
3687 LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL); 3861 LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
3688 return res; 3862 return res;
3689 } 3863 }
3690 #endif 3864 #endif
3691 3865
3866 /* $Source: /cvs/libtom/libtommath/bn_mp_invmod_slow.c,v $ */
3867 /* $Revision: 1.3 $ */
3868 /* $Date: 2006/03/31 14:18:44 $ */
3869
3692 /* End: bn_mp_invmod_slow.c */ 3870 /* End: bn_mp_invmod_slow.c */
3693 3871
3694 /* Start: bn_mp_is_square.c */ 3872 /* Start: bn_mp_is_square.c */
3695 #include <tommath.h> 3873 #include <tommath.h>
3696 #ifdef BN_MP_IS_SQUARE_C 3874 #ifdef BN_MP_IS_SQUARE_C
3704 * additional optimizations in place. 3882 * additional optimizations in place.
3705 * 3883 *
3706 * The library is free for all purposes without any express 3884 * The library is free for all purposes without any express
3707 * guarantee it works. 3885 * guarantee it works.
3708 * 3886 *
3709 * Tom St Denis, [email protected], http://math.libtomcrypt.org 3887 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3710 */ 3888 */
3711 3889
3712 /* Check if remainders are possible squares - fast exclude non-squares */ 3890 /* Check if remainders are possible squares - fast exclude non-squares */
3713 static const char rem_128[128] = { 3891 static const char rem_128[128] = {
3714 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 3892 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3796 ERR:mp_clear(&t); 3974 ERR:mp_clear(&t);
3797 return res; 3975 return res;
3798 } 3976 }
3799 #endif 3977 #endif
3800 3978
3979 /* $Source: /cvs/libtom/libtommath/bn_mp_is_square.c,v $ */
3980 /* $Revision: 1.3 $ */
3981 /* $Date: 2006/03/31 14:18:44 $ */
3982
3801 /* End: bn_mp_is_square.c */ 3983 /* End: bn_mp_is_square.c */
3802 3984
3803 /* Start: bn_mp_jacobi.c */ 3985 /* Start: bn_mp_jacobi.c */
3804 #include <tommath.h> 3986 #include <tommath.h>
3805 #ifdef BN_MP_JACOBI_C 3987 #ifdef BN_MP_JACOBI_C
3813 * additional optimizations in place. 3995 * additional optimizations in place.
3814 * 3996 *
3815 * The library is free for all purposes without any express 3997 * The library is free for all purposes without any express
3816 * guarantee it works. 3998 * guarantee it works.
3817 * 3999 *
3818 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4000 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3819 */ 4001 */
3820 4002
3821 /* computes the jacobi c = (a | n) (or Legendre if n is prime) 4003 /* computes the jacobi c = (a | n) (or Legendre if n is prime)
3822 * HAC pp. 73 Algorithm 2.149 4004 * HAC pp. 73 Algorithm 2.149
3823 */ 4005 */
3901 LBL_A1:mp_clear (&a1); 4083 LBL_A1:mp_clear (&a1);
3902 return res; 4084 return res;
3903 } 4085 }
3904 #endif 4086 #endif
3905 4087
4088 /* $Source: /cvs/libtom/libtommath/bn_mp_jacobi.c,v $ */
4089 /* $Revision: 1.3 $ */
4090 /* $Date: 2006/03/31 14:18:44 $ */
4091
3906 /* End: bn_mp_jacobi.c */ 4092 /* End: bn_mp_jacobi.c */
3907 4093
3908 /* Start: bn_mp_karatsuba_mul.c */ 4094 /* Start: bn_mp_karatsuba_mul.c */
3909 #include <tommath.h> 4095 #include <tommath.h>
3910 #ifdef BN_MP_KARATSUBA_MUL_C 4096 #ifdef BN_MP_KARATSUBA_MUL_C
3918 * additional optimizations in place. 4104 * additional optimizations in place.
3919 * 4105 *
3920 * The library is free for all purposes without any express 4106 * The library is free for all purposes without any express
3921 * guarantee it works. 4107 * guarantee it works.
3922 * 4108 *
3923 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4109 * Tom St Denis, [email protected], http://math.libtomcrypt.com
3924 */ 4110 */
3925 4111
3926 /* c = |a| * |b| using Karatsuba Multiplication using 4112 /* c = |a| * |b| using Karatsuba Multiplication using
3927 * three half size multiplications 4113 * three half size multiplications
3928 * 4114 *
3932 * 4118 *
3933 * a = a1 * B**n + a0 4119 * a = a1 * B**n + a0
3934 * b = b1 * B**n + b0 4120 * b = b1 * B**n + b0
3935 * 4121 *
3936 * Then, a * b => 4122 * Then, a * b =>
3937 a1b1 * B**2n + ((a1 - a0)(b1 - b0) + a0b0 + a1b1) * B + a0b0 4123 a1b1 * B**2n + ((a1 + a0)(b1 + b0) - (a0b0 + a1b1)) * B + a0b0
3938 * 4124 *
3939 * Note that a1b1 and a0b0 are used twice and only need to be 4125 * Note that a1b1 and a0b0 are used twice and only need to be
3940 * computed once. So in total three half size (half # of 4126 * computed once. So in total three half size (half # of
3941 * digit) multiplications are performed, a0b0, a1b1 and 4127 * digit) multiplications are performed, a0b0, a1b1 and
3942 * (a1-b1)(a0-b0) 4128 * (a1+b1)(a0+b0)
3943 * 4129 *
3944 * Note that a multiplication of half the digits requires 4130 * Note that a multiplication of half the digits requires
3945 * 1/4th the number of single precision multiplications so in 4131 * 1/4th the number of single precision multiplications so in
3946 * total after one call 25% of the single precision multiplications 4132 * total after one call 25% of the single precision multiplications
3947 * are saved. Note also that the call to mp_mul can end up back 4133 * are saved. Note also that the call to mp_mul can end up back
4028 if (mp_mul (&x0, &y0, &x0y0) != MP_OKAY) 4214 if (mp_mul (&x0, &y0, &x0y0) != MP_OKAY)
4029 goto X1Y1; /* x0y0 = x0*y0 */ 4215 goto X1Y1; /* x0y0 = x0*y0 */
4030 if (mp_mul (&x1, &y1, &x1y1) != MP_OKAY) 4216 if (mp_mul (&x1, &y1, &x1y1) != MP_OKAY)
4031 goto X1Y1; /* x1y1 = x1*y1 */ 4217 goto X1Y1; /* x1y1 = x1*y1 */
4032 4218
4033 /* now calc x1-x0 and y1-y0 */ 4219 /* now calc x1+x0 and y1+y0 */
4034 if (mp_sub (&x1, &x0, &t1) != MP_OKAY) 4220 if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
4035 goto X1Y1; /* t1 = x1 - x0 */ 4221 goto X1Y1; /* t1 = x1 - x0 */
4036 if (mp_sub (&y1, &y0, &x0) != MP_OKAY) 4222 if (s_mp_add (&y1, &y0, &x0) != MP_OKAY)
4037 goto X1Y1; /* t2 = y1 - y0 */ 4223 goto X1Y1; /* t2 = y1 - y0 */
4038 if (mp_mul (&t1, &x0, &t1) != MP_OKAY) 4224 if (mp_mul (&t1, &x0, &t1) != MP_OKAY)
4039 goto X1Y1; /* t1 = (x1 - x0) * (y1 - y0) */ 4225 goto X1Y1; /* t1 = (x1 + x0) * (y1 + y0) */
4040 4226
4041 /* add x0y0 */ 4227 /* add x0y0 */
4042 if (mp_add (&x0y0, &x1y1, &x0) != MP_OKAY) 4228 if (mp_add (&x0y0, &x1y1, &x0) != MP_OKAY)
4043 goto X1Y1; /* t2 = x0y0 + x1y1 */ 4229 goto X1Y1; /* t2 = x0y0 + x1y1 */
4044 if (mp_sub (&x0, &t1, &t1) != MP_OKAY) 4230 if (s_mp_sub (&t1, &x0, &t1) != MP_OKAY)
4045 goto X1Y1; /* t1 = x0y0 + x1y1 - (x1-x0)*(y1-y0) */ 4231 goto X1Y1; /* t1 = (x1+x0)*(y1+y0) - (x1y1 + x0y0) */
4046 4232
4047 /* shift by B */ 4233 /* shift by B */
4048 if (mp_lshd (&t1, B) != MP_OKAY) 4234 if (mp_lshd (&t1, B) != MP_OKAY)
4049 goto X1Y1; /* t1 = (x0y0 + x1y1 - (x1-x0)*(y1-y0))<<B */ 4235 goto X1Y1; /* t1 = (x0y0 + x1y1 - (x1-x0)*(y1-y0))<<B */
4050 if (mp_lshd (&x1y1, B * 2) != MP_OKAY) 4236 if (mp_lshd (&x1y1, B * 2) != MP_OKAY)
4068 ERR: 4254 ERR:
4069 return err; 4255 return err;
4070 } 4256 }
4071 #endif 4257 #endif
4072 4258
4259 /* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_mul.c,v $ */
4260 /* $Revision: 1.5 $ */
4261 /* $Date: 2006/03/31 14:18:44 $ */
4262
4073 /* End: bn_mp_karatsuba_mul.c */ 4263 /* End: bn_mp_karatsuba_mul.c */
4074 4264
4075 /* Start: bn_mp_karatsuba_sqr.c */ 4265 /* Start: bn_mp_karatsuba_sqr.c */
4076 #include <tommath.h> 4266 #include <tommath.h>
4077 #ifdef BN_MP_KARATSUBA_SQR_C 4267 #ifdef BN_MP_KARATSUBA_SQR_C
4085 * additional optimizations in place. 4275 * additional optimizations in place.
4086 * 4276 *
4087 * The library is free for all purposes without any express 4277 * The library is free for all purposes without any express
4088 * guarantee it works. 4278 * guarantee it works.
4089 * 4279 *
4090 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4280 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4091 */ 4281 */
4092 4282
4093 /* Karatsuba squaring, computes b = a*a using three 4283 /* Karatsuba squaring, computes b = a*a using three
4094 * half size squarings 4284 * half size squarings
4095 * 4285 *
4153 if (mp_sqr (&x0, &x0x0) != MP_OKAY) 4343 if (mp_sqr (&x0, &x0x0) != MP_OKAY)
4154 goto X1X1; /* x0x0 = x0*x0 */ 4344 goto X1X1; /* x0x0 = x0*x0 */
4155 if (mp_sqr (&x1, &x1x1) != MP_OKAY) 4345 if (mp_sqr (&x1, &x1x1) != MP_OKAY)
4156 goto X1X1; /* x1x1 = x1*x1 */ 4346 goto X1X1; /* x1x1 = x1*x1 */
4157 4347
4158 /* now calc (x1-x0)**2 */ 4348 /* now calc (x1+x0)**2 */
4159 if (mp_sub (&x1, &x0, &t1) != MP_OKAY) 4349 if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
4160 goto X1X1; /* t1 = x1 - x0 */ 4350 goto X1X1; /* t1 = x1 - x0 */
4161 if (mp_sqr (&t1, &t1) != MP_OKAY) 4351 if (mp_sqr (&t1, &t1) != MP_OKAY)
4162 goto X1X1; /* t1 = (x1 - x0) * (x1 - x0) */ 4352 goto X1X1; /* t1 = (x1 - x0) * (x1 - x0) */
4163 4353
4164 /* add x0y0 */ 4354 /* add x0y0 */
4165 if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY) 4355 if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY)
4166 goto X1X1; /* t2 = x0x0 + x1x1 */ 4356 goto X1X1; /* t2 = x0x0 + x1x1 */
4167 if (mp_sub (&t2, &t1, &t1) != MP_OKAY) 4357 if (s_mp_sub (&t1, &t2, &t1) != MP_OKAY)
4168 goto X1X1; /* t1 = x0x0 + x1x1 - (x1-x0)*(x1-x0) */ 4358 goto X1X1; /* t1 = (x1+x0)**2 - (x0x0 + x1x1) */
4169 4359
4170 /* shift by B */ 4360 /* shift by B */
4171 if (mp_lshd (&t1, B) != MP_OKAY) 4361 if (mp_lshd (&t1, B) != MP_OKAY)
4172 goto X1X1; /* t1 = (x0x0 + x1x1 - (x1-x0)*(x1-x0))<<B */ 4362 goto X1X1; /* t1 = (x0x0 + x1x1 - (x1-x0)*(x1-x0))<<B */
4173 if (mp_lshd (&x1x1, B * 2) != MP_OKAY) 4363 if (mp_lshd (&x1x1, B * 2) != MP_OKAY)
4189 ERR: 4379 ERR:
4190 return err; 4380 return err;
4191 } 4381 }
4192 #endif 4382 #endif
4193 4383
4384 /* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_sqr.c,v $ */
4385 /* $Revision: 1.5 $ */
4386 /* $Date: 2006/03/31 14:18:44 $ */
4387
4194 /* End: bn_mp_karatsuba_sqr.c */ 4388 /* End: bn_mp_karatsuba_sqr.c */
4195 4389
4196 /* Start: bn_mp_lcm.c */ 4390 /* Start: bn_mp_lcm.c */
4197 #include <tommath.h> 4391 #include <tommath.h>
4198 #ifdef BN_MP_LCM_C 4392 #ifdef BN_MP_LCM_C
4206 * additional optimizations in place. 4400 * additional optimizations in place.
4207 * 4401 *
4208 * The library is free for all purposes without any express 4402 * The library is free for all purposes without any express
4209 * guarantee it works. 4403 * guarantee it works.
4210 * 4404 *
4211 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4405 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4212 */ 4406 */
4213 4407
4214 /* computes least common multiple as |a*b|/(a, b) */ 4408 /* computes least common multiple as |a*b|/(a, b) */
4215 int mp_lcm (mp_int * a, mp_int * b, mp_int * c) 4409 int mp_lcm (mp_int * a, mp_int * b, mp_int * c)
4216 { 4410 {
4249 mp_clear_multi (&t1, &t2, NULL); 4443 mp_clear_multi (&t1, &t2, NULL);
4250 return res; 4444 return res;
4251 } 4445 }
4252 #endif 4446 #endif
4253 4447
4448 /* $Source: /cvs/libtom/libtommath/bn_mp_lcm.c,v $ */
4449 /* $Revision: 1.3 $ */
4450 /* $Date: 2006/03/31 14:18:44 $ */
4451
4254 /* End: bn_mp_lcm.c */ 4452 /* End: bn_mp_lcm.c */
4255 4453
4256 /* Start: bn_mp_lshd.c */ 4454 /* Start: bn_mp_lshd.c */
4257 #include <tommath.h> 4455 #include <tommath.h>
4258 #ifdef BN_MP_LSHD_C 4456 #ifdef BN_MP_LSHD_C
4266 * additional optimizations in place. 4464 * additional optimizations in place.
4267 * 4465 *
4268 * The library is free for all purposes without any express 4466 * The library is free for all purposes without any express
4269 * guarantee it works. 4467 * guarantee it works.
4270 * 4468 *
4271 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4469 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4272 */ 4470 */
4273 4471
4274 /* shift left a certain amount of digits */ 4472 /* shift left a certain amount of digits */
4275 int mp_lshd (mp_int * a, int b) 4473 int mp_lshd (mp_int * a, int b)
4276 { 4474 {
4316 } 4514 }
4317 return MP_OKAY; 4515 return MP_OKAY;
4318 } 4516 }
4319 #endif 4517 #endif
4320 4518
4519 /* $Source: /cvs/libtom/libtommath/bn_mp_lshd.c,v $ */
4520 /* $Revision: 1.3 $ */
4521 /* $Date: 2006/03/31 14:18:44 $ */
4522
4321 /* End: bn_mp_lshd.c */ 4523 /* End: bn_mp_lshd.c */
4322 4524
4323 /* Start: bn_mp_mod.c */ 4525 /* Start: bn_mp_mod.c */
4324 #include <tommath.h> 4526 #include <tommath.h>
4325 #ifdef BN_MP_MOD_C 4527 #ifdef BN_MP_MOD_C
4333 * additional optimizations in place. 4535 * additional optimizations in place.
4334 * 4536 *
4335 * The library is free for all purposes without any express 4537 * The library is free for all purposes without any express
4336 * guarantee it works. 4538 * guarantee it works.
4337 * 4539 *
4338 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4540 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4339 */ 4541 */
4340 4542
4341 /* c = a mod b, 0 <= c < b */ 4543 /* c = a mod b, 0 <= c < b */
4342 int 4544 int
4343 mp_mod (mp_int * a, mp_int * b, mp_int * c) 4545 mp_mod (mp_int * a, mp_int * b, mp_int * c)
4364 mp_clear (&t); 4566 mp_clear (&t);
4365 return res; 4567 return res;
4366 } 4568 }
4367 #endif 4569 #endif
4368 4570
4571 /* $Source: /cvs/libtom/libtommath/bn_mp_mod.c,v $ */
4572 /* $Revision: 1.3 $ */
4573 /* $Date: 2006/03/31 14:18:44 $ */
4574
4369 /* End: bn_mp_mod.c */ 4575 /* End: bn_mp_mod.c */
4370 4576
4371 /* Start: bn_mp_mod_2d.c */ 4577 /* Start: bn_mp_mod_2d.c */
4372 #include <tommath.h> 4578 #include <tommath.h>
4373 #ifdef BN_MP_MOD_2D_C 4579 #ifdef BN_MP_MOD_2D_C
4381 * additional optimizations in place. 4587 * additional optimizations in place.
4382 * 4588 *
4383 * The library is free for all purposes without any express 4589 * The library is free for all purposes without any express
4384 * guarantee it works. 4590 * guarantee it works.
4385 * 4591 *
4386 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4592 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4387 */ 4593 */
4388 4594
4389 /* calc a value mod 2**b */ 4595 /* calc a value mod 2**b */
4390 int 4596 int
4391 mp_mod_2d (mp_int * a, int b, mp_int * c) 4597 mp_mod_2d (mp_int * a, int b, mp_int * c)
4419 mp_clamp (c); 4625 mp_clamp (c);
4420 return MP_OKAY; 4626 return MP_OKAY;
4421 } 4627 }
4422 #endif 4628 #endif
4423 4629
4630 /* $Source: /cvs/libtom/libtommath/bn_mp_mod_2d.c,v $ */
4631 /* $Revision: 1.3 $ */
4632 /* $Date: 2006/03/31 14:18:44 $ */
4633
4424 /* End: bn_mp_mod_2d.c */ 4634 /* End: bn_mp_mod_2d.c */
4425 4635
4426 /* Start: bn_mp_mod_d.c */ 4636 /* Start: bn_mp_mod_d.c */
4427 #include <tommath.h> 4637 #include <tommath.h>
4428 #ifdef BN_MP_MOD_D_C 4638 #ifdef BN_MP_MOD_D_C
4436 * additional optimizations in place. 4646 * additional optimizations in place.
4437 * 4647 *
4438 * The library is free for all purposes without any express 4648 * The library is free for all purposes without any express
4439 * guarantee it works. 4649 * guarantee it works.
4440 * 4650 *
4441 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4651 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4442 */ 4652 */
4443 4653
4444 int 4654 int
4445 mp_mod_d (mp_int * a, mp_digit b, mp_digit * c) 4655 mp_mod_d (mp_int * a, mp_digit b, mp_digit * c)
4446 { 4656 {
4447 return mp_div_d(a, b, NULL, c); 4657 return mp_div_d(a, b, NULL, c);
4448 } 4658 }
4449 #endif 4659 #endif
4450 4660
4661 /* $Source: /cvs/libtom/libtommath/bn_mp_mod_d.c,v $ */
4662 /* $Revision: 1.3 $ */
4663 /* $Date: 2006/03/31 14:18:44 $ */
4664
4451 /* End: bn_mp_mod_d.c */ 4665 /* End: bn_mp_mod_d.c */
4452 4666
4453 /* Start: bn_mp_montgomery_calc_normalization.c */ 4667 /* Start: bn_mp_montgomery_calc_normalization.c */
4454 #include <tommath.h> 4668 #include <tommath.h>
4455 #ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C 4669 #ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
4463 * additional optimizations in place. 4677 * additional optimizations in place.
4464 * 4678 *
4465 * The library is free for all purposes without any express 4679 * The library is free for all purposes without any express
4466 * guarantee it works. 4680 * guarantee it works.
4467 * 4681 *
4468 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4682 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4469 */ 4683 */
4470 4684
4471 /* 4685 /*
4472 * shifts with subtractions when the result is greater than b. 4686 * shifts with subtractions when the result is greater than b.
4473 * 4687 *
4505 4719
4506 return MP_OKAY; 4720 return MP_OKAY;
4507 } 4721 }
4508 #endif 4722 #endif
4509 4723
4724 /* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_calc_normalization.c,v $ */
4725 /* $Revision: 1.3 $ */
4726 /* $Date: 2006/03/31 14:18:44 $ */
4727
4510 /* End: bn_mp_montgomery_calc_normalization.c */ 4728 /* End: bn_mp_montgomery_calc_normalization.c */
4511 4729
4512 /* Start: bn_mp_montgomery_reduce.c */ 4730 /* Start: bn_mp_montgomery_reduce.c */
4513 #include <tommath.h> 4731 #include <tommath.h>
4514 #ifdef BN_MP_MONTGOMERY_REDUCE_C 4732 #ifdef BN_MP_MONTGOMERY_REDUCE_C
4522 * additional optimizations in place. 4740 * additional optimizations in place.
4523 * 4741 *
4524 * The library is free for all purposes without any express 4742 * The library is free for all purposes without any express
4525 * guarantee it works. 4743 * guarantee it works.
4526 * 4744 *
4527 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4745 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4528 */ 4746 */
4529 4747
4530 /* computes xR**-1 == x (mod N) via Montgomery Reduction */ 4748 /* computes xR**-1 == x (mod N) via Montgomery Reduction */
4531 int 4749 int
4532 mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) 4750 mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
4623 4841
4624 return MP_OKAY; 4842 return MP_OKAY;
4625 } 4843 }
4626 #endif 4844 #endif
4627 4845
4846 /* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_reduce.c,v $ */
4847 /* $Revision: 1.3 $ */
4848 /* $Date: 2006/03/31 14:18:44 $ */
4849
4628 /* End: bn_mp_montgomery_reduce.c */ 4850 /* End: bn_mp_montgomery_reduce.c */
4629 4851
4630 /* Start: bn_mp_montgomery_setup.c */ 4852 /* Start: bn_mp_montgomery_setup.c */
4631 #include <tommath.h> 4853 #include <tommath.h>
4632 #ifdef BN_MP_MONTGOMERY_SETUP_C 4854 #ifdef BN_MP_MONTGOMERY_SETUP_C
4640 * additional optimizations in place. 4862 * additional optimizations in place.
4641 * 4863 *
4642 * The library is free for all purposes without any express 4864 * The library is free for all purposes without any express
4643 * guarantee it works. 4865 * guarantee it works.
4644 * 4866 *
4645 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4867 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4646 */ 4868 */
4647 4869
4648 /* setups the montgomery reduction stuff */ 4870 /* setups the montgomery reduction stuff */
4649 int 4871 int
4650 mp_montgomery_setup (mp_int * n, mp_digit * rho) 4872 mp_montgomery_setup (mp_int * n, mp_digit * rho)
4676 #ifdef MP_64BIT 4898 #ifdef MP_64BIT
4677 x *= 2 - b * x; /* here x*a==1 mod 2**64 */ 4899 x *= 2 - b * x; /* here x*a==1 mod 2**64 */
4678 #endif 4900 #endif
4679 4901
4680 /* rho = -1/m mod b */ 4902 /* rho = -1/m mod b */
4681 *rho = (((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK; 4903 *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
4682 4904
4683 return MP_OKAY; 4905 return MP_OKAY;
4684 } 4906 }
4685 #endif 4907 #endif
4686 4908
4909 /* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_setup.c,v $ */
4910 /* $Revision: 1.4 $ */
4911 /* $Date: 2006/12/04 21:34:03 $ */
4912
4687 /* End: bn_mp_montgomery_setup.c */ 4913 /* End: bn_mp_montgomery_setup.c */
4688 4914
4689 /* Start: bn_mp_mul.c */ 4915 /* Start: bn_mp_mul.c */
4690 #include <tommath.h> 4916 #include <tommath.h>
4691 #ifdef BN_MP_MUL_C 4917 #ifdef BN_MP_MUL_C
4699 * additional optimizations in place. 4925 * additional optimizations in place.
4700 * 4926 *
4701 * The library is free for all purposes without any express 4927 * The library is free for all purposes without any express
4702 * guarantee it works. 4928 * guarantee it works.
4703 * 4929 *
4704 * Tom St Denis, [email protected], http://math.libtomcrypt.org 4930 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4705 */ 4931 */
4706 4932
4707 /* high level multiplication (handles sign) */ 4933 /* high level multiplication (handles sign) */
4708 int mp_mul (mp_int * a, mp_int * b, mp_int * c) 4934 int mp_mul (mp_int * a, mp_int * b, mp_int * c)
4709 { 4935 {
4748 c->sign = (c->used > 0) ? neg : MP_ZPOS; 4974 c->sign = (c->used > 0) ? neg : MP_ZPOS;
4749 return res; 4975 return res;
4750 } 4976 }
4751 #endif 4977 #endif
4752 4978
4979 /* $Source: /cvs/libtom/libtommath/bn_mp_mul.c,v $ */
4980 /* $Revision: 1.3 $ */
4981 /* $Date: 2006/03/31 14:18:44 $ */
4982
4753 /* End: bn_mp_mul.c */ 4983 /* End: bn_mp_mul.c */
4754 4984
4755 /* Start: bn_mp_mul_2.c */ 4985 /* Start: bn_mp_mul_2.c */
4756 #include <tommath.h> 4986 #include <tommath.h>
4757 #ifdef BN_MP_MUL_2_C 4987 #ifdef BN_MP_MUL_2_C
4765 * additional optimizations in place. 4995 * additional optimizations in place.
4766 * 4996 *
4767 * The library is free for all purposes without any express 4997 * The library is free for all purposes without any express
4768 * guarantee it works. 4998 * guarantee it works.
4769 * 4999 *
4770 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5000 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4771 */ 5001 */
4772 5002
4773 /* b = a*2 */ 5003 /* b = a*2 */
4774 int mp_mul_2(mp_int * a, mp_int * b) 5004 int mp_mul_2(mp_int * a, mp_int * b)
4775 { 5005 {
4830 b->sign = a->sign; 5060 b->sign = a->sign;
4831 return MP_OKAY; 5061 return MP_OKAY;
4832 } 5062 }
4833 #endif 5063 #endif
4834 5064
5065 /* $Source: /cvs/libtom/libtommath/bn_mp_mul_2.c,v $ */
5066 /* $Revision: 1.3 $ */
5067 /* $Date: 2006/03/31 14:18:44 $ */
5068
4835 /* End: bn_mp_mul_2.c */ 5069 /* End: bn_mp_mul_2.c */
4836 5070
4837 /* Start: bn_mp_mul_2d.c */ 5071 /* Start: bn_mp_mul_2d.c */
4838 #include <tommath.h> 5072 #include <tommath.h>
4839 #ifdef BN_MP_MUL_2D_C 5073 #ifdef BN_MP_MUL_2D_C
4847 * additional optimizations in place. 5081 * additional optimizations in place.
4848 * 5082 *
4849 * The library is free for all purposes without any express 5083 * The library is free for all purposes without any express
4850 * guarantee it works. 5084 * guarantee it works.
4851 * 5085 *
4852 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5086 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4853 */ 5087 */
4854 5088
4855 /* shift left by a certain bit count */ 5089 /* shift left by a certain bit count */
4856 int mp_mul_2d (mp_int * a, int b, mp_int * c) 5090 int mp_mul_2d (mp_int * a, int b, mp_int * c)
4857 { 5091 {
4915 mp_clamp (c); 5149 mp_clamp (c);
4916 return MP_OKAY; 5150 return MP_OKAY;
4917 } 5151 }
4918 #endif 5152 #endif
4919 5153
5154 /* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */
5155 /* $Revision: 1.3 $ */
5156 /* $Date: 2006/03/31 14:18:44 $ */
5157
4920 /* End: bn_mp_mul_2d.c */ 5158 /* End: bn_mp_mul_2d.c */
4921 5159
4922 /* Start: bn_mp_mul_d.c */ 5160 /* Start: bn_mp_mul_d.c */
4923 #include <tommath.h> 5161 #include <tommath.h>
4924 #ifdef BN_MP_MUL_D_C 5162 #ifdef BN_MP_MUL_D_C
4932 * additional optimizations in place. 5170 * additional optimizations in place.
4933 * 5171 *
4934 * The library is free for all purposes without any express 5172 * The library is free for all purposes without any express
4935 * guarantee it works. 5173 * guarantee it works.
4936 * 5174 *
4937 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5175 * Tom St Denis, [email protected], http://math.libtomcrypt.com
4938 */ 5176 */
4939 5177
4940 /* multiply by a digit */ 5178 /* multiply by a digit */
4941 int 5179 int
4942 mp_mul_d (mp_int * a, mp_digit b, mp_int * c) 5180 mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
4994 5232
4995 return MP_OKAY; 5233 return MP_OKAY;
4996 } 5234 }
4997 #endif 5235 #endif
4998 5236
5237 /* $Source: /cvs/libtom/libtommath/bn_mp_mul_d.c,v $ */
5238 /* $Revision: 1.3 $ */
5239 /* $Date: 2006/03/31 14:18:44 $ */
5240
4999 /* End: bn_mp_mul_d.c */ 5241 /* End: bn_mp_mul_d.c */
5000 5242
5001 /* Start: bn_mp_mulmod.c */ 5243 /* Start: bn_mp_mulmod.c */
5002 #include <tommath.h> 5244 #include <tommath.h>
5003 #ifdef BN_MP_MULMOD_C 5245 #ifdef BN_MP_MULMOD_C
5011 * additional optimizations in place. 5253 * additional optimizations in place.
5012 * 5254 *
5013 * The library is free for all purposes without any express 5255 * The library is free for all purposes without any express
5014 * guarantee it works. 5256 * guarantee it works.
5015 * 5257 *
5016 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5258 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5017 */ 5259 */
5018 5260
5019 /* d = a * b (mod c) */ 5261 /* d = a * b (mod c) */
5020 int 5262 int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
5021 mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
5022 { 5263 {
5023 int res; 5264 int res;
5024 mp_int t; 5265 mp_int t;
5025 5266
5026 if ((res = mp_init (&t)) != MP_OKAY) { 5267 if ((res = mp_init (&t)) != MP_OKAY) {
5035 mp_clear (&t); 5276 mp_clear (&t);
5036 return res; 5277 return res;
5037 } 5278 }
5038 #endif 5279 #endif
5039 5280
5281 /* $Source: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */
5282 /* $Revision: 1.4 $ */
5283 /* $Date: 2006/03/31 14:18:44 $ */
5284
5040 /* End: bn_mp_mulmod.c */ 5285 /* End: bn_mp_mulmod.c */
5041 5286
5042 /* Start: bn_mp_n_root.c */ 5287 /* Start: bn_mp_n_root.c */
5043 #include <tommath.h> 5288 #include <tommath.h>
5044 #ifdef BN_MP_N_ROOT_C 5289 #ifdef BN_MP_N_ROOT_C
5052 * additional optimizations in place. 5297 * additional optimizations in place.
5053 * 5298 *
5054 * The library is free for all purposes without any express 5299 * The library is free for all purposes without any express
5055 * guarantee it works. 5300 * guarantee it works.
5056 * 5301 *
5057 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5302 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5058 */ 5303 */
5059 5304
5060 /* find the n'th root of an integer 5305 /* find the n'th root of an integer
5061 * 5306 *
5062 * Result found such that (c)**b <= a and (c+1)**b > a 5307 * Result found such that (c)**b <= a and (c+1)**b > a
5167 LBL_T1:mp_clear (&t1); 5412 LBL_T1:mp_clear (&t1);
5168 return res; 5413 return res;
5169 } 5414 }
5170 #endif 5415 #endif
5171 5416
5417 /* $Source: /cvs/libtom/libtommath/bn_mp_n_root.c,v $ */
5418 /* $Revision: 1.3 $ */
5419 /* $Date: 2006/03/31 14:18:44 $ */
5420
5172 /* End: bn_mp_n_root.c */ 5421 /* End: bn_mp_n_root.c */
5173 5422
5174 /* Start: bn_mp_neg.c */ 5423 /* Start: bn_mp_neg.c */
5175 #include <tommath.h> 5424 #include <tommath.h>
5176 #ifdef BN_MP_NEG_C 5425 #ifdef BN_MP_NEG_C
5184 * additional optimizations in place. 5433 * additional optimizations in place.
5185 * 5434 *
5186 * The library is free for all purposes without any express 5435 * The library is free for all purposes without any express
5187 * guarantee it works. 5436 * guarantee it works.
5188 * 5437 *
5189 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5438 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5190 */ 5439 */
5191 5440
5192 /* b = -a */ 5441 /* b = -a */
5193 int mp_neg (mp_int * a, mp_int * b) 5442 int mp_neg (mp_int * a, mp_int * b)
5194 { 5443 {
5207 5456
5208 return MP_OKAY; 5457 return MP_OKAY;
5209 } 5458 }
5210 #endif 5459 #endif
5211 5460
5461 /* $Source: /cvs/libtom/libtommath/bn_mp_neg.c,v $ */
5462 /* $Revision: 1.3 $ */
5463 /* $Date: 2006/03/31 14:18:44 $ */
5464
5212 /* End: bn_mp_neg.c */ 5465 /* End: bn_mp_neg.c */
5213 5466
5214 /* Start: bn_mp_or.c */ 5467 /* Start: bn_mp_or.c */
5215 #include <tommath.h> 5468 #include <tommath.h>
5216 #ifdef BN_MP_OR_C 5469 #ifdef BN_MP_OR_C
5224 * additional optimizations in place. 5477 * additional optimizations in place.
5225 * 5478 *
5226 * The library is free for all purposes without any express 5479 * The library is free for all purposes without any express
5227 * guarantee it works. 5480 * guarantee it works.
5228 * 5481 *
5229 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5482 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5230 */ 5483 */
5231 5484
5232 /* OR two ints together */ 5485 /* OR two ints together */
5233 int mp_or (mp_int * a, mp_int * b, mp_int * c) 5486 int mp_or (mp_int * a, mp_int * b, mp_int * c)
5234 { 5487 {
5257 mp_clear (&t); 5510 mp_clear (&t);
5258 return MP_OKAY; 5511 return MP_OKAY;
5259 } 5512 }
5260 #endif 5513 #endif
5261 5514
5515 /* $Source: /cvs/libtom/libtommath/bn_mp_or.c,v $ */
5516 /* $Revision: 1.3 $ */
5517 /* $Date: 2006/03/31 14:18:44 $ */
5518
5262 /* End: bn_mp_or.c */ 5519 /* End: bn_mp_or.c */
5263 5520
5264 /* Start: bn_mp_prime_fermat.c */ 5521 /* Start: bn_mp_prime_fermat.c */
5265 #include <tommath.h> 5522 #include <tommath.h>
5266 #ifdef BN_MP_PRIME_FERMAT_C 5523 #ifdef BN_MP_PRIME_FERMAT_C
5274 * additional optimizations in place. 5531 * additional optimizations in place.
5275 * 5532 *
5276 * The library is free for all purposes without any express 5533 * The library is free for all purposes without any express
5277 * guarantee it works. 5534 * guarantee it works.
5278 * 5535 *
5279 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5536 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5280 */ 5537 */
5281 5538
5282 /* performs one Fermat test. 5539 /* performs one Fermat test.
5283 * 5540 *
5284 * If "a" were prime then b**a == b (mod a) since the order of 5541 * If "a" were prime then b**a == b (mod a) since the order of
5319 LBL_T:mp_clear (&t); 5576 LBL_T:mp_clear (&t);
5320 return err; 5577 return err;
5321 } 5578 }
5322 #endif 5579 #endif
5323 5580
5581 /* $Source: /cvs/libtom/libtommath/bn_mp_prime_fermat.c,v $ */
5582 /* $Revision: 1.3 $ */
5583 /* $Date: 2006/03/31 14:18:44 $ */
5584
5324 /* End: bn_mp_prime_fermat.c */ 5585 /* End: bn_mp_prime_fermat.c */
5325 5586
5326 /* Start: bn_mp_prime_is_divisible.c */ 5587 /* Start: bn_mp_prime_is_divisible.c */
5327 #include <tommath.h> 5588 #include <tommath.h>
5328 #ifdef BN_MP_PRIME_IS_DIVISIBLE_C 5589 #ifdef BN_MP_PRIME_IS_DIVISIBLE_C
5336 * additional optimizations in place. 5597 * additional optimizations in place.
5337 * 5598 *
5338 * The library is free for all purposes without any express 5599 * The library is free for all purposes without any express
5339 * guarantee it works. 5600 * guarantee it works.
5340 * 5601 *
5341 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5602 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5342 */ 5603 */
5343 5604
5344 /* determines if an integers is divisible by one 5605 /* determines if an integers is divisible by one
5345 * of the first PRIME_SIZE primes or not 5606 * of the first PRIME_SIZE primes or not
5346 * 5607 *
5369 5630
5370 return MP_OKAY; 5631 return MP_OKAY;
5371 } 5632 }
5372 #endif 5633 #endif
5373 5634
5635 /* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v $ */
5636 /* $Revision: 1.3 $ */
5637 /* $Date: 2006/03/31 14:18:44 $ */
5638
5374 /* End: bn_mp_prime_is_divisible.c */ 5639 /* End: bn_mp_prime_is_divisible.c */
5375 5640
5376 /* Start: bn_mp_prime_is_prime.c */ 5641 /* Start: bn_mp_prime_is_prime.c */
5377 #include <tommath.h> 5642 #include <tommath.h>
5378 #ifdef BN_MP_PRIME_IS_PRIME_C 5643 #ifdef BN_MP_PRIME_IS_PRIME_C
5386 * additional optimizations in place. 5651 * additional optimizations in place.
5387 * 5652 *
5388 * The library is free for all purposes without any express 5653 * The library is free for all purposes without any express
5389 * guarantee it works. 5654 * guarantee it works.
5390 * 5655 *
5391 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5656 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5392 */ 5657 */
5393 5658
5394 /* performs a variable number of rounds of Miller-Rabin 5659 /* performs a variable number of rounds of Miller-Rabin
5395 * 5660 *
5396 * Probability of error after t rounds is no more than 5661 * Probability of error after t rounds is no more than
5452 LBL_B:mp_clear (&b); 5717 LBL_B:mp_clear (&b);
5453 return err; 5718 return err;
5454 } 5719 }
5455 #endif 5720 #endif
5456 5721
5722 /* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_prime.c,v $ */
5723 /* $Revision: 1.3 $ */
5724 /* $Date: 2006/03/31 14:18:44 $ */
5725
5457 /* End: bn_mp_prime_is_prime.c */ 5726 /* End: bn_mp_prime_is_prime.c */
5458 5727
5459 /* Start: bn_mp_prime_miller_rabin.c */ 5728 /* Start: bn_mp_prime_miller_rabin.c */
5460 #include <tommath.h> 5729 #include <tommath.h>
5461 #ifdef BN_MP_PRIME_MILLER_RABIN_C 5730 #ifdef BN_MP_PRIME_MILLER_RABIN_C
5469 * additional optimizations in place. 5738 * additional optimizations in place.
5470 * 5739 *
5471 * The library is free for all purposes without any express 5740 * The library is free for all purposes without any express
5472 * guarantee it works. 5741 * guarantee it works.
5473 * 5742 *
5474 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5743 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5475 */ 5744 */
5476 5745
5477 /* Miller-Rabin test of "a" to the base of "b" as described in 5746 /* Miller-Rabin test of "a" to the base of "b" as described in
5478 * HAC pp. 139 Algorithm 4.24 5747 * HAC pp. 139 Algorithm 4.24
5479 * 5748 *
5555 LBL_N1:mp_clear (&n1); 5824 LBL_N1:mp_clear (&n1);
5556 return err; 5825 return err;
5557 } 5826 }
5558 #endif 5827 #endif
5559 5828
5829 /* $Source: /cvs/libtom/libtommath/bn_mp_prime_miller_rabin.c,v $ */
5830 /* $Revision: 1.3 $ */
5831 /* $Date: 2006/03/31 14:18:44 $ */
5832
5560 /* End: bn_mp_prime_miller_rabin.c */ 5833 /* End: bn_mp_prime_miller_rabin.c */
5561 5834
5562 /* Start: bn_mp_prime_next_prime.c */ 5835 /* Start: bn_mp_prime_next_prime.c */
5563 #include <tommath.h> 5836 #include <tommath.h>
5564 #ifdef BN_MP_PRIME_NEXT_PRIME_C 5837 #ifdef BN_MP_PRIME_NEXT_PRIME_C
5572 * additional optimizations in place. 5845 * additional optimizations in place.
5573 * 5846 *
5574 * The library is free for all purposes without any express 5847 * The library is free for all purposes without any express
5575 * guarantee it works. 5848 * guarantee it works.
5576 * 5849 *
5577 * Tom St Denis, [email protected], http://math.libtomcrypt.org 5850 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5578 */ 5851 */
5579 5852
5580 /* finds the next prime after the number "a" using "t" trials 5853 /* finds the next prime after the number "a" using "t" trials
5581 * of Miller-Rabin. 5854 * of Miller-Rabin.
5582 * 5855 *
5725 return err; 5998 return err;
5726 } 5999 }
5727 6000
5728 #endif 6001 #endif
5729 6002
6003 /* $Source: /cvs/libtom/libtommath/bn_mp_prime_next_prime.c,v $ */
6004 /* $Revision: 1.3 $ */
6005 /* $Date: 2006/03/31 14:18:44 $ */
6006
5730 /* End: bn_mp_prime_next_prime.c */ 6007 /* End: bn_mp_prime_next_prime.c */
5731 6008
5732 /* Start: bn_mp_prime_rabin_miller_trials.c */ 6009 /* Start: bn_mp_prime_rabin_miller_trials.c */
5733 #include <tommath.h> 6010 #include <tommath.h>
5734 #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C 6011 #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C
5742 * additional optimizations in place. 6019 * additional optimizations in place.
5743 * 6020 *
5744 * The library is free for all purposes without any express 6021 * The library is free for all purposes without any express
5745 * guarantee it works. 6022 * guarantee it works.
5746 * 6023 *
5747 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6024 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5748 */ 6025 */
5749 6026
5750 6027
5751 static const struct { 6028 static const struct {
5752 int k, t; 6029 int k, t;
5777 } 6054 }
5778 6055
5779 6056
5780 #endif 6057 #endif
5781 6058
6059 /* $Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v $ */
6060 /* $Revision: 1.3 $ */
6061 /* $Date: 2006/03/31 14:18:44 $ */
6062
5782 /* End: bn_mp_prime_rabin_miller_trials.c */ 6063 /* End: bn_mp_prime_rabin_miller_trials.c */
5783 6064
5784 /* Start: bn_mp_prime_random_ex.c */ 6065 /* Start: bn_mp_prime_random_ex.c */
5785 #include <tommath.h> 6066 #include <tommath.h>
5786 #ifdef BN_MP_PRIME_RANDOM_EX_C 6067 #ifdef BN_MP_PRIME_RANDOM_EX_C
5794 * additional optimizations in place. 6075 * additional optimizations in place.
5795 * 6076 *
5796 * The library is free for all purposes without any express 6077 * The library is free for all purposes without any express
5797 * guarantee it works. 6078 * guarantee it works.
5798 * 6079 *
5799 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6080 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5800 */ 6081 */
5801 6082
5802 /* makes a truly random prime of a given size (bits), 6083 /* makes a truly random prime of a given size (bits),
5803 * 6084 *
5804 * Flags are as follows: 6085 * Flags are as follows:
5844 6125
5845 /* calc the maskOR_msb */ 6126 /* calc the maskOR_msb */
5846 maskOR_msb = 0; 6127 maskOR_msb = 0;
5847 maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0; 6128 maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
5848 if (flags & LTM_PRIME_2MSB_ON) { 6129 if (flags & LTM_PRIME_2MSB_ON) {
5849 maskOR_msb |= 1 << ((size - 2) & 7); 6130 maskOR_msb |= 0x80 >> ((9 - size) & 7);
5850 } else if (flags & LTM_PRIME_2MSB_OFF) { 6131 }
5851 maskAND &= ~(1 << ((size - 2) & 7));
5852 }
5853 6132
5854 /* get the maskOR_lsb */ 6133 /* get the maskOR_lsb */
5855 maskOR_lsb = 1; 6134 maskOR_lsb = 1;
5856 if (flags & LTM_PRIME_BBS) { 6135 if (flags & LTM_PRIME_BBS) {
5857 maskOR_lsb |= 3; 6136 maskOR_lsb |= 3;
5904 } 6183 }
5905 6184
5906 6185
5907 #endif 6186 #endif
5908 6187
6188 /* $Source: /cvs/libtom/libtommath/bn_mp_prime_random_ex.c,v $ */
6189 /* $Revision: 1.4 $ */
6190 /* $Date: 2006/03/31 14:18:44 $ */
6191
5909 /* End: bn_mp_prime_random_ex.c */ 6192 /* End: bn_mp_prime_random_ex.c */
5910 6193
5911 /* Start: bn_mp_radix_size.c */ 6194 /* Start: bn_mp_radix_size.c */
5912 #include <tommath.h> 6195 #include <tommath.h>
5913 #ifdef BN_MP_RADIX_SIZE_C 6196 #ifdef BN_MP_RADIX_SIZE_C
5921 * additional optimizations in place. 6204 * additional optimizations in place.
5922 * 6205 *
5923 * The library is free for all purposes without any express 6206 * The library is free for all purposes without any express
5924 * guarantee it works. 6207 * guarantee it works.
5925 * 6208 *
5926 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6209 * Tom St Denis, [email protected], http://math.libtomcrypt.com
5927 */ 6210 */
5928 6211
5929 /* returns size of ASCII reprensentation */ 6212 /* returns size of ASCII reprensentation */
5930 int mp_radix_size (mp_int * a, int radix, int *size) 6213 int mp_radix_size (mp_int * a, int radix, int *size)
5931 { 6214 {
5945 if (radix < 2 || radix > 64) { 6228 if (radix < 2 || radix > 64) {
5946 return MP_VAL; 6229 return MP_VAL;
5947 } 6230 }
5948 6231
5949 if (mp_iszero(a) == MP_YES) { 6232 if (mp_iszero(a) == MP_YES) {
5950 *size = 2; 6233 *size = 2;
5951 return MP_OKAY; 6234 return MP_OKAY;
5952 } 6235 }
5953 6236
5954 /* digs is the digit count */ 6237 /* digs is the digit count */
5955 digs = 0; 6238 digs = 0;
5982 return MP_OKAY; 6265 return MP_OKAY;
5983 } 6266 }
5984 6267
5985 #endif 6268 #endif
5986 6269
6270 /* $Source: /cvs/libtom/libtommath/bn_mp_radix_size.c,v $ */
6271 /* $Revision: 1.4 $ */
6272 /* $Date: 2006/03/31 14:18:44 $ */
6273
5987 /* End: bn_mp_radix_size.c */ 6274 /* End: bn_mp_radix_size.c */
5988 6275
5989 /* Start: bn_mp_radix_smap.c */ 6276 /* Start: bn_mp_radix_smap.c */
5990 #include <tommath.h> 6277 #include <tommath.h>
5991 #ifdef BN_MP_RADIX_SMAP_C 6278 #ifdef BN_MP_RADIX_SMAP_C
5999 * additional optimizations in place. 6286 * additional optimizations in place.
6000 * 6287 *
6001 * The library is free for all purposes without any express 6288 * The library is free for all purposes without any express
6002 * guarantee it works. 6289 * guarantee it works.
6003 * 6290 *
6004 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6291 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6005 */ 6292 */
6006 6293
6007 /* chars used in radix conversions */ 6294 /* chars used in radix conversions */
6008 const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; 6295 const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
6009 #endif 6296 #endif
6010 6297
6298 /* $Source: /cvs/libtom/libtommath/bn_mp_radix_smap.c,v $ */
6299 /* $Revision: 1.3 $ */
6300 /* $Date: 2006/03/31 14:18:44 $ */
6301
6011 /* End: bn_mp_radix_smap.c */ 6302 /* End: bn_mp_radix_smap.c */
6012 6303
6013 /* Start: bn_mp_rand.c */ 6304 /* Start: bn_mp_rand.c */
6014 #include <tommath.h> 6305 #include <tommath.h>
6015 #ifdef BN_MP_RAND_C 6306 #ifdef BN_MP_RAND_C
6023 * additional optimizations in place. 6314 * additional optimizations in place.
6024 * 6315 *
6025 * The library is free for all purposes without any express 6316 * The library is free for all purposes without any express
6026 * guarantee it works. 6317 * guarantee it works.
6027 * 6318 *
6028 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6319 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6029 */ 6320 */
6030 6321
6031 /* makes a pseudo-random int of a given size */ 6322 /* makes a pseudo-random int of a given size */
6032 int 6323 int
6033 mp_rand (mp_int * a, int digits) 6324 mp_rand (mp_int * a, int digits)
6061 6352
6062 return MP_OKAY; 6353 return MP_OKAY;
6063 } 6354 }
6064 #endif 6355 #endif
6065 6356
6357 /* $Source: /cvs/libtom/libtommath/bn_mp_rand.c,v $ */
6358 /* $Revision: 1.3 $ */
6359 /* $Date: 2006/03/31 14:18:44 $ */
6360
6066 /* End: bn_mp_rand.c */ 6361 /* End: bn_mp_rand.c */
6067 6362
6068 /* Start: bn_mp_read_radix.c */ 6363 /* Start: bn_mp_read_radix.c */
6069 #include <tommath.h> 6364 #include <tommath.h>
6070 #ifdef BN_MP_READ_RADIX_C 6365 #ifdef BN_MP_READ_RADIX_C
6078 * additional optimizations in place. 6373 * additional optimizations in place.
6079 * 6374 *
6080 * The library is free for all purposes without any express 6375 * The library is free for all purposes without any express
6081 * guarantee it works. 6376 * guarantee it works.
6082 * 6377 *
6083 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6378 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6084 */ 6379 */
6085 6380
6086 /* read a string [ASCII] in a given radix */ 6381 /* read a string [ASCII] in a given radix */
6087 int mp_read_radix (mp_int * a, const char *str, int radix) 6382 int mp_read_radix (mp_int * a, const char *str, int radix)
6088 { 6383 {
6089 int y, res, neg; 6384 int y, res, neg;
6090 char ch; 6385 char ch;
6386
6387 /* zero the digit bignum */
6388 mp_zero(a);
6091 6389
6092 /* make sure the radix is ok */ 6390 /* make sure the radix is ok */
6093 if (radix < 2 || radix > 64) { 6391 if (radix < 2 || radix > 64) {
6094 return MP_VAL; 6392 return MP_VAL;
6095 } 6393 }
6143 } 6441 }
6144 return MP_OKAY; 6442 return MP_OKAY;
6145 } 6443 }
6146 #endif 6444 #endif
6147 6445
6446 /* $Source: /cvs/libtom/libtommath/bn_mp_read_radix.c,v $ */
6447 /* $Revision: 1.4 $ */
6448 /* $Date: 2006/03/31 14:18:44 $ */
6449
6148 /* End: bn_mp_read_radix.c */ 6450 /* End: bn_mp_read_radix.c */
6149 6451
6150 /* Start: bn_mp_read_signed_bin.c */ 6452 /* Start: bn_mp_read_signed_bin.c */
6151 #include <tommath.h> 6453 #include <tommath.h>
6152 #ifdef BN_MP_READ_SIGNED_BIN_C 6454 #ifdef BN_MP_READ_SIGNED_BIN_C
6160 * additional optimizations in place. 6462 * additional optimizations in place.
6161 * 6463 *
6162 * The library is free for all purposes without any express 6464 * The library is free for all purposes without any express
6163 * guarantee it works. 6465 * guarantee it works.
6164 * 6466 *
6165 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6467 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6166 */ 6468 */
6167 6469
6168 /* read signed bin, big endian, first byte is 0==positive or 1==negative */ 6470 /* read signed bin, big endian, first byte is 0==positive or 1==negative */
6169 int 6471 int mp_read_signed_bin (mp_int * a, const unsigned char *b, int c)
6170 mp_read_signed_bin (mp_int * a, unsigned char *b, int c)
6171 { 6472 {
6172 int res; 6473 int res;
6173 6474
6174 /* read magnitude */ 6475 /* read magnitude */
6175 if ((res = mp_read_unsigned_bin (a, b + 1, c - 1)) != MP_OKAY) { 6476 if ((res = mp_read_unsigned_bin (a, b + 1, c - 1)) != MP_OKAY) {
6185 6486
6186 return MP_OKAY; 6487 return MP_OKAY;
6187 } 6488 }
6188 #endif 6489 #endif
6189 6490
6491 /* $Source: /cvs/libtom/libtommath/bn_mp_read_signed_bin.c,v $ */
6492 /* $Revision: 1.4 $ */
6493 /* $Date: 2006/03/31 14:18:44 $ */
6494
6190 /* End: bn_mp_read_signed_bin.c */ 6495 /* End: bn_mp_read_signed_bin.c */
6191 6496
6192 /* Start: bn_mp_read_unsigned_bin.c */ 6497 /* Start: bn_mp_read_unsigned_bin.c */
6193 #include <tommath.h> 6498 #include <tommath.h>
6194 #ifdef BN_MP_READ_UNSIGNED_BIN_C 6499 #ifdef BN_MP_READ_UNSIGNED_BIN_C
6202 * additional optimizations in place. 6507 * additional optimizations in place.
6203 * 6508 *
6204 * The library is free for all purposes without any express 6509 * The library is free for all purposes without any express
6205 * guarantee it works. 6510 * guarantee it works.
6206 * 6511 *
6207 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6512 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6208 */ 6513 */
6209 6514
6210 /* reads a unsigned char array, assumes the msb is stored first [big endian] */ 6515 /* reads a unsigned char array, assumes the msb is stored first [big endian] */
6211 int 6516 int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c)
6212 mp_read_unsigned_bin (mp_int * a, unsigned char *b, int c)
6213 { 6517 {
6214 int res; 6518 int res;
6215 6519
6216 /* make sure there are at least two digits */ 6520 /* make sure there are at least two digits */
6217 if (a->alloc < 2) { 6521 if (a->alloc < 2) {
6241 mp_clamp (a); 6545 mp_clamp (a);
6242 return MP_OKAY; 6546 return MP_OKAY;
6243 } 6547 }
6244 #endif 6548 #endif
6245 6549
6550 /* $Source: /cvs/libtom/libtommath/bn_mp_read_unsigned_bin.c,v $ */
6551 /* $Revision: 1.4 $ */
6552 /* $Date: 2006/03/31 14:18:44 $ */
6553
6246 /* End: bn_mp_read_unsigned_bin.c */ 6554 /* End: bn_mp_read_unsigned_bin.c */
6247 6555
6248 /* Start: bn_mp_reduce.c */ 6556 /* Start: bn_mp_reduce.c */
6249 #include <tommath.h> 6557 #include <tommath.h>
6250 #ifdef BN_MP_REDUCE_C 6558 #ifdef BN_MP_REDUCE_C
6258 * additional optimizations in place. 6566 * additional optimizations in place.
6259 * 6567 *
6260 * The library is free for all purposes without any express 6568 * The library is free for all purposes without any express
6261 * guarantee it works. 6569 * guarantee it works.
6262 * 6570 *
6263 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6571 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6264 */ 6572 */
6265 6573
6266 /* reduces x mod m, assumes 0 < x < m**2, mu is 6574 /* reduces x mod m, assumes 0 < x < m**2, mu is
6267 * precomputed via mp_reduce_setup. 6575 * precomputed via mp_reduce_setup.
6268 * From HAC pp.604 Algorithm 14.42 6576 * From HAC pp.604 Algorithm 14.42
6341 6649
6342 return res; 6650 return res;
6343 } 6651 }
6344 #endif 6652 #endif
6345 6653
6654 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce.c,v $ */
6655 /* $Revision: 1.3 $ */
6656 /* $Date: 2006/03/31 14:18:44 $ */
6657
6346 /* End: bn_mp_reduce.c */ 6658 /* End: bn_mp_reduce.c */
6347 6659
6348 /* Start: bn_mp_reduce_2k.c */ 6660 /* Start: bn_mp_reduce_2k.c */
6349 #include <tommath.h> 6661 #include <tommath.h>
6350 #ifdef BN_MP_REDUCE_2K_C 6662 #ifdef BN_MP_REDUCE_2K_C
6358 * additional optimizations in place. 6670 * additional optimizations in place.
6359 * 6671 *
6360 * The library is free for all purposes without any express 6672 * The library is free for all purposes without any express
6361 * guarantee it works. 6673 * guarantee it works.
6362 * 6674 *
6363 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6675 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6364 */ 6676 */
6365 6677
6366 /* reduces a modulo n where n is of the form 2**p - d */ 6678 /* reduces a modulo n where n is of the form 2**p - d */
6367 int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d) 6679 int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d)
6368 { 6680 {
6402 return res; 6714 return res;
6403 } 6715 }
6404 6716
6405 #endif 6717 #endif
6406 6718
6719 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k.c,v $ */
6720 /* $Revision: 1.3 $ */
6721 /* $Date: 2006/03/31 14:18:44 $ */
6722
6407 /* End: bn_mp_reduce_2k.c */ 6723 /* End: bn_mp_reduce_2k.c */
6408 6724
6409 /* Start: bn_mp_reduce_2k_l.c */ 6725 /* Start: bn_mp_reduce_2k_l.c */
6410 #include <tommath.h> 6726 #include <tommath.h>
6411 #ifdef BN_MP_REDUCE_2K_L_C 6727 #ifdef BN_MP_REDUCE_2K_L_C
6419 * additional optimizations in place. 6735 * additional optimizations in place.
6420 * 6736 *
6421 * The library is free for all purposes without any express 6737 * The library is free for all purposes without any express
6422 * guarantee it works. 6738 * guarantee it works.
6423 * 6739 *
6424 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6740 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6425 */ 6741 */
6426 6742
6427 /* reduces a modulo n where n is of the form 2**p - d 6743 /* reduces a modulo n where n is of the form 2**p - d
6428 This differs from reduce_2k since "d" can be larger 6744 This differs from reduce_2k since "d" can be larger
6429 than a single digit. 6745 than a single digit.
6464 return res; 6780 return res;
6465 } 6781 }
6466 6782
6467 #endif 6783 #endif
6468 6784
6785 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_l.c,v $ */
6786 /* $Revision: 1.3 $ */
6787 /* $Date: 2006/03/31 14:18:44 $ */
6788
6469 /* End: bn_mp_reduce_2k_l.c */ 6789 /* End: bn_mp_reduce_2k_l.c */
6470 6790
6471 /* Start: bn_mp_reduce_2k_setup.c */ 6791 /* Start: bn_mp_reduce_2k_setup.c */
6472 #include <tommath.h> 6792 #include <tommath.h>
6473 #ifdef BN_MP_REDUCE_2K_SETUP_C 6793 #ifdef BN_MP_REDUCE_2K_SETUP_C
6481 * additional optimizations in place. 6801 * additional optimizations in place.
6482 * 6802 *
6483 * The library is free for all purposes without any express 6803 * The library is free for all purposes without any express
6484 * guarantee it works. 6804 * guarantee it works.
6485 * 6805 *
6486 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6806 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6487 */ 6807 */
6488 6808
6489 /* determines the setup value */ 6809 /* determines the setup value */
6490 int mp_reduce_2k_setup(mp_int *a, mp_digit *d) 6810 int mp_reduce_2k_setup(mp_int *a, mp_digit *d)
6491 { 6811 {
6511 mp_clear(&tmp); 6831 mp_clear(&tmp);
6512 return MP_OKAY; 6832 return MP_OKAY;
6513 } 6833 }
6514 #endif 6834 #endif
6515 6835
6836 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup.c,v $ */
6837 /* $Revision: 1.3 $ */
6838 /* $Date: 2006/03/31 14:18:44 $ */
6839
6516 /* End: bn_mp_reduce_2k_setup.c */ 6840 /* End: bn_mp_reduce_2k_setup.c */
6517 6841
6518 /* Start: bn_mp_reduce_2k_setup_l.c */ 6842 /* Start: bn_mp_reduce_2k_setup_l.c */
6519 #include <tommath.h> 6843 #include <tommath.h>
6520 #ifdef BN_MP_REDUCE_2K_SETUP_L_C 6844 #ifdef BN_MP_REDUCE_2K_SETUP_L_C
6528 * additional optimizations in place. 6852 * additional optimizations in place.
6529 * 6853 *
6530 * The library is free for all purposes without any express 6854 * The library is free for all purposes without any express
6531 * guarantee it works. 6855 * guarantee it works.
6532 * 6856 *
6533 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6857 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6534 */ 6858 */
6535 6859
6536 /* determines the setup value */ 6860 /* determines the setup value */
6537 int mp_reduce_2k_setup_l(mp_int *a, mp_int *d) 6861 int mp_reduce_2k_setup_l(mp_int *a, mp_int *d)
6538 { 6862 {
6555 mp_clear(&tmp); 6879 mp_clear(&tmp);
6556 return res; 6880 return res;
6557 } 6881 }
6558 #endif 6882 #endif
6559 6883
6884 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup_l.c,v $ */
6885 /* $Revision: 1.3 $ */
6886 /* $Date: 2006/03/31 14:18:44 $ */
6887
6560 /* End: bn_mp_reduce_2k_setup_l.c */ 6888 /* End: bn_mp_reduce_2k_setup_l.c */
6561 6889
6562 /* Start: bn_mp_reduce_is_2k.c */ 6890 /* Start: bn_mp_reduce_is_2k.c */
6563 #include <tommath.h> 6891 #include <tommath.h>
6564 #ifdef BN_MP_REDUCE_IS_2K_C 6892 #ifdef BN_MP_REDUCE_IS_2K_C
6572 * additional optimizations in place. 6900 * additional optimizations in place.
6573 * 6901 *
6574 * The library is free for all purposes without any express 6902 * The library is free for all purposes without any express
6575 * guarantee it works. 6903 * guarantee it works.
6576 * 6904 *
6577 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6905 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6578 */ 6906 */
6579 6907
6580 /* determines if mp_reduce_2k can be used */ 6908 /* determines if mp_reduce_2k can be used */
6581 int mp_reduce_is_2k(mp_int *a) 6909 int mp_reduce_is_2k(mp_int *a)
6582 { 6910 {
6607 return MP_YES; 6935 return MP_YES;
6608 } 6936 }
6609 6937
6610 #endif 6938 #endif
6611 6939
6940 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k.c,v $ */
6941 /* $Revision: 1.3 $ */
6942 /* $Date: 2006/03/31 14:18:44 $ */
6943
6612 /* End: bn_mp_reduce_is_2k.c */ 6944 /* End: bn_mp_reduce_is_2k.c */
6613 6945
6614 /* Start: bn_mp_reduce_is_2k_l.c */ 6946 /* Start: bn_mp_reduce_is_2k_l.c */
6615 #include <tommath.h> 6947 #include <tommath.h>
6616 #ifdef BN_MP_REDUCE_IS_2K_L_C 6948 #ifdef BN_MP_REDUCE_IS_2K_L_C
6624 * additional optimizations in place. 6956 * additional optimizations in place.
6625 * 6957 *
6626 * The library is free for all purposes without any express 6958 * The library is free for all purposes without any express
6627 * guarantee it works. 6959 * guarantee it works.
6628 * 6960 *
6629 * Tom St Denis, [email protected], http://math.libtomcrypt.org 6961 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6630 */ 6962 */
6631 6963
6632 /* determines if reduce_2k_l can be used */ 6964 /* determines if reduce_2k_l can be used */
6633 int mp_reduce_is_2k_l(mp_int *a) 6965 int mp_reduce_is_2k_l(mp_int *a)
6634 { 6966 {
6651 return MP_NO; 6983 return MP_NO;
6652 } 6984 }
6653 6985
6654 #endif 6986 #endif
6655 6987
6988 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v $ */
6989 /* $Revision: 1.3 $ */
6990 /* $Date: 2006/03/31 14:18:44 $ */
6991
6656 /* End: bn_mp_reduce_is_2k_l.c */ 6992 /* End: bn_mp_reduce_is_2k_l.c */
6657 6993
6658 /* Start: bn_mp_reduce_setup.c */ 6994 /* Start: bn_mp_reduce_setup.c */
6659 #include <tommath.h> 6995 #include <tommath.h>
6660 #ifdef BN_MP_REDUCE_SETUP_C 6996 #ifdef BN_MP_REDUCE_SETUP_C
6668 * additional optimizations in place. 7004 * additional optimizations in place.
6669 * 7005 *
6670 * The library is free for all purposes without any express 7006 * The library is free for all purposes without any express
6671 * guarantee it works. 7007 * guarantee it works.
6672 * 7008 *
6673 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7009 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6674 */ 7010 */
6675 7011
6676 /* pre-calculate the value required for Barrett reduction 7012 /* pre-calculate the value required for Barrett reduction
6677 * For a given modulus "b" it calulates the value required in "a" 7013 * For a given modulus "b" it calulates the value required in "a"
6678 */ 7014 */
6685 } 7021 }
6686 return mp_div (a, b, a, NULL); 7022 return mp_div (a, b, a, NULL);
6687 } 7023 }
6688 #endif 7024 #endif
6689 7025
7026 /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_setup.c,v $ */
7027 /* $Revision: 1.3 $ */
7028 /* $Date: 2006/03/31 14:18:44 $ */
7029
6690 /* End: bn_mp_reduce_setup.c */ 7030 /* End: bn_mp_reduce_setup.c */
6691 7031
6692 /* Start: bn_mp_rshd.c */ 7032 /* Start: bn_mp_rshd.c */
6693 #include <tommath.h> 7033 #include <tommath.h>
6694 #ifdef BN_MP_RSHD_C 7034 #ifdef BN_MP_RSHD_C
6702 * additional optimizations in place. 7042 * additional optimizations in place.
6703 * 7043 *
6704 * The library is free for all purposes without any express 7044 * The library is free for all purposes without any express
6705 * guarantee it works. 7045 * guarantee it works.
6706 * 7046 *
6707 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7047 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6708 */ 7048 */
6709 7049
6710 /* shift right a certain amount of digits */ 7050 /* shift right a certain amount of digits */
6711 void mp_rshd (mp_int * a, int b) 7051 void mp_rshd (mp_int * a, int b)
6712 { 7052 {
6757 /* remove excess digits */ 7097 /* remove excess digits */
6758 a->used -= b; 7098 a->used -= b;
6759 } 7099 }
6760 #endif 7100 #endif
6761 7101
7102 /* $Source: /cvs/libtom/libtommath/bn_mp_rshd.c,v $ */
7103 /* $Revision: 1.3 $ */
7104 /* $Date: 2006/03/31 14:18:44 $ */
7105
6762 /* End: bn_mp_rshd.c */ 7106 /* End: bn_mp_rshd.c */
6763 7107
6764 /* Start: bn_mp_set.c */ 7108 /* Start: bn_mp_set.c */
6765 #include <tommath.h> 7109 #include <tommath.h>
6766 #ifdef BN_MP_SET_C 7110 #ifdef BN_MP_SET_C
6774 * additional optimizations in place. 7118 * additional optimizations in place.
6775 * 7119 *
6776 * The library is free for all purposes without any express 7120 * The library is free for all purposes without any express
6777 * guarantee it works. 7121 * guarantee it works.
6778 * 7122 *
6779 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7123 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6780 */ 7124 */
6781 7125
6782 /* set to a digit */ 7126 /* set to a digit */
6783 void mp_set (mp_int * a, mp_digit b) 7127 void mp_set (mp_int * a, mp_digit b)
6784 { 7128 {
6786 a->dp[0] = b & MP_MASK; 7130 a->dp[0] = b & MP_MASK;
6787 a->used = (a->dp[0] != 0) ? 1 : 0; 7131 a->used = (a->dp[0] != 0) ? 1 : 0;
6788 } 7132 }
6789 #endif 7133 #endif
6790 7134
7135 /* $Source: /cvs/libtom/libtommath/bn_mp_set.c,v $ */
7136 /* $Revision: 1.3 $ */
7137 /* $Date: 2006/03/31 14:18:44 $ */
7138
6791 /* End: bn_mp_set.c */ 7139 /* End: bn_mp_set.c */
6792 7140
6793 /* Start: bn_mp_set_int.c */ 7141 /* Start: bn_mp_set_int.c */
6794 #include <tommath.h> 7142 #include <tommath.h>
6795 #ifdef BN_MP_SET_INT_C 7143 #ifdef BN_MP_SET_INT_C
6803 * additional optimizations in place. 7151 * additional optimizations in place.
6804 * 7152 *
6805 * The library is free for all purposes without any express 7153 * The library is free for all purposes without any express
6806 * guarantee it works. 7154 * guarantee it works.
6807 * 7155 *
6808 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7156 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6809 */ 7157 */
6810 7158
6811 /* set a 32-bit const */ 7159 /* set a 32-bit const */
6812 int mp_set_int (mp_int * a, unsigned long b) 7160 int mp_set_int (mp_int * a, unsigned long b)
6813 { 7161 {
6834 mp_clamp (a); 7182 mp_clamp (a);
6835 return MP_OKAY; 7183 return MP_OKAY;
6836 } 7184 }
6837 #endif 7185 #endif
6838 7186
7187 /* $Source: /cvs/libtom/libtommath/bn_mp_set_int.c,v $ */
7188 /* $Revision: 1.3 $ */
7189 /* $Date: 2006/03/31 14:18:44 $ */
7190
6839 /* End: bn_mp_set_int.c */ 7191 /* End: bn_mp_set_int.c */
6840 7192
6841 /* Start: bn_mp_shrink.c */ 7193 /* Start: bn_mp_shrink.c */
6842 #include <tommath.h> 7194 #include <tommath.h>
6843 #ifdef BN_MP_SHRINK_C 7195 #ifdef BN_MP_SHRINK_C
6851 * additional optimizations in place. 7203 * additional optimizations in place.
6852 * 7204 *
6853 * The library is free for all purposes without any express 7205 * The library is free for all purposes without any express
6854 * guarantee it works. 7206 * guarantee it works.
6855 * 7207 *
6856 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7208 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6857 */ 7209 */
6858 7210
6859 /* shrink a bignum */ 7211 /* shrink a bignum */
6860 int mp_shrink (mp_int * a) 7212 int mp_shrink (mp_int * a)
6861 { 7213 {
6869 } 7221 }
6870 return MP_OKAY; 7222 return MP_OKAY;
6871 } 7223 }
6872 #endif 7224 #endif
6873 7225
7226 /* $Source: /cvs/libtom/libtommath/bn_mp_shrink.c,v $ */
7227 /* $Revision: 1.3 $ */
7228 /* $Date: 2006/03/31 14:18:44 $ */
7229
6874 /* End: bn_mp_shrink.c */ 7230 /* End: bn_mp_shrink.c */
6875 7231
6876 /* Start: bn_mp_signed_bin_size.c */ 7232 /* Start: bn_mp_signed_bin_size.c */
6877 #include <tommath.h> 7233 #include <tommath.h>
6878 #ifdef BN_MP_SIGNED_BIN_SIZE_C 7234 #ifdef BN_MP_SIGNED_BIN_SIZE_C
6886 * additional optimizations in place. 7242 * additional optimizations in place.
6887 * 7243 *
6888 * The library is free for all purposes without any express 7244 * The library is free for all purposes without any express
6889 * guarantee it works. 7245 * guarantee it works.
6890 * 7246 *
6891 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7247 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6892 */ 7248 */
6893 7249
6894 /* get the size for an signed equivalent */ 7250 /* get the size for an signed equivalent */
6895 int mp_signed_bin_size (mp_int * a) 7251 int mp_signed_bin_size (mp_int * a)
6896 { 7252 {
6897 return 1 + mp_unsigned_bin_size (a); 7253 return 1 + mp_unsigned_bin_size (a);
6898 } 7254 }
6899 #endif 7255 #endif
6900 7256
7257 /* $Source: /cvs/libtom/libtommath/bn_mp_signed_bin_size.c,v $ */
7258 /* $Revision: 1.3 $ */
7259 /* $Date: 2006/03/31 14:18:44 $ */
7260
6901 /* End: bn_mp_signed_bin_size.c */ 7261 /* End: bn_mp_signed_bin_size.c */
6902 7262
6903 /* Start: bn_mp_sqr.c */ 7263 /* Start: bn_mp_sqr.c */
6904 #include <tommath.h> 7264 #include <tommath.h>
6905 #ifdef BN_MP_SQR_C 7265 #ifdef BN_MP_SQR_C
6913 * additional optimizations in place. 7273 * additional optimizations in place.
6914 * 7274 *
6915 * The library is free for all purposes without any express 7275 * The library is free for all purposes without any express
6916 * guarantee it works. 7276 * guarantee it works.
6917 * 7277 *
6918 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7278 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6919 */ 7279 */
6920 7280
6921 /* computes b = a*a */ 7281 /* computes b = a*a */
6922 int 7282 int
6923 mp_sqr (mp_int * a, mp_int * b) 7283 mp_sqr (mp_int * a, mp_int * b)
6954 b->sign = MP_ZPOS; 7314 b->sign = MP_ZPOS;
6955 return res; 7315 return res;
6956 } 7316 }
6957 #endif 7317 #endif
6958 7318
7319 /* $Source: /cvs/libtom/libtommath/bn_mp_sqr.c,v $ */
7320 /* $Revision: 1.3 $ */
7321 /* $Date: 2006/03/31 14:18:44 $ */
7322
6959 /* End: bn_mp_sqr.c */ 7323 /* End: bn_mp_sqr.c */
6960 7324
6961 /* Start: bn_mp_sqrmod.c */ 7325 /* Start: bn_mp_sqrmod.c */
6962 #include <tommath.h> 7326 #include <tommath.h>
6963 #ifdef BN_MP_SQRMOD_C 7327 #ifdef BN_MP_SQRMOD_C
6971 * additional optimizations in place. 7335 * additional optimizations in place.
6972 * 7336 *
6973 * The library is free for all purposes without any express 7337 * The library is free for all purposes without any express
6974 * guarantee it works. 7338 * guarantee it works.
6975 * 7339 *
6976 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7340 * Tom St Denis, [email protected], http://math.libtomcrypt.com
6977 */ 7341 */
6978 7342
6979 /* c = a * a (mod b) */ 7343 /* c = a * a (mod b) */
6980 int 7344 int
6981 mp_sqrmod (mp_int * a, mp_int * b, mp_int * c) 7345 mp_sqrmod (mp_int * a, mp_int * b, mp_int * c)
6995 mp_clear (&t); 7359 mp_clear (&t);
6996 return res; 7360 return res;
6997 } 7361 }
6998 #endif 7362 #endif
6999 7363
7364 /* $Source: /cvs/libtom/libtommath/bn_mp_sqrmod.c,v $ */
7365 /* $Revision: 1.3 $ */
7366 /* $Date: 2006/03/31 14:18:44 $ */
7367
7000 /* End: bn_mp_sqrmod.c */ 7368 /* End: bn_mp_sqrmod.c */
7001 7369
7002 /* Start: bn_mp_sqrt.c */ 7370 /* Start: bn_mp_sqrt.c */
7003 #include <tommath.h> 7371 #include <tommath.h>
7004 #ifdef BN_MP_SQRT_C 7372 #ifdef BN_MP_SQRT_C
7012 * additional optimizations in place. 7380 * additional optimizations in place.
7013 * 7381 *
7014 * The library is free for all purposes without any express 7382 * The library is free for all purposes without any express
7015 * guarantee it works. 7383 * guarantee it works.
7016 * 7384 *
7017 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7385 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7018 */ 7386 */
7019 7387
7020 /* this function is less generic than mp_n_root, simpler and faster */ 7388 /* this function is less generic than mp_n_root, simpler and faster */
7021 int mp_sqrt(mp_int *arg, mp_int *ret) 7389 int mp_sqrt(mp_int *arg, mp_int *ret)
7022 { 7390 {
7076 return res; 7444 return res;
7077 } 7445 }
7078 7446
7079 #endif 7447 #endif
7080 7448
7449 /* $Source: /cvs/libtom/libtommath/bn_mp_sqrt.c,v $ */
7450 /* $Revision: 1.3 $ */
7451 /* $Date: 2006/03/31 14:18:44 $ */
7452
7081 /* End: bn_mp_sqrt.c */ 7453 /* End: bn_mp_sqrt.c */
7082 7454
7083 /* Start: bn_mp_sub.c */ 7455 /* Start: bn_mp_sub.c */
7084 #include <tommath.h> 7456 #include <tommath.h>
7085 #ifdef BN_MP_SUB_C 7457 #ifdef BN_MP_SUB_C
7093 * additional optimizations in place. 7465 * additional optimizations in place.
7094 * 7466 *
7095 * The library is free for all purposes without any express 7467 * The library is free for all purposes without any express
7096 * guarantee it works. 7468 * guarantee it works.
7097 * 7469 *
7098 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7470 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7099 */ 7471 */
7100 7472
7101 /* high level subtraction (handles signs) */ 7473 /* high level subtraction (handles signs) */
7102 int 7474 int
7103 mp_sub (mp_int * a, mp_int * b, mp_int * c) 7475 mp_sub (mp_int * a, mp_int * b, mp_int * c)
7135 return res; 7507 return res;
7136 } 7508 }
7137 7509
7138 #endif 7510 #endif
7139 7511
7512 /* $Source: /cvs/libtom/libtommath/bn_mp_sub.c,v $ */
7513 /* $Revision: 1.3 $ */
7514 /* $Date: 2006/03/31 14:18:44 $ */
7515
7140 /* End: bn_mp_sub.c */ 7516 /* End: bn_mp_sub.c */
7141 7517
7142 /* Start: bn_mp_sub_d.c */ 7518 /* Start: bn_mp_sub_d.c */
7143 #include <tommath.h> 7519 #include <tommath.h>
7144 #ifdef BN_MP_SUB_D_C 7520 #ifdef BN_MP_SUB_D_C
7152 * additional optimizations in place. 7528 * additional optimizations in place.
7153 * 7529 *
7154 * The library is free for all purposes without any express 7530 * The library is free for all purposes without any express
7155 * guarantee it works. 7531 * guarantee it works.
7156 * 7532 *
7157 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7533 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7158 */ 7534 */
7159 7535
7160 /* single digit subtraction */ 7536 /* single digit subtraction */
7161 int 7537 int
7162 mp_sub_d (mp_int * a, mp_digit b, mp_int * c) 7538 mp_sub_d (mp_int * a, mp_digit b, mp_int * c)
7176 */ 7552 */
7177 if (a->sign == MP_NEG) { 7553 if (a->sign == MP_NEG) {
7178 a->sign = MP_ZPOS; 7554 a->sign = MP_ZPOS;
7179 res = mp_add_d(a, b, c); 7555 res = mp_add_d(a, b, c);
7180 a->sign = c->sign = MP_NEG; 7556 a->sign = c->sign = MP_NEG;
7557
7558 /* clamp */
7559 mp_clamp(c);
7560
7181 return res; 7561 return res;
7182 } 7562 }
7183 7563
7184 /* setup regs */ 7564 /* setup regs */
7185 oldused = c->used; 7565 oldused = c->used;
7224 return MP_OKAY; 7604 return MP_OKAY;
7225 } 7605 }
7226 7606
7227 #endif 7607 #endif
7228 7608
7609 /* $Source: /cvs/libtom/libtommath/bn_mp_sub_d.c,v $ */
7610 /* $Revision: 1.5 $ */
7611 /* $Date: 2006/03/31 14:18:44 $ */
7612
7229 /* End: bn_mp_sub_d.c */ 7613 /* End: bn_mp_sub_d.c */
7230 7614
7231 /* Start: bn_mp_submod.c */ 7615 /* Start: bn_mp_submod.c */
7232 #include <tommath.h> 7616 #include <tommath.h>
7233 #ifdef BN_MP_SUBMOD_C 7617 #ifdef BN_MP_SUBMOD_C
7241 * additional optimizations in place. 7625 * additional optimizations in place.
7242 * 7626 *
7243 * The library is free for all purposes without any express 7627 * The library is free for all purposes without any express
7244 * guarantee it works. 7628 * guarantee it works.
7245 * 7629 *
7246 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7630 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7247 */ 7631 */
7248 7632
7249 /* d = a - b (mod c) */ 7633 /* d = a - b (mod c) */
7250 int 7634 int
7251 mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 7635 mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
7266 mp_clear (&t); 7650 mp_clear (&t);
7267 return res; 7651 return res;
7268 } 7652 }
7269 #endif 7653 #endif
7270 7654
7655 /* $Source: /cvs/libtom/libtommath/bn_mp_submod.c,v $ */
7656 /* $Revision: 1.3 $ */
7657 /* $Date: 2006/03/31 14:18:44 $ */
7658
7271 /* End: bn_mp_submod.c */ 7659 /* End: bn_mp_submod.c */
7272 7660
7273 /* Start: bn_mp_to_signed_bin.c */ 7661 /* Start: bn_mp_to_signed_bin.c */
7274 #include <tommath.h> 7662 #include <tommath.h>
7275 #ifdef BN_MP_TO_SIGNED_BIN_C 7663 #ifdef BN_MP_TO_SIGNED_BIN_C
7283 * additional optimizations in place. 7671 * additional optimizations in place.
7284 * 7672 *
7285 * The library is free for all purposes without any express 7673 * The library is free for all purposes without any express
7286 * guarantee it works. 7674 * guarantee it works.
7287 * 7675 *
7288 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7676 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7289 */ 7677 */
7290 7678
7291 /* store in signed [big endian] format */ 7679 /* store in signed [big endian] format */
7292 int mp_to_signed_bin (mp_int * a, unsigned char *b) 7680 int mp_to_signed_bin (mp_int * a, unsigned char *b)
7293 { 7681 {
7299 b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1); 7687 b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1);
7300 return MP_OKAY; 7688 return MP_OKAY;
7301 } 7689 }
7302 #endif 7690 #endif
7303 7691
7692 /* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin.c,v $ */
7693 /* $Revision: 1.3 $ */
7694 /* $Date: 2006/03/31 14:18:44 $ */
7695
7304 /* End: bn_mp_to_signed_bin.c */ 7696 /* End: bn_mp_to_signed_bin.c */
7305 7697
7306 /* Start: bn_mp_to_signed_bin_n.c */ 7698 /* Start: bn_mp_to_signed_bin_n.c */
7307 #include <tommath.h> 7699 #include <tommath.h>
7308 #ifdef BN_MP_TO_SIGNED_BIN_N_C 7700 #ifdef BN_MP_TO_SIGNED_BIN_N_C
7316 * additional optimizations in place. 7708 * additional optimizations in place.
7317 * 7709 *
7318 * The library is free for all purposes without any express 7710 * The library is free for all purposes without any express
7319 * guarantee it works. 7711 * guarantee it works.
7320 * 7712 *
7321 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7713 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7322 */ 7714 */
7323 7715
7324 /* store in signed [big endian] format */ 7716 /* store in signed [big endian] format */
7325 int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) 7717 int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen)
7326 { 7718 {
7330 *outlen = mp_signed_bin_size(a); 7722 *outlen = mp_signed_bin_size(a);
7331 return mp_to_signed_bin(a, b); 7723 return mp_to_signed_bin(a, b);
7332 } 7724 }
7333 #endif 7725 #endif
7334 7726
7727 /* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin_n.c,v $ */
7728 /* $Revision: 1.3 $ */
7729 /* $Date: 2006/03/31 14:18:44 $ */
7730
7335 /* End: bn_mp_to_signed_bin_n.c */ 7731 /* End: bn_mp_to_signed_bin_n.c */
7336 7732
7337 /* Start: bn_mp_to_unsigned_bin.c */ 7733 /* Start: bn_mp_to_unsigned_bin.c */
7338 #include <tommath.h> 7734 #include <tommath.h>
7339 #ifdef BN_MP_TO_UNSIGNED_BIN_C 7735 #ifdef BN_MP_TO_UNSIGNED_BIN_C
7347 * additional optimizations in place. 7743 * additional optimizations in place.
7348 * 7744 *
7349 * The library is free for all purposes without any express 7745 * The library is free for all purposes without any express
7350 * guarantee it works. 7746 * guarantee it works.
7351 * 7747 *
7352 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7748 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7353 */ 7749 */
7354 7750
7355 /* store in unsigned [big endian] format */ 7751 /* store in unsigned [big endian] format */
7356 int mp_to_unsigned_bin (mp_int * a, unsigned char *b) 7752 int mp_to_unsigned_bin (mp_int * a, unsigned char *b)
7357 { 7753 {
7378 mp_clear (&t); 7774 mp_clear (&t);
7379 return MP_OKAY; 7775 return MP_OKAY;
7380 } 7776 }
7381 #endif 7777 #endif
7382 7778
7779 /* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin.c,v $ */
7780 /* $Revision: 1.3 $ */
7781 /* $Date: 2006/03/31 14:18:44 $ */
7782
7383 /* End: bn_mp_to_unsigned_bin.c */ 7783 /* End: bn_mp_to_unsigned_bin.c */
7384 7784
7385 /* Start: bn_mp_to_unsigned_bin_n.c */ 7785 /* Start: bn_mp_to_unsigned_bin_n.c */
7386 #include <tommath.h> 7786 #include <tommath.h>
7387 #ifdef BN_MP_TO_UNSIGNED_BIN_N_C 7787 #ifdef BN_MP_TO_UNSIGNED_BIN_N_C
7395 * additional optimizations in place. 7795 * additional optimizations in place.
7396 * 7796 *
7397 * The library is free for all purposes without any express 7797 * The library is free for all purposes without any express
7398 * guarantee it works. 7798 * guarantee it works.
7399 * 7799 *
7400 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7800 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7401 */ 7801 */
7402 7802
7403 /* store in unsigned [big endian] format */ 7803 /* store in unsigned [big endian] format */
7404 int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) 7804 int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen)
7405 { 7805 {
7409 *outlen = mp_unsigned_bin_size(a); 7809 *outlen = mp_unsigned_bin_size(a);
7410 return mp_to_unsigned_bin(a, b); 7810 return mp_to_unsigned_bin(a, b);
7411 } 7811 }
7412 #endif 7812 #endif
7413 7813
7814 /* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin_n.c,v $ */
7815 /* $Revision: 1.3 $ */
7816 /* $Date: 2006/03/31 14:18:44 $ */
7817
7414 /* End: bn_mp_to_unsigned_bin_n.c */ 7818 /* End: bn_mp_to_unsigned_bin_n.c */
7415 7819
7416 /* Start: bn_mp_toom_mul.c */ 7820 /* Start: bn_mp_toom_mul.c */
7417 #include <tommath.h> 7821 #include <tommath.h>
7418 #ifdef BN_MP_TOOM_MUL_C 7822 #ifdef BN_MP_TOOM_MUL_C
7426 * additional optimizations in place. 7830 * additional optimizations in place.
7427 * 7831 *
7428 * The library is free for all purposes without any express 7832 * The library is free for all purposes without any express
7429 * guarantee it works. 7833 * guarantee it works.
7430 * 7834 *
7431 * Tom St Denis, [email protected], http://math.libtomcrypt.org 7835 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7432 */ 7836 */
7433 7837
7434 /* multiplication using the Toom-Cook 3-way algorithm 7838 /* multiplication using the Toom-Cook 3-way algorithm
7435 * 7839 *
7436 * Much more complicated than Karatsuba but has a lower 7840 * Much more complicated than Karatsuba but has a lower
7693 return res; 8097 return res;
7694 } 8098 }
7695 8099
7696 #endif 8100 #endif
7697 8101
8102 /* $Source: /cvs/libtom/libtommath/bn_mp_toom_mul.c,v $ */
8103 /* $Revision: 1.3 $ */
8104 /* $Date: 2006/03/31 14:18:44 $ */
8105
7698 /* End: bn_mp_toom_mul.c */ 8106 /* End: bn_mp_toom_mul.c */
7699 8107
7700 /* Start: bn_mp_toom_sqr.c */ 8108 /* Start: bn_mp_toom_sqr.c */
7701 #include <tommath.h> 8109 #include <tommath.h>
7702 #ifdef BN_MP_TOOM_SQR_C 8110 #ifdef BN_MP_TOOM_SQR_C
7710 * additional optimizations in place. 8118 * additional optimizations in place.
7711 * 8119 *
7712 * The library is free for all purposes without any express 8120 * The library is free for all purposes without any express
7713 * guarantee it works. 8121 * guarantee it works.
7714 * 8122 *
7715 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8123 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7716 */ 8124 */
7717 8125
7718 /* squaring using Toom-Cook 3-way algorithm */ 8126 /* squaring using Toom-Cook 3-way algorithm */
7719 int 8127 int
7720 mp_toom_sqr(mp_int *a, mp_int *b) 8128 mp_toom_sqr(mp_int *a, mp_int *b)
7919 return res; 8327 return res;
7920 } 8328 }
7921 8329
7922 #endif 8330 #endif
7923 8331
8332 /* $Source: /cvs/libtom/libtommath/bn_mp_toom_sqr.c,v $ */
8333 /* $Revision: 1.3 $ */
8334 /* $Date: 2006/03/31 14:18:44 $ */
8335
7924 /* End: bn_mp_toom_sqr.c */ 8336 /* End: bn_mp_toom_sqr.c */
7925 8337
7926 /* Start: bn_mp_toradix.c */ 8338 /* Start: bn_mp_toradix.c */
7927 #include <tommath.h> 8339 #include <tommath.h>
7928 #ifdef BN_MP_TORADIX_C 8340 #ifdef BN_MP_TORADIX_C
7936 * additional optimizations in place. 8348 * additional optimizations in place.
7937 * 8349 *
7938 * The library is free for all purposes without any express 8350 * The library is free for all purposes without any express
7939 * guarantee it works. 8351 * guarantee it works.
7940 * 8352 *
7941 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8353 * Tom St Denis, [email protected], http://math.libtomcrypt.com
7942 */ 8354 */
7943 8355
7944 /* stores a bignum as a ASCII string in a given radix (2..64) */ 8356 /* stores a bignum as a ASCII string in a given radix (2..64) */
7945 int mp_toradix (mp_int * a, char *str, int radix) 8357 int mp_toradix (mp_int * a, char *str, int radix)
7946 { 8358 {
7994 return MP_OKAY; 8406 return MP_OKAY;
7995 } 8407 }
7996 8408
7997 #endif 8409 #endif
7998 8410
8411 /* $Source: /cvs/libtom/libtommath/bn_mp_toradix.c,v $ */
8412 /* $Revision: 1.3 $ */
8413 /* $Date: 2006/03/31 14:18:44 $ */
8414
7999 /* End: bn_mp_toradix.c */ 8415 /* End: bn_mp_toradix.c */
8000 8416
8001 /* Start: bn_mp_toradix_n.c */ 8417 /* Start: bn_mp_toradix_n.c */
8002 #include <tommath.h> 8418 #include <tommath.h>
8003 #ifdef BN_MP_TORADIX_N_C 8419 #ifdef BN_MP_TORADIX_N_C
8011 * additional optimizations in place. 8427 * additional optimizations in place.
8012 * 8428 *
8013 * The library is free for all purposes without any express 8429 * The library is free for all purposes without any express
8014 * guarantee it works. 8430 * guarantee it works.
8015 * 8431 *
8016 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8432 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8017 */ 8433 */
8018 8434
8019 /* stores a bignum as a ASCII string in a given radix (2..64) 8435 /* stores a bignum as a ASCII string in a given radix (2..64)
8020 * 8436 *
8021 * Stores upto maxlen-1 chars and always a NULL byte 8437 * Stores upto maxlen-1 chars and always a NULL byte
8026 mp_int t; 8442 mp_int t;
8027 mp_digit d; 8443 mp_digit d;
8028 char *_s = str; 8444 char *_s = str;
8029 8445
8030 /* check range of the maxlen, radix */ 8446 /* check range of the maxlen, radix */
8031 if (maxlen < 3 || radix < 2 || radix > 64) { 8447 if (maxlen < 2 || radix < 2 || radix > 64) {
8032 return MP_VAL; 8448 return MP_VAL;
8033 } 8449 }
8034 8450
8035 /* quick out if its zero */ 8451 /* quick out if its zero */
8036 if (mp_iszero(a) == 1) { 8452 if (mp_iszero(a) == MP_YES) {
8037 *str++ = '0'; 8453 *str++ = '0';
8038 *str = '\0'; 8454 *str = '\0';
8039 return MP_OKAY; 8455 return MP_OKAY;
8040 } 8456 }
8041 8457
8056 --maxlen; 8472 --maxlen;
8057 } 8473 }
8058 8474
8059 digs = 0; 8475 digs = 0;
8060 while (mp_iszero (&t) == 0) { 8476 while (mp_iszero (&t) == 0) {
8477 if (--maxlen < 1) {
8478 /* no more room */
8479 break;
8480 }
8061 if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) { 8481 if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
8062 mp_clear (&t); 8482 mp_clear (&t);
8063 return res; 8483 return res;
8064 } 8484 }
8065 *str++ = mp_s_rmap[d]; 8485 *str++ = mp_s_rmap[d];
8066 ++digs; 8486 ++digs;
8067
8068 if (--maxlen == 1) {
8069 /* no more room */
8070 break;
8071 }
8072 } 8487 }
8073 8488
8074 /* reverse the digits of the string. In this case _s points 8489 /* reverse the digits of the string. In this case _s points
8075 * to the first digit [exluding the sign] of the number] 8490 * to the first digit [exluding the sign] of the number
8076 */ 8491 */
8077 bn_reverse ((unsigned char *)_s, digs); 8492 bn_reverse ((unsigned char *)_s, digs);
8078 8493
8079 /* append a NULL so the string is properly terminated */ 8494 /* append a NULL so the string is properly terminated */
8080 *str = '\0'; 8495 *str = '\0';
8083 return MP_OKAY; 8498 return MP_OKAY;
8084 } 8499 }
8085 8500
8086 #endif 8501 #endif
8087 8502
8503 /* $Source: /cvs/libtom/libtommath/bn_mp_toradix_n.c,v $ */
8504 /* $Revision: 1.4 $ */
8505 /* $Date: 2006/03/31 14:18:44 $ */
8506
8088 /* End: bn_mp_toradix_n.c */ 8507 /* End: bn_mp_toradix_n.c */
8089 8508
8090 /* Start: bn_mp_unsigned_bin_size.c */ 8509 /* Start: bn_mp_unsigned_bin_size.c */
8091 #include <tommath.h> 8510 #include <tommath.h>
8092 #ifdef BN_MP_UNSIGNED_BIN_SIZE_C 8511 #ifdef BN_MP_UNSIGNED_BIN_SIZE_C
8100 * additional optimizations in place. 8519 * additional optimizations in place.
8101 * 8520 *
8102 * The library is free for all purposes without any express 8521 * The library is free for all purposes without any express
8103 * guarantee it works. 8522 * guarantee it works.
8104 * 8523 *
8105 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8524 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8106 */ 8525 */
8107 8526
8108 /* get the size for an unsigned equivalent */ 8527 /* get the size for an unsigned equivalent */
8109 int mp_unsigned_bin_size (mp_int * a) 8528 int mp_unsigned_bin_size (mp_int * a)
8110 { 8529 {
8111 int size = mp_count_bits (a); 8530 int size = mp_count_bits (a);
8112 return (size / 8 + ((size & 7) != 0 ? 1 : 0)); 8531 return (size / 8 + ((size & 7) != 0 ? 1 : 0));
8113 } 8532 }
8114 #endif 8533 #endif
8115 8534
8535 /* $Source: /cvs/libtom/libtommath/bn_mp_unsigned_bin_size.c,v $ */
8536 /* $Revision: 1.3 $ */
8537 /* $Date: 2006/03/31 14:18:44 $ */
8538
8116 /* End: bn_mp_unsigned_bin_size.c */ 8539 /* End: bn_mp_unsigned_bin_size.c */
8117 8540
8118 /* Start: bn_mp_xor.c */ 8541 /* Start: bn_mp_xor.c */
8119 #include <tommath.h> 8542 #include <tommath.h>
8120 #ifdef BN_MP_XOR_C 8543 #ifdef BN_MP_XOR_C
8128 * additional optimizations in place. 8551 * additional optimizations in place.
8129 * 8552 *
8130 * The library is free for all purposes without any express 8553 * The library is free for all purposes without any express
8131 * guarantee it works. 8554 * guarantee it works.
8132 * 8555 *
8133 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8556 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8134 */ 8557 */
8135 8558
8136 /* XOR two ints together */ 8559 /* XOR two ints together */
8137 int 8560 int
8138 mp_xor (mp_int * a, mp_int * b, mp_int * c) 8561 mp_xor (mp_int * a, mp_int * b, mp_int * c)
8162 mp_clear (&t); 8585 mp_clear (&t);
8163 return MP_OKAY; 8586 return MP_OKAY;
8164 } 8587 }
8165 #endif 8588 #endif
8166 8589
8590 /* $Source: /cvs/libtom/libtommath/bn_mp_xor.c,v $ */
8591 /* $Revision: 1.3 $ */
8592 /* $Date: 2006/03/31 14:18:44 $ */
8593
8167 /* End: bn_mp_xor.c */ 8594 /* End: bn_mp_xor.c */
8168 8595
8169 /* Start: bn_mp_zero.c */ 8596 /* Start: bn_mp_zero.c */
8170 #include <tommath.h> 8597 #include <tommath.h>
8171 #ifdef BN_MP_ZERO_C 8598 #ifdef BN_MP_ZERO_C
8179 * additional optimizations in place. 8606 * additional optimizations in place.
8180 * 8607 *
8181 * The library is free for all purposes without any express 8608 * The library is free for all purposes without any express
8182 * guarantee it works. 8609 * guarantee it works.
8183 * 8610 *
8184 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8611 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8185 */ 8612 */
8186 8613
8187 /* set to zero */ 8614 /* set to zero */
8188 void mp_zero (mp_int * a) 8615 void mp_zero (mp_int * a)
8189 { 8616 {
8198 *tmp++ = 0; 8625 *tmp++ = 0;
8199 } 8626 }
8200 } 8627 }
8201 #endif 8628 #endif
8202 8629
8630 /* $Source: /cvs/libtom/libtommath/bn_mp_zero.c,v $ */
8631 /* $Revision: 1.3 $ */
8632 /* $Date: 2006/03/31 14:18:44 $ */
8633
8203 /* End: bn_mp_zero.c */ 8634 /* End: bn_mp_zero.c */
8204 8635
8205 /* Start: bn_prime_tab.c */ 8636 /* Start: bn_prime_tab.c */
8206 #include <tommath.h> 8637 #include <tommath.h>
8207 #ifdef BN_PRIME_TAB_C 8638 #ifdef BN_PRIME_TAB_C
8215 * additional optimizations in place. 8646 * additional optimizations in place.
8216 * 8647 *
8217 * The library is free for all purposes without any express 8648 * The library is free for all purposes without any express
8218 * guarantee it works. 8649 * guarantee it works.
8219 * 8650 *
8220 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8651 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8221 */ 8652 */
8222 const mp_digit ltm_prime_tab[] = { 8653 const mp_digit ltm_prime_tab[] = {
8223 0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013, 8654 0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
8224 0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035, 8655 0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
8225 0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059, 8656 0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
8259 0x062B, 0x062F, 0x063D, 0x0641, 0x0647, 0x0649, 0x064D, 0x0653 8690 0x062B, 0x062F, 0x063D, 0x0641, 0x0647, 0x0649, 0x064D, 0x0653
8260 #endif 8691 #endif
8261 }; 8692 };
8262 #endif 8693 #endif
8263 8694
8695 /* $Source: /cvs/libtom/libtommath/bn_prime_tab.c,v $ */
8696 /* $Revision: 1.3 $ */
8697 /* $Date: 2006/03/31 14:18:44 $ */
8698
8264 /* End: bn_prime_tab.c */ 8699 /* End: bn_prime_tab.c */
8265 8700
8266 /* Start: bn_reverse.c */ 8701 /* Start: bn_reverse.c */
8267 #include <tommath.h> 8702 #include <tommath.h>
8268 #ifdef BN_REVERSE_C 8703 #ifdef BN_REVERSE_C
8276 * additional optimizations in place. 8711 * additional optimizations in place.
8277 * 8712 *
8278 * The library is free for all purposes without any express 8713 * The library is free for all purposes without any express
8279 * guarantee it works. 8714 * guarantee it works.
8280 * 8715 *
8281 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8716 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8282 */ 8717 */
8283 8718
8284 /* reverse an array, used for radix code */ 8719 /* reverse an array, used for radix code */
8285 void 8720 void
8286 bn_reverse (unsigned char *s, int len) 8721 bn_reverse (unsigned char *s, int len)
8298 --iy; 8733 --iy;
8299 } 8734 }
8300 } 8735 }
8301 #endif 8736 #endif
8302 8737
8738 /* $Source: /cvs/libtom/libtommath/bn_reverse.c,v $ */
8739 /* $Revision: 1.3 $ */
8740 /* $Date: 2006/03/31 14:18:44 $ */
8741
8303 /* End: bn_reverse.c */ 8742 /* End: bn_reverse.c */
8304 8743
8305 /* Start: bn_s_mp_add.c */ 8744 /* Start: bn_s_mp_add.c */
8306 #include <tommath.h> 8745 #include <tommath.h>
8307 #ifdef BN_S_MP_ADD_C 8746 #ifdef BN_S_MP_ADD_C
8315 * additional optimizations in place. 8754 * additional optimizations in place.
8316 * 8755 *
8317 * The library is free for all purposes without any express 8756 * The library is free for all purposes without any express
8318 * guarantee it works. 8757 * guarantee it works.
8319 * 8758 *
8320 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8759 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8321 */ 8760 */
8322 8761
8323 /* low level addition, based on HAC pp.594, Algorithm 14.7 */ 8762 /* low level addition, based on HAC pp.594, Algorithm 14.7 */
8324 int 8763 int
8325 s_mp_add (mp_int * a, mp_int * b, mp_int * c) 8764 s_mp_add (mp_int * a, mp_int * b, mp_int * c)
8407 mp_clamp (c); 8846 mp_clamp (c);
8408 return MP_OKAY; 8847 return MP_OKAY;
8409 } 8848 }
8410 #endif 8849 #endif
8411 8850
8851 /* $Source: /cvs/libtom/libtommath/bn_s_mp_add.c,v $ */
8852 /* $Revision: 1.3 $ */
8853 /* $Date: 2006/03/31 14:18:44 $ */
8854
8412 /* End: bn_s_mp_add.c */ 8855 /* End: bn_s_mp_add.c */
8413 8856
8414 /* Start: bn_s_mp_exptmod.c */ 8857 /* Start: bn_s_mp_exptmod.c */
8415 #include <tommath.h> 8858 #include <tommath.h>
8416 #ifdef BN_S_MP_EXPTMOD_C 8859 #ifdef BN_S_MP_EXPTMOD_C
8424 * additional optimizations in place. 8867 * additional optimizations in place.
8425 * 8868 *
8426 * The library is free for all purposes without any express 8869 * The library is free for all purposes without any express
8427 * guarantee it works. 8870 * guarantee it works.
8428 * 8871 *
8429 * Tom St Denis, [email protected], http://math.libtomcrypt.org 8872 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8430 */ 8873 */
8431
8432 #ifdef MP_LOW_MEM 8874 #ifdef MP_LOW_MEM
8433 #define TAB_SIZE 32 8875 #define TAB_SIZE 32
8434 #else 8876 #else
8435 #define TAB_SIZE 256 8877 #define TAB_SIZE 256
8436 #endif 8878 #endif
8660 } 9102 }
8661 return err; 9103 return err;
8662 } 9104 }
8663 #endif 9105 #endif
8664 9106
9107 /* $Source: /cvs/libtom/libtommath/bn_s_mp_exptmod.c,v $ */
9108 /* $Revision: 1.4 $ */
9109 /* $Date: 2006/03/31 14:18:44 $ */
9110
8665 /* End: bn_s_mp_exptmod.c */ 9111 /* End: bn_s_mp_exptmod.c */
8666 9112
8667 /* Start: bn_s_mp_mul_digs.c */ 9113 /* Start: bn_s_mp_mul_digs.c */
8668 #include <tommath.h> 9114 #include <tommath.h>
8669 #ifdef BN_S_MP_MUL_DIGS_C 9115 #ifdef BN_S_MP_MUL_DIGS_C
8677 * additional optimizations in place. 9123 * additional optimizations in place.
8678 * 9124 *
8679 * The library is free for all purposes without any express 9125 * The library is free for all purposes without any express
8680 * guarantee it works. 9126 * guarantee it works.
8681 * 9127 *
8682 * Tom St Denis, [email protected], http://math.libtomcrypt.org 9128 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8683 */ 9129 */
8684 9130
8685 /* multiplies |a| * |b| and only computes upto digs digits of result 9131 /* multiplies |a| * |b| and only computes upto digs digits of result
8686 * HAC pp. 595, Algorithm 14.12 Modified so you can control how 9132 * HAC pp. 595, Algorithm 14.12 Modified so you can control how
8687 * many digits of output are created. 9133 * many digits of output are created.
8750 mp_clear (&t); 9196 mp_clear (&t);
8751 return MP_OKAY; 9197 return MP_OKAY;
8752 } 9198 }
8753 #endif 9199 #endif
8754 9200
9201 /* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_digs.c,v $ */
9202 /* $Revision: 1.3 $ */
9203 /* $Date: 2006/03/31 14:18:44 $ */
9204
8755 /* End: bn_s_mp_mul_digs.c */ 9205 /* End: bn_s_mp_mul_digs.c */
8756 9206
8757 /* Start: bn_s_mp_mul_high_digs.c */ 9207 /* Start: bn_s_mp_mul_high_digs.c */
8758 #include <tommath.h> 9208 #include <tommath.h>
8759 #ifdef BN_S_MP_MUL_HIGH_DIGS_C 9209 #ifdef BN_S_MP_MUL_HIGH_DIGS_C
8767 * additional optimizations in place. 9217 * additional optimizations in place.
8768 * 9218 *
8769 * The library is free for all purposes without any express 9219 * The library is free for all purposes without any express
8770 * guarantee it works. 9220 * guarantee it works.
8771 * 9221 *
8772 * Tom St Denis, [email protected], http://math.libtomcrypt.org 9222 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8773 */ 9223 */
8774 9224
8775 /* multiplies |a| * |b| and does not compute the lower digs digits 9225 /* multiplies |a| * |b| and does not compute the lower digs digits
8776 * [meant to get the higher part of the product] 9226 * [meant to get the higher part of the product]
8777 */ 9227 */
8831 mp_clear (&t); 9281 mp_clear (&t);
8832 return MP_OKAY; 9282 return MP_OKAY;
8833 } 9283 }
8834 #endif 9284 #endif
8835 9285
9286 /* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_high_digs.c,v $ */
9287 /* $Revision: 1.3 $ */
9288 /* $Date: 2006/03/31 14:18:44 $ */
9289
8836 /* End: bn_s_mp_mul_high_digs.c */ 9290 /* End: bn_s_mp_mul_high_digs.c */
8837 9291
8838 /* Start: bn_s_mp_sqr.c */ 9292 /* Start: bn_s_mp_sqr.c */
8839 #include <tommath.h> 9293 #include <tommath.h>
8840 #ifdef BN_S_MP_SQR_C 9294 #ifdef BN_S_MP_SQR_C
8848 * additional optimizations in place. 9302 * additional optimizations in place.
8849 * 9303 *
8850 * The library is free for all purposes without any express 9304 * The library is free for all purposes without any express
8851 * guarantee it works. 9305 * guarantee it works.
8852 * 9306 *
8853 * Tom St Denis, [email protected], http://math.libtomcrypt.org 9307 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8854 */ 9308 */
8855 9309
8856 /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */ 9310 /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
8857 int s_mp_sqr (mp_int * a, mp_int * b) 9311 int s_mp_sqr (mp_int * a, mp_int * b)
8858 { 9312 {
8915 mp_clear (&t); 9369 mp_clear (&t);
8916 return MP_OKAY; 9370 return MP_OKAY;
8917 } 9371 }
8918 #endif 9372 #endif
8919 9373
9374 /* $Source: /cvs/libtom/libtommath/bn_s_mp_sqr.c,v $ */
9375 /* $Revision: 1.3 $ */
9376 /* $Date: 2006/03/31 14:18:44 $ */
9377
8920 /* End: bn_s_mp_sqr.c */ 9378 /* End: bn_s_mp_sqr.c */
8921 9379
8922 /* Start: bn_s_mp_sub.c */ 9380 /* Start: bn_s_mp_sub.c */
8923 #include <tommath.h> 9381 #include <tommath.h>
8924 #ifdef BN_S_MP_SUB_C 9382 #ifdef BN_S_MP_SUB_C
8932 * additional optimizations in place. 9390 * additional optimizations in place.
8933 * 9391 *
8934 * The library is free for all purposes without any express 9392 * The library is free for all purposes without any express
8935 * guarantee it works. 9393 * guarantee it works.
8936 * 9394 *
8937 * Tom St Denis, [email protected], http://math.libtomcrypt.org 9395 * Tom St Denis, [email protected], http://math.libtomcrypt.com
8938 */ 9396 */
8939 9397
8940 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */ 9398 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
8941 int 9399 int
8942 s_mp_sub (mp_int * a, mp_int * b, mp_int * c) 9400 s_mp_sub (mp_int * a, mp_int * b, mp_int * c)
9004 return MP_OKAY; 9462 return MP_OKAY;
9005 } 9463 }
9006 9464
9007 #endif 9465 #endif
9008 9466
9467 /* $Source: /cvs/libtom/libtommath/bn_s_mp_sub.c,v $ */
9468 /* $Revision: 1.3 $ */
9469 /* $Date: 2006/03/31 14:18:44 $ */
9470
9009 /* End: bn_s_mp_sub.c */ 9471 /* End: bn_s_mp_sub.c */
9010 9472
9011 /* Start: bncore.c */ 9473 /* Start: bncore.c */
9012 #include <tommath.h> 9474 #include <tommath.h>
9013 #ifdef BNCORE_C 9475 #ifdef BNCORE_C
9021 * additional optimizations in place. 9483 * additional optimizations in place.
9022 * 9484 *
9023 * The library is free for all purposes without any express 9485 * The library is free for all purposes without any express
9024 * guarantee it works. 9486 * guarantee it works.
9025 * 9487 *
9026 * Tom St Denis, [email protected], http://math.libtomcrypt.org 9488 * Tom St Denis, [email protected], http://math.libtomcrypt.com
9027 */ 9489 */
9028 9490
9029 /* Known optimal configurations 9491 /* Known optimal configurations
9030 9492
9031 CPU /Compiler /MUL CUTOFF/SQR CUTOFF 9493 CPU /Compiler /MUL CUTOFF/SQR CUTOFF
9032 ------------------------------------------------------------- 9494 -------------------------------------------------------------
9033 Intel P4 Northwood /GCC v3.4.1 / 88/ 128/LTM 0.32 ;-) 9495 Intel P4 Northwood /GCC v3.4.1 / 88/ 128/LTM 0.32 ;-)
9034 AMD Athlon64 /GCC v3.4.4 / 74/ 124/LTM 0.34 9496 AMD Athlon64 /GCC v3.4.4 / 80/ 120/LTM 0.35
9035 9497
9036 */ 9498 */
9037 9499
9038 int KARATSUBA_MUL_CUTOFF = 74, /* Min. number of digits before Karatsuba multiplication is used. */ 9500 int KARATSUBA_MUL_CUTOFF = 80, /* Min. number of digits before Karatsuba multiplication is used. */
9039 KARATSUBA_SQR_CUTOFF = 124, /* Min. number of digits before Karatsuba squaring is used. */ 9501 KARATSUBA_SQR_CUTOFF = 120, /* Min. number of digits before Karatsuba squaring is used. */
9040 9502
9041 TOOM_MUL_CUTOFF = 350, /* no optimal values of these are known yet so set em high */ 9503 TOOM_MUL_CUTOFF = 350, /* no optimal values of these are known yet so set em high */
9042 TOOM_SQR_CUTOFF = 400; 9504 TOOM_SQR_CUTOFF = 400;
9043 #endif 9505 #endif
9044 9506
9507 /* $Source: /cvs/libtom/libtommath/bncore.c,v $ */
9508 /* $Revision: 1.4 $ */
9509 /* $Date: 2006/03/31 14:18:44 $ */
9510
9045 /* End: bncore.c */ 9511 /* End: bncore.c */
9046 9512
9047 9513
9048 /* EOF */ 9514 /* EOF */