svn rev #21527: branches/mskrb-integ/src/lib/ crypto/ crypto/des/ crypto/dk/ ...

lhoward@MIT.EDU lhoward at MIT.EDU
Wed Dec 17 22:29:38 EST 2008


http://src.mit.edu/fisheye/changelog/krb5/?cs=21527
Commit By: lhoward
Log Message:
Add DES raw IOV support to libk5crypto, fix DES gss_wrap_iov()
implementation



Changed Files:
U   branches/mskrb-integ/src/lib/crypto/des/Makefile.in
U   branches/mskrb-integ/src/lib/crypto/des/des_int.h
A   branches/mskrb-integ/src/lib/crypto/des/f_aead.c
U   branches/mskrb-integ/src/lib/crypto/dk/dk_aead.c
U   branches/mskrb-integ/src/lib/crypto/enc_provider/Makefile.in
U   branches/mskrb-integ/src/lib/crypto/enc_provider/des.c
U   branches/mskrb-integ/src/lib/crypto/etypes.c
U   branches/mskrb-integ/src/lib/crypto/raw/Makefile.in
U   branches/mskrb-integ/src/lib/crypto/raw/raw.h
A   branches/mskrb-integ/src/lib/crypto/raw/raw_aead.c
U   branches/mskrb-integ/src/lib/gssapi/krb5/k5unsealiov.c
U   branches/mskrb-integ/src/lib/gssapi/krb5/util_crypt.c
Modified: branches/mskrb-integ/src/lib/crypto/des/Makefile.in
===================================================================
--- branches/mskrb-integ/src/lib/crypto/des/Makefile.in	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/des/Makefile.in	2008-12-18 03:29:36 UTC (rev 21527)
@@ -18,6 +18,7 @@
 	d3_cbc.o	\
 	d3_aead.o	\
 	d3_kysched.o	\
+	f_aead.o 	\
 	f_cbc.o 	\
 	f_cksum.o	\
 	f_parity.o 	\
@@ -31,6 +32,7 @@
 	$(OUTPRE)d3_cbc.$(OBJEXT)	\
 	$(OUTPRE)d3_aead.$(OBJEXT)	\
 	$(OUTPRE)d3_kysched.$(OBJEXT)	\
+	$(OUTPRE)f_aead.$(OBJEXT) 	\
 	$(OUTPRE)f_cbc.$(OBJEXT) 	\
 	$(OUTPRE)f_cksum.$(OBJEXT)	\
 	$(OUTPRE)f_parity.$(OBJEXT) 	\
@@ -44,6 +46,7 @@
 	$(srcdir)/d3_cbc.c	\
 	$(srcdir)/d3_aead.c	\
 	$(srcdir)/d3_kysched.c	\
+	$(srcdir)/f_aead.c	\
 	$(srcdir)/f_cbc.c	\
 	$(srcdir)/f_cksum.c	\
 	$(srcdir)/f_parity.c	\
@@ -145,6 +148,17 @@
   $(SRCTOP)/include/krb5/preauth_plugin.h $(SRCTOP)/include/port-sockets.h \
   $(SRCTOP)/include/socket-utils.h des_int.h f_cbc.c \
   f_tables.h
+f_aead.so f_aead.po $(OUTPRE)f_aead.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
+  $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
+  $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(SRCTOP)/include/k5-buf.h \
+  $(SRCTOP)/include/k5-err.h $(SRCTOP)/include/k5-gmt_mktime.h \
+  $(SRCTOP)/include/k5-int-pkinit.h $(SRCTOP)/include/k5-int.h \
+  $(SRCTOP)/include/k5-platform.h $(SRCTOP)/include/k5-plugin.h \
+  $(SRCTOP)/include/k5-thread.h $(SRCTOP)/include/kerberosIV/des.h \
+  $(SRCTOP)/include/krb5.h $(SRCTOP)/include/krb5/locate_plugin.h \
+  $(SRCTOP)/include/krb5/preauth_plugin.h $(SRCTOP)/include/port-sockets.h \
+  $(SRCTOP)/include/socket-utils.h des_int.h f_aead.c \
+  f_tables.h
 f_cksum.so f_cksum.po $(OUTPRE)f_cksum.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
   $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
   $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(SRCTOP)/include/k5-buf.h \

