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
|
<pre>Internet Engineering Task Force (IETF) K. Moriarty, Ed.
Request for Comments: 8017 EMC Corporation
Obsoletes: <a href="./rfc3447">3447</a> B. Kaliski
Category: Informational Verisign
ISSN: 2070-1721 J. Jonsson
Subset AB
A. Rusch
RSA
November 2016
<span class="h1">PKCS #1: RSA Cryptography Specifications Version 2.2</span>
Abstract
This document provides recommendations for the implementation of
public-key cryptography based on the RSA algorithm, covering
cryptographic primitives, encryption schemes, signature schemes with
appendix, and ASN.1 syntax for representing keys and for identifying
the schemes.
This document represents a republication of PKCS #1 v2.2 from RSA
Laboratories' Public-Key Cryptography Standards (PKCS) series. By
publishing this RFC, change control is transferred to the IETF.
This document also obsoletes <a href="./rfc3447">RFC 3447</a>.
Status of This Memo
This document is not an Internet Standards Track specification; it is
published for informational purposes.
This document is a product of the Internet Engineering Task Force
(IETF). It represents the consensus of the IETF community. It has
received public review and has been approved for publication by the
Internet Engineering Steering Group (IESG). Not all documents
approved by the IESG are a candidate for any level of Internet
Standard; see <a href="./rfc7841#section-2">Section 2 of RFC 7841</a>.
Information about the current status of this document, any errata,
and how to provide feedback on it may be obtained at
<a href="http://www.rfc-editor.org/info/rfc8017">http://www.rfc-editor.org/info/rfc8017</a>.
<span class="grey">Moriarty, et al. Informational [Page 1]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-2" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Copyright Notice
Copyright (c) 2016 IETF Trust and the persons identified as the
document authors. All rights reserved.
This document is subject to <a href="https://www.rfc-editor.org/bcp/bcp78">BCP 78</a> and the IETF Trust's Legal
Provisions Relating to IETF Documents
(<a href="http://trustee.ietf.org/license-info">http://trustee.ietf.org/license-info</a>) in effect on the date of
publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License.
<span class="grey">Moriarty, et al. Informational [Page 2]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-3" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Table of Contents
<a href="#section-1">1</a>. Introduction . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-4">4</a>
<a href="#section-1.1">1.1</a>. Requirements Language . . . . . . . . . . . . . . . . . . <a href="#page-5">5</a>
<a href="#section-2">2</a>. Notation . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-6">6</a>
<a href="#section-3">3</a>. Key Types . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-8">8</a>
<a href="#section-3.1">3.1</a>. RSA Public Key . . . . . . . . . . . . . . . . . . . . . <a href="#page-8">8</a>
<a href="#section-3.2">3.2</a>. RSA Private Key . . . . . . . . . . . . . . . . . . . . . <a href="#page-9">9</a>
<a href="#section-4">4</a>. Data Conversion Primitives . . . . . . . . . . . . . . . . . <a href="#page-11">11</a>
<a href="#section-4.1">4.1</a>. I2OSP . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-11">11</a>
<a href="#section-4.2">4.2</a>. OS2IP . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-12">12</a>
<a href="#section-5">5</a>. Cryptographic Primitives . . . . . . . . . . . . . . . . . . <a href="#page-12">12</a>
<a href="#section-5.1">5.1</a>. Encryption and Decryption Primitives . . . . . . . . . . <a href="#page-12">12</a>
<a href="#section-5.1.1">5.1.1</a>. RSAEP . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-13">13</a>
<a href="#section-5.1.2">5.1.2</a>. RSADP . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-13">13</a>
<a href="#section-5.2">5.2</a>. Signature and Verification Primitives . . . . . . . . . . <a href="#page-15">15</a>
<a href="#section-5.2.1">5.2.1</a>. RSASP1 . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-15">15</a>
<a href="#section-5.2.2">5.2.2</a>. RSAVP1 . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-16">16</a>
<a href="#section-6">6</a>. Overview of Schemes . . . . . . . . . . . . . . . . . . . . . <a href="#page-17">17</a>
<a href="#section-7">7</a>. Encryption Schemes . . . . . . . . . . . . . . . . . . . . . <a href="#page-18">18</a>
<a href="#section-7.1">7.1</a>. RSAES-OAEP . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-19">19</a>
<a href="#section-7.1.1">7.1.1</a>. Encryption Operation . . . . . . . . . . . . . . . . <a href="#page-22">22</a>
<a href="#section-7.1.2">7.1.2</a>. Decryption Operation . . . . . . . . . . . . . . . . <a href="#page-25">25</a>
<a href="#section-7.2">7.2</a>. RSAES-PKCS1-v1_5 . . . . . . . . . . . . . . . . . . . . <a href="#page-27">27</a>
<a href="#section-7.2.1">7.2.1</a>. Encryption Operation . . . . . . . . . . . . . . . . <a href="#page-28">28</a>
<a href="#section-7.2.2">7.2.2</a>. Decryption Operation . . . . . . . . . . . . . . . . <a href="#page-29">29</a>
<a href="#section-8">8</a>. Signature Scheme with Appendix . . . . . . . . . . . . . . . <a href="#page-31">31</a>
<a href="#section-8.1">8.1</a>. RSASSA-PSS . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-32">32</a>
<a href="#section-8.1.1">8.1.1</a>. Signature Generation Operation . . . . . . . . . . . <a href="#page-33">33</a>
<a href="#section-8.1.2">8.1.2</a>. Signature Verification Operation . . . . . . . . . . <a href="#page-34">34</a>
<a href="#section-8.2">8.2</a>. RSASSA-PKCS1-v1_5 . . . . . . . . . . . . . . . . . . . . <a href="#page-35">35</a>
<a href="#section-8.2.1">8.2.1</a>. Signature Generation Operation . . . . . . . . . . . <a href="#page-36">36</a>
<a href="#section-8.2.2">8.2.2</a>. Signature Verification Operation . . . . . . . . . . <a href="#page-37">37</a>
<a href="#section-9">9</a>. Encoding Methods for Signatures with Appendix . . . . . . . . <a href="#page-39">39</a>
<a href="#section-9.1">9.1</a>. EMSA-PSS . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-40">40</a>
<a href="#section-9.1.1">9.1.1</a>. Encoding Operation . . . . . . . . . . . . . . . . . <a href="#page-42">42</a>
<a href="#section-9.1.2">9.1.2</a>. Verification Operation . . . . . . . . . . . . . . . <a href="#page-44">44</a>
<a href="#section-9.2">9.2</a>. EMSA-PKCS1-v1_5 . . . . . . . . . . . . . . . . . . . . . <a href="#page-45">45</a>
<a href="#section-10">10</a>. Security Considerations . . . . . . . . . . . . . . . . . . . <a href="#page-47">47</a>
<a href="#section-11">11</a>. References . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-48">48</a>
<a href="#section-11.1">11.1</a>. Normative References . . . . . . . . . . . . . . . . . . <a href="#page-48">48</a>
<a href="#section-11.2">11.2</a>. Informative References . . . . . . . . . . . . . . . . . <a href="#page-48">48</a>
<span class="grey">Moriarty, et al. Informational [Page 3]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-4" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<a href="#appendix-A">Appendix A</a>. ASN.1 Syntax . . . . . . . . . . . . . . . . . . . . <a href="#page-54">54</a>
<a href="#appendix-A.1">A.1</a>. RSA Key Representation . . . . . . . . . . . . . . . . . <a href="#page-54">54</a>
<a href="#appendix-A.1.1">A.1.1</a>. RSA Public Key Syntax . . . . . . . . . . . . . . . . <a href="#page-54">54</a>
<a href="#appendix-A.1.2">A.1.2</a>. RSA Private Key Syntax . . . . . . . . . . . . . . . <a href="#page-55">55</a>
<a href="#appendix-A.2">A.2</a>. Scheme Identification . . . . . . . . . . . . . . . . . . <a href="#page-57">57</a>
<a href="#appendix-A.2.1">A.2.1</a>. RSAES-OAEP . . . . . . . . . . . . . . . . . . . . . <a href="#page-57">57</a>
<a href="#appendix-A.2.2">A.2.2</a>. RSAES-PKCS-v1_5 . . . . . . . . . . . . . . . . . . . <a href="#page-60">60</a>
<a href="#appendix-A.2.3">A.2.3</a>. RSASSA-PSS . . . . . . . . . . . . . . . . . . . . . <a href="#page-60">60</a>
<a href="#appendix-A.2.4">A.2.4</a>. RSASSA-PKCS-v1_5 . . . . . . . . . . . . . . . . . . <a href="#page-62">62</a>
<a href="#appendix-B">Appendix B</a>. Supporting Techniques . . . . . . . . . . . . . . . <a href="#page-63">63</a>
<a href="#appendix-B.1">B.1</a>. Hash Functions . . . . . . . . . . . . . . . . . . . . . <a href="#page-63">63</a>
<a href="#appendix-B.2">B.2</a>. Mask Generation Functions . . . . . . . . . . . . . . . . <a href="#page-66">66</a>
<a href="#appendix-B.2.1">B.2.1</a>. MGF1 . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-67">67</a>
<a href="#appendix-C">Appendix C</a>. ASN.1 Module . . . . . . . . . . . . . . . . . . . . <a href="#page-68">68</a>
<a href="#appendix-D">Appendix D</a>. Revision History of PKCS #1 . . . . . . . . . . . . <a href="#page-76">76</a>
<a href="#appendix-E">Appendix E</a>. About PKCS . . . . . . . . . . . . . . . . . . . . . <a href="#page-77">77</a>
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-78">78</a>
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-78">78</a>
<span class="h2"><a class="selflink" id="section-1" href="#section-1">1</a>. Introduction</span>
This document provides recommendations for the implementation of
public-key cryptography based on the RSA algorithm [<a href="#ref-RSA" title=""A Method for Obtaining Digital Signatures and Public-Key Cryptosystems"">RSA</a>], covering
the following aspects:
o Cryptographic primitives
o Encryption schemes
o Signature schemes with appendix
o ASN.1 syntax for representing keys and for identifying the schemes
The recommendations are intended for general application within
computer and communications systems and as such include a fair amount
of flexibility. It is expected that application standards based on
these specifications may include additional constraints. The
recommendations are intended to be compatible with the standards IEEE
1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>], IEEE 1363a [<a href="#ref-IEEE1363A">IEEE1363A</a>], and ANSI X9.44 [<a href="#ref-ANSIX944" title=""Key Establishment Using Integer Factorization Cryptography"">ANSIX944</a>].
This document supersedes PKCS #1 version 2.1 [<a href="./rfc3447" title=""Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1"">RFC3447</a>] but includes
compatible techniques.
The organization of this document is as follows:
o <a href="#section-1">Section 1</a> is an introduction.
o <a href="#section-2">Section 2</a> defines some notation used in this document.
<span class="grey">Moriarty, et al. Informational [Page 4]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-5" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
o <a href="#section-3">Section 3</a> defines the RSA public and private key types.
o Sections <a href="#section-4">4</a> and <a href="#section-5">5</a> define several primitives, or basic mathematical
operations. Data conversion primitives are in <a href="#section-4">Section 4</a>, and
cryptographic primitives (encryption-decryption and signature-
verification) are in <a href="#section-5">Section 5</a>.
o Sections <a href="#section-6">6</a>, <a href="#section-7">7</a>, and <a href="#section-8">8</a> deal with the encryption and signature
schemes in this document. <a href="#section-6">Section 6</a> gives an overview. Along
with the methods found in PKCS #1 v1.5, <a href="#section-7">Section 7</a> defines an
encryption scheme based on Optimal Asymmetric Encryption Padding
(OAEP) [<a href="#ref-OAEP" title=""Optimal Asymmetric Encryption - How to Encrypt with RSA"">OAEP</a>], and <a href="#section-8">Section 8</a> defines a signature scheme with
appendix based on the Probabilistic Signature Scheme (PSS)
[<a href="#ref-RSARABIN" title=""The Exact Security of Digital Signatures - How to Sign with RSA and Rabin"">RSARABIN</a>] [<a href="#ref-PSS" title=""PSS: Provably Secure Encoding Method for Digital Signatures"">PSS</a>].
o <a href="#section-9">Section 9</a> defines the encoding methods for the signature schemes
in <a href="#section-8">Section 8</a>.
o <a href="#appendix-A">Appendix A</a> defines the ASN.1 syntax for the keys defined in
<a href="#section-3">Section 3</a> and the schemes in Sections <a href="#section-7">7</a> and <a href="#section-8">8</a>.
o <a href="#appendix-B">Appendix B</a> defines the hash functions and the mask generation
function (MGF) used in this document, including ASN.1 syntax for
the techniques.
o <a href="#appendix-C">Appendix C</a> gives an ASN.1 module.
o Appendices D and E outline the revision history of PKCS #1 and
provide general information about the Public-Key Cryptography
Standards.
This document represents a republication of PKCS #1 v2.2 [<a href="#ref-PKCS1_22" title=""PKCS #1: RSA Cryptography Standard Version 2.2"">PKCS1_22</a>]
from RSA Laboratories' Public-Key Cryptography Standards (PKCS)
series.
<span class="h3"><a class="selflink" id="section-1.1" href="#section-1.1">1.1</a>. Requirements Language</span>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in [<a href="./rfc2119" title=""Key words for use in RFCs to Indicate Requirement Levels"">RFC2119</a>].
<span class="grey">Moriarty, et al. Informational [Page 5]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-6" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h2"><a class="selflink" id="section-2" href="#section-2">2</a>. Notation</span>
The notation in this document includes:
c ciphertext representative, an integer between 0 and
n-1
C ciphertext, an octet string
d RSA private exponent
d_i additional factor r_i's CRT exponent,
a positive integer such that
e * d_i == 1 (mod (r_i-1)), i = 3, ..., u
dP p's CRT exponent, a positive integer such that
e * dP == 1 (mod (p-1))
dQ q's CRT exponent, a positive integer such that
e * dQ == 1 (mod (q-1))
e RSA public exponent
EM encoded message, an octet string
emBits (intended) length in bits of an encoded message EM
emLen (intended) length in octets of an encoded message
EM
GCD(. , .) greatest common divisor of two nonnegative integers
Hash hash function
hLen output length in octets of hash function Hash
k length in octets of the RSA modulus n
K RSA private key
L optional RSAES-OAEP label, an octet string
LCM(., ..., .) least common multiple of a list of nonnegative
integers
<span class="grey">Moriarty, et al. Informational [Page 6]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-7" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
m message representative, an integer between 0 and
n-1
M message, an octet string
mask MGF output, an octet string
maskLen (intended) length of the octet string mask
MGF mask generation function
mgfSeed seed from which mask is generated, an octet string
mLen length in octets of a message M
n RSA modulus, n = r_1 * r_2 * ... * r_u , u >= 2
(n, e) RSA public key
p, q first two prime factors of the RSA modulus n
qInv CRT coefficient, a positive integer less than
p such that q * qInv == 1 (mod p)
r_i prime factors of the RSA modulus n, including
r_1 = p, r_2 = q, and additional factors if any
s signature representative, an integer between 0 and
n-1
S signature, an octet string
sLen length in octets of the EMSA-PSS salt
t_i additional prime factor r_i's CRT coefficient, a
positive integer less than r_i such that
r_1 * r_2 * ... * r_(i-1) * t_i == 1 (mod r_i) ,
i = 3, ... , u
u number of prime factors of the RSA modulus, u >= 2
x a nonnegative integer
X an octet string corresponding to x
xLen (intended) length of the octet string X
<span class="grey">Moriarty, et al. Informational [Page 7]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-8" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
0x indicator of hexadecimal representation of an octet
or an octet string: "0x48" denotes the octet with
hexadecimal value 48; "(0x)48 09 0e" denotes the
string of three consecutive octets with hexadecimal
values 48, 09, and 0e, respectively
\lambda(n) LCM(r_1-1, r_2-1, ... , r_u-1)
\xor bit-wise exclusive-or of two octet strings
\ceil(.) ceiling function; \ceil(x) is the smallest integer
larger than or equal to the real number x
|| concatenation operator
== congruence symbol; a == b (mod n) means that the
integer n divides the integer a - b
Note: The Chinese Remainder Theorem (CRT) can be applied in a non-
recursive as well as a recursive way. In this document, a recursive
approach following Garner's algorithm [<a href="#ref-GARNER" title=""The Residue Number System"">GARNER</a>] is used. See also
Note 1 in <a href="#section-3.2">Section 3.2</a>.
<span class="h2"><a class="selflink" id="section-3" href="#section-3">3</a>. Key Types</span>
Two key types are employed in the primitives and schemes defined in
this document: RSA public key and RSA private key. Together, an RSA
public key and an RSA private key form an RSA key pair.
This specification supports so-called "multi-prime" RSA where the
modulus may have more than two prime factors. The benefit of multi-
prime RSA is lower computational cost for the decryption and
signature primitives, provided that the CRT is used. Better
performance can be achieved on single processor platforms, but to a
greater extent on multiprocessor platforms, where the modular
exponentiations involved can be done in parallel.
For a discussion on how multi-prime affects the security of the RSA
cryptosystem, the reader is referred to [<a href="#ref-SILVERMAN">SILVERMAN</a>].
<span class="h3"><a class="selflink" id="section-3.1" href="#section-3.1">3.1</a>. RSA Public Key</span>
For the purposes of this document, an RSA public key consists of two
components:
n the RSA modulus, a positive integer
e the RSA public exponent, a positive integer
<span class="grey">Moriarty, et al. Informational [Page 8]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-9" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
In a valid RSA public key, the RSA modulus n is a product of u
distinct odd primes r_i, i = 1, 2, ..., u, where u >= 2, and the RSA
public exponent e is an integer between 3 and n - 1 satisfying
GCD(e,\lambda(n)) = 1, where \lambda(n) = LCM(r_1 - 1, ..., r_u - 1).
By convention, the first two primes r_1 and r_2 may also be denoted p
and q, respectively.
A recommended syntax for interchanging RSA public keys between
implementations is given in <a href="#appendix-A.1.1">Appendix A.1.1</a>; an implementation's
internal representation may differ.
<span class="h3"><a class="selflink" id="section-3.2" href="#section-3.2">3.2</a>. RSA Private Key</span>
For the purposes of this document, an RSA private key may have either
of two representations.
1. The first representation consists of the pair (n, d), where the
components have the following meanings:
n the RSA modulus, a positive integer
d the RSA private exponent, a positive integer
2. The second representation consists of a quintuple (p, q, dP, dQ,
qInv) and a (possibly empty) sequence of triplets (r_i, d_i,
t_i), i = 3, ..., u, one for each prime not in the quintuple,
where the components have the following meanings:
p the first factor, a positive integer
q the second factor, a positive integer
dP the first factor's CRT exponent, a positive integer
dQ the second factor's CRT exponent, a positive integer
qInv the (first) CRT coefficient, a positive integer
r_i the i-th factor, a positive integer
d_i the i-th factor's CRT exponent, a positive integer
t_i the i-th factor's CRT coefficient, a positive integer
In a valid RSA private key with the first representation, the RSA
modulus n is the same as in the corresponding RSA public key and is
the product of u distinct odd primes r_i, i = 1, 2, ..., u, where u
>= 2. The RSA private exponent d is a positive integer less than n
satisfying
e * d == 1 (mod \lambda(n)),
where e is the corresponding RSA public exponent and \lambda(n) is
defined as in <a href="#section-3.1">Section 3.1</a>.
<span class="grey">Moriarty, et al. Informational [Page 9]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-10" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
In a valid RSA private key with the second representation, the two
factors p and q are the first two prime factors of the RSA modulus n
(i.e., r_1 and r_2); the CRT exponents dP and dQ are positive
integers less than p and q, respectively, satisfying
e * dP == 1 (mod (p-1))
e * dQ == 1 (mod (q-1)) ,
and the CRT coefficient qInv is a positive integer less than p
satisfying
q * qInv == 1 (mod p).
If u > 2, the representation will include one or more triplets (r_i,
d_i, t_i), i = 3, ..., u. The factors r_i are the additional prime
factors of the RSA modulus n. Each CRT exponent d_i (i = 3, ..., u)
satisfies
e * d_i == 1 (mod (r_i - 1)).
Each CRT coefficient t_i (i = 3, ..., u) is a positive integer less
than r_i satisfying
R_i * t_i == 1 (mod r_i) ,
where R_i = r_1 * r_2 * ... * r_(i-1).
A recommended syntax for interchanging RSA private keys between
implementations, which includes components from both representations,
is given in <a href="#appendix-A.1.2">Appendix A.1.2</a>; an implementation's internal
representation may differ.
Notes:
1. The definition of the CRT coefficients here and the formulas that
use them in the primitives in <a href="#section-5">Section 5</a> generally follow Garner's
algorithm [<a href="#ref-GARNER" title=""The Residue Number System"">GARNER</a>] (see also Algorithm 14.71 in [<a href="#ref-HANDBOOK" title=""Handbook of Applied Cryptography"">HANDBOOK</a>]).
However, for compatibility with the representations of RSA
private keys in PKCS #1 v2.0 and previous versions, the roles of
p and q are reversed compared to the rest of the primes. Thus,
the first CRT coefficient, qInv, is defined as the inverse of q
mod p, rather than as the inverse of R_1 mod r_2, i.e., of
p mod q.
2. Quisquater and Couvreur [<a href="#ref-FASTDEC" title=""Fast Decipherment Algorithm for RSA Public-Key Cryptosystem"">FASTDEC</a>] observed the benefit of
applying the CRT to RSA operations.
<span class="grey">Moriarty, et al. Informational [Page 10]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-11" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h2"><a class="selflink" id="section-4" href="#section-4">4</a>. Data Conversion Primitives</span>
Two data conversion primitives are employed in the schemes defined in
this document:
o I2OSP - Integer-to-Octet-String primitive
o OS2IP - Octet-String-to-Integer primitive
For the purposes of this document, and consistent with ASN.1 syntax,
an octet string is an ordered sequence of octets (eight-bit bytes).
The sequence is indexed from first (conventionally, leftmost) to last
(rightmost). For purposes of conversion to and from integers, the
first octet is considered the most significant in the following
conversion primitives.
<span class="h3"><a class="selflink" id="section-4.1" href="#section-4.1">4.1</a>. I2OSP</span>
I2OSP converts a nonnegative integer to an octet string of a
specified length.
I2OSP (x, xLen)
Input:
x nonnegative integer to be converted
xLen intended length of the resulting octet string
Output:
X corresponding octet string of length xLen
Error: "integer too large"
Steps:
1. If x >= 256^xLen, output "integer too large" and stop.
2. Write the integer x in its unique xLen-digit representation in
base 256:
x = x_(xLen-1) 256^(xLen-1) + x_(xLen-2) 256^(xLen-2) + ...
+ x_1 256 + x_0,
where 0 <= x_i < 256 (note that one or more leading digits
will be zero if x is less than 256^(xLen-1)).
<span class="grey">Moriarty, et al. Informational [Page 11]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-12" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
3. Let the octet X_i have the integer value x_(xLen-i) for 1 <= i
<= xLen. Output the octet string
X = X_1 X_2 ... X_xLen.
<span class="h3"><a class="selflink" id="section-4.2" href="#section-4.2">4.2</a>. OS2IP</span>
OS2IP converts an octet string to a nonnegative integer.
OS2IP (X)
Input: X octet string to be converted
Output: x corresponding nonnegative integer
Steps:
1. Let X_1 X_2 ... X_xLen be the octets of X from first to last,
and let x_(xLen-i) be the integer value of the octet X_i for 1
<= i <= xLen.
2. Let x = x_(xLen-1) 256^(xLen-1) + x_(xLen-2) 256^(xLen-2) +
... + x_1 256 + x_0.
3. Output x.
<span class="h2"><a class="selflink" id="section-5" href="#section-5">5</a>. Cryptographic Primitives</span>
Cryptographic primitives are basic mathematical operations on which
cryptographic schemes can be built. They are intended for
implementation in hardware or as software modules and are not
intended to provide security apart from a scheme.
Four types of primitive are specified in this document, organized in
pairs: encryption and decryption; and signature and verification.
The specifications of the primitives assume that certain conditions
are met by the inputs, in particular that RSA public and private keys
are valid.
<span class="h3"><a class="selflink" id="section-5.1" href="#section-5.1">5.1</a>. Encryption and Decryption Primitives</span>
An encryption primitive produces a ciphertext representative from a
message representative under the control of a public key, and a
decryption primitive recovers the message representative from the
ciphertext representative under the control of the corresponding
private key.
<span class="grey">Moriarty, et al. Informational [Page 12]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-13" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
One pair of encryption and decryption primitives is employed in the
encryption schemes defined in this document and is specified here:
RSA Encryption Primitive (RSAEP) / RSA Decryption Primitive (RSADP).
RSAEP and RSADP involve the same mathematical operation, with
different keys as input. The primitives defined here are the same as
Integer Factorization Encryption Primitive using RSA (IFEP-RSA) /
Integer Factorization Decryption Primitive using RSA (IFDP-RSA) in
IEEE 1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>] (except that support for multi-prime RSA has
been added) and are compatible with PKCS #1 v1.5.
The main mathematical operation in each primitive is exponentiation.
<span class="h4"><a class="selflink" id="section-5.1.1" href="#section-5.1.1">5.1.1</a>. RSAEP</span>
RSAEP ((n, e), m)
Input:
(n, e) RSA public key
m message representative, an integer between 0 and n - 1
Output: c ciphertext representative, an integer between 0 and n - 1
Error: "message representative out of range"
Assumption: RSA public key (n, e) is valid
Steps:
1. If the message representative m is not between 0 and n - 1,
output "message representative out of range" and stop.
2. Let c = m^e mod n.
3. Output c.
<span class="h4"><a class="selflink" id="section-5.1.2" href="#section-5.1.2">5.1.2</a>. RSADP</span>
RSADP (K, c)
Input:
K RSA private key, where K has one of the following forms:
+ a pair (n, d)
<span class="grey">Moriarty, et al. Informational [Page 13]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-14" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
+ a quintuple (p, q, dP, dQ, qInv) and a possibly empty
sequence of triplets (r_i, d_i, t_i), i = 3, ..., u
c ciphertext representative, an integer between 0 and n - 1
Output: m message representative, an integer between 0 and n - 1
Error: "ciphertext representative out of range"
Assumption: RSA private key K is valid
Steps:
1. If the ciphertext representative c is not between 0 and n - 1,
output "ciphertext representative out of range" and stop.
2. The message representative m is computed as follows.
a. If the first form (n, d) of K is used, let m = c^d mod n.
b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i,
t_i) of K is used, proceed as follows:
i. Let m_1 = c^dP mod p and m_2 = c^dQ mod q.
ii. If u > 2, let m_i = c^(d_i) mod r_i, i = 3, ..., u.
iii. Let h = (m_1 - m_2) * qInv mod p.
iv. Let m = m_2 + q * h.
v. If u > 2, let R = r_1 and for i = 3 to u do
1. Let R = R * r_(i-1).
2. Let h = (m_i - m) * t_i mod r_i.
3. Let m = m + R * h.
3. Output m.
Note: Step 2.b can be rewritten as a single loop, provided that one
reverses the order of p and q. For consistency with PKCS #1 v2.0,
however, the first two primes p and q are treated separately from the
additional primes.
<span class="grey">Moriarty, et al. Informational [Page 14]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-15" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h3"><a class="selflink" id="section-5.2" href="#section-5.2">5.2</a>. Signature and Verification Primitives</span>
A signature primitive produces a signature representative from a
message representative under the control of a private key, and a
verification primitive recovers the message representative from the
signature representative under the control of the corresponding
public key. One pair of signature and verification primitives is
employed in the signature schemes defined in this document and is
specified here: RSA Signature Primitive, version 1 (RSASP1) / RSA
Verification Primitive, version 1 (RSAVP1).
The primitives defined here are the same as Integer Factorization
Signature Primitive using RSA, version 1 (IFSP-RSA1) / Integer
Factorization Verification Primitive using RSA, version 1 (IFVP-RSA1)
in IEEE 1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>] (except that support for multi-prime RSA has
been added) and are compatible with PKCS #1 v1.5.
The main mathematical operation in each primitive is exponentiation,
as in the encryption and decryption primitives of <a href="#section-5.1">Section 5.1</a>.
RSASP1 and RSAVP1 are the same as RSADP and RSAEP except for the
names of their input and output arguments; they are distinguished as
they are intended for different purposes.
<span class="h4"><a class="selflink" id="section-5.2.1" href="#section-5.2.1">5.2.1</a>. RSASP1</span>
RSASP1 (K, m)
Input:
K RSA private key, where K has one of the following forms:
- a pair (n, d)
- a quintuple (p, q, dP, dQ, qInv) and a (possibly empty)
sequence of triplets (r_i, d_i, t_i), i = 3, ..., u
m message representative, an integer between 0 and n - 1
Output:
s signature representative, an integer between 0 and n - 1
Error: "message representative out of range"
Assumption: RSA private key K is valid
<span class="grey">Moriarty, et al. Informational [Page 15]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-16" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Steps:
1. If the message representative m is not between 0 and n - 1,
output "message representative out of range" and stop.
2. The signature representative s is computed as follows.
a. If the first form (n, d) of K is used, let s = m^d mod n.
b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i,
t_i) of K is used, proceed as follows:
1. Let s_1 = m^dP mod p and s_2 = m^dQ mod q.
2. If u > 2, let s_i = m^(d_i) mod r_i, i = 3, ..., u.
3. Let h = (s_1 - s_2) * qInv mod p.
4. Let s = s_2 + q * h.
5. If u > 2, let R = r_1 and for i = 3 to u do
a. Let R = R * r_(i-1).
b. Let h = (s_i - s) * t_i mod r_i.
c. Let s = s + R * h.
3. Output s.
Note: Step 2.b can be rewritten as a single loop, provided that one
reverses the order of p and q. For consistency with PKCS #1 v2.0,
however, the first two primes p and q are treated separately from the
additional primes.
<span class="h4"><a class="selflink" id="section-5.2.2" href="#section-5.2.2">5.2.2</a>. RSAVP1</span>
RSAVP1 ((n, e), s)
Input:
(n, e) RSA public key
s signature representative, an integer between 0 and n - 1
<span class="grey">Moriarty, et al. Informational [Page 16]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-17" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Output:
m message representative, an integer between 0 and n - 1
Error: "signature representative out of range"
Assumption: RSA public key (n, e) is valid
Steps:
1. If the signature representative s is not between 0 and n - 1,
output "signature representative out of range" and stop.
2. Let m = s^e mod n.
3. Output m.
<span class="h2"><a class="selflink" id="section-6" href="#section-6">6</a>. Overview of Schemes</span>
A scheme combines cryptographic primitives and other techniques to
achieve a particular security goal. Two types of scheme are
specified in this document: encryption schemes and signature schemes
with appendix.
The schemes specified in this document are limited in scope in that
their operations consist only of steps to process data with an RSA
public or private key, and they do not include steps for obtaining or
validating the key. Thus, in addition to the scheme operations, an
application will typically include key management operations by which
parties may select RSA public and private keys for a scheme
operation. The specific additional operations and other details are
outside the scope of this document.
As was the case for the cryptographic primitives (<a href="#section-5">Section 5</a>), the
specifications of scheme operations assume that certain conditions
are met by the inputs, in particular that RSA public and private keys
are valid. The behavior of an implementation is thus unspecified
when a key is invalid. The impact of such unspecified behavior
depends on the application. Possible means of addressing key
validation include explicit key validation by the application; key
validation within the public-key infrastructure; and assignment of
liability for operations performed with an invalid key to the party
who generated the key.
A generally good cryptographic practice is to employ a given RSA key
pair in only one scheme. This avoids the risk that vulnerability in
one scheme may compromise the security of the other and may be
essential to maintain provable security. While RSAES-PKCS1-v1_5
<span class="grey">Moriarty, et al. Informational [Page 17]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-18" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
(<a href="#section-7.2">Section 7.2</a>) and RSASSA-PKCS1-v1_5 (<a href="#section-8.2">Section 8.2</a>) have traditionally
been employed together without any known bad interactions (indeed,
this is the model introduced by PKCS #1 v1.5), such a combined use of
an RSA key pair is NOT RECOMMENDED for new applications.
To illustrate the risks related to the employment of an RSA key pair
in more than one scheme, suppose an RSA key pair is employed in both
RSAES-OAEP (<a href="#section-7.1">Section 7.1</a>) and RSAES-PKCS1-v1_5. Although RSAES-OAEP
by itself would resist attack, an opponent might be able to exploit a
weakness in the implementation of RSAES-PKCS1-v1_5 to recover
messages encrypted with either scheme. As another example, suppose
an RSA key pair is employed in both RSASSA-PSS (<a href="#section-8.1">Section 8.1</a>) and
RSASSA-PKCS1-v1_5. Then the security proof for RSASSA-PSS would no
longer be sufficient since the proof does not account for the
possibility that signatures might be generated with a second scheme.
Similar considerations may apply if an RSA key pair is employed in
one of the schemes defined here and in a variant defined elsewhere.
<span class="h2"><a class="selflink" id="section-7" href="#section-7">7</a>. Encryption Schemes</span>
For the purposes of this document, an encryption scheme consists of
an encryption operation and a decryption operation, where the
encryption operation produces a ciphertext from a message with a
recipient's RSA public key, and the decryption operation recovers the
message from the ciphertext with the recipient's corresponding RSA
private key.
An encryption scheme can be employed in a variety of applications. A
typical application is a key establishment protocol, where the
message contains key material to be delivered confidentially from one
party to another. For instance, PKCS #7 [<a href="./rfc2315" title=""PKCS #7: Cryptographic Message Syntax Version 1.5"">RFC2315</a>] employs such a
protocol to deliver a content-encryption key from a sender to a
recipient; the encryption schemes defined here would be suitable key-
encryption algorithms in that context.
Two encryption schemes are specified in this document: RSAES-OAEP and
RSAES-PKCS1-v1_5. RSAES-OAEP is REQUIRED to be supported for new
applications; RSAES-PKCS1-v1_5 is included only for compatibility
with existing applications.
The encryption schemes given here follow a general model similar to
that employed in IEEE 1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>], combining encryption and
decryption primitives with an encoding method for encryption. The
encryption operations apply a message encoding operation to a message
to produce an encoded message, which is then converted to an integer
message representative. An encryption primitive is applied to the
message representative to produce the ciphertext. Reversing this,
the decryption operations apply a decryption primitive to the
<span class="grey">Moriarty, et al. Informational [Page 18]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-19" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
ciphertext to recover a message representative, which is then
converted to an octet-string-encoded message. A message decoding
operation is applied to the encoded message to recover the message
and verify the correctness of the decryption.
To avoid implementation weaknesses related to the way errors are
handled within the decoding operation (see [<a href="#ref-BLEICHENBACHER">BLEICHENBACHER</a>] and
[<a href="#ref-MANGER" title=""A Chosen Ciphertext Attack on RSA Optimal Asymmetric Encryption Padding (OAEP) as Standardized in PKCS #1 v2.0"">MANGER</a>]), the encoding and decoding operations for RSAES-OAEP and
RSAES-PKCS1-v1_5 are embedded in the specifications of the respective
encryption schemes rather than defined in separate specifications.
Both encryption schemes are compatible with the corresponding schemes
in PKCS #1 v2.1.
<span class="h3"><a class="selflink" id="section-7.1" href="#section-7.1">7.1</a>. RSAES-OAEP</span>
RSAES-OAEP combines the RSAEP and RSADP primitives (Sections <a href="#section-5.1.1">5.1.1</a>
and 5.1.2) with the EME-OAEP encoding method (Step 2 in
<a href="#section-7.1.1">Section 7.1.1</a>, and Step 3 in <a href="#section-7.1.2">Section 7.1.2</a>). EME-OAEP is based on
Bellare and Rogaway's Optimal Asymmetric Encryption scheme [<a href="#ref-OAEP" title=""Optimal Asymmetric Encryption - How to Encrypt with RSA"">OAEP</a>].
It is compatible with the Integer Factorization Encryption Scheme
(IFES) defined in IEEE 1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>], where the encryption and
decryption primitives are IFEP-RSA and IFDP-RSA and the message
encoding method is EME-OAEP. RSAES-OAEP can operate on messages of
length up to k - 2hLen -2 octets, where hLen is the length of the
output from the underlying hash function and k is the length in
octets of the recipient's RSA modulus.
Assuming that computing e-th roots modulo n is infeasible and the
mask generation function in RSAES-OAEP has appropriate properties,
RSAES-OAEP is semantically secure against adaptive chosen-ciphertext
attacks. This assurance is provable in the sense that the difficulty
of breaking RSAES-OAEP can be directly related to the difficulty of
inverting the RSA function, provided that the mask generation
function is viewed as a black box or random oracle; see [<a href="#ref-FOPS" title=""RSA-OAEP is Secure under the RSA Assumption"">FOPS</a>] and
the note below for further discussion.
Both the encryption and the decryption operations of RSAES-OAEP take
the value of a label L as input. In this version of PKCS #1, L is
the empty string; other uses of the label are outside the scope of
this document. See <a href="#appendix-A.2.1">Appendix A.2.1</a> for the relevant ASN.1 syntax.
RSAES-OAEP is parameterized by the choice of hash function and mask
generation function. This choice should be fixed for a given RSA
key. Suggested hash and mask generation functions are given in
<a href="#appendix-B">Appendix B</a>.
<span class="grey">Moriarty, et al. Informational [Page 19]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-20" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Note: Past results have helpfully clarified the security properties
of the OAEP encoding method [<a href="#ref-OAEP" title=""Optimal Asymmetric Encryption - How to Encrypt with RSA"">OAEP</a>] (roughly the procedure described
in Step 2 in <a href="#section-7.1.1">Section 7.1.1</a>). The background is as follows. In 1994,
Bellare and Rogaway [<a href="#ref-OAEP" title=""Optimal Asymmetric Encryption - How to Encrypt with RSA"">OAEP</a>] introduced a security concept that they
denoted plaintext awareness (PA94). They proved that if a
deterministic public-key encryption primitive (e.g., RSAEP) is hard
to invert without the private key, then the corresponding OAEP-based
encryption scheme is plaintext aware (in the random oracle model),
meaning roughly that an adversary cannot produce a valid ciphertext
without actually "knowing" the underlying plaintext. Plaintext
awareness of an encryption scheme is closely related to the
resistance of the scheme against chosen-ciphertext attacks. In such
attacks, an adversary is given the opportunity to send queries to an
oracle simulating the decryption primitive. Using the results of
these queries, the adversary attempts to decrypt a challenge
ciphertext.
However, there are two flavors of chosen-ciphertext attacks, and PA94
implies security against only one of them. The difference relies on
what the adversary is allowed to do after she is given the challenge
ciphertext. The indifferent attack scenario (denoted CCA1) does not
admit any queries to the decryption oracle after the adversary is
given the challenge ciphertext, whereas the adaptive scenario
(denoted CCA2) does (except that the decryption oracle refuses to
decrypt the challenge ciphertext once it is published). In 1998,
Bellare and Rogaway, together with Desai and Pointcheval [<a href="#ref-PA98" title=""Relations Among Notions of Security for Public-Key Encryption Schemes"">PA98</a>], came
up with a new, stronger notion of plaintext awareness (PA98) that
does imply security against CCA2.
To summarize, there have been two potential sources for
misconception: that PA94 and PA98 are equivalent concepts, or that
CCA1 and CCA2 are equivalent concepts. Either assumption leads to
the conclusion that the Bellare-Rogaway paper implies security of
OAEP against CCA2, which it does not.
(Footnote: It might be fair to mention that PKCS #1 v2.0 cites [<a href="#ref-OAEP" title=""Optimal Asymmetric Encryption - How to Encrypt with RSA"">OAEP</a>]
and claims that "a chosen ciphertext attack is ineffective against a
plaintext-aware encryption scheme such as RSAES-OAEP" without
specifying the kind of plaintext awareness or chosen ciphertext
attack considered.)
OAEP has never been proven secure against CCA2; in fact, Victor Shoup
[<a href="#ref-SHOUP" title=""OAEP Reconsidered (Extended Abstract)"">SHOUP</a>] has demonstrated that such a proof does not exist in the
general case. Put briefly, Shoup showed that an adversary in the
CCA2 scenario who knows how to partially invert the encryption
primitive but does not know how to invert it completely may well be
able to break the scheme. For example, one may imagine an attacker
who is able to break RSAES-OAEP if she knows how to recover all but
<span class="grey">Moriarty, et al. Informational [Page 20]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-21" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
the first 20 bytes of a random integer encrypted with RSAEP. Such an
attacker does not need to be able to fully invert RSAEP, because she
does not use the first 20 octets in her attack.
Still, RSAES-OAEP is secure against CCA2, which was proved by
Fujisaki, Okamoto, Pointcheval, and Stern [<a href="#ref-FOPS" title=""RSA-OAEP is Secure under the RSA Assumption"">FOPS</a>] shortly after the
announcement of Shoup's result. Using clever lattice reduction
techniques, they managed to show how to invert RSAEP completely given
a sufficiently large part of the pre-image. This observation,
combined with a proof that OAEP is secure against CCA2 if the
underlying encryption primitive is hard to partially invert, fills
the gap between what Bellare and Rogaway proved about RSAES-OAEP and
what some may have believed that they proved. Somewhat
paradoxically, we are hence saved by an ostensible weakness in RSAEP
(i.e., the whole inverse can be deduced from parts of it).
Unfortunately, however, the security reduction is not efficient for
concrete parameters. While the proof successfully relates an
adversary A against the CCA2 security of RSAES-OAEP to an algorithm I
inverting RSA, the probability of success for I is only approximately
\epsilon^2 / 2^18, where \epsilon is the probability of success for
A.
(Footnote: In [<a href="#ref-FOPS" title=""RSA-OAEP is Secure under the RSA Assumption"">FOPS</a>], the probability of success for the inverter was
\epsilon^2 / 4. The additional factor 1 / 2^16 is due to the eight
fixed zero bits at the beginning of the encoded message EM, which are
not present in the variant of OAEP considered in [<a href="#ref-FOPS" title=""RSA-OAEP is Secure under the RSA Assumption"">FOPS</a>]. (A must be
applied twice to invert RSA, and each application corresponds to a
factor 1 / 2^8.))
In addition, the running time for I is approximately t^2, where t is
the running time of the adversary. The consequence is that we cannot
exclude the possibility that attacking RSAES-OAEP is considerably
easier than inverting RSA for concrete parameters. Still, the
existence of a security proof provides some assurance that the
RSAES-OAEP construction is sounder than ad hoc constructions such as
RSAES-PKCS1-v1_5.
Hybrid encryption schemes based on the RSA Key Encapsulation
Mechanism (RSA-KEM) paradigm offer tight proofs of security directly
applicable to concrete parameters; see [<a href="#ref-ISO18033" title=""Information technology -- Security techniques -- Encryption algorithms - Part 2: Asymmetric ciphers"">ISO18033</a>] for discussion.
Future versions of PKCS #1 may specify schemes based on this
paradigm.
<span class="grey">Moriarty, et al. Informational [Page 21]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-22" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h4"><a class="selflink" id="section-7.1.1" href="#section-7.1.1">7.1.1</a>. Encryption Operation</span>
RSAES-OAEP-ENCRYPT ((n, e), M, L)
Options:
Hash hash function (hLen denotes the length in octets of
the hash function output)
MGF mask generation function
Input:
(n, e) recipient's RSA public key (k denotes the length in
octets of the RSA modulus n)
M message to be encrypted, an octet string of length mLen,
where mLen <= k - 2hLen - 2
L optional label to be associated with the message; the
default value for L, if L is not provided, is the empty
string
Output:
C ciphertext, an octet string of length k
Errors: "message too long"; "label too long"
Assumption: RSA public key (n, e) is valid
Steps:
1. Length checking:
a. If the length of L is greater than the input limitation
for the hash function (2^61 - 1 octets for SHA-1), output
"label too long" and stop.
b. If mLen > k - 2hLen - 2, output "message too long" and
stop.
2. EME-OAEP encoding (see Figure 1 below):
a. If the label L is not provided, let L be the empty string.
Let lHash = Hash(L), an octet string of length hLen (see
the note below).
b. Generate a padding string PS consisting of k - mLen -
2hLen - 2 zero octets. The length of PS may be zero.
<span class="grey">Moriarty, et al. Informational [Page 22]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-23" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
c. Concatenate lHash, PS, a single octet with hexadecimal
value 0x01, and the message M to form a data block DB of
length k - hLen - 1 octets as
DB = lHash || PS || 0x01 || M.
d. Generate a random octet string seed of length hLen.
e. Let dbMask = MGF(seed, k - hLen - 1).
f. Let maskedDB = DB \xor dbMask.
g. Let seedMask = MGF(maskedDB, hLen).
h. Let maskedSeed = seed \xor seedMask.
i. Concatenate a single octet with hexadecimal value 0x00,
maskedSeed, and maskedDB to form an encoded message EM of
length k octets as
EM = 0x00 || maskedSeed || maskedDB.
3. RSA encryption:
a. Convert the encoded message EM to an integer message
representative m (see <a href="#section-4.2">Section 4.2</a>):
m = OS2IP (EM).
b. Apply the RSAEP encryption primitive (<a href="#section-5.1.1">Section 5.1.1</a>) to
the RSA public key (n, e) and the message representative m
to produce an integer ciphertext representative c:
c = RSAEP ((n, e), m).
c. Convert the ciphertext representative c to a ciphertext C
of length k octets (see <a href="#section-4.1">Section 4.1</a>):
C = I2OSP (c, k).
<span class="grey">Moriarty, et al. Informational [Page 23]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-24" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
4. Output the ciphertext C.
_________________________________________________________________
+----------+------+--+-------+
DB = | lHash | PS |01| M |
+----------+------+--+-------+
|
+----------+ |
| seed | |
+----------+ |
| |
|-------> MGF ---> xor
| |
+--+ V |
|00| xor <----- MGF <-----|
+--+ | |
| | |
V V V
+--+----------+----------------------------+
EM = |00|maskedSeed| maskedDB |
+--+----------+----------------------------+
_________________________________________________________________
Figure 1: EME-OAEP Encoding Operation
Notes:
- lHash is the hash of the optional label L.
- The decoding operation follows reverse steps to recover M and
verify lHash and PS.
- If L is the empty string, the corresponding hash value lHash has
the following hexadecimal representation for different choices of
Hash:
SHA-1: (0x)da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709
SHA-256: (0x)e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c
a495991b 7852b855
SHA-384: (0x)38b060a7 51ac9638 4cd9327e b1b1e36a 21fdb711 14be0743
4c0cc7bf 63f6e1da 274edebf e76f65fb d51ad2f1 4898b95b
SHA-512: (0x)cf83e135 7eefb8bd f1542850 d66d8007 d620e405 0b5715dc
83f4a921 d36ce9ce 47d0d13c 5d85f2b0 ff8318d2 877eec2f
63b931bd 47417a81 a538327a f927da3e
<span class="grey">Moriarty, et al. Informational [Page 24]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-25" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h4"><a class="selflink" id="section-7.1.2" href="#section-7.1.2">7.1.2</a>. Decryption Operation</span>
RSAES-OAEP-DECRYPT (K, C, L)
Options:
Hash hash function (hLen denotes the length in octets of
the hash function output)
MGF mask generation function
Input:
K recipient's RSA private key (k denotes the length in
octets of the RSA modulus n), where k >= 2hLen + 2
C ciphertext to be decrypted, an octet string of length k
L optional label whose association with the message is to
be verified; the default value for L, if L is not
provided, is the empty string
Output:
M message, an octet string of length mLen, where
mLen <= k - 2hLen - 2
Error: "decryption error"
Steps:
1. Length checking:
a. If the length of L is greater than the input limitation
for the hash function (2^61 - 1 octets for SHA-1), output
"decryption error" and stop.
b. If the length of the ciphertext C is not k octets, output
"decryption error" and stop.
c. If k < 2hLen + 2, output "decryption error" and stop.
2. RSA decryption:
a. Convert the ciphertext C to an integer ciphertext
representative c (see <a href="#section-4.2">Section 4.2</a>):
c = OS2IP (C).
<span class="grey">Moriarty, et al. Informational [Page 25]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-26" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
b. Apply the RSADP decryption primitive (<a href="#section-5.1.2">Section 5.1.2</a>) to
the RSA private key K and the ciphertext representative c
to produce an integer message representative m:
m = RSADP (K, c).
If RSADP outputs "ciphertext representative out of range"
(meaning that c >= n), output "decryption error" and stop.
c. Convert the message representative m to an encoded message
EM of length k octets (see <a href="#section-4.1">Section 4.1</a>):
EM = I2OSP (m, k).
3. EME-OAEP decoding:
a. If the label L is not provided, let L be the empty string.
Let lHash = Hash(L), an octet string of length hLen (see
the note in <a href="#section-7.1.1">Section 7.1.1</a>).
b. Separate the encoded message EM into a single octet Y, an
octet string maskedSeed of length hLen, and an octet
string maskedDB of length k - hLen - 1 as
EM = Y || maskedSeed || maskedDB.
c. Let seedMask = MGF(maskedDB, hLen).
d. Let seed = maskedSeed \xor seedMask.
e. Let dbMask = MGF(seed, k - hLen - 1).
f. Let DB = maskedDB \xor dbMask.
g. Separate DB into an octet string lHash' of length hLen, a
(possibly empty) padding string PS consisting of octets
with hexadecimal value 0x00, and a message M as
DB = lHash' || PS || 0x01 || M.
If there is no octet with hexadecimal value 0x01 to
separate PS from M, if lHash does not equal lHash', or if
Y is nonzero, output "decryption error" and stop. (See
the note below.)
<span class="grey">Moriarty, et al. Informational [Page 26]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-27" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
4. Output the message M.
Note: Care must be taken to ensure that an opponent cannot
distinguish the different error conditions in Step 3.g, whether by
error message or timing, and, more generally, that an opponent
cannot learn partial information about the encoded message EM.
Otherwise, an opponent may be able to obtain useful information
about the decryption of the ciphertext C, leading to a chosen-
ciphertext attack such as the one observed by Manger [<a href="#ref-MANGER" title=""A Chosen Ciphertext Attack on RSA Optimal Asymmetric Encryption Padding (OAEP) as Standardized in PKCS #1 v2.0"">MANGER</a>].
<span class="h3"><a class="selflink" id="section-7.2" href="#section-7.2">7.2</a>. RSAES-PKCS1-v1_5</span>
RSAES-PKCS1-v1_5 combines the RSAEP and RSADP primitives (Sections
5.1.1 and 5.1.2) with the EME-PKCS1-v1_5 encoding method (Step 2 in
<a href="#section-7.2.1">Section 7.2.1</a>, and Step 3 in <a href="#section-7.2.2">Section 7.2.2</a>). It is mathematically
equivalent to the encryption scheme in PKCS #1 v1.5.
RSAES-PKCS1-v1_5 can operate on messages of length up to k - 11
octets (k is the octet length of the RSA modulus), although care
should be taken to avoid certain attacks on low-exponent RSA due to
Coppersmith, Franklin, Patarin, and Reiter when long messages are
encrypted (see the third bullet in the notes below and [<a href="#ref-LOWEXP" title=""Low-Exponent RSA with Related Messages"">LOWEXP</a>];
[<a href="#ref-NEWATTACK">NEWATTACK</a>] contains an improved attack). As a general rule, the use
of this scheme for encrypting an arbitrary message, as opposed to a
randomly generated key, is NOT RECOMMENDED.
It is possible to generate valid RSAES-PKCS1-v1_5 ciphertexts without
knowing the corresponding plaintexts, with a reasonable probability
of success. This ability can be exploited in a chosen-ciphertext
attack as shown in [<a href="#ref-BLEICHENBACHER">BLEICHENBACHER</a>]. Therefore, if RSAES-PKCS1-v1_5
is to be used, certain easily implemented countermeasures should be
taken to thwart the attack found in [<a href="#ref-BLEICHENBACHER">BLEICHENBACHER</a>]. Typical
examples include the addition of structure to the data to be encoded,
rigorous checking of PKCS #1 v1.5 conformance (and other redundancy)
in decrypted messages, and the consolidation of error messages in a
client-server protocol based on PKCS #1 v1.5. These can all be
effective countermeasures and do not involve changes to a protocol
based on PKCS #1 v1.5. See [<a href="#ref-BKS" title=""Recent Results on PKCS #1: RSA Encryption Standard"">BKS</a>] for a further discussion of these
and other countermeasures. It has recently been shown that the
security of the SSL/TLS handshake protocol [<a href="./rfc5246" title=""The Transport Layer Security (TLS) Protocol Version 1.2"">RFC5246</a>], which uses
RSAES-PKCS1-v1_5 and certain countermeasures, can be related to a
variant of the RSA problem; see [<a href="#ref-RSATLS" title=""On the Security of RSA Encryption in TLS"">RSATLS</a>] for discussion.
Note: The following passages describe some security recommendations
pertaining to the use of RSAES-PKCS1-v1_5. Recommendations from PKCS
#1 v1.5 are included as well as new recommendations motivated by
cryptanalytic advances made in the intervening years.
<span class="grey">Moriarty, et al. Informational [Page 27]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-28" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
o It is RECOMMENDED that the pseudorandom octets in Step 2 in
<a href="#section-7.2.1">Section 7.2.1</a> be generated independently for each encryption
process, especially if the same data is input to more than one
encryption process. Haastad's results [<a href="#ref-HAASTAD" title=""Solving Simultaneous Modular Equations of Low Degree"">HAASTAD</a>] are one
motivation for this recommendation.
o The padding string PS in Step 2 in <a href="#section-7.2.1">Section 7.2.1</a> is at least eight
octets long, which is a security condition for public-key
operations that makes it difficult for an attacker to recover data
by trying all possible encryption blocks.
o The pseudorandom octets can also help thwart an attack due to
Coppersmith et al. [<a href="#ref-LOWEXP" title=""Low-Exponent RSA with Related Messages"">LOWEXP</a>] (see [<a href="#ref-NEWATTACK">NEWATTACK</a>] for an improvement
of the attack) when the size of the message to be encrypted is
kept small. The attack works on low-exponent RSA when similar
messages are encrypted with the same RSA public key. More
specifically, in one flavor of the attack, when two inputs to
RSAEP agree on a large fraction of bits (8/9) and low-exponent RSA
(e = 3) is used to encrypt both of them, it may be possible to
recover both inputs with the attack. Another flavor of the attack
is successful in decrypting a single ciphertext when a large
fraction (2/3) of the input to RSAEP is already known. For
typical applications, the message to be encrypted is short (e.g.,
a 128-bit symmetric key), so not enough information will be known
or common between two messages to enable the attack. However, if
a long message is encrypted, or if part of a message is known,
then the attack may be a concern. In any case, the RSAES-OAEP
scheme overcomes the attack.
<span class="h4"><a class="selflink" id="section-7.2.1" href="#section-7.2.1">7.2.1</a>. Encryption Operation</span>
RSAES-PKCS1-V1_5-ENCRYPT ((n, e), M)
Input:
(n, e) recipient's RSA public key (k denotes the length in
octets of the modulus n)
M message to be encrypted, an octet string of length
mLen, where mLen <= k - 11
Output:
C ciphertext, an octet string of length k
Error: "message too long"
<span class="grey">Moriarty, et al. Informational [Page 28]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-29" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Steps:
1. Length checking: If mLen > k - 11, output "message too long"
and stop.
2. EME-PKCS1-v1_5 encoding:
a. Generate an octet string PS of length k - mLen - 3
consisting of pseudo-randomly generated nonzero octets.
The length of PS will be at least eight octets.
b. Concatenate PS, the message M, and other padding to form
an encoded message EM of length k octets as
EM = 0x00 || 0x02 || PS || 0x00 || M.
3. RSA encryption:
a. Convert the encoded message EM to an integer message
representative m (see <a href="#section-4.2">Section 4.2</a>):
m = OS2IP (EM).
b. Apply the RSAEP encryption primitive (<a href="#section-5.1.1">Section 5.1.1</a>) to
the RSA public key (n, e) and the message representative m
to produce an integer ciphertext representative c:
c = RSAEP ((n, e), m).
c. Convert the ciphertext representative c to a ciphertext C
of length k octets (see <a href="#section-4.1">Section 4.1</a>):
C = I2OSP (c, k).
4. Output the ciphertext C.
<span class="h4"><a class="selflink" id="section-7.2.2" href="#section-7.2.2">7.2.2</a>. Decryption Operation</span>
RSAES-PKCS1-V1_5-DECRYPT (K, C)
Input:
K recipient's RSA private key
C ciphertext to be decrypted, an octet string of length k,
where k is the length in octets of the RSA modulus n
<span class="grey">Moriarty, et al. Informational [Page 29]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-30" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Output:
M message, an octet string of length at most k - 11
Error: "decryption error"
Steps:
1. Length checking: If the length of the ciphertext C is not k
octets (or if k < 11), output "decryption error" and stop.
2. RSA decryption:
a. Convert the ciphertext C to an integer ciphertext
representative c (see <a href="#section-4.2">Section 4.2</a>):
c = OS2IP (C).
b. Apply the RSADP decryption primitive (<a href="#section-5.1.2">Section 5.1.2</a>) to
the RSA private key (n, d) and the ciphertext
representative c to produce an integer message
representative m:
m = RSADP ((n, d), c).
If RSADP outputs "ciphertext representative out of range"
(meaning that c >= n), output "decryption error" and stop.
c. Convert the message representative m to an encoded message
EM of length k octets (see <a href="#section-4.1">Section 4.1</a>):
EM = I2OSP (m, k).
3. EME-PKCS1-v1_5 decoding: Separate the encoded message EM into
an octet string PS consisting of nonzero octets and a message
M as
EM = 0x00 || 0x02 || PS || 0x00 || M.
If the first octet of EM does not have hexadecimal value 0x00,
if the second octet of EM does not have hexadecimal value
0x02, if there is no octet with hexadecimal value 0x00 to
separate PS from M, or if the length of PS is less than 8
octets, output "decryption error" and stop. (See the note
below.)
4. Output M.
<span class="grey">Moriarty, et al. Informational [Page 30]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-31" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Note: Care shall be taken to ensure that an opponent cannot
distinguish the different error conditions in Step 3, whether by
error message or timing. Otherwise, an opponent may be able to
obtain useful information about the decryption of the ciphertext
C, leading to a strengthened version of Bleichenbacher's attack
[<a href="#ref-BLEICHENBACHER">BLEICHENBACHER</a>]; compare to Manger's attack [<a href="#ref-MANGER" title=""A Chosen Ciphertext Attack on RSA Optimal Asymmetric Encryption Padding (OAEP) as Standardized in PKCS #1 v2.0"">MANGER</a>].
<span class="h2"><a class="selflink" id="section-8" href="#section-8">8</a>. Signature Scheme with Appendix</span>
For the purposes of this document, a signature scheme with appendix
consists of a signature generation operation and a signature
verification operation, where the signature generation operation
produces a signature from a message with a signer's RSA private key,
and the signature verification operation verifies the signature on
the message with the signer's corresponding RSA public key. To
verify a signature constructed with this type of scheme, it is
necessary to have the message itself. In this way, signature schemes
with appendix are distinguished from signature schemes with message
recovery, which are not supported in this document.
A signature scheme with appendix can be employed in a variety of
applications. For instance, the signature schemes with appendix
defined here would be suitable signature algorithms for X.509
certificates [<a href="#ref-ISO9594" title=""Information technology - Open Systems Interconnection - The Directory: Public-key and attribute certificate frameworks"">ISO9594</a>]. Related signature schemes could be employed
in PKCS #7 [<a href="./rfc2315" title=""PKCS #7: Cryptographic Message Syntax Version 1.5"">RFC2315</a>], although for technical reasons the current
version of PKCS #7 separates a hash function from a signature scheme,
which is different than what is done here; see the note in
<a href="#appendix-A.2.3">Appendix A.2.3</a> for more discussion.
Two signature schemes with appendix are specified in this document:
RSASSA-PSS and RSASSA-PKCS1-v1_5. Although no attacks are known
against RSASSA-PKCS1-v1_5, in the interest of increased robustness,
RSASSA-PSS is REQUIRED in new applications. RSASSA-PKCS1-v1_5 is
included only for compatibility with existing applications.
The signature schemes with appendix given here follow a general model
similar to that employed in IEEE 1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>], combining signature
and verification primitives with an encoding method for signatures.
The signature generation operations apply a message encoding
operation to a message to produce an encoded message, which is then
converted to an integer message representative. A signature
primitive is applied to the message representative to produce the
signature. Reversing this, the signature verification operations
apply a signature verification primitive to the signature to recover
a message representative, which is then converted to an octet-string-
encoded message. A verification operation is applied to the message
and the encoded message to determine whether they are consistent.
<span class="grey">Moriarty, et al. Informational [Page 31]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-32" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
If the encoding method is deterministic (e.g., EMSA-PKCS1-v1_5), the
verification operation may apply the message encoding operation to
the message and compare the resulting encoded message to the
previously derived encoded message. If there is a match, the
signature is considered valid. If the method is randomized (e.g.,
EMSA-PSS), the verification operation is typically more complicated.
For example, the verification operation in EMSA-PSS extracts the
random salt and a hash output from the encoded message and checks
whether the hash output, the salt, and the message are consistent;
the hash output is a deterministic function in terms of the message
and the salt. For both signature schemes with appendix defined in
this document, the signature generation and signature verification
operations are readily implemented as "single-pass" operations if the
signature is placed after the message. See PKCS #7 [<a href="./rfc2315" title=""PKCS #7: Cryptographic Message Syntax Version 1.5"">RFC2315</a>] for an
example format in the case of RSASSA-PKCS1-v1_5.
<span class="h3"><a class="selflink" id="section-8.1" href="#section-8.1">8.1</a>. RSASSA-PSS</span>
RSASSA-PSS combines the RSASP1 and RSAVP1 primitives with the
EMSA-PSS encoding method. It is compatible with the Integer
Factorization Signature Scheme with Appendix (IFSSA) as amended in
IEEE 1363a [<a href="#ref-IEEE1363A">IEEE1363A</a>], where the signature and verification
primitives are IFSP-RSA1 and IFVP-RSA1 as defined in IEEE 1363
[<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>], and the message encoding method is EMSA4. EMSA4 is
slightly more general than EMSA-PSS as it acts on bit strings rather
than on octet strings. EMSA-PSS is equivalent to EMSA4 restricted to
the case that the operands as well as the hash and salt values are
octet strings.
The length of messages on which RSASSA-PSS can operate is either
unrestricted or constrained by a very large number, depending on the
hash function underlying the EMSA-PSS encoding method.
Assuming that computing e-th roots modulo n is infeasible and the
hash and mask generation functions in EMSA-PSS have appropriate
properties, RSASSA-PSS provides secure signatures. This assurance is
provable in the sense that the difficulty of forging signatures can
be directly related to the difficulty of inverting the RSA function,
provided that the hash and mask generation functions are viewed as
black boxes or random oracles. The bounds in the security proof are
essentially "tight", meaning that the success probability and running
time for the best forger against RSASSA-PSS are very close to the
corresponding parameters for the best RSA inversion algorithm; see
[<a href="#ref-RSARABIN" title=""The Exact Security of Digital Signatures - How to Sign with RSA and Rabin"">RSARABIN</a>] [<a href="#ref-PSSPROOF" title=""Optimal Security Proofs for PSS and Other Signature Schemes"">PSSPROOF</a>] [<a href="#ref-JONSSON" title=""Security Proofs for the RSA-PSS Signature Scheme and Its Variants"">JONSSON</a>] for further discussion.
In contrast to the RSASSA-PKCS1-v1_5 signature scheme, a hash
function identifier is not embedded in the EMSA-PSS encoded message,
so in theory it is possible for an adversary to substitute a
<span class="grey">Moriarty, et al. Informational [Page 32]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-33" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
different (and potentially weaker) hash function than the one
selected by the signer. Therefore, it is RECOMMENDED that the
EMSA-PSS mask generation function be based on the same hash function.
In this manner, the entire encoded message will be dependent on the
hash function, and it will be difficult for an opponent to substitute
a different hash function than the one intended by the signer. This
matching of hash functions is only for the purpose of preventing hash
function substitution and is not necessary if hash function
substitution is addressed by other means (e.g., the verifier accepts
only a designated hash function). See [<a href="#ref-HASHID" title=""On Hash Function Firewalls in Signature Schemes"">HASHID</a>] for further
discussion of these points. The provable security of RSASSA-PSS does
not rely on the hash function in the mask generation function being
the same as the hash function applied to the message.
RSASSA-PSS is different from other RSA-based signature schemes in
that it is probabilistic rather than deterministic, incorporating a
randomly generated salt value. The salt value enhances the security
of the scheme by affording a "tighter" security proof than
deterministic alternatives such as Full Domain Hashing (FDH); see
[<a href="#ref-RSARABIN" title=""The Exact Security of Digital Signatures - How to Sign with RSA and Rabin"">RSARABIN</a>] for discussion. However, the randomness is not critical
to security. In situations where random generation is not possible,
a fixed value or a sequence number could be employed instead, with
the resulting provable security similar to that of FDH [<a href="#ref-FDH" title=""On the Exact Security of Full Domain Hash"">FDH</a>].
<span class="h4"><a class="selflink" id="section-8.1.1" href="#section-8.1.1">8.1.1</a>. Signature Generation Operation</span>
RSASSA-PSS-SIGN (K, M)
Input:
K signer's RSA private key
M message to be signed, an octet string
Output:
S signature, an octet string of length k, where k is the
length in octets of the RSA modulus n
Errors: "message too long;" "encoding error"
Steps:
1. EMSA-PSS encoding: Apply the EMSA-PSS encoding operation
(<a href="#section-9.1.1">Section 9.1.1</a>) to the message M to produce an encoded message
EM of length \ceil ((modBits - 1)/8) octets such that the bit
length of the integer OS2IP (EM) (see <a href="#section-4.2">Section 4.2</a>) is at most
modBits - 1, where modBits is the length in bits of the RSA
modulus n:
<span class="grey">Moriarty, et al. Informational [Page 33]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-34" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
EM = EMSA-PSS-ENCODE (M, modBits - 1).
Note that the octet length of EM will be one less than k if
modBits - 1 is divisible by 8 and equal to k otherwise. If
the encoding operation outputs "message too long", output
"message too long" and stop. If the encoding operation
outputs "encoding error", output "encoding error" and stop.
2. RSA signature:
a. Convert the encoded message EM to an integer message
representative m (see <a href="#section-4.2">Section 4.2</a>):
m = OS2IP (EM).
b. Apply the RSASP1 signature primitive (<a href="#section-5.2.1">Section 5.2.1</a>) to
the RSA private key K and the message representative m to
produce an integer signature representative s:
s = RSASP1 (K, m).
c. Convert the signature representative s to a signature S of
length k octets (see <a href="#section-4.1">Section 4.1</a>):
S = I2OSP (s, k).
3. Output the signature S.
<span class="h4"><a class="selflink" id="section-8.1.2" href="#section-8.1.2">8.1.2</a>. Signature Verification Operation</span>
RSASSA-PSS-VERIFY ((n, e), M, S)
Input:
(n, e) signer's RSA public key
M message whose signature is to be verified, an octet string
S signature to be verified, an octet string of length k,
where k is the length in octets of the RSA modulus n
Output: "valid signature" or "invalid signature"
Steps:
1. Length checking: If the length of the signature S is not k
octets, output "invalid signature" and stop.
<span class="grey">Moriarty, et al. Informational [Page 34]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-35" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
2. RSA verification:
a. Convert the signature S to an integer signature
representative s (see <a href="#section-4.2">Section 4.2</a>):
s = OS2IP (S).
b. Apply the RSAVP1 verification primitive (<a href="#section-5.2.2">Section 5.2.2</a>) to
the RSA public key (n, e) and the signature representative
s to produce an integer message representative m:
m = RSAVP1 ((n, e), s).
If RSAVP1 output "signature representative out of range",
output "invalid signature" and stop.
c. Convert the message representative m to an encoded message
EM of length emLen = \ceil ((modBits - 1)/8) octets, where
modBits is the length in bits of the RSA modulus n (see
<a href="#section-4.1">Section 4.1</a>):
EM = I2OSP (m, emLen).
Note that emLen will be one less than k if modBits - 1 is
divisible by 8 and equal to k otherwise. If I2OSP outputs
"integer too large", output "invalid signature" and stop.
3. EMSA-PSS verification: Apply the EMSA-PSS verification
operation (<a href="#section-9.1.2">Section 9.1.2</a>) to the message M and the encoded
message EM to determine whether they are consistent:
Result = EMSA-PSS-VERIFY (M, EM, modBits - 1).
4. If Result = "consistent", output "valid signature".
Otherwise, output "invalid signature".
<span class="h3"><a class="selflink" id="section-8.2" href="#section-8.2">8.2</a>. RSASSA-PKCS1-v1_5</span>
RSASSA-PKCS1-v1_5 combines the RSASP1 and RSAVP1 primitives with the
EMSA-PKCS1-v1_5 encoding method. It is compatible with the IFSSA
scheme defined in IEEE 1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>], where the signature and
verification primitives are IFSP-RSA1 and IFVP-RSA1, and the message
encoding method is EMSA-PKCS1-v1_5 (which is not defined in IEEE 1363
but is in IEEE 1363a [<a href="#ref-IEEE1363A">IEEE1363A</a>]).
The length of messages on which RSASSA-PKCS1-v1_5 can operate is
either unrestricted or constrained by a very large number, depending
on the hash function underlying the EMSA-PKCS1-v1_5 method.
<span class="grey">Moriarty, et al. Informational [Page 35]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-36" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Assuming that computing e-th roots modulo n is infeasible and the
hash function in EMSA-PKCS1-v1_5 has appropriate properties,
RSASSA-PKCS1-v1_5 is conjectured to provide secure signatures. More
precisely, forging signatures without knowing the RSA private key is
conjectured to be computationally infeasible. Also, in the encoding
method EMSA-PKCS1-v1_5, a hash function identifier is embedded in the
encoding. Because of this feature, an adversary trying to find a
message with the same signature as a previously signed message must
find collisions of the particular hash function being used; attacking
a different hash function than the one selected by the signer is not
useful to the adversary. See [<a href="#ref-HASHID" title=""On Hash Function Firewalls in Signature Schemes"">HASHID</a>] for further discussion.
Note: As noted in PKCS #1 v1.5, the EMSA-PKCS1-v1_5 encoding method
has the property that the encoded message, converted to an integer
message representative, is guaranteed to be large and at least
somewhat "random". This prevents attacks of the kind proposed by
Desmedt and Odlyzko [<a href="#ref-CHOSEN" title=""A Chosen Text Attack on the RSA Cryptosystem and Some Discrete Logarithm Schemes"">CHOSEN</a>] where multiplicative relationships
between message representatives are developed by factoring the
message representatives into a set of small values (e.g., a set of
small primes). Coron, Naccache, and Stern [<a href="#ref-PADDING" title=""On the Security of RSA Padding"">PADDING</a>] showed that a
stronger form of this type of attack could be quite effective against
some instances of the ISO/IEC 9796-2 signature scheme. They also
analyzed the complexity of this type of attack against the
EMSA-PKCS1-v1_5 encoding method and concluded that an attack would be
impractical, requiring more operations than a collision search on the
underlying hash function (i.e., more than 2^80 operations).
Coppersmith, Halevi, and Jutla [<a href="#ref-FORGERY" title=""ISO 9796-1 and the new forgery strategy"">FORGERY</a>] subsequently extended Coron
et al.'s attack to break the ISO/IEC 9796-1 signature scheme with
message recovery. The various attacks illustrate the importance of
carefully constructing the input to the RSA signature primitive,
particularly in a signature scheme with message recovery.
Accordingly, the EMSA-PKCS-v1_5 encoding method explicitly includes a
hash operation and is not intended for signature schemes with message
recovery. Moreover, while no attack is known against the
EMSA-PKCS-v1_5 encoding method, a gradual transition to EMSA-PSS is
recommended as a precaution against future developments.
<span class="h4"><a class="selflink" id="section-8.2.1" href="#section-8.2.1">8.2.1</a>. Signature Generation Operation</span>
RSASSA-PKCS1-V1_5-SIGN (K, M)
Input:
K signer's RSA private key
M message to be signed, an octet string
<span class="grey">Moriarty, et al. Informational [Page 36]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-37" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Output:
S signature, an octet string of length k, where k is the
length in octets of the RSA modulus n
Errors: "message too long"; "RSA modulus too short"
Steps:
1. EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
operation (<a href="#section-9.2">Section 9.2</a>) to the message M to produce an encoded
message EM of length k octets:
EM = EMSA-PKCS1-V1_5-ENCODE (M, k).
If the encoding operation outputs "message too long", output
"message too long" and stop. If the encoding operation
outputs "intended encoded message length too short", output
"RSA modulus too short" and stop.
2. RSA signature:
a. Convert the encoded message EM to an integer message
representative m (see <a href="#section-4.2">Section 4.2</a>):
m = OS2IP (EM).
b. Apply the RSASP1 signature primitive (<a href="#section-5.2.1">Section 5.2.1</a>) to
the RSA private key K and the message representative m to
produce an integer signature representative s:
s = RSASP1 (K, m).
c. Convert the signature representative s to a signature S of
length k octets (see <a href="#section-4.1">Section 4.1</a>):
S = I2OSP (s, k).
3. Output the signature S.
<span class="h4"><a class="selflink" id="section-8.2.2" href="#section-8.2.2">8.2.2</a>. Signature Verification Operation</span>
RSASSA-PKCS1-V1_5-VERIFY ((n, e), M, S)
Input:
(n, e) signer's RSA public key
M message whose signature is to be verified, an octet string
<span class="grey">Moriarty, et al. Informational [Page 37]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-38" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
S signature to be verified, an octet string of length k,
where k is the length in octets of the RSA modulus n
Output "valid signature" or "invalid signature"
Errors: "message too long"; "RSA modulus too short"
Steps:
1. Length checking: If the length of the signature S is not k
octets, output "invalid signature" and stop.
2. RSA verification:
a. Convert the signature S to an integer signature
representative s (see <a href="#section-4.2">Section 4.2</a>):
s = OS2IP (S).
b. Apply the RSAVP1 verification primitive (<a href="#section-5.2.2">Section 5.2.2</a>) to
the RSA public key (n, e) and the signature representative
s to produce an integer message representative m:
m = RSAVP1 ((n, e), s).
If RSAVP1 outputs "signature representative out of range",
output "invalid signature" and stop.
c. Convert the message representative m to an encoded message
EM of length k octets (see <a href="#section-4.1">Section 4.1</a>):
EM = I2OSP (m, k).
If I2OSP outputs "integer too large", output "invalid
signature" and stop.
3. EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding
operation (<a href="#section-9.2">Section 9.2</a>) to the message M to produce a second
encoded message EM' of length k octets:
EM' = EMSA-PKCS1-V1_5-ENCODE (M, k).
If the encoding operation outputs "message too long", output
"message too long" and stop. If the encoding operation
outputs "intended encoded message length too short", output
"RSA modulus too short" and stop.
<span class="grey">Moriarty, et al. Informational [Page 38]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-39" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
4. Compare the encoded message EM and the second encoded message
EM'. If they are the same, output "valid signature";
otherwise, output "invalid signature".
Note: Another way to implement the signature verification
operation is to apply a "decoding" operation (not specified in
this document) to the encoded message to recover the underlying
hash value, and then compare it to a newly computed hash value.
This has the advantage that it requires less intermediate storage
(two hash values rather than two encoded messages), but the
disadvantage that it requires additional code.
<span class="h2"><a class="selflink" id="section-9" href="#section-9">9</a>. Encoding Methods for Signatures with Appendix</span>
Encoding methods consist of operations that map between octet string
messages and octet-string-encoded messages, which are converted to
and from integer message representatives in the schemes. The integer
message representatives are processed via the primitives. The
encoding methods thus provide the connection between the schemes,
which process messages, and the primitives.
An encoding method for signatures with appendix, for the purposes of
this document, consists of an encoding operation and optionally a
verification operation. An encoding operation maps a message M to an
encoded message EM of a specified length. A verification operation
determines whether a message M and an encoded message EM are
consistent, i.e., whether the encoded message EM is a valid encoding
of the message M.
The encoding operation may introduce some randomness, so that
different applications of the encoding operation to the same message
will produce different encoded messages, which has benefits for
provable security. For such an encoding method, both an encoding and
a verification operation are needed unless the verifier can reproduce
the randomness (e.g., by obtaining the salt value from the signer).
For a deterministic encoding method, only an encoding operation is
needed.
Two encoding methods for signatures with appendix are employed in the
signature schemes and are specified here: EMSA-PSS and
EMSA-PKCS1-v1_5.
<span class="grey">Moriarty, et al. Informational [Page 39]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-40" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h3"><a class="selflink" id="section-9.1" href="#section-9.1">9.1</a>. EMSA-PSS</span>
This encoding method is parameterized by the choice of hash function,
mask generation function, and salt length. These options should be
fixed for a given RSA key, except that the salt length can be
variable (see [<a href="#ref-JONSSON" title=""Security Proofs for the RSA-PSS Signature Scheme and Its Variants"">JONSSON</a>] for discussion). Suggested hash and mask
generation functions are given in <a href="#appendix-B">Appendix B</a>. The encoding method is
based on Bellare and Rogaway's Probabilistic Signature Scheme (PSS)
[<a href="#ref-RSARABIN" title=""The Exact Security of Digital Signatures - How to Sign with RSA and Rabin"">RSARABIN</a>][PSS]. It is randomized and has an encoding operation and
a verification operation.
Figure 2 illustrates the encoding operation.
__________________________________________________________________
+-----------+
| M |
+-----------+
|
V
Hash
|
V
+--------+----------+----------+
M' = |Padding1| mHash | salt |
+--------+----------+----------+
|
+--------+----------+ V
DB = |Padding2| salt | Hash
+--------+----------+ |
| |
V |
xor <--- MGF <---|
| |
| |
V V
+-------------------+----------+--+
EM = | maskedDB | H |bc|
+-------------------+----------+--+
__________________________________________________________________
Figure 2: EMSA-PSS Encoding Operation
Note that the verification operation follows reverse steps to recover
salt and then forward steps to recompute and compare H.
<span class="grey">Moriarty, et al. Informational [Page 40]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-41" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Notes:
1. The encoding method defined here differs from the one in Bellare
and Rogaway's submission to IEEE 1363a [<a href="#ref-PSS" title=""PSS: Provably Secure Encoding Method for Digital Signatures"">PSS</a>] in three respects:
* It applies a hash function rather than a mask generation
function to the message. Even though the mask generation
function is based on a hash function, it seems more natural to
apply a hash function directly.
* The value that is hashed together with the salt value is the
string (0x)00 00 00 00 00 00 00 00 || mHash rather than the
message M itself. Here, mHash is the hash of M. Note that
the hash function is the same in both steps. See Note 3 below
for further discussion. (Also, the name "salt" is used
instead of "seed", as it is more reflective of the value's
role.)
* The encoded message in EMSA-PSS has nine fixed bits; the first
bit is 0 and the last eight bits form a "trailer field", the
octet 0xbc. In the original scheme, only the first bit is
fixed. The rationale for the trailer field is for
compatibility with the Integer Factorization Signature
Primitive using Rabin-Williams (IFSP-RW) in IEEE 1363
[<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>] and the corresponding primitive in ISO/IEC
9796-2:2010 [<a href="#ref-ISO9796" title=""Information technology - Security techniques - Digital signature schemes giving message recovery - Part 2: Integer factorization based mechanisms"">ISO9796</a>].
2. Assuming that the mask generation function is based on a hash
function, it is RECOMMENDED that the hash function be the same as
the one that is applied to the message; see <a href="#section-8.1">Section 8.1</a> for
further discussion.
3. Without compromising the security proof for RSASSA-PSS, one may
perform Steps 1 and 2 of EMSA-PSS-ENCODE and EMSA-PSS-VERIFY (the
application of the hash function to the message) outside the
module that computes the rest of the signature operation, so that
mHash rather than the message M itself is input to the module.
In other words, the security proof for RSASSA-PSS still holds
even if an opponent can control the value of mHash. This is
convenient if the module has limited I/O bandwidth, e.g., a smart
card. Note that previous versions of PSS [<a href="#ref-RSARABIN" title=""The Exact Security of Digital Signatures - How to Sign with RSA and Rabin"">RSARABIN</a>][PSS] did not
have this property. Of course, it may be desirable for other
security reasons to have the module process the full message.
For instance, the module may need to "see" what it is signing if
it does not trust the component that computes the hash value.
<span class="grey">Moriarty, et al. Informational [Page 41]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-42" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
4. Typical salt lengths in octets are hLen (the length of the output
of the hash function Hash) and 0. In both cases, the security of
RSASSA-PSS can be closely related to the hardness of inverting
RSAVP1. Bellare and Rogaway [<a href="#ref-RSARABIN" title=""The Exact Security of Digital Signatures - How to Sign with RSA and Rabin"">RSARABIN</a>] give a tight lower bound
for the security of the original RSA-PSS scheme, which
corresponds roughly to the former case, while Coron [<a href="#ref-FDH" title=""On the Exact Security of Full Domain Hash"">FDH</a>] gives a
lower bound for the related Full Domain Hashing scheme, which
corresponds roughly to the latter case. In [<a href="#ref-PSSPROOF" title=""Optimal Security Proofs for PSS and Other Signature Schemes"">PSSPROOF</a>], Coron
provides a general treatment with various salt lengths ranging
from 0 to hLen; see [<a href="#ref-IEEE1363A">IEEE1363A</a>] for discussion. See also
[<a href="#ref-JONSSON" title=""Security Proofs for the RSA-PSS Signature Scheme and Its Variants"">JONSSON</a>], which adapts the security proofs in [<a href="#ref-RSARABIN" title=""The Exact Security of Digital Signatures - How to Sign with RSA and Rabin"">RSARABIN</a>]
[<a href="#ref-PSSPROOF" title=""Optimal Security Proofs for PSS and Other Signature Schemes"">PSSPROOF</a>] to address the differences between the original and
the present version of RSA-PSS as listed in Note 1 above.
5. As noted in IEEE 1363a [<a href="#ref-IEEE1363A">IEEE1363A</a>], the use of randomization in
signature schemes -- such as the salt value in EMSA-PSS -- may
provide a "covert channel" for transmitting information other
than the message being signed. For more on covert channels, see
[<a href="#ref-SIMMONS" title=""Subliminal Communication is Easy Using the DSA"">SIMMONS</a>].
<span class="h4"><a class="selflink" id="section-9.1.1" href="#section-9.1.1">9.1.1</a>. Encoding Operation</span>
EMSA-PSS-ENCODE (M, emBits)
Options:
Hash hash function (hLen denotes the length in octets of
the hash function output)
MGF mask generation function
sLen intended length in octets of the salt
Input:
M message to be encoded, an octet string
emBits maximal bit length of the integer OS2IP (EM) (see <a href="#section-4.2">Section</a>
<a href="#section-4.2">4.2</a>), at least 8hLen + 8sLen + 9
Output:
EM encoded message, an octet string of length emLen = \ceil
(emBits/8)
Errors: "Encoding error"; "message too long"
<span class="grey">Moriarty, et al. Informational [Page 42]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-43" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Steps:
1. If the length of M is greater than the input limitation for
the hash function (2^61 - 1 octets for SHA-1), output
"message too long" and stop.
2. Let mHash = Hash(M), an octet string of length hLen.
3. If emLen < hLen + sLen + 2, output "encoding error" and stop.
4. Generate a random octet string salt of length sLen; if sLen =
0, then salt is the empty string.
5. Let
M' = (0x)00 00 00 00 00 00 00 00 || mHash || salt;
M' is an octet string of length 8 + hLen + sLen with eight
initial zero octets.
6. Let H = Hash(M'), an octet string of length hLen.
7. Generate an octet string PS consisting of emLen - sLen - hLen
- 2 zero octets. The length of PS may be 0.
8. Let DB = PS || 0x01 || salt; DB is an octet string of length
emLen - hLen - 1.
9. Let dbMask = MGF(H, emLen - hLen - 1).
10. Let maskedDB = DB \xor dbMask.
11. Set the leftmost 8emLen - emBits bits of the leftmost octet
in maskedDB to zero.
12. Let EM = maskedDB || H || 0xbc.
13. Output EM.
<span class="grey">Moriarty, et al. Informational [Page 43]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-44" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h4"><a class="selflink" id="section-9.1.2" href="#section-9.1.2">9.1.2</a>. Verification Operation</span>
EMSA-PSS-VERIFY (M, EM, emBits)
Options:
Hash hash function (hLen denotes the length in octets of
the hash function output)
MGF mask generation function
sLen intended length in octets of the salt
Input:
M message to be verified, an octet string
EM encoded message, an octet string of length emLen = \ceil
(emBits/8)
emBits maximal bit length of the integer OS2IP (EM) (see <a href="#section-4.2">Section</a>
<a href="#section-4.2">4.2</a>), at least 8hLen + 8sLen + 9
Output: "consistent" or "inconsistent"
Steps:
1. If the length of M is greater than the input limitation for
the hash function (2^61 - 1 octets for SHA-1), output
"inconsistent" and stop.
2. Let mHash = Hash(M), an octet string of length hLen.
3. If emLen < hLen + sLen + 2, output "inconsistent" and stop.
4. If the rightmost octet of EM does not have hexadecimal value
0xbc, output "inconsistent" and stop.
5. Let maskedDB be the leftmost emLen - hLen - 1 octets of EM,
and let H be the next hLen octets.
6. If the leftmost 8emLen - emBits bits of the leftmost octet in
maskedDB are not all equal to zero, output "inconsistent" and
stop.
7. Let dbMask = MGF(H, emLen - hLen - 1).
8. Let DB = maskedDB \xor dbMask.
9. Set the leftmost 8emLen - emBits bits of the leftmost octet
in DB to zero.
<span class="grey">Moriarty, et al. Informational [Page 44]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-45" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
10. If the emLen - hLen - sLen - 2 leftmost octets of DB are not
zero or if the octet at position emLen - hLen - sLen - 1 (the
leftmost position is "position 1") does not have hexadecimal
value 0x01, output "inconsistent" and stop.
11. Let salt be the last sLen octets of DB.
12. Let
M' = (0x)00 00 00 00 00 00 00 00 || mHash || salt ;
M' is an octet string of length 8 + hLen + sLen with eight
initial zero octets.
13. Let H' = Hash(M'), an octet string of length hLen.
14. If H = H', output "consistent". Otherwise, output
"inconsistent".
<span class="h3"><a class="selflink" id="section-9.2" href="#section-9.2">9.2</a>. EMSA-PKCS1-v1_5</span>
This encoding method is deterministic and only has an encoding
operation.
EMSA-PKCS1-v1_5-ENCODE (M, emLen)
Option:
Hash hash function (hLen denotes the length in octets of
the hash function output)
Input:
M message to be encoded
emLen intended length in octets of the encoded message, at
least tLen + 11, where tLen is the octet length of the
Distinguished Encoding Rules (DER) encoding T of
a certain value computed during the encoding operation
Output:
EM encoded message, an octet string of length emLen
Errors: "message too long"; "intended encoded message length too
short"
<span class="grey">Moriarty, et al. Informational [Page 45]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-46" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Steps:
1. Apply the hash function to the message M to produce a hash
value H:
H = Hash(M).
If the hash function outputs "message too long", output
"message too long" and stop.
2. Encode the algorithm ID for the hash function and the hash
value into an ASN.1 value of type DigestInfo (see
<a href="#appendix-A.2.4">Appendix A.2.4</a>) with the DER, where the type DigestInfo has
the syntax
DigestInfo ::= SEQUENCE {
digestAlgorithm AlgorithmIdentifier,
digest OCTET STRING
}
The first field identifies the hash function and the second
contains the hash value. Let T be the DER encoding of the
DigestInfo value (see the notes below), and let tLen be the
length in octets of T.
3. If emLen < tLen + 11, output "intended encoded message length
too short" and stop.
4. Generate an octet string PS consisting of emLen - tLen - 3
octets with hexadecimal value 0xff. The length of PS will be
at least 8 octets.
5. Concatenate PS, the DER encoding T, and other padding to form
the encoded message EM as
EM = 0x00 || 0x01 || PS || 0x00 || T.
6. Output EM.
<span class="grey">Moriarty, et al. Informational [Page 46]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-47" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Notes:
1. For the nine hash functions mentioned in <a href="#appendix-B.1">Appendix B.1</a>, the DER
encoding T of the DigestInfo value is equal to the following:
MD2: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 02 05 00 04
10 || H.
MD5: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 05 05 00 04
10 || H.
SHA-1: (0x)30 21 30 09 06 05 2b 0e 03 02 1a 05 00 04 14 || H.
SHA-224: (0x)30 2d 30 0d 06 09 60 86 48 01 65 03 04 02 04
05 00 04 1c || H.
SHA-256: (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00
04 20 || H.
SHA-384: (0x)30 41 30 0d 06 09 60 86 48 01 65 03 04 02 02 05 00
04 30 || H.
SHA-512: (0x)30 51 30 0d 06 09 60 86 48 01 65 03 04 02 03 05 00
04 40 || H.
SHA-512/224: (0x)30 2d 30 0d 06 09 60 86 48 01 65 03 04 02 05
05 00 04 1c || H.
SHA-512/256: (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 06
05 00 04 20 || H.
2. In version 1.5 of this document, T was defined as the BER
encoding, rather than the DER encoding, of the DigestInfo value.
In particular, it is possible -- at least in theory -- that the
verification operation defined in this document (as well as in
version 2.0) rejects a signature that is valid with respect to
the specification given in PKCS #1 v1.5. This occurs if other
rules than DER are applied to DigestInfo (e.g., an indefinite
length encoding of the underlying SEQUENCE type). While this is
unlikely to be a concern in practice, a cautious implementor may
choose to employ a verification operation based on a BER decoding
operation as specified in PKCS #1 v1.5. In this manner,
compatibility with any valid implementation based on PKCS #1 v1.5
is obtained. Such a verification operation should indicate
whether the underlying BER encoding is a DER encoding and hence
whether the signature is valid with respect to the specification
given in this document.
<span class="h2"><a class="selflink" id="section-10" href="#section-10">10</a>. Security Considerations</span>
Security considerations are discussed throughout this memo.
<span class="grey">Moriarty, et al. Informational [Page 47]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-48" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h2"><a class="selflink" id="section-11" href="#section-11">11</a>. References</span>
<span class="h3"><a class="selflink" id="section-11.1" href="#section-11.1">11.1</a>. Normative References</span>
[<a id="ref-GARNER">GARNER</a>] Garner, H., "The Residue Number System", IRE Transactions
on Electronic Computers, Volume EC-8, Issue 2, pp.
140-147, DOI 10.1109/TEC.1959.5219515, June 1959.
[<a id="ref-RFC2119">RFC2119</a>] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", <a href="https://www.rfc-editor.org/bcp/bcp14">BCP 14</a>, <a href="./rfc2119">RFC 2119</a>,
DOI 10.17487/RFC2119, March 1997,
<<a href="http://www.rfc-editor.org/info/rfc2119">http://www.rfc-editor.org/info/rfc2119</a>>.
[<a id="ref-RSA">RSA</a>] Rivest, R., Shamir, A., and L. Adleman, "A Method for
Obtaining Digital Signatures and Public-Key
Cryptosystems", Communications of the ACM, Volume 21,
Issue 2, pp. 120-126, DOI 10.1145/359340.359342, February
1978.
<span class="h3"><a class="selflink" id="section-11.2" href="#section-11.2">11.2</a>. Informative References</span>
[<a id="ref-ANSIX944">ANSIX944</a>] ANSI, "Key Establishment Using Integer Factorization
Cryptography", ANSI X9.44-2007, August 2007.
[<a id="ref-BKS">BKS</a>] Bleichenbacher, D., Kaliski, B., and J. Staddon, "Recent
Results on PKCS #1: RSA Encryption Standard", RSA
Laboratories, Bulletin No. 7, June 1998.
[<a id="ref-BLEICHENBACHER">BLEICHENBACHER</a>]
Bleichenbacher, D., "Chosen Ciphertext Attacks Against
Protocols Based on the RSA Encryption Standard PKCS #1",
Lecture Notes in Computer Science, Volume 1462, pp. 1-12,
1998.
[<a id="ref-CHOSEN">CHOSEN</a>] Desmedt, Y. and A. Odlyzko, "A Chosen Text Attack on the
RSA Cryptosystem and Some Discrete Logarithm Schemes",
Lecture Notes in Computer Science, Volume 218, pp.
516-522, 1985.
[<a id="ref-COCHRAN">COCHRAN</a>] Cochran, M., "Notes on the Wang et al. 2^63 SHA-1
Differential Path", Cryptology ePrint Archive: Report
2007/474, August 2008, <<a href="http://eprint.iacr.org/2007/474">http://eprint.iacr.org/2007/474</a>>.
[<a id="ref-FASTDEC">FASTDEC</a>] Quisquater, J. and C. Couvreur, "Fast Decipherment
Algorithm for RSA Public-Key Cryptosystem", Electronic
Letters, Volume 18, Issue 21, pp. 905-907,
DOI 10.1049/el:19820617, October 1982.
<span class="grey">Moriarty, et al. Informational [Page 48]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-49" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
[<a id="ref-FDH">FDH</a>] Coron, J., "On the Exact Security of Full Domain Hash",
Lecture Notes in Computer Science, Volume 1880, pp.
229-235, 2000.
[<a id="ref-FOPS">FOPS</a>] Fujisaki, E., Okamoto, T., Pointcheval, D., and J. Stern,
"RSA-OAEP is Secure under the RSA Assumption", Lecture
Notes in Computer Science, Volume 2139, pp. 260-274,
August 2001.
[<a id="ref-FORGERY">FORGERY</a>] Coppersmith, D., Halevi, S., and C. Jutla, "ISO 9796-1 and
the new forgery strategy", rump session of Crypto, August
1999.
[<a id="ref-HAASTAD">HAASTAD</a>] Haastad, J., "Solving Simultaneous Modular Equations of
Low Degree", SIAM Journal on Computing, Volume 17,
Issue 2, pp. 336-341, DOI 10.1137/0217019, April 1988.
[<a id="ref-HANDBOOK">HANDBOOK</a>] Menezes, A., van Oorschot, P., and S. Vanstone, "Handbook
of Applied Cryptography", CRC Press, ISBN: 0849385237,
1996.
[<a id="ref-HASHID">HASHID</a>] Kaliski, B., "On Hash Function Firewalls in Signature
Schemes", Lecture Notes in Computer Science, Volume 2271,
pp. 1-16, DOI 10.1007/3-540-45760-7_1, February 2002.
[<a id="ref-IEEE1363">IEEE1363</a>] IEEE, "Standard Specifications for Public Key
Cryptography", IEEE Std 1363-2000,
DOI 10.1109/IEEESTD.2000.92292, August 2000,
<<a href="http://ieeexplore.ieee.org/document/891000/">http://ieeexplore.ieee.org/document/891000/</a>>.
[<a id="ref-IEEE1363A">IEEE1363A</a>]
IEEE, "Standard Specifications for Public Key Cryptography
- Amendment 1: Additional Techniques", IEEE Std 1363a-
2004, DOI 10.1109/IEEESTD.2004.94612, September 2004,
<<a href="http://ieeexplore.ieee.org/document/1335427/">http://ieeexplore.ieee.org/document/1335427/</a>>.
[<a id="ref-ISO18033">ISO18033</a>] International Organization for Standardization,
"Information technology -- Security techniques --
Encryption algorithms - Part 2: Asymmetric ciphers", ISO/
IEC 18033-2:2006, May 2006.
[<a id="ref-ISO9594">ISO9594</a>] International Organization for Standardization,
"Information technology - Open Systems Interconnection -
The Directory: Public-key and attribute certificate
frameworks", ISO/IEC 9594-8:2008, December 2008.
<span class="grey">Moriarty, et al. Informational [Page 49]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-50" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
[<a id="ref-ISO9796">ISO9796</a>] International Organization for Standardization,
"Information technology - Security techniques - Digital
signature schemes giving message recovery - Part 2:
Integer factorization based mechanisms",
ISO/IEC 9796-2:2010, December 2010.
[<a id="ref-JONSSON">JONSSON</a>] Jonsson, J., "Security Proofs for the RSA-PSS Signature
Scheme and Its Variants", Cryptology ePrint
Archive: Report 2001/053, March 2002,
<<a href="http://eprint.iacr.org/2001/053">http://eprint.iacr.org/2001/053</a>>.
[<a id="ref-LOWEXP">LOWEXP</a>] Coppersmith, D., Franklin, M., Patarin, J., and M. Reiter,
"Low-Exponent RSA with Related Messages", Lecture Notes in
Computer Science, Volume 1070, pp. 1-9, 1996.
[<a id="ref-MANGER">MANGER</a>] Manger, J., "A Chosen Ciphertext Attack on RSA Optimal
Asymmetric Encryption Padding (OAEP) as Standardized in
PKCS #1 v2.0", Lecture Notes in Computer Science, Volume
2139, pp. 230-238, DOI 10.1007/3-540-44647-8_14, 2001.
[<a id="ref-MD4">MD4</a>] Dobbertin, H., "Cryptanalysis of MD4", Lecture Notes in
Computer Science, Volume 1039, pp. 53-69,
DOI 10.1007/3-540-60865-6_43, 1996.
[<a id="ref-MD4FIRST">MD4FIRST</a>] Dobbertin, H., "The First Two Rounds of MD4 are Not One-
Way", Lecture Notes in Computer Science, Volume 1372, pp.
284-292, DOI 10.1007/3-540-69710-1_19, March 1998.
[<a id="ref-MD4LAST">MD4LAST</a>] den Boer, B. and A. Bosselaers, "An Attack on the Last Two
Rounds of MD4", Lecture Notes in Computer Science, Volume
576, pp. 194-203, DOI 10.1007/3-540-46766-1_14, 1992.
[<a id="ref-NEWATTACK">NEWATTACK</a>]
Coron, J., Joye, M., Naccache, D., and P. Paillier, "New
Attacks on PKCS #1 v1.5 Encryption", Lecture Notes in
Computer Science, Volume 1807, pp. 369-381,
DOI 10.1007/3-540-45539-6_25, May 2000.
[<a id="ref-OAEP">OAEP</a>] Bellare, M. and P. Rogaway, "Optimal Asymmetric Encryption
- How to Encrypt with RSA", Lecture Notes in Computer
Science, Volume 950, pp. 92-111, November 1995.
[<a id="ref-PA98">PA98</a>] Bellare, M., Desai, A., Pointcheval, D., and P. Rogaway,
"Relations Among Notions of Security for Public-Key
Encryption Schemes", Lecture Notes in Computer
Science, Volume 1462, pp. 26-45, DOI 10.1007/BFb0055718,
1998.
<span class="grey">Moriarty, et al. Informational [Page 50]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-51" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
[<a id="ref-PADDING">PADDING</a>] Coron, J., Naccache, D., and J. Stern, "On the Security of
RSA Padding", Lecture Notes in Computer Science, Volume
1666, pp. 1-18, DOI 10.1007/3-540-48405-1_1, December
1999.
[<a id="ref-PKCS1_22">PKCS1_22</a>] RSA Laboratories, "PKCS #1: RSA Cryptography Standard
Version 2.2", October 2012.
[<a id="ref-PREFIX">PREFIX</a>] Stevens, M., Lenstra, A., and B. de Weger, "Chosen-prefix
collisions for MD5 and applications", International
Journal of Applied Cryptography, Volume 2, No. 4, pp.
322-359, July 2012.
[<a id="ref-PSS">PSS</a>] Bellare, M. and P. Rogaway, "PSS: Provably Secure Encoding
Method for Digital Signatures", Submission to IEEE P1363a,
August 1998, <<a href="http://grouper.ieee.org/groups/1363/P1363a/contributions/pss-submission.pdf">http://grouper.ieee.org/groups/1363/</a>
<a href="http://grouper.ieee.org/groups/1363/P1363a/contributions/pss-submission.pdf">P1363a/contributions/pss-submission.pdf</a>>.
[<a id="ref-PSSPROOF">PSSPROOF</a>] Coron, J., "Optimal Security Proofs for PSS and Other
Signature Schemes", Lecture Notes in Computer
Science, Volume 2332, pp. 272-287,
DOI 10.1007/3-540-46035-7_18, 2002.
[<a id="ref-RFC1319">RFC1319</a>] Kaliski, B., "The MD2 Message-Digest Algorithm", <a href="./rfc1319">RFC 1319</a>,
DOI 10.17487/RFC1319, April 1992,
<<a href="http://www.rfc-editor.org/info/rfc1319">http://www.rfc-editor.org/info/rfc1319</a>>.
[<a id="ref-RFC1321">RFC1321</a>] Rivest, R., "The MD5 Message-Digest Algorithm", <a href="./rfc1321">RFC 1321</a>,
DOI 10.17487/RFC1321, April 1992,
<<a href="http://www.rfc-editor.org/info/rfc1321">http://www.rfc-editor.org/info/rfc1321</a>>.
[<a id="ref-RFC2313">RFC2313</a>] Kaliski, B., "PKCS #1: RSA Encryption Version 1.5",
<a href="./rfc2313">RFC 2313</a>, DOI 10.17487/RFC2313, March 1998,
<<a href="http://www.rfc-editor.org/info/rfc2313">http://www.rfc-editor.org/info/rfc2313</a>>.
[<a id="ref-RFC2315">RFC2315</a>] Kaliski, B., "PKCS #7: Cryptographic Message Syntax
Version 1.5", <a href="./rfc2315">RFC 2315</a>, DOI 10.17487/RFC2315, March 1998,
<<a href="http://www.rfc-editor.org/info/rfc2315">http://www.rfc-editor.org/info/rfc2315</a>>.
[<a id="ref-RFC2437">RFC2437</a>] Kaliski, B. and J. Staddon, "PKCS #1: RSA Cryptography
Specifications Version 2.0", <a href="./rfc2437">RFC 2437</a>,
DOI 10.17487/RFC2437, October 1998,
<<a href="http://www.rfc-editor.org/info/rfc2437">http://www.rfc-editor.org/info/rfc2437</a>>.
[<a id="ref-RFC3447">RFC3447</a>] Jonsson, J. and B. Kaliski, "Public-Key Cryptography
Standards (PKCS) #1: RSA Cryptography Specifications
Version 2.1", <a href="./rfc3447">RFC 3447</a>, DOI 10.17487/RFC3447, February
2003, <<a href="http://www.rfc-editor.org/info/rfc3447">http://www.rfc-editor.org/info/rfc3447</a>>.
<span class="grey">Moriarty, et al. Informational [Page 51]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-52" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
[<a id="ref-RFC5246">RFC5246</a>] Dierks, T. and E. Rescorla, "The Transport Layer Security
(TLS) Protocol Version 1.2", <a href="./rfc5246">RFC 5246</a>,
DOI 10.17487/RFC5246, August 2008,
<<a href="http://www.rfc-editor.org/info/rfc5246">http://www.rfc-editor.org/info/rfc5246</a>>.
[<a id="ref-RFC5652">RFC5652</a>] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70,
<a href="./rfc5652">RFC 5652</a>, DOI 10.17487/RFC5652, September 2009,
<<a href="http://www.rfc-editor.org/info/rfc5652">http://www.rfc-editor.org/info/rfc5652</a>>.
[<a id="ref-RFC5958">RFC5958</a>] Turner, S., "Asymmetric Key Packages", <a href="./rfc5958">RFC 5958</a>,
DOI 10.17487/RFC5958, August 2010,
<<a href="http://www.rfc-editor.org/info/rfc5958">http://www.rfc-editor.org/info/rfc5958</a>>.
[<a id="ref-RFC6149">RFC6149</a>] Turner, S. and L. Chen, "MD2 to Historic Status",
<a href="./rfc6149">RFC 6149</a>, DOI 10.17487/RFC6149, March 2011,
<<a href="http://www.rfc-editor.org/info/rfc6149">http://www.rfc-editor.org/info/rfc6149</a>>.
[<a id="ref-RFC7292">RFC7292</a>] Moriarty, K., Ed., Nystrom, M., Parkinson, S., Rusch, A.,
and M. Scott, "PKCS #12: Personal Information Exchange
Syntax v1.1", <a href="./rfc7292">RFC 7292</a>, DOI 10.17487/RFC7292, July 2014,
<<a href="http://www.rfc-editor.org/info/rfc7292">http://www.rfc-editor.org/info/rfc7292</a>>.
[<a id="ref-RSARABIN">RSARABIN</a>] Bellare, M. and P. Rogaway, "The Exact Security of Digital
Signatures - How to Sign with RSA and Rabin", Lecture
Notes in Computer Science, Volume 1070, pp. 399-416,
DOI 10.1007/3-540-68339-9_34, 1996.
[<a id="ref-RSATLS">RSATLS</a>] Jonsson, J. and B. Kaliski, "On the Security of RSA
Encryption in TLS", Lecture Notes in Computer
Science, Volume 2442, pp. 127-142,
DOI 10.1007/3-540-45708-9_9, 2002.
[<a id="ref-SHA1CRYPT">SHA1CRYPT</a>]
Wang, X., Yao, A., and F. Yao, "Cryptanalysis on SHA-1",
Lecture Notes in Computer Science, Volume 2442, pp.
127-142, February 2005,
<<a href="http://csrc.nist.gov/groups/ST/hash/documents/Wang_SHA1-New-Result.pdf">http://csrc.nist.gov/groups/ST/hash/documents/</a>
<a href="http://csrc.nist.gov/groups/ST/hash/documents/Wang_SHA1-New-Result.pdf">Wang_SHA1-New-Result.pdf</a>>.
[<a id="ref-SHOUP">SHOUP</a>] Shoup, V., "OAEP Reconsidered (Extended Abstract)",
Lecture Notes in Computer Science, Volume 2139, pp.
239-259, DOI 10.1007/3-540-44647-8_15, 2001.
[<a id="ref-SHS">SHS</a>] National Institute of Standards and Technology, "Secure
Hash Standard (SHS)", FIPS PUB 180-4, August 2015,
<<a href="http://dx.doi.org/10.6028/NIST.FIPS.180-4">http://dx.doi.org/10.6028/NIST.FIPS.180-4</a>>.
<span class="grey">Moriarty, et al. Informational [Page 52]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-53" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
[<a id="ref-SILVERMAN">SILVERMAN</a>]
Silverman, R., "A Cost-Based Security Analysis of
Symmetric and Asymmetric Key Lengths", RSA
Laboratories, Bulletin No. 13, 2000.
[<a id="ref-SIMMONS">SIMMONS</a>] Simmons, G., "Subliminal Communication is Easy Using the
DSA", Lecture Notes in Computer Science, Volume 765, pp.
218-232, DOI 10.1007/3-540-48285-7_18, 1994.
<span class="grey">Moriarty, et al. Informational [Page 53]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-54" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h2"><a class="selflink" id="appendix-A" href="#appendix-A">Appendix A</a>. ASN.1 Syntax</span>
<span class="h3"><a class="selflink" id="appendix-A.1" href="#appendix-A.1">A.1</a>. RSA Key Representation</span>
This section defines ASN.1 object identifiers for RSA public and
private keys and defines the types RSAPublicKey and RSAPrivateKey.
The intended application of these definitions includes X.509
certificates, PKCS #8 [<a href="./rfc5958" title=""Asymmetric Key Packages"">RFC5958</a>], and PKCS #12 [<a href="./rfc7292" title=""PKCS #12: Personal Information Exchange Syntax v1.1"">RFC7292</a>].
The object identifier rsaEncryption identifies RSA public and private
keys as defined in Appendices A.1.1 and A.1.2. The parameters field
has associated with this OID in a value of type AlgorithmIdentifier
SHALL have a value of type NULL.
rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }
The definitions in this section have been extended to support multi-
prime RSA, but they are backward compatible with previous versions.
<span class="h4"><a class="selflink" id="appendix-A.1.1" href="#appendix-A.1.1">A.1.1</a>. RSA Public Key Syntax</span>
An RSA public key should be represented with the ASN.1 type
RSAPublicKey:
RSAPublicKey ::= SEQUENCE {
modulus INTEGER, -- n
publicExponent INTEGER -- e
}
The fields of type RSAPublicKey have the following meanings:
o modulus is the RSA modulus n.
o publicExponent is the RSA public exponent e.
<span class="grey">Moriarty, et al. Informational [Page 54]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-55" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h4"><a class="selflink" id="appendix-A.1.2" href="#appendix-A.1.2">A.1.2</a>. RSA Private Key Syntax</span>
An RSA private key should be represented with the ASN.1 type
RSAPrivateKey:
RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}
The fields of type RSAPrivateKey have the following meanings:
o version is the version number, for compatibility with future
revisions of this document. It SHALL be 0 for this version of the
document, unless multi-prime is used; in which case, it SHALL be
1.
Version ::= INTEGER { two-prime(0), multi(1) }
(CONSTRAINED BY
{-- version must be multi if otherPrimeInfos present --})
o modulus is the RSA modulus n.
o publicExponent is the RSA public exponent e.
o privateExponent is the RSA private exponent d.
o prime1 is the prime factor p of n.
o prime2 is the prime factor q of n.
o exponent1 is d mod (p - 1).
o exponent2 is d mod (q - 1).
o coefficient is the CRT coefficient q^(-1) mod p.
<span class="grey">Moriarty, et al. Informational [Page 55]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-56" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
o otherPrimeInfos contains the information for the additional primes
r_3, ..., r_u, in order. It SHALL be omitted if version is 0 and
SHALL contain at least one instance of OtherPrimeInfo if version
is 1.
OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo
OtherPrimeInfo ::= SEQUENCE {
prime INTEGER, -- ri
exponent INTEGER, -- di
coefficient INTEGER -- ti
}
The fields of type OtherPrimeInfo have the following meanings:
o prime is a prime factor r_i of n, where i >= 3.
o exponent is d_i = d mod (r_i - 1).
o coefficient is the CRT coefficient t_i = (r_1 * r_2 * ... *
r_(i-1))^(-1) mod r_i.
Note: It is important to protect the RSA private key against both
disclosure and modification. Techniques for such protection are
outside the scope of this document. Methods for storing and
distributing private keys and other cryptographic data are described
in PKCS #12 and #15.
<span class="grey">Moriarty, et al. Informational [Page 56]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-57" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h3"><a class="selflink" id="appendix-A.2" href="#appendix-A.2">A.2</a>. Scheme Identification</span>
This section defines object identifiers for the encryption and
signature schemes. The schemes compatible with PKCS #1 v1.5 have the
same definitions as in PKCS #1 v1.5. The intended application of
these definitions includes X.509 certificates and PKCS #7.
Here are type identifier definitions for the PKCS #1 OIDs:
PKCS1Algorithms ALGORITHM-IDENTIFIER ::= {
{ OID rsaEncryption PARAMETERS NULL } |
{ OID md2WithRSAEncryption PARAMETERS NULL } |
{ OID md5WithRSAEncryption PARAMETERS NULL } |
{ OID sha1WithRSAEncryption PARAMETERS NULL } |
{ OID sha224WithRSAEncryption PARAMETERS NULL } |
{ OID sha256WithRSAEncryption PARAMETERS NULL } |
{ OID sha384WithRSAEncryption PARAMETERS NULL } |
{ OID sha512WithRSAEncryption PARAMETERS NULL } |
{ OID sha512-224WithRSAEncryption PARAMETERS NULL } |
{ OID sha512-256WithRSAEncryption PARAMETERS NULL } |
{ OID id-RSAES-OAEP PARAMETERS RSAES-OAEP-params } |
PKCS1PSourceAlgorithms |
{ OID id-RSASSA-PSS PARAMETERS RSASSA-PSS-params },
... -- Allows for future expansion --
}
<span class="h4"><a class="selflink" id="appendix-A.2.1" href="#appendix-A.2.1">A.2.1</a>. RSAES-OAEP</span>
The object identifier id-RSAES-OAEP identifies the RSAES-OAEP
encryption scheme.
id-RSAES-OAEP OBJECT IDENTIFIER ::= { pkcs-1 7 }
The parameters field associated with this OID in a value of type
AlgorithmIdentifier SHALL have a value of type RSAES-OAEP-params:
RSAES-OAEP-params ::= SEQUENCE {
hashAlgorithm [0] HashAlgorithm DEFAULT sha1,
maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1,
pSourceAlgorithm [2] PSourceAlgorithm DEFAULT pSpecifiedEmpty
}
The fields of type RSAES-OAEP-params have the following meanings:
o hashAlgorithm identifies the hash function. It SHALL be an
algorithm ID with an OID in the set OAEP-PSSDigestAlgorithms. For
a discussion of supported hash functions, see <a href="#appendix-B.1">Appendix B.1</a>.
<span class="grey">Moriarty, et al. Informational [Page 57]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-58" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
HashAlgorithm ::= AlgorithmIdentifier {
{OAEP-PSSDigestAlgorithms}
}
OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-sha1 PARAMETERS NULL }|
{ OID id-sha224 PARAMETERS NULL }|
{ OID id-sha256 PARAMETERS NULL }|
{ OID id-sha384 PARAMETERS NULL }|
{ OID id-sha512 PARAMETERS NULL }|
{ OID id-sha512-224 PARAMETERS NULL }|
{ OID id-sha512-256 PARAMETERS NULL },
... -- Allows for future expansion --
}
The default hash function is SHA-1:
sha1 HashAlgorithm ::= {
algorithm id-sha1,
parameters SHA1Parameters : NULL
}
SHA1Parameters ::= NULL
o maskGenAlgorithm identifies the mask generation function. It
SHALL be an algorithm ID with an OID in the set
PKCS1MGFAlgorithms, which for this version SHALL consist of
id-mgf1, identifying the MGF1 mask generation function (see
<a href="#appendix-B.2.1">Appendix B.2.1</a>). The parameters field associated with id-mgf1
SHALL be an algorithm ID with an OID in the set
OAEP-PSSDigestAlgorithms, identifying the hash function on which
MGF1 is based.
MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} }
PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-mgf1 PARAMETERS HashAlgorithm },
... -- Allows for future expansion --
}
o The default mask generation function is MGF1 with SHA-1:
mgf1SHA1 MaskGenAlgorithm ::= {
algorithm id-mgf1,
parameters HashAlgorithm : sha1
}
<span class="grey">Moriarty, et al. Informational [Page 58]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-59" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
o pSourceAlgorithm identifies the source (and possibly the value) of
the label L. It SHALL be an algorithm ID with an OID in the set
PKCS1PSourceAlgorithms, which for this version SHALL consist of
id-pSpecified, indicating that the label is specified explicitly.
The parameters field associated with id-pSpecified SHALL have a
value of type OCTET STRING, containing the label. In previous
versions of this specification, the term "encoding parameters" was
used rather than "label", hence the name of the type below.
PSourceAlgorithm ::= AlgorithmIdentifier {
{PKCS1PSourceAlgorithms}
}
PKCS1PSourceAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-pSpecified PARAMETERS EncodingParameters },
... -- Allows for future expansion --
}
id-pSpecified OBJECT IDENTIFIER ::= { pkcs-1 9 }
EncodingParameters ::= OCTET STRING(SIZE(0..MAX))
o The default label is an empty string (so that lHash will contain
the hash of the empty string):
pSpecifiedEmpty PSourceAlgorithm ::= {
algorithm id-pSpecified,
parameters EncodingParameters : emptyString
}
emptyString EncodingParameters ::= ''H
If all of the default values of the fields in RSAES-OAEP-params are
used, then the algorithm identifier will have the following value:
rSAES-OAEP-Default-Identifier RSAES-AlgorithmIdentifier ::= {
algorithm id-RSAES-OAEP,
parameters RSAES-OAEP-params : {
hashAlgorithm sha1,
maskGenAlgorithm mgf1SHA1,
pSourceAlgorithm pSpecifiedEmpty
}
}
RSAES-AlgorithmIdentifier ::= AlgorithmIdentifier {
{PKCS1Algorithms}
}
<span class="grey">Moriarty, et al. Informational [Page 59]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-60" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h4"><a class="selflink" id="appendix-A.2.2" href="#appendix-A.2.2">A.2.2</a>. RSAES-PKCS-v1_5</span>
The object identifier rsaEncryption (see <a href="#appendix-A.1">Appendix A.1</a>) identifies the
RSAES-PKCS1-v1_5 encryption scheme. The parameters field associated
with this OID in a value of type AlgorithmIdentifier SHALL have a
value of type NULL. This is the same as in PKCS #1 v1.5.
rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }
<span class="h4"><a class="selflink" id="appendix-A.2.3" href="#appendix-A.2.3">A.2.3</a>. RSASSA-PSS</span>
The object identifier id-RSASSA-PSS identifies the RSASSA-PSS
encryption scheme.
id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 }
The parameters field associated with this OID in a value of type
AlgorithmIdentifier SHALL have a value of type RSASSA-PSS-params:
RSASSA-PSS-params ::= SEQUENCE {
hashAlgorithm [0] HashAlgorithm DEFAULT sha1,
maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1,
saltLength [2] INTEGER DEFAULT 20,
trailerField [3] TrailerField DEFAULT trailerFieldBC
}
The fields of type RSASSA-PSS-params have the following meanings:
o hashAlgorithm identifies the hash function. It SHALL be an
algorithm ID with an OID in the set OAEP-PSSDigestAlgorithms (see
<a href="#appendix-A.2.1">Appendix A.2.1</a>). The default hash function is SHA-1.
o maskGenAlgorithm identifies the mask generation function. It
SHALL be an algorithm ID with an OID in the set PKCS1MGFAlgorithms
(see <a href="#appendix-A.2.1">Appendix A.2.1</a>). The default mask generation function is
MGF1 with SHA-1. For MGF1 (and more generally, for other mask
generation functions based on a hash function), it is RECOMMENDED
that the underlying hash function be the same as the one
identified by hashAlgorithm; see Note 2 in <a href="#section-9.1">Section 9.1</a> for further
comments.
o saltLength is the octet length of the salt. It SHALL be an
integer. For a given hashAlgorithm, the default value of
saltLength is the octet length of the hash value. Unlike the
other fields of type RSASSA-PSS-params, saltLength does not need
to be fixed for a given RSA key pair.
<span class="grey">Moriarty, et al. Informational [Page 60]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-61" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
o trailerField is the trailer field number, for compatibility with
IEEE 1363a [<a href="#ref-IEEE1363A">IEEE1363A</a>]. It SHALL be 1 for this version of the
document, which represents the trailer field with hexadecimal
value 0xbc. Other trailer fields (including the trailer field
HashID || 0xcc in IEEE 1363a) are not supported in this document.
TrailerField ::= INTEGER { trailerFieldBC(1) }
If the default values of the hashAlgorithm, maskGenAlgorithm, and
trailerField fields of RSASSA-PSS-params are used, then the algorithm
identifier will have the following value:
rSASSA-PSS-Default-Identifier RSASSA-AlgorithmIdentifier ::= {
algorithm id-RSASSA-PSS,
parameters RSASSA-PSS-params : {
hashAlgorithm sha1,
maskGenAlgorithm mgf1SHA1,
saltLength 20,
trailerField trailerFieldBC
}
}
RSASSA-AlgorithmIdentifier ::= AlgorithmIdentifier {
{PKCS1Algorithms}
}
Note: In some applications, the hash function underlying a signature
scheme is identified separately from the rest of the operations in
the signature scheme. For instance, in PKCS #7 [<a href="./rfc2315" title=""PKCS #7: Cryptographic Message Syntax Version 1.5"">RFC2315</a>], a hash
function identifier is placed before the message and a "digest
encryption" algorithm identifier (indicating the rest of the
operations) is carried with the signature. In order for PKCS #7 to
support the RSASSA-PSS signature scheme, an object identifier would
need to be defined for the operations in RSASSA-PSS after the hash
function (analogous to the RSAEncryption OID for the
RSASSA-PKCS1-v1_5 scheme). S/MIME Cryptographic Message Syntax (CMS)
[<a href="./rfc5652" title=""Cryptographic Message Syntax (CMS)"">RFC5652</a>] takes a different approach. Although a hash function
identifier is placed before the message, an algorithm identifier for
the full signature scheme may be carried with a CMS signature (this
is done for DSA signatures). Following this convention, the
id-RSASSA-PSS OID can be used to identify RSASSA-PSS signatures in
CMS. Since CMS is considered the successor to PKCS #7 and new
developments such as the addition of support for RSASSA-PSS will be
pursued with respect to CMS rather than PKCS #7, an OID for the "rest
of" RSASSA-PSS is not defined in this version of PKCS #1.
<span class="grey">Moriarty, et al. Informational [Page 61]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-62" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h4"><a class="selflink" id="appendix-A.2.4" href="#appendix-A.2.4">A.2.4</a>. RSASSA-PKCS-v1_5</span>
The object identifier for RSASSA-PKCS1-v1_5 SHALL be one of the
following. The choice of OID depends on the choice of hash
algorithm: MD2, MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512,
SHA-512/224, or SHA-512/256. Note that if either MD2 or MD5 is used,
then the OID is just as in PKCS #1 v1.5. For each OID, the
parameters field associated with this OID in a value of type
AlgorithmIdentifier SHALL have a value of type NULL. The OID should
be chosen in accordance with the following table:
Hash algorithm OID
------------------------------------------------------------
MD2 md2WithRSAEncryption ::= {pkcs-1 2}
MD5 md5WithRSAEncryption ::= {pkcs-1 4}
SHA-1 sha1WithRSAEncryption ::= {pkcs-1 5}
SHA-256 sha224WithRSAEncryption ::= {pkcs-1 14}
SHA-256 sha256WithRSAEncryption ::= {pkcs-1 11}
SHA-384 sha384WithRSAEncryption ::= {pkcs-1 12}
SHA-512 sha512WithRSAEncryption ::= {pkcs-1 13}
SHA-512/224 sha512-224WithRSAEncryption ::= {pkcs-1 15}
SHA-512/256 sha512-256WithRSAEncryption ::= {pkcs-1 16}
The EMSA-PKCS1-v1_5 encoding method includes an ASN.1 value of type
DigestInfo, where the type DigestInfo has the syntax
DigestInfo ::= SEQUENCE {
digestAlgorithm DigestAlgorithm,
digest OCTET STRING
}
digestAlgorithm identifies the hash function and SHALL be an
algorithm ID with an OID in the set PKCS1-v1-5DigestAlgorithms. For
a discussion of supported hash functions, see <a href="#appendix-B.1">Appendix B.1</a>.
<span class="grey">Moriarty, et al. Informational [Page 62]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-63" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
DigestAlgorithm ::= AlgorithmIdentifier {
{PKCS1-v1-5DigestAlgorithms}
}
PKCS1-v1-5DigestAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-md2 PARAMETERS NULL }|
{ OID id-md5 PARAMETERS NULL }|
{ OID id-sha1 PARAMETERS NULL }|
{ OID id-sha224 PARAMETERS NULL }|
{ OID id-sha256 PARAMETERS NULL }|
{ OID id-sha384 PARAMETERS NULL }|
{ OID id-sha512 PARAMETERS NULL }|
{ OID id-sha512-224 PARAMETERS NULL }|
{ OID id-sha512-256 PARAMETERS NULL }
}
<span class="h2"><a class="selflink" id="appendix-B" href="#appendix-B">Appendix B</a>. Supporting Techniques</span>
This section gives several examples of underlying functions
supporting the encryption schemes in <a href="#section-7">Section 7</a> and the encoding
methods in <a href="#section-9">Section 9</a>. A range of techniques is given here to allow
compatibility with existing applications as well as migration to new
techniques. While these supporting techniques are appropriate for
applications to implement, none of them is required to be
implemented. It is expected that profiles for PKCS #1 v2.2 will be
developed that specify particular supporting techniques.
This section also gives object identifiers for the supporting
techniques.
<span class="h3"><a class="selflink" id="appendix-B.1" href="#appendix-B.1">B.1</a>. Hash Functions</span>
Hash functions are used in the operations contained in Sections <a href="#section-7">7</a> and
9. Hash functions are deterministic, meaning that the output is
completely determined by the input. Hash functions take octet
strings of variable length and generate fixed-length octet strings.
The hash functions used in the operations contained in Sections <a href="#section-7">7</a> and
9 should generally be collision-resistant. This means that it is
infeasible to find two distinct inputs to the hash function that
produce the same output. A collision-resistant hash function also
has the desirable property of being one-way; this means that given an
output, it is infeasible to find an input whose hash is the specified
output. In addition to the requirements, the hash function should
yield a mask generation function (Appendix B.2) with pseudorandom
output.
<span class="grey">Moriarty, et al. Informational [Page 63]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-64" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Nine hash functions are given as examples for the encoding methods in
this document: MD2 [<a href="./rfc1319" title=""The MD2 Message-Digest Algorithm"">RFC1319</a>] (which was retired by [<a href="./rfc6149" title=""MD2 to Historic Status"">RFC6149</a>]), MD5
[<a href="./rfc1321" title=""The MD5 Message-Digest Algorithm"">RFC1321</a>], SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224,
and SHA-512/256 [<a href="#ref-SHS" title=""Secure Hash Standard (SHS)"">SHS</a>]. For the RSAES-OAEP encryption scheme and
EMSA-PSS encoding method, only SHA-1, SHA-224, SHA-256, SHA-384, SHA-
512, SHA-512/224, and SHA-512/256 are RECOMMENDED. For the EMSA-
PKCS1-v1_5 encoding method, SHA-224, SHA-256, SHA-384, SHA-512, SHA-
512/224, and SHA-512/256 are RECOMMENDED for new applications. MD2,
MD5, and SHA-1 are recommended only for compatibility with existing
applications based on PKCS #1 v1.5.
The object identifiers id-md2, id-md5, id-sha1, id-sha224, id-sha256,
id-sha384, id-sha512, id-sha512/224, and id-sha512/256 identify the
respective hash functions:
id-md2 OBJECT IDENTIFIER ::= {
iso (1) member-body (2) us (840) rsadsi (113549)
digestAlgorithm (2) 2
}
id-md5 OBJECT IDENTIFIER ::= {
iso (1) member-body (2) us (840) rsadsi (113549)
digestAlgorithm (2) 5
}
id-sha1 OBJECT IDENTIFIER ::= {
iso(1) identified-organization(3) oiw(14) secsig(3)
algorithms(2) 26
}
id-sha224 OBJECT IDENTIFIER ::= {
joint-iso-itu-t (2) country (16) us (840) organization (1)
gov (101) csor (3) nistalgorithm (4) hashalgs (2) 4
}
id-sha256 OBJECT IDENTIFIER ::= {
joint-iso-itu-t (2) country (16) us (840) organization (1)
gov (101) csor (3) nistalgorithm (4) hashalgs (2) 1
}
id-sha384 OBJECT IDENTIFIER ::= {
joint-iso-itu-t (2) country (16) us (840) organization (1)
gov (101) csor (3) nistalgorithm (4) hashalgs (2) 2
}
<span class="grey">Moriarty, et al. Informational [Page 64]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-65" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
id-sha512 OBJECT IDENTIFIER ::= {
joint-iso-itu-t (2) country (16) us (840) organization (1)
gov (101) csor (3) nistalgorithm (4) hashalgs (2) 3
}
id-sha512-224 OBJECT IDENTIFIER ::= {
joint-iso-itu-t (2) country (16) us (840) organization (1)
gov (101) csor (3) nistalgorithm (4) hashalgs (2) 5
}
id-sha512-256 OBJECT IDENTIFIER ::= {
joint-iso-itu-t (2) country (16) us (840) organization (1)
gov (101) csor (3) nistalgorithm (4) hashalgs (2) 6
}
The parameters field associated with these OIDs in a value of type
AlgorithmIdentifier SHALL have a value of type NULL.
The parameters field associated with id-md2 and id-md5 in a value of
type AlgorithmIdentifier shall have a value of type NULL.
The parameters field associated with id-sha1, id-sha224, id-sha256,
id-sha384, id-sha512, id-sha512/224, and id-sha512/256 should
generally be omitted, but if present, it shall have a value of type
NULL.
This is to align with the definitions originally promulgated by NIST.
For the SHA algorithms, implementations MUST accept
AlgorithmIdentifier values both without parameters and with NULL
parameters.
Exception: When formatting the DigestInfoValue in EMSA-PKCS1-v1_5
(see <a href="#section-9.2">Section 9.2</a>), the parameters field associated with id-sha1,
id-sha224, id-sha256, id-sha384, id-sha512, id-sha512/224, and
id-sha512/256 shall have a value of type NULL. This is to maintain
compatibility with existing implementations and with the numeric
information values already published for EMSA-PKCS1-v1_5, which are
also reflected in IEEE 1363a [<a href="#ref-IEEE1363A">IEEE1363A</a>].
Note: Version 1.5 of PKCS #1 also allowed for the use of MD4 in
signature schemes. The cryptanalysis of MD4 has progressed
significantly in the intervening years. For example, Dobbertin [<a href="#ref-MD4" title=""Cryptanalysis of MD4"">MD4</a>]
demonstrated how to find collisions for MD4 and that the first two
rounds of MD4 are not one-way [<a href="#ref-MD4FIRST" title=""The First Two Rounds of MD4 are Not One- Way"">MD4FIRST</a>]. Because of these results
and others (e.g., [<a href="#ref-MD4LAST" title=""An Attack on the Last Two Rounds of MD4"">MD4LAST</a>]), MD4 is NOT RECOMMENDED.
Further advances have been made in the cryptanalysis of MD2 and MD5,
especially after the findings of Stevens et al. [<a href="#ref-PREFIX" title=""Chosen-prefix collisions for MD5 and applications"">PREFIX</a>] on chosen-
<span class="grey">Moriarty, et al. Informational [Page 65]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-66" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
prefix collisions on MD5. MD2 and MD5 should be considered
cryptographically broken and removed from existing applications.
This version of the standard supports MD2 and MD5 just for backwards-
compatibility reasons.
There have also been advances in the cryptanalysis of SHA-1.
Particularly, the results of Wang et al. [<a href="#ref-SHA1CRYPT">SHA1CRYPT</a>] (which have
been independently verified by M. Cochran in his analysis [<a href="#ref-COCHRAN" title=""Notes on the Wang et al. 2^63 SHA-1 Differential Path"">COCHRAN</a>])
on using a differential path to find collisions in SHA-1, which
conclude that the security strength of the SHA-1 hashing algorithm is
significantly reduced. However, this reduction is not significant
enough to warrant the removal of SHA-1 from existing applications,
but its usage is only recommended for backwards-compatibility
reasons.
To address these concerns, only SHA-224, SHA-256, SHA-384, SHA-512,
SHA-512/224, and SHA-512/256 are RECOMMENDED for new applications.
As of today, the best (known) collision attacks against these hash
functions are generic attacks with complexity 2L/2, where L is the
bit length of the hash output. For the signature schemes in this
document, a collision attack is easily translated into a signature
forgery. Therefore, the value L / 2 should be at least equal to the
desired security level in bits of the signature scheme (a security
level of B bits means that the best attack has complexity 2B). The
same rule of thumb can be applied to RSAES-OAEP; it is RECOMMENDED
that the bit length of the seed (which is equal to the bit length of
the hash output) be twice the desired security level in bits.
<span class="h3"><a class="selflink" id="appendix-B.2" href="#appendix-B.2">B.2</a>. Mask Generation Functions</span>
A mask generation function takes an octet string of variable length
and a desired output length as input and outputs an octet string of
the desired length. There may be restrictions on the length of the
input and output octet strings, but such bounds are generally very
large. Mask generation functions are deterministic; the octet string
output is completely determined by the input octet string. The
output of a mask generation function should be pseudorandom: Given
one part of the output but not the input, it should be infeasible to
predict another part of the output. The provable security of
RSAES-OAEP and RSASSA-PSS relies on the random nature of the output
of the mask generation function, which in turn relies on the random
nature of the underlying hash.
One mask generation function is given here: MGF1, which is based on a
hash function. MGF1 coincides with the mask generation functions
defined in IEEE 1363 [<a href="#ref-IEEE1363" title=""Standard Specifications for Public Key Cryptography"">IEEE1363</a>] and ANSI X9.44 [<a href="#ref-ANSIX944" title=""Key Establishment Using Integer Factorization Cryptography"">ANSIX944</a>]. Future
versions of this document may define other mask generation functions.
<span class="grey">Moriarty, et al. Informational [Page 66]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-67" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h4"><a class="selflink" id="appendix-B.2.1" href="#appendix-B.2.1">B.2.1</a>. MGF1</span>
MGF1 is a mask generation function based on a hash function.
MGF1 (mgfSeed, maskLen)
Options:
Hash hash function (hLen denotes the length in octets of
the hash function output)
Input:
mgfSeed seed from which mask is generated, an octet string
maskLen intended length in octets of the mask, at most 2^32 hLen
Output:
mask mask, an octet string of length maskLen
Error: "mask too long"
Steps:
1. If maskLen > 2^32 hLen, output "mask too long" and stop.
2. Let T be the empty octet string.
3. For counter from 0 to \ceil (maskLen / hLen) - 1, do the
following:
A. Convert counter to an octet string C of length 4 octets (see
<a href="#section-4.1">Section 4.1</a>):
C = I2OSP (counter, 4) .
B. Concatenate the hash of the seed mgfSeed and C to the octet
string T:
T = T || Hash(mgfSeed || C) .
4. Output the leading maskLen octets of T as the octet string mask.
The object identifier id-mgf1 identifies the MGF1 mask generation
function:
id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 }
<span class="grey">Moriarty, et al. Informational [Page 67]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-68" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
The parameters field associated with this OID in a value of type
AlgorithmIdentifier shall have a value of type hashAlgorithm,
identifying the hash function on which MGF1 is based.
<span class="h2"><a class="selflink" id="appendix-C" href="#appendix-C">Appendix C</a>. ASN.1 Module</span>
-- PKCS #1 v2.2 ASN.1 Module
-- Revised October 27, 2012
-- This module has been checked for conformance with the
-- ASN.1 standard by the OSS ASN.1 Tools
PKCS-1 {
iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-1(1)
modules(0) pkcs-1(1)
}
DEFINITIONS EXPLICIT TAGS ::=
BEGIN
-- EXPORTS ALL
-- All types and values defined in this module are exported for use
-- in other ASN.1 modules.
IMPORTS
id-sha224, id-sha256, id-sha384, id-sha512, id-sha512-224,
id-sha512-256
FROM NIST-SHA2 {
joint-iso-itu-t(2) country(16) us(840) organization(1)
gov(101) csor(3) nistalgorithm(4) hashAlgs(2)
};
-- ============================
-- Basic object identifiers
-- ============================
-- The DER encoding of this in hexadecimal is:
-- (0x)06 08
-- 2A 86 48 86 F7 0D 01 01
--
pkcs-1 OBJECT IDENTIFIER ::= {
iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1
}
--
-- When rsaEncryption is used in an AlgorithmIdentifier,
<span class="grey">Moriarty, et al. Informational [Page 68]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-69" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
-- the parameters MUST be present and MUST be NULL.
--
rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }
--
-- When id-RSAES-OAEP is used in an AlgorithmIdentifier, the
-- parameters MUST be present and MUST be RSAES-OAEP-params.
--
id-RSAES-OAEP OBJECT IDENTIFIER ::= { pkcs-1 7 }
--
-- When id-pSpecified is used in an AlgorithmIdentifier, the
-- parameters MUST be an OCTET STRING.
--
id-pSpecified OBJECT IDENTIFIER ::= { pkcs-1 9 }
--
-- When id-RSASSA-PSS is used in an AlgorithmIdentifier, the
-- parameters MUST be present and MUST be RSASSA-PSS-params.
--
id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 }
--
-- When the following OIDs are used in an AlgorithmIdentifier,
-- the parameters MUST be present and MUST be NULL.
--
md2WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 2 }
md5WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 4 }
sha1WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 5 }
sha224WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 14 }
sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 11 }
sha384WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 12 }
sha512WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 13 }
sha512-224WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 15 }
sha512-256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 16 }
--
-- This OID really belongs in a module with the secsig OIDs.
--
id-sha1 OBJECT IDENTIFIER ::= {
iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2)
26
}
--
-- OIDs for MD2 and MD5, allowed only in EMSA-PKCS1-v1_5.
--
id-md2 OBJECT IDENTIFIER ::= {
<span class="grey">Moriarty, et al. Informational [Page 69]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-70" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 2
}
id-md5 OBJECT IDENTIFIER ::= {
iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5
}
--
-- When id-mgf1 is used in an AlgorithmIdentifier, the parameters
-- MUST be present and MUST be a HashAlgorithm, for example, sha1.
--
id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 }
-- ================
-- Useful types
-- ================
ALGORITHM-IDENTIFIER ::= CLASS {
&id OBJECT IDENTIFIER UNIQUE,
&Type OPTIONAL
}
WITH SYNTAX { OID &id [PARAMETERS &Type] }
-- Note: the parameter InfoObjectSet in the following definitions
-- allows a distinct information object set to be specified for sets
-- of algorithms such as:
-- DigestAlgorithms ALGORITHM-IDENTIFIER ::= {
-- { OID id-md2 PARAMETERS NULL }|
-- { OID id-md5 PARAMETERS NULL }|
-- { OID id-sha1 PARAMETERS NULL }
-- }
--
AlgorithmIdentifier { ALGORITHM-IDENTIFIER:InfoObjectSet } ::=
SEQUENCE {
algorithm
ALGORITHM-IDENTIFIER.&id({InfoObjectSet}),
parameters
ALGORITHM-IDENTIFIER.&Type({InfoObjectSet}{@.algorithm})
OPTIONAL
}
-- ==============
-- Algorithms
-- ==============
--
-- Allowed EME-OAEP and EMSA-PSS digest algorithms.
<span class="grey">Moriarty, et al. Informational [Page 70]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-71" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
--
OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-sha1 PARAMETERS NULL }|
{ OID id-sha224 PARAMETERS NULL }|
{ OID id-sha256 PARAMETERS NULL }|
{ OID id-sha384 PARAMETERS NULL }|
{ OID id-sha512 PARAMETERS NULL }|
{ OID id-sha512-224 PARAMETERS NULL }|
{ OID id-sha512-256 PARAMETERS NULL },
... -- Allows for future expansion --
}
--
-- Allowed EMSA-PKCS1-v1_5 digest algorithms.
--
PKCS1-v1-5DigestAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-md2 PARAMETERS NULL }|
{ OID id-md5 PARAMETERS NULL }|
{ OID id-sha1 PARAMETERS NULL }|
{ OID id-sha224 PARAMETERS NULL }|
{ OID id-sha256 PARAMETERS NULL }|
{ OID id-sha384 PARAMETERS NULL }|
{ OID id-sha512 PARAMETERS NULL }|
{ OID id-sha512-224 PARAMETERS NULL }|
{ OID id-sha512-256 PARAMETERS NULL }
}
-- When id-md2 and id-md5 are used in an AlgorithmIdentifier, the
-- parameters field shall have a value of type NULL.
-- When id-sha1, id-sha224, id-sha256, id-sha384, id-sha512,
-- id-sha512-224, and id-sha512-256 are used in an
-- AlgorithmIdentifier, the parameters (which are optional) SHOULD be
-- omitted, but if present, they SHALL have a value of type NULL.
-- However, implementations MUST accept AlgorithmIdentifier values
-- both without parameters and with NULL parameters.
-- Exception: When formatting the DigestInfoValue in EMSA-PKCS1-v1_5
-- (see <a href="#section-9.2">Section 9.2</a>), the parameters field associated with id-sha1,
-- id-sha224, id-sha256, id-sha384, id-sha512, id-sha512-224, and
-- id-sha512-256 SHALL have a value of type NULL. This is to
-- maintain compatibility with existing implementations and with the
-- numeric information values already published for EMSA-PKCS1-v1_5,
-- which are also reflected in IEEE 1363a.
sha1 HashAlgorithm ::= {
algorithm id-sha1,
parameters SHA1Parameters : NULL
<span class="grey">Moriarty, et al. Informational [Page 71]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-72" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
}
HashAlgorithm ::= AlgorithmIdentifier { {OAEP-PSSDigestAlgorithms} }
SHA1Parameters ::= NULL
--
-- Allowed mask generation function algorithms.
-- If the identifier is id-mgf1, the parameters are a HashAlgorithm.
--
PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-mgf1 PARAMETERS HashAlgorithm },
... -- Allows for future expansion --
}
--
-- Default AlgorithmIdentifier for id-RSAES-OAEP.maskGenAlgorithm and
-- id-RSASSA-PSS.maskGenAlgorithm.
--
mgf1SHA1 MaskGenAlgorithm ::= {
algorithm id-mgf1,
parameters HashAlgorithm : sha1
}
MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} }
--
-- Allowed algorithms for pSourceAlgorithm.
--
PKCS1PSourceAlgorithms ALGORITHM-IDENTIFIER ::= {
{ OID id-pSpecified PARAMETERS EncodingParameters },
... -- Allows for future expansion --
}
EncodingParameters ::= OCTET STRING(SIZE(0..MAX))
--
-- This identifier means that the label L is an empty string, so the
-- digest of the empty string appears in the RSA block before
-- masking.
--
pSpecifiedEmpty PSourceAlgorithm ::= {
algorithm id-pSpecified,
parameters EncodingParameters : emptyString
}
PSourceAlgorithm ::= AlgorithmIdentifier { {PKCS1PSourceAlgorithms} }
<span class="grey">Moriarty, et al. Informational [Page 72]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-73" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
emptyString EncodingParameters ::= ''H
--
-- Type identifier definitions for the PKCS #1 OIDs.
--
PKCS1Algorithms ALGORITHM-IDENTIFIER ::= {
{ OID rsaEncryption PARAMETERS NULL } |
{ OID md2WithRSAEncryption PARAMETERS NULL } |
{ OID md5WithRSAEncryption PARAMETERS NULL } |
{ OID sha1WithRSAEncryption PARAMETERS NULL } |
{ OID sha224WithRSAEncryption PARAMETERS NULL } |
{ OID sha256WithRSAEncryption PARAMETERS NULL } |
{ OID sha384WithRSAEncryption PARAMETERS NULL } |
{ OID sha512WithRSAEncryption PARAMETERS NULL } |
{ OID sha512-224WithRSAEncryption PARAMETERS NULL } |
{ OID sha512-256WithRSAEncryption PARAMETERS NULL } |
{ OID id-RSAES-OAEP PARAMETERS RSAES-OAEP-params } |
PKCS1PSourceAlgorithms |
{ OID id-RSASSA-PSS PARAMETERS RSASSA-PSS-params },
... -- Allows for future expansion --
}
-- ===================
-- Main structures
-- ===================
RSAPublicKey ::= SEQUENCE {
modulus INTEGER, -- n
publicExponent INTEGER -- e
}
--
-- Representation of RSA private key with information for the CRT
-- algorithm.
--
RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}
<span class="grey">Moriarty, et al. Informational [Page 73]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-74" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Version ::= INTEGER { two-prime(0), multi(1) }
(CONSTRAINED BY
{-- version MUST
be multi if otherPrimeInfos present --})
OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo
OtherPrimeInfo ::= SEQUENCE {
prime INTEGER, -- ri
exponent INTEGER, -- di
coefficient INTEGER -- ti
}
--
-- AlgorithmIdentifier.parameters for id-RSAES-OAEP.
-- Note that the tags in this Sequence are explicit.
--
RSAES-OAEP-params ::= SEQUENCE {
hashAlgorithm [0] HashAlgorithm DEFAULT sha1,
maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1,
pSourceAlgorithm [2] PSourceAlgorithm DEFAULT pSpecifiedEmpty
}
--
-- Identifier for default RSAES-OAEP algorithm identifier.
-- The DER encoding of this is in hexadecimal:
-- (0x)30 0D
-- 06 09
-- 2A 86 48 86 F7 0D 01 01 07
-- 30 00
-- Notice that the DER encoding of default values is "empty".
--
rSAES-OAEP-Default-Identifier RSAES-AlgorithmIdentifier ::= {
algorithm id-RSAES-OAEP,
parameters RSAES-OAEP-params : {
hashAlgorithm sha1,
maskGenAlgorithm mgf1SHA1,
pSourceAlgorithm pSpecifiedEmpty
}
}
RSAES-AlgorithmIdentifier ::= AlgorithmIdentifier {
{PKCS1Algorithms}
}
--
<span class="grey">Moriarty, et al. Informational [Page 74]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-75" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
-- AlgorithmIdentifier.parameters for id-RSASSA-PSS.
-- Note that the tags in this Sequence are explicit.
--
RSASSA-PSS-params ::= SEQUENCE {
hashAlgorithm [0] HashAlgorithm DEFAULT sha1,
maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1,
saltLength [2] INTEGER DEFAULT 20,
trailerField [3] TrailerField DEFAULT trailerFieldBC
}
TrailerField ::= INTEGER { trailerFieldBC(1) }
--
-- Identifier for default RSASSA-PSS algorithm identifier
-- The DER encoding of this is in hexadecimal:
-- (0x)30 0D
-- 06 09
-- 2A 86 48 86 F7 0D 01 01 0A
-- 30 00
-- Notice that the DER encoding of default values is "empty".
--
rSASSA-PSS-Default-Identifier RSASSA-AlgorithmIdentifier ::= {
algorithm id-RSASSA-PSS,
parameters RSASSA-PSS-params : {
hashAlgorithm sha1,
maskGenAlgorithm mgf1SHA1,
saltLength 20,
trailerField trailerFieldBC
}
}
RSASSA-AlgorithmIdentifier ::= AlgorithmIdentifier {
{PKCS1Algorithms}
}
--
-- Syntax for the EMSA-PKCS1-v1_5 hash identifier.
--
DigestInfo ::= SEQUENCE {
digestAlgorithm DigestAlgorithm,
digest OCTET STRING
}
DigestAlgorithm ::= AlgorithmIdentifier {
{PKCS1-v1-5DigestAlgorithms}
}
END
<span class="grey">Moriarty, et al. Informational [Page 75]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-76" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
<span class="h2"><a class="selflink" id="appendix-D" href="#appendix-D">Appendix D</a>. Revision History of PKCS #1</span>
Versions 1.0 - 1.5:
Versions 1.0 - 1.3 were distributed to participants in RSA Data
Security, Inc.'s Public-Key Cryptography Standards meetings in
February and March 1991.
Version 1.4 was part of the June 3, 1991 initial public release of
PKCS. Version 1.4 was published as NIST/OSI Implementors'
Workshop document SEC-SIG-91-18.
Version 1.5 incorporated several editorial changes, including
updates to the references and the addition of a revision history.
The following substantive changes were made:
* <a href="#section-10">Section 10</a>: "MD4 with RSA" signature and verification processes
were added.
* <a href="#section-11">Section 11</a>: md4WithRSAEncryption object identifier was added.
Version 1.5 was republished as [<a href="./rfc2313" title=""PKCS #1: RSA Encryption Version 1.5"">RFC2313</a>] (which was later
obsoleted by [<a href="./rfc2437" title=""PKCS #1: RSA Cryptography Specifications Version 2.0"">RFC2437</a>]).
Version 2.0:
Version 2.0 incorporated major editorial changes in terms of the
document structure and introduced the RSAES-OAEP encryption
scheme. This version continued to support the encryption and
signature processes in version 1.5, although the hash algorithm
MD4 was no longer allowed due to cryptanalytic advances in the
intervening years. Version 2.0 was republished as [<a href="./rfc2437" title=""PKCS #1: RSA Cryptography Specifications Version 2.0"">RFC2437</a>]
(which was later obsoleted by [<a href="./rfc3447" title=""Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1"">RFC3447</a>]).
Version 2.1:
Version 2.1 introduced multi-prime RSA and the RSASSA-PSS
signature scheme with appendix along with several editorial
improvements. This version continued to support the schemes in
version 2.0. Version 2.1 was republished as [<a href="./rfc3447" title=""Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1"">RFC3447</a>].
<span class="grey">Moriarty, et al. Informational [Page 76]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-77" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Version 2.2:
Version 2.2 updates the list of allowed hashing algorithms to
align them with FIPS 180-4 [<a href="#ref-SHS" title=""Secure Hash Standard (SHS)"">SHS</a>], therefore adding SHA-224,
SHA-512/224, and SHA-512/256. The following substantive changes
were made:
* Object identifiers for sha224WithRSAEncryption,
sha512-224WithRSAEncryption, and sha512-256WithRSAEncryption
were added.
* This version continues to support the schemes in version 2.1.
<span class="h2"><a class="selflink" id="appendix-E" href="#appendix-E">Appendix E</a>. About PKCS</span>
The Public-Key Cryptography Standards are specifications produced by
RSA Laboratories in cooperation with secure systems developers
worldwide for the purpose of accelerating the deployment of public-
key cryptography. First published in 1991 as a result of meetings
with a small group of early adopters of public-key technology, the
PKCS documents have become widely referenced and implemented.
Contributions from the PKCS series have become part of many formal
and de facto standards, including ANSI X9 and IEEE P1363 documents,
PKIX, Secure Electronic Transaction (SET), S/MIME, SSL/TLS, and
Wireless Application Protocol (WAP) / WAP Transport Layer Security
(WTLS).
Further development of most PKCS documents occurs through the IETF.
Suggestions for improvement are welcome.
<span class="grey">Moriarty, et al. Informational [Page 77]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-78" ></span>
<span class="grey"><a href="./rfc8017">RFC 8017</a> PKCS #1 v2.2 November 2016</span>
Acknowledgements
This document is based on a contribution of RSA Laboratories, the
research center of RSA Security Inc.
Authors' Addresses
Kathleen M. Moriarty (editor)
EMC Corporation
176 South Street
Hopkinton, MA 01748
United States of America
Email: kathleen.moriarty@emc.com
Burt Kaliski
Verisign
12061 Bluemont Way
Reston, VA 20190
United States of America
Email: bkaliski@verisign.com
URI: <a href="http://verisignlabs.com">http://verisignlabs.com</a>
Jakob Jonsson
Subset AB
Munkbrogtan 4
Stockholm SE-11127
Sweden
Phone: +46 8 428 687 43
Email: jakob.jonsson@subset.se
Andreas Rusch
RSA
345 Queen Street
Brisbane, QLD 4000
Australia
Email: andreas.rusch@rsa.com
Moriarty, et al. Informational [Page 78]
</pre>
|