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