From 3c0343f2c144cf9ccf6387b53d0fcad4399f55d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Thu, 14 Apr 2005 16:27:24 +0000 Subject: [PATCH] Add krb5_keyblock_init to allocate an fill in a keyblock from key data. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14791 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/keyblock.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/krb5/keyblock.c b/lib/krb5/keyblock.c index a2dc74973..5af23d67f 100644 --- a/lib/krb5/keyblock.c +++ b/lib/krb5/keyblock.c @@ -92,3 +92,41 @@ krb5_keyblock_get_enctype(const krb5_keyblock *block) { return block->keytype; } + +/* + * Fill in `key' with key data of type `enctype' from `data' of length + * `size'. Key should be freed using krb5_free_keyblock_contents. + */ + +krb5_error_code KRB5_LIB_FUNCTION +krb5_keyblock_init(krb5_context context, + krb5_enctype type, + const void *data, + size_t size, + krb5_keyblock *key) +{ + krb5_error_code ret; + size_t len; + + memset(key, 0, sizeof(*key)); + + ret = krb5_enctype_keysize(context, type, &len); + if (ret) + return ret; + + if (len != size) { + krb5_set_error_string(context, "Encryption key %d is %lu bytes " + "long, %lu was passed in", + type, (unsigned long)len, (unsigned long)size); + return KRB5_PROG_ETYPE_NOSUPP; + } + ret = krb5_data_copy(&key->keyvalue, data, len); + if(ret) { + krb5_set_error_string(context, "malloc failed: %lu", + (unsigned long)len); + return ret; + } + key->keytype = type; + + return 0; +}