Add krb5_init_keyblock
authorSam Hartman <hartmans@mit.edu>
Fri, 29 Mar 2002 05:05:27 +0000 (05:05 +0000)
committerSam Hartman <hartmans@mit.edu>
Fri, 29 Mar 2002 05:05:27 +0000 (05:05 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14312 dc483132-0cff-0310-8789-dd5450dbe970

src/include/ChangeLog
src/include/krb5.hin
src/lib/crypto/ChangeLog
src/lib/crypto/Makefile.in
src/lib/crypto/t_encrypt.c
src/lib/krb5/krb/ChangeLog
src/lib/krb5/krb/Makefile.in
src/lib/krb5/krb/init_keyblock.c [new file with mode: 0644]

index c1bf46f2fcd7da13f4b014d2742c5cecde568b33..31b99b289d87805a66b6a6ce221344933c7f8cb9 100644 (file)
@@ -1,3 +1,7 @@
+2002-03-28  Sam Hartman  <hartmans@mit.edu>
+
+       * krb5.hin: krb5_init_keyblock new function.
+
 2002-03-28  Ken Raeburn  <raeburn@mit.edu>
 
        * k5-int.h: Include errno.h.
index 348d803d5772cf5380a147c65b122d8f015dbe79..743fdfc616e677a2d534c56de602d24214e6d651 100644 (file)
@@ -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 *,
index aeb31e6782f0f396f1e876c549d80806a1a0f48c..a1e6355ca27de464e8c28bb9a1edbe3ab81f592e 100644 (file)
@@ -1,3 +1,7 @@
+2002-03-28  Sam Hartman  <hartmans@mit.edu>
+
+       * t_encrypt.c (main): Test krb5_init_keyblock
+
 2002-01-14  Sam Hartman  <hartmans@mit.edu>
 
        * t_prng.expected: Update to be correct for 0 MSW in v_i calculation.
index a51f06efe5aec1fd941891fbbffcd5f6d6f53a23..59102ad6b7060844975e4721f52e84aa5699399c 100644 (file)
@@ -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
index a52c22659a2181dabe3aa9d8cacf1f21e8ce719a..e15d2d03975bc9113146c4b98b824e5efe76ffe1 100644 (file)
@@ -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);
index 3d6aa46f62d66987f91064f4ed702a6afd1a1415..f2d3ac21f7fe14879775ddb836f3bdd9b98a5cfc 100644 (file)
@@ -1,3 +1,9 @@
+2002-03-28  Sam Hartman  <hartmans@mit.edu>
+
+       * Makefile.in :  New file init_keyblock.c
+
+       * init_keyblock.c (krb5_init_keyblock): New function
+
 2002-03-16  Sam Hartman  <hartmans@mit.edu>
 
        * fwd_tgt.c (krb5_fwd_tgt_creds): Fix merge of patch from 1.2.2
index 558a13d2cb400d751668ca5624cbd8c41f00b864..77a6987c778977cf32c6891e8cb253dda979e846 100644 (file)
@@ -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 (file)
index 0000000..a6feeea
--- /dev/null
@@ -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 <assert.h>
+
+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;
+}