1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/crypto/crypto_tests/t_prng.c */
4 * Copyright (C) 2001 by the Massachusetts Institute of Technology.
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.
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.
28 * This file contains tests for the PRNG code in Kerberos. It reads
29 * an input file, and writes an output file. It is assumed that the
30 * output file will be diffed against expected output to see whether
31 * regression tests pass. The input file has a very primitive format.
32 * It is composed of alternating seeds and outputs. The first line in
33 * the file is an integer source id from the krb5_c_randsource enum in
34 * krb5.h. Then an integer seed length is read. Then that many bytes
35 * (encoded in hex) are read; whitespace or newlines may be inserted
36 * between bytes. Then after the seed data is an integer describing
37 * how many bytes of output should be written. Then another source ID
38 * and seed length is read. If the seed length is 0, the source id is
39 * ignored and the seed is not seeded.
47 krb5_data input, output;
48 unsigned int source_id, seed_length;
52 if (scanf ("%u", &source_id ) == EOF )
55 if (scanf ("%u", &seed_length) == EOF)
59 ret = alloc_data(&input, seed_length);
61 for (lc = seed_length; lc > 0; lc--) {
63 input.data[seed_length-lc] = (unsigned) (i&0xff);
65 ret = krb5_c_random_add_entropy (0, source_id, &input);
70 if (scanf ("%u", &i) == EOF)
73 ret = alloc_data(&output, i);
75 ret = krb5_c_random_make_octets (0, &output);
81 (unsigned int) ((unsigned char ) output.data[output.length-i]));