When iterating through the keytab in krb5_rd_req(), do not
[krb5.git] / src / lib / crypto / builtin / t_cf2.c
1 /*
2  * lib/crypto/t_cf2.c
3  *
4  * Copyright (C) 2004, 2009 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  * This file contains tests for theKRB-FX-CF2 code in Kerberos, based
27  *on the PRF regression tests.  It reads an input file, and writes an
28  *output file.  It is assumed that the output file will be diffed
29  *against expected output to see whether regression tests pass.  The
30  *input file is a very primitive format.
31  *First line: enctype
32  *second line: key to pass to string2key; also used as salt
33  *Third line: second key to pass to string2key
34  *fourth line: pepper1
35  *fifth line:  pepper2
36  *scanf is used to read the file, so interior spaces are not permitted.  The program outputs the hex bytes of the key.
37  */
38 #include <krb5.h>
39
40 #include <assert.h>
41 #include <stdio.h>
42 #include <string.h>
43
44 int main () {
45   char pepper1[1024], pepper2[1024];
46   krb5_keyblock *k1 = NULL, *k2 = NULL, *out = NULL;
47   krb5_data s2k;
48   unsigned int i;
49   while (1) {
50     krb5_enctype enctype;
51     char s[1025];
52
53     if (scanf( "%d", &enctype) == EOF)
54       break;
55     if (scanf("%1024s", &s[0]) == EOF)
56       break;
57     assert (krb5_init_keyblock(0, enctype, 0, &k1) == 0);
58     s2k.data = &s[0];
59     s2k.length = strlen(s);
60     assert(krb5_c_string_to_key (0, enctype, &s2k, &s2k, k1) == 0);
61     if (scanf("%1024s", &s[0]) == EOF)
62       break;
63     assert (krb5_init_keyblock(0, enctype, 0, &k2) == 0);
64     s2k.data = &s[0];
65     s2k.length = strlen(s);
66     assert(krb5_c_string_to_key (0, enctype, &s2k, &s2k, k2) == 0);
67     if (scanf("%1024s %1024s", pepper1, pepper2) == EOF)
68       break;
69     assert(krb5_c_fx_cf2_simple(0, k1, pepper1,
70                                 k2, pepper2, &out) ==0);
71     i = out->length;
72     for (; i > 0; i--) {
73       printf ("%02x",
74               (unsigned int) ((unsigned char) out->contents[out->length-i]));
75     }
76     printf ("\n");
77
78     krb5_free_keyblock(0,out);
79     out = NULL;
80           
81     krb5_free_keyblock(0, k1);
82     k1 = NULL;
83     krb5_free_keyblock(0, k2);
84     k2 =  NULL;
85   }
86
87   return (0);
88 }