Revision 10832,
1.5 KB
checked in by brlewis, 27 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r10831,
which included commits to RCS files with non-trunk default branches.
|
Line | |
---|
1 | /* |
---|
2 | * This file, and the certdata file, shamelessly stolen |
---|
3 | * from Phil Karn's DES implementation. |
---|
4 | */ |
---|
5 | |
---|
6 | #ifdef HAVE_CONFIG_H |
---|
7 | #include <config.h> |
---|
8 | #endif |
---|
9 | |
---|
10 | #include <stdio.h> |
---|
11 | #include <sys/types.h> |
---|
12 | #include <sys/socket.h> |
---|
13 | #include <netinet/in.h> |
---|
14 | |
---|
15 | #ifndef DES |
---|
16 | # define DES |
---|
17 | #endif |
---|
18 | |
---|
19 | #include "ntp_stdlib.h" |
---|
20 | |
---|
21 | u_char ekeys[128]; |
---|
22 | u_char dkeys[128]; |
---|
23 | |
---|
24 | static void get8 P((u_int32 *)); |
---|
25 | static void put8 P((u_int32 *)); |
---|
26 | |
---|
27 | void |
---|
28 | main() |
---|
29 | { |
---|
30 | u_int32 key[2], plain[2], cipher[2], answer[2], temp; |
---|
31 | int i; |
---|
32 | int test; |
---|
33 | int fail; |
---|
34 | |
---|
35 | for(test = 0; !feof(stdin); test++){ |
---|
36 | get8(key); |
---|
37 | DESauth_subkeys(key, ekeys, dkeys); |
---|
38 | printf(" K: "); put8(key); |
---|
39 | get8(plain); |
---|
40 | printf(" P: "); put8(plain); |
---|
41 | get8(answer); |
---|
42 | printf(" C: "); put8(answer); |
---|
43 | for (i = 0; i < 2; i++) |
---|
44 | cipher[i] = htonl(plain[i]); |
---|
45 | DESauth_des(cipher, ekeys); |
---|
46 | for (i = 0; i < 2; i++) { |
---|
47 | temp = ntohl(cipher[i]); |
---|
48 | if (temp != answer[i]) |
---|
49 | break; |
---|
50 | } |
---|
51 | |
---|
52 | fail = 0; |
---|
53 | if (i != 2) { |
---|
54 | printf(" Encrypt FAIL"); |
---|
55 | fail++; |
---|
56 | } |
---|
57 | DESauth_des(cipher, dkeys); |
---|
58 | for (i = 0; i < 2; i++) { |
---|
59 | temp = ntohl(cipher[i]); |
---|
60 | if (temp != plain[i]) |
---|
61 | break; |
---|
62 | } |
---|
63 | if (i != 2) { |
---|
64 | printf(" Decrypt FAIL"); |
---|
65 | fail++; |
---|
66 | } |
---|
67 | if (fail == 0) |
---|
68 | printf(" OK"); |
---|
69 | printf("\n"); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | static void |
---|
74 | get8(lp) |
---|
75 | u_int32 *lp; |
---|
76 | { |
---|
77 | int t; |
---|
78 | u_int32 l[2]; |
---|
79 | int i; |
---|
80 | |
---|
81 | l[0] = l[1] = 0; |
---|
82 | for (i = 0; i < 8; i++) { |
---|
83 | scanf("%2x", &t); |
---|
84 | if (feof(stdin)) |
---|
85 | exit(0); |
---|
86 | l[i / 4] <<= 8; |
---|
87 | l[i / 4] |= (u_int32)(t & 0xff); |
---|
88 | } |
---|
89 | *lp = l[0]; |
---|
90 | *(lp + 1) = l[1]; |
---|
91 | } |
---|
92 | |
---|
93 | static void |
---|
94 | put8(lp) |
---|
95 | u_int32 *lp; |
---|
96 | { |
---|
97 | int i; |
---|
98 | |
---|
99 | |
---|
100 | for(i = 0; i < 2; i++) |
---|
101 | printf("%08lx", (u_long)(*lp++)); |
---|
102 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.