Modified: branches/mskrb-integ/src/lib/crypto/des/des_int.h
===================================================================
--- branches/mskrb-integ/src/lib/crypto/des/des_int.h	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/des/des_int.h	2008-12-18 03:29:36 UTC (rev 21527)
@@ -277,7 +277,18 @@
     ((enc ? krb5int_des_cbc_encrypt : krb5int_des_cbc_decrypt) \
      (in, out, length, schedule, ivec), 0)
 
+void
+krb5int_des_cbc_encrypt_iov(krb5_crypto_iov *data,
+			    unsigned long num_data,
+			    const mit_des_key_schedule schedule,
+			    mit_des_cblock ivec);
 
+void
+krb5int_des_cbc_decrypt_iov(krb5_crypto_iov *data,
+			    unsigned long num_data,
+			    const mit_des_key_schedule schedule,
+			    mit_des_cblock ivec);
+
 /* d3_procky.c */
 extern krb5_error_code mit_des3_process_key
 	(krb5_encrypt_block * eblock,

Added: branches/mskrb-integ/src/lib/crypto/des/f_aead.c
===================================================================
--- branches/mskrb-integ/src/lib/crypto/des/f_aead.c	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/des/f_aead.c	2008-12-18 03:29:36 UTC (rev 21527)
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2008 by the Massachusetts Institute of Technology.
+ * Copyright 1995 by Richard P. Basch.  All Rights Reserved.
+ * Copyright 1995 by Lehman Brothers, Inc.  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 Richard P. Basch, Lehman Brothers and M.I.T. not be used
+ * in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  Richard P. Basch,
+ * Lehman Brothers and M.I.T. make no representations about the suitability
+ * of this software for any purpose.  It is provided "as is" without
+ * express or implied warranty.
+ */
+
+#include "des_int.h"
+#include "f_tables.h"
+#include "../aead.h"
+
+void
+krb5int_des_cbc_encrypt_iov(krb5_crypto_iov *data,
+			    unsigned long num_data,
+			    const mit_des_key_schedule schedule,
+			    mit_des_cblock ivec)
+{
+    unsigned DES_INT32 left, right;
+    const unsigned DES_INT32 *kp;
+    const unsigned char *ip;
+    unsigned char *op;
+    struct iov_block_state input_pos, output_pos;
+    unsigned char iblock[MIT_DES_BLOCK_LENGTH];
+    unsigned char oblock[MIT_DES_BLOCK_LENGTH];
+
+    IOV_BLOCK_STATE_INIT(&input_pos);
+    IOV_BLOCK_STATE_INIT(&output_pos);
+
+    /*
+     * Get key pointer here.  This won't need to be reinitialized
+     */
+    kp = (const unsigned DES_INT32 *)schedule;
+
+    /*
+     * Initialize left and right with the contents of the initial
+     * vector.
+     */
+    if (ivec != NULL)
+	ip = ivec;
+    else
+	ip = mit_des_zeroblock;
+    GET_HALF_BLOCK(left, ip);
+    GET_HALF_BLOCK(right, ip);
+
+    /*
+     * Suitably initialized, now work the length down 8 bytes
+     * at a time.
+     */
+    for (;;) {
+	unsigned DES_INT32 temp;
+
+	ip = iblock;
+	op = oblock;
+
+	if (!krb5int_c_iov_get_block(iblock, MIT_DES_BLOCK_LENGTH, data, num_data, &input_pos))
+	    break;
+
+	if (input_pos.iov_pos == num_data)
+	    break;
+
+	GET_HALF_BLOCK(temp, ip);
+	left  ^= temp;
+	GET_HALF_BLOCK(temp, ip);
+	right ^= temp;
+
+	/*
+	 * Encrypt what we have
+	 */
+	DES_DO_ENCRYPT(left, right, kp);
+
+	/*
+	 * Copy the results out
+	 */
+	PUT_HALF_BLOCK(left, op);
+	PUT_HALF_BLOCK(right, op);
+
+	krb5int_c_iov_put_block(data, num_data, oblock, MIT_DES_BLOCK_LENGTH, &output_pos);
+    }
+
+    if (ivec != NULL)
+	memcpy(ivec, oblock, MIT_DES_BLOCK_LENGTH);
+}
+
+void
+krb5int_des_cbc_decrypt_iov(krb5_crypto_iov *data,
+			    unsigned long num_data,
+			    const mit_des_key_schedule schedule,
+			    mit_des_cblock ivec)
+{
+    unsigned DES_INT32 left, right;
+    const unsigned DES_INT32 *kp;
+    const unsigned char *ip;
+    unsigned DES_INT32 ocipherl, ocipherr;
+    unsigned DES_INT32 cipherl, cipherr;
+    unsigned char *op;
+    struct iov_block_state input_pos, output_pos;
+    unsigned char iblock[MIT_DES_BLOCK_LENGTH];
+    unsigned char oblock[MIT_DES_BLOCK_LENGTH];
+
+    IOV_BLOCK_STATE_INIT(&input_pos);
+    IOV_BLOCK_STATE_INIT(&output_pos);
+
+    /*
+     * Get key pointer here.  This won't need to be reinitialized
+     */
+    kp = (const unsigned DES_INT32 *)schedule;
+
+    /*
+     * Decrypting is harder than encrypting because of
+     * the necessity of remembering a lot more things.
+     * Should think about this a little more...
+     */
+
+    if (num_data == 0)
+	return;
+
+    /*
+     * Prime the old cipher with ivec.
+     */
+    if (ivec != NULL)
+	ip = ivec;
+    else
+	ip = mit_des_zeroblock;
+    GET_HALF_BLOCK(ocipherl, ip);
+    GET_HALF_BLOCK(ocipherr, ip);
+
+    /*
+     * Now do this in earnest until we run out of length.
+     */
+    for (;;) {
+	/*
+	 * Read a block from the input into left and
+	 * right.  Save this cipher block for later.
+	 */
+
+	if (!krb5int_c_iov_get_block(iblock, MIT_DES_BLOCK_LENGTH, data, num_data, &input_pos))
+	    break;
+
+	if (input_pos.iov_pos == num_data)
+	    break;
+
+	ip = iblock;
+	op = oblock;
+
+	GET_HALF_BLOCK(left, ip);
+	GET_HALF_BLOCK(right, ip);
+	cipherl = left;
+	cipherr = right;
+
+	/*
+	 * Decrypt this.
+	 */
+	DES_DO_DECRYPT(left, right, kp);
+
+	/*
+	 * Xor with the old cipher to get plain
+	 * text.  Output 8 or less bytes of this.
+	 */
+	left ^= ocipherl;
+	right ^= ocipherr;
+
+	PUT_HALF_BLOCK(left, op);
+	PUT_HALF_BLOCK(right, op);
+
+	/*
+	 * Save current cipher block here
+	 */
+	ocipherl = cipherl;
+	ocipherr = cipherr;
+
+	krb5int_c_iov_put_block(data, num_data, oblock, MIT_DES_BLOCK_LENGTH, &output_pos);
+    }
+
+    if (ivec != NULL)
+	memcpy(ivec, oblock, MIT_DES_BLOCK_LENGTH);
+}

Modified: branches/mskrb-integ/src/lib/crypto/dk/dk_aead.c
===================================================================
--- branches/mskrb-integ/src/lib/crypto/dk/dk_aead.c	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/dk/dk_aead.c	2008-12-18 03:29:36 UTC (rev 21527)
@@ -257,7 +257,7 @@
 
     if (blocksize == 0) {
 	/* Check for correct input length in CTS mode */
-        if (enc->block_size != 0 && cipherlen < enc->block_size)
+	if (enc->block_size != 0 && cipherlen < enc->block_size)
 	    return KRB5_BAD_MSIZE;
     } else {
 	/* Check that the input data is correctly padded */

Modified: branches/mskrb-integ/src/lib/crypto/enc_provider/Makefile.in
===================================================================
--- branches/mskrb-integ/src/lib/crypto/enc_provider/Makefile.in	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/enc_provider/Makefile.in	2008-12-18 03:29:36 UTC (rev 21527)
@@ -2,7 +2,7 @@
 myfulldir=lib/crypto/enc_provider
 mydir=lib/crypto/enc_provider
 BUILDTOP=$(REL)..$(S)..$(S)..
-LOCALINCLUDES = -I$(srcdir)/../des -I$(srcdir)/../arcfour -I$(srcdir)/../aes
+LOCALINCLUDES = -I$(srcdir)/../des -I$(srcdir)/../arcfour -I$(srcdir)/../aes -I$(srcdir)/..
 DEFS=
 
 ##DOS##BUILDTOP = ..\..\..

Modified: branches/mskrb-integ/src/lib/crypto/enc_provider/des.c
===================================================================
--- branches/mskrb-integ/src/lib/crypto/enc_provider/des.c	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/enc_provider/des.c	2008-12-18 03:29:36 UTC (rev 21527)
@@ -27,6 +27,7 @@
 #include "k5-int.h"
 #include "des_int.h"
 #include "enc_provider.h"
+#include "aead.h"
 
 static krb5_error_code
 k5_des_docrypt(const krb5_keyblock *key, const krb5_data *ivec,
@@ -106,6 +107,67 @@
     return(0);
 }
 
+static krb5_error_code
+k5_des_docrypt_iov(const krb5_keyblock *key, const krb5_data *ivec,
+		   krb5_crypto_iov *data, size_t num_data, int enc)
+{
+    mit_des_key_schedule schedule;
+    size_t input_length = 0;
+    int i;
+
+    /* key->enctype was checked by the caller */
+
+    if (key->length != 8)
+	return(KRB5_BAD_KEYSIZE);
+
+    for (i = 0; i < num_data; i++) {
+	const krb5_crypto_iov *iov = &data[i];
+
+	if (ENCRYPT_DATA_IOV(iov))
+	    input_length += iov->data.length;
+    }
+
+    if ((input_length % 8) != 0)
+	return(KRB5_BAD_MSIZE);
+    if (ivec && (ivec->length != 8))
+	return(KRB5_BAD_MSIZE);
+
+    switch (mit_des_key_sched(key->contents, schedule)) {
+    case -1:
+	return(KRB5DES_BAD_KEYPAR);
+    case -2:
+	return(KRB5DES_WEAK_KEY);
+    }
+
+    /* this has a return value, but the code always returns zero */
+    if (enc)
+	krb5int_des_cbc_encrypt_iov(data, num_data, schedule, ivec ? ivec->data : NULL);
+    else
+	krb5int_des_cbc_decrypt_iov(data, num_data, schedule, ivec ? ivec->data : NULL);
+
+    memset(schedule, 0, sizeof(schedule));
+
+    return(0);
+}
+
+static krb5_error_code
+k5_des_encrypt_iov(const krb5_keyblock *key,
+		    const krb5_data *ivec,
+		    krb5_crypto_iov *data,
+		    size_t num_data)
+{
+    return k5_des_docrypt_iov(key, ivec, data, num_data, 1);
+}
+
+static krb5_error_code
+k5_des_decrypt_iov(const krb5_keyblock *key,
+		   const krb5_data *ivec,
+		   krb5_crypto_iov *data,
+		   size_t num_data)
+{
+    return k5_des_docrypt_iov(key, ivec, data, num_data, 0);
+}
+
 const struct krb5_enc_provider krb5int_enc_des = {
     8,
     7, 8,
@@ -113,5 +175,7 @@
     k5_des_decrypt,
     k5_des_make_key,
     krb5int_des_init_state,
-    krb5int_default_free_state
+    krb5int_default_free_state,
+    k5_des_encrypt_iov,
+    k5_des_decrypt_iov
 };

Modified: branches/mskrb-integ/src/lib/crypto/etypes.c
===================================================================
--- branches/mskrb-integ/src/lib/crypto/etypes.c	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/etypes.c	2008-12-18 03:29:36 UTC (rev 21527)
@@ -86,7 +86,7 @@
       krb5int_des_string_to_key,
       NULL, /*PRF*/
       0,
-      NULL  /*AEAD*/ },
+      &krb5int_aead_raw  /*AEAD*/ },
     { ENCTYPE_DES3_CBC_RAW,
       "des3-cbc-raw", "Triple DES cbc mode raw",
       &krb5int_enc_des3, NULL,

Modified: branches/mskrb-integ/src/lib/crypto/raw/Makefile.in
===================================================================
--- branches/mskrb-integ/src/lib/crypto/raw/Makefile.in	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/raw/Makefile.in	2008-12-18 03:29:36 UTC (rev 21527)
@@ -2,6 +2,7 @@
 myfulldir=lib/crypto/raw
 mydir=lib/crypto/raw
 BUILDTOP=$(REL)..$(S)..$(S)..
+LOCALINCLUDES = -I$(srcdir)/..
 DEFS=
 
 ##DOS##BUILDTOP = ..\..\..
@@ -13,11 +14,11 @@
 
 RUN_SETUP = @KRB5_RUN_ENV@ KRB5_CONFIG=$(SRCTOP)/config-files/krb5.conf
 
-STLIBOBJS= raw_decrypt.o raw_encrypt.o
+STLIBOBJS= raw_decrypt.o raw_encrypt.o raw_aead.o
 
-OBJS= $(OUTPRE)raw_decrypt.$(OBJEXT) $(OUTPRE)raw_encrypt.$(OBJEXT)
+OBJS= $(OUTPRE)raw_decrypt.$(OBJEXT) $(OUTPRE)raw_encrypt.$(OBJEXT) $(OUTPRE)raw_aead.$(OBJEXT)
 
-SRCS= $(srcdir)/raw_decrypt.c $(srcdir)/raw_encrypt.c
+SRCS= $(srcdir)/raw_decrypt.c $(srcdir)/raw_encrypt.c $(srcdir)/raw_aead.c
 
 ##DOS##LIBOBJS = $(OBJS)
 
@@ -56,3 +57,13 @@
   $(SRCTOP)/include/krb5.h $(SRCTOP)/include/krb5/locate_plugin.h \
   $(SRCTOP)/include/krb5/preauth_plugin.h $(SRCTOP)/include/port-sockets.h \
   $(SRCTOP)/include/socket-utils.h raw.h raw_encrypt.c
+raw_aead.so raw_aead.po $(OUTPRE)raw_aead.$(OBJEXT): \
+  $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
+  $(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
+  $(COM_ERR_DEPS) $(SRCTOP)/include/k5-buf.h $(SRCTOP)/include/k5-err.h \
+  $(SRCTOP)/include/k5-gmt_mktime.h $(SRCTOP)/include/k5-int-pkinit.h \
+  $(SRCTOP)/include/k5-int.h $(SRCTOP)/include/k5-platform.h \
+  $(SRCTOP)/include/k5-plugin.h $(SRCTOP)/include/k5-thread.h \
+  $(SRCTOP)/include/krb5.h $(SRCTOP)/include/krb5/locate_plugin.h \
+  $(SRCTOP)/include/krb5/preauth_plugin.h $(SRCTOP)/include/port-sockets.h \
+  $(SRCTOP)/include/socket-utils.h raw.h raw_aead.c

Modified: branches/mskrb-integ/src/lib/crypto/raw/raw.h
===================================================================
--- branches/mskrb-integ/src/lib/crypto/raw/raw.h	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/raw/raw.h	2008-12-18 03:29:36 UTC (rev 21527)
@@ -44,3 +44,6 @@
 		const krb5_keyblock *key, krb5_keyusage usage,
 		const krb5_data *ivec, const krb5_data *input,
 		krb5_data *arg_output);
+
+extern const struct krb5_aead_provider krb5int_aead_raw;
+

Added: branches/mskrb-integ/src/lib/crypto/raw/raw_aead.c
===================================================================
--- branches/mskrb-integ/src/lib/crypto/raw/raw_aead.c	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/crypto/raw/raw_aead.c	2008-12-18 03:29:36 UTC (rev 21527)
@@ -0,0 +1,165 @@
+/*
+ * lib/crypto/raw/raw_aead.c
+ *
+ * Copyright 2008 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.
+ */
+
+
+#include "k5-int.h"
+#include "raw.h"
+#include "aead.h"
+
+#define K5CLENGTH 5 /* 32 bit net byte order integer + one byte seed */
+
+/* AEAD */
+
+static krb5_error_code
+krb5int_raw_crypto_length(const struct krb5_aead_provider *aead,
+			  const struct krb5_enc_provider *enc,
+			  const struct krb5_hash_provider *hash,
+			  krb5_cryptotype type,
+			  unsigned int *length)
+{
+    switch (type) {
+    case KRB5_CRYPTO_TYPE_PADDING:
+	*length = enc->block_size;
+	break;
+    default:
+	*length = 0;
+	break;
+    }
+
+    return 0;
+}
+
+static krb5_error_code
+krb5int_raw_encrypt_iov(const struct krb5_aead_provider *aead,
+			const struct krb5_enc_provider *enc,
+			const struct krb5_hash_provider *hash,
+			const krb5_keyblock *key,
+			krb5_keyusage usage,
+			const krb5_data *ivec,
+			krb5_crypto_iov *data,
+			size_t num_data)
+{
+    krb5_error_code ret;
+    krb5_crypto_iov *padding;
+    size_t i;
+    unsigned int blocksize = 0;
+    unsigned int plainlen = 0;
+    unsigned int padsize = 0;
+
+    ret = aead->crypto_length(aead, enc, hash, KRB5_CRYPTO_TYPE_PADDING, &blocksize);
+    if (ret != 0)
+	return ret;
+
+    for (i = 0; i < num_data; i++) {
+	krb5_crypto_iov *iov = &data[i];
+
+	if (iov->flags == KRB5_CRYPTO_TYPE_DATA)
+	    plainlen += iov->data.length;
+    }
+
+    if (blocksize != 0) {
+	/* Check that the input data is correctly padded */
+	if (plainlen % blocksize)
+	    padsize = blocksize - (plainlen % blocksize);
+    }
+
+    padding = krb5int_c_locate_iov(data, num_data, KRB5_CRYPTO_TYPE_PADDING);
+    if (padsize && (padding == NULL || padding->data.length < padsize))
+	return KRB5_BAD_MSIZE;
+
+    if (padding != NULL) {
+	memset(padding->data.data, 0, padsize);
+	padding->data.length = padsize;
+    }
+
+    assert(enc->encrypt_iov != NULL);
+
+    ret = enc->encrypt_iov(key, ivec, data, num_data); /* will update ivec */
+
+    return ret;
+}
+
+static krb5_error_code
+krb5int_raw_decrypt_iov(const struct krb5_aead_provider *aead,
+			const struct krb5_enc_provider *enc,
+			const struct krb5_hash_provider *hash,
+			const krb5_keyblock *key,
+			krb5_keyusage usage,
+			const krb5_data *ivec,
+			krb5_crypto_iov *data,
+			size_t num_data)
+{
+    krb5_error_code ret;
+    size_t i;
+    unsigned int blocksize = 0; /* careful, this is enc block size not confounder len */
+    unsigned int cipherlen = 0;
+
+    if (krb5int_c_locate_iov(data, num_data, KRB5_CRYPTO_TYPE_STREAM) != NULL) {
+	return krb5int_c_iov_decrypt_stream(aead, enc, hash, key,
+					    usage, ivec, data, num_data);
+    }
+
+
+    /* E(Confounder | Plaintext | Pad) | Checksum */
+
+    ret = aead->crypto_length(aead, enc, hash, KRB5_CRYPTO_TYPE_PADDING, &blocksize);
+    if (ret != 0)
+	return ret;
+
+    for (i = 0; i < num_data; i++) {
+	const krb5_crypto_iov *iov = &data[i];
+
+	if (ENCRYPT_DATA_IOV(iov))
+	    cipherlen += iov->data.length;
+    }
+
+    if (blocksize == 0) {
+	/* Check for correct input length in CTS mode */
+	if (enc->block_size != 0 && cipherlen < enc->block_size)
+	    return KRB5_BAD_MSIZE;
+    } else {
+	/* Check that the input data is correctly padded */
+	if ((cipherlen % blocksize) != 0)
+	    return KRB5_BAD_MSIZE;
+    }
+
+    /* Validate header and trailer lengths */
+
+    /* derive the keys */
+
+    /* decrypt the plaintext (header | data | padding) */
+    assert(enc->decrypt_iov != NULL);
+
+    ret = enc->decrypt_iov(key, ivec, data, num_data); /* will update ivec */
+
+    return ret;
+}
+
+const struct krb5_aead_provider krb5int_aead_raw = {
+    krb5int_raw_crypto_length,
+    krb5int_raw_encrypt_iov,
+    krb5int_raw_decrypt_iov
+};

Modified: branches/mskrb-integ/src/lib/gssapi/krb5/k5unsealiov.c
===================================================================
--- branches/mskrb-integ/src/lib/gssapi/krb5/k5unsealiov.c	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/gssapi/krb5/k5unsealiov.c	2008-12-18 03:29:36 UTC (rev 21527)
@@ -183,19 +183,6 @@
 		goto cleanup;
 	    }
 	}
