+2003-03-04 Ken Raeburn <raeburn@mit.edu>
+
+ * aes_s2k.c, aes_s2k.h: New files.
+ * Makefile.in (STLIBOBJS, OBJS, SRCS): Build aes_s2k.
+ (LOCALINCLUDES): Add dk directory.
+ (GEN_OBJS): New variable.
+ (aes-gen): Use GEN_OBJS.
+
2003-02-28 Ezra Peisach <epeisach@bu.edu>
* Makefile.in (clean): Cleanup testing objects and outputs
myfulldir=lib/crypto/aes
mydir=aes
BUILDTOP=$(REL)..$(S)..$(S)..
-LOCALINCLUDES = -I$(srcdir)/..
+LOCALINCLUDES = -I$(srcdir)/.. -I$(srcdir)/../dk
##DOS##BUILDTOP = ..\..\..
##DOS##PREFIXDIR=aes
STLIBOBJS=\
aescrypt.o \
aestab.o \
- aeskey.o
-# aess2k.o
+ aeskey.o \
+ aes_s2k.o
OBJS=\
$(OUTPRE)aescrypt.$(OBJEXT) \
$(OUTPRE)aestab.$(OBJEXT) \
- $(OUTPRE)aeskey.$(OBJEXT)
-# $(OUTPRE)aess2k.$(OBJEXT)
+ $(OUTPRE)aeskey.$(OBJEXT) \
+ $(OUTPRE)aes_s2k.$(OBJEXT)
SRCS=\
$(srcdir)/aescrypt.c \
$(srcdir)/aestab.c \
- $(srcdir)/aeskey.c
-# $(srcdir)/aess2k.c
+ $(srcdir)/aeskey.c \
+ $(srcdir)/aes_s2k.c
+
+GEN_OBJS=\
+ $(OUTPRE)aescrypt.$(OBJEXT) \
+ $(OUTPRE)aestab.$(OBJEXT) \
+ $(OUTPRE)aeskey.$(OBJEXT)
##DOS##LIBOBJS = $(OBJS)
depend:: $(SRCS)
-aes-gen: aes-gen.o $(OBJS)
- $(CC) -o aes-gen aes-gen.o $(OBJS)
+aes-gen: aes-gen.o $(GEN_OBJS)
+ $(CC) -o aes-gen aes-gen.o $(GEN_OBJS)
run-aes-gen: aes-gen
./aes-gen > kresults.out
uitypes.h
aeskey.so aeskey.po $(OUTPRE)aeskey.$(OBJEXT): aeskey.c aesopt.h aes.h \
uitypes.h
+aes_s2k.so aes_s2k.po $(OUTPRE)aes_s2k.$(OBJEXT): aes_s2k.c $(SRCTOP)/include/k5-int.h \
+ $(BUILDTOP)/include/krb5/osconf.h $(BUILDTOP)/include/krb5/autoconf.h \
+ $(BUILDTOP)/include/krb5.h $(COM_ERR_DEPS) $(SRCTOP)/include/port-sockets.h \
+ $(SRCTOP)/include/socket-utils.h $(SRCTOP)/include/krb5/kdb.h \
+ $(BUILDTOP)/include/profile.h aes_s2k.h
--- /dev/null
+/* Insert MIT copyright here. */
+
+#include "k5-int.h"
+#include "dk.h"
+#include "aes_s2k.h"
+
+krb5_error_code
+krb5int_aes_string_to_key(const struct krb5_enc_provider *enc,
+ const krb5_data *string,
+ const krb5_data *salt,
+ const krb5_data *params,
+ krb5_keyblock *key)
+{
+ unsigned long iter_count;
+ krb5_data out;
+ static const krb5_data usage = { KV5M_DATA, 8, "kerberos" };
+ krb5_error_code err;
+
+ if (params) {
+ unsigned char *p = (unsigned char *) params->data;
+ if (params->length != 4)
+ return KRB5_ERR_BAD_S2K_PARAMS;
+ iter_count = ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]));
+ if (iter_count == 0) {
+ iter_count = (1L << 16) << 16;
+ if (((iter_count >> 16) >> 16) != 1)
+ return KRB5_ERR_BAD_S2K_PARAMS;
+ }
+ } else
+ iter_count = 0xb000L;
+
+ /*
+ * Dense key space, no parity bits or anything, so take a shortcut
+ * and use the key contents buffer for the generated bytes.
+ */
+ out.data = (char *) key->contents;
+ out.length = key->length;
+ if (out.length != 16 && out.length != 32)
+ return KRB5_CRYPTO_INTERNAL;
+
+ err = krb5int_pbkdf2_hmac_sha1 (&out, iter_count, string, salt);
+ if (err) {
+ memset(out.data, 0, out.length);
+ return err;
+ }
+
+ err = krb5_derive_key (enc, key, key, &usage);
+ if (err) {
+ memset(out.data, 0, out.length);
+ return err;
+ }
+ return 0;
+}
--- /dev/null
+extern krb5_error_code
+krb5int_aes_string_to_key (const struct krb5_enc_provider *,
+ const krb5_data *, const krb5_data *,
+ const krb5_data *, krb5_keyblock *key);