added libtommath-0.33
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..deffba1
--- /dev/null
+++ b/TODO
@@ -0,0 +1,16 @@
+things for book in order of importance...
+
+- Fix up pseudo-code [only] for combas that are not consistent with source
+- Start in chapter 3 [basics] and work up...
+ - re-write to prose [less abrupt]
+ - clean up pseudo code [spacing]
+ - more examples where appropriate and figures
+
+Goal:
+ - Get sync done by mid January [roughly 8-12 hours work]
+ - Finish ch3-6 by end of January [roughly 12-16 hours of work]
+ - Finish ch7-end by mid Feb [roughly 20-24 hours of work].
+
+Goal isn't "first edition" but merely cleaner to read.
+
+
diff --git a/bn.pdf b/bn.pdf
index fbd5b2a..9b873e1 100644
Binary files a/bn.pdf and b/bn.pdf differ
diff --git a/bn.tex b/bn.tex
index 74a4f01..962d6ea 100644
--- a/bn.tex
+++ b/bn.tex
@@ -49,7 +49,7 @@
\begin{document}
\frontmatter
\pagestyle{empty}
-\title{LibTomMath User Manual \\ v0.32}
+\title{LibTomMath User Manual \\ v0.33}
\author{Tom St Denis \\ tomstdenis@iahu.ca}
\maketitle
This text, the library and the accompanying textbook are all hereby placed in the public domain. This book has been
diff --git a/bn_fast_mp_invmod.c b/bn_fast_mp_invmod.c
index 492a3f1..b5b9f10 100644
--- a/bn_fast_mp_invmod.c
+++ b/bn_fast_mp_invmod.c
@@ -39,20 +39,20 @@ fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
/* x == modulus, y == value to invert */
if ((res = mp_copy (b, &x)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* we need y = |a| */
if ((res = mp_abs (a, &y)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
if ((res = mp_copy (&x, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_copy (&y, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
mp_set (&D, 1);
@@ -61,17 +61,17 @@ top:
while (mp_iseven (&u) == 1) {
/* 4.1 u = u/2 */
if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 4.2 if B is odd then */
if (mp_isodd (&B) == 1) {
if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* B = B/2 */
if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -79,18 +79,18 @@ top:
while (mp_iseven (&v) == 1) {
/* 5.1 v = v/2 */
if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 5.2 if D is odd then */
if (mp_isodd (&D) == 1) {
/* D = (D-x)/2 */
if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* D = D/2 */
if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -98,20 +98,20 @@ top:
if (mp_cmp (&u, &v) != MP_LT) {
/* u = u - v, B = B - D */
if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
} else {
/* v - v - u, D = D - B */
if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -125,21 +125,21 @@ top:
/* if v != 1 then there is no inverse */
if (mp_cmp_d (&v, 1) != MP_EQ) {
res = MP_VAL;
- goto __ERR;
+ goto LBL_ERR;
}
/* b is now the inverse */
neg = a->sign;
while (D.sign == MP_NEG) {
if ((res = mp_add (&D, b, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
mp_exch (&D, c);
c->sign = neg;
res = MP_OKAY;
-__ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
return res;
}
#endif
diff --git a/bn_fast_s_mp_mul_digs.c b/bn_fast_s_mp_mul_digs.c
index 92b50bb..e1ff5f3 100644
--- a/bn_fast_s_mp_mul_digs.c
+++ b/bn_fast_s_mp_mul_digs.c
@@ -50,7 +50,7 @@ fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* clear the carry */
_W = 0;
- for (ix = 0; ix <= pa; ix++) {
+ for (ix = 0; ix < pa; ix++) {
int tx, ty;
int iy;
mp_digit *tmpx, *tmpy;
@@ -80,6 +80,9 @@ fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
_W = _W >> ((mp_word)DIGIT_BIT);
}
+ /* store final carry */
+ W[ix] = _W;
+
/* setup dest */
olduse = c->used;
c->used = digs;
diff --git a/bn_fast_s_mp_mul_high_digs.c b/bn_fast_s_mp_mul_high_digs.c
index 9e0cf55..064a9dd 100644
--- a/bn_fast_s_mp_mul_high_digs.c
+++ b/bn_fast_s_mp_mul_high_digs.c
@@ -42,7 +42,7 @@ fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* number of output digits to produce */
pa = a->used + b->used;
_W = 0;
- for (ix = digs; ix <= pa; ix++) {
+ for (ix = digs; ix < pa; ix++) {
int tx, ty, iy;
mp_digit *tmpx, *tmpy;
@@ -70,6 +70,9 @@ fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* make next carry */
_W = _W >> ((mp_word)DIGIT_BIT);
}
+
+ /* store final carry */
+ W[ix] = _W;
/* setup dest */
olduse = c->used;
diff --git a/bn_fast_s_mp_sqr.c b/bn_fast_s_mp_sqr.c
index 9f6962d..d6014ab 100644
--- a/bn_fast_s_mp_sqr.c
+++ b/bn_fast_s_mp_sqr.c
@@ -60,7 +60,7 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
/* number of output digits to produce */
W1 = 0;
- for (ix = 0; ix <= pa; ix++) {
+ for (ix = 0; ix < pa; ix++) {
int tx, ty, iy;
mp_word _W;
mp_digit *tmpy;
diff --git a/bn_mp_div.c b/bn_mp_div.c
index 39d921a..6b2b8f0 100644
--- a/bn_mp_div.c
+++ b/bn_mp_div.c
@@ -49,23 +49,23 @@ int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
mp_set(&tq, 1);
n = mp_count_bits(a) - mp_count_bits(b);
- if (((res = mp_copy(a, &ta)) != MP_OKAY) ||
- ((res = mp_copy(b, &tb)) != MP_OKAY) ||
+ if (((res = mp_abs(a, &ta)) != MP_OKAY) ||
+ ((res = mp_abs(b, &tb)) != MP_OKAY) ||
((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) ||
((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) {
- goto __ERR;
+ goto LBL_ERR;
}
while (n-- >= 0) {
if (mp_cmp(&tb, &ta) != MP_GT) {
if (((res = mp_sub(&ta, &tb, &ta)) != MP_OKAY) ||
((res = mp_add(&q, &tq, &q)) != MP_OKAY)) {
- goto __ERR;
+ goto LBL_ERR;
}
}
if (((res = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) ||
((res = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -74,13 +74,13 @@ int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG);
if (c != NULL) {
mp_exch(c, &q);
- c->sign = n2;
+ c->sign = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2;
}
if (d != NULL) {
mp_exch(d, &ta);
- d->sign = n;
+ d->sign = (mp_iszero(d) == MP_YES) ? MP_ZPOS : n;
}
-__ERR:
+LBL_ERR:
mp_clear_multi(&ta, &tb, &tq, &q, NULL);
return res;
}
@@ -129,19 +129,19 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
q.used = a->used + 2;
if ((res = mp_init (&t1)) != MP_OKAY) {
- goto __Q;
+ goto LBL_Q;
}
if ((res = mp_init (&t2)) != MP_OKAY) {
- goto __T1;
+ goto LBL_T1;
}
if ((res = mp_init_copy (&x, a)) != MP_OKAY) {
- goto __T2;
+ goto LBL_T2;
}
if ((res = mp_init_copy (&y, b)) != MP_OKAY) {
- goto __X;
+ goto LBL_X;
}
/* fix the sign */
@@ -153,10 +153,10 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
if (norm < (int)(DIGIT_BIT-1)) {
norm = (DIGIT_BIT-1) - norm;
if ((res = mp_mul_2d (&x, norm, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_mul_2d (&y, norm, &y)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
} else {
norm = 0;
@@ -168,13 +168,13 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
/* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
if ((res = mp_lshd (&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */
- goto __Y;
+ goto LBL_Y;
}
while (mp_cmp (&x, &y) != MP_LT) {
++(q.dp[n - t]);
if ((res = mp_sub (&x, &y, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
}
@@ -216,7 +216,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
t1.dp[1] = y.dp[t];
t1.used = 2;
if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* find right hand */
@@ -228,27 +228,27 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
/* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_sub (&x, &t1, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */
if (x.sign == MP_NEG) {
if ((res = mp_copy (&y, &t1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
@@ -275,11 +275,11 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
res = MP_OKAY;
-__Y:mp_clear (&y);
-__X:mp_clear (&x);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
-__Q:mp_clear (&q);
+LBL_Y:mp_clear (&y);
+LBL_X:mp_clear (&x);
+LBL_T2:mp_clear (&t2);
+LBL_T1:mp_clear (&t1);
+LBL_Q:mp_clear (&q);
return res;
}
diff --git a/bn_mp_dr_reduce.c b/bn_mp_dr_reduce.c
index 308b80a..9bb7ad7 100644
--- a/bn_mp_dr_reduce.c
+++ b/bn_mp_dr_reduce.c
@@ -20,7 +20,7 @@
* Based on algorithm from the paper
*
* "Generating Efficient Primes for Discrete Log Cryptosystems"
- * Chae Hoon Lim, Pil Loong Lee,
+ * Chae Hoon Lim, Pil Joong Lee,
* POSTECH Information Research Laboratories
*
* The modulus must be of a special format [see manual]
diff --git a/bn_mp_exptmod.c b/bn_mp_exptmod.c
index da88fec..7309170 100644
--- a/bn_mp_exptmod.c
+++ b/bn_mp_exptmod.c
@@ -61,7 +61,7 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
return err;
#else
/* no invmod */
- return MP_VAL
+ return MP_VAL;
#endif
}
diff --git a/bn_mp_exptmod_fast.c b/bn_mp_exptmod_fast.c
index 4351e60..255e9d9 100644
--- a/bn_mp_exptmod_fast.c
+++ b/bn_mp_exptmod_fast.c
@@ -88,11 +88,11 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
#ifdef BN_MP_MONTGOMERY_SETUP_C
/* now setup montgomery */
if ((err = mp_montgomery_setup (P, &mp)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
/* automatically pick the comba one if available (saves quite a few calls/ifs) */
@@ -108,7 +108,7 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
redux = mp_montgomery_reduce;
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
}
} else if (redmode == 1) {
@@ -118,24 +118,24 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
redux = mp_dr_reduce;
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
} else {
#if defined(BN_MP_REDUCE_2K_SETUP_C) && defined(BN_MP_REDUCE_2K_C)
/* setup DR reduction for moduli of the form 2**k - b */
if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
redux = mp_reduce_2k;
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
}
/* setup result */
if ((err = mp_init (&res)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
/* create M table
@@ -149,45 +149,45 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
#ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
/* now we need R mod m */
if ((err = mp_montgomery_calc_normalization (&res, P)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
#else
err = MP_VAL;
- goto __RES;
+ goto LBL_RES;
#endif
/* now set M[1] to G * R mod m */
if ((err = mp_mulmod (G, &res, P, &M[1])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
} else {
mp_set(&res, 1);
if ((err = mp_mod(G, P, &M[1])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times */
if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
for (x = 0; x < (winsize - 1); x++) {
if ((err = mp_sqr (&M[1 << (winsize - 1)], &M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&M[1 << (winsize - 1)], P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* create upper table */
for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&M[x], P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
@@ -227,10 +227,10 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
/* if the bit is zero and mode == 1 then we square */
if (mode == 1 && y == 0) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
continue;
}
@@ -244,19 +244,19 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
/* square first */
for (x = 0; x < winsize; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* then multiply */
if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
/* empty window and reset */
@@ -271,10 +271,10 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
/* square then multiply if the bit is set */
for (x = 0; x < bitcpy; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
/* get next bit of the window */
@@ -282,10 +282,10 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
if ((bitbuf & (1 << winsize)) != 0) {
/* then multiply */
if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
}
@@ -299,15 +299,15 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
* of R.
*/
if ((err = redux(&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* swap res with Y */
mp_exch (&res, Y);
err = MP_OKAY;
-__RES:mp_clear (&res);
-__M:
+LBL_RES:mp_clear (&res);
+LBL_M:
mp_clear(&M[1]);
for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
mp_clear (&M[x]);
diff --git a/bn_mp_gcd.c b/bn_mp_gcd.c
index 1cd21fc..6265df1 100644
--- a/bn_mp_gcd.c
+++ b/bn_mp_gcd.c
@@ -43,7 +43,7 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
}
if ((res = mp_init_copy (&v, b)) != MP_OKAY) {
- goto __U;
+ goto LBL_U;
}
/* must be positive for the remainder of the algorithm */
@@ -57,24 +57,24 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
if (k > 0) {
/* divide the power of two out */
if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
/* divide any remaining factors of two out */
if (u_lsb != k) {
if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
if (v_lsb != k) {
if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
@@ -87,23 +87,23 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
/* subtract smallest from largest */
if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
/* Divide out all factors of two */
if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
/* multiply by 2**k which we divided out at the beginning */
if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
c->sign = MP_ZPOS;
res = MP_OKAY;
-__V:mp_clear (&u);
-__U:mp_clear (&v);
+LBL_V:mp_clear (&u);
+LBL_U:mp_clear (&v);
return res;
}
#endif
diff --git a/bn_mp_invmod_slow.c b/bn_mp_invmod_slow.c
index 8ecb009..c1884c0 100644
--- a/bn_mp_invmod_slow.c
+++ b/bn_mp_invmod_slow.c
@@ -34,24 +34,24 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
/* x = a, y = b */
if ((res = mp_copy (a, &x)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_copy (b, &y)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 2. [modified] if x,y are both even then return an error! */
if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
res = MP_VAL;
- goto __ERR;
+ goto LBL_ERR;
}
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
if ((res = mp_copy (&x, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_copy (&y, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
mp_set (&A, 1);
mp_set (&D, 1);
@@ -61,24 +61,24 @@ top:
while (mp_iseven (&u) == 1) {
/* 4.1 u = u/2 */
if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 4.2 if A or B is odd then */
if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
/* A = (A+y)/2, B = (B-x)/2 */
if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* A = A/2, B = B/2 */
if ((res = mp_div_2 (&A, &A)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -86,24 +86,24 @@ top:
while (mp_iseven (&v) == 1) {
/* 5.1 v = v/2 */
if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 5.2 if C or D is odd then */
if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
/* C = (C+y)/2, D = (D-x)/2 */
if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* C = C/2, D = D/2 */
if ((res = mp_div_2 (&C, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -111,28 +111,28 @@ top:
if (mp_cmp (&u, &v) != MP_LT) {
/* u = u - v, A = A - C, B = B - D */
if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&A, &C, &A)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
} else {
/* v - v - u, C = C - A, D = D - B */
if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&C, &A, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -145,27 +145,27 @@ top:
/* if v != 1 then there is no inverse */
if (mp_cmp_d (&v, 1) != MP_EQ) {
res = MP_VAL;
- goto __ERR;
+ goto LBL_ERR;
}
/* if its too low */
while (mp_cmp_d(&C, 0) == MP_LT) {
if ((res = mp_add(&C, b, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* too big */
while (mp_cmp_mag(&C, b) != MP_LT) {
if ((res = mp_sub(&C, b, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* C is now the inverse */
mp_exch (&C, c);
res = MP_OKAY;
-__ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
return res;
}
#endif
diff --git a/bn_mp_jacobi.c b/bn_mp_jacobi.c
index 1c69cfd..74cbbf3 100644
--- a/bn_mp_jacobi.c
+++ b/bn_mp_jacobi.c
@@ -50,13 +50,13 @@ int mp_jacobi (mp_int * a, mp_int * p, int *c)
}
if ((res = mp_init (&p1)) != MP_OKAY) {
- goto __A1;
+ goto LBL_A1;
}
/* divide out larger power of two */
k = mp_cnt_lsb(&a1);
if ((res = mp_div_2d(&a1, k, &a1, NULL)) != MP_OKAY) {
- goto __P1;
+ goto LBL_P1;
}
/* step 4. if e is even set s=1 */
@@ -84,18 +84,18 @@ int mp_jacobi (mp_int * a, mp_int * p, int *c)
} else {
/* n1 = n mod a1 */
if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) {
- goto __P1;
+ goto LBL_P1;
}
if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) {
- goto __P1;
+ goto LBL_P1;
}
*c = s * r;
}
/* done */
res = MP_OKAY;
-__P1:mp_clear (&p1);
-__A1:mp_clear (&a1);
+LBL_P1:mp_clear (&p1);
+LBL_A1:mp_clear (&a1);
return res;
}
#endif
diff --git a/bn_mp_lcm.c b/bn_mp_lcm.c
index 340d757..8e3a759 100644
--- a/bn_mp_lcm.c
+++ b/bn_mp_lcm.c
@@ -28,20 +28,20 @@ int mp_lcm (mp_int * a, mp_int * b, mp_int * c)
/* t1 = get the GCD of the two inputs */
if ((res = mp_gcd (a, b, &t1)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
/* divide the smallest by the GCD */
if (mp_cmp_mag(a, b) == MP_LT) {
/* store quotient in t2 such that t2 * b is the LCM */
if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
res = mp_mul(b, &t2, c);
} else {
/* store quotient in t2 such that t2 * a is the LCM */
if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
res = mp_mul(a, &t2, c);
}
@@ -49,7 +49,7 @@ int mp_lcm (mp_int * a, mp_int * b, mp_int * c)
/* fix the sign to positive */
c->sign = MP_ZPOS;
-__T:
+LBL_T:
mp_clear_multi (&t1, &t2, NULL);
return res;
}
diff --git a/bn_mp_mod_2d.c b/bn_mp_mod_2d.c
index f81a0d4..589e4ba 100644
--- a/bn_mp_mod_2d.c
+++ b/bn_mp_mod_2d.c
@@ -28,7 +28,7 @@ mp_mod_2d (mp_int * a, int b, mp_int * c)
}
/* if the modulus is larger than the value than return */
- if (b > (int) (a->used * DIGIT_BIT)) {
+ if (b >= (int) (a->used * DIGIT_BIT)) {
res = mp_copy (a, c);
return res;
}
diff --git a/bn_mp_n_root.c b/bn_mp_n_root.c
index 9489903..7b11aa2 100644
--- a/bn_mp_n_root.c
+++ b/bn_mp_n_root.c
@@ -40,11 +40,11 @@ int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
}
if ((res = mp_init (&t2)) != MP_OKAY) {
- goto __T1;
+ goto LBL_T1;
}
if ((res = mp_init (&t3)) != MP_OKAY) {
- goto __T2;
+ goto LBL_T2;
}
/* if a is negative fudge the sign but keep track */
@@ -57,52 +57,52 @@ int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
do {
/* t1 = t2 */
if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
/* t3 = t1**(b-1) */
if ((res = mp_expt_d (&t1, b - 1, &t3)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* numerator */
/* t2 = t1**b */
if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* t2 = t1**b - a */
if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* denominator */
/* t3 = t1**(b-1) * b */
if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* t3 = (t1**b - a)/(b * t1**(b-1)) */
if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
} while (mp_cmp (&t1, &t2) != MP_EQ);
/* result can be off by a few so check */
for (;;) {
if ((res = mp_expt_d (&t1, b, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
if (mp_cmp (&t2, a) == MP_GT) {
if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
} else {
break;
@@ -120,9 +120,9 @@ int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
res = MP_OKAY;
-__T3:mp_clear (&t3);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
+LBL_T3:mp_clear (&t3);
+LBL_T2:mp_clear (&t2);
+LBL_T1:mp_clear (&t1);
return res;
}
#endif
diff --git a/bn_mp_prime_fermat.c b/bn_mp_prime_fermat.c
index fe17aaa..fd74dbe 100644
--- a/bn_mp_prime_fermat.c
+++ b/bn_mp_prime_fermat.c
@@ -43,7 +43,7 @@ int mp_prime_fermat (mp_int * a, mp_int * b, int *result)
/* compute t = b**a mod a */
if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
/* is it equal to b? */
@@ -52,7 +52,7 @@ int mp_prime_fermat (mp_int * a, mp_int * b, int *result)
}
err = MP_OKAY;
-__T:mp_clear (&t);
+LBL_T:mp_clear (&t);
return err;
}
#endif
diff --git a/bn_mp_prime_is_divisible.c b/bn_mp_prime_is_divisible.c
index 22ec1ae..f85fe7c 100644
--- a/bn_mp_prime_is_divisible.c
+++ b/bn_mp_prime_is_divisible.c
@@ -29,8 +29,8 @@ int mp_prime_is_divisible (mp_int * a, int *result)
*result = MP_NO;
for (ix = 0; ix < PRIME_SIZE; ix++) {
- /* what is a mod __prime_tab[ix] */
- if ((err = mp_mod_d (a, __prime_tab[ix], &res)) != MP_OKAY) {
+ /* what is a mod LBL_prime_tab[ix] */
+ if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) {
return err;
}
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index c2354d2..188053a 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -37,7 +37,7 @@ int mp_prime_is_prime (mp_int * a, int t, int *result)
/* is the input equal to one of the primes in the table? */
for (ix = 0; ix < PRIME_SIZE; ix++) {
- if (mp_cmp_d(a, __prime_tab[ix]) == MP_EQ) {
+ if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) {
*result = 1;
return MP_OKAY;
}
@@ -60,20 +60,20 @@ int mp_prime_is_prime (mp_int * a, int t, int *result)
for (ix = 0; ix < t; ix++) {
/* set the prime */
- mp_set (&b, __prime_tab[ix]);
+ mp_set (&b, ltm_prime_tab[ix]);
if ((err = mp_prime_miller_rabin (a, &b, &res)) != MP_OKAY) {
- goto __B;
+ goto LBL_B;
}
if (res == MP_NO) {
- goto __B;
+ goto LBL_B;
}
}
/* passed the test */
*result = MP_YES;
-__B:mp_clear (&b);
+LBL_B:mp_clear (&b);
return err;
}
#endif
diff --git a/bn_mp_prime_miller_rabin.c b/bn_mp_prime_miller_rabin.c
index 22dec2f..758a2c3 100644
--- a/bn_mp_prime_miller_rabin.c
+++ b/bn_mp_prime_miller_rabin.c
@@ -40,12 +40,12 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
return err;
}
if ((err = mp_sub_d (&n1, 1, &n1)) != MP_OKAY) {
- goto __N1;
+ goto LBL_N1;
}
/* set 2**s * r = n1 */
if ((err = mp_init_copy (&r, &n1)) != MP_OKAY) {
- goto __N1;
+ goto LBL_N1;
}
/* count the number of least significant bits
@@ -55,15 +55,15 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
/* now divide n - 1 by 2**s */
if ((err = mp_div_2d (&r, s, &r, NULL)) != MP_OKAY) {
- goto __R;
+ goto LBL_R;
}
/* compute y = b**r mod a */
if ((err = mp_init (&y)) != MP_OKAY) {
- goto __R;
+ goto LBL_R;
}
if ((err = mp_exptmod (b, &r, a, &y)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* if y != 1 and y != n1 do */
@@ -72,12 +72,12 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
/* while j <= s-1 and y != n1 */
while ((j <= (s - 1)) && mp_cmp (&y, &n1) != MP_EQ) {
if ((err = mp_sqrmod (&y, a, &y)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* if y == 1 then composite */
if (mp_cmp_d (&y, 1) == MP_EQ) {
- goto __Y;
+ goto LBL_Y;
}
++j;
@@ -85,15 +85,15 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
/* if y != n1 then composite */
if (mp_cmp (&y, &n1) != MP_EQ) {
- goto __Y;
+ goto LBL_Y;
}
}
/* probably prime now */
*result = MP_YES;
-__Y:mp_clear (&y);
-__R:mp_clear (&r);
-__N1:mp_clear (&n1);
+LBL_Y:mp_clear (&y);
+LBL_R:mp_clear (&r);
+LBL_N1:mp_clear (&n1);
return err;
}
#endif
diff --git a/bn_mp_prime_next_prime.c b/bn_mp_prime_next_prime.c
index c478ce5..24f93c4 100644
--- a/bn_mp_prime_next_prime.c
+++ b/bn_mp_prime_next_prime.c
@@ -35,10 +35,10 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
a->sign = MP_ZPOS;
/* simple algo if a is less than the largest prime in the table */
- if (mp_cmp_d(a, __prime_tab[PRIME_SIZE-1]) == MP_LT) {
+ if (mp_cmp_d(a, ltm_prime_tab[PRIME_SIZE-1]) == MP_LT) {
/* find which prime it is bigger than */
for (x = PRIME_SIZE - 2; x >= 0; x--) {
- if (mp_cmp_d(a, __prime_tab[x]) != MP_LT) {
+ if (mp_cmp_d(a, ltm_prime_tab[x]) != MP_LT) {
if (bbs_style == 1) {
/* ok we found a prime smaller or
* equal [so the next is larger]
@@ -46,17 +46,17 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
* however, the prime must be
* congruent to 3 mod 4
*/
- if ((__prime_tab[x + 1] & 3) != 3) {
+ if ((ltm_prime_tab[x + 1] & 3) != 3) {
/* scan upwards for a prime congruent to 3 mod 4 */
for (y = x + 1; y < PRIME_SIZE; y++) {
- if ((__prime_tab[y] & 3) == 3) {
- mp_set(a, __prime_tab[y]);
+ if ((ltm_prime_tab[y] & 3) == 3) {
+ mp_set(a, ltm_prime_tab[y]);
return MP_OKAY;
}
}
}
} else {
- mp_set(a, __prime_tab[x + 1]);
+ mp_set(a, ltm_prime_tab[x + 1]);
return MP_OKAY;
}
}
@@ -94,7 +94,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
/* generate the restable */
for (x = 1; x < PRIME_SIZE; x++) {
- if ((err = mp_mod_d(a, __prime_tab[x], res_tab + x)) != MP_OKAY) {
+ if ((err = mp_mod_d(a, ltm_prime_tab[x], res_tab + x)) != MP_OKAY) {
return err;
}
}
@@ -120,8 +120,8 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
res_tab[x] += kstep;
/* subtract the modulus [instead of using division] */
- if (res_tab[x] >= __prime_tab[x]) {
- res_tab[x] -= __prime_tab[x];
+ if (res_tab[x] >= ltm_prime_tab[x]) {
+ res_tab[x] -= ltm_prime_tab[x];
}
/* set flag if zero */
@@ -133,7 +133,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
/* add the step */
if ((err = mp_add_d(a, step, a)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* if didn't pass sieve and step == MAX then skip test */
@@ -143,9 +143,9 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
/* is this prime? */
for (x = 0; x < t; x++) {
- mp_set(&b, __prime_tab[t]);
+ mp_set(&b, ltm_prime_tab[t]);
if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if (res == MP_NO) {
break;
@@ -158,7 +158,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
}
err = MP_OKAY;
-__ERR:
+LBL_ERR:
mp_clear(&b);
return err;
}
diff --git a/bn_mp_prime_random_ex.c b/bn_mp_prime_random_ex.c
index 2c4f4f0..2010ebe 100644
--- a/bn_mp_prime_random_ex.c
+++ b/bn_mp_prime_random_ex.c
@@ -47,7 +47,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
}
/* calc the byte size */
- bsize = (size>>3)+(size&7?1:0);
+ bsize = (size>>3) + ((size&7)?1:0);
/* we need a buffer of bsize bytes */
tmp = OPT_CAST(unsigned char) XMALLOC(bsize);
@@ -56,7 +56,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
}
/* calc the maskAND value for the MSbyte*/
- maskAND = 0xFF >> (8 - (size & 7));
+ maskAND = ((size&7) == 0) ? 0xFF : (0xFF >> (8 - (size & 7)));
/* calc the maskOR_msb */
maskOR_msb = 0;
@@ -65,7 +65,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
maskOR_msb |= 1 << ((size - 2) & 7);
} else if (flags & LTM_PRIME_2MSB_OFF) {
maskAND &= ~(1 << ((size - 2) & 7));
- }
+ }
/* get the maskOR_lsb */
maskOR_lsb = 0;
diff --git a/bn_prime_tab.c b/bn_prime_tab.c
index 18ecc47..14306c2 100644
--- a/bn_prime_tab.c
+++ b/bn_prime_tab.c
@@ -14,7 +14,7 @@
*
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
*/
-const mp_digit __prime_tab[] = {
+const mp_digit ltm_prime_tab[] = {
0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
diff --git a/bn_s_mp_exptmod.c b/bn_s_mp_exptmod.c
index 4f1032a..01a766f 100644
--- a/bn_s_mp_exptmod.c
+++ b/bn_s_mp_exptmod.c
@@ -70,10 +70,10 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* create mu, used for Barrett reduction */
if ((err = mp_init (&mu)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
/* create M table
@@ -85,23 +85,23 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
* computed though accept for M[0] and M[1]
*/
if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
/* compute the value at M[1<<(winsize-1)] by squaring
* M[1] (winsize-1) times
*/
if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
for (x = 0; x < (winsize - 1); x++) {
if ((err = mp_sqr (&M[1 << (winsize - 1)],
&M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
if ((err = mp_reduce (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
}
@@ -110,16 +110,16 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
*/
for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
if ((err = mp_reduce (&M[x], P, &mu)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
}
/* setup result */
if ((err = mp_init (&res)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
mp_set (&res, 1);
@@ -159,10 +159,10 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* if the bit is zero and mode == 1 then we square */
if (mode == 1 && y == 0) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
continue;
}
@@ -176,19 +176,19 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* square first */
for (x = 0; x < winsize; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* then multiply */
if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
/* empty window and reset */
@@ -203,20 +203,20 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* square then multiply if the bit is set */
for (x = 0; x < bitcpy; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
bitbuf <<= 1;
if ((bitbuf & (1 << winsize)) != 0) {
/* then multiply */
if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
}
@@ -224,9 +224,9 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
mp_exch (&res, Y);
err = MP_OKAY;
-__RES:mp_clear (&res);
-__MU:mp_clear (&mu);
-__M:
+LBL_RES:mp_clear (&res);
+LBL_MU:mp_clear (&mu);
+LBL_M:
mp_clear(&M[1]);
for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
mp_clear (&M[x]);
diff --git a/callgraph.txt b/callgraph.txt
index 56d4f8b..4dc4cba 100644
--- a/callgraph.txt
+++ b/callgraph.txt
@@ -245,6 +245,7 @@ BN_MP_SQRT_C
| | +--->BN_MP_INIT_MULTI_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -298,6 +299,7 @@ BN_MP_SQRT_C
| | +--->BN_MP_CLEAR_C
| +--->BN_MP_SET_C
| +--->BN_MP_COUNT_BITS_C
+| +--->BN_MP_ABS_C
| +--->BN_MP_MUL_2D_C
| | +--->BN_MP_GROW_C
| | +--->BN_MP_LSHD_C
@@ -404,6 +406,7 @@ BN_MP_IS_SQUARE_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -700,6 +703,7 @@ BN_MP_IS_SQUARE_C
| | | +--->BN_MP_INIT_MULTI_C
| | | | +--->BN_MP_CLEAR_C
| | | +--->BN_MP_COUNT_BITS_C
+| | | +--->BN_MP_ABS_C
| | | +--->BN_MP_MUL_2D_C
| | | | +--->BN_MP_GROW_C
| | | | +--->BN_MP_LSHD_C
@@ -753,6 +757,7 @@ BN_MP_IS_SQUARE_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -2618,6 +2623,7 @@ BN_MP_SUBMOD_C
| | +--->BN_MP_INIT_MULTI_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -2838,6 +2844,7 @@ BN_MP_SQRMOD_C
| | +--->BN_MP_INIT_MULTI_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -3313,6 +3320,7 @@ BN_MP_N_ROOT_C
| +--->BN_MP_INIT_MULTI_C
| | +--->BN_MP_CLEAR_C
| +--->BN_MP_COUNT_BITS_C
+| +--->BN_MP_ABS_C
| +--->BN_MP_MUL_2D_C
| | +--->BN_MP_GROW_C
| | +--->BN_MP_LSHD_C
@@ -4322,6 +4330,7 @@ BN_MP_PRIME_RANDOM_EX_C
| | | | | +--->BN_MP_ZERO_C
| | | | | +--->BN_MP_INIT_MULTI_C
| | | | | +--->BN_MP_COUNT_BITS_C
+| | | | | +--->BN_MP_ABS_C
| | | | | +--->BN_MP_MUL_2D_C
| | | | | | +--->BN_MP_GROW_C
| | | | | | +--->BN_MP_LSHD_C
@@ -4548,6 +4557,7 @@ BN_MP_MOD_C
| | +--->BN_MP_CLEAR_C
| +--->BN_MP_SET_C
| +--->BN_MP_COUNT_BITS_C
+| +--->BN_MP_ABS_C
| +--->BN_MP_MUL_2D_C
| | +--->BN_MP_GROW_C
| | +--->BN_MP_LSHD_C
@@ -5600,6 +5610,7 @@ BN_MP_PRIME_IS_PRIME_C
| | | | +--->BN_MP_ZERO_C
| | | | +--->BN_MP_INIT_MULTI_C
| | | | +--->BN_MP_COUNT_BITS_C
+| | | | +--->BN_MP_ABS_C
| | | | +--->BN_MP_MUL_2D_C
| | | | | +--->BN_MP_GROW_C
| | | | | +--->BN_MP_LSHD_C
@@ -5809,6 +5820,7 @@ BN_MP_EXPTMOD_FAST_C
| | | +--->BN_MP_ZERO_C
| | | +--->BN_MP_INIT_MULTI_C
| | | +--->BN_MP_SET_C
+| | | +--->BN_MP_ABS_C
| | | +--->BN_MP_MUL_2D_C
| | | | +--->BN_MP_GROW_C
| | | | +--->BN_MP_LSHD_C
@@ -5865,6 +5877,7 @@ BN_MP_EXPTMOD_FAST_C
| | | +--->BN_MP_GROW_C
| | +--->BN_MP_ZERO_C
| | +--->BN_MP_INIT_MULTI_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -6284,6 +6297,7 @@ BN_MP_MULMOD_C
| | +--->BN_MP_INIT_MULTI_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -7339,6 +7353,7 @@ BN_MP_PRIME_NEXT_PRIME_C
| | | | +--->BN_MP_ZERO_C
| | | | +--->BN_MP_INIT_MULTI_C
| | | | +--->BN_MP_COUNT_BITS_C
+| | | | +--->BN_MP_ABS_C
| | | | +--->BN_MP_MUL_2D_C
| | | | | +--->BN_MP_GROW_C
| | | | | +--->BN_MP_LSHD_C
@@ -7465,6 +7480,7 @@ BN_MP_LCM_C
| +--->BN_MP_ZERO_C
| +--->BN_MP_SET_C
| +--->BN_MP_COUNT_BITS_C
+| +--->BN_MP_ABS_C
| +--->BN_MP_MUL_2D_C
| | +--->BN_MP_GROW_C
| | +--->BN_MP_LSHD_C
@@ -7928,6 +7944,7 @@ BN_S_MP_EXPTMOD_C
| | +--->BN_MP_ZERO_C
| | +--->BN_MP_INIT_MULTI_C
| | +--->BN_MP_SET_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -7974,6 +7991,7 @@ BN_S_MP_EXPTMOD_C
| | +--->BN_MP_ZERO_C
| | +--->BN_MP_INIT_MULTI_C
| | +--->BN_MP_SET_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -8372,6 +8390,7 @@ BN_MP_DIV_C
| +--->BN_MP_CLEAR_C
+--->BN_MP_SET_C
+--->BN_MP_COUNT_BITS_C
++--->BN_MP_ABS_C
+--->BN_MP_MUL_2D_C
| +--->BN_MP_GROW_C
| +--->BN_MP_LSHD_C
@@ -8465,6 +8484,7 @@ BN_MP_ADDMOD_C
| | +--->BN_MP_INIT_MULTI_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -8551,6 +8571,7 @@ BN_MP_REDUCE_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -8766,6 +8787,7 @@ BN_MP_JACOBI_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_SET_C
| | +--->BN_MP_COUNT_BITS_C
+| | +--->BN_MP_ABS_C
| | +--->BN_MP_MUL_2D_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_LSHD_C
@@ -8912,6 +8934,7 @@ BN_MP_EXTEUCLID_C
| +--->BN_MP_CMP_MAG_C
| +--->BN_MP_ZERO_C
| +--->BN_MP_COUNT_BITS_C
+| +--->BN_MP_ABS_C
| +--->BN_MP_MUL_2D_C
| | +--->BN_MP_GROW_C
| | +--->BN_MP_LSHD_C
@@ -9078,6 +9101,7 @@ BN_MP_REDUCE_SETUP_C
| | +--->BN_MP_CLEAR_C
| +--->BN_MP_SET_C
| +--->BN_MP_COUNT_BITS_C
+| +--->BN_MP_ABS_C
| +--->BN_MP_MUL_2D_C
| | +--->BN_MP_GROW_C
| | +--->BN_MP_LSHD_C
@@ -10118,6 +10142,7 @@ BN_MP_PRIME_MILLER_RABIN_C
| | | +--->BN_MP_INIT_MULTI_C
| | | +--->BN_MP_SET_C
| | | +--->BN_MP_COUNT_BITS_C
+| | | +--->BN_MP_ABS_C
| | | +--->BN_MP_MUL_2D_C
| | | | +--->BN_MP_GROW_C
| | | | +--->BN_MP_LSHD_C
diff --git a/changes.txt b/changes.txt
index 6a86209..0d1ec2e 100644
--- a/changes.txt
+++ b/changes.txt
@@ -1,3 +1,12 @@
+December 23rd, 2004
+v0.33 -- Fixed "small" variant for mp_div() which would munge with negative dividends...
+ -- Fixed bug in mp_prime_random_ex() which would set the most significant byte to zero when
+ no special flags were set
+ -- Fixed overflow [minor] bug in fast_s_mp_sqr()
+ -- Made the makefiles easier to configure the group/user that ltm will install as
+ -- Fixed "final carry" bug in comba multipliers. (Volkan Ceylan)
+ -- Matt Johnston pointed out a missing semi-colon in mp_exptmod
+
October 29th, 2004
v0.32 -- Added "makefile.shared" for shared object support
-- Added more to the build options/configs in the manual
diff --git a/demo/demo.c b/demo/demo.c
index 53eb3cf..62615cd 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -11,9 +11,9 @@
void ndraw(mp_int *a, char *name)
{
- char buf[4096];
+ char buf[16000];
printf("%s: ", name);
- mp_toradix(a, buf, 64);
+ mp_toradix(a, buf, 10);
printf("%s\n", buf);
}
@@ -395,7 +395,7 @@ draw(&a);draw(&b);draw(&c);draw(&d);
mp_div(&a, &b, &e, &f);
if (mp_cmp(&c, &e) != MP_EQ || mp_cmp(&d, &f) != MP_EQ) {
- printf("div %lu failure!\n", div_n);
+ printf("div %lu %d, %d, failure!\n", div_n, mp_cmp(&c, &e), mp_cmp(&d, &f));
draw(&a);draw(&b);draw(&c);draw(&d); draw(&e); draw(&f);
return 0;
}
diff --git a/demo/timing.c b/demo/timing.c
index 865c444..7b27d53 100644
--- a/demo/timing.c
+++ b/demo/timing.c
@@ -38,14 +38,13 @@ int lbit(void)
}
}
-#if defined(__i386__) || defined(_M_IX86) || defined(_M_AMD64)
/* RDTSC from Scott Duplichan */
static ulong64 TIMFUNC (void)
{
#if defined __GNUC__
- #ifdef __i386__
- ulong64 a;
- __asm__ __volatile__ ("rdtsc ":"=A" (a));
+ #if defined(__i386__) || defined(__x86_64__)
+ unsigned long long a;
+ __asm__ __volatile__ ("rdtsc\nmovl %%eax,%0\nmovl %%edx,4+%0\n"::"m"(a):"%eax","%edx");
return a;
#else /* gcc-IA64 version */
unsigned long result;
@@ -69,9 +68,6 @@ static ulong64 TIMFUNC (void)
#error need rdtsc function for this build
#endif
}
-#else
-#define TIMFUNC clock
-#endif
#define DO(x) x; x;
//#define DO4(x) DO2(x); DO2(x);
diff --git a/etc/mersenne.c b/etc/mersenne.c
index da6c111..1cd5b50 100644
--- a/etc/mersenne.c
+++ b/etc/mersenne.c
@@ -18,15 +18,15 @@ is_mersenne (long s, int *pp)
}
if ((res = mp_init (&u)) != MP_OKAY) {
- goto __N;
+ goto LBL_N;
}
/* n = 2^s - 1 */
if ((res = mp_2expt(&n, s)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
if ((res = mp_sub_d (&n, 1, &n)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
/* set u=4 */
@@ -36,22 +36,22 @@ is_mersenne (long s, int *pp)
for (k = 1; k <= s - 2; k++) {
/* u = u^2 - 2 mod n */
if ((res = mp_sqr (&u, &u)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
if ((res = mp_sub_d (&u, 2, &u)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
/* make sure u is positive */
while (u.sign == MP_NEG) {
if ((res = mp_add (&u, &n, &u)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
}
/* reduce */
if ((res = mp_reduce_2k (&u, &n, 1)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
}
@@ -62,8 +62,8 @@ is_mersenne (long s, int *pp)
}
res = MP_OKAY;
-__MU:mp_clear (&u);
-__N:mp_clear (&n);
+LBL_MU:mp_clear (&u);
+LBL_N:mp_clear (&n);
return res;
}
diff --git a/etc/pprime.c b/etc/pprime.c
index cccb748..26e0d84 100644
--- a/etc/pprime.c
+++ b/etc/pprime.c
@@ -189,7 +189,7 @@ pprime (int k, int li, mp_int * p, mp_int * q)
}
if ((res = mp_init (&v)) != MP_OKAY) {
- goto __C;
+ goto LBL_C;
}
/* product of first 50 primes */
@@ -197,34 +197,34 @@ pprime (int k, int li, mp_int * p, mp_int * q)
mp_read_radix (&v,
"19078266889580195013601891820992757757219839668357012055907516904309700014933909014729740190",
10)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
if ((res = mp_init (&a)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
/* set the prime */
mp_set (&a, prime_digit ());
if ((res = mp_init (&b)) != MP_OKAY) {
- goto __A;
+ goto LBL_A;
}
if ((res = mp_init (&n)) != MP_OKAY) {
- goto __B;
+ goto LBL_B;
}
if ((res = mp_init (&x)) != MP_OKAY) {
- goto __N;
+ goto LBL_N;
}
if ((res = mp_init (&y)) != MP_OKAY) {
- goto __X;
+ goto LBL_X;
}
if ((res = mp_init (&z)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* now loop making the single digit */
@@ -236,25 +236,25 @@ pprime (int k, int li, mp_int * p, mp_int * q)
/* now compute z = a * b * 2 */
if ((res = mp_mul (&a, &b, &z)) != MP_OKAY) { /* z = a * b */
- goto __Z;
+ goto LBL_Z;
}
if ((res = mp_copy (&z, &c)) != MP_OKAY) { /* c = a * b */
- goto __Z;
+ goto LBL_Z;
}
if ((res = mp_mul_2 (&z, &z)) != MP_OKAY) { /* z = 2 * a * b */
- goto __Z;
+ goto LBL_Z;
}
/* n = z + 1 */
if ((res = mp_add_d (&z, 1, &n)) != MP_OKAY) { /* n = z + 1 */
- goto __Z;
+ goto LBL_Z;
}
/* check (n, v) == 1 */
if ((res = mp_gcd (&n, &v, &y)) != MP_OKAY) { /* y = (n, v) */
- goto __Z;
+ goto LBL_Z;
}
if (mp_cmp_d (&y, 1) != MP_EQ)
@@ -266,7 +266,7 @@ pprime (int k, int li, mp_int * p, mp_int * q)
/* compute x^a mod n */
if ((res = mp_exptmod (&x, &a, &n, &y)) != MP_OKAY) { /* y = x^a mod n */
- goto __Z;
+ goto LBL_Z;
}
/* if y == 1 loop */
@@ -275,7 +275,7 @@ pprime (int k, int li, mp_int * p, mp_int * q)
/* now x^2a mod n */
if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) { /* y = x^2a mod n */
- goto __Z;
+ goto LBL_Z;
}
if (mp_cmp_d (&y, 1) == MP_EQ)
@@ -283,7 +283,7 @@ pprime (int k, int li, mp_int * p, mp_int * q)
/* compute x^b mod n */
if ((res = mp_exptmod (&x, &b, &n, &y)) != MP_OKAY) { /* y = x^b mod n */
- goto __Z;
+ goto LBL_Z;
}
/* if y == 1 loop */
@@ -292,7 +292,7 @@ pprime (int k, int li, mp_int * p, mp_int * q)
/* now x^2b mod n */
if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) { /* y = x^2b mod n */
- goto __Z;
+ goto LBL_Z;
}
if (mp_cmp_d (&y, 1) == MP_EQ)
@@ -300,7 +300,7 @@ pprime (int k, int li, mp_int * p, mp_int * q)
/* compute x^c mod n == x^ab mod n */
if ((res = mp_exptmod (&x, &c, &n, &y)) != MP_OKAY) { /* y = x^ab mod n */
- goto __Z;
+ goto LBL_Z;
}
/* if y == 1 loop */
@@ -309,7 +309,7 @@ pprime (int k, int li, mp_int * p, mp_int * q)
/* now compute (x^c mod n)^2 */
if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) { /* y = x^2ab mod n */
- goto __Z;
+ goto LBL_Z;
}
/* y should be 1 */
@@ -346,14 +346,14 @@ pprime (int k, int li, mp_int * p, mp_int * q)
mp_exch (&n, p);
res = MP_OKAY;
-__Z:mp_clear (&z);
-__Y:mp_clear (&y);
-__X:mp_clear (&x);
-__N:mp_clear (&n);
-__B:mp_clear (&b);
-__A:mp_clear (&a);
-__V:mp_clear (&v);
-__C:mp_clear (&c);
+LBL_Z:mp_clear (&z);
+LBL_Y:mp_clear (&y);
+LBL_X:mp_clear (&x);
+LBL_N:mp_clear (&n);
+LBL_B:mp_clear (&b);
+LBL_A:mp_clear (&a);
+LBL_V:mp_clear (&v);
+LBL_C:mp_clear (&c);
return res;
}
diff --git a/etc/tune.c b/etc/tune.c
index bc101be..14aace2 100644
--- a/etc/tune.c
+++ b/etc/tune.c
@@ -14,9 +14,9 @@
#ifndef X86_TIMER
/* generic ISO C timer */
-ulong64 __T;
-void t_start(void) { __T = clock(); }
-ulong64 t_read(void) { return clock() - __T; }
+ulong64 LBL_T;
+void t_start(void) { LBL_T = clock(); }
+ulong64 t_read(void) { return clock() - LBL_T; }
#else
extern void t_start(void);
diff --git a/logs/add.log b/logs/add.log
index d44c4cd..fa11039 100644
--- a/logs/add.log
+++ b/logs/add.log
@@ -1,16 +1,16 @@
-224 222
-448 330
-672 436
-896 520
-1120 612
-1344 696
-1568 810
-1792 912
-2016 1006
-2240 1116
-2464 1152
-2688 1284
-2912 1348
-3136 1486
-3360 1580
-3584 1636
+480 88
+960 113
+1440 138
+1920 163
+2400 202
+2880 226
+3360 251
+3840 272
+4320 296
+4800 320
+5280 344
+5760 368
+6240 392
+6720 416
+7200 440
+7680 464
diff --git a/logs/expt.log b/logs/expt.log
index e69de29..e65e927 100644
--- a/logs/expt.log
+++ b/logs/expt.log
@@ -0,0 +1,7 @@
+513 1499509
+769 3682671
+1025 8098887
+2049 49332743
+2561 89647783
+3073 149440713
+4097 326135364
diff --git a/logs/expt_2k.log b/logs/expt_2k.log
index e69de29..d106280 100644
--- a/logs/expt_2k.log
+++ b/logs/expt_2k.log
@@ -0,0 +1,6 @@
+521 1423346
+607 1841305
+1279 8375656
+2203 34104708
+3217 83830729
+4253 167916804
diff --git a/logs/expt_dr.log b/logs/expt_dr.log
index e69de29..6cfc874 100644
--- a/logs/expt_dr.log
+++ b/logs/expt_dr.log
@@ -0,0 +1,7 @@
+532 1803110
+784 3607375
+1036 6089790
+1540 14739797
+2072 33251589
+3080 82794331
+4116 165212734
diff --git a/logs/mult.log b/logs/mult.log
index a2c9c18..864de46 100644
--- a/logs/mult.log
+++ b/logs/mult.log
@@ -1,143 +1,143 @@
-140 1272
-195 1428
-252 1996
-307 2586
-364 3464
-420 4420
-476 5260
-532 6430
-588 7692
-644 8704
-699 10226
-755 11670
-812 13190
-865 14834
-924 16738
-979 18362
-1036 20660
-1092 22776
-1148 24848
-1204 27168
-1260 29930
-1316 32258
-1370 35172
-1422 37534
-1482 40390
-1537 43990
-1589 46946
-1652 50438
-1703 52902
-1764 56646
-1820 59892
-1876 63248
-1932 66872
-1988 72596
-2042 74662
-2100 78512
-2156 82944
-2211 87444
-2268 92170
-2324 95534
-2380 100484
-2435 105024
-2491 109460
-2546 114154
-2603 118946
-2660 124110
-2716 129300
-2771 134274
-2828 139594
-2883 145234
-2939 150332
-2996 155750
-3048 161718
-3108 167492
-3162 173882
-3219 179766
-3276 185560
-3330 191826
-3388 197822
-3442 204176
-3500 210682
-3556 217236
-3612 223484
-3666 230714
-3724 237744
-3779 244080
-3835 250970
-3890 257914
-3947 265162
-4001 272128
-4060 279108
-4116 287606
-4171 294716
-4227 302806
-4284 310260
-4340 318564
-4395 326164
-4443 334034
-4508 342108
-4561 351810
-4618 358828
-4675 367332
-4732 376140
-4787 384172
-4841 393308
-4899 402036
-4955 411286
-5010 420290
-5067 429688
-5124 438810
-5180 448130
-5235 457264
-5290 467390
-5348 476586
-5404 486120
-5459 496512
-5516 506624
-5569 516346
-5628 526604
-5684 536544
-5740 546936
-5796 557284
-5852 568106
-5907 578824
-5963 589204
-6019 600176
-6076 610564
-6127 621972
-6188 633564
-6244 644730
-6300 655288
-6354 667402
-6412 678824
-6467 690594
-6522 702718
-6580 714148
-6636 725608
-6690 737834
-6747 750100
-6804 762202
-6860 774184
-6916 787298
-6971 798734
-7028 811162
-7083 824570
-7139 837738
-7196 2579488
-7245 2626714
-7308 2643582
-7364 2698746
-7416 2734106
-7476 2773372
-7530 2816738
-7588 2859204
-7643 2938596
-7698 2919716
-7754 2988542
-7812 3026520
-7867 3058304
-7924 3115790
-7977 3161450
-8035 3203138
-8092 3244056
+271 580
+390 861
+511 1177
+630 1598
+749 2115
+871 2670
+991 3276
+1111 3987
+1231 4722
+1351 5474
+1471 6281
+1589 7126
+1710 8114
+1831 8988
+1946 10038
+2071 10995
+2188 12286
+2310 13152
+2430 14480
+2549 15521
+2671 17171
+2790 18081
+2911 19754
+3031 20809
+3150 22849
+3269 23757
+3391 25772
+3508 26832
+3631 29304
+3750 30149
+3865 32581
+3988 33644
+4111 36565
+4231 37309
+4351 40152
+4471 41188
+4590 44658
+4710 45256
+4827 48538
+4951 49490
+5070 53472
+5190 53902
+5308 57619
+5431 58509
+5550 63044
+5664 63333
+5791 67542
+5911 68279
+6028 73477
+6150 73475
+6271 78189
+6390 78842
+6510 84691
+6631 84444
+6751 89721
+6871 90186
+6991 96665
+7111 96119
+7231 101937
+7350 102212
+7471 109439
+7591 108491
+7709 114965
+7829 115025
+7951 123002
+8071 121630
+8190 128725
+8311 128536
+8430 137298
+8550 135568
+8671 143265
+8791 142793
+8911 152432
+9030 150202
+9151 158616
+9271 157848
+9391 168374
+9511 165651
+9627 174775
+9750 173375
+9871 185067
+9985 181845
+10111 191708
+10229 190239
+10351 202585
+10467 198704
+10591 209193
+10711 207322
+10831 220842
+10950 215882
+11071 227761
+11191 225501
+11311 239669
+11430 234809
+11550 243511
+11671 255947
+11791 255243
+11906 267828
+12029 263437
+12149 276571
+12270 275579
+12390 288963
+12510 284001
+12631 298196
+12751 297018
+12869 310848
+12990 305369
+13111 319086
+13230 318940
+13349 333685
+13471 327495
+13588 343678
+13711 341817
+13831 357181
+13948 350440
+14071 367526
+14189 365330
+14311 381551
+14429 374149
+14549 392203
+14670 389764
+14791 406761
+14910 398652
+15026 417718
+15150 414733
+15269 432759
+15390 1037071
+15511 1053454
+15631 1069198
+15748 1086164
+15871 1112820
+15991 1129676
+16111 1145924
+16230 1163016
+16345 1179911
+16471 1197048
+16586 1214352
+16711 1232095
+16829 1249338
+16947 1266987
+17071 1284181
+17188 1302521
+17311 1320539
diff --git a/logs/sqr.log b/logs/sqr.log
index 3e175ac..0898342 100644
--- a/logs/sqr.log
+++ b/logs/sqr.log
@@ -1,143 +1,143 @@
-139 806
-195 1212
-252 1604
-307 2260
-364 2892
-420 3308
-476 4152
-532 4814
-588 5754
-644 6684
-700 7226
-756 8324
-808 9092
-866 10068
-924 11204
-976 12918
-1036 13656
-1092 15248
-1148 15956
-1204 17270
-1260 19894
-1316 20516
-1370 21864
-1428 25554
-1483 26138
-1540 27086
-1596 29246
-1652 32210
-1707 32704
-1764 35142
-1820 39050
-1876 39256
-1931 41574
-1985 45070
-2044 46352
-2099 48114
-2155 51332
-2212 53268
-2267 55890
-2324 59054
-2380 60206
-2434 63540
-2491 66084
-2547 68590
-2604 74332
-2660 74784
-2715 77974
-2772 79924
-2826 82914
-2884 87210
-2929 89076
-2996 92480
-3052 96814
-3108 99990
-3162 102550
-3219 105396
-3276 109284
-3332 113752
-3387 116628
-3444 120782
-3500 122938
-3556 127940
-3612 303656
-3667 312212
-3724 324376
-3779 329204
-3833 340910
-3892 353850
-3943 362348
-4003 367780
-4056 380448
-4114 393616
-4172 404104
-4227 415148
-4284 409770
-4339 436648
-4394 442970
-4451 463096
-4507 472056
-4564 485780
-4616 496286
-4675 507612
-4732 519524
-4788 536768
-4843 542754
-4899 553090
-4956 571986
-5012 586340
-5068 599606
-5124 613670
-5179 624256
-5235 636266
-5292 655518
-5348 668142
-5403 677266
-5460 696040
-5516 712772
-5570 723942
-5628 739052
-5684 755350
-5739 769962
-5790 775258
-5851 790128
-5908 814536
-5962 827278
-6018 844510
-6076 851606
-6130 865748
-6188 894752
-6244 900474
-6300 928174
-6356 928440
-6410 957758
-6468 981134
-6524 994088
-6580 1011124
-6636 1027178
-6692 1045466
-6747 1056910
-6804 1083784
-6860 1104706
-6915 1116450
-6972 1137894
-7028 1154670
-7084 1158064
-7138 1188734
-7196 1214218
-7249 1226822
-7307 1247528
-7363 1255338
-7420 1291104
-7475 1297940
-7532 1324994
-7587 1340274
-7644 1342596
-7698 1381418
-7756 1382904
-7812 1432588
-7867 1443632
-7922 1465092
-7979 1496804
-8036 1520142
-8092 1539566
+271 552
+389 883
+510 1191
+629 1572
+750 1996
+863 2428
+991 2891
+1108 3539
+1231 4182
+1351 4980
+1471 5771
+1590 6551
+1711 7313
+1830 8240
+1951 9184
+2070 10087
+2191 11140
+2311 12111
+2431 13219
+2550 14247
+2669 15353
+2791 16446
+2911 17692
+3029 18848
+3151 20028
+3268 21282
+3391 22696
+3511 23971
+3631 25303
+3751 26675
+3871 28245
+3990 29736
+4111 31124
+4229 32714
+4347 34397
+4471 35877
+4587 37269
+4710 39011
+4831 40884
+4950 42501
+5070 44005
+5191 46026
+5310 48168
+5431 49801
+5551 51385
+5671 53604
+5787 55942
+5910 57757
+6031 59391
+6151 61754
+6271 64234
+6390 66110
+6511 67845
+6627 70474
+6751 73113
+6871 75064
+6990 76940
+7111 79681
+7230 82548
+7351 84597
+7471 86507
+7591 89497
+7711 225216
+7831 232192
+7951 239583
+8071 247302
+8191 255497
+8308 261587
+8431 271490
+8550 279492
+8671 286927
+8790 294680
+8910 302974
+9030 311300
+9150 318635
+9271 326740
+9390 335304
+9511 344297
+9630 352056
+9748 358652
+9870 369723
+9991 379119
+10111 386982
+10231 396075
+10349 404396
+10470 415375
+10590 424146
+10711 433390
+10829 442662
+10950 453238
+11071 462178
+11186 469811
+11311 482529
+11431 493214
+11550 503210
+11671 513486
+11791 524244
+11911 535277
+12031 544872
+12151 555695
+12271 566893
+12391 578385
+12510 588658
+12628 596914
+12751 611324
+12871 623437
+12991 633907
+13110 645605
+13231 657684
+13351 670037
+13471 680939
+13591 693047
+13710 705363
+13829 718178
+13949 727930
+14069 739641
+14190 754817
+14310 768192
+14431 779875
+14551 792655
+14667 802847
+14791 819806
+14911 831684
+15031 844936
+15151 858813
+15270 873037
+15387 882123
+15510 899117
+15631 913465
+15750 927989
+15870 940790
+15991 954948
+16110 969483
+16231 984544
+16350 997837
+16470 1012445
+16590 1027834
+16710 1043032
+16831 1056394
+16951 1071408
+17069 1097263
+17191 1113364
+17306 1123650
diff --git a/logs/sub.log b/logs/sub.log
index cf2bcd6..a42d91e 100644
--- a/logs/sub.log
+++ b/logs/sub.log
@@ -1,16 +1,16 @@
-224 216
-448 324
-672 428
-896 532
-1120 648
-1344 766
-1568 862
-1792 928
-2016 1070
-2240 1128
-2464 1250
-2688 1344
-2912 1436
-3136 1542
-3360 1628
-3584 1696
+480 87
+960 114
+1440 139
+1920 159
+2400 204
+2880 228
+3360 250
+3840 273
+4320 300
+4800 321
+5280 348
+5760 370
+6240 393
+6720 420
+7200 444
+7680 466
diff --git a/makefile b/makefile
index 4fe2256..164a0ab 100644
--- a/makefile
+++ b/makefile
@@ -1,10 +1,14 @@
#Makefile for GCC
#
#Tom St Denis
+
+#version of library
+VERSION=0.33
+
CFLAGS += -I./ -Wall -W -Wshadow -Wsign-compare
#for speed
-CFLAGS += -O3 -funroll-loops
+CFLAGS += -O3 -funroll-all-loops
#for size
#CFLAGS += -Os
@@ -15,13 +19,15 @@ CFLAGS += -fomit-frame-pointer
#debug
#CFLAGS += -g3
-VERSION=0.32
+#install as this user
+USER=root
+GROUP=root
default: libtommath.a
#default files to install
LIBNAME=libtommath.a
-HEADERS=tommath.h
+HEADERS=tommath.h tommath_class.h tommath_superclass.h
#LIBPATH-The directory for libtommath to be installed to.
#INCPATH-The directory to install the header files for libtommath.
@@ -61,7 +67,6 @@ libtommath.a: $(OBJECTS)
$(AR) $(ARFLAGS) libtommath.a $(OBJECTS)
ranlib libtommath.a
-
#make a profiled library (takes a while!!!)
#
# This will build the library with profile generation
@@ -86,19 +91,19 @@ profiled_single:
ranlib libtommath.a
install: libtommath.a
- install -d -g root -o root $(DESTDIR)$(LIBPATH)
- install -d -g root -o root $(DESTDIR)$(INCPATH)
- install -g root -o root $(LIBNAME) $(DESTDIR)$(LIBPATH)
- install -g root -o root $(HEADERS) $(DESTDIR)$(INCPATH)
+ install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
+ install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
+ install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
+ install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
test: libtommath.a demo/demo.o
- $(CC) demo/demo.o libtommath.a -o test
+ $(CC) $(CFLAGS) demo/demo.o libtommath.a -o test
mtest: test
- cd mtest ; $(CC) $(CFLAGS) mtest.c -o mtest -s
+ cd mtest ; $(CC) $(CFLAGS) mtest.c -o mtest
timing: libtommath.a
- $(CC) $(CFLAGS) -DTIMER demo/timing.c libtommath.a -o ltmtest -s
+ $(CC) $(CFLAGS) -DTIMER demo/timing.c libtommath.a -o ltmtest
# makes the LTM book DVI file, requires tetex, perl and makeindex [part of tetex I think]
docdvi: tommath.src
diff --git a/makefile.icc b/makefile.icc
index 09117b7..3775b20 100644
--- a/makefile.icc
+++ b/makefile.icc
@@ -21,6 +21,10 @@ CFLAGS += -I./
# Default to just generic max opts
CFLAGS += -O3 -xN
+#install as this user
+USER=root
+GROUP=root
+
default: libtommath.a
#default files to install
@@ -89,10 +93,10 @@ profiled_single:
ranlib libtommath.a
install: libtommath.a
- install -d -g root -o root $(DESTDIR)$(LIBPATH)
- install -d -g root -o root $(DESTDIR)$(INCPATH)
- install -g root -o root $(LIBNAME) $(DESTDIR)$(LIBPATH)
- install -g root -o root $(HEADERS) $(DESTDIR)$(INCPATH)
+ install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
+ install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
+ install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
+ install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
test: libtommath.a demo/demo.o
$(CC) demo/demo.o libtommath.a -o test
diff --git a/makefile.shared b/makefile.shared
index 96bbf32..86a3786 100644
--- a/makefile.shared
+++ b/makefile.shared
@@ -1,10 +1,9 @@
#Makefile for GCC
#
#Tom St Denis
-VERSION=0:32
+VERSION=0:33
CC = libtool --mode=compile gcc
-
CFLAGS += -I./ -Wall -W -Wshadow -Wsign-compare
#for speed
@@ -16,11 +15,15 @@ CFLAGS += -O3 -funroll-loops
#x86 optimizations [should be valid for any GCC install though]
CFLAGS += -fomit-frame-pointer
+#install as this user
+USER=root
+GROUP=root
+
default: libtommath.la
#default files to install
LIBNAME=libtommath.la
-HEADERS=tommath.h
+HEADERS=tommath.h tommath_class.h tommath_superclass.h
#LIBPATH-The directory for libtommath to be installed to.
#INCPATH-The directory to install the header files for libtommath.
@@ -60,8 +63,8 @@ libtommath.la: $(OBJECTS)
libtool --mode=link gcc *.lo -o libtommath.la -rpath $(LIBPATH) -version-info $(VERSION)
libtool --mode=link gcc *.o -o libtommath.a
libtool --mode=install install -c libtommath.la $(LIBPATH)/libtommath.la
- install -d -g root -o root $(DESTDIR)$(INCPATH)
- install -g root -o root $(HEADERS) $(DESTDIR)$(INCPATH)
+ install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
+ install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
test: libtommath.a demo/demo.o
gcc $(CFLAGS) -c demo/demo.c -o demo/demo.o
diff --git a/mtest/mtest.c b/mtest/mtest.c
index ef0e093..d46f456 100644
--- a/mtest/mtest.c
+++ b/mtest/mtest.c
@@ -46,7 +46,7 @@ void rand_num(mp_int *a)
int n, size;
unsigned char buf[2048];
- size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % 1031;
+ size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % 101;
buf[0] = (fgetc(rng)&1)?1:0;
fread(buf+1, 1, size, rng);
while (buf[1] == 0) buf[1] = fgetc(rng);
@@ -58,7 +58,7 @@ void rand_num2(mp_int *a)
int n, size;
unsigned char buf[2048];
- size = 10 + ((fgetc(rng)<<8) + fgetc(rng)) % 97;
+ size = 10 + ((fgetc(rng)<<8) + fgetc(rng)) % 101;
buf[0] = (fgetc(rng)&1)?1:0;
fread(buf+1, 1, size, rng);
while (buf[1] == 0) buf[1] = fgetc(rng);
diff --git a/poster.pdf b/poster.pdf
index 60999da..e0b4f84 100644
Binary files a/poster.pdf and b/poster.pdf differ
diff --git a/pre_gen/mpi.c b/pre_gen/mpi.c
index 78a73f0..7d832e7 100644
--- a/pre_gen/mpi.c
+++ b/pre_gen/mpi.c
@@ -87,20 +87,20 @@ fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
/* x == modulus, y == value to invert */
if ((res = mp_copy (b, &x)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* we need y = |a| */
if ((res = mp_abs (a, &y)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
if ((res = mp_copy (&x, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_copy (&y, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
mp_set (&D, 1);
@@ -109,17 +109,17 @@ top:
while (mp_iseven (&u) == 1) {
/* 4.1 u = u/2 */
if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 4.2 if B is odd then */
if (mp_isodd (&B) == 1) {
if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* B = B/2 */
if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -127,18 +127,18 @@ top:
while (mp_iseven (&v) == 1) {
/* 5.1 v = v/2 */
if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 5.2 if D is odd then */
if (mp_isodd (&D) == 1) {
/* D = (D-x)/2 */
if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* D = D/2 */
if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -146,20 +146,20 @@ top:
if (mp_cmp (&u, &v) != MP_LT) {
/* u = u - v, B = B - D */
if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
} else {
/* v - v - u, D = D - B */
if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -173,21 +173,21 @@ top:
/* if v != 1 then there is no inverse */
if (mp_cmp_d (&v, 1) != MP_EQ) {
res = MP_VAL;
- goto __ERR;
+ goto LBL_ERR;
}
/* b is now the inverse */
neg = a->sign;
while (D.sign == MP_NEG) {
if ((res = mp_add (&D, b, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
mp_exch (&D, c);
c->sign = neg;
res = MP_OKAY;
-__ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
return res;
}
#endif
@@ -420,7 +420,7 @@ fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* clear the carry */
_W = 0;
- for (ix = 0; ix <= pa; ix++) {
+ for (ix = 0; ix < pa; ix++) {
int tx, ty;
int iy;
mp_digit *tmpx, *tmpy;
@@ -450,6 +450,9 @@ fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
_W = _W >> ((mp_word)DIGIT_BIT);
}
+ /* store final carry */
+ W[ix] = _W;
+
/* setup dest */
olduse = c->used;
c->used = digs;
@@ -519,7 +522,7 @@ fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* number of output digits to produce */
pa = a->used + b->used;
_W = 0;
- for (ix = digs; ix <= pa; ix++) {
+ for (ix = digs; ix < pa; ix++) {
int tx, ty, iy;
mp_digit *tmpx, *tmpy;
@@ -547,6 +550,9 @@ fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* make next carry */
_W = _W >> ((mp_word)DIGIT_BIT);
}
+
+ /* store final carry */
+ W[ix] = _W;
/* setup dest */
olduse = c->used;
@@ -636,7 +642,7 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
/* number of output digits to produce */
W1 = 0;
- for (ix = 0; ix <= pa; ix++) {
+ for (ix = 0; ix < pa; ix++) {
int tx, ty, iy;
mp_word _W;
mp_digit *tmpy;
@@ -1539,23 +1545,23 @@ int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
mp_set(&tq, 1);
n = mp_count_bits(a) - mp_count_bits(b);
- if (((res = mp_copy(a, &ta)) != MP_OKAY) ||
- ((res = mp_copy(b, &tb)) != MP_OKAY) ||
+ if (((res = mp_abs(a, &ta)) != MP_OKAY) ||
+ ((res = mp_abs(b, &tb)) != MP_OKAY) ||
((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) ||
((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) {
- goto __ERR;
+ goto LBL_ERR;
}
while (n-- >= 0) {
if (mp_cmp(&tb, &ta) != MP_GT) {
if (((res = mp_sub(&ta, &tb, &ta)) != MP_OKAY) ||
((res = mp_add(&q, &tq, &q)) != MP_OKAY)) {
- goto __ERR;
+ goto LBL_ERR;
}
}
if (((res = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) ||
((res = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -1564,13 +1570,13 @@ int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG);
if (c != NULL) {
mp_exch(c, &q);
- c->sign = n2;
+ c->sign = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2;
}
if (d != NULL) {
mp_exch(d, &ta);
- d->sign = n;
+ d->sign = (mp_iszero(d) == MP_YES) ? MP_ZPOS : n;
}
-__ERR:
+LBL_ERR:
mp_clear_multi(&ta, &tb, &tq, &q, NULL);
return res;
}
@@ -1619,19 +1625,19 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
q.used = a->used + 2;
if ((res = mp_init (&t1)) != MP_OKAY) {
- goto __Q;
+ goto LBL_Q;
}
if ((res = mp_init (&t2)) != MP_OKAY) {
- goto __T1;
+ goto LBL_T1;
}
if ((res = mp_init_copy (&x, a)) != MP_OKAY) {
- goto __T2;
+ goto LBL_T2;
}
if ((res = mp_init_copy (&y, b)) != MP_OKAY) {
- goto __X;
+ goto LBL_X;
}
/* fix the sign */
@@ -1643,10 +1649,10 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
if (norm < (int)(DIGIT_BIT-1)) {
norm = (DIGIT_BIT-1) - norm;
if ((res = mp_mul_2d (&x, norm, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_mul_2d (&y, norm, &y)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
} else {
norm = 0;
@@ -1658,13 +1664,13 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
/* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
if ((res = mp_lshd (&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */
- goto __Y;
+ goto LBL_Y;
}
while (mp_cmp (&x, &y) != MP_LT) {
++(q.dp[n - t]);
if ((res = mp_sub (&x, &y, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
}
@@ -1706,7 +1712,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
t1.dp[1] = y.dp[t];
t1.used = 2;
if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* find right hand */
@@ -1718,27 +1724,27 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
/* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_sub (&x, &t1, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */
if (x.sign == MP_NEG) {
if ((res = mp_copy (&y, &t1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
@@ -1765,11 +1771,11 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
res = MP_OKAY;
-__Y:mp_clear (&y);
-__X:mp_clear (&x);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
-__Q:mp_clear (&q);
+LBL_Y:mp_clear (&y);
+LBL_X:mp_clear (&x);
+LBL_T2:mp_clear (&t2);
+LBL_T1:mp_clear (&t1);
+LBL_Q:mp_clear (&q);
return res;
}
@@ -2199,7 +2205,7 @@ int mp_dr_is_modulus(mp_int *a)
* Based on algorithm from the paper
*
* "Generating Efficient Primes for Discrete Log Cryptosystems"
- * Chae Hoon Lim, Pil Loong Lee,
+ * Chae Hoon Lim, Pil Joong Lee,
* POSTECH Information Research Laboratories
*
* The modulus must be of a special format [see manual]
@@ -2457,7 +2463,7 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
return err;
#else
/* no invmod */
- return MP_VAL
+ return MP_VAL;
#endif
}
@@ -2588,11 +2594,11 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
#ifdef BN_MP_MONTGOMERY_SETUP_C
/* now setup montgomery */
if ((err = mp_montgomery_setup (P, &mp)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
/* automatically pick the comba one if available (saves quite a few calls/ifs) */
@@ -2608,7 +2614,7 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
redux = mp_montgomery_reduce;
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
}
} else if (redmode == 1) {
@@ -2618,24 +2624,24 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
redux = mp_dr_reduce;
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
} else {
#if defined(BN_MP_REDUCE_2K_SETUP_C) && defined(BN_MP_REDUCE_2K_C)
/* setup DR reduction for moduli of the form 2**k - b */
if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
redux = mp_reduce_2k;
#else
err = MP_VAL;
- goto __M;
+ goto LBL_M;
#endif
}
/* setup result */
if ((err = mp_init (&res)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
/* create M table
@@ -2649,45 +2655,45 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
#ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
/* now we need R mod m */
if ((err = mp_montgomery_calc_normalization (&res, P)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
#else
err = MP_VAL;
- goto __RES;
+ goto LBL_RES;
#endif
/* now set M[1] to G * R mod m */
if ((err = mp_mulmod (G, &res, P, &M[1])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
} else {
mp_set(&res, 1);
if ((err = mp_mod(G, P, &M[1])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times */
if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
for (x = 0; x < (winsize - 1); x++) {
if ((err = mp_sqr (&M[1 << (winsize - 1)], &M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&M[1 << (winsize - 1)], P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* create upper table */
for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&M[x], P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
@@ -2727,10 +2733,10 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
/* if the bit is zero and mode == 1 then we square */
if (mode == 1 && y == 0) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
continue;
}
@@ -2744,19 +2750,19 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
/* square first */
for (x = 0; x < winsize; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* then multiply */
if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
/* empty window and reset */
@@ -2771,10 +2777,10 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
/* square then multiply if the bit is set */
for (x = 0; x < bitcpy; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
/* get next bit of the window */
@@ -2782,10 +2788,10 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
if ((bitbuf & (1 << winsize)) != 0) {
/* then multiply */
if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = redux (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
}
@@ -2799,15 +2805,15 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
* of R.
*/
if ((err = redux(&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* swap res with Y */
mp_exch (&res, Y);
err = MP_OKAY;
-__RES:mp_clear (&res);
-__M:
+LBL_RES:mp_clear (&res);
+LBL_M:
mp_clear(&M[1]);
for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
mp_clear (&M[x]);
@@ -3059,7 +3065,7 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
}
if ((res = mp_init_copy (&v, b)) != MP_OKAY) {
- goto __U;
+ goto LBL_U;
}
/* must be positive for the remainder of the algorithm */
@@ -3073,24 +3079,24 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
if (k > 0) {
/* divide the power of two out */
if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
/* divide any remaining factors of two out */
if (u_lsb != k) {
if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
if (v_lsb != k) {
if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
@@ -3103,23 +3109,23 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
/* subtract smallest from largest */
if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
/* Divide out all factors of two */
if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
}
/* multiply by 2**k which we divided out at the beginning */
if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) {
- goto __V;
+ goto LBL_V;
}
c->sign = MP_ZPOS;
res = MP_OKAY;
-__V:mp_clear (&u);
-__U:mp_clear (&v);
+LBL_V:mp_clear (&u);
+LBL_U:mp_clear (&v);
return res;
}
#endif
@@ -3556,24 +3562,24 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
/* x = a, y = b */
if ((res = mp_copy (a, &x)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_copy (b, &y)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 2. [modified] if x,y are both even then return an error! */
if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
res = MP_VAL;
- goto __ERR;
+ goto LBL_ERR;
}
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
if ((res = mp_copy (&x, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_copy (&y, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
mp_set (&A, 1);
mp_set (&D, 1);
@@ -3583,24 +3589,24 @@ top:
while (mp_iseven (&u) == 1) {
/* 4.1 u = u/2 */
if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 4.2 if A or B is odd then */
if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
/* A = (A+y)/2, B = (B-x)/2 */
if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* A = A/2, B = B/2 */
if ((res = mp_div_2 (&A, &A)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -3608,24 +3614,24 @@ top:
while (mp_iseven (&v) == 1) {
/* 5.1 v = v/2 */
if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* 5.2 if C or D is odd then */
if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
/* C = (C+y)/2, D = (D-x)/2 */
if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* C = C/2, D = D/2 */
if ((res = mp_div_2 (&C, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -3633,28 +3639,28 @@ top:
if (mp_cmp (&u, &v) != MP_LT) {
/* u = u - v, A = A - C, B = B - D */
if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&A, &C, &A)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
} else {
/* v - v - u, C = C - A, D = D - B */
if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&C, &A, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
@@ -3667,27 +3673,27 @@ top:
/* if v != 1 then there is no inverse */
if (mp_cmp_d (&v, 1) != MP_EQ) {
res = MP_VAL;
- goto __ERR;
+ goto LBL_ERR;
}
/* if its too low */
while (mp_cmp_d(&C, 0) == MP_LT) {
if ((res = mp_add(&C, b, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* too big */
while (mp_cmp_mag(&C, b) != MP_LT) {
if ((res = mp_sub(&C, b, &C)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
}
/* C is now the inverse */
mp_exch (&C, c);
res = MP_OKAY;
-__ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
return res;
}
#endif
@@ -3856,13 +3862,13 @@ int mp_jacobi (mp_int * a, mp_int * p, int *c)
}
if ((res = mp_init (&p1)) != MP_OKAY) {
- goto __A1;
+ goto LBL_A1;
}
/* divide out larger power of two */
k = mp_cnt_lsb(&a1);
if ((res = mp_div_2d(&a1, k, &a1, NULL)) != MP_OKAY) {
- goto __P1;
+ goto LBL_P1;
}
/* step 4. if e is even set s=1 */
@@ -3890,18 +3896,18 @@ int mp_jacobi (mp_int * a, mp_int * p, int *c)
} else {
/* n1 = n mod a1 */
if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) {
- goto __P1;
+ goto LBL_P1;
}
if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) {
- goto __P1;
+ goto LBL_P1;
}
*c = s * r;
}
/* done */
res = MP_OKAY;
-__P1:mp_clear (&p1);
-__A1:mp_clear (&a1);
+LBL_P1:mp_clear (&p1);
+LBL_A1:mp_clear (&a1);
return res;
}
#endif
@@ -4227,20 +4233,20 @@ int mp_lcm (mp_int * a, mp_int * b, mp_int * c)
/* t1 = get the GCD of the two inputs */
if ((res = mp_gcd (a, b, &t1)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
/* divide the smallest by the GCD */
if (mp_cmp_mag(a, b) == MP_LT) {
/* store quotient in t2 such that t2 * b is the LCM */
if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
res = mp_mul(b, &t2, c);
} else {
/* store quotient in t2 such that t2 * a is the LCM */
if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
res = mp_mul(a, &t2, c);
}
@@ -4248,7 +4254,7 @@ int mp_lcm (mp_int * a, mp_int * b, mp_int * c)
/* fix the sign to positive */
c->sign = MP_ZPOS;
-__T:
+LBL_T:
mp_clear_multi (&t1, &t2, NULL);
return res;
}
@@ -4402,7 +4408,7 @@ mp_mod_2d (mp_int * a, int b, mp_int * c)
}
/* if the modulus is larger than the value than return */
- if (b > (int) (a->used * DIGIT_BIT)) {
+ if (b >= (int) (a->used * DIGIT_BIT)) {
res = mp_copy (a, c);
return res;
}
@@ -5085,11 +5091,11 @@ int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
}
if ((res = mp_init (&t2)) != MP_OKAY) {
- goto __T1;
+ goto LBL_T1;
}
if ((res = mp_init (&t3)) != MP_OKAY) {
- goto __T2;
+ goto LBL_T2;
}
/* if a is negative fudge the sign but keep track */
@@ -5102,52 +5108,52 @@ int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
do {
/* t1 = t2 */
if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
/* t3 = t1**(b-1) */
if ((res = mp_expt_d (&t1, b - 1, &t3)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* numerator */
/* t2 = t1**b */
if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* t2 = t1**b - a */
if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* denominator */
/* t3 = t1**(b-1) * b */
if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
/* t3 = (t1**b - a)/(b * t1**(b-1)) */
if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
} while (mp_cmp (&t1, &t2) != MP_EQ);
/* result can be off by a few so check */
for (;;) {
if ((res = mp_expt_d (&t1, b, &t2)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
if (mp_cmp (&t2, a) == MP_GT) {
if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
- goto __T3;
+ goto LBL_T3;
}
} else {
break;
@@ -5165,9 +5171,9 @@ int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
res = MP_OKAY;
-__T3:mp_clear (&t3);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
+LBL_T3:mp_clear (&t3);
+LBL_T2:mp_clear (&t2);
+LBL_T1:mp_clear (&t1);
return res;
}
#endif
@@ -5304,7 +5310,7 @@ int mp_prime_fermat (mp_int * a, mp_int * b, int *result)
/* compute t = b**a mod a */
if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) {
- goto __T;
+ goto LBL_T;
}
/* is it equal to b? */
@@ -5313,7 +5319,7 @@ int mp_prime_fermat (mp_int * a, mp_int * b, int *result)
}
err = MP_OKAY;
-__T:mp_clear (&t);
+LBL_T:mp_clear (&t);
return err;
}
#endif
@@ -5352,8 +5358,8 @@ int mp_prime_is_divisible (mp_int * a, int *result)
*result = MP_NO;
for (ix = 0; ix < PRIME_SIZE; ix++) {
- /* what is a mod __prime_tab[ix] */
- if ((err = mp_mod_d (a, __prime_tab[ix], &res)) != MP_OKAY) {
+ /* what is a mod LBL_prime_tab[ix] */
+ if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) {
return err;
}
@@ -5410,7 +5416,7 @@ int mp_prime_is_prime (mp_int * a, int t, int *result)
/* is the input equal to one of the primes in the table? */
for (ix = 0; ix < PRIME_SIZE; ix++) {
- if (mp_cmp_d(a, __prime_tab[ix]) == MP_EQ) {
+ if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) {
*result = 1;
return MP_OKAY;
}
@@ -5433,20 +5439,20 @@ int mp_prime_is_prime (mp_int * a, int t, int *result)
for (ix = 0; ix < t; ix++) {
/* set the prime */
- mp_set (&b, __prime_tab[ix]);
+ mp_set (&b, ltm_prime_tab[ix]);
if ((err = mp_prime_miller_rabin (a, &b, &res)) != MP_OKAY) {
- goto __B;
+ goto LBL_B;
}
if (res == MP_NO) {
- goto __B;
+ goto LBL_B;
}
}
/* passed the test */
*result = MP_YES;
-__B:mp_clear (&b);
+LBL_B:mp_clear (&b);
return err;
}
#endif
@@ -5496,12 +5502,12 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
return err;
}
if ((err = mp_sub_d (&n1, 1, &n1)) != MP_OKAY) {
- goto __N1;
+ goto LBL_N1;
}
/* set 2**s * r = n1 */
if ((err = mp_init_copy (&r, &n1)) != MP_OKAY) {
- goto __N1;
+ goto LBL_N1;
}
/* count the number of least significant bits
@@ -5511,15 +5517,15 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
/* now divide n - 1 by 2**s */
if ((err = mp_div_2d (&r, s, &r, NULL)) != MP_OKAY) {
- goto __R;
+ goto LBL_R;
}
/* compute y = b**r mod a */
if ((err = mp_init (&y)) != MP_OKAY) {
- goto __R;
+ goto LBL_R;
}
if ((err = mp_exptmod (b, &r, a, &y)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* if y != 1 and y != n1 do */
@@ -5528,12 +5534,12 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
/* while j <= s-1 and y != n1 */
while ((j <= (s - 1)) && mp_cmp (&y, &n1) != MP_EQ) {
if ((err = mp_sqrmod (&y, a, &y)) != MP_OKAY) {
- goto __Y;
+ goto LBL_Y;
}
/* if y == 1 then composite */
if (mp_cmp_d (&y, 1) == MP_EQ) {
- goto __Y;
+ goto LBL_Y;
}
++j;
@@ -5541,15 +5547,15 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
/* if y != n1 then composite */
if (mp_cmp (&y, &n1) != MP_EQ) {
- goto __Y;
+ goto LBL_Y;
}
}
/* probably prime now */
*result = MP_YES;
-__Y:mp_clear (&y);
-__R:mp_clear (&r);
-__N1:mp_clear (&n1);
+LBL_Y:mp_clear (&y);
+LBL_R:mp_clear (&r);
+LBL_N1:mp_clear (&n1);
return err;
}
#endif
@@ -5594,10 +5600,10 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
a->sign = MP_ZPOS;
/* simple algo if a is less than the largest prime in the table */
- if (mp_cmp_d(a, __prime_tab[PRIME_SIZE-1]) == MP_LT) {
+ if (mp_cmp_d(a, ltm_prime_tab[PRIME_SIZE-1]) == MP_LT) {
/* find which prime it is bigger than */
for (x = PRIME_SIZE - 2; x >= 0; x--) {
- if (mp_cmp_d(a, __prime_tab[x]) != MP_LT) {
+ if (mp_cmp_d(a, ltm_prime_tab[x]) != MP_LT) {
if (bbs_style == 1) {
/* ok we found a prime smaller or
* equal [so the next is larger]
@@ -5605,17 +5611,17 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
* however, the prime must be
* congruent to 3 mod 4
*/
- if ((__prime_tab[x + 1] & 3) != 3) {
+ if ((ltm_prime_tab[x + 1] & 3) != 3) {
/* scan upwards for a prime congruent to 3 mod 4 */
for (y = x + 1; y < PRIME_SIZE; y++) {
- if ((__prime_tab[y] & 3) == 3) {
- mp_set(a, __prime_tab[y]);
+ if ((ltm_prime_tab[y] & 3) == 3) {
+ mp_set(a, ltm_prime_tab[y]);
return MP_OKAY;
}
}
}
} else {
- mp_set(a, __prime_tab[x + 1]);
+ mp_set(a, ltm_prime_tab[x + 1]);
return MP_OKAY;
}
}
@@ -5653,7 +5659,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
/* generate the restable */
for (x = 1; x < PRIME_SIZE; x++) {
- if ((err = mp_mod_d(a, __prime_tab[x], res_tab + x)) != MP_OKAY) {
+ if ((err = mp_mod_d(a, ltm_prime_tab[x], res_tab + x)) != MP_OKAY) {
return err;
}
}
@@ -5679,8 +5685,8 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
res_tab[x] += kstep;
/* subtract the modulus [instead of using division] */
- if (res_tab[x] >= __prime_tab[x]) {
- res_tab[x] -= __prime_tab[x];
+ if (res_tab[x] >= ltm_prime_tab[x]) {
+ res_tab[x] -= ltm_prime_tab[x];
}
/* set flag if zero */
@@ -5692,7 +5698,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
/* add the step */
if ((err = mp_add_d(a, step, a)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
/* if didn't pass sieve and step == MAX then skip test */
@@ -5702,9 +5708,9 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
/* is this prime? */
for (x = 0; x < t; x++) {
- mp_set(&b, __prime_tab[t]);
+ mp_set(&b, ltm_prime_tab[t]);
if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
- goto __ERR;
+ goto LBL_ERR;
}
if (res == MP_NO) {
break;
@@ -5717,7 +5723,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
}
err = MP_OKAY;
-__ERR:
+LBL_ERR:
mp_clear(&b);
return err;
}
@@ -5828,7 +5834,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
}
/* calc the byte size */
- bsize = (size>>3)+(size&7?1:0);
+ bsize = (size>>3) + ((size&7)?1:0);
/* we need a buffer of bsize bytes */
tmp = OPT_CAST(unsigned char) XMALLOC(bsize);
@@ -5837,7 +5843,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
}
/* calc the maskAND value for the MSbyte*/
- maskAND = 0xFF >> (8 - (size & 7));
+ maskAND = ((size&7) == 0) ? 0xFF : (0xFF >> (8 - (size & 7)));
/* calc the maskOR_msb */
maskOR_msb = 0;
@@ -5846,7 +5852,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
maskOR_msb |= 1 << ((size - 2) & 7);
} else if (flags & LTM_PRIME_2MSB_OFF) {
maskAND &= ~(1 << ((size - 2) & 7));
- }
+ }
/* get the maskOR_lsb */
maskOR_lsb = 0;
@@ -7996,7 +8002,7 @@ mp_zero (mp_int * a)
*
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
*/
-const mp_digit __prime_tab[] = {
+const mp_digit ltm_prime_tab[] = {
0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
@@ -8261,10 +8267,10 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* create mu, used for Barrett reduction */
if ((err = mp_init (&mu)) != MP_OKAY) {
- goto __M;
+ goto LBL_M;
}
if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
/* create M table
@@ -8276,23 +8282,23 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
* computed though accept for M[0] and M[1]
*/
if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
/* compute the value at M[1<<(winsize-1)] by squaring
* M[1] (winsize-1) times
*/
if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
for (x = 0; x < (winsize - 1); x++) {
if ((err = mp_sqr (&M[1 << (winsize - 1)],
&M[1 << (winsize - 1)])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
if ((err = mp_reduce (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
}
@@ -8301,16 +8307,16 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
*/
for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
if ((err = mp_reduce (&M[x], P, &mu)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
}
/* setup result */
if ((err = mp_init (&res)) != MP_OKAY) {
- goto __MU;
+ goto LBL_MU;
}
mp_set (&res, 1);
@@ -8350,10 +8356,10 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* if the bit is zero and mode == 1 then we square */
if (mode == 1 && y == 0) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
continue;
}
@@ -8367,19 +8373,19 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* square first */
for (x = 0; x < winsize; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
/* then multiply */
if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
/* empty window and reset */
@@ -8394,20 +8400,20 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* square then multiply if the bit is set */
for (x = 0; x < bitcpy; x++) {
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
bitbuf <<= 1;
if ((bitbuf & (1 << winsize)) != 0) {
/* then multiply */
if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
- goto __RES;
+ goto LBL_RES;
}
}
}
@@ -8415,9 +8421,9 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
mp_exch (&res, Y);
err = MP_OKAY;
-__RES:mp_clear (&res);
-__MU:mp_clear (&mu);
-__M:
+LBL_RES:mp_clear (&res);
+LBL_MU:mp_clear (&mu);
+LBL_M:
mp_clear(&M[1]);
for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
mp_clear (&M[x]);
diff --git a/tommath.h b/tommath.h
index 896d389..7cc92c2 100644
--- a/tommath.h
+++ b/tommath.h
@@ -442,7 +442,7 @@ int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
#endif
/* table of first PRIME_SIZE primes */
-extern const mp_digit __prime_tab[];
+extern const mp_digit ltm_prime_tab[];
/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
int mp_prime_is_divisible(mp_int *a, int *result);
diff --git a/tommath.pdf b/tommath.pdf
index 18cac6f..88e2dc7 100644
Binary files a/tommath.pdf and b/tommath.pdf differ
diff --git a/tommath.tex b/tommath.tex
index d0ac947..9c4dc82 100644
--- a/tommath.tex
+++ b/tommath.tex
@@ -3420,7 +3420,7 @@ is copied to $b$, leading digits are removed and the remaining leading digit is
027 \}
028
029 /* if the modulus is larger than the value than return */
-030 if (b > (int) (a->used * DIGIT_BIT)) \{
+030 if (b >= (int) (a->used * DIGIT_BIT)) \{
031 res = mp_copy (a, c);
032 return res;
033 \}
@@ -3896,7 +3896,7 @@ and addition operations in the nested loop in parallel.
049
050 /* clear the carry */
051 _W = 0;
-052 for (ix = 0; ix <= pa; ix++) \{
+052 for (ix = 0; ix < pa; ix++) \{
053 int tx, ty;
054 int iy;
055 mp_digit *tmpx, *tmpy;
@@ -3927,27 +3927,30 @@ and addition operations in the nested loop in parallel.
079 _W = _W >> ((mp_word)DIGIT_BIT);
080 \}
081
-082 /* setup dest */
-083 olduse = c->used;
-084 c->used = digs;
-085
-086 \{
-087 register mp_digit *tmpc;
-088 tmpc = c->dp;
-089 for (ix = 0; ix < digs; ix++) \{
-090 /* now extract the previous digit [below the carry] */
-091 *tmpc++ = W[ix];
-092 \}
-093
-094 /* clear unused digits [that existed in the old copy of c] */
-095 for (; ix < olduse; ix++) \{
-096 *tmpc++ = 0;
-097 \}
-098 \}
-099 mp_clamp (c);
-100 return MP_OKAY;
-101 \}
-102 #endif
+082 /* store final carry */
+083 W[ix] = _W;
+084
+085 /* setup dest */
+086 olduse = c->used;
+087 c->used = digs;
+088
+089 \{
+090 register mp_digit *tmpc;
+091 tmpc = c->dp;
+092 for (ix = 0; ix < digs; ix++) \{
+093 /* now extract the previous digit [below the carry] */
+094 *tmpc++ = W[ix];
+095 \}
+096
+097 /* clear unused digits [that existed in the old copy of c] */
+098 for (; ix < olduse; ix++) \{
+099 *tmpc++ = 0;
+100 \}
+101 \}
+102 mp_clamp (c);
+103 return MP_OKAY;
+104 \}
+105 #endif
\end{alltt}
\end{small}
@@ -3955,7 +3958,7 @@ The memset on line @47,memset@ clears the initial $\hat W$ array to zero in a si
implementation a series of aliases (\textit{lines 62, 63 and 76}) are used to simplify the inner $O(n^2)$ loop.
In this case a new alias $\_\hat W$ has been added which refers to the double precision columns offset by $ix$ in each pass.
-The inner loop on lines 89, 79 and 80 is where the algorithm will spend the majority of the time, which is why it has been
+The inner loop on lines 92, 79 and 80 is where the algorithm will spend the majority of the time, which is why it has been
stripped to the bones of any extra baggage\footnote{Hence the pointer aliases.}. On x86 processors the multiplication and additions amount to at the
very least five instructions (\textit{two loads, two additions, one multiply}) while on the ARMv4 processors they amount to only three
(\textit{one load, one store, one multiply-add}). For both of the x86 and ARMv4 processors the GCC compiler performs a good job at unrolling the loop
@@ -5100,7 +5103,7 @@ squares in place.
059
060 /* number of output digits to produce */
061 W1 = 0;
-062 for (ix = 0; ix <= pa; ix++) \{
+062 for (ix = 0; ix < pa; ix++) \{
063 int tx, ty, iy;
064 mp_word _W;
065 mp_digit *tmpy;
@@ -6739,7 +6742,7 @@ at step 3.
019 * Based on algorithm from the paper
020 *
021 * "Generating Efficient Primes for Discrete Log Cryptosystems"
-022 * Chae Hoon Lim, Pil Loong Lee,
+022 * Chae Hoon Lim, Pil Joong Lee,
023 * POSTECH Information Research Laboratories
024 *
025 * The modulus must be of a special format [see manual]
@@ -7594,7 +7597,7 @@ algorithm since their arguments are essentially the same (\textit{two mp\_ints a
060 return err;
061 #else
062 /* no invmod */
-063 return MP_VAL
+063 return MP_VAL;
064 #endif
065 \}
066
@@ -7866,10 +7869,10 @@ a Left-to-Right algorithm is used to process the remaining few bits.
069
070 /* create mu, used for Barrett reduction */
071 if ((err = mp_init (&mu)) != MP_OKAY) \{
-072 goto __M;
+072 goto LBL_M;
073 \}
074 if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) \{
-075 goto __MU;
+075 goto LBL_MU;
076 \}
077
078 /* create M table
@@ -7881,23 +7884,23 @@ a Left-to-Right algorithm is used to process the remaining few bits.
084 * computed though accept for M[0] and M[1]
085 */
086 if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) \{
-087 goto __MU;
+087 goto LBL_MU;
088 \}
089
090 /* compute the value at M[1<<(winsize-1)] by squaring
091 * M[1] (winsize-1) times
092 */
093 if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) \{
-094 goto __MU;
+094 goto LBL_MU;
095 \}
096
097 for (x = 0; x < (winsize - 1); x++) \{
098 if ((err = mp_sqr (&M[1 << (winsize - 1)],
099 &M[1 << (winsize - 1)])) != MP_OKAY) \{
-100 goto __MU;
+100 goto LBL_MU;
101 \}
102 if ((err = mp_reduce (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) \{
-103 goto __MU;
+103 goto LBL_MU;
104 \}
105 \}
106
@@ -7906,16 +7909,16 @@ a Left-to-Right algorithm is used to process the remaining few bits.
109 */
110 for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) \{
111 if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) \{
-112 goto __MU;
+112 goto LBL_MU;
113 \}
114 if ((err = mp_reduce (&M[x], P, &mu)) != MP_OKAY) \{
-115 goto __MU;
+115 goto LBL_MU;
116 \}
117 \}
118
119 /* setup result */
120 if ((err = mp_init (&res)) != MP_OKAY) \{
-121 goto __MU;
+121 goto LBL_MU;
122 \}
123 mp_set (&res, 1);
124
@@ -7955,10 +7958,10 @@ a Left-to-Right algorithm is used to process the remaining few bits.
158 /* if the bit is zero and mode == 1 then we square */
159 if (mode == 1 && y == 0) \{
160 if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
-161 goto __RES;
+161 goto LBL_RES;
162 \}
163 if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) \{
-164 goto __RES;
+164 goto LBL_RES;
165 \}
166 continue;
167 \}
@@ -7972,19 +7975,19 @@ a Left-to-Right algorithm is used to process the remaining few bits.
175 /* square first */
176 for (x = 0; x < winsize; x++) \{
177 if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
-178 goto __RES;
+178 goto LBL_RES;
179 \}
180 if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) \{
-181 goto __RES;
+181 goto LBL_RES;
182 \}
183 \}
184
185 /* then multiply */
186 if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) \{
-187 goto __RES;
+187 goto LBL_RES;
188 \}
189 if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) \{
-190 goto __RES;
+190 goto LBL_RES;
191 \}
192
193 /* empty window and reset */
@@ -7999,20 +8002,20 @@ a Left-to-Right algorithm is used to process the remaining few bits.
202 /* square then multiply if the bit is set */
203 for (x = 0; x < bitcpy; x++) \{
204 if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
-205 goto __RES;
+205 goto LBL_RES;
206 \}
207 if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) \{
-208 goto __RES;
+208 goto LBL_RES;
209 \}
210
211 bitbuf <<= 1;
212 if ((bitbuf & (1 << winsize)) != 0) \{
213 /* then multiply */
214 if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) \{
-215 goto __RES;
+215 goto LBL_RES;
216 \}
217 if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) \{
-218 goto __RES;
+218 goto LBL_RES;
219 \}
220 \}
221 \}
@@ -8020,9 +8023,9 @@ a Left-to-Right algorithm is used to process the remaining few bits.
223
224 mp_exch (&res, Y);
225 err = MP_OKAY;
-226 __RES:mp_clear (&res);
-227 __MU:mp_clear (&mu);
-228 __M:
+226 LBL_RES:mp_clear (&res);
+227 LBL_MU:mp_clear (&mu);
+228 LBL_M:
229 mp_clear(&M[1]);
230 for (x = 1<<(winsize-1); x < (1 << winsize); x++) \{
231 mp_clear (&M[x]);
@@ -8386,23 +8389,23 @@ respectively be replaced with a zero.
048
049 mp_set(&tq, 1);
050 n = mp_count_bits(a) - mp_count_bits(b);
-051 if (((res = mp_copy(a, &ta)) != MP_OKAY) ||
-052 ((res = mp_copy(b, &tb)) != MP_OKAY) ||
+051 if (((res = mp_abs(a, &ta)) != MP_OKAY) ||
+052 ((res = mp_abs(b, &tb)) != MP_OKAY) ||
053 ((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) ||
054 ((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) \{
-055 goto __ERR;
+055 goto LBL_ERR;
056 \}
057
058 while (n-- >= 0) \{
059 if (mp_cmp(&tb, &ta) != MP_GT) \{
060 if (((res = mp_sub(&ta, &tb, &ta)) != MP_OKAY) ||
061 ((res = mp_add(&q, &tq, &q)) != MP_OKAY)) \{
-062 goto __ERR;
+062 goto LBL_ERR;
063 \}
064 \}
065 if (((res = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) ||
066 ((res = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) \{
-067 goto __ERR;
+067 goto LBL_ERR;
068 \}
069 \}
070
@@ -8411,13 +8414,13 @@ respectively be replaced with a zero.
073 n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG);
074 if (c != NULL) \{
075 mp_exch(c, &q);
-076 c->sign = n2;
+076 c->sign = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2;
077 \}
078 if (d != NULL) \{
079 mp_exch(d, &ta);
-080 d->sign = n;
+080 d->sign = (mp_iszero(d) == MP_YES) ? MP_ZPOS : n;
081 \}
-082 __ERR:
+082 LBL_ERR:
083 mp_clear_multi(&ta, &tb, &tq, &q, NULL);
084 return res;
085 \}
@@ -8466,19 +8469,19 @@ respectively be replaced with a zero.
128 q.used = a->used + 2;
129
130 if ((res = mp_init (&t1)) != MP_OKAY) \{
-131 goto __Q;
+131 goto LBL_Q;
132 \}
133
134 if ((res = mp_init (&t2)) != MP_OKAY) \{
-135 goto __T1;
+135 goto LBL_T1;
136 \}
137
138 if ((res = mp_init_copy (&x, a)) != MP_OKAY) \{
-139 goto __T2;
+139 goto LBL_T2;
140 \}
141
142 if ((res = mp_init_copy (&y, b)) != MP_OKAY) \{
-143 goto __X;
+143 goto LBL_X;
144 \}
145
146 /* fix the sign */
@@ -8490,10 +8493,10 @@ respectively be replaced with a zero.
152 if (norm < (int)(DIGIT_BIT-1)) \{
153 norm = (DIGIT_BIT-1) - norm;
154 if ((res = mp_mul_2d (&x, norm, &x)) != MP_OKAY) \{
-155 goto __Y;
+155 goto LBL_Y;
156 \}
157 if ((res = mp_mul_2d (&y, norm, &y)) != MP_OKAY) \{
-158 goto __Y;
+158 goto LBL_Y;
159 \}
160 \} else \{
161 norm = 0;
@@ -8505,13 +8508,13 @@ respectively be replaced with a zero.
167
168 /* while (x >= y*b**n-t) do \{ q[n-t] += 1; x -= y*b**\{n-t\} \} */
169 if ((res = mp_lshd (&y, n - t)) != MP_OKAY) \{ /* y = y*b**\{n-t\} */
-170 goto __Y;
+170 goto LBL_Y;
171 \}
172
173 while (mp_cmp (&x, &y) != MP_LT) \{
174 ++(q.dp[n - t]);
175 if ((res = mp_sub (&x, &y, &x)) != MP_OKAY) \{
-176 goto __Y;
+176 goto LBL_Y;
177 \}
178 \}
179
@@ -8553,7 +8556,7 @@ respectively be replaced with a zero.
215 t1.dp[1] = y.dp[t];
216 t1.used = 2;
217 if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) \{
-218 goto __Y;
+218 goto LBL_Y;
219 \}
220
221 /* find right hand */
@@ -8565,27 +8568,27 @@ respectively be replaced with a zero.
227
228 /* step 3.3 x = x - q\{i-t-1\} * y * b**\{i-t-1\} */
229 if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) \{
-230 goto __Y;
+230 goto LBL_Y;
231 \}
232
233 if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) \{
-234 goto __Y;
+234 goto LBL_Y;
235 \}
236
237 if ((res = mp_sub (&x, &t1, &x)) != MP_OKAY) \{
-238 goto __Y;
+238 goto LBL_Y;
239 \}
240
241 /* if x < 0 then \{ x = x + y*b**\{i-t-1\}; q\{i-t-1\} -= 1; \} */
242 if (x.sign == MP_NEG) \{
243 if ((res = mp_copy (&y, &t1)) != MP_OKAY) \{
-244 goto __Y;
+244 goto LBL_Y;
245 \}
246 if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) \{
-247 goto __Y;
+247 goto LBL_Y;
248 \}
249 if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) \{
-250 goto __Y;
+250 goto LBL_Y;
251 \}
252
253 q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
@@ -8612,11 +8615,11 @@ respectively be replaced with a zero.
274
275 res = MP_OKAY;
276
-277 __Y:mp_clear (&y);
-278 __X:mp_clear (&x);
-279 __T2:mp_clear (&t2);
-280 __T1:mp_clear (&t1);
-281 __Q:mp_clear (&q);
+277 LBL_Y:mp_clear (&y);
+278 LBL_X:mp_clear (&x);
+279 LBL_T2:mp_clear (&t2);
+280 LBL_T1:mp_clear (&t1);
+281 LBL_Q:mp_clear (&q);
282 return res;
283 \}
284
@@ -9130,11 +9133,11 @@ root. Ideally this algorithm is meant to find the $n$'th root of an input where
039 \}
040
041 if ((res = mp_init (&t2)) != MP_OKAY) \{
-042 goto __T1;
+042 goto LBL_T1;
043 \}
044
045 if ((res = mp_init (&t3)) != MP_OKAY) \{
-046 goto __T2;
+046 goto LBL_T2;
047 \}
048
049 /* if a is negative fudge the sign but keep track */
@@ -9147,52 +9150,52 @@ root. Ideally this algorithm is meant to find the $n$'th root of an input where
056 do \{
057 /* t1 = t2 */
058 if ((res = mp_copy (&t2, &t1)) != MP_OKAY) \{
-059 goto __T3;
+059 goto LBL_T3;
060 \}
061
062 /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
063
064 /* t3 = t1**(b-1) */
065 if ((res = mp_expt_d (&t1, b - 1, &t3)) != MP_OKAY) \{
-066 goto __T3;
+066 goto LBL_T3;
067 \}
068
069 /* numerator */
070 /* t2 = t1**b */
071 if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) \{
-072 goto __T3;
+072 goto LBL_T3;
073 \}
074
075 /* t2 = t1**b - a */
076 if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) \{
-077 goto __T3;
+077 goto LBL_T3;
078 \}
079
080 /* denominator */
081 /* t3 = t1**(b-1) * b */
082 if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) \{
-083 goto __T3;
+083 goto LBL_T3;
084 \}
085
086 /* t3 = (t1**b - a)/(b * t1**(b-1)) */
087 if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) \{
-088 goto __T3;
+088 goto LBL_T3;
089 \}
090
091 if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) \{
-092 goto __T3;
+092 goto LBL_T3;
093 \}
094 \} while (mp_cmp (&t1, &t2) != MP_EQ);
095
096 /* result can be off by a few so check */
097 for (;;) \{
098 if ((res = mp_expt_d (&t1, b, &t2)) != MP_OKAY) \{
-099 goto __T3;
+099 goto LBL_T3;
100 \}
101
102 if (mp_cmp (&t2, a) == MP_GT) \{
103 if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) \{
-104 goto __T3;
+104 goto LBL_T3;
105 \}
106 \} else \{
107 break;
@@ -9210,9 +9213,9 @@ root. Ideally this algorithm is meant to find the $n$'th root of an input where
119
120 res = MP_OKAY;
121
-122 __T3:mp_clear (&t3);
-123 __T2:mp_clear (&t2);
-124 __T1:mp_clear (&t1);
+122 LBL_T3:mp_clear (&t3);
+123 LBL_T2:mp_clear (&t2);
+124 LBL_T1:mp_clear (&t1);
125 return res;
126 \}
127 #endif
@@ -9771,7 +9774,7 @@ must be adjusted by multiplying by the common factors of two ($2^k$) removed ear
042 \}
043
044 if ((res = mp_init_copy (&v, b)) != MP_OKAY) \{
-045 goto __U;
+045 goto LBL_U;
046 \}
047
048 /* must be positive for the remainder of the algorithm */
@@ -9785,24 +9788,24 @@ must be adjusted by multiplying by the common factors of two ($2^k$) removed ear
056 if (k > 0) \{
057 /* divide the power of two out */
058 if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) \{
-059 goto __V;
+059 goto LBL_V;
060 \}
061
062 if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) \{
-063 goto __V;
+063 goto LBL_V;
064 \}
065 \}
066
067 /* divide any remaining factors of two out */
068 if (u_lsb != k) \{
069 if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) \{
-070 goto __V;
+070 goto LBL_V;
071 \}
072 \}
073
074 if (v_lsb != k) \{
075 if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) \{
-076 goto __V;
+076 goto LBL_V;
077 \}
078 \}
079
@@ -9815,23 +9818,23 @@ must be adjusted by multiplying by the common factors of two ($2^k$) removed ear
086
087 /* subtract smallest from largest */
088 if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) \{
-089 goto __V;
+089 goto LBL_V;
090 \}
091
092 /* Divide out all factors of two */
093 if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) \{
-094 goto __V;
+094 goto LBL_V;
095 \}
096 \}
097
098 /* multiply by 2**k which we divided out at the beginning */
099 if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) \{
-100 goto __V;
+100 goto LBL_V;
101 \}
102 c->sign = MP_ZPOS;
103 res = MP_OKAY;
-104 __V:mp_clear (&u);
-105 __U:mp_clear (&v);
+104 LBL_V:mp_clear (&u);
+105 LBL_U:mp_clear (&v);
106 return res;
107 \}
108 #endif
@@ -9904,20 +9907,20 @@ dividing the product of the two inputs by their greatest common divisor.
027
028 /* t1 = get the GCD of the two inputs */
029 if ((res = mp_gcd (a, b, &t1)) != MP_OKAY) \{
-030 goto __T;
+030 goto LBL_T;
031 \}
032
033 /* divide the smallest by the GCD */
034 if (mp_cmp_mag(a, b) == MP_LT) \{
035 /* store quotient in t2 such that t2 * b is the LCM */
036 if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) \{
-037 goto __T;
+037 goto LBL_T;
038 \}
039 res = mp_mul(b, &t2, c);
040 \} else \{
041 /* store quotient in t2 such that t2 * a is the LCM */
042 if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) \{
-043 goto __T;
+043 goto LBL_T;
044 \}
045 res = mp_mul(a, &t2, c);
046 \}
@@ -9925,7 +9928,7 @@ dividing the product of the two inputs by their greatest common divisor.
048 /* fix the sign to positive */
049 c->sign = MP_ZPOS;
050
-051 __T:
+051 LBL_T:
052 mp_clear_multi (&t1, &t2, NULL);
053 return res;
054 \}
@@ -10123,13 +10126,13 @@ $\left ( {p' \over a'} \right )$ which is multiplied against the current Jacobi
049 \}
050
051 if ((res = mp_init (&p1)) != MP_OKAY) \{
-052 goto __A1;
+052 goto LBL_A1;
053 \}
054
055 /* divide out larger power of two */
056 k = mp_cnt_lsb(&a1);
057 if ((res = mp_div_2d(&a1, k, &a1, NULL)) != MP_OKAY) \{
-058 goto __P1;
+058 goto LBL_P1;
059 \}
060
061 /* step 4. if e is even set s=1 */
@@ -10157,18 +10160,18 @@ $\left ( {p' \over a'} \right )$ which is multiplied against the current Jacobi
083 \} else \{
084 /* n1 = n mod a1 */
085 if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) \{
-086 goto __P1;
+086 goto LBL_P1;
087 \}
088 if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) \{
-089 goto __P1;
+089 goto LBL_P1;
090 \}
091 *c = s * r;
092 \}
093
094 /* done */
095 res = MP_OKAY;
-096 __P1:mp_clear (&p1);
-097 __A1:mp_clear (&a1);
+096 LBL_P1:mp_clear (&p1);
+097 LBL_A1:mp_clear (&a1);
098 return res;
099 \}
100 #endif
@@ -10406,8 +10409,8 @@ This algorithm attempts to determine if a candidate integer $n$ is composite by
028 *result = MP_NO;
029
030 for (ix = 0; ix < PRIME_SIZE; ix++) \{
-031 /* what is a mod __prime_tab[ix] */
-032 if ((err = mp_mod_d (a, __prime_tab[ix], &res)) != MP_OKAY) \{
+031 /* what is a mod LBL_prime_tab[ix] */
+032 if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) \{
033 return err;
034 \}
035
@@ -10431,7 +10434,7 @@ mp\_digit. The table \_\_prime\_tab is defined in the following file.
\hspace{-5.1mm}{\bf File}: bn\_prime\_tab.c
\vspace{-3mm}
\begin{alltt}
-016 const mp_digit __prime_tab[] = \{
+016 const mp_digit ltm_prime_tab[] = \{
017 0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
018 0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
019 0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
@@ -10547,7 +10550,7 @@ determine the result.
042
043 /* compute t = b**a mod a */
044 if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) \{
-045 goto __T;
+045 goto LBL_T;
046 \}
047
048 /* is it equal to b? */
@@ -10556,7 +10559,7 @@ determine the result.
051 \}
052
053 err = MP_OKAY;
-054 __T:mp_clear (&t);
+054 LBL_T:mp_clear (&t);
055 return err;
056 \}
057 #endif
@@ -10638,12 +10641,12 @@ composite then it is \textit{probably} prime.
039 return err;
040 \}
041 if ((err = mp_sub_d (&n1, 1, &n1)) != MP_OKAY) \{
-042 goto __N1;
+042 goto LBL_N1;
043 \}
044
045 /* set 2**s * r = n1 */
046 if ((err = mp_init_copy (&r, &n1)) != MP_OKAY) \{
-047 goto __N1;
+047 goto LBL_N1;
048 \}
049
050 /* count the number of least significant bits
@@ -10653,15 +10656,15 @@ composite then it is \textit{probably} prime.
054
055 /* now divide n - 1 by 2**s */
056 if ((err = mp_div_2d (&r, s, &r, NULL)) != MP_OKAY) \{
-057 goto __R;
+057 goto LBL_R;
058 \}
059
060 /* compute y = b**r mod a */
061 if ((err = mp_init (&y)) != MP_OKAY) \{
-062 goto __R;
+062 goto LBL_R;
063 \}
064 if ((err = mp_exptmod (b, &r, a, &y)) != MP_OKAY) \{
-065 goto __Y;
+065 goto LBL_Y;
066 \}
067
068 /* if y != 1 and y != n1 do */
@@ -10670,12 +10673,12 @@ composite then it is \textit{probably} prime.
071 /* while j <= s-1 and y != n1 */
072 while ((j <= (s - 1)) && mp_cmp (&y, &n1) != MP_EQ) \{
073 if ((err = mp_sqrmod (&y, a, &y)) != MP_OKAY) \{
-074 goto __Y;
+074 goto LBL_Y;
075 \}
076
077 /* if y == 1 then composite */
078 if (mp_cmp_d (&y, 1) == MP_EQ) \{
-079 goto __Y;
+079 goto LBL_Y;
080 \}
081
082 ++j;
@@ -10683,15 +10686,15 @@ composite then it is \textit{probably} prime.
084
085 /* if y != n1 then composite */
086 if (mp_cmp (&y, &n1) != MP_EQ) \{
-087 goto __Y;
+087 goto LBL_Y;
088 \}
089 \}
090
091 /* probably prime now */
092 *result = MP_YES;
-093 __Y:mp_clear (&y);
-094 __R:mp_clear (&r);
-095 __N1:mp_clear (&n1);
+093 LBL_Y:mp_clear (&y);
+094 LBL_R:mp_clear (&r);
+095 LBL_N1:mp_clear (&n1);
096 return err;
097 \}
098 #endif
diff --git a/tommath_class.h b/tommath_class.h
index 2a17d43..53bfa31 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -242,6 +242,7 @@
#define BN_MP_INIT_MULTI_C
#define BN_MP_SET_C
#define BN_MP_COUNT_BITS_C
+ #define BN_MP_ABS_C
#define BN_MP_MUL_2D_C
#define BN_MP_CMP_C
#define BN_MP_SUB_C