-
-	/*
-	* For GSS_C_DCE_STYLE, the caller manages the padding, because the
-	* pad length is in the RPC PDU. The value of the padding may be
-	* uninitialized. For normal GSS, the last bytes of the decrypted
-	* data contain the pad length. kg_fixup_padding_iov() will find
-	* this and fixup the last data IOV and padding IOV appropriately.
-	*/
-	if ((ctx->gss_flags & GSS_C_DCE_STYLE) == 0) {
-	    retval = kg_fixup_padding_iov(&code, iov, iov_count);
-	    if (retval != GSS_S_COMPLETE)
-		goto cleanup;
-	}
 	conflen = kg_confounder_size(context, ctx->enc);
     }
 
@@ -275,6 +262,19 @@
 	goto cleanup;
     }
 
+    /*
+     * For GSS_C_DCE_STYLE, the caller manages the padding, because the
+     * pad length is in the RPC PDU. The value of the padding may be
+     * uninitialized. For normal GSS, the last bytes of the decrypted
+     * data contain the pad length. kg_fixup_padding_iov() will find
+     * this and fixup the last data IOV and padding IOV appropriately.
+     */
+    if ((ctx->gss_flags & GSS_C_DCE_STYLE) == 0) {
+	retval = kg_fixup_padding_iov(&code, iov, iov_count);
+	if (retval != GSS_S_COMPLETE)
+	    goto cleanup;
+    }
+
     if (conf_state != NULL)
 	*conf_state = (sealalg != 0xFFFF);
 

Modified: branches/mskrb-integ/src/lib/gssapi/krb5/util_crypt.c
===================================================================
--- branches/mskrb-integ/src/lib/gssapi/krb5/util_crypt.c	2008-12-18 02:38:43 UTC (rev 21526)
+++ branches/mskrb-integ/src/lib/gssapi/krb5/util_crypt.c	2008-12-18 03:29:36 UTC (rev 21527)
@@ -742,8 +742,12 @@
 
     data->buffer.length -= relative_padlength;
 
-    padding->buffer.length += relative_padlength;
-    padding->buffer.value = p - relative_padlength;
+    /*
+     * We don't really know DATA and PADDING buffers are
+     * adjacent in memory so just set PADDING to NULL.
+     */
+    padding->buffer.length = 0;
+    padding->buffer.value = NULL;
 
     return GSS_S_COMPLETE;
 }




More information about the cvs-krb5 mailing list