From fdeda13512d0a90457ca0004d4cc1e9c8e8c410a Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Fri, 29 Mar 2002 05:05:27 +0000 Subject: [PATCH] Add krb5_init_keyblock git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14312 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/ChangeLog | 4 +++ src/include/krb5.hin | 9 +++++ src/lib/crypto/ChangeLog | 4 +++ src/lib/crypto/Makefile.in | 2 +- src/lib/crypto/t_encrypt.c | 25 +++++++------ src/lib/krb5/krb/ChangeLog | 6 ++++ src/lib/krb5/krb/Makefile.in | 3 ++ src/lib/krb5/krb/init_keyblock.c | 61 ++++++++++++++++++++++++++++++++ 8 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 src/lib/krb5/krb/init_keyblock.c diff --git a/src/include/ChangeLog b/src/include/ChangeLog index c1bf46f2f..31b99b289 100644 --- a/src/include/ChangeLog +++ b/src/include/ChangeLog @@ -1,3 +1,7 @@ +2002-03-28 Sam Hartman + + * krb5.hin: krb5_init_keyblock new function. + 2002-03-28 Ken Raeburn * k5-int.h: Include errno.h. diff --git a/src/include/krb5.hin b/src/include/krb5.hin index 348d803d5..743fdfc61 100644 --- a/src/include/krb5.hin +++ b/src/include/krb5.hin @@ -1483,6 +1483,15 @@ krb5_boolean KRB5_CALLCONV krb5_principal_compare (krb5_context, krb5_const_principal, krb5_const_principal); +krb5_error_code KRB5_CALLCONV krb5_init_keyblock + (krb5_context, krb5_enctype enctype, + size_t length, krb5_keyblock **out); + /* Initialize a new keyblock and allocate storage + * for the contents of the key, which will be freed along + * with the keyblock when krb5_free_keyblock is called. + * It is legal to pass in a length of 0, in which + * case contents are left unallocated. + */ krb5_error_code KRB5_CALLCONV krb5_copy_keyblock (krb5_context, const krb5_keyblock *, diff --git a/src/lib/crypto/ChangeLog b/src/lib/crypto/ChangeLog index aeb31e678..a1e6355ca 100644 --- a/src/lib/crypto/ChangeLog +++ b/src/lib/crypto/ChangeLog @@ -1,3 +1,7 @@ +2002-03-28 Sam Hartman + + * t_encrypt.c (main): Test krb5_init_keyblock + 2002-01-14 Sam Hartman * t_prng.expected: Update to be correct for 0 MSW in v_i calculation. diff --git a/src/lib/crypto/Makefile.in b/src/lib/crypto/Makefile.in index a51f06efe..59102ad6b 100644 --- a/src/lib/crypto/Makefile.in +++ b/src/lib/crypto/Makefile.in @@ -153,7 +153,7 @@ t_nfold$(EXEEXT): t_nfold.$(OBJEXT) nfold.$(OBJEXT) $(CC_LINK) -o $@ t_nfold.$(OBJEXT) nfold.$(OBJEXT) t_encrypt$(EXEEXT): t_encrypt.$(OBJEXT) nfold.$(OBJEXT) - $(CC_LINK) -o $@ t_encrypt.$(OBJEXT) -lk5crypto -lcom_err + $(CC_LINK) -o $@ t_encrypt.$(OBJEXT) -lkrb5 -lk5crypto -lcom_err t_prng$(EXEEXT): t_prng.$(OBJEXT) $(CC_LINK) -o $@ t_prng.$(OBJEXT) -lk5crypto -lcom_err diff --git a/src/lib/crypto/t_encrypt.c b/src/lib/crypto/t_encrypt.c index a52c22659..e15d2d039 100644 --- a/src/lib/crypto/t_encrypt.c +++ b/src/lib/crypto/t_encrypt.c @@ -62,7 +62,7 @@ main () size_t len; krb5_enc_data enc_out; krb5_error_code retval; - krb5_keyblock key; + krb5_keyblock *key; in.data = "This is a test.\n"; in.length = strlen (in.data); @@ -75,30 +75,29 @@ main () for (i = 0; interesting_enctypes[i]; i++) { krb5_enctype enctype = interesting_enctypes [i]; printf ("Testing enctype %d\n", enctype); + test ("Initializing a keyblock", + krb5_init_keyblock (context, enctype, 0, &key)); test ("Generating random key", - krb5_c_make_random_key (context, enctype, &key)); + krb5_c_make_random_key (context, enctype, key)); enc_out.ciphertext.data = out.data; enc_out.ciphertext.length = out.length; /* We use an intermediate `len' because size_t may be different size than `int' */ - krb5_c_encrypt_length (context, key.enctype, in.length, &len); + krb5_c_encrypt_length (context, key->enctype, in.length, &len); enc_out.ciphertext.length = len; test ("Encrypting", - krb5_c_encrypt (context, &key, 7, 0, &in, &enc_out)); + krb5_c_encrypt (context, key, 7, 0, &in, &enc_out)); test ("Decrypting", - krb5_c_decrypt (context, &key, 7, 0, &enc_out, &check)); + krb5_c_decrypt (context, key, 7, 0, &enc_out, &check)); test ("init_state", - krb5_c_init_state (context, &key, 7, &state)); + krb5_c_init_state (context, key, 7, &state)); test ("Encrypting with state", - krb5_c_encrypt (context, &key, 7, &state, &in, &enc_out)); + krb5_c_encrypt (context, key, 7, &state, &in, &enc_out)); test ("Decrypting", - krb5_c_decrypt (context, &key, 7, 0, &enc_out, &check)); + krb5_c_decrypt (context, key, 7, 0, &enc_out, &check)); test ("free_state", - krb5_c_free_state (context, &key, &state)); - if(key.contents) { - free(key.contents); - key.contents = NULL; - } + krb5_c_free_state (context, key, &state)); + krb5_free_keyblock (context, key); } free(out.data); diff --git a/src/lib/krb5/krb/ChangeLog b/src/lib/krb5/krb/ChangeLog index 3d6aa46f6..f2d3ac21f 100644 --- a/src/lib/krb5/krb/ChangeLog +++ b/src/lib/krb5/krb/ChangeLog @@ -1,3 +1,9 @@ +2002-03-28 Sam Hartman + + * Makefile.in : New file init_keyblock.c + + * init_keyblock.c (krb5_init_keyblock): New function + 2002-03-16 Sam Hartman * fwd_tgt.c (krb5_fwd_tgt_creds): Fix merge of patch from 1.2.2 diff --git a/src/lib/krb5/krb/Makefile.in b/src/lib/krb5/krb/Makefile.in index 558a13d2c..77a6987c7 100644 --- a/src/lib/krb5/krb/Makefile.in +++ b/src/lib/krb5/krb/Makefile.in @@ -55,6 +55,7 @@ STLIBOBJS= \ in_tkt_pwd.o \ in_tkt_sky.o \ init_ctx.o \ + init_keyblock.o \ kdc_rep_dc.o \ kfree.o \ mk_cred.o \ @@ -140,6 +141,7 @@ OBJS= $(OUTPRE)addr_comp.$(OBJEXT) \ $(OUTPRE)in_tkt_pwd.$(OBJEXT) \ $(OUTPRE)in_tkt_sky.$(OBJEXT) \ $(OUTPRE)init_ctx.$(OBJEXT) \ + $(OUTPRE)init_keyblock.$(OBJEXT) \ $(OUTPRE)kdc_rep_dc.$(OBJEXT) \ $(OUTPRE)kfree.$(OBJEXT) \ $(OUTPRE)mk_cred.$(OBJEXT) \ @@ -226,6 +228,7 @@ SRCS= $(srcdir)/addr_comp.c \ $(srcdir)/in_tkt_pwd.c \ $(srcdir)/in_tkt_sky.c \ $(srcdir)/init_ctx.c \ + $(srcdir)/init_keyblock.c \ $(srcdir)/kdc_rep_dc.c \ $(srcdir)/kfree.c \ $(srcdir)/mk_cred.c \ diff --git a/src/lib/krb5/krb/init_keyblock.c b/src/lib/krb5/krb/init_keyblock.c new file mode 100644 index 000000000..a6feeeaf1 --- /dev/null +++ b/src/lib/krb5/krb/init_keyblock.c @@ -0,0 +1,61 @@ +/* + * lib/krb5/krb/init_keyblock.c + * + * Copyright (C) 2002 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. + * + * + * + * krb5_init_keyblock- a function to set up + * an empty keyblock + */ + + +#include "k5-int.h" +#include + +krb5_error_code KRB5_CALLCONV krb5_init_keyblock + (krb5_context context, krb5_enctype enctype, + size_t length, krb5_keyblock **out) +{ + krb5_keyblock *kb; + kb = malloc (sizeof(krb5_keyblock)); + assert (out); + *out = NULL; + if (!kb) { + return ENOMEM; + } + kb->magic = KV5M_KEYBLOCK; + kb->enctype = enctype; + kb->length = length; + if(length) { + kb->contents = malloc (length); + if(!kb->contents) { + free (kb); + return ENOMEM; + } + } else { + kb->contents = NULL; + } + *out = kb; + return 0; +} -- 2.26.2