KIM: window settings
[krb5.git] / src / lib / des425 / t_pcbc.c
1 /*
2  * lib/des425/t_quad.c
3  *
4  * Copyright 2001 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  * 
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26
27
28 #include <stdio.h>
29 #include <errno.h>
30 #include "des_int.h"
31 #include "des.h"
32
33 char *progname;
34 int des_debug;
35
36 /* These test values were constructed by experimentation, because I
37    couldn't be bothered to look up the spec for the encryption mode
38    and see if any test vector is defined.  But really, the thing we
39    need to test is that the operation we use doesn't changed.  Like
40    with quad_cksum, compatibility is more important than strict
41    adherence to the spec, if we have to choose.  In any case, if you
42    have a useful test vector, send it in....  */
43 struct {
44     unsigned char text[32];
45     des_cblock out[4];
46 } tests[] = {
47     {
48         "Now is the time for all ",
49         {
50             {  0x7f, 0x81, 0x65, 0x41, 0x21, 0xdb, 0xd4, 0xcf, },
51             {  0xf8, 0xaa, 0x09, 0x90, 0xeb, 0xc7, 0x60, 0x2b, },
52             {  0x45, 0x3e, 0x4e, 0x65, 0x83, 0x6c, 0xf1, 0x98, },
53             {  0x4c, 0xfc, 0x69, 0x72, 0x23, 0xdb, 0x48, 0x78, }
54         }
55     }, {
56         "7654321 Now is the time for ",
57         {
58             {  0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4, },
59             {  0x6d, 0xec, 0xb4, 0x70, 0xa0, 0xe5, 0x6b, 0x15, },
60             {  0xae, 0xa6, 0xbf, 0x61, 0xed, 0x7d, 0x9c, 0x9f, },
61             {  0xf7, 0x17, 0x46, 0x3b, 0x8a, 0xb3, 0xcc, 0x88, }
62         }
63     }, {
64         "hi",
65         { {  0x76, 0x61, 0x0e, 0x8b, 0x23, 0xa4, 0x5f, 0x34, } }
66     },
67 };
68
69 /* 0x0123456789abcdef */
70 unsigned char default_key[8] = {
71     0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
72 };
73 des_cblock ivec = {
74     0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10
75 };
76
77 int
78 main(argc,argv)
79     int argc;
80     char *argv[];
81 {
82     int i;
83     int fail=0;
84     des_cblock out[32/8];
85     des_cblock out2[32/8];
86     des_key_schedule sked;
87
88     progname=argv[0];           /* salt away invoking program */
89
90     /* use known input and key */
91
92     for (i = 0; i < 3; i++) {
93         int wrong = 0, j, jmax;
94         des_key_sched (default_key, sked);
95         /* This could lose on alignment... */
96         des_pcbc_encrypt ((des_cblock *)&tests[i].text, out,
97                           strlen(tests[i].text) + 1, sked, &ivec, 1);
98         printf ("pcbc_encrypt(\"%s\") = {", tests[i].text);
99         jmax = (strlen (tests[i].text) + 8) & ~7U;
100         for (j = 0; j < jmax; j++) {
101             if (j % 8 == 0)
102                 printf ("\n\t");
103             printf (" 0x%02x,", out[j/8][j%8]);
104             if (out[j/8][j%8] != tests[i].out[j/8][j%8])
105                 wrong = 1;
106         }
107         printf ("\n}\n");
108
109         /* reverse it */
110         des_pcbc_encrypt (out, out2, jmax, sked, &ivec, 0);
111         if (strcmp ((char *)out2, tests[i].text)) {
112             printf ("decrypt failed\n");
113             wrong = 1;
114         } else
115             printf ("decrypt worked\n");
116
117         if (wrong) {
118             printf ("wrong result!\n");
119             fail = 1;
120         }
121     }
122     return fail;
123 }