| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | a partial implementation of DES designed for use in the
|
|---|
| 5 | SMB authentication protocol
|
|---|
| 6 |
|
|---|
| 7 | Copyright (C) Andrew Tridgell 1998
|
|---|
| 8 |
|
|---|
| 9 | This program is free software; you can redistribute it and/or modify
|
|---|
| 10 | it under the terms of the GNU General Public License as published by
|
|---|
| 11 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 12 | (at your option) any later version.
|
|---|
| 13 |
|
|---|
| 14 | This program is distributed in the hope that it will be useful,
|
|---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | GNU General Public License for more details.
|
|---|
| 18 |
|
|---|
| 19 | You should have received a copy of the GNU General Public License
|
|---|
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | #include "includes.h"
|
|---|
| 24 |
|
|---|
| 25 | /* NOTES:
|
|---|
| 26 |
|
|---|
| 27 | This code makes no attempt to be fast! In fact, it is a very
|
|---|
| 28 | slow implementation
|
|---|
| 29 |
|
|---|
| 30 | This code is NOT a complete DES implementation. It implements only
|
|---|
| 31 | the minimum necessary for SMB authentication, as used by all SMB
|
|---|
| 32 | products (including every copy of Microsoft Windows95 ever sold)
|
|---|
| 33 |
|
|---|
| 34 | In particular, it can only do a unchained forward DES pass. This
|
|---|
| 35 | means it is not possible to use this code for encryption/decryption
|
|---|
| 36 | of data, instead it is only useful as a "hash" algorithm.
|
|---|
| 37 |
|
|---|
| 38 | There is no entry point into this code that allows normal DES operation.
|
|---|
| 39 |
|
|---|
| 40 | I believe this means that this code does not come under ITAR
|
|---|
| 41 | regulations but this is NOT a legal opinion. If you are concerned
|
|---|
| 42 | about the applicability of ITAR regulations to this code then you
|
|---|
| 43 | should confirm it for yourself (and maybe let me know if you come
|
|---|
| 44 | up with a different answer to the one above)
|
|---|
| 45 | */
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | #define uchar unsigned char
|
|---|
| 49 |
|
|---|
| 50 | static const uchar perm1[56] = {57, 49, 41, 33, 25, 17, 9,
|
|---|
| 51 | 1, 58, 50, 42, 34, 26, 18,
|
|---|
| 52 | 10, 2, 59, 51, 43, 35, 27,
|
|---|
| 53 | 19, 11, 3, 60, 52, 44, 36,
|
|---|
| 54 | 63, 55, 47, 39, 31, 23, 15,
|
|---|
| 55 | 7, 62, 54, 46, 38, 30, 22,
|
|---|
| 56 | 14, 6, 61, 53, 45, 37, 29,
|
|---|
| 57 | 21, 13, 5, 28, 20, 12, 4};
|
|---|
| 58 |
|
|---|
| 59 | static const uchar perm2[48] = {14, 17, 11, 24, 1, 5,
|
|---|
| 60 | 3, 28, 15, 6, 21, 10,
|
|---|
| 61 | 23, 19, 12, 4, 26, 8,
|
|---|
| 62 | 16, 7, 27, 20, 13, 2,
|
|---|
| 63 | 41, 52, 31, 37, 47, 55,
|
|---|
| 64 | 30, 40, 51, 45, 33, 48,
|
|---|
| 65 | 44, 49, 39, 56, 34, 53,
|
|---|
| 66 | 46, 42, 50, 36, 29, 32};
|
|---|
| 67 |
|
|---|
| 68 | static const uchar perm3[64] = {58, 50, 42, 34, 26, 18, 10, 2,
|
|---|
| 69 | 60, 52, 44, 36, 28, 20, 12, 4,
|
|---|
| 70 | 62, 54, 46, 38, 30, 22, 14, 6,
|
|---|
| 71 | 64, 56, 48, 40, 32, 24, 16, 8,
|
|---|
| 72 | 57, 49, 41, 33, 25, 17, 9, 1,
|
|---|
| 73 | 59, 51, 43, 35, 27, 19, 11, 3,
|
|---|
| 74 | 61, 53, 45, 37, 29, 21, 13, 5,
|
|---|
| 75 | 63, 55, 47, 39, 31, 23, 15, 7};
|
|---|
| 76 |
|
|---|
| 77 | static const uchar perm4[48] = { 32, 1, 2, 3, 4, 5,
|
|---|
| 78 | 4, 5, 6, 7, 8, 9,
|
|---|
| 79 | 8, 9, 10, 11, 12, 13,
|
|---|
| 80 | 12, 13, 14, 15, 16, 17,
|
|---|
| 81 | 16, 17, 18, 19, 20, 21,
|
|---|
| 82 | 20, 21, 22, 23, 24, 25,
|
|---|
| 83 | 24, 25, 26, 27, 28, 29,
|
|---|
| 84 | 28, 29, 30, 31, 32, 1};
|
|---|
| 85 |
|
|---|
| 86 | static const uchar perm5[32] = { 16, 7, 20, 21,
|
|---|
| 87 | 29, 12, 28, 17,
|
|---|
| 88 | 1, 15, 23, 26,
|
|---|
| 89 | 5, 18, 31, 10,
|
|---|
| 90 | 2, 8, 24, 14,
|
|---|
| 91 | 32, 27, 3, 9,
|
|---|
|
|---|