From 3c40c7f134b4e87baa43b0cacb435b6f96245e2f Mon Sep 17 00:00:00 2001 From: Zhanna Tsitkov Date: Mon, 3 Aug 2009 14:19:16 +0000 Subject: Crypto modularity proj: Separate files under crypto directory based on their functionality. Move Kerberos specific files into krb subdir and MIT specific - into builtin subdir. Place all tests into crypto_tests subfolder. bigredbutton: whitespace git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22477 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/crypto/crypto_tests/t_prng.c | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/lib/crypto/crypto_tests/t_prng.c (limited to 'src/lib/crypto/crypto_tests/t_prng.c') diff --git a/src/lib/crypto/crypto_tests/t_prng.c b/src/lib/crypto/crypto_tests/t_prng.c new file mode 100644 index 0000000..7df743b --- /dev/null +++ b/src/lib/crypto/crypto_tests/t_prng.c @@ -0,0 +1,87 @@ +/* + * lib/crypto/t_prng.c + * + * Copyright (C) 2001 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * This file contains tests for the PRNG code in Kerberos. It reads + * an input file, and writes an output file. It is assumed that the + * output file will be diffed against expected output to see whether + * regression tests pass. The input file has a very primitive format. + * It is composed of alternating seeds and outputs. The first line in + * the file is an integer source id from the krb5_c_randsource enum in + * krb5.h. Then an integer seed length is read. Then that many bytes + * (encoded in hex) are read; whitespace or newlines may be inserted + * between bytes. Then after the seed data is an integer describing + * how many bytes of output should be written. Then another source ID + * and seed length is read. If the seed length is 0, the source id is + * ignored and the seed is not seeded. + */ + +#include "k5-int.h" +#include + +int main () { + krb5_error_code ret; + krb5_data input, output; + unsigned int source_id, seed_length; + unsigned int i; + while (1) { + /* Read source*/ + if (scanf ("%u", &source_id ) == EOF ) + break; + /* Read seed length*/ + if (scanf ("%u", &seed_length) == EOF) + break; + if (seed_length ) { + unsigned int lc; + assert ((input.data = malloc(seed_length)) != NULL); + for (lc = seed_length; lc > 0; lc--) { + scanf ("%2x", &i); + input.data[seed_length-lc] = (unsigned) (i&0xff); + } + input.length = seed_length; + assert (krb5_c_random_add_entropy (0, source_id, &input) == 0); + free (input.data); + input.data = NULL; + } + if (scanf ("%u", &i) == EOF) + break; + if (i) { + assert ((output.data = malloc (i)) != NULL); + output.length = i; + ret = krb5_c_random_make_octets (0, &output); + if (ret) + printf ("failed\n"); + else { + for (; i > 0; i--) { + printf ("%02x", + (unsigned int) ((unsigned char ) output.data[output.length-i])); + } + printf ("\n"); + } + free (output.data); + output.data = NULL; + } + } + return (0); +} -- cgit v1.1