* Initialize various tables. This need only be done once. It could even be * done at compile time, if the compiler were capable of that sort of thing. */
| 763 | * done at compile time, if the compiler were capable of that sort of thing. |
| 764 | */ |
| 765 | STATIC void init_des() |
| 766 | { |
| 767 | SLONG k; |
| 768 | static unsigned char perm[64]; // "static" for speed |
| 769 | |
| 770 | // table that converts chars "./0-9A-Za-z"to integers 0-63. |
| 771 | |
| 772 | for (int i = 0; i < 64; i++) |
| 773 | a64toi[itoa64[i]] = i; |
| 774 | |
| 775 | // PC1ROT - bit reverse, then PC1, then Rotate, then PC2. |
| 776 | |
| 777 | for (int i = 0; i < 64; i++) |
| 778 | perm[i] = 0; |
| 779 | |
| 780 | for (int i = 0; i < 64; i++) |
| 781 | { |
| 782 | if ((k = PC2[i]) == 0) |
| 783 | continue; |
| 784 | k += Rotates[0] - 1; |
| 785 | if ((k % 28) < Rotates[0]) |
| 786 | k -= 28; |
| 787 | k = PC1[k]; |
| 788 | if (k > 0) |
| 789 | { |
| 790 | k--; |
| 791 | k = (k | 07) - (k & 07); |
| 792 | k++; |
| 793 | } |
| 794 | perm[i] = (unsigned char) k; |
| 795 | } |
| 796 | init_perm(PC1ROT, perm, 8); |
| 797 | |
| 798 | // PC2ROT - PC2 inverse, then Rotate (once or twice), then PC2. |
| 799 | |
| 800 | for (int j = 0; j < 2; j++) |
| 801 | { |
| 802 | unsigned char pc2inv[64]; |
| 803 | for (int i = 0; i < 64; i++) |
| 804 | perm[i] = pc2inv[i] = 0; |
| 805 | |
| 806 | for (int i = 0; i < 64; i++) |
| 807 | { |
| 808 | if ((k = PC2[i]) == 0) |
| 809 | continue; |
| 810 | pc2inv[k - 1] = i + 1; |
| 811 | } |
| 812 | |
| 813 | for (int i = 0; i < 64; i++) |
| 814 | { |
| 815 | if ((k = PC2[i]) == 0) |
| 816 | continue; |
| 817 | k += j; |
| 818 | if ((k % 28) <= j) |
| 819 | k -= 28; |
| 820 | perm[i] = pc2inv[k]; |
| 821 | } |
| 822 | init_perm(PC2ROT[j], perm, 8); |
no test coverage detected