Merge lorikeet-heimdal -r 787 into Samba4 tree.
authorAndrew Bartlett <abartlet@samba.org>
Tue, 18 Mar 2008 23:17:42 +0000 (10:17 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 18 Mar 2008 23:17:42 +0000 (10:17 +1100)
Andrew Bartlett

155 files changed:
source/heimdal/kdc/digest.c
source/heimdal/kdc/kaserver.c
source/heimdal/kdc/kdc_locl.h
source/heimdal/kdc/kerberos5.c
source/heimdal/kdc/krb5tgs.c
source/heimdal/kdc/log.c
source/heimdal/kdc/pkinit.c
source/heimdal/kuser/kinit.c
source/heimdal/lib/asn1/asn1-common.h
source/heimdal/lib/asn1/canthandle.asn1
source/heimdal/lib/asn1/der.c
source/heimdal/lib/asn1/digest.asn1
source/heimdal/lib/asn1/gen.c
source/heimdal/lib/asn1/gen_encode.c
source/heimdal/lib/asn1/k5.asn1
source/heimdal/lib/asn1/lex.c
source/heimdal/lib/asn1/parse.c
source/heimdal/lib/asn1/parse.h
source/heimdal/lib/asn1/pkinit.asn1
source/heimdal/lib/asn1/rfc2459.asn1
source/heimdal/lib/com_err/lex.c
source/heimdal/lib/com_err/parse.c
source/heimdal/lib/com_err/parse.h
source/heimdal/lib/gssapi/gssapi/gssapi_krb5.h
source/heimdal/lib/gssapi/gssapi_mech.h
source/heimdal/lib/gssapi/krb5/acquire_cred.c
source/heimdal/lib/gssapi/krb5/external.c
source/heimdal/lib/gssapi/krb5/gsskrb5-private.h
source/heimdal/lib/gssapi/krb5/gsskrb5_locl.h
source/heimdal/lib/gssapi/krb5/init_sec_context.c
source/heimdal/lib/gssapi/krb5/set_cred_option.c
source/heimdal/lib/gssapi/mech/context.c
source/heimdal/lib/gssapi/mech/gss_accept_sec_context.c
source/heimdal/lib/gssapi/mech/gss_krb5.c
source/heimdal/lib/gssapi/mech/gss_mech_switch.c
source/heimdal/lib/gssapi/mech/gss_release_oid_set.c
source/heimdal/lib/gssapi/spnego/accept_sec_context.c
source/heimdal/lib/gssapi/spnego/compat.c
source/heimdal/lib/gssapi/spnego/context_stubs.c
source/heimdal/lib/gssapi/spnego/external.c
source/heimdal/lib/gssapi/spnego/init_sec_context.c
source/heimdal/lib/gssapi/spnego/spnego-private.h
source/heimdal/lib/hcrypto/bn.c
source/heimdal/lib/hcrypto/bn.h
source/heimdal/lib/hcrypto/camellia-ntt.c [new file with mode: 0644]
source/heimdal/lib/hcrypto/camellia-ntt.h [new file with mode: 0644]
source/heimdal/lib/hcrypto/camellia.c [new file with mode: 0644]
source/heimdal/lib/hcrypto/camellia.h [new file with mode: 0644]
source/heimdal/lib/hcrypto/dh-imath.c
source/heimdal/lib/hcrypto/dh.c
source/heimdal/lib/hcrypto/evp.c
source/heimdal/lib/hcrypto/evp.h
source/heimdal/lib/hcrypto/hmac.c
source/heimdal/lib/hcrypto/imath/imath.c
source/heimdal/lib/hcrypto/rand.c
source/heimdal/lib/hcrypto/rsa.c
source/heimdal/lib/hcrypto/rsa.h
source/heimdal/lib/hdb/dbinfo.c [new file with mode: 0644]
source/heimdal/lib/hdb/hdb-protos.h
source/heimdal/lib/hdb/hdb.h
source/heimdal/lib/hdb/hdb_locl.h
source/heimdal/lib/hdb/keys.c
source/heimdal/lib/hdb/mkey.c
source/heimdal/lib/hx509/ca.c
source/heimdal/lib/hx509/cert.c
source/heimdal/lib/hx509/cms.c
source/heimdal/lib/hx509/crypto.c
source/heimdal/lib/hx509/env.c
source/heimdal/lib/hx509/error.c
source/heimdal/lib/hx509/hx509-private.h
source/heimdal/lib/hx509/hx509-protos.h
source/heimdal/lib/hx509/hx509.h
source/heimdal/lib/hx509/hx509_err.et
source/heimdal/lib/hx509/hx_locl.h
source/heimdal/lib/hx509/keyset.c
source/heimdal/lib/hx509/ks_file.c
source/heimdal/lib/hx509/ks_keychain.c
source/heimdal/lib/hx509/ks_p11.c
source/heimdal/lib/hx509/lock.c
source/heimdal/lib/hx509/name.c
source/heimdal/lib/hx509/peer.c
source/heimdal/lib/hx509/print.c
source/heimdal/lib/hx509/revoke.c
source/heimdal/lib/krb5/acache.c
source/heimdal/lib/krb5/add_et_list.c
source/heimdal/lib/krb5/addr_families.c
source/heimdal/lib/krb5/asn1_glue.c
source/heimdal/lib/krb5/auth_context.c
source/heimdal/lib/krb5/cache.c
source/heimdal/lib/krb5/context.c
source/heimdal/lib/krb5/convert_creds.c
source/heimdal/lib/krb5/copy_host_realm.c
source/heimdal/lib/krb5/creds.c
source/heimdal/lib/krb5/crypto.c
source/heimdal/lib/krb5/data.c
source/heimdal/lib/krb5/eai_to_heim_errno.c
source/heimdal/lib/krb5/error_string.c
source/heimdal/lib/krb5/expand_hostname.c
source/heimdal/lib/krb5/fcache.c
source/heimdal/lib/krb5/get_cred.c
source/heimdal/lib/krb5/get_for_creds.c
source/heimdal/lib/krb5/get_in_tkt.c
source/heimdal/lib/krb5/init_creds.c
source/heimdal/lib/krb5/init_creds_pw.c
source/heimdal/lib/krb5/kcm.c
source/heimdal/lib/krb5/keytab.c
source/heimdal/lib/krb5/keytab_file.c
source/heimdal/lib/krb5/keytab_keyfile.c
source/heimdal/lib/krb5/keytab_krb4.c
source/heimdal/lib/krb5/krb5-private.h
source/heimdal/lib/krb5/krb5-protos.h
source/heimdal/lib/krb5/krb5.h
source/heimdal/lib/krb5/krb5_ccapi.h
source/heimdal/lib/krb5/krb5_locl.h
source/heimdal/lib/krb5/mcache.c
source/heimdal/lib/krb5/n-fold.c
source/heimdal/lib/krb5/pac.c
source/heimdal/lib/krb5/pkinit.c
source/heimdal/lib/krb5/plugin.c
source/heimdal/lib/krb5/principal.c
source/heimdal/lib/krb5/rd_priv.c
source/heimdal/lib/krb5/rd_req.c
source/heimdal/lib/krb5/send_to_kdc.c
source/heimdal/lib/krb5/store.c
source/heimdal/lib/krb5/store_emem.c
source/heimdal/lib/krb5/transited.c
source/heimdal/lib/krb5/v4_glue.c
source/heimdal/lib/ntlm/heimntlm-protos.h
source/heimdal/lib/ntlm/heimntlm.h
source/heimdal/lib/ntlm/ntlm.c
source/heimdal/lib/vers/print_version.c
source/heimdal/lib/wind/bidi.c [new file with mode: 0644]
source/heimdal/lib/wind/bidi_table.c [new file with mode: 0644]
source/heimdal/lib/wind/bidi_table.h [new file with mode: 0644]
source/heimdal/lib/wind/combining.c [new file with mode: 0644]
source/heimdal/lib/wind/combining_table.c [new file with mode: 0644]
source/heimdal/lib/wind/combining_table.h [new file with mode: 0644]
source/heimdal/lib/wind/errorlist.c [new file with mode: 0644]
source/heimdal/lib/wind/errorlist_table.c [new file with mode: 0644]
source/heimdal/lib/wind/errorlist_table.h [new file with mode: 0644]
source/heimdal/lib/wind/ldap.c [new file with mode: 0644]
source/heimdal/lib/wind/map.c [new file with mode: 0644]
source/heimdal/lib/wind/map_table.c [new file with mode: 0644]
source/heimdal/lib/wind/map_table.h [new file with mode: 0644]
source/heimdal/lib/wind/normalize.c [new file with mode: 0644]
source/heimdal/lib/wind/normalize_table.c [new file with mode: 0644]
source/heimdal/lib/wind/normalize_table.h [new file with mode: 0644]
source/heimdal/lib/wind/stringprep.c [new file with mode: 0644]
source/heimdal/lib/wind/utf8.c [new file with mode: 0644]
source/heimdal/lib/wind/wind.h [new file with mode: 0644]
source/heimdal/lib/wind/wind_err.et [new file with mode: 0644]
source/heimdal/lib/wind/windlocl.h [new file with mode: 0644]
source/heimdal_build/config.mk
source/kdc/kdc.c
source/static_deps.mk

index 358ca5ad56d7162b2a083c38e127057b90035f87..b845b0f9a894e03760881a35d009e2647cdd95e5 100644 (file)
@@ -34,7 +34,7 @@
 #include "kdc_locl.h"
 #include <hex.h>
 
-RCSID("$Id: digest.c 21606 2007-07-17 07:03:25Z lha $");
+RCSID("$Id: digest.c 22374 2007-12-28 18:36:52Z lha $");
 
 #define MS_CHAP_V2     0x20
 #define CHAP_MD5       0x10
@@ -1003,7 +1003,8 @@ _kdc_do_digest(krb5_context context,
        }
 
        r.u.ntlmInitReply.flags |= 
-           NTLM_NEG_TARGET_DOMAIN |
+           NTLM_NEG_TARGET |
+           NTLM_TARGET_DOMAIN |
            NTLM_ENC_128;
 
 #define ALL                                    \
@@ -1331,6 +1332,27 @@ _kdc_do_digest(krb5_context context,
                version, ireq.u.ntlmRequest.username);
        break;
     }
+    case choice_DigestReqInner_supportedMechs:
+
+       kdc_log(context, config, 0, "digest supportedMechs from %s", from);
+
+       r.element = choice_DigestRepInner_supportedMechs;
+       memset(&r.u.supportedMechs, 0, sizeof(r.u.supportedMechs));
+
+       if (config->digests_allowed & NTLM_V1)
+           r.u.supportedMechs.ntlm_v1 = 1;
+       if (config->digests_allowed & NTLM_V1_SESSION)
+           r.u.supportedMechs.ntlm_v1_session = 1;
+       if (config->digests_allowed & NTLM_V2)
+           r.u.supportedMechs.ntlm_v2 = 1;
+       if (config->digests_allowed & DIGEST_MD5)
+           r.u.supportedMechs.digest_md5 = 1;
+       if (config->digests_allowed & CHAP_MD5)
+           r.u.supportedMechs.chap_md5 = 1;
+       if (config->digests_allowed & MS_CHAP_V2)
+           r.u.supportedMechs.ms_chap_v2 = 1;
+       break;
+
     default: {
        char *s;
        krb5_set_error_string(context, "unknown operation to digest");
index 15624e8e76393b03ccd97c6533bd5c30895fbd77..27f497ea6643c5ecc485160061b5e0840e28fbec 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "kdc_locl.h"
 
-RCSID("$Id: kaserver.c 21661 2007-07-22 01:57:17Z lha $");
+RCSID("$Id: kaserver.c 21654 2007-07-21 17:30:18Z lha $");
 
 #include <krb5-v4compat.h>
 #include <rx.h>
index fdbdf271defa233a161caf75256e03828517a977..fe0523665a4dbf983b299ecfbbcdffb095becb4b 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 /* 
- * $Id: kdc_locl.h 20954 2007-06-07 03:30:15Z lha $ 
+ * $Id: kdc_locl.h 22247 2007-12-08 23:49:41Z lha $ 
  */
 
 #ifndef __KDC_LOCL_H__
@@ -58,8 +58,7 @@ extern int detach_from_console;
 
 extern const struct units _kdc_digestunits[];
 
-#define _PATH_KDC_CONF         HDB_DB_DIR "/kdc.conf"
-#define DEFAULT_LOG_DEST       "0-1/FILE:" HDB_DB_DIR "/kdc.log"
+#define KDC_LOG_FILE           "kdc.log"
 
 extern struct timeval _kdc_now;
 #define kdc_time (_kdc_now.tv_sec)
index 40a9c9c972f53ba52d871c24f598bf1611fc732f..bc600a5319b2c959e5ee61724d7763db7aa35a7c 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "kdc_locl.h"
 
-RCSID("$Id: kerberos5.c 21529 2007-07-13 12:37:14Z lha $");
+RCSID("$Id: kerberos5.c 22071 2007-11-14 20:04:50Z lha $");
 
 #define MAX_TIME ((time_t)((1U << 31) - 1))
 
@@ -362,6 +362,13 @@ older_enctype(krb5_enctype enctype)
     case ETYPE_DES3_CBC_SHA1:
     case ETYPE_ARCFOUR_HMAC_MD5:
     case ETYPE_ARCFOUR_HMAC_MD5_56:
+    /* 
+     * The following three is "old" windows enctypes and is needed for
+     * windows 2000 hosts.
+     */
+    case ETYPE_ARCFOUR_MD4:
+    case ETYPE_ARCFOUR_HMAC_OLD:
+    case ETYPE_ARCFOUR_HMAC_OLD_EXP:
        return 1;
     default:
        return 0;
@@ -411,8 +418,8 @@ make_etype_info_entry(krb5_context context, ETYPE_INFO_ENTRY *ent, Key *key)
        *ent->salttype = key->salt->type;
 #else
        /* 
-        * We shouldn't sent salttype since its incompatible with the
-        * specification and its break windows clients.  The afs
+        * We shouldn't sent salttype since it is incompatible with the
+        * specification and it breaks windows clients.  The afs
         * salting problem is solved by using KRB5-PADATA-AFS3-SALT
         * implemented in Heimdal 0.7 and later.
         */
@@ -472,11 +479,13 @@ get_pa_etype_info(krb5_context context,
                    free_ETYPE_INFO(&pa);
                    return ret;
                }
+               break;
            }
        }
     skip1:;
     }
     for(i = 0; i < client->keys.len; i++) {
+       /* already added? */
        for(j = 0; j < etypes_len; j++) {
            if(client->keys.val[i].key.keytype == etypes[j])
                goto skip2;
@@ -497,7 +506,7 @@ get_pa_etype_info(krb5_context context,
     }
     
     if(n < pa.len) {
-       /* stripped out newer enctypes */
+       /* stripped out dups, newer enctypes, and not valid enctypes */
        pa.len = n;
     }
 
@@ -621,23 +630,29 @@ get_pa_etype_info2(krb5_context context,
            if(client->keys.val[i].key.keytype == etypes[j]) {
                if (krb5_enctype_valid(context, etypes[j]) != 0)
                    continue;
+               if (n >= pa.len)
+                   krb5_abortx(context, "internal error: n >= p.len");
                if((ret = make_etype_info2_entry(&pa.val[n++], 
                                                 &client->keys.val[i])) != 0) {
                    free_ETYPE_INFO2(&pa);
                    return ret;
                }
+               break;
            }
        }
     skip1:;
     }
-    /* send enctypes that the cliene doesn't know about too */
+    /* send enctypes that the client doesn't know about too */
     for(i = 0; i < client->keys.len; i++) {
+       /* already added? */
        for(j = 0; j < etypes_len; j++) {
            if(client->keys.val[i].key.keytype == etypes[j])
                goto skip2;
        }
        if (krb5_enctype_valid(context, client->keys.val[i].key.keytype) != 0)
            continue;
+       if (n >= pa.len)
+           krb5_abortx(context, "internal error: n >= p.len");
        if((ret = make_etype_info2_entry(&pa.val[n++],
                                         &client->keys.val[i])) != 0) {
            free_ETYPE_INFO2(&pa);
@@ -646,16 +661,8 @@ get_pa_etype_info2(krb5_context context,
       skip2:;
     }
     
-    if(n != pa.len) {
-       char *name;
-       ret = krb5_unparse_name(context, client->principal, &name);
-       if (ret)
-           name = rk_UNCONST("<unparse_name failed>");
-       kdc_log(context, config, 0,
-               "internal error in get_pa_etype_info2(%s): %d != %d", 
-               name, n, pa.len);
-       if (ret == 0)
-           free(name);
+    if(n < pa.len) {
+       /* stripped out dups, and not valid enctypes */
        pa.len = n;
     }
 
@@ -1554,6 +1561,10 @@ _kdc_as_rep(krb5_context context,
      * otherwise just a dummy lr.
      */
     ek.last_req.val = malloc(2 * sizeof(*ek.last_req.val));
+    if (ek.last_req.val == NULL) {
+       ret = ENOMEM;
+       goto out;
+    }
     ek.last_req.len = 0;
     if (client->entry.pw_end
        && (config->kdc_warn_pwexpire == 0
index 4d6be60f68fe2d40012604b2069a72dadaee161d..32bdee9799ca8407852b3ac2881465645839eaa2 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "kdc_locl.h"
 
-RCSID("$Id: krb5tgs.c 21262 2007-06-21 15:18:37Z lha $");
+RCSID("$Id: krb5tgs.c 22071 2007-11-14 20:04:50Z lha $");
 
 /*
  * return the realm of a krbtgt-ticket or NULL
@@ -822,7 +822,7 @@ tgs_make_reply(krb5_context context,
     if(rspac->length) {
        /*
         * No not need to filter out the any PAC from the
-        * auth_data since its signed by the KDC.
+        * auth_data since it's signed by the KDC.
         */
        ret = _kdc_tkt_add_if_relevant_ad(context, &et,
                                          KRB5_AUTHDATA_WIN2K_PAC,
@@ -1099,11 +1099,14 @@ tgs_parse_request(krb5_context context,
     ret = hdb_enctype2key(context, &(*krbtgt)->entry, 
                          ap_req.ticket.enc_part.etype, &tkey);
     if(ret){
-       char *str, *p;
+       char *str = NULL, *p = NULL;
+
        krb5_enctype_to_string(context, ap_req.ticket.enc_part.etype, &str);
        krb5_unparse_name(context, princ, &p);
-       kdc_log(context, config, 0,
-               "No server key with enctype %s found for %s", str, p);
+       kdc_log(context, config, 0,
+               "No server key with enctype %s found for %s",
+               str ? str : "<unknown enctype>",
+               p ? p : "<unparse_name failed>");
        free(str);
        free(p);
        ret = KRB5KRB_AP_ERR_BADKEYVER;
@@ -1163,8 +1166,10 @@ tgs_parse_request(krb5_context context,
     }
 
     if (b->enc_authorization_data) {
+       unsigned usage = KRB5_KU_TGS_REQ_AUTH_DAT_SUBKEY;
        krb5_keyblock *subkey;
        krb5_data ad;
+
        ret = krb5_auth_con_getremotesubkey(context,
                                            ac,
                                            &subkey);
@@ -1175,6 +1180,7 @@ tgs_parse_request(krb5_context context,
            goto out;
        }
        if(subkey == NULL){
+           usage = KRB5_KU_TGS_REQ_AUTH_DAT_SESSION;
            ret = krb5_auth_con_getkey(context, ac, &subkey);
            if(ret) {
                krb5_auth_con_free(context, ac);
@@ -1199,7 +1205,7 @@ tgs_parse_request(krb5_context context,
        }
        ret = krb5_decrypt_EncryptedData (context,
                                          crypto,
-                                         KRB5_KU_TGS_REQ_AUTH_DAT_SUBKEY,
+                                         usage,
                                          b->enc_authorization_data,
                                          &ad);
        krb5_crypto_destroy(context, crypto);
@@ -1373,6 +1379,7 @@ server_lookup:
                    ret = krb5_unparse_name(context, sp, &spn); 
                    if (ret)
                        goto out;
+                   auth_data = NULL; /* ms don't handle AD in referals */
                    goto server_lookup;
                }
            }
@@ -1390,6 +1397,7 @@ server_lookup:
                if (ret)
                    goto out;
                krb5_free_host_realm(context, realms);
+               auth_data = NULL; /* ms don't handle AD in referals */
                goto server_lookup;
            }
            krb5_free_host_realm(context, realms);
@@ -1431,8 +1439,8 @@ server_lookup:
     }
     
     /*
-     * Check that service is in the same realm as the krbtgt. If its
-     * not the same, its someone that is using a uni-directional trust
+     * Check that service is in the same realm as the krbtgt. If it's
+     * not the same, it's someone that is using a uni-directional trust
      * backward.
      */
     
index 977b1c9476015f3bd41a557cf57b74ef546eebc7..8cf967fbfb8b179da9055e96c8e9df0e2c359bc4 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 #include "kdc_locl.h"
-RCSID("$Id: log.c 15532 2005-06-30 01:54:49Z lha $");
+RCSID("$Id: log.c 22254 2007-12-09 06:01:05Z lha $");
 
 void
 kdc_openlog(krb5_context context, 
@@ -47,8 +47,12 @@ kdc_openlog(krb5_context context,
        for(p = s; *p; p++)
            krb5_addlog_dest(context, config->logf, *p);
        krb5_config_free_strings(s);
-    }else
-       krb5_addlog_dest(context, config->logf, DEFAULT_LOG_DEST);
+    }else {
+       char *s;
+       asprintf(&s, "0-1/FILE:%s/%s", hdb_db_dir(context), KDC_LOG_FILE);
+       krb5_addlog_dest(context, config->logf, s);
+       free(s);
+    }
     krb5_set_warn_dest(context, config->logf);
 }
 
index ead961022d18a27fc9f3c177d03157112ab0a7d6..bf248af588fcbbb81d6ae7abfeabfcec81c551cc 100755 (executable)
@@ -33,7 +33,7 @@
 
 #include "kdc_locl.h"
 
-RCSID("$Id: pkinit.c 21290 2007-06-25 14:13:23Z lha $");
+RCSID("$Id: pkinit.c 22243 2007-12-08 23:39:30Z lha $");
 
 #ifdef PKINIT
 
@@ -1248,6 +1248,7 @@ out:
 static int
 match_rfc_san(krb5_context context, 
              krb5_kdc_configuration *config,
+             hx509_context hx509ctx,
              hx509_cert client_cert, 
              krb5_const_principal match)
 {
@@ -1256,7 +1257,8 @@ match_rfc_san(krb5_context context,
 
     memset(&list, 0 , sizeof(list));
 
-    ret = hx509_cert_find_subjectAltName_otherName(client_cert,
+    ret = hx509_cert_find_subjectAltName_otherName(hx509ctx,
+                                                  client_cert,
                                                   oid_id_pkinit_san(),
                                                   &list);
     if (ret)
@@ -1304,6 +1306,7 @@ out:
 static int
 match_ms_upn_san(krb5_context context, 
                 krb5_kdc_configuration *config,
+                hx509_context hx509ctx,
                 hx509_cert client_cert, 
                 krb5_const_principal match)
 {
@@ -1315,7 +1318,8 @@ match_ms_upn_san(krb5_context context,
 
     memset(&list, 0 , sizeof(list));
 
-    ret = hx509_cert_find_subjectAltName_otherName(client_cert,
+    ret = hx509_cert_find_subjectAltName_otherName(hx509ctx,
+                                                  client_cert,
                                                   oid_id_pkinit_ms_san(),
                                                   &list);
     if (ret)
@@ -1376,7 +1380,7 @@ _kdc_pk_check_client(krb5_context context,
     hx509_name name;
     int i;
 
-    ret = hx509_cert_get_base_subject(kdc_identity->hx509ctx, 
+    ret = hx509_cert_get_base_subject(kdc_identity->hx509ctx,
                                      client_params->cert,
                                      &name);
     if (ret)
@@ -1393,6 +1397,7 @@ _kdc_pk_check_client(krb5_context context,
 
     if (config->pkinit_princ_in_cert) {
        ret = match_rfc_san(context, config,
+                           kdc_identity->hx509ctx,
                            client_params->cert,
                            client->entry.principal);
        if (ret == 0) {
@@ -1401,6 +1406,7 @@ _kdc_pk_check_client(krb5_context context,
            return 0;
        }
        ret = match_ms_upn_san(context, config,
+                              kdc_identity->hx509ctx,
                               client_params->cert,
                               client->entry.principal);
        if (ret == 0) {
@@ -1580,7 +1586,8 @@ _kdc_pk_initialize(krb5_context context,
                   char **pool,
                   char **revoke_list)
 {
-    const char *file; 
+    const char *file;
+    char *fn = NULL;
     krb5_error_code ret;
 
     file = krb5_config_get_string(context, NULL,
@@ -1646,14 +1653,19 @@ _kdc_pk_initialize(krb5_context context,
                                       NULL);
     _krb5_pk_allow_proxy_certificate(kdc_identity, ret);
 
-    file = krb5_config_get_string_default(context, 
-                                         NULL,
-                                         HDB_DB_DIR "/pki-mapping",
-                                         "kdc",
-                                         "pkinit_mappings_file",
-                                         NULL);
+    file = krb5_config_get_string(context, 
+                                 NULL,
+                                 "kdc",
+                                 "pkinit_mappings_file",
+                                 NULL);
+    if (file == NULL) {
+       asprintf(&fn, "%s/pki-mapping", hdb_db_dir(context));
+       file = fn;
+    }
 
     load_mappings(context, file);
+    if (fn)
+       free(fn);
 
     return 0;
 }
index 23fa7a5bafb0623cb2188811cca4bbf53a230ce9..2676309859089bda9136eeaa0d157e9c48cad707 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden). 
  * All rights reserved. 
  *
@@ -32,7 +32,7 @@
  */
 
 #include "kuser_locl.h"
-RCSID("$Id: kinit.c 21483 2007-07-10 16:40:46Z lha $");
+RCSID("$Id: kinit.c 22116 2007-12-03 21:22:58Z lha $");
 
 #include "krb5-v4compat.h"
 
@@ -260,7 +260,7 @@ renew_validate(krb5_context context,
 
     if (renew) {
        /* 
-        * no need to check the error here, its only to be 
+        * no need to check the error here, it's only to be 
         * friendly to the user
         */
        krb5_get_credentials(context, KRB5_GC_CACHED, cache, &in, &out);
@@ -377,6 +377,7 @@ get_new_tickets(krb5_context context,
     char *renewstr = NULL;
     krb5_enctype *enctype = NULL;
     struct ntlm_buf ntlmkey;
+    krb5_ccache tempccache;
 
     memset(&ntlmkey, 0, sizeof(ntlmkey));
     passwd[0] = '\0';
@@ -577,16 +578,25 @@ get_new_tickets(krb5_context context,
        }
     }
 
-    ret = krb5_cc_initialize (context, ccache, cred.client);
+    ret = krb5_cc_new_unique(context, krb5_cc_get_type(context, ccache), 
+                            NULL, &tempccache);
+    if (ret)
+       krb5_err (context, 1, ret, "krb5_cc_new_unique");
+
+    ret = krb5_cc_initialize (context, tempccache, cred.client);
     if (ret)
        krb5_err (context, 1, ret, "krb5_cc_initialize");
     
-    ret = krb5_cc_store_cred (context, ccache, &cred);
+    ret = krb5_cc_store_cred (context, tempccache, &cred);
     if (ret)
        krb5_err (context, 1, ret, "krb5_cc_store_cred");
 
     krb5_free_cred_contents (context, &cred);
 
+    ret = krb5_cc_move(context, tempccache, ccache);
+    if (ret)
+       krb5_err (context, 1, ret, "krb5_cc_move");
+
     if (ntlm_domain && ntlmkey.data)
        store_ntlmkey(context, ccache, ntlm_domain, principal, &ntlmkey);
 
@@ -757,8 +767,11 @@ main (int argc, char **argv)
                    krb4_cc_name = NULL;
                }
            }
-       } else
-           ret = krb5_cc_default (context, &ccache);
+       } else {
+           ret = krb5_cc_cache_match(context, principal, NULL, &ccache);
+           if (ret)
+               ret = krb5_cc_default (context, &ccache);
+       }
     }
     if (ret)
        krb5_err (context, 1, ret, "resolving credentials cache");
index 15c4a09cd0d0725492c3ab9f155508a363dfe1ab..5789e0f22dfbb03c3a4bb7c83ae5690dda7acdb7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: asn1-common.h 19539 2006-12-28 17:15:05Z lha $ */
+/* $Id: asn1-common.h 22429 2008-01-13 10:25:50Z lha $ */
 
 #include <stddef.h>
 #include <time.h>
index edb8375ee35c38b20d967ad87c0096976250639c..5ba3e3880c2e23a5fae1aa90140073ce5e3fd370 100644 (file)
@@ -1,4 +1,4 @@
--- $Id: canthandle.asn1 16593 2006-01-18 19:12:33Z lha $ --
+-- $Id: canthandle.asn1 22071 2007-11-14 20:04:50Z lha $ --
 
 CANTHANDLE DEFINITIONS ::= BEGIN
 
@@ -19,7 +19,7 @@ Foo ::= SEQUENCE {
         kaka3 [2] IMPLICIT Kaka3 OPTIONAL
 }
 
--- Don't code kaka if its 1
+-- Don't code kaka if it's 1
 -- Workaround is to use OPTIONAL and check for in the encoder stubs
 
 Bar ::= SEQUENCE {
index c7b911b8d6c82cc8601c187c0df32436d20bf804..120dc086afc9383c9e19b4386120bbc2c9492148 100644 (file)
@@ -38,7 +38,7 @@
 #include <getarg.h>
 #include <err.h>
 
-RCSID("$Id: der.c 15617 2005-07-12 06:27:42Z lha $");
+RCSID("$Id: der.c 22429 2008-01-13 10:25:50Z lha $");
 
 
 static const char *class_names[] = {
index 17341863c66b080ad49301dd73d939733604fd3e..eafe48ea5aee1e57bfa361863494e6f976429fe9 100644 (file)
@@ -1,10 +1,19 @@
--- $Id: digest.asn1 20138 2007-02-02 21:08:24Z lha $
+-- $Id: digest.asn1 22152 2007-12-04 19:59:18Z lha $
 
 DIGEST DEFINITIONS ::=
 BEGIN
 
 IMPORTS EncryptedData, Principal FROM krb5;
 
+DigestTypes ::= BIT STRING {
+       ntlm-v1(0),
+       ntlm-v1-session(1),
+       ntlm-v2(2),
+       digest-md5(3),
+       chap-md5(4),
+       ms-chap-v2(5)
+}
+
 DigestInit ::= SEQUENCE {
     type               UTF8String, -- http, sasl, chap, cram-md5 --
     channel            [0] SEQUENCE {
@@ -95,7 +104,8 @@ DigestReqInner ::= CHOICE {
     init               [0] DigestInit,
     digestRequest      [1] DigestRequest,
     ntlmInit           [2] NTLMInit,
-    ntlmRequest                [3] NTLMRequest
+    ntlmRequest                [3] NTLMRequest,
+    supportedMechs     [4] NULL
 }
 
 DigestREQ ::= [APPLICATION 128] SEQUENCE {
@@ -108,7 +118,9 @@ DigestRepInner ::= CHOICE {
     initReply          [1] DigestInitReply,
     response           [2] DigestResponse,
     ntlmInitReply      [3] NTLMInitReply,
-    ntlmResponse       [4] NTLMResponse
+    ntlmResponse       [4] NTLMResponse,
+    supportedMechs     [5] DigestTypes,
+    ...
 }
 
 DigestREP ::= [APPLICATION 129] SEQUENCE {
index 26890212ae6425c6249381f3d3ebfe424e686943..499f8eab363b56f51392a5f0977c3a894b90b795 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "gen_locl.h"
 
-RCSID("$Id: gen.c 21364 2007-06-27 08:51:06Z lha $");
+RCSID("$Id: gen.c 22429 2008-01-13 10:25:50Z lha $");
 
 FILE *headerfile, *codefile, *logfile;
 
index 9544514212f89f543db40b6e2f0386231d4d86fc..08f1a9449f8baf91dda4105df2bdcccdc9d77bb1 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "gen_locl.h"
 
-RCSID("$Id: gen_encode.c 21503 2007-07-12 11:57:19Z lha $");
+RCSID("$Id: gen_encode.c 22429 2008-01-13 10:25:50Z lha $");
 
 static void
 encode_primitive (const char *typename, const char *name)
index e3fe2b11e9ac297a631c21e11a507c64bccdd30e..18f1e1541b5f6723b256ac89645abab219cc52a3 100644 (file)
@@ -1,4 +1,4 @@
--- $Id: k5.asn1 21400 2007-07-02 19:57:31Z lha $
+-- $Id: k5.asn1 21965 2007-10-18 18:24:36Z lha $
 
 KERBEROS5 DEFINITIONS ::=
 BEGIN
@@ -137,6 +137,10 @@ ENCTYPE ::= INTEGER {
        ETYPE_ARCFOUR_HMAC_MD5(23),
        ETYPE_ARCFOUR_HMAC_MD5_56(24),
        ETYPE_ENCTYPE_PK_CROSS(48),
+-- some "old" windows types
+       ETYPE_ARCFOUR_MD4(-128),
+       ETYPE_ARCFOUR_HMAC_OLD(-133),
+       ETYPE_ARCFOUR_HMAC_OLD_EXP(-135),
 -- these are for Heimdal internal use
        ETYPE_DES_CBC_NONE(-0x1000),
        ETYPE_DES3_CBC_NONE(-0x1001),
index 86c4359f1a0f9a537f58a4f1a9bab2045c1f8b71..da4f729c3d6966e6026ada705541fea8c93ac16a 100644 (file)
@@ -1,6 +1,5 @@
-#include "config.h"
 
-#line 3 "heimdal/lib/asn1/lex.c"
+#line 3 "lex.c"
 
 #define  YY_INT_ALIGNED short int
 
@@ -827,7 +826,7 @@ char *yytext;
  * SUCH DAMAGE. 
  */
 
-/* $Id: lex.l,v 1.31 2006/10/21 11:57:22 lha Exp $ */
+/* $Id: lex.l 18738 2006-10-21 11:57:22Z lha $ */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -852,7 +851,7 @@ static unsigned lineno = 1;
 static void unterminated(const char *, unsigned);
 
 /* This is for broken old lexes (solaris 10 and hpux) */
-#line 855 "heimdal/lib/asn1/lex.c"
+#line 855 "lex.c"
 
 #define INITIAL 0
 
@@ -870,6 +869,35 @@ static void unterminated(const char *, unsigned);
 
 static int yy_init_globals (void );
 
+/* Accessor methods to globals.
+   These are made visible to non-reentrant scanners for convenience. */
+
+int yylex_destroy (void );
+
+int yyget_debug (void );
+
+void yyset_debug (int debug_flag  );
+
+YY_EXTRA_TYPE yyget_extra (void );
+
+void yyset_extra (YY_EXTRA_TYPE user_defined  );
+
+FILE *yyget_in (void );
+
+void yyset_in  (FILE * in_str  );
+
+FILE *yyget_out (void );
+
+void yyset_out  (FILE * out_str  );
+
+int yyget_leng (void );
+
+char *yyget_text (void );
+
+int yyget_lineno (void );
+
+void yyset_lineno (int line_number  );
+
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -1007,7 +1035,7 @@ YY_DECL
     
 #line 68 "lex.l"
 
-#line 1010 "heimdal/lib/asn1/lex.c"
+#line 1039 "lex.c"
 
        if ( !(yy_init) )
                {
@@ -1676,7 +1704,7 @@ YY_RULE_SETUP
 #line 274 "lex.l"
 ECHO;
        YY_BREAK
-#line 1679 "heimdal/lib/asn1/lex.c"
+#line 1708 "lex.c"
 case YY_STATE_EOF(INITIAL):
        yyterminate();
 
@@ -1907,7 +1935,7 @@ static int yy_get_next_buffer (void)
 
                /* Read in more data. */
                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
-                       (yy_n_chars), (size_t) num_to_read );
+                       (yy_n_chars), num_to_read );
 
                YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
                }
@@ -2408,7 +2436,7 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
 
 /** Setup the input buffer state to scan a string. The next call to yylex() will
  * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
+ * @param str a NUL-terminated string to scan
  * 
  * @return the newly allocated buffer state object.
  * @note If you want to scan bytes that may contain NUL values, then use
index edcb313bd02bffbfb07e60ecd376a9bd3fc2b06e..6a3e524e93a949e354eb856ee69029c2eebb1ef9 100644 (file)
 
 
 /* Copy the first part of user declarations.  */
-#line 36 "heimdal/lib/asn1/parse.y"
+#line 36 "parse.y"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -280,7 +280,7 @@ struct string_list {
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
-# define YYDEBUG 0
+# define YYDEBUG 1
 #endif
 
 /* Enabling verbose error messages.  */
@@ -298,7 +298,7 @@ struct string_list {
 
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 65 "heimdal/lib/asn1/parse.y"
+#line 65 "parse.y"
 {
     int constant;
     struct value *value;
@@ -314,7 +314,7 @@ typedef union YYSTYPE
     struct constraint_spec *constraint_spec;
 }
 /* Line 187 of yacc.c.  */
-#line 318 "heimdal/lib/asn1/parse.y"
+#line 318 "parse.c"
        YYSTYPE;
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
@@ -327,7 +327,7 @@ typedef union YYSTYPE
 
 
 /* Line 216 of yacc.c.  */
-#line 331 "heimdal/lib/asn1/parse.y"
+#line 331 "parse.c"
 
 #ifdef short
 # undef short
@@ -1762,29 +1762,29 @@ yyreduce:
   switch (yyn)
     {
         case 2:
-#line 235 "heimdal/lib/asn1/parse.y"
+#line 235 "parse.y"
     {
                        checkundefined();
                }
     break;
 
   case 4:
-#line 242 "heimdal/lib/asn1/parse.y"
+#line 242 "parse.y"
     { error_message("implicit tagging is not supported"); }
     break;
 
   case 5:
-#line 244 "heimdal/lib/asn1/parse.y"
+#line 244 "parse.y"
     { error_message("automatic tagging is not supported"); }
     break;
 
   case 7:
-#line 249 "heimdal/lib/asn1/parse.y"
+#line 249 "parse.y"
     { error_message("no extensibility options supported"); }
     break;
 
   case 17:
-#line 270 "heimdal/lib/asn1/parse.y"
+#line 270 "parse.y"
     { 
                    struct string_list *sl;
                    for(sl = (yyvsp[(1) - (4)].sl); sl != NULL; sl = sl->next) {
@@ -1796,7 +1796,7 @@ yyreduce:
     break;
 
   case 22:
-#line 289 "heimdal/lib/asn1/parse.y"
+#line 289 "parse.y"
     {
                    (yyval.sl) = emalloc(sizeof(*(yyval.sl)));
                    (yyval.sl)->string = (yyvsp[(1) - (3)].name);
@@ -1805,7 +1805,7 @@ yyreduce:
     break;
 
   case 23:
-#line 295 "heimdal/lib/asn1/parse.y"
+#line 295 "parse.y"
     {
                    (yyval.sl) = emalloc(sizeof(*(yyval.sl)));
                    (yyval.sl)->string = (yyvsp[(1) - (1)].name);
@@ -1814,7 +1814,7 @@ yyreduce:
     break;
 
   case 24:
-#line 303 "heimdal/lib/asn1/parse.y"
+#line 303 "parse.y"
     {
                    Symbol *s = addsym ((yyvsp[(1) - (3)].name));
                    s->stype = Stype;
@@ -1825,7 +1825,7 @@ yyreduce:
     break;
 
   case 42:
-#line 334 "heimdal/lib/asn1/parse.y"
+#line 334 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_Boolean, 
                                     TE_EXPLICIT, new_type(TBoolean));
@@ -1833,7 +1833,7 @@ yyreduce:
     break;
 
   case 43:
-#line 341 "heimdal/lib/asn1/parse.y"
+#line 341 "parse.y"
     {
                    if((yyvsp[(2) - (5)].value)->type != integervalue)
                        error_message("Non-integer used in first part of range");
@@ -1846,7 +1846,7 @@ yyreduce:
     break;
 
   case 44:
-#line 351 "heimdal/lib/asn1/parse.y"
+#line 351 "parse.y"
     {          
                    if((yyvsp[(2) - (5)].value)->type != integervalue)
                        error_message("Non-integer in first part of range");
@@ -1857,7 +1857,7 @@ yyreduce:
     break;
 
   case 45:
-#line 359 "heimdal/lib/asn1/parse.y"
+#line 359 "parse.y"
     {          
                    if((yyvsp[(4) - (5)].value)->type != integervalue)
                        error_message("Non-integer in second part of range");
@@ -1868,7 +1868,7 @@ yyreduce:
     break;
 
   case 46:
-#line 367 "heimdal/lib/asn1/parse.y"
+#line 367 "parse.y"
     {
                    if((yyvsp[(2) - (3)].value)->type != integervalue)
                        error_message("Non-integer used in limit");
@@ -1879,7 +1879,7 @@ yyreduce:
     break;
 
   case 47:
-#line 378 "heimdal/lib/asn1/parse.y"
+#line 378 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_Integer, 
                                     TE_EXPLICIT, new_type(TInteger));
@@ -1887,7 +1887,7 @@ yyreduce:
     break;
 
   case 48:
-#line 383 "heimdal/lib/asn1/parse.y"
+#line 383 "parse.y"
     {
                        (yyval.type) = new_type(TInteger);
                        (yyval.type)->range = (yyvsp[(2) - (2)].range);
@@ -1896,7 +1896,7 @@ yyreduce:
     break;
 
   case 49:
-#line 389 "heimdal/lib/asn1/parse.y"
+#line 389 "parse.y"
     {
                  (yyval.type) = new_type(TInteger);
                  (yyval.type)->members = (yyvsp[(3) - (4)].members);
@@ -1905,7 +1905,7 @@ yyreduce:
     break;
 
   case 50:
-#line 397 "heimdal/lib/asn1/parse.y"
+#line 397 "parse.y"
     {
                        (yyval.members) = emalloc(sizeof(*(yyval.members)));
                        ASN1_TAILQ_INIT((yyval.members));
@@ -1914,7 +1914,7 @@ yyreduce:
     break;
 
   case 51:
-#line 403 "heimdal/lib/asn1/parse.y"
+#line 403 "parse.y"
     {
                        ASN1_TAILQ_INSERT_TAIL((yyvsp[(1) - (3)].members), (yyvsp[(3) - (3)].member), members);
                        (yyval.members) = (yyvsp[(1) - (3)].members);
@@ -1922,12 +1922,12 @@ yyreduce:
     break;
 
   case 52:
-#line 408 "heimdal/lib/asn1/parse.y"
+#line 408 "parse.y"
     { (yyval.members) = (yyvsp[(1) - (3)].members); }
     break;
 
   case 53:
-#line 412 "heimdal/lib/asn1/parse.y"
+#line 412 "parse.y"
     {
                        (yyval.member) = emalloc(sizeof(*(yyval.member)));
                        (yyval.member)->name = (yyvsp[(1) - (4)].name);
@@ -1941,7 +1941,7 @@ yyreduce:
     break;
 
   case 54:
-#line 425 "heimdal/lib/asn1/parse.y"
+#line 425 "parse.y"
     {
                  (yyval.type) = new_type(TInteger);
                  (yyval.type)->members = (yyvsp[(3) - (4)].members);
@@ -1950,7 +1950,7 @@ yyreduce:
     break;
 
   case 56:
-#line 436 "heimdal/lib/asn1/parse.y"
+#line 436 "parse.y"
     {
                  (yyval.type) = new_type(TBitString);
                  (yyval.type)->members = emalloc(sizeof(*(yyval.type)->members));
@@ -1960,7 +1960,7 @@ yyreduce:
     break;
 
   case 57:
-#line 443 "heimdal/lib/asn1/parse.y"
+#line 443 "parse.y"
     {
                  (yyval.type) = new_type(TBitString);
                  (yyval.type)->members = (yyvsp[(4) - (5)].members);
@@ -1969,7 +1969,7 @@ yyreduce:
     break;
 
   case 58:
-#line 451 "heimdal/lib/asn1/parse.y"
+#line 451 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_OID, 
                                     TE_EXPLICIT, new_type(TOID));
@@ -1977,7 +1977,7 @@ yyreduce:
     break;
 
   case 59:
-#line 457 "heimdal/lib/asn1/parse.y"
+#line 457 "parse.y"
     {
                    Type *t = new_type(TOctetString);
                    t->range = (yyvsp[(3) - (3)].range);
@@ -1987,7 +1987,7 @@ yyreduce:
     break;
 
   case 60:
-#line 466 "heimdal/lib/asn1/parse.y"
+#line 466 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_Null, 
                                     TE_EXPLICIT, new_type(TNull));
@@ -1995,17 +1995,17 @@ yyreduce:
     break;
 
   case 61:
-#line 473 "heimdal/lib/asn1/parse.y"
+#line 473 "parse.y"
     { (yyval.range) = NULL; }
     break;
 
   case 62:
-#line 475 "heimdal/lib/asn1/parse.y"
+#line 475 "parse.y"
     { (yyval.range) = (yyvsp[(2) - (2)].range); }
     break;
 
   case 63:
-#line 480 "heimdal/lib/asn1/parse.y"
+#line 480 "parse.y"
     {
                  (yyval.type) = new_type(TSequence);
                  (yyval.type)->members = (yyvsp[(3) - (4)].members);
@@ -2014,7 +2014,7 @@ yyreduce:
     break;
 
   case 64:
-#line 486 "heimdal/lib/asn1/parse.y"
+#line 486 "parse.y"
     {
                  (yyval.type) = new_type(TSequence);
                  (yyval.type)->members = NULL;
@@ -2023,7 +2023,7 @@ yyreduce:
     break;
 
   case 65:
-#line 494 "heimdal/lib/asn1/parse.y"
+#line 494 "parse.y"
     {
                  (yyval.type) = new_type(TSequenceOf);
                  (yyval.type)->range = (yyvsp[(2) - (4)].range);
@@ -2033,7 +2033,7 @@ yyreduce:
     break;
 
   case 66:
-#line 503 "heimdal/lib/asn1/parse.y"
+#line 503 "parse.y"
     {
                  (yyval.type) = new_type(TSet);
                  (yyval.type)->members = (yyvsp[(3) - (4)].members);
@@ -2042,7 +2042,7 @@ yyreduce:
     break;
 
   case 67:
-#line 509 "heimdal/lib/asn1/parse.y"
+#line 509 "parse.y"
     {
                  (yyval.type) = new_type(TSet);
                  (yyval.type)->members = NULL;
@@ -2051,7 +2051,7 @@ yyreduce:
     break;
 
   case 68:
-#line 517 "heimdal/lib/asn1/parse.y"
+#line 517 "parse.y"
     {
                  (yyval.type) = new_type(TSetOf);
                  (yyval.type)->subtype = (yyvsp[(3) - (3)].type);
@@ -2060,7 +2060,7 @@ yyreduce:
     break;
 
   case 69:
-#line 525 "heimdal/lib/asn1/parse.y"
+#line 525 "parse.y"
     {
                  (yyval.type) = new_type(TChoice);
                  (yyval.type)->members = (yyvsp[(3) - (4)].members);
@@ -2068,7 +2068,7 @@ yyreduce:
     break;
 
   case 72:
-#line 536 "heimdal/lib/asn1/parse.y"
+#line 536 "parse.y"
     {
                  Symbol *s = addsym((yyvsp[(1) - (1)].name));
                  (yyval.type) = new_type(TType);
@@ -2080,7 +2080,7 @@ yyreduce:
     break;
 
   case 73:
-#line 547 "heimdal/lib/asn1/parse.y"
+#line 547 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_GeneralizedTime, 
                                     TE_EXPLICIT, new_type(TGeneralizedTime));
@@ -2088,7 +2088,7 @@ yyreduce:
     break;
 
   case 74:
-#line 552 "heimdal/lib/asn1/parse.y"
+#line 552 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_UTCTime, 
                                     TE_EXPLICIT, new_type(TUTCTime));
@@ -2096,7 +2096,7 @@ yyreduce:
     break;
 
   case 75:
-#line 559 "heimdal/lib/asn1/parse.y"
+#line 559 "parse.y"
     {
                    /* if (Constraint.type == contentConstrant) {
                       assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too
@@ -2112,14 +2112,14 @@ yyreduce:
     break;
 
   case 76:
-#line 575 "heimdal/lib/asn1/parse.y"
+#line 575 "parse.y"
     {
                    (yyval.constraint_spec) = (yyvsp[(2) - (3)].constraint_spec);
                }
     break;
 
   case 80:
-#line 588 "heimdal/lib/asn1/parse.y"
+#line 588 "parse.y"
     {
                    (yyval.constraint_spec) = new_constraint_spec(CT_CONTENTS);
                    (yyval.constraint_spec)->u.content.type = (yyvsp[(2) - (2)].type);
@@ -2128,7 +2128,7 @@ yyreduce:
     break;
 
   case 81:
-#line 594 "heimdal/lib/asn1/parse.y"
+#line 594 "parse.y"
     {
                    if ((yyvsp[(3) - (3)].value)->type != objectidentifiervalue)
                        error_message("Non-OID used in ENCODED BY constraint");
@@ -2139,7 +2139,7 @@ yyreduce:
     break;
 
   case 82:
-#line 602 "heimdal/lib/asn1/parse.y"
+#line 602 "parse.y"
     {
                    if ((yyvsp[(5) - (5)].value)->type != objectidentifiervalue)
                        error_message("Non-OID used in ENCODED BY constraint");
@@ -2150,14 +2150,14 @@ yyreduce:
     break;
 
   case 83:
-#line 612 "heimdal/lib/asn1/parse.y"
+#line 612 "parse.y"
     {
                    (yyval.constraint_spec) = new_constraint_spec(CT_USER);
                }
     break;
 
   case 84:
-#line 618 "heimdal/lib/asn1/parse.y"
+#line 618 "parse.y"
     {
                        (yyval.type) = new_type(TTag);
                        (yyval.type)->tag = (yyvsp[(1) - (3)].tag);
@@ -2171,7 +2171,7 @@ yyreduce:
     break;
 
   case 85:
-#line 631 "heimdal/lib/asn1/parse.y"
+#line 631 "parse.y"
     {
                        (yyval.tag).tagclass = (yyvsp[(2) - (4)].constant);
                        (yyval.tag).tagvalue = (yyvsp[(3) - (4)].constant);
@@ -2180,56 +2180,56 @@ yyreduce:
     break;
 
   case 86:
-#line 639 "heimdal/lib/asn1/parse.y"
+#line 639 "parse.y"
     {
                        (yyval.constant) = ASN1_C_CONTEXT;
                }
     break;
 
   case 87:
-#line 643 "heimdal/lib/asn1/parse.y"
+#line 643 "parse.y"
     {
                        (yyval.constant) = ASN1_C_UNIV;
                }
     break;
 
   case 88:
-#line 647 "heimdal/lib/asn1/parse.y"
+#line 647 "parse.y"
     {
                        (yyval.constant) = ASN1_C_APPL;
                }
     break;
 
   case 89:
-#line 651 "heimdal/lib/asn1/parse.y"
+#line 651 "parse.y"
     {
                        (yyval.constant) = ASN1_C_PRIVATE;
                }
     break;
 
   case 90:
-#line 657 "heimdal/lib/asn1/parse.y"
+#line 657 "parse.y"
     {
                        (yyval.constant) = TE_EXPLICIT;
                }
     break;
 
   case 91:
-#line 661 "heimdal/lib/asn1/parse.y"
+#line 661 "parse.y"
     {
                        (yyval.constant) = TE_EXPLICIT;
                }
     break;
 
   case 92:
-#line 665 "heimdal/lib/asn1/parse.y"
+#line 665 "parse.y"
     {
                        (yyval.constant) = TE_IMPLICIT;
                }
     break;
 
   case 93:
-#line 672 "heimdal/lib/asn1/parse.y"
+#line 672 "parse.y"
     {
                        Symbol *s;
                        s = addsym ((yyvsp[(1) - (4)].name));
@@ -2241,7 +2241,7 @@ yyreduce:
     break;
 
   case 95:
-#line 686 "heimdal/lib/asn1/parse.y"
+#line 686 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_GeneralString, 
                                     TE_EXPLICIT, new_type(TGeneralString));
@@ -2249,7 +2249,7 @@ yyreduce:
     break;
 
   case 96:
-#line 691 "heimdal/lib/asn1/parse.y"
+#line 691 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_UTF8String, 
                                     TE_EXPLICIT, new_type(TUTF8String));
@@ -2257,7 +2257,7 @@ yyreduce:
     break;
 
   case 97:
-#line 696 "heimdal/lib/asn1/parse.y"
+#line 696 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_PrintableString, 
                                     TE_EXPLICIT, new_type(TPrintableString));
@@ -2265,7 +2265,7 @@ yyreduce:
     break;
 
   case 98:
-#line 701 "heimdal/lib/asn1/parse.y"
+#line 701 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_VisibleString, 
                                     TE_EXPLICIT, new_type(TVisibleString));
@@ -2273,7 +2273,7 @@ yyreduce:
     break;
 
   case 99:
-#line 706 "heimdal/lib/asn1/parse.y"
+#line 706 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_IA5String, 
                                     TE_EXPLICIT, new_type(TIA5String));
@@ -2281,7 +2281,7 @@ yyreduce:
     break;
 
   case 100:
-#line 711 "heimdal/lib/asn1/parse.y"
+#line 711 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_BMPString, 
                                     TE_EXPLICIT, new_type(TBMPString));
@@ -2289,7 +2289,7 @@ yyreduce:
     break;
 
   case 101:
-#line 716 "heimdal/lib/asn1/parse.y"
+#line 716 "parse.y"
     {
                        (yyval.type) = new_tag(ASN1_C_UNIV, UT_UniversalString, 
                                     TE_EXPLICIT, new_type(TUniversalString));
@@ -2297,7 +2297,7 @@ yyreduce:
     break;
 
   case 102:
-#line 724 "heimdal/lib/asn1/parse.y"
+#line 724 "parse.y"
     {
                        (yyval.members) = emalloc(sizeof(*(yyval.members)));
                        ASN1_TAILQ_INIT((yyval.members));
@@ -2306,7 +2306,7 @@ yyreduce:
     break;
 
   case 103:
-#line 730 "heimdal/lib/asn1/parse.y"
+#line 730 "parse.y"
     {
                        ASN1_TAILQ_INSERT_TAIL((yyvsp[(1) - (3)].members), (yyvsp[(3) - (3)].member), members);
                        (yyval.members) = (yyvsp[(1) - (3)].members);
@@ -2314,7 +2314,7 @@ yyreduce:
     break;
 
   case 104:
-#line 735 "heimdal/lib/asn1/parse.y"
+#line 735 "parse.y"
     {
                        struct member *m = ecalloc(1, sizeof(*m));
                        m->name = estrdup("...");
@@ -2326,7 +2326,7 @@ yyreduce:
     break;
 
   case 105:
-#line 746 "heimdal/lib/asn1/parse.y"
+#line 746 "parse.y"
     {
                  (yyval.member) = emalloc(sizeof(*(yyval.member)));
                  (yyval.member)->name = (yyvsp[(1) - (2)].name);
@@ -2338,7 +2338,7 @@ yyreduce:
     break;
 
   case 106:
-#line 757 "heimdal/lib/asn1/parse.y"
+#line 757 "parse.y"
     {
                        (yyval.member) = (yyvsp[(1) - (1)].member);
                        (yyval.member)->optional = 0;
@@ -2347,7 +2347,7 @@ yyreduce:
     break;
 
   case 107:
-#line 763 "heimdal/lib/asn1/parse.y"
+#line 763 "parse.y"
     {
                        (yyval.member) = (yyvsp[(1) - (2)].member);
                        (yyval.member)->optional = 1;
@@ -2356,7 +2356,7 @@ yyreduce:
     break;
 
   case 108:
-#line 769 "heimdal/lib/asn1/parse.y"
+#line 769 "parse.y"
     {
                        (yyval.member) = (yyvsp[(1) - (3)].member);
                        (yyval.member)->optional = 0;
@@ -2365,7 +2365,7 @@ yyreduce:
     break;
 
   case 109:
-#line 777 "heimdal/lib/asn1/parse.y"
+#line 777 "parse.y"
     {
                        (yyval.members) = emalloc(sizeof(*(yyval.members)));
                        ASN1_TAILQ_INIT((yyval.members));
@@ -2374,7 +2374,7 @@ yyreduce:
     break;
 
   case 110:
-#line 783 "heimdal/lib/asn1/parse.y"
+#line 783 "parse.y"
     {
                        ASN1_TAILQ_INSERT_TAIL((yyvsp[(1) - (3)].members), (yyvsp[(3) - (3)].member), members);
                        (yyval.members) = (yyvsp[(1) - (3)].members);
@@ -2382,7 +2382,7 @@ yyreduce:
     break;
 
   case 111:
-#line 790 "heimdal/lib/asn1/parse.y"
+#line 790 "parse.y"
     {
                  (yyval.member) = emalloc(sizeof(*(yyval.member)));
                  (yyval.member)->name = (yyvsp[(1) - (4)].name);
@@ -2396,26 +2396,26 @@ yyreduce:
     break;
 
   case 113:
-#line 803 "heimdal/lib/asn1/parse.y"
+#line 803 "parse.y"
     { (yyval.objid) = NULL; }
     break;
 
   case 114:
-#line 807 "heimdal/lib/asn1/parse.y"
+#line 807 "parse.y"
     {
                        (yyval.objid) = (yyvsp[(2) - (3)].objid);
                }
     break;
 
   case 115:
-#line 813 "heimdal/lib/asn1/parse.y"
+#line 813 "parse.y"
     {
                        (yyval.objid) = NULL;
                }
     break;
 
   case 116:
-#line 817 "heimdal/lib/asn1/parse.y"
+#line 817 "parse.y"
     {
                        if ((yyvsp[(2) - (2)].objid)) {
                                (yyval.objid) = (yyvsp[(2) - (2)].objid);
@@ -2427,14 +2427,14 @@ yyreduce:
     break;
 
   case 117:
-#line 828 "heimdal/lib/asn1/parse.y"
+#line 828 "parse.y"
     {
                        (yyval.objid) = new_objid((yyvsp[(1) - (4)].name), (yyvsp[(3) - (4)].constant));
                }
     break;
 
   case 118:
-#line 832 "heimdal/lib/asn1/parse.y"
+#line 832 "parse.y"
     {
                    Symbol *s = addsym((yyvsp[(1) - (1)].name));
                    if(s->stype != SValue ||
@@ -2448,14 +2448,14 @@ yyreduce:
     break;
 
   case 119:
-#line 843 "heimdal/lib/asn1/parse.y"
+#line 843 "parse.y"
     {
                    (yyval.objid) = new_objid(NULL, (yyvsp[(1) - (1)].constant));
                }
     break;
 
   case 129:
-#line 866 "heimdal/lib/asn1/parse.y"
+#line 866 "parse.y"
     {
                        Symbol *s = addsym((yyvsp[(1) - (1)].name));
                        if(s->stype != SValue)
@@ -2467,7 +2467,7 @@ yyreduce:
     break;
 
   case 130:
-#line 877 "heimdal/lib/asn1/parse.y"
+#line 877 "parse.y"
     {
                        (yyval.value) = emalloc(sizeof(*(yyval.value)));
                        (yyval.value)->type = stringvalue;
@@ -2476,7 +2476,7 @@ yyreduce:
     break;
 
   case 131:
-#line 885 "heimdal/lib/asn1/parse.y"
+#line 885 "parse.y"
     {
                        (yyval.value) = emalloc(sizeof(*(yyval.value)));
                        (yyval.value)->type = booleanvalue;
@@ -2485,7 +2485,7 @@ yyreduce:
     break;
 
   case 132:
-#line 891 "heimdal/lib/asn1/parse.y"
+#line 891 "parse.y"
     {
                        (yyval.value) = emalloc(sizeof(*(yyval.value)));
                        (yyval.value)->type = booleanvalue;
@@ -2494,7 +2494,7 @@ yyreduce:
     break;
 
   case 133:
-#line 899 "heimdal/lib/asn1/parse.y"
+#line 899 "parse.y"
     {
                        (yyval.value) = emalloc(sizeof(*(yyval.value)));
                        (yyval.value)->type = integervalue;
@@ -2503,13 +2503,13 @@ yyreduce:
     break;
 
   case 135:
-#line 910 "heimdal/lib/asn1/parse.y"
+#line 910 "parse.y"
     {
                }
     break;
 
   case 136:
-#line 915 "heimdal/lib/asn1/parse.y"
+#line 915 "parse.y"
     {
                        (yyval.value) = emalloc(sizeof(*(yyval.value)));
                        (yyval.value)->type = objectidentifiervalue;
@@ -2519,7 +2519,7 @@ yyreduce:
 
 
 /* Line 1267 of yacc.c.  */
-#line 2523 "heimdal/lib/asn1/parse.y"
+#line 2523 "parse.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -2733,7 +2733,7 @@ yyreturn:
 }
 
 
-#line 922 "heimdal/lib/asn1/parse.y"
+#line 922 "parse.y"
 
 
 void
index bea506ca7b984ab873e6cae8128e8c1a1a833d24..5e73094f9e6b2a1833f6d12a411c710437bc7d96 100644 (file)
 
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 65 "heimdal/lib/asn1/parse.y"
+#line 65 "parse.y"
 {
     int constant;
     struct value *value;
@@ -238,7 +238,7 @@ typedef union YYSTYPE
     struct constraint_spec *constraint_spec;
 }
 /* Line 1489 of yacc.c.  */
-#line 242 "heimdal/lib/asn1/parse.y"
+#line 242 "parse.h"
        YYSTYPE;
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
index 1bfc11ad740f362539094b45307fdec0388a2c3e..989b26581b3a1b69eea569b96e37bbef624da33a 100644 (file)
@@ -2,7 +2,7 @@
 
 PKINIT DEFINITIONS ::= BEGIN
 
-IMPORTS EncryptionKey, PrincipalName, Realm, KerberosTime, Checksum FROM krb5
+IMPORTS EncryptionKey, PrincipalName, Realm, KerberosTime, Checksum, Ticket FROM krb5
        IssuerAndSerialNumber, ContentInfo FROM cms
        SubjectPublicKeyInfo, AlgorithmIdentifier FROM rfc2459
        heim_any FROM heim;
@@ -40,6 +40,11 @@ td-dh-parameters INTEGER ::=             109
 
 DHNonce ::= OCTET STRING
 
+KDFAlgorithmId ::= SEQUENCE {
+       kdf-id            [0] OBJECT IDENTIFIER,
+       ...
+}
+
 TrustedCA ::= SEQUENCE {
        caName                  [0] IMPLICIT OCTET STRING,
        certificateSerialNumber [1] INTEGER OPTIONAL,
@@ -76,6 +81,8 @@ AuthPack ::= SEQUENCE {
        clientPublicValue       [1] SubjectPublicKeyInfo OPTIONAL,
        supportedCMSTypes       [2] SEQUENCE OF AlgorithmIdentifier OPTIONAL,
        clientDHNonce           [3] DHNonce OPTIONAL,
+       ...,
+       supportedKDFs           [4] SEQUENCE OF KDFAlgorithmId OPTIONAL,
        ...
 }
 
@@ -89,10 +96,12 @@ KRB5PrincipalName ::= SEQUENCE {
 
 AD-INITIAL-VERIFIED-CAS ::= SEQUENCE OF ExternalPrincipalIdentifier
 
-
 DHRepInfo ::= SEQUENCE {
        dhSignedData            [0] IMPLICIT OCTET STRING,
-       serverDHNonce           [1] DHNonce OPTIONAL
+       serverDHNonce           [1] DHNonce OPTIONAL,
+       ...,
+       kdf                     [2] KDFAlgorithmId OPTIONAL,
+       ...
 }
 
 PA-PK-AS-REP ::= CHOICE {
@@ -162,4 +171,12 @@ ReplyKeyPack-Win2k ::= SEQUENCE {
        ...
 }
 
+PkinitSuppPubInfo ::= SEQUENCE {
+       enctype           [0] INTEGER (-2147483648..2147483647),
+       as-REQ            [1] OCTET STRING,
+       pk-as-rep         [2] OCTET STRING,
+       ticket            [3] Ticket,
+       ...
+}
+
 END
index 0ec3b695ebebeb9c50a6015e9e25c4f226bf2f1a..8e24f0740b8a6b6f5a1f70b4bb4e4fcd37c484b8 100644 (file)
@@ -21,6 +21,8 @@ id-pkcs1-sha256WithRSAEncryption OBJECT IDENTIFIER ::=        { id-pkcs-1 11 }
 id-pkcs1-sha384WithRSAEncryption OBJECT IDENTIFIER ::= { id-pkcs-1 12 }
 id-pkcs1-sha512WithRSAEncryption OBJECT IDENTIFIER ::= { id-pkcs-1 13 }
 
+id-heim-rsa-pkcs1-x509 OBJECT IDENTIFIER ::= { 1  2 752 43 16 1 }
+
 id-pkcs-2 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
        rsadsi(113549) pkcs(1) 2 }
 id-pkcs2-md2 OBJECT IDENTIFIER ::=             { id-pkcs-2 2 }
index 7a85b302a11bcb80cab551a11c2ebe2acf9bbb88..3c6ea3beb71dfa4a8e78a718bfcb93c0c1234d3d 100644 (file)
@@ -1,6 +1,5 @@
-#include "config.h"
 
-#line 3 "heimdal/lib/com_err/lex.c"
+#line 3 "lex.c"
 
 #define  YY_INT_ALIGNED short int
 
@@ -524,7 +523,7 @@ char *yytext;
 #include "parse.h"
 #include "lex.h"
 
-RCSID("$Id: lex.l,v 1.8 2005/05/16 08:52:54 lha Exp $");
+RCSID("$Id: lex.l 15143 2005-05-16 08:52:54Z lha $");
 
 static unsigned lineno = 1;
 static int getstring(void);
@@ -533,7 +532,7 @@ static int getstring(void);
 
 #undef ECHO
 
-#line 536 "heimdal/lib/com_err/lex.c"
+#line 536 "lex.c"
 
 #define INITIAL 0
 
@@ -551,6 +550,35 @@ static int getstring(void);
 
 static int yy_init_globals (void );
 
+/* Accessor methods to globals.
+   These are made visible to non-reentrant scanners for convenience. */
+
+int yylex_destroy (void );
+
+int yyget_debug (void );
+
+void yyset_debug (int debug_flag  );
+
+YY_EXTRA_TYPE yyget_extra (void );
+
+void yyset_extra (YY_EXTRA_TYPE user_defined  );
+
+FILE *yyget_in (void );
+
+void yyset_in  (FILE * in_str  );
+
+FILE *yyget_out (void );
+
+void yyset_out  (FILE * out_str  );
+
+int yyget_leng (void );
+
+char *yyget_text (void );
+
+int yyget_lineno (void );
+
+void yyset_lineno (int line_number  );
+
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  */
@@ -688,7 +716,7 @@ YY_DECL
     
 #line 59 "lex.l"
 
-#line 691 "heimdal/lib/com_err/lex.c"
+#line 720 "lex.c"
 
        if ( !(yy_init) )
                {
@@ -852,7 +880,7 @@ YY_RULE_SETUP
 #line 75 "lex.l"
 ECHO;
        YY_BREAK
-#line 855 "heimdal/lib/com_err/lex.c"
+#line 884 "lex.c"
 case YY_STATE_EOF(INITIAL):
        yyterminate();
 
@@ -1083,7 +1111,7 @@ static int yy_get_next_buffer (void)
 
                /* Read in more data. */
                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
-                       (yy_n_chars), (size_t) num_to_read );
+                       (yy_n_chars), num_to_read );
 
                YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
                }
@@ -1584,7 +1612,7 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
 
 /** Setup the input buffer state to scan a string. The next call to yylex() will
  * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
+ * @param str a NUL-terminated string to scan
  * 
  * @return the newly allocated buffer state object.
  * @note If you want to scan bytes that may contain NUL values, then use
index 95fe18f16e4dabf25a69a4267c7513d6be31e6d6..4bacb721ca112acfb3bab591a2ece14f16737d4b 100644 (file)
@@ -90,7 +90,7 @@
 
 
 /* Copy the first part of user declarations.  */
-#line 1 "heimdal/lib/com_err/parse.y"
+#line 1 "parse.y"
 
 /*
  * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
@@ -163,13 +163,13 @@ extern char *yytext;
 
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 53 "heimdal/lib/com_err/parse.y"
+#line 53 "parse.y"
 {
   char *string;
   int number;
 }
 /* Line 187 of yacc.c.  */
-#line 173 "heimdal/lib/com_err/parse.y"
+#line 173 "parse.c"
        YYSTYPE;
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
@@ -182,7 +182,7 @@ typedef union YYSTYPE
 
 
 /* Line 216 of yacc.c.  */
-#line 186 "heimdal/lib/com_err/parse.y"
+#line 186 "parse.c"
 
 #ifdef short
 # undef short
@@ -1381,14 +1381,14 @@ yyreduce:
   switch (yyn)
     {
         case 6:
-#line 73 "heimdal/lib/com_err/parse.y"
+#line 73 "parse.y"
     {
                    id_str = (yyvsp[(2) - (2)].string);
                }
     break;
 
   case 7:
-#line 79 "heimdal/lib/com_err/parse.y"
+#line 79 "parse.y"
     {
                    base_id = name2number((yyvsp[(2) - (2)].string));
                    strlcpy(name, (yyvsp[(2) - (2)].string), sizeof(name));
@@ -1397,7 +1397,7 @@ yyreduce:
     break;
 
   case 8:
-#line 85 "heimdal/lib/com_err/parse.y"
+#line 85 "parse.y"
     {
                    base_id = name2number((yyvsp[(2) - (3)].string));
                    strlcpy(name, (yyvsp[(3) - (3)].string), sizeof(name));
@@ -1407,14 +1407,14 @@ yyreduce:
     break;
 
   case 11:
-#line 98 "heimdal/lib/com_err/parse.y"
+#line 98 "parse.y"
     {
                        number = (yyvsp[(2) - (2)].number);
                }
     break;
 
   case 12:
-#line 102 "heimdal/lib/com_err/parse.y"
+#line 102 "parse.y"
     {
                    free(prefix);
                    asprintf (&prefix, "%s_", (yyvsp[(2) - (2)].string));
@@ -1425,7 +1425,7 @@ yyreduce:
     break;
 
   case 13:
-#line 110 "heimdal/lib/com_err/parse.y"
+#line 110 "parse.y"
     {
                    prefix = realloc(prefix, 1);
                    if (prefix == NULL)
@@ -1435,7 +1435,7 @@ yyreduce:
     break;
 
   case 14:
-#line 117 "heimdal/lib/com_err/parse.y"
+#line 117 "parse.y"
     {
                    struct error_code *ec = malloc(sizeof(*ec));
                    
@@ -1458,7 +1458,7 @@ yyreduce:
     break;
 
   case 15:
-#line 137 "heimdal/lib/com_err/parse.y"
+#line 137 "parse.y"
     {
                        YYACCEPT;
                }
@@ -1466,7 +1466,7 @@ yyreduce:
 
 
 /* Line 1267 of yacc.c.  */
-#line 1470 "heimdal/lib/com_err/parse.y"
+#line 1470 "parse.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1680,7 +1680,7 @@ yyreturn:
 }
 
 
-#line 142 "heimdal/lib/com_err/parse.y"
+#line 142 "parse.y"
 
 
 static long
index 9aabca90236f4b732d92c6930a159af8e4e3c553..4c9681ff34f5aaa6e6a84c5b39285fcd5feb2a20 100644 (file)
 
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 53 "heimdal/lib/com_err/parse.y"
+#line 53 "parse.y"
 {
   char *string;
   int number;
 }
 /* Line 1489 of yacc.c.  */
-#line 74 "heimdal/lib/com_err/parse.y"
+#line 74 "parse.h"
        YYSTYPE;
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
index cca529fe26ff5c9e1f43f9a34e436728ce7f24b7..2223f4f22f778f916d6e36fb3c4ee4b761785c68 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE. 
  */
 
-/* $Id: gssapi_krb5.h 20385 2007-04-18 08:51:32Z lha $ */
+/* $Id: gssapi_krb5.h 22655 2008-02-26 12:40:35Z lha $ */
 
 #ifndef GSSAPI_KRB5_H_
 #define GSSAPI_KRB5_H_
@@ -80,6 +80,7 @@ extern gss_OID GSS_KRB5_GET_SERVICE_KEYBLOCK_X;
 /* Extensions creds */
 extern gss_OID GSS_KRB5_IMPORT_CRED_X;
 extern gss_OID GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X;
+extern gss_OID GSS_KRB5_CRED_NO_CI_FLAGS_X;
 
 /*
  * kerberos mechanism specific functions
index 403990ad47a1d68087bdb873feda43585d3af38d..b360de13fcaf53192de49fc62d6c719ef72610cb 100644 (file)
@@ -356,4 +356,6 @@ gssapi_mech_interface __gss_spnego_initialize(void);
 gssapi_mech_interface __gss_krb5_initialize(void);
 gssapi_mech_interface __gss_ntlm_initialize(void);
 
+void           gss_mg_collect_error(gss_OID, OM_uint32, OM_uint32);
+
 #endif /* GSSAPI_MECH_H */
index d5c70636bc5824f9834fa8232494d460e65c4765..051446c19b4d4e09bc32f2b048816ce1106d7647 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "krb5/gsskrb5_locl.h"
 
-RCSID("$Id: acquire_cred.c 21221 2007-06-20 08:42:10Z lha $");
+RCSID("$Id: acquire_cred.c 22596 2008-02-18 18:05:55Z lha $");
 
 OM_uint32
 __gsskrb5_ccache_lifetime(OM_uint32 *minor_status,
@@ -128,9 +128,12 @@ static OM_uint32 acquire_initiator_cred
     ret = GSS_S_FAILURE;
     memset(&cred, 0, sizeof(cred));
 
-    /* If we have a preferred principal, lets try to find it in all
-     * caches, otherwise, fall back to default cache.  Ignore
-     * errors. */
+    /* 
+     * If we have a preferred principal, lets try to find it in all
+     * caches, otherwise, fall back to default cache, ignore all
+     * errors while searching.
+     */
+
     if (handle->principal)
        kret = krb5_cc_cache_match (context,
                                    handle->principal,
@@ -142,32 +145,30 @@ static OM_uint32 acquire_initiator_cred
        if (kret)
            goto end;
     }
-    kret = krb5_cc_get_principal(context, ccache,
-       &def_princ);
+    kret = krb5_cc_get_principal(context, ccache, &def_princ);
     if (kret != 0) {
        /* we'll try to use a keytab below */
-       krb5_cc_destroy(context, ccache);
-       ccache = NULL;
+       krb5_cc_close(context, ccache);
+       def_princ = NULL;
        kret = 0;
     } else if (handle->principal == NULL)  {
-       kret = krb5_copy_principal(context, def_princ,
-           &handle->principal);
+       kret = krb5_copy_principal(context, def_princ, &handle->principal);
        if (kret)
            goto end;
     } else if (handle->principal != NULL &&
-       krb5_principal_compare(context, handle->principal,
-       def_princ) == FALSE) {
-       /* Before failing, lets check the keytab */
+              krb5_principal_compare(context, handle->principal,
+                                     def_princ) == FALSE) {
        krb5_free_principal(context, def_princ);
        def_princ = NULL;
+       krb5_cc_close(context, ccache);
+       ccache = NULL;
     }
     if (def_princ == NULL) {
        /* We have no existing credentials cache,
         * so attempt to get a TGT using a keytab.
         */
        if (handle->principal == NULL) {
-           kret = krb5_get_default_principal(context,
-               &handle->principal);
+           kret = krb5_get_default_principal(context, &handle->principal);
            if (kret)
                goto end;
        }
@@ -182,16 +183,19 @@ static OM_uint32 acquire_initiator_cred
        krb5_get_init_creds_opt_free(context, opt);
        if (kret)
            goto end;
-       kret = krb5_cc_gen_new(context, &krb5_mcc_ops,
-               &ccache);
+       kret = krb5_cc_gen_new(context, &krb5_mcc_ops, &ccache);
        if (kret)
            goto end;
        kret = krb5_cc_initialize(context, ccache, cred.client);
-       if (kret)
+       if (kret) {
+           krb5_cc_destroy(context, ccache);
            goto end;
+       }
        kret = krb5_cc_store_cred(context, ccache, &cred);
-       if (kret)
+       if (kret) {
+           krb5_cc_destroy(context, ccache);
            goto end;
+       }
        handle->lifetime = cred.times.endtime;
        handle->cred_flags |= GSS_CF_DESTROY_CRED_ON_RELEASE;
     } else {
@@ -201,8 +205,10 @@ static OM_uint32 acquire_initiator_cred
                                        ccache,
                                        handle->principal,
                                        &handle->lifetime);
-       if (ret != GSS_S_COMPLETE)
+       if (ret != GSS_S_COMPLETE) {
+           krb5_cc_close(context, ccache);
            goto end;
+       }
        kret = 0;
     }
 
@@ -216,13 +222,8 @@ end:
        krb5_free_principal(context, def_princ);
     if (keytab != NULL)
        krb5_kt_close(context, keytab);
-    if (ret != GSS_S_COMPLETE) {
-       if (ccache != NULL)
-           krb5_cc_close(context, ccache);
-       if (kret != 0) {
-           *minor_status = kret;
-       }
-    }
+    if (ret != GSS_S_COMPLETE && kret != 0)
+       *minor_status = kret;
     return (ret);
 }
 
@@ -257,8 +258,23 @@ static OM_uint32 acquire_acceptor_cred
            goto end;
        krb5_kt_free_entry(context, &entry);
        ret = GSS_S_COMPLETE;
-    }
+    } else {
+       /* 
+        * Check if there is at least one entry in the keytab before
+        * declaring it as an useful keytab.
+        */
+       krb5_keytab_entry tmp;
+       krb5_kt_cursor c;
+
+       kret = krb5_kt_start_seq_get (context, handle->keytab, &c);
+       if (kret)
+           goto end;
+       if (krb5_kt_next_entry(context, handle->keytab, &tmp, &c) == 0) {
+           krb5_kt_free_entry(context, &tmp);
+           ret = GSS_S_COMPLETE; /* ok found one entry */
+       }
+       krb5_kt_end_seq_get (context, handle->keytab, &c);
+    } 
 end:
     if (ret != GSS_S_COMPLETE) {
        if (handle->keytab != NULL)
index d4c1bc4db299d00d0a346ba9b3a322f1824d14dc..03fe61dc5744f772dfd98934d08d16b97aa92fa2 100644 (file)
@@ -34,7 +34,7 @@
 #include "krb5/gsskrb5_locl.h"
 #include <gssapi_mech.h>
 
-RCSID("$Id: external.c 20386 2007-04-18 08:52:08Z lha $");
+RCSID("$Id: external.c 22128 2007-12-04 00:56:55Z lha $");
 
 /*
  * The implementation must reserve static storage for a
@@ -374,8 +374,6 @@ gss_OID GSS_SASL_DIGEST_MD5_MECHANISM = &gss_sasl_digest_md5_mechanism_desc;
  * Context for krb5 calls.
  */
 
-krb5_context context;
-
 /*
  *
  */
index c2239f1346258876f6db00427f46b8d033fa6c53..64a0dd36b19d9cd6d0ed083915ac6a6f4a9a266a 100644 (file)
@@ -413,7 +413,7 @@ _gsskrb5_init (krb5_context */*context*/);
 OM_uint32
 _gsskrb5_init_sec_context (
        OM_uint32 * /*minor_status*/,
-       const gss_cred_id_t /*initiator_cred_handle*/,
+       const gss_cred_id_t /*cred_handle*/,
        gss_ctx_id_t * /*context_handle*/,
        const gss_name_t /*target_name*/,
        const gss_OID /*mech_type*/,
index 6ffb6070352fc85c512375fd3509645f76c6a209..3e8c1b8fa65de5d7952a343478b037f24b183c32 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE. 
  */
 
-/* $Id: gsskrb5_locl.h 20324 2007-04-12 16:46:01Z lha $ */
+/* $Id: gsskrb5_locl.h 22655 2008-02-26 12:40:35Z lha $ */
 
 #ifndef GSSKRB5_LOCL_H
 #define GSSKRB5_LOCL_H
@@ -86,6 +86,7 @@ typedef struct {
   krb5_principal principal;
   int cred_flags;
 #define GSS_CF_DESTROY_CRED_ON_RELEASE 1
+#define GSS_CF_NO_CI_FLAGS             2
   struct krb5_keytab_data *keytab;
   OM_uint32 lifetime;
   gss_cred_usage_t usage;
index 4d1ae0daa9f9042236e472b248a256a554f8bf9b..d4482a54b275243ca8414d4c069c001c42544b4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden). 
  * All rights reserved. 
  *
@@ -33,7 +33,7 @@
 
 #include "krb5/gsskrb5_locl.h"
 
-RCSID("$Id: init_sec_context.c 20326 2007-04-12 16:49:57Z lha $");
+RCSID("$Id: init_sec_context.c 22671 2008-03-09 23:57:54Z lha $");
 
 /*
  * copy the addresses from `input_chan_bindings' (if any) to
@@ -326,7 +326,7 @@ do_delegation (krb5_context context,
 static OM_uint32
 init_auth
 (OM_uint32 * minor_status,
- gsskrb5_cred initiator_cred_handle,
+ gsskrb5_cred cred,
  gsskrb5_ctx ctx,
  krb5_context context,
  krb5_const_principal name,
@@ -344,7 +344,7 @@ init_auth
     OM_uint32 ret = GSS_S_FAILURE;
     krb5_error_code kret;
     krb5_flags ap_options;
-    krb5_creds *cred = NULL;
+    krb5_creds *kcred = NULL;
     krb5_data outbuf;
     krb5_ccache ccache = NULL;
     uint32_t flags;
@@ -362,7 +362,7 @@ init_auth
     if (actual_mech_type)
        *actual_mech_type = GSS_KRB5_MECHANISM;
 
-    if (initiator_cred_handle == NULL) {
+    if (cred == NULL) {
        kret = krb5_cc_default (context, &ccache);
        if (kret) {
            *minor_status = kret;
@@ -370,7 +370,7 @@ init_auth
            goto failure;
        }
     } else
-       ccache = initiator_cred_handle->ccache;
+       ccache = cred->ccache;
 
     kret = krb5_cc_get_principal (context, ccache, &ctx->source);
     if (kret) {
@@ -400,8 +400,8 @@ init_auth
     {
        krb5_enctype *enctypes = NULL;
 
-       if (initiator_cred_handle && initiator_cred_handle->enctypes)
-           enctypes = initiator_cred_handle->enctypes;
+       if (cred && cred->enctypes)
+           enctypes = cred->enctypes;
        krb5_set_default_in_tkt_etypes(context, enctypes);
     }
 
@@ -412,11 +412,11 @@ init_auth
                            ctx->target,
                            time_req,
                            time_rec,
-                           &cred);
+                           &kcred);
     if (ret)
        goto failure;
 
-    ctx->lifetime = cred->times.endtime;
+    ctx->lifetime = kcred->times.endtime;
 
     ret = _gsskrb5_lifetime_left(minor_status,
                                 context,
@@ -434,11 +434,11 @@ init_auth
 
     krb5_auth_con_setkey(context, 
                         ctx->auth_context, 
-                        &cred->session);
+                        &kcred->session);
 
     kret = krb5_auth_con_generatelocalsubkey(context, 
                                             ctx->auth_context,
-                                            &cred->session);
+                                            &kcred->session);
     if(kret) {
        *minor_status = kret;
        ret = GSS_S_FAILURE;
@@ -449,10 +449,10 @@ init_auth
      * If the credential doesn't have ok-as-delegate, check what local
      * policy say about ok-as-delegate, default is FALSE that makes
      * code ignore the KDC setting and follow what the application
-     * requested. If its TRUE, strip of the GSS_C_DELEG_FLAG if the
+     * requested. If it is TRUE, strip of the GSS_C_DELEG_FLAG if the
      * KDC doesn't set ok-as-delegate.
      */
-    if (!cred->flags.b.ok_as_delegate) {
+    if (!kcred->flags.b.ok_as_delegate) {
        krb5_boolean delegate;
     
        krb5_appdefault_boolean(context,
@@ -467,7 +467,7 @@ init_auth
     if (req_flags & GSS_C_DELEG_FLAG)
        do_delegation (context,
                       ctx->auth_context,
-                      ccache, cred, name, &fwd_data, &flags);
+                      ccache, kcred, name, &fwd_data, &flags);
     
     if (req_flags & GSS_C_MUTUAL_FLAG) {
        flags |= GSS_C_MUTUAL_FLAG;
@@ -490,8 +490,10 @@ init_auth
     if (req_flags & GSS_C_EXTENDED_ERROR_FLAG)
        flags |= GSS_C_EXTENDED_ERROR_FLAG;
 
-    flags |= GSS_C_CONF_FLAG;
-    flags |= GSS_C_INTEG_FLAG;
+    if (cred == NULL || !(cred->cred_flags & GSS_CF_NO_CI_FLAGS)) {
+       flags |= GSS_C_CONF_FLAG;
+       flags |= GSS_C_INTEG_FLAG;
+    }
     flags |= GSS_C_TRANS_FLAG;
     
     if (ret_flags)
@@ -513,7 +515,7 @@ init_auth
     kret = krb5_build_authenticator (context,
                                     ctx->auth_context,
                                     enctype,
-                                    cred,
+                                    kcred,
                                     &cksum,
                                     NULL,
                                     &authenticator,
@@ -527,7 +529,7 @@ init_auth
 
     kret = krb5_build_ap_req (context,
                              enctype,
-                             cred,
+                             kcred,
                              ap_options,
                              authenticator,
                              &outbuf);
@@ -544,9 +546,9 @@ init_auth
        goto failure;
 
     krb5_data_free (&outbuf);
-    krb5_free_creds(context, cred);
+    krb5_free_creds(context, kcred);
     free_Checksum(&cksum);
-    if (initiator_cred_handle == NULL)
+    if (cred == NULL)
        krb5_cc_close(context, ccache);
 
     if (flags & GSS_C_MUTUAL_FLAG) {
@@ -556,9 +558,9 @@ init_auth
 
     return gsskrb5_initiator_ready(minor_status, ctx, context);
 failure:
-    if(cred)
-       krb5_free_creds(context, cred);
-    if (ccache && initiator_cred_handle == NULL)
+    if(kcred)
+       krb5_free_creds(context, kcred);
+    if (ccache && cred == NULL)
        krb5_cc_close(context, ccache);
 
     return ret;
@@ -682,7 +684,7 @@ repl_mutual
 
 OM_uint32 _gsskrb5_init_sec_context
 (OM_uint32 * minor_status,
- const gss_cred_id_t initiator_cred_handle,
+ const gss_cred_id_t cred_handle,
  gss_ctx_id_t * context_handle,
  const gss_name_t target_name,
  const gss_OID mech_type,
@@ -697,7 +699,7 @@ OM_uint32 _gsskrb5_init_sec_context
     )
 {
     krb5_context context;
-    gsskrb5_cred cred = (gsskrb5_cred)initiator_cred_handle;
+    gsskrb5_cred cred = (gsskrb5_cred)cred_handle;
     krb5_const_principal name = (krb5_const_principal)target_name;
     gsskrb5_ctx ctx;
     OM_uint32 ret;
index d0ca1c4d95ddf779ebc3969a2c02a0669c2d24c0..242dfa87b476982e967b2fb1acbbcdf5d30dc987 100644 (file)
 
 #include "krb5/gsskrb5_locl.h"
 
-RCSID("$Id: set_cred_option.c 20325 2007-04-12 16:49:17Z lha $");
+RCSID("$Id: set_cred_option.c 22655 2008-02-26 12:40:35Z lha $");
 
+/* 1.2.752.43.13.17 */
+static gss_OID_desc gss_krb5_ccache_name_x_oid_desc =
+{6, rk_UNCONST("\x2a\x85\x70\x2b\x0d\x11")};
+
+gss_OID GSS_KRB5_CRED_NO_CI_FLAGS_X = &gss_krb5_ccache_name_x_oid_desc;
+
+/* 1.2.752.43.13.18 */
 static gss_OID_desc gss_krb5_import_cred_x_oid_desc =
-{9, (void *)"\x2b\x06\x01\x04\x01\xa9\x4a\x13\x04"}; /* XXX */
+{6, rk_UNCONST("\x2a\x85\x70\x2b\x0d\x12")};
 
 gss_OID GSS_KRB5_IMPORT_CRED_X = &gss_krb5_import_cred_x_oid_desc;
 
+
+
 static OM_uint32
 import_cred(OM_uint32 *minor_status,
            krb5_context context,
@@ -201,6 +210,27 @@ out:
     return major_stat;
 }
 
+static OM_uint32
+no_ci_flags(OM_uint32 *minor_status,
+           krb5_context context,
+           gss_cred_id_t *cred_handle,
+           const gss_buffer_t value)
+{
+    gsskrb5_cred cred;
+
+    if (cred_handle == NULL || *cred_handle == GSS_C_NO_CREDENTIAL) {
+       *minor_status = 0;
+       return GSS_S_FAILURE;
+    }
+
+    cred = (gsskrb5_cred)*cred_handle;
+    cred->cred_flags |= GSS_CF_NO_CI_FLAGS;
+       
+    *minor_status = 0;
+    return GSS_S_COMPLETE;
+
+}
+
 
 OM_uint32
 _gsskrb5_set_cred_option
@@ -224,6 +254,11 @@ _gsskrb5_set_cred_option
     if (gss_oid_equal(desired_object, GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X))
        return allowed_enctypes(minor_status, context, cred_handle, value);
 
+    if (gss_oid_equal(desired_object, GSS_KRB5_CRED_NO_CI_FLAGS_X)) {
+       return no_ci_flags(minor_status, context, cred_handle, value);
+    }
+       
+
     *minor_status = EINVAL;
     return GSS_S_FAILURE;
 }
index e4517bee449cbcb364d4997c7b141ee22a130813..926630c42dcd0c41742ec73c39c6102ba3a2d5e6 100644 (file)
@@ -1,7 +1,7 @@
 #include "mech/mech_locl.h"
 #include "heim_threads.h"
 
-RCSID("$Id: context.c 21248 2007-06-21 00:45:13Z lha $");
+RCSID("$Id: context.c 22600 2008-02-21 12:46:24Z lha $");
 
 struct mg_thread_ctx {
     gss_OID mech;
@@ -107,6 +107,13 @@ _gss_mg_error(gssapi_mech_interface m, OM_uint32 maj, OM_uint32 min)
     OM_uint32 message_content;
     struct mg_thread_ctx *mg;
 
+    /* 
+     * Mechs without gss_display_status() does
+     * gss_mg_collect_error() by themself.
+     */
+    if (m->gm_display_status == NULL)
+       return ;
+
     mg = _gss_mechglue_thread();
     if (mg == NULL)
        return;
@@ -139,3 +146,12 @@ _gss_mg_error(gssapi_mech_interface m, OM_uint32 maj, OM_uint32 min)
        mg->min_error.length = 0;
     }
 }
+
+void
+gss_mg_collect_error(gss_OID mech, OM_uint32 maj, OM_uint32 min)
+{
+    gssapi_mech_interface m = __gss_get_mechanism(mech);
+    if (m == NULL)
+       return;
+    _gss_mg_error(m, maj, min);
+}
index d1e243d8b854a16c47a8ece08b8024e5ca700b5b..a6b1ded5cad50141e959fab969f8903432ebd462 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 #include "mech_locl.h"
-RCSID("$Id: gss_accept_sec_context.c 21237 2007-06-20 11:21:09Z lha $");
+RCSID("$Id: gss_accept_sec_context.c 22071 2007-11-14 20:04:50Z lha $");
 
 static OM_uint32
 parse_header(const gss_buffer_t input_token, gss_OID mech_oid)
@@ -38,7 +38,7 @@ parse_header(const gss_buffer_t input_token, gss_OID mech_oid)
        
        /*
         * Token must start with [APPLICATION 0] SEQUENCE.
-        * But if it doesn't assume its DCE-STYLE Kerberos!
+        * But if it doesn't assume it is DCE-STYLE Kerberos!
         */
        if (len == 0)
                return (GSS_S_DEFECTIVE_TOKEN);
@@ -102,7 +102,7 @@ choose_mech(const gss_buffer_t input, gss_OID mech_oid)
        OM_uint32 status;
 
        /*
-        * First try to parse the gssapi token header and see if its a
+        * First try to parse the gssapi token header and see if it's a
         * correct header, use that in the first hand.
         */
 
index 9e77f429828e1be63a73be0cb212adff807253c3..03081cb70ffe906262a4c2436b21456a1a221dc8 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 #include "mech_locl.h"
-RCSID("$Id: gss_krb5.c 21123 2007-06-18 20:05:26Z lha $");
+RCSID("$Id: gss_krb5.c 21889 2007-08-09 07:43:24Z lha $");
 
 #include <krb5.h>
 #include <roken.h>
@@ -253,7 +253,6 @@ free_key(gss_krb5_lucid_key_t *key)
     memset(key, 0, sizeof(*key));
 }
 
-
 OM_uint32
 gss_krb5_export_lucid_sec_context(OM_uint32 *minor_status,
                                  gss_ctx_id_t *context_handle,
@@ -824,3 +823,43 @@ gsskrb5_set_default_realm(const char *realm)
 
        return (GSS_S_COMPLETE);
 }
+
+OM_uint32
+gss_krb5_get_tkt_flags(OM_uint32 *minor_status,
+                      gss_ctx_id_t context_handle,
+                      OM_uint32 *tkt_flags)
+{
+
+    OM_uint32 major_status;
+    gss_buffer_set_t data_set = GSS_C_NO_BUFFER_SET;
+
+    if (context_handle == GSS_C_NO_CONTEXT) {
+       *minor_status = EINVAL;
+       return GSS_S_FAILURE;
+    }
+    
+    major_status =
+       gss_inquire_sec_context_by_oid (minor_status,
+                                       context_handle,
+                                       GSS_KRB5_GET_TKT_FLAGS_X,
+                                       &data_set);
+    if (major_status)
+       return major_status;
+    
+    if (data_set == GSS_C_NO_BUFFER_SET || 
+       data_set->count != 1 ||
+       data_set->elements[0].length < 4) {
+       gss_release_buffer_set(minor_status, &data_set);
+       *minor_status = EINVAL;
+       return GSS_S_FAILURE;
+    }
+
+    {
+       const u_char *p = data_set->elements[0].value;
+       *tkt_flags = (p[0] << 0) | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
+    }
+
+    gss_release_buffer_set(minor_status, &data_set);
+    return GSS_S_COMPLETE;
+}
+
index f1a18afb13a65cf77dad28737f02f0977e272296..fe65ad1ae15561c0b309b3b10dd3eb55daa3bcd7 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "mech_locl.h"
 #include <heim_threads.h>
-RCSID("$Id: gss_mech_switch.c 21700 2007-07-26 19:08:34Z lha $");
+RCSID("$Id: gss_mech_switch.c 21698 2007-07-26 19:07:11Z lha $");
 
 #ifndef _PATH_GSS_MECH
 #define _PATH_GSS_MECH "/etc/gss/mech"
index 4372e622948b2bf0efd28acb599138360cecd102..388cfdbf4cfa0012b13085ee4348040255ac6675 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 #include "mech_locl.h"
-RCSID("$Id: gss_release_oid_set.c 19963 2007-01-17 16:01:22Z lha $");
+RCSID("$Id: gss_release_oid_set.c 22144 2007-12-04 17:31:55Z lha $");
 
 OM_uint32
 gss_release_oid_set(OM_uint32 *minor_status,
@@ -35,7 +35,7 @@ gss_release_oid_set(OM_uint32 *minor_status,
 {
 
        *minor_status = 0;
-       if (*set) {
+       if (set && *set) {
                if ((*set)->elements)
                        free((*set)->elements);
                free(*set);
index 1afe26f1e39dae042c68a37f69fa792a49a8efa9..df25b0f4bf61c76570c2de575f03ad118661cc2b 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "spnego/spnego_locl.h"
 
-RCSID("$Id: accept_sec_context.c 21461 2007-07-10 14:01:13Z lha $");
+RCSID("$Id: accept_sec_context.c 22600 2008-02-21 12:46:24Z lha $");
 
 static OM_uint32
 send_reject (OM_uint32 *minor_status,
@@ -540,7 +540,7 @@ acceptor_start
            gss_cred_id_t *delegated_cred_handle
           )
 {
-    OM_uint32 ret, junk, minor;
+    OM_uint32 ret, junk;
     NegotiationToken nt;
     size_t nt_len;
     NegTokenInit *ni;
@@ -609,7 +609,7 @@ acceptor_start
     /*
      * First we try the opportunistic token if we have support for it,
      * don't try to verify we have credential for the token,
-     * gss_accept_sec_context will (hopefully) tell us that.
+     * gss_accept_sec_context() will (hopefully) tell us that.
      * If that failes, 
      */
 
@@ -633,12 +633,12 @@ acceptor_start
            mech_cred = GSS_C_NO_CREDENTIAL;
        
        if (ctx->mech_src_name != GSS_C_NO_NAME)
-           gss_release_name(&minor, &ctx->mech_src_name);
+           gss_release_name(&junk, &ctx->mech_src_name);
        
        if (ctx->delegated_cred_id != GSS_C_NO_CREDENTIAL)
-           _gss_spnego_release_cred(&minor, &ctx->delegated_cred_id);
+           _gss_spnego_release_cred(&junk, &ctx->delegated_cred_id);
        
-       ret = gss_accept_sec_context(&minor,
+       ret = gss_accept_sec_context(minor_status,
                                     &ctx->negotiated_ctx_id,
                                     mech_cred,
                                     mech_input_token,
@@ -656,7 +656,7 @@ acceptor_start
                ctx->open = 1;
 
            if (mech_delegated_cred && delegated_cred_handle)
-               ret = _gss_spnego_alloc_cred(minor_status,
+               ret = _gss_spnego_alloc_cred(&junk,
                                             mech_delegated_cred,
                                             delegated_cred_handle);
            else
@@ -674,6 +674,8 @@ acceptor_start
                goto out;
 
            first_ok = 1;
+       } else {
+           gss_mg_collect_error(preferred_mech_type, ret, *minor_status);
        }
     }
 
@@ -681,7 +683,9 @@ acceptor_start
      * If opportunistic token failed, lets try the other mechs.
      */
 
-    if (!first_ok) {
+    if (!first_ok && ni->mechToken != NULL) {
+
+       preferred_mech_type = GSS_C_NO_OID;
 
        /* Call glue layer to find first mech we support */
        for (i = 1; i < ni->mechTypes.len; ++i) {
@@ -695,7 +699,7 @@ acceptor_start
        if (preferred_mech_type == GSS_C_NO_OID) {
            HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);
            free_NegotiationToken(&nt);
-           return GSS_S_BAD_MECH;
+           return ret;
        }
 
        ctx->preferred_mech_type = preferred_mech_type;
@@ -717,7 +721,7 @@ acceptor_start
     
 out:
     if (mech_output_token.value != NULL)
-       gss_release_buffer(&minor, &mech_output_token);
+       gss_release_buffer(&junk, &mech_output_token);
     if (mech_buf.value != NULL) {
        free(mech_buf.value);
        mech_buf.value = NULL;
@@ -754,7 +758,7 @@ out:
        return ret;
     }
 
-    _gss_spnego_internal_delete_sec_context(&minor, context_handle,
+    _gss_spnego_internal_delete_sec_context(&junk, context_handle,
                                            GSS_C_NO_BUFFER);
     
     return ret;
@@ -877,6 +881,7 @@ acceptor_continue
            }
            if (ret != GSS_S_COMPLETE && ret != GSS_S_CONTINUE_NEEDED) {
                free_NegotiationToken(&nt);
+               gss_mg_collect_error(ctx->negotiated_mech_type, ret, minor);
                send_reject (minor_status, output_token);
                HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);
                return ret;
index bc7da9410e6a71317e7f65d3a8300353c2005afd..287f4f760ed76871241cf41d1dd5404f4dca07c0 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "spnego/spnego_locl.h"
 
-RCSID("$Id: compat.c 19415 2006-12-18 17:52:26Z lha $");
+RCSID("$Id: compat.c 21866 2007-08-08 11:31:29Z lha $");
 
 /*
  * Apparently Microsoft got the OID wrong, and used
@@ -129,6 +129,7 @@ OM_uint32 _gss_spnego_internal_delete_sec_context
     gss_release_oid(&minor, &ctx->preferred_mech_type);
     ctx->negotiated_mech_type = GSS_C_NO_OID;
 
+    gss_release_name(&minor, &ctx->target_name);
     gss_release_name(&minor, &ctx->mech_src_name);
 
     if (ctx->negotiated_ctx_id != GSS_C_NO_CONTEXT) {
index 3535c7bb3596cb782b0fe745eb5fd1ad8478d529..0169017ee5af9de3bff86d5b3db2fad233ee76ac 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "spnego/spnego_locl.h"
 
-RCSID("$Id: context_stubs.c 21035 2007-06-09 15:32:47Z lha $");
+RCSID("$Id: context_stubs.c 22604 2008-02-21 21:12:48Z lha $");
 
 static OM_uint32
 spnego_supported_mechs(OM_uint32 *minor_status, gss_OID_set *mechs)
@@ -263,18 +263,6 @@ OM_uint32 _gss_spnego_unwrap
                      qop_state);
 }
 
-OM_uint32 _gss_spnego_display_status
-           (OM_uint32 * minor_status,
-            OM_uint32 status_value,
-            int status_type,
-            const gss_OID mech_type,
-            OM_uint32 * message_context,
-            gss_buffer_t status_string
-           )
-{
-    return GSS_S_FAILURE;
-}
-
 OM_uint32 _gss_spnego_compare_name
            (OM_uint32 *minor_status,
             const gss_name_t name1,
@@ -406,28 +394,58 @@ OM_uint32 _gss_spnego_inquire_context (
            )
 {
     gssspnego_ctx ctx;
+    OM_uint32 maj_stat, junk;
+    gss_name_t src_mn, targ_mn;
 
     *minor_status = 0;
 
-    if (context_handle == GSS_C_NO_CONTEXT) {
+    if (context_handle == GSS_C_NO_CONTEXT)
        return GSS_S_NO_CONTEXT;
-    }
 
     ctx = (gssspnego_ctx)context_handle;
 
-    if (ctx->negotiated_ctx_id == GSS_C_NO_CONTEXT) {
+    if (ctx->negotiated_ctx_id == GSS_C_NO_CONTEXT)
        return GSS_S_NO_CONTEXT;
-    }
 
-    return gss_inquire_context(minor_status,
-                              ctx->negotiated_ctx_id,
-                              src_name,
-                              targ_name,
-                              lifetime_rec,
-                              mech_type,
-                              ctx_flags,
-                              locally_initiated,
-                              open_context);
+    maj_stat = gss_inquire_context(minor_status,
+                                  ctx->negotiated_ctx_id,
+                                  &src_mn,
+                                  &targ_mn,
+                                  lifetime_rec,
+                                  mech_type,
+                                  ctx_flags,
+                                  locally_initiated,
+                                  open_context);
+    if (maj_stat != GSS_S_COMPLETE)
+       return maj_stat;
+
+    if (src_name) {
+       spnego_name name = calloc(1, sizeof(*name));
+       if (name == NULL)
+           goto enomem;
+       name->mech = src_mn;
+       *src_name = (gss_name_t)name;
+    } else
+       gss_release_name(&junk, &src_mn);
+    
+    if (targ_name) {
+       spnego_name name = calloc(1, sizeof(*name));
+       if (name == NULL) {
+           gss_release_name(minor_status, src_name);
+           goto enomem;
+       }
+       name->mech = targ_mn;
+       *targ_name = (gss_name_t)name;
+    } else
+       gss_release_name(&junk, &targ_mn);
+
+    return GSS_S_COMPLETE;
+
+enomem:
+    gss_release_name(&junk, &targ_mn);
+    gss_release_name(&junk, &src_mn);
+    *minor_status = ENOMEM;
+    return GSS_S_FAILURE;
 }
 
 OM_uint32 _gss_spnego_wrap_size_limit (
index fbc231f3aebbdb53d73ff8d31a8e55e105f10daf..6c9a03a3b0042c66f7c81115310ebfc353da5089 100644 (file)
@@ -33,7 +33,7 @@
 #include "spnego/spnego_locl.h"
 #include <gssapi_mech.h>
 
-RCSID("$Id: external.c 18336 2006-10-07 22:27:13Z lha $");
+RCSID("$Id: external.c 22600 2008-02-21 12:46:24Z lha $");
 
 /*
  * RFC2478, SPNEGO:
@@ -57,7 +57,7 @@ static gssapi_mech_interface_desc spnego_mech = {
     _gss_spnego_verify_mic,
     _gss_spnego_wrap,
     _gss_spnego_unwrap,
-    _gss_spnego_display_status,
+    NULL,
     NULL,
     _gss_spnego_compare_name,
     _gss_spnego_display_name,
index 7c74981e664e880a9bd6ee45da07d2d947df6978..bee489589810d076fb4047f71ec39621f42ac1e8 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "spnego/spnego_locl.h"
 
-RCSID("$Id: init_sec_context.c 19411 2006-12-18 15:42:03Z lha $");
+RCSID("$Id: init_sec_context.c 22600 2008-02-21 12:46:24Z lha $");
 
 /*
  * Is target_name an sane target for `mech´.
@@ -59,8 +59,10 @@ initiator_approved(gss_name_t target_name, gss_OID mech)
                                    &out,
                                    NULL,
                                    NULL);
-    if (GSS_ERROR(maj_stat))
+    if (GSS_ERROR(maj_stat)) {
+       gss_mg_collect_error(mech, maj_stat, min_stat);
        return GSS_S_BAD_MECH;
+    }
     gss_release_buffer(&min_stat, &out);
     gss_delete_sec_context(&min_stat, &ctx, NULL);
 
@@ -268,6 +270,7 @@ spnego_initial
     if (GSS_ERROR(sub)) {
        free_NegTokenInit(&ni);
        *minor_status = minor;
+       gss_mg_collect_error(ctx->preferred_mech_type, sub, minor);
        _gss_spnego_internal_delete_sec_context(&minor, &context, GSS_C_NO_BUFFER);
        return sub;
     }
@@ -480,7 +483,8 @@ spnego_reply
        return GSS_S_BAD_MECH;
     }
 
-    if (resp.responseToken != NULL || 
+    /* if a token (of non zero length), or no context, pass to underlaying mech */
+    if ((resp.responseToken != NULL && resp.responseToken->length) || 
        ctx->negotiated_ctx_id == GSS_C_NO_CONTEXT) {
        gss_buffer_desc mech_input_token;
 
@@ -515,6 +519,7 @@ spnego_reply
        if (GSS_ERROR(ret)) {
            HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);
            free_NegTokenResp(&resp);
+           gss_mg_collect_error(&mech, ret, minor);
            *minor_status = minor;
            return ret;
        }
index d80db0018adfc173f3a83dac91b57844f57846b9..69f4d8423d24e63aa911b0689b5b1e73ecc3f275 100644 (file)
@@ -90,15 +90,6 @@ _gss_spnego_display_name (
        gss_buffer_t /*output_name_buffer*/,
        gss_OID * output_name_type );
 
-OM_uint32
-_gss_spnego_display_status (
-       OM_uint32 * /*minor_status*/,
-       OM_uint32 /*status_value*/,
-       int /*status_type*/,
-       const gss_OID /*mech_type*/,
-       OM_uint32 * /*message_context*/,
-       gss_buffer_t status_string );
-
 OM_uint32
 _gss_spnego_duplicate_name (
         OM_uint32 * /*minor_status*/,
index 698da2fe0b1d89b0923ed7a1593ddaa26b05082b..6076478bbb04bdddc9ef612e4bdd0d521924c4a1 100644 (file)
@@ -35,7 +35,7 @@
 #include <config.h>
 #endif
 
-RCSID("$Id: bn.c 18449 2006-10-14 09:21:09Z lha $");
+RCSID("$Id: bn.c 22261 2007-12-09 06:24:18Z lha $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -232,9 +232,9 @@ BN_set_negative(BIGNUM *bn, int flag)
 }
 
 int
-BN_is_negative(BIGNUM *bn)
+BN_is_negative(const BIGNUM *bn)
 {
-    return ((heim_integer *)bn)->negative ? 1 : 0;
+    return ((const heim_integer *)bn)->negative ? 1 : 0;
 }
 
 static const unsigned char is_set[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
index 82c9991c2cb96298545e3ac51d212101d474a7a4..92cacec2a66cec0f27738a78967f50d997a09cb3 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 /*
- * $Id: bn.h 16536 2006-01-13 08:27:50Z lha $
+ * $Id: bn.h 22260 2007-12-09 06:23:47Z lha $
  */
 
 #ifndef _HEIM_BN_H
@@ -97,7 +97,7 @@ int   BN_num_bytes(const BIGNUM *);
 int    BN_cmp(const BIGNUM *, const BIGNUM *);
 
 void   BN_set_negative(BIGNUM *, int);
-int    BN_is_negative(BIGNUM *);
+int    BN_is_negative(const BIGNUM *);
 
 int    BN_is_bit_set(const BIGNUM *, int);
 int    BN_set_bit(BIGNUM *, int);
diff --git a/source/heimdal/lib/hcrypto/camellia-ntt.c b/source/heimdal/lib/hcrypto/camellia-ntt.c
new file mode 100644 (file)
index 0000000..c32c406
--- /dev/null
@@ -0,0 +1,1461 @@
+/* camellia.h  ver 1.2.0
+ *
+ * Copyright (C) 2006,2007
+ * NTT (Nippon Telegraph and Telephone Corporation).
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/*
+ * Algorithm Specification 
+ *  http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "camellia.h"
+
+/* u32 must be 32bit word */
+typedef unsigned int u32;
+typedef unsigned char u8;
+
+/* key constants */
+
+#define CAMELLIA_SIGMA1L (0xA09E667FL)
+#define CAMELLIA_SIGMA1R (0x3BCC908BL)
+#define CAMELLIA_SIGMA2L (0xB67AE858L)
+#define CAMELLIA_SIGMA2R (0x4CAA73B2L)
+#define CAMELLIA_SIGMA3L (0xC6EF372FL)
+#define CAMELLIA_SIGMA3R (0xE94F82BEL)
+#define CAMELLIA_SIGMA4L (0x54FF53A5L)
+#define CAMELLIA_SIGMA4R (0xF1D36F1CL)
+#define CAMELLIA_SIGMA5L (0x10E527FAL)
+#define CAMELLIA_SIGMA5R (0xDE682D1DL)
+#define CAMELLIA_SIGMA6L (0xB05688C2L)
+#define CAMELLIA_SIGMA6R (0xB3E6C1FDL)
+
+/*
+ *  macros
+ */
+
+
+#if defined(_MSC_VER)
+
+# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
+# define GETU32(p) SWAP(*((u32 *)(p)))
+# define PUTU32(ct, st) {*((u32 *)(ct)) = SWAP((st));}
+
+#else /* not MS-VC */
+
+# define GETU32(pt)                            \
+    (((u32)(pt)[0] << 24)                      \
+     ^ ((u32)(pt)[1] << 16)                    \
+     ^ ((u32)(pt)[2] <<  8)                    \
+     ^ ((u32)(pt)[3]))
+
+# define PUTU32(ct, st)  {                     \
+       (ct)[0] = (u8)((st) >> 24);             \
+       (ct)[1] = (u8)((st) >> 16);             \
+       (ct)[2] = (u8)((st) >>  8);             \
+       (ct)[3] = (u8)(st); }
+
+#endif
+
+#define CamelliaSubkeyL(INDEX) (subkey[(INDEX)*2])
+#define CamelliaSubkeyR(INDEX) (subkey[(INDEX)*2 + 1])
+
+/* rotation right shift 1byte */
+#define CAMELLIA_RR8(x) (((x) >> 8) + ((x) << 24))
+/* rotation left shift 1bit */
+#define CAMELLIA_RL1(x) (((x) << 1) + ((x) >> 31))
+/* rotation left shift 1byte */
+#define CAMELLIA_RL8(x) (((x) << 8) + ((x) >> 24))
+
+#define CAMELLIA_ROLDQ(ll, lr, rl, rr, w0, w1, bits)   \
+    do {                                               \
+       w0 = ll;                                        \
+       ll = (ll << bits) + (lr >> (32 - bits));        \
+       lr = (lr << bits) + (rl >> (32 - bits));        \
+       rl = (rl << bits) + (rr >> (32 - bits));        \
+       rr = (rr << bits) + (w0 >> (32 - bits));        \
+    } while(0)
+
+#define CAMELLIA_ROLDQo32(ll, lr, rl, rr, w0, w1, bits)        \
+    do {                                               \
+       w0 = ll;                                        \
+       w1 = lr;                                        \
+       ll = (lr << (bits - 32)) + (rl >> (64 - bits)); \
+       lr = (rl << (bits - 32)) + (rr >> (64 - bits)); \
+       rl = (rr << (bits - 32)) + (w0 >> (64 - bits)); \
+       rr = (w0 << (bits - 32)) + (w1 >> (64 - bits)); \
+    } while(0)
+
+#define CAMELLIA_SP1110(INDEX) (camellia_sp1110[(INDEX)])
+#define CAMELLIA_SP0222(INDEX) (camellia_sp0222[(INDEX)])
+#define CAMELLIA_SP3033(INDEX) (camellia_sp3033[(INDEX)])
+#define CAMELLIA_SP4404(INDEX) (camellia_sp4404[(INDEX)])
+
+#define CAMELLIA_F(xl, xr, kl, kr, yl, yr, il, ir, t0, t1)     \
+    do {                                                       \
+       il = xl ^ kl;                                           \
+       ir = xr ^ kr;                                           \
+       t0 = il >> 16;                                          \
+       t1 = ir >> 16;                                          \
+       yl = CAMELLIA_SP1110(ir & 0xff)                         \
+           ^ CAMELLIA_SP0222((t1 >> 8) & 0xff)                 \
+           ^ CAMELLIA_SP3033(t1 & 0xff)                        \
+           ^ CAMELLIA_SP4404((ir >> 8) & 0xff);                \
+       yr = CAMELLIA_SP1110((t0 >> 8) & 0xff)                  \
+           ^ CAMELLIA_SP0222(t0 & 0xff)                        \
+           ^ CAMELLIA_SP3033((il >> 8) & 0xff)                 \
+           ^ CAMELLIA_SP4404(il & 0xff);                       \
+       yl ^= yr;                                               \
+       yr = CAMELLIA_RR8(yr);                                  \
+       yr ^= yl;                                               \
+    } while(0)
+
+
+/*
+ * for speed up
+ *
+ */
+#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) \
+    do {                                                               \
+       t0 = kll;                                                       \
+       t0 &= ll;                                                       \
+       lr ^= CAMELLIA_RL1(t0);                                         \
+       t1 = klr;                                                       \
+       t1 |= lr;                                                       \
+       ll ^= t1;                                                       \
+                                                                       \
+       t2 = krr;                                                       \
+       t2 |= rr;                                                       \
+       rl ^= t2;                                                       \
+       t3 = krl;                                                       \
+       t3 &= rl;                                                       \
+       rr ^= CAMELLIA_RL1(t3);                                         \
+    } while(0)
+
+#define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir, t0, t1)       \
+    do {                                                               \
+       ir = CAMELLIA_SP1110(xr & 0xff)                                 \
+           ^ CAMELLIA_SP0222((xr >> 24) & 0xff)                        \
+           ^ CAMELLIA_SP3033((xr >> 16) & 0xff)                        \
+           ^ CAMELLIA_SP4404((xr >> 8) & 0xff);                        \
+       il = CAMELLIA_SP1110((xl >> 24) & 0xff)                         \
+           ^ CAMELLIA_SP0222((xl >> 16) & 0xff)                        \
+           ^ CAMELLIA_SP3033((xl >> 8) & 0xff)                         \
+           ^ CAMELLIA_SP4404(xl & 0xff);                               \
+       il ^= kl;                                                       \
+       ir ^= kr;                                                       \
+       ir ^= il;                                                       \
+       il = CAMELLIA_RR8(il);                                          \
+       il ^= ir;                                                       \
+       yl ^= ir;                                                       \
+       yr ^= il;                                                       \
+    } while(0)
+
+
+static const u32 camellia_sp1110[256] = {
+    0x70707000,0x82828200,0x2c2c2c00,0xececec00,
+    0xb3b3b300,0x27272700,0xc0c0c000,0xe5e5e500,
+    0xe4e4e400,0x85858500,0x57575700,0x35353500,
+    0xeaeaea00,0x0c0c0c00,0xaeaeae00,0x41414100,
+    0x23232300,0xefefef00,0x6b6b6b00,0x93939300,
+    0x45454500,0x19191900,0xa5a5a500,0x21212100,
+    0xededed00,0x0e0e0e00,0x4f4f4f00,0x4e4e4e00,
+    0x1d1d1d00,0x65656500,0x92929200,0xbdbdbd00,
+    0x86868600,0xb8b8b800,0xafafaf00,0x8f8f8f00,
+    0x7c7c7c00,0xebebeb00,0x1f1f1f00,0xcecece00,
+    0x3e3e3e00,0x30303000,0xdcdcdc00,0x5f5f5f00,
+    0x5e5e5e00,0xc5c5c500,0x0b0b0b00,0x1a1a1a00,
+    0xa6a6a600,0xe1e1e100,0x39393900,0xcacaca00,
+    0xd5d5d500,0x47474700,0x5d5d5d00,0x3d3d3d00,
+    0xd9d9d900,0x01010100,0x5a5a5a00,0xd6d6d600,
+    0x51515100,0x56565600,0x6c6c6c00,0x4d4d4d00,
+    0x8b8b8b00,0x0d0d0d00,0x9a9a9a00,0x66666600,
+    0xfbfbfb00,0xcccccc00,0xb0b0b000,0x2d2d2d00,
+    0x74747400,0x12121200,0x2b2b2b00,0x20202000,
+    0xf0f0f000,0xb1b1b100,0x84848400,0x99999900,
+    0xdfdfdf00,0x4c4c4c00,0xcbcbcb00,0xc2c2c200,
+    0x34343400,0x7e7e7e00,0x76767600,0x05050500,
+    0x6d6d6d00,0xb7b7b700,0xa9a9a900,0x31313100,
+    0xd1d1d100,0x17171700,0x04040400,0xd7d7d700,
+    0x14141400,0x58585800,0x3a3a3a00,0x61616100,
+    0xdedede00,0x1b1b1b00,0x11111100,0x1c1c1c00,
+    0x32323200,0x0f0f0f00,0x9c9c9c00,0x16161600,
+    0x53535300,0x18181800,0xf2f2f200,0x22222200,
+    0xfefefe00,0x44444400,0xcfcfcf00,0xb2b2b200,
+    0xc3c3c300,0xb5b5b500,0x7a7a7a00,0x91919100,
+    0x24242400,0x08080800,0xe8e8e800,0xa8a8a800,
+    0x60606000,0xfcfcfc00,0x69696900,0x50505000,
+    0xaaaaaa00,0xd0d0d000,0xa0a0a000,0x7d7d7d00,
+    0xa1a1a100,0x89898900,0x62626200,0x97979700,
+    0x54545400,0x5b5b5b00,0x1e1e1e00,0x95959500,
+    0xe0e0e000,0xffffff00,0x64646400,0xd2d2d200,
+    0x10101000,0xc4c4c400,0x00000000,0x48484800,
+    0xa3a3a300,0xf7f7f700,0x75757500,0xdbdbdb00,
+    0x8a8a8a00,0x03030300,0xe6e6e600,0xdadada00,
+    0x09090900,0x3f3f3f00,0xdddddd00,0x94949400,
+    0x87878700,0x5c5c5c00,0x83838300,0x02020200,
+    0xcdcdcd00,0x4a4a4a00,0x90909000,0x33333300,
+    0x73737300,0x67676700,0xf6f6f600,0xf3f3f300,
+    0x9d9d9d00,0x7f7f7f00,0xbfbfbf00,0xe2e2e200,
+    0x52525200,0x9b9b9b00,0xd8d8d800,0x26262600,
+    0xc8c8c800,0x37373700,0xc6c6c600,0x3b3b3b00,
+    0x81818100,0x96969600,0x6f6f6f00,0x4b4b4b00,
+    0x13131300,0xbebebe00,0x63636300,0x2e2e2e00,
+    0xe9e9e900,0x79797900,0xa7a7a700,0x8c8c8c00,
+    0x9f9f9f00,0x6e6e6e00,0xbcbcbc00,0x8e8e8e00,
+    0x29292900,0xf5f5f500,0xf9f9f900,0xb6b6b600,
+    0x2f2f2f00,0xfdfdfd00,0xb4b4b400,0x59595900,
+    0x78787800,0x98989800,0x06060600,0x6a6a6a00,
+    0xe7e7e700,0x46464600,0x71717100,0xbababa00,
+    0xd4d4d400,0x25252500,0xababab00,0x42424200,
+    0x88888800,0xa2a2a200,0x8d8d8d00,0xfafafa00,
+    0x72727200,0x07070700,0xb9b9b900,0x55555500,
+    0xf8f8f800,0xeeeeee00,0xacacac00,0x0a0a0a00,
+    0x36363600,0x49494900,0x2a2a2a00,0x68686800,
+    0x3c3c3c00,0x38383800,0xf1f1f100,0xa4a4a400,
+    0x40404000,0x28282800,0xd3d3d300,0x7b7b7b00,
+    0xbbbbbb00,0xc9c9c900,0x43434300,0xc1c1c100,
+    0x15151500,0xe3e3e300,0xadadad00,0xf4f4f400,
+    0x77777700,0xc7c7c700,0x80808000,0x9e9e9e00,
+};
+
+static const u32 camellia_sp0222[256] = {
+    0x00e0e0e0,0x00050505,0x00585858,0x00d9d9d9,
+    0x00676767,0x004e4e4e,0x00818181,0x00cbcbcb,
+    0x00c9c9c9,0x000b0b0b,0x00aeaeae,0x006a6a6a,
+    0x00d5d5d5,0x00181818,0x005d5d5d,0x00828282,
+    0x00464646,0x00dfdfdf,0x00d6d6d6,0x00272727,
+    0x008a8a8a,0x00323232,0x004b4b4b,0x00424242,
+    0x00dbdbdb,0x001c1c1c,0x009e9e9e,0x009c9c9c,
+    0x003a3a3a,0x00cacaca,0x00252525,0x007b7b7b,
+    0x000d0d0d,0x00717171,0x005f5f5f,0x001f1f1f,
+    0x00f8f8f8,0x00d7d7d7,0x003e3e3e,0x009d9d9d,
+    0x007c7c7c,0x00606060,0x00b9b9b9,0x00bebebe,
+    0x00bcbcbc,0x008b8b8b,0x00161616,0x00343434,
+    0x004d4d4d,0x00c3c3c3,0x00727272,0x00959595,
+    0x00ababab,0x008e8e8e,0x00bababa,0x007a7a7a,
+    0x00b3b3b3,0x00020202,0x00b4b4b4,0x00adadad,
+    0x00a2a2a2,0x00acacac,0x00d8d8d8,0x009a9a9a,
+    0x00171717,0x001a1a1a,0x00353535,0x00cccccc,
+    0x00f7f7f7,0x00999999,0x00616161,0x005a5a5a,
+    0x00e8e8e8,0x00242424,0x00565656,0x00404040,
+    0x00e1e1e1,0x00636363,0x00090909,0x00333333,
+    0x00bfbfbf,0x00989898,0x00979797,0x00858585,
+    0x00686868,0x00fcfcfc,0x00ececec,0x000a0a0a,
+    0x00dadada,0x006f6f6f,0x00535353,0x00626262,
+    0x00a3a3a3,0x002e2e2e,0x00080808,0x00afafaf,
+    0x00282828,0x00b0b0b0,0x00747474,0x00c2c2c2,
+    0x00bdbdbd,0x00363636,0x00222222,0x00383838,
+    0x00646464,0x001e1e1e,0x00393939,0x002c2c2c,
+    0x00a6a6a6,0x00303030,0x00e5e5e5,0x00444444,
+    0x00fdfdfd,0x00888888,0x009f9f9f,0x00656565,
+    0x00878787,0x006b6b6b,0x00f4f4f4,0x00232323,
+    0x00484848,0x00101010,0x00d1d1d1,0x00515151,
+    0x00c0c0c0,0x00f9f9f9,0x00d2d2d2,0x00a0a0a0,
+    0x00555555,0x00a1a1a1,0x00414141,0x00fafafa,
+    0x00434343,0x00131313,0x00c4c4c4,0x002f2f2f,
+    0x00a8a8a8,0x00b6b6b6,0x003c3c3c,0x002b2b2b,
+    0x00c1c1c1,0x00ffffff,0x00c8c8c8,0x00a5a5a5,
+    0x00202020,0x00898989,0x00000000,0x00909090,
+    0x00474747,0x00efefef,0x00eaeaea,0x00b7b7b7,
+    0x00151515,0x00060606,0x00cdcdcd,0x00b5b5b5,
+    0x00121212,0x007e7e7e,0x00bbbbbb,0x00292929,
+    0x000f0f0f,0x00b8b8b8,0x00070707,0x00040404,
+    0x009b9b9b,0x00949494,0x00212121,0x00666666,
+    0x00e6e6e6,0x00cecece,0x00ededed,0x00e7e7e7,
+    0x003b3b3b,0x00fefefe,0x007f7f7f,0x00c5c5c5,
+    0x00a4a4a4,0x00373737,0x00b1b1b1,0x004c4c4c,
+    0x00919191,0x006e6e6e,0x008d8d8d,0x00767676,
+    0x00030303,0x002d2d2d,0x00dedede,0x00969696,
+    0x00262626,0x007d7d7d,0x00c6c6c6,0x005c5c5c,
+    0x00d3d3d3,0x00f2f2f2,0x004f4f4f,0x00191919,
+    0x003f3f3f,0x00dcdcdc,0x00797979,0x001d1d1d,
+    0x00525252,0x00ebebeb,0x00f3f3f3,0x006d6d6d,
+    0x005e5e5e,0x00fbfbfb,0x00696969,0x00b2b2b2,
+    0x00f0f0f0,0x00313131,0x000c0c0c,0x00d4d4d4,
+    0x00cfcfcf,0x008c8c8c,0x00e2e2e2,0x00757575,
+    0x00a9a9a9,0x004a4a4a,0x00575757,0x00848484,
+    0x00111111,0x00454545,0x001b1b1b,0x00f5f5f5,
+    0x00e4e4e4,0x000e0e0e,0x00737373,0x00aaaaaa,
+    0x00f1f1f1,0x00dddddd,0x00595959,0x00141414,
+    0x006c6c6c,0x00929292,0x00545454,0x00d0d0d0,
+    0x00787878,0x00707070,0x00e3e3e3,0x00494949,
+    0x00808080,0x00505050,0x00a7a7a7,0x00f6f6f6,
+    0x00777777,0x00939393,0x00868686,0x00838383,
+    0x002a2a2a,0x00c7c7c7,0x005b5b5b,0x00e9e9e9,
+    0x00eeeeee,0x008f8f8f,0x00010101,0x003d3d3d,
+};
+
+static const u32 camellia_sp3033[256] = {
+    0x38003838,0x41004141,0x16001616,0x76007676,
+    0xd900d9d9,0x93009393,0x60006060,0xf200f2f2,
+    0x72007272,0xc200c2c2,0xab00abab,0x9a009a9a,
+    0x75007575,0x06000606,0x57005757,0xa000a0a0,
+    0x91009191,0xf700f7f7,0xb500b5b5,0xc900c9c9,
+    0xa200a2a2,0x8c008c8c,0xd200d2d2,0x90009090,
+    0xf600f6f6,0x07000707,0xa700a7a7,0x27002727,
+    0x8e008e8e,0xb200b2b2,0x49004949,0xde00dede,
+    0x43004343,0x5c005c5c,0xd700d7d7,0xc700c7c7,
+    0x3e003e3e,0xf500f5f5,0x8f008f8f,0x67006767,
+    0x1f001f1f,0x18001818,0x6e006e6e,0xaf00afaf,
+    0x2f002f2f,0xe200e2e2,0x85008585,0x0d000d0d,
+    0x53005353,0xf000f0f0,0x9c009c9c,0x65006565,
+    0xea00eaea,0xa300a3a3,0xae00aeae,0x9e009e9e,
+    0xec00ecec,0x80008080,0x2d002d2d,0x6b006b6b,
+    0xa800a8a8,0x2b002b2b,0x36003636,0xa600a6a6,
+    0xc500c5c5,0x86008686,0x4d004d4d,0x33003333,
+    0xfd00fdfd,0x66006666,0x58005858,0x96009696,
+    0x3a003a3a,0x09000909,0x95009595,0x10001010,
+    0x78007878,0xd800d8d8,0x42004242,0xcc00cccc,
+    0xef00efef,0x26002626,0xe500e5e5,0x61006161,
+    0x1a001a1a,0x3f003f3f,0x3b003b3b,0x82008282,
+    0xb600b6b6,0xdb00dbdb,0xd400d4d4,0x98009898,
+    0xe800e8e8,0x8b008b8b,0x02000202,0xeb00ebeb,
+    0x0a000a0a,0x2c002c2c,0x1d001d1d,0xb000b0b0,
+    0x6f006f6f,0x8d008d8d,0x88008888,0x0e000e0e,
+    0x19001919,0x87008787,0x4e004e4e,0x0b000b0b,
+    0xa900a9a9,0x0c000c0c,0x79007979,0x11001111,
+    0x7f007f7f,0x22002222,0xe700e7e7,0x59005959,
+    0xe100e1e1,0xda00dada,0x3d003d3d,0xc800c8c8,
+    0x12001212,0x04000404,0x74007474,0x54005454,
+    0x30003030,0x7e007e7e,0xb400b4b4,0x28002828,
+    0x55005555,0x68006868,0x50005050,0xbe00bebe,
+    0xd000d0d0,0xc400c4c4,0x31003131,0xcb00cbcb,
+    0x2a002a2a,0xad00adad,0x0f000f0f,0xca00caca,
+    0x70007070,0xff00ffff,0x32003232,0x69006969,
+    0x08000808,0x62006262,0x00000000,0x24002424,
+    0xd100d1d1,0xfb00fbfb,0xba00baba,0xed00eded,
+    0x45004545,0x81008181,0x73007373,0x6d006d6d,
+    0x84008484,0x9f009f9f,0xee00eeee,0x4a004a4a,
+    0xc300c3c3,0x2e002e2e,0xc100c1c1,0x01000101,
+    0xe600e6e6,0x25002525,0x48004848,0x99009999,
+    0xb900b9b9,0xb300b3b3,0x7b007b7b,0xf900f9f9,
+    0xce00cece,0xbf00bfbf,0xdf00dfdf,0x71007171,
+    0x29002929,0xcd00cdcd,0x6c006c6c,0x13001313,
+    0x64006464,0x9b009b9b,0x63006363,0x9d009d9d,
+    0xc000c0c0,0x4b004b4b,0xb700b7b7,0xa500a5a5,
+    0x89008989,0x5f005f5f,0xb100b1b1,0x17001717,
+    0xf400f4f4,0xbc00bcbc,0xd300d3d3,0x46004646,
+    0xcf00cfcf,0x37003737,0x5e005e5e,0x47004747,
+    0x94009494,0xfa00fafa,0xfc00fcfc,0x5b005b5b,
+    0x97009797,0xfe00fefe,0x5a005a5a,0xac00acac,
+    0x3c003c3c,0x4c004c4c,0x03000303,0x35003535,
+    0xf300f3f3,0x23002323,0xb800b8b8,0x5d005d5d,
+    0x6a006a6a,0x92009292,0xd500d5d5,0x21002121,
+    0x44004444,0x51005151,0xc600c6c6,0x7d007d7d,
+    0x39003939,0x83008383,0xdc00dcdc,0xaa00aaaa,
+    0x7c007c7c,0x77007777,0x56005656,0x05000505,
+    0x1b001b1b,0xa400a4a4,0x15001515,0x34003434,
+    0x1e001e1e,0x1c001c1c,0xf800f8f8,0x52005252,
+    0x20002020,0x14001414,0xe900e9e9,0xbd00bdbd,
+    0xdd00dddd,0xe400e4e4,0xa100a1a1,0xe000e0e0,
+    0x8a008a8a,0xf100f1f1,0xd600d6d6,0x7a007a7a,
+    0xbb00bbbb,0xe300e3e3,0x40004040,0x4f004f4f,
+};
+
+static const u32 camellia_sp4404[256] = {
+    0x70700070,0x2c2c002c,0xb3b300b3,0xc0c000c0,
+    0xe4e400e4,0x57570057,0xeaea00ea,0xaeae00ae,
+    0x23230023,0x6b6b006b,0x45450045,0xa5a500a5,
+    0xeded00ed,0x4f4f004f,0x1d1d001d,0x92920092,
+    0x86860086,0xafaf00af,0x7c7c007c,0x1f1f001f,
+    0x3e3e003e,0xdcdc00dc,0x5e5e005e,0x0b0b000b,
+    0xa6a600a6,0x39390039,0xd5d500d5,0x5d5d005d,
+    0xd9d900d9,0x5a5a005a,0x51510051,0x6c6c006c,
+    0x8b8b008b,0x9a9a009a,0xfbfb00fb,0xb0b000b0,
+    0x74740074,0x2b2b002b,0xf0f000f0,0x84840084,
+    0xdfdf00df,0xcbcb00cb,0x34340034,0x76760076,
+    0x6d6d006d,0xa9a900a9,0xd1d100d1,0x04040004,
+    0x14140014,0x3a3a003a,0xdede00de,0x11110011,
+    0x32320032,0x9c9c009c,0x53530053,0xf2f200f2,
+    0xfefe00fe,0xcfcf00cf,0xc3c300c3,0x7a7a007a,
+    0x24240024,0xe8e800e8,0x60600060,0x69690069,
+    0xaaaa00aa,0xa0a000a0,0xa1a100a1,0x62620062,
+    0x54540054,0x1e1e001e,0xe0e000e0,0x64640064,
+    0x10100010,0x00000000,0xa3a300a3,0x75750075,
+    0x8a8a008a,0xe6e600e6,0x09090009,0xdddd00dd,
+    0x87870087,0x83830083,0xcdcd00cd,0x90900090,
+    0x73730073,0xf6f600f6,0x9d9d009d,0xbfbf00bf,
+    0x52520052,0xd8d800d8,0xc8c800c8,0xc6c600c6,
+    0x81810081,0x6f6f006f,0x13130013,0x63630063,
+    0xe9e900e9,0xa7a700a7,0x9f9f009f,0xbcbc00bc,
+    0x29290029,0xf9f900f9,0x2f2f002f,0xb4b400b4,
+    0x78780078,0x06060006,0xe7e700e7,0x71710071,
+    0xd4d400d4,0xabab00ab,0x88880088,0x8d8d008d,
+    0x72720072,0xb9b900b9,0xf8f800f8,0xacac00ac,
+    0x36360036,0x2a2a002a,0x3c3c003c,0xf1f100f1,
+    0x40400040,0xd3d300d3,0xbbbb00bb,0x43430043,
+    0x15150015,0xadad00ad,0x77770077,0x80800080,
+    0x82820082,0xecec00ec,0x27270027,0xe5e500e5,
+    0x85850085,0x35350035,0x0c0c000c,0x41410041,
+    0xefef00ef,0x93930093,0x19190019,0x21210021,
+    0x0e0e000e,0x4e4e004e,0x65650065,0xbdbd00bd,
+    0xb8b800b8,0x8f8f008f,0xebeb00eb,0xcece00ce,
+    0x30300030,0x5f5f005f,0xc5c500c5,0x1a1a001a,
+    0xe1e100e1,0xcaca00ca,0x47470047,0x3d3d003d,
+    0x01010001,0xd6d600d6,0x56560056,0x4d4d004d,
+    0x0d0d000d,0x66660066,0xcccc00cc,0x2d2d002d,
+    0x12120012,0x20200020,0xb1b100b1,0x99990099,
+    0x4c4c004c,0xc2c200c2,0x7e7e007e,0x05050005,
+    0xb7b700b7,0x31310031,0x17170017,0xd7d700d7,
+    0x58580058,0x61610061,0x1b1b001b,0x1c1c001c,
+    0x0f0f000f,0x16160016,0x18180018,0x22220022,
+    0x44440044,0xb2b200b2,0xb5b500b5,0x91910091,
+    0x08080008,0xa8a800a8,0xfcfc00fc,0x50500050,
+    0xd0d000d0,0x7d7d007d,0x89890089,0x97970097,
+    0x5b5b005b,0x95950095,0xffff00ff,0xd2d200d2,
+    0xc4c400c4,0x48480048,0xf7f700f7,0xdbdb00db,
+    0x03030003,0xdada00da,0x3f3f003f,0x94940094,
+    0x5c5c005c,0x02020002,0x4a4a004a,0x33330033,
+    0x67670067,0xf3f300f3,0x7f7f007f,0xe2e200e2,
+    0x9b9b009b,0x26260026,0x37370037,0x3b3b003b,
+    0x96960096,0x4b4b004b,0xbebe00be,0x2e2e002e,
+    0x79790079,0x8c8c008c,0x6e6e006e,0x8e8e008e,
+    0xf5f500f5,0xb6b600b6,0xfdfd00fd,0x59590059,
+    0x98980098,0x6a6a006a,0x46460046,0xbaba00ba,
+    0x25250025,0x42420042,0xa2a200a2,0xfafa00fa,
+    0x07070007,0x55550055,0xeeee00ee,0x0a0a000a,
+    0x49490049,0x68680068,0x38380038,0xa4a400a4,
+    0x28280028,0x7b7b007b,0xc9c900c9,0xc1c100c1,
+    0xe3e300e3,0xf4f400f4,0xc7c700c7,0x9e9e009e,
+};
+
+
+/**
+ * Stuff related to the Camellia key schedule
+ */
+#define subl(x) subL[(x)]
+#define subr(x) subR[(x)]
+
+void camellia_setup128(const unsigned char *key, u32 *subkey)
+{
+    u32 kll, klr, krl, krr;
+    u32 il, ir, t0, t1, w0, w1;
+    u32 kw4l, kw4r, dw, tl, tr;
+    u32 subL[26];
+    u32 subR[26];
+
+    /**
+     *  k == kll || klr || krl || krr (|| is concatination)
+     */
+    kll = GETU32(key     );
+    klr = GETU32(key +  4);
+    krl = GETU32(key +  8);
+    krr = GETU32(key + 12);
+    /**
+     * generate KL dependent subkeys
+     */
+    subl(0) = kll; subr(0) = klr;
+    subl(1) = krl; subr(1) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(4) = kll; subr(4) = klr;
+    subl(5) = krl; subr(5) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 30);
+    subl(10) = kll; subr(10) = klr;
+    subl(11) = krl; subr(11) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(13) = krl; subr(13) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
+    subl(16) = kll; subr(16) = klr;
+    subl(17) = krl; subr(17) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
+    subl(18) = kll; subr(18) = klr;
+    subl(19) = krl; subr(19) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
+    subl(22) = kll; subr(22) = klr;
+    subl(23) = krl; subr(23) = krr;
+
+    /* generate KA */
+    kll = subl(0); klr = subr(0);
+    krl = subl(1); krr = subr(1);
+    CAMELLIA_F(kll, klr,
+              CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R,
+              w0, w1, il, ir, t0, t1);
+    krl ^= w0; krr ^= w1;
+    CAMELLIA_F(krl, krr,
+              CAMELLIA_SIGMA2L, CAMELLIA_SIGMA2R,
+              kll, klr, il, ir, t0, t1);
+    CAMELLIA_F(kll, klr,
+              CAMELLIA_SIGMA3L, CAMELLIA_SIGMA3R,
+              krl, krr, il, ir, t0, t1);
+    krl ^= w0; krr ^= w1;
+    CAMELLIA_F(krl, krr,
+              CAMELLIA_SIGMA4L, CAMELLIA_SIGMA4R,
+              w0, w1, il, ir, t0, t1);
+    kll ^= w0; klr ^= w1;
+
+    /* generate KA dependent subkeys */
+    subl(2) = kll; subr(2) = klr;
+    subl(3) = krl; subr(3) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(6) = kll; subr(6) = klr;
+    subl(7) = krl; subr(7) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(8) = kll; subr(8) = klr;
+    subl(9) = krl; subr(9) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(12) = kll; subr(12) = klr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(14) = kll; subr(14) = klr;
+    subl(15) = krl; subr(15) = krr;
+    CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 34);
+    subl(20) = kll; subr(20) = klr;
+    subl(21) = krl; subr(21) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
+    subl(24) = kll; subr(24) = klr;
+    subl(25) = krl; subr(25) = krr;
+
+
+    /* absorb kw2 to other subkeys */
+    subl(3) ^= subl(1); subr(3) ^= subr(1);
+    subl(5) ^= subl(1); subr(5) ^= subr(1);
+    subl(7) ^= subl(1); subr(7) ^= subr(1);
+    subl(1) ^= subr(1) & ~subr(9);
+    dw = subl(1) & subl(9), subr(1) ^= CAMELLIA_RL1(dw);
+    subl(11) ^= subl(1); subr(11) ^= subr(1);
+    subl(13) ^= subl(1); subr(13) ^= subr(1);
+    subl(15) ^= subl(1); subr(15) ^= subr(1);
+    subl(1) ^= subr(1) & ~subr(17);
+    dw = subl(1) & subl(17), subr(1) ^= CAMELLIA_RL1(dw);
+    subl(19) ^= subl(1); subr(19) ^= subr(1);
+    subl(21) ^= subl(1); subr(21) ^= subr(1);
+    subl(23) ^= subl(1); subr(23) ^= subr(1);
+    subl(24) ^= subl(1); subr(24) ^= subr(1);
+
+    /* absorb kw4 to other subkeys */
+    kw4l = subl(25); kw4r = subr(25);
+    subl(22) ^= kw4l; subr(22) ^= kw4r;
+    subl(20) ^= kw4l; subr(20) ^= kw4r;
+    subl(18) ^= kw4l; subr(18) ^= kw4r;
+    kw4l ^= kw4r & ~subr(16);
+    dw = kw4l & subl(16), kw4r ^= CAMELLIA_RL1(dw);
+    subl(14) ^= kw4l; subr(14) ^= kw4r;
+    subl(12) ^= kw4l; subr(12) ^= kw4r;
+    subl(10) ^= kw4l; subr(10) ^= kw4r;
+    kw4l ^= kw4r & ~subr(8);
+    dw = kw4l & subl(8), kw4r ^= CAMELLIA_RL1(dw);
+    subl(6) ^= kw4l; subr(6) ^= kw4r;
+    subl(4) ^= kw4l; subr(4) ^= kw4r;
+    subl(2) ^= kw4l; subr(2) ^= kw4r;
+    subl(0) ^= kw4l; subr(0) ^= kw4r;
+
+    /* key XOR is end of F-function */
+    CamelliaSubkeyL(0) = subl(0) ^ subl(2);
+    CamelliaSubkeyR(0) = subr(0) ^ subr(2);
+    CamelliaSubkeyL(2) = subl(3);
+    CamelliaSubkeyR(2) = subr(3);
+    CamelliaSubkeyL(3) = subl(2) ^ subl(4);
+    CamelliaSubkeyR(3) = subr(2) ^ subr(4);
+    CamelliaSubkeyL(4) = subl(3) ^ subl(5);
+    CamelliaSubkeyR(4) = subr(3) ^ subr(5);
+    CamelliaSubkeyL(5) = subl(4) ^ subl(6);
+    CamelliaSubkeyR(5) = subr(4) ^ subr(6);
+    CamelliaSubkeyL(6) = subl(5) ^ subl(7);
+    CamelliaSubkeyR(6) = subr(5) ^ subr(7);
+    tl = subl(10) ^ (subr(10) & ~subr(8));
+    dw = tl & subl(8), tr = subr(10) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(7) = subl(6) ^ tl;
+    CamelliaSubkeyR(7) = subr(6) ^ tr;
+    CamelliaSubkeyL(8) = subl(8);
+    CamelliaSubkeyR(8) = subr(8);
+    CamelliaSubkeyL(9) = subl(9);
+    CamelliaSubkeyR(9) = subr(9);
+    tl = subl(7) ^ (subr(7) & ~subr(9));
+    dw = tl & subl(9), tr = subr(7) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(10) = tl ^ subl(11);
+    CamelliaSubkeyR(10) = tr ^ subr(11);
+    CamelliaSubkeyL(11) = subl(10) ^ subl(12);
+    CamelliaSubkeyR(11) = subr(10) ^ subr(12);
+    CamelliaSubkeyL(12) = subl(11) ^ subl(13);
+    CamelliaSubkeyR(12) = subr(11) ^ subr(13);
+    CamelliaSubkeyL(13) = subl(12) ^ subl(14);
+    CamelliaSubkeyR(13) = subr(12) ^ subr(14);
+    CamelliaSubkeyL(14) = subl(13) ^ subl(15);
+    CamelliaSubkeyR(14) = subr(13) ^ subr(15);
+    tl = subl(18) ^ (subr(18) & ~subr(16));
+    dw = tl & subl(16),        tr = subr(18) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(15) = subl(14) ^ tl;
+    CamelliaSubkeyR(15) = subr(14) ^ tr;
+    CamelliaSubkeyL(16) = subl(16);
+    CamelliaSubkeyR(16) = subr(16);
+    CamelliaSubkeyL(17) = subl(17);
+    CamelliaSubkeyR(17) = subr(17);
+    tl = subl(15) ^ (subr(15) & ~subr(17));
+    dw = tl & subl(17),        tr = subr(15) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(18) = tl ^ subl(19);
+    CamelliaSubkeyR(18) = tr ^ subr(19);
+    CamelliaSubkeyL(19) = subl(18) ^ subl(20);
+    CamelliaSubkeyR(19) = subr(18) ^ subr(20);
+    CamelliaSubkeyL(20) = subl(19) ^ subl(21);
+    CamelliaSubkeyR(20) = subr(19) ^ subr(21);
+    CamelliaSubkeyL(21) = subl(20) ^ subl(22);
+    CamelliaSubkeyR(21) = subr(20) ^ subr(22);
+    CamelliaSubkeyL(22) = subl(21) ^ subl(23);
+    CamelliaSubkeyR(22) = subr(21) ^ subr(23);
+    CamelliaSubkeyL(23) = subl(22);
+    CamelliaSubkeyR(23) = subr(22);
+    CamelliaSubkeyL(24) = subl(24) ^ subl(23);
+    CamelliaSubkeyR(24) = subr(24) ^ subr(23);
+
+    /* apply the inverse of the last half of P-function */
+    dw = CamelliaSubkeyL(2) ^ CamelliaSubkeyR(2), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(2) = CamelliaSubkeyL(2) ^ dw, CamelliaSubkeyL(2) = dw;
+    dw = CamelliaSubkeyL(3) ^ CamelliaSubkeyR(3), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(3) = CamelliaSubkeyL(3) ^ dw, CamelliaSubkeyL(3) = dw;
+    dw = CamelliaSubkeyL(4) ^ CamelliaSubkeyR(4), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(4) = CamelliaSubkeyL(4) ^ dw, CamelliaSubkeyL(4) = dw;
+    dw = CamelliaSubkeyL(5) ^ CamelliaSubkeyR(5), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(5) = CamelliaSubkeyL(5) ^ dw, CamelliaSubkeyL(5) = dw;
+    dw = CamelliaSubkeyL(6) ^ CamelliaSubkeyR(6), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(6) = CamelliaSubkeyL(6) ^ dw, CamelliaSubkeyL(6) = dw;
+    dw = CamelliaSubkeyL(7) ^ CamelliaSubkeyR(7), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(7) = CamelliaSubkeyL(7) ^ dw, CamelliaSubkeyL(7) = dw;
+    dw = CamelliaSubkeyL(10) ^ CamelliaSubkeyR(10), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(10) = CamelliaSubkeyL(10) ^ dw, CamelliaSubkeyL(10) = dw;
+    dw = CamelliaSubkeyL(11) ^ CamelliaSubkeyR(11), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(11) = CamelliaSubkeyL(11) ^ dw, CamelliaSubkeyL(11) = dw;
+    dw = CamelliaSubkeyL(12) ^ CamelliaSubkeyR(12), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(12) = CamelliaSubkeyL(12) ^ dw, CamelliaSubkeyL(12) = dw;
+    dw = CamelliaSubkeyL(13) ^ CamelliaSubkeyR(13), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(13) = CamelliaSubkeyL(13) ^ dw, CamelliaSubkeyL(13) = dw;
+    dw = CamelliaSubkeyL(14) ^ CamelliaSubkeyR(14), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(14) = CamelliaSubkeyL(14) ^ dw, CamelliaSubkeyL(14) = dw;
+    dw = CamelliaSubkeyL(15) ^ CamelliaSubkeyR(15), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(15) = CamelliaSubkeyL(15) ^ dw, CamelliaSubkeyL(15) = dw;
+    dw = CamelliaSubkeyL(18) ^ CamelliaSubkeyR(18), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(18) = CamelliaSubkeyL(18) ^ dw, CamelliaSubkeyL(18) = dw;
+    dw = CamelliaSubkeyL(19) ^ CamelliaSubkeyR(19), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(19) = CamelliaSubkeyL(19) ^ dw, CamelliaSubkeyL(19) = dw;
+    dw = CamelliaSubkeyL(20) ^ CamelliaSubkeyR(20), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(20) = CamelliaSubkeyL(20) ^ dw, CamelliaSubkeyL(20) = dw;
+    dw = CamelliaSubkeyL(21) ^ CamelliaSubkeyR(21), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(21) = CamelliaSubkeyL(21) ^ dw, CamelliaSubkeyL(21) = dw;
+    dw = CamelliaSubkeyL(22) ^ CamelliaSubkeyR(22), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(22) = CamelliaSubkeyL(22) ^ dw, CamelliaSubkeyL(22) = dw;
+    dw = CamelliaSubkeyL(23) ^ CamelliaSubkeyR(23), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(23) = CamelliaSubkeyL(23) ^ dw, CamelliaSubkeyL(23) = dw;
+
+    return;
+}
+
+void camellia_setup256(const unsigned char *key, u32 *subkey)
+{
+    u32 kll,klr,krl,krr;           /* left half of key */
+    u32 krll,krlr,krrl,krrr;       /* right half of key */
+    u32 il, ir, t0, t1, w0, w1;    /* temporary variables */
+    u32 kw4l, kw4r, dw, tl, tr;
+    u32 subL[34];
+    u32 subR[34];
+
+    /**
+     *  key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
+     *  (|| is concatination)
+     */
+
+    kll  = GETU32(key     );
+    klr  = GETU32(key +  4);
+    krl  = GETU32(key +  8);
+    krr  = GETU32(key + 12);
+    krll = GETU32(key + 16);
+    krlr = GETU32(key + 20);
+    krrl = GETU32(key + 24);
+    krrr = GETU32(key + 28);
+
+    /* generate KL dependent subkeys */
+    subl(0) = kll; subr(0) = klr;
+    subl(1) = krl; subr(1) = krr;
+    CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 45);
+    subl(12) = kll; subr(12) = klr;
+    subl(13) = krl; subr(13) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(16) = kll; subr(16) = klr;
+    subl(17) = krl; subr(17) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
+    subl(22) = kll; subr(22) = klr;
+    subl(23) = krl; subr(23) = krr;
+    CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 34);
+    subl(30) = kll; subr(30) = klr;
+    subl(31) = krl; subr(31) = krr;
+
+    /* generate KR dependent subkeys */
+    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
+    subl(4) = krll; subr(4) = krlr;
+    subl(5) = krrl; subr(5) = krrr;
+    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
+    subl(8) = krll; subr(8) = krlr;
+    subl(9) = krrl; subr(9) = krrr;
+    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
+    subl(18) = krll; subr(18) = krlr;
+    subl(19) = krrl; subr(19) = krrr;
+    CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);
+    subl(26) = krll; subr(26) = krlr;
+    subl(27) = krrl; subr(27) = krrr;
+    CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);
+
+    /* generate KA */
+    kll = subl(0) ^ krll; klr = subr(0) ^ krlr;
+    krl = subl(1) ^ krrl; krr = subr(1) ^ krrr;
+    CAMELLIA_F(kll, klr,
+              CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R,
+              w0, w1, il, ir, t0, t1);
+    krl ^= w0; krr ^= w1;
+    CAMELLIA_F(krl, krr,
+              CAMELLIA_SIGMA2L, CAMELLIA_SIGMA2R,
+              kll, klr, il, ir, t0, t1);
+    kll ^= krll; klr ^= krlr;
+    CAMELLIA_F(kll, klr,
+              CAMELLIA_SIGMA3L, CAMELLIA_SIGMA3R,
+              krl, krr, il, ir, t0, t1);
+    krl ^= w0 ^ krrl; krr ^= w1 ^ krrr;
+    CAMELLIA_F(krl, krr,
+              CAMELLIA_SIGMA4L, CAMELLIA_SIGMA4R,
+              w0, w1, il, ir, t0, t1);
+    kll ^= w0; klr ^= w1;
+
+    /* generate KB */
+    krll ^= kll; krlr ^= klr;
+    krrl ^= krl; krrr ^= krr;
+    CAMELLIA_F(krll, krlr,
+              CAMELLIA_SIGMA5L, CAMELLIA_SIGMA5R,
+              w0, w1, il, ir, t0, t1);
+    krrl ^= w0; krrr ^= w1;
+    CAMELLIA_F(krrl, krrr,
+              CAMELLIA_SIGMA6L, CAMELLIA_SIGMA6R,
+              w0, w1, il, ir, t0, t1);
+    krll ^= w0; krlr ^= w1;
+
+    /* generate KA dependent subkeys */
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
+    subl(6) = kll; subr(6) = klr;
+    subl(7) = krl; subr(7) = krr;
+    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 30);
+    subl(14) = kll; subr(14) = klr;
+    subl(15) = krl; subr(15) = krr;
+    subl(24) = klr; subr(24) = krl;
+    subl(25) = krr; subr(25) = kll;
+    CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 49);
+    subl(28) = kll; subr(28) = klr;
+    subl(29) = krl; subr(29) = krr;
+
+    /* generate KB dependent subkeys */
+    subl(2) = krll; subr(2) = krlr;
+    subl(3) = krrl; subr(3) = krrr;
+    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
+    subl(10) = krll; subr(10) = krlr;
+    subl(11) = krrl; subr(11) = krrr;
+    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
+    subl(20) = krll; subr(20) = krlr;
+    subl(21) = krrl; subr(21) = krrr;
+    CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 51);
+    subl(32) = krll; subr(32) = krlr;
+    subl(33) = krrl; subr(33) = krrr;
+
+    /* absorb kw2 to other subkeys */
+    subl(3) ^= subl(1); subr(3) ^= subr(1);
+    subl(5) ^= subl(1); subr(5) ^= subr(1);
+    subl(7) ^= subl(1); subr(7) ^= subr(1);
+    subl(1) ^= subr(1) & ~subr(9);
+    dw = subl(1) & subl(9), subr(1) ^= CAMELLIA_RL1(dw);
+    subl(11) ^= subl(1); subr(11) ^= subr(1);
+    subl(13) ^= subl(1); subr(13) ^= subr(1);
+    subl(15) ^= subl(1); subr(15) ^= subr(1);
+    subl(1) ^= subr(1) & ~subr(17);
+    dw = subl(1) & subl(17), subr(1) ^= CAMELLIA_RL1(dw);
+    subl(19) ^= subl(1); subr(19) ^= subr(1);
+    subl(21) ^= subl(1); subr(21) ^= subr(1);
+    subl(23) ^= subl(1); subr(23) ^= subr(1);
+    subl(1) ^= subr(1) & ~subr(25);
+    dw = subl(1) & subl(25), subr(1) ^= CAMELLIA_RL1(dw);
+    subl(27) ^= subl(1); subr(27) ^= subr(1);
+    subl(29) ^= subl(1); subr(29) ^= subr(1);
+    subl(31) ^= subl(1); subr(31) ^= subr(1);
+    subl(32) ^= subl(1); subr(32) ^= subr(1);
+
+    /* absorb kw4 to other subkeys */
+    kw4l = subl(33); kw4r = subr(33);
+    subl(30) ^= kw4l; subr(30) ^= kw4r;
+    subl(28) ^= kw4l; subr(28) ^= kw4r;
+    subl(26) ^= kw4l; subr(26) ^= kw4r;
+    kw4l ^= kw4r & ~subr(24);
+    dw = kw4l & subl(24), kw4r ^= CAMELLIA_RL1(dw);
+    subl(22) ^= kw4l; subr(22) ^= kw4r;
+    subl(20) ^= kw4l; subr(20) ^= kw4r;
+    subl(18) ^= kw4l; subr(18) ^= kw4r;
+    kw4l ^= kw4r & ~subr(16);
+    dw = kw4l & subl(16), kw4r ^= CAMELLIA_RL1(dw);
+    subl(14) ^= kw4l; subr(14) ^= kw4r;
+    subl(12) ^= kw4l; subr(12) ^= kw4r;
+    subl(10) ^= kw4l; subr(10) ^= kw4r;
+    kw4l ^= kw4r & ~subr(8);
+    dw = kw4l & subl(8), kw4r ^= CAMELLIA_RL1(dw);
+    subl(6) ^= kw4l; subr(6) ^= kw4r;
+    subl(4) ^= kw4l; subr(4) ^= kw4r;
+    subl(2) ^= kw4l; subr(2) ^= kw4r;
+    subl(0) ^= kw4l; subr(0) ^= kw4r;
+
+    /* key XOR is end of F-function */
+    CamelliaSubkeyL(0) = subl(0) ^ subl(2);
+    CamelliaSubkeyR(0) = subr(0) ^ subr(2);
+    CamelliaSubkeyL(2) = subl(3);
+    CamelliaSubkeyR(2) = subr(3);
+    CamelliaSubkeyL(3) = subl(2) ^ subl(4);
+    CamelliaSubkeyR(3) = subr(2) ^ subr(4);
+    CamelliaSubkeyL(4) = subl(3) ^ subl(5);
+    CamelliaSubkeyR(4) = subr(3) ^ subr(5);
+    CamelliaSubkeyL(5) = subl(4) ^ subl(6);
+    CamelliaSubkeyR(5) = subr(4) ^ subr(6);
+    CamelliaSubkeyL(6) = subl(5) ^ subl(7);
+    CamelliaSubkeyR(6) = subr(5) ^ subr(7);
+    tl = subl(10) ^ (subr(10) & ~subr(8));
+    dw = tl & subl(8), tr = subr(10) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(7) = subl(6) ^ tl;
+    CamelliaSubkeyR(7) = subr(6) ^ tr;
+    CamelliaSubkeyL(8) = subl(8);
+    CamelliaSubkeyR(8) = subr(8);
+    CamelliaSubkeyL(9) = subl(9);
+    CamelliaSubkeyR(9) = subr(9);
+    tl = subl(7) ^ (subr(7) & ~subr(9));
+    dw = tl & subl(9), tr = subr(7) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(10) = tl ^ subl(11);
+    CamelliaSubkeyR(10) = tr ^ subr(11);
+    CamelliaSubkeyL(11) = subl(10) ^ subl(12);
+    CamelliaSubkeyR(11) = subr(10) ^ subr(12);
+    CamelliaSubkeyL(12) = subl(11) ^ subl(13);
+    CamelliaSubkeyR(12) = subr(11) ^ subr(13);
+    CamelliaSubkeyL(13) = subl(12) ^ subl(14);
+    CamelliaSubkeyR(13) = subr(12) ^ subr(14);
+    CamelliaSubkeyL(14) = subl(13) ^ subl(15);
+    CamelliaSubkeyR(14) = subr(13) ^ subr(15);
+    tl = subl(18) ^ (subr(18) & ~subr(16));
+    dw = tl & subl(16), tr = subr(18) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(15) = subl(14) ^ tl;
+    CamelliaSubkeyR(15) = subr(14) ^ tr;
+    CamelliaSubkeyL(16) = subl(16);
+    CamelliaSubkeyR(16) = subr(16);
+    CamelliaSubkeyL(17) = subl(17);
+    CamelliaSubkeyR(17) = subr(17);
+    tl = subl(15) ^ (subr(15) & ~subr(17));
+    dw = tl & subl(17), tr = subr(15) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(18) = tl ^ subl(19);
+    CamelliaSubkeyR(18) = tr ^ subr(19);
+    CamelliaSubkeyL(19) = subl(18) ^ subl(20);
+    CamelliaSubkeyR(19) = subr(18) ^ subr(20);
+    CamelliaSubkeyL(20) = subl(19) ^ subl(21);
+    CamelliaSubkeyR(20) = subr(19) ^ subr(21);
+    CamelliaSubkeyL(21) = subl(20) ^ subl(22);
+    CamelliaSubkeyR(21) = subr(20) ^ subr(22);
+    CamelliaSubkeyL(22) = subl(21) ^ subl(23);
+    CamelliaSubkeyR(22) = subr(21) ^ subr(23);
+    tl = subl(26) ^ (subr(26) & ~subr(24));
+    dw = tl & subl(24), tr = subr(26) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(23) = subl(22) ^ tl;
+    CamelliaSubkeyR(23) = subr(22) ^ tr;
+    CamelliaSubkeyL(24) = subl(24);
+    CamelliaSubkeyR(24) = subr(24);
+    CamelliaSubkeyL(25) = subl(25);
+    CamelliaSubkeyR(25) = subr(25);
+    tl = subl(23) ^ (subr(23) &  ~subr(25));
+    dw = tl & subl(25), tr = subr(23) ^ CAMELLIA_RL1(dw);
+    CamelliaSubkeyL(26) = tl ^ subl(27);
+    CamelliaSubkeyR(26) = tr ^ subr(27);
+    CamelliaSubkeyL(27) = subl(26) ^ subl(28);
+    CamelliaSubkeyR(27) = subr(26) ^ subr(28);
+    CamelliaSubkeyL(28) = subl(27) ^ subl(29);
+    CamelliaSubkeyR(28) = subr(27) ^ subr(29);
+    CamelliaSubkeyL(29) = subl(28) ^ subl(30);
+    CamelliaSubkeyR(29) = subr(28) ^ subr(30);
+    CamelliaSubkeyL(30) = subl(29) ^ subl(31);
+    CamelliaSubkeyR(30) = subr(29) ^ subr(31);
+    CamelliaSubkeyL(31) = subl(30);
+    CamelliaSubkeyR(31) = subr(30);
+    CamelliaSubkeyL(32) = subl(32) ^ subl(31);
+    CamelliaSubkeyR(32) = subr(32) ^ subr(31);
+
+    /* apply the inverse of the last half of P-function */
+    dw = CamelliaSubkeyL(2) ^ CamelliaSubkeyR(2), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(2) = CamelliaSubkeyL(2) ^ dw, CamelliaSubkeyL(2) = dw;
+    dw = CamelliaSubkeyL(3) ^ CamelliaSubkeyR(3), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(3) = CamelliaSubkeyL(3) ^ dw, CamelliaSubkeyL(3) = dw;
+    dw = CamelliaSubkeyL(4) ^ CamelliaSubkeyR(4), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(4) = CamelliaSubkeyL(4) ^ dw, CamelliaSubkeyL(4) = dw;
+    dw = CamelliaSubkeyL(5) ^ CamelliaSubkeyR(5), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(5) = CamelliaSubkeyL(5) ^ dw, CamelliaSubkeyL(5) = dw;
+    dw = CamelliaSubkeyL(6) ^ CamelliaSubkeyR(6), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(6) = CamelliaSubkeyL(6) ^ dw, CamelliaSubkeyL(6) = dw;
+    dw = CamelliaSubkeyL(7) ^ CamelliaSubkeyR(7), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(7) = CamelliaSubkeyL(7) ^ dw, CamelliaSubkeyL(7) = dw;
+    dw = CamelliaSubkeyL(10) ^ CamelliaSubkeyR(10), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(10) = CamelliaSubkeyL(10) ^ dw, CamelliaSubkeyL(10) = dw;
+    dw = CamelliaSubkeyL(11) ^ CamelliaSubkeyR(11), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(11) = CamelliaSubkeyL(11) ^ dw, CamelliaSubkeyL(11) = dw;
+    dw = CamelliaSubkeyL(12) ^ CamelliaSubkeyR(12), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(12) = CamelliaSubkeyL(12) ^ dw, CamelliaSubkeyL(12) = dw;
+    dw = CamelliaSubkeyL(13) ^ CamelliaSubkeyR(13), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(13) = CamelliaSubkeyL(13) ^ dw, CamelliaSubkeyL(13) = dw;
+    dw = CamelliaSubkeyL(14) ^ CamelliaSubkeyR(14), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(14) = CamelliaSubkeyL(14) ^ dw, CamelliaSubkeyL(14) = dw;
+    dw = CamelliaSubkeyL(15) ^ CamelliaSubkeyR(15), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(15) = CamelliaSubkeyL(15) ^ dw, CamelliaSubkeyL(15) = dw;
+    dw = CamelliaSubkeyL(18) ^ CamelliaSubkeyR(18), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(18) = CamelliaSubkeyL(18) ^ dw, CamelliaSubkeyL(18) = dw;
+    dw = CamelliaSubkeyL(19) ^ CamelliaSubkeyR(19), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(19) = CamelliaSubkeyL(19) ^ dw, CamelliaSubkeyL(19) = dw;
+    dw = CamelliaSubkeyL(20) ^ CamelliaSubkeyR(20), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(20) = CamelliaSubkeyL(20) ^ dw, CamelliaSubkeyL(20) = dw;
+    dw = CamelliaSubkeyL(21) ^ CamelliaSubkeyR(21), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(21) = CamelliaSubkeyL(21) ^ dw, CamelliaSubkeyL(21) = dw;
+    dw = CamelliaSubkeyL(22) ^ CamelliaSubkeyR(22), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(22) = CamelliaSubkeyL(22) ^ dw, CamelliaSubkeyL(22) = dw;
+    dw = CamelliaSubkeyL(23) ^ CamelliaSubkeyR(23), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(23) = CamelliaSubkeyL(23) ^ dw, CamelliaSubkeyL(23) = dw;
+    dw = CamelliaSubkeyL(26) ^ CamelliaSubkeyR(26), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(26) = CamelliaSubkeyL(26) ^ dw, CamelliaSubkeyL(26) = dw;
+    dw = CamelliaSubkeyL(27) ^ CamelliaSubkeyR(27), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(27) = CamelliaSubkeyL(27) ^ dw, CamelliaSubkeyL(27) = dw;
+    dw = CamelliaSubkeyL(28) ^ CamelliaSubkeyR(28), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(28) = CamelliaSubkeyL(28) ^ dw, CamelliaSubkeyL(28) = dw;
+    dw = CamelliaSubkeyL(29) ^ CamelliaSubkeyR(29), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(29) = CamelliaSubkeyL(29) ^ dw, CamelliaSubkeyL(29) = dw;
+    dw = CamelliaSubkeyL(30) ^ CamelliaSubkeyR(30), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(30) = CamelliaSubkeyL(30) ^ dw, CamelliaSubkeyL(30) = dw;
+    dw = CamelliaSubkeyL(31) ^ CamelliaSubkeyR(31), dw = CAMELLIA_RL8(dw);
+    CamelliaSubkeyR(31) = CamelliaSubkeyL(31) ^ dw,CamelliaSubkeyL(31) = dw;
+    
+    return;
+}
+
+void camellia_setup192(const unsigned char *key, u32 *subkey)
+{
+    unsigned char kk[32];
+    u32 krll, krlr, krrl,krrr;
+
+    memcpy(kk, key, 24);
+    memcpy((unsigned char *)&krll, key+16,4);
+    memcpy((unsigned char *)&krlr, key+20,4);
+    krrl = ~krll;
+    krrr = ~krlr;
+    memcpy(kk+24, (unsigned char *)&krrl, 4);
+    memcpy(kk+28, (unsigned char *)&krrr, 4);
+    camellia_setup256(kk, subkey);
+    return;
+}
+
+
+/**
+ * Stuff related to camellia encryption/decryption
+ *
+ * "io" must be 4byte aligned and big-endian data.
+ */
+void camellia_encrypt128(const u32 *subkey, u32 *io)
+{
+    u32 il, ir, t0, t1;
+
+    /* pre whitening but absorb kw2*/
+    io[0] ^= CamelliaSubkeyL(0);
+    io[1] ^= CamelliaSubkeyR(0);
+    /* main iteration */
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(2),CamelliaSubkeyR(2),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(3),CamelliaSubkeyR(3),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(4),CamelliaSubkeyR(4),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(5),CamelliaSubkeyR(5),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(6),CamelliaSubkeyR(6),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(7),CamelliaSubkeyR(7),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(8),CamelliaSubkeyR(8),
+                CamelliaSubkeyL(9),CamelliaSubkeyR(9),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(10),CamelliaSubkeyR(10),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(11),CamelliaSubkeyR(11),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(12),CamelliaSubkeyR(12),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(13),CamelliaSubkeyR(13),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(14),CamelliaSubkeyR(14),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(15),CamelliaSubkeyR(15),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(16),CamelliaSubkeyR(16),
+                CamelliaSubkeyL(17),CamelliaSubkeyR(17),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(18),CamelliaSubkeyR(18),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(19),CamelliaSubkeyR(19),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(20),CamelliaSubkeyR(20),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(21),CamelliaSubkeyR(21),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(22),CamelliaSubkeyR(22),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(23),CamelliaSubkeyR(23),
+                    io[0],io[1],il,ir,t0,t1);
+
+    /* post whitening but kw4 */
+    io[2] ^= CamelliaSubkeyL(24);
+    io[3] ^= CamelliaSubkeyR(24);
+
+    t0 = io[0];
+    t1 = io[1];
+    io[0] = io[2];
+    io[1] = io[3];
+    io[2] = t0;
+    io[3] = t1;
+       
+    return;
+}
+
+void camellia_decrypt128(const u32 *subkey, u32 *io)
+{
+    u32 il,ir,t0,t1;               /* temporary valiables */
+    
+    /* pre whitening but absorb kw2*/
+    io[0] ^= CamelliaSubkeyL(24);
+    io[1] ^= CamelliaSubkeyR(24);
+
+    /* main iteration */
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(23),CamelliaSubkeyR(23),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(22),CamelliaSubkeyR(22),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(21),CamelliaSubkeyR(21),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(20),CamelliaSubkeyR(20),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(19),CamelliaSubkeyR(19),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(18),CamelliaSubkeyR(18),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(17),CamelliaSubkeyR(17),
+                CamelliaSubkeyL(16),CamelliaSubkeyR(16),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(15),CamelliaSubkeyR(15),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(14),CamelliaSubkeyR(14),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(13),CamelliaSubkeyR(13),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(12),CamelliaSubkeyR(12),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(11),CamelliaSubkeyR(11),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(10),CamelliaSubkeyR(10),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(9),CamelliaSubkeyR(9),
+                CamelliaSubkeyL(8),CamelliaSubkeyR(8),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(7),CamelliaSubkeyR(7),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(6),CamelliaSubkeyR(6),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(5),CamelliaSubkeyR(5),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(4),CamelliaSubkeyR(4),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(3),CamelliaSubkeyR(3),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(2),CamelliaSubkeyR(2),
+                    io[0],io[1],il,ir,t0,t1);
+
+    /* post whitening but kw4 */
+    io[2] ^= CamelliaSubkeyL(0);
+    io[3] ^= CamelliaSubkeyR(0);
+
+    t0 = io[0];
+    t1 = io[1];
+    io[0] = io[2];
+    io[1] = io[3];
+    io[2] = t0;
+    io[3] = t1;
+
+    return;
+}
+
+/**
+ * stuff for 192 and 256bit encryption/decryption
+ */
+void camellia_encrypt256(const u32 *subkey, u32 *io)
+{
+    u32 il,ir,t0,t1;           /* temporary valiables */
+
+    /* pre whitening but absorb kw2*/
+    io[0] ^= CamelliaSubkeyL(0);
+    io[1] ^= CamelliaSubkeyR(0);
+
+    /* main iteration */
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(2),CamelliaSubkeyR(2),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(3),CamelliaSubkeyR(3),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(4),CamelliaSubkeyR(4),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(5),CamelliaSubkeyR(5),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(6),CamelliaSubkeyR(6),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(7),CamelliaSubkeyR(7),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(8),CamelliaSubkeyR(8),
+                CamelliaSubkeyL(9),CamelliaSubkeyR(9),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(10),CamelliaSubkeyR(10),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(11),CamelliaSubkeyR(11),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(12),CamelliaSubkeyR(12),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(13),CamelliaSubkeyR(13),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(14),CamelliaSubkeyR(14),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(15),CamelliaSubkeyR(15),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(16),CamelliaSubkeyR(16),
+                CamelliaSubkeyL(17),CamelliaSubkeyR(17),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(18),CamelliaSubkeyR(18),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(19),CamelliaSubkeyR(19),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(20),CamelliaSubkeyR(20),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(21),CamelliaSubkeyR(21),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(22),CamelliaSubkeyR(22),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(23),CamelliaSubkeyR(23),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(24),CamelliaSubkeyR(24),
+                CamelliaSubkeyL(25),CamelliaSubkeyR(25),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(26),CamelliaSubkeyR(26),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(27),CamelliaSubkeyR(27),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(28),CamelliaSubkeyR(28),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(29),CamelliaSubkeyR(29),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(30),CamelliaSubkeyR(30),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(31),CamelliaSubkeyR(31),
+                    io[0],io[1],il,ir,t0,t1);
+
+    /* post whitening but kw4 */
+    io[2] ^= CamelliaSubkeyL(32);
+    io[3] ^= CamelliaSubkeyR(32);
+
+    t0 = io[0];
+    t1 = io[1];
+    io[0] = io[2];
+    io[1] = io[3];
+    io[2] = t0;
+    io[3] = t1;
+
+    return;
+}
+
+void camellia_decrypt256(const u32 *subkey, u32 *io)
+{
+    u32 il,ir,t0,t1;           /* temporary valiables */
+
+    /* pre whitening but absorb kw2*/
+    io[0] ^= CamelliaSubkeyL(32);
+    io[1] ^= CamelliaSubkeyR(32);
+       
+    /* main iteration */
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(31),CamelliaSubkeyR(31),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(30),CamelliaSubkeyR(30),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(29),CamelliaSubkeyR(29),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(28),CamelliaSubkeyR(28),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(27),CamelliaSubkeyR(27),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(26),CamelliaSubkeyR(26),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(25),CamelliaSubkeyR(25),
+                CamelliaSubkeyL(24),CamelliaSubkeyR(24),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(23),CamelliaSubkeyR(23),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(22),CamelliaSubkeyR(22),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(21),CamelliaSubkeyR(21),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(20),CamelliaSubkeyR(20),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(19),CamelliaSubkeyR(19),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(18),CamelliaSubkeyR(18),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(17),CamelliaSubkeyR(17),
+                CamelliaSubkeyL(16),CamelliaSubkeyR(16),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(15),CamelliaSubkeyR(15),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(14),CamelliaSubkeyR(14),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(13),CamelliaSubkeyR(13),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(12),CamelliaSubkeyR(12),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(11),CamelliaSubkeyR(11),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(10),CamelliaSubkeyR(10),
+                    io[0],io[1],il,ir,t0,t1);
+
+    CAMELLIA_FLS(io[0],io[1],io[2],io[3],
+                CamelliaSubkeyL(9),CamelliaSubkeyR(9),
+                CamelliaSubkeyL(8),CamelliaSubkeyR(8),
+                t0,t1,il,ir);
+
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(7),CamelliaSubkeyR(7),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(6),CamelliaSubkeyR(6),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(5),CamelliaSubkeyR(5),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(4),CamelliaSubkeyR(4),
+                    io[0],io[1],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[0],io[1],
+                    CamelliaSubkeyL(3),CamelliaSubkeyR(3),
+                    io[2],io[3],il,ir,t0,t1);
+    CAMELLIA_ROUNDSM(io[2],io[3],
+                    CamelliaSubkeyL(2),CamelliaSubkeyR(2),
+                    io[0],io[1],il,ir,t0,t1);
+
+    /* post whitening but kw4 */
+    io[2] ^= CamelliaSubkeyL(0);
+    io[3] ^= CamelliaSubkeyR(0);
+
+    t0 = io[0];
+    t1 = io[1];
+    io[0] = io[2];
+    io[1] = io[3];
+    io[2] = t0;
+    io[3] = t1;
+
+    return;
+}
+
+/***
+ *
+ * API for compatibility
+ */
+
+void Camellia_Ekeygen(const int keyBitLength, 
+                     const unsigned char *rawKey, 
+                     KEY_TABLE_TYPE keyTable)
+{
+    switch(keyBitLength) {
+    case 128:
+       camellia_setup128(rawKey, keyTable);
+       break;
+    case 192:
+       camellia_setup192(rawKey, keyTable);
+       break;
+    case 256:
+       camellia_setup256(rawKey, keyTable);
+       break;
+    default:
+       break;
+    }
+}
+
+
+void Camellia_EncryptBlock(const int keyBitLength, 
+                          const unsigned char *plaintext, 
+                          const KEY_TABLE_TYPE keyTable, 
+                          unsigned char *ciphertext)
+{
+    u32 tmp[4];
+
+    tmp[0] = GETU32(plaintext);
+    tmp[1] = GETU32(plaintext + 4);
+    tmp[2] = GETU32(plaintext + 8);
+    tmp[3] = GETU32(plaintext + 12);
+
+    switch (keyBitLength) {
+    case 128:
+       camellia_encrypt128(keyTable, tmp);
+       break;
+    case 192:
+       /* fall through */
+    case 256:
+       camellia_encrypt256(keyTable, tmp);
+       break;
+    default:
+       break;
+    }
+
+    PUTU32(ciphertext, tmp[0]);
+    PUTU32(ciphertext + 4, tmp[1]);
+    PUTU32(ciphertext + 8, tmp[2]);
+    PUTU32(ciphertext + 12, tmp[3]);
+}
+
+void Camellia_DecryptBlock(const int keyBitLength, 
+                          const unsigned char *ciphertext, 
+                          const KEY_TABLE_TYPE keyTable, 
+                          unsigned char *plaintext)
+{
+    u32 tmp[4];
+
+    tmp[0] = GETU32(ciphertext);
+    tmp[1] = GETU32(ciphertext + 4);
+    tmp[2] = GETU32(ciphertext + 8);
+    tmp[3] = GETU32(ciphertext + 12);
+
+    switch (keyBitLength) {
+    case 128:
+       camellia_decrypt128(keyTable, tmp);
+       break;
+    case 192:
+       /* fall through */
+    case 256:
+       camellia_decrypt256(keyTable, tmp);
+       break;
+    default:
+       break;
+    }
+    PUTU32(plaintext, tmp[0]);
+    PUTU32(plaintext + 4, tmp[1]);
+    PUTU32(plaintext + 8, tmp[2]);
+    PUTU32(plaintext + 12, tmp[3]);
+}
diff --git a/source/heimdal/lib/hcrypto/camellia-ntt.h b/source/heimdal/lib/hcrypto/camellia-ntt.h
new file mode 100644 (file)
index 0000000..740ed8b
--- /dev/null
@@ -0,0 +1,54 @@
+/* camellia.h  ver 1.2.0
+ *
+ * Copyright (C) 2006,2007
+ * NTT (Nippon Telegraph and Telephone Corporation).
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef HEADER_CAMELLIA_H
+#define HEADER_CAMELLIA_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#define CAMELLIA_BLOCK_SIZE 16
+#define CAMELLIA_TABLE_BYTE_LEN 272
+#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
+
+typedef unsigned int KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN];
+
+
+void Camellia_Ekeygen(const int keyBitLength,
+                     const unsigned char *rawKey, 
+                     KEY_TABLE_TYPE keyTable);
+
+void Camellia_EncryptBlock(const int keyBitLength,
+                          const unsigned char *plaintext, 
+                          const KEY_TABLE_TYPE keyTable, 
+                          unsigned char *cipherText);
+
+void Camellia_DecryptBlock(const int keyBitLength, 
+                          const unsigned char *cipherText, 
+                          const KEY_TABLE_TYPE keyTable, 
+                          unsigned char *plaintext);
+
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif /* HEADER_CAMELLIA_H */
diff --git a/source/heimdal/lib/hcrypto/camellia.c b/source/heimdal/lib/hcrypto/camellia.c
new file mode 100644 (file)
index 0000000..2047b75
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2007 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+
+RCSID("$Id: aes.c 20466 2007-04-20 08:29:05Z lha $");
+#endif
+
+#ifdef KRB5
+#include <krb5-types.h>
+#endif
+
+#include <string.h>
+
+#include "camellia-ntt.h"
+#include "camellia.h"
+
+int
+CAMELLIA_set_key(const unsigned char *userkey, 
+                const int bits, CAMELLIA_KEY *key)
+{
+    key->bits = bits;
+    Camellia_Ekeygen(bits, userkey, key->key);
+    return 1;
+}
+
+void
+CAMELLIA_encrypt(const unsigned char *in, unsigned char *out, 
+                const CAMELLIA_KEY *key)
+{
+    Camellia_EncryptBlock(key->bits, in, key->key, out);
+
+}
+
+void
+CAMELLIA_decrypt(const unsigned char *in, unsigned char *out, 
+                const CAMELLIA_KEY *key)
+{
+    Camellia_DecryptBlock(key->bits, in, key->key, out);
+}
+
+void
+CAMELLIA_cbc_encrypt(const unsigned char *in, unsigned char *out,
+                    unsigned long size, const CAMELLIA_KEY *key,
+                    unsigned char *iv, int mode_encrypt)
+{
+    unsigned char tmp[CAMELLIA_BLOCK_SIZE];
+    int i;
+
+    if (mode_encrypt) {
+       while (size >= CAMELLIA_BLOCK_SIZE) {
+           for (i = 0; i < CAMELLIA_BLOCK_SIZE; i++)
+               tmp[i] = in[i] ^ iv[i];
+           CAMELLIA_encrypt(tmp, out, key);
+           memcpy(iv, out, CAMELLIA_BLOCK_SIZE);
+           size -= CAMELLIA_BLOCK_SIZE;
+           in += CAMELLIA_BLOCK_SIZE;
+           out += CAMELLIA_BLOCK_SIZE;
+       }
+       if (size) {
+           for (i = 0; i < size; i++)
+               tmp[i] = in[i] ^ iv[i];
+           for (i = size; i < CAMELLIA_BLOCK_SIZE; i++)
+               tmp[i] = iv[i];
+           CAMELLIA_encrypt(tmp, out, key);
+           memcpy(iv, out, CAMELLIA_BLOCK_SIZE);
+       }
+    } else {
+       while (size >= CAMELLIA_BLOCK_SIZE) {
+           memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
+           CAMELLIA_decrypt(tmp, out, key);
+           for (i = 0; i < CAMELLIA_BLOCK_SIZE; i++)
+               out[i] ^= iv[i];
+           memcpy(iv, tmp, CAMELLIA_BLOCK_SIZE);
+           size -= CAMELLIA_BLOCK_SIZE;
+           in += CAMELLIA_BLOCK_SIZE;
+           out += CAMELLIA_BLOCK_SIZE;
+       }
+       if (size) {
+           memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
+           CAMELLIA_decrypt(tmp, out, key);
+           for (i = 0; i < size; i++)
+               out[i] ^= iv[i];
+           memcpy(iv, tmp, CAMELLIA_BLOCK_SIZE);
+       }
+    }
+}
diff --git a/source/heimdal/lib/hcrypto/camellia.h b/source/heimdal/lib/hcrypto/camellia.h
new file mode 100644 (file)
index 0000000..3b21934
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2007 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $Id$ */
+
+#ifndef HEIM_CAMELLIA_H
+#define HEIM_CAMELLIA_H 1
+
+#include <krb5-types.h>
+#include "camellia-ntt.h"
+
+/* symbol renaming */
+#define CAMELLIA_set_key hc_CAMELLIA_set_encrypt_key
+#define CAMELLIA_encrypt hc_CAMELLIA_encrypt
+#define CAMELLIA_decrypt hc_CAMELLIA_decrypt
+#define CAMELLIA_cbc_encrypt hc_CAMELLIA_cbc_encrypt
+
+/*
+ *
+ */
+
+#define CAMELLIA_BLOCK_SIZE 16
+#define CAMELLIA_MAXNR 14
+
+#define CAMELLIA_ENCRYPT 1
+#define CAMELLIA_DECRYPT 0
+
+typedef struct camellia_key {
+    unsigned int bits;
+    KEY_TABLE_TYPE key;
+} CAMELLIA_KEY;
+
+int CAMELLIA_set_key(const unsigned char *, const int, CAMELLIA_KEY *);
+
+void CAMELLIA_encrypt(const unsigned char *, unsigned char *,
+                     const CAMELLIA_KEY *);
+void CAMELLIA_decrypt(const unsigned char *, unsigned char *,
+                     const CAMELLIA_KEY *);
+
+void CAMELLIA_cbc_encrypt(const unsigned char *, unsigned char *,
+                         const unsigned long, const CAMELLIA_KEY *,
+                         unsigned char *, int);
+
+#endif /* HEIM_CAMELLIA_H */
index 17592bbdf69d4474087c19c90b7be093d240c3aa..494d436d131118f00a0ca733d13e8e9bd9ff8c16 100644 (file)
@@ -43,7 +43,7 @@
 
 #include "imath/imath.h"
 
-RCSID("$Id: dh-imath.c 18645 2006-10-20 06:56:57Z lha $");
+RCSID("$Id: dh-imath.c 22368 2007-12-28 15:27:52Z lha $");
 
 static void
 BN2mpz(mpz_t *s, const BIGNUM *bn)
@@ -224,7 +224,7 @@ dh_finish(DH *dh)
  *
  */
 
-const DH_METHOD hc_dh_imath_method = {
+const DH_METHOD _hc_dh_imath_method = {
     "hcrypto imath DH",
     dh_generate_key,
     dh_compute_key,
@@ -236,8 +236,16 @@ const DH_METHOD hc_dh_imath_method = {
     dh_generate_params
 };
 
+/**
+ * DH implementation using libimath.
+ *
+ * @return the DH_METHOD for the DH implementation using libimath.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 const DH_METHOD *
 DH_imath_method(void)
 {
-    return &hc_dh_imath_method;
+    return &_hc_dh_imath_method;
 }
index b558eb901cce84b9d0eabf1eddfe6e42f91cf772..9f1af0b3b114b8fabd7a3c29ffb90bd49eb1b6e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006 Kungliga Tekniska Högskolan
+ * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden). 
  * All rights reserved. 
  *
@@ -35,7 +35,7 @@
 #include <config.h>
 #endif
 
-RCSID("$Id: dh.c 18618 2006-10-19 17:31:51Z lha $");
+RCSID("$Id: dh.c 22397 2008-01-01 20:20:31Z lha $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -43,8 +43,23 @@ RCSID("$Id: dh.c 18618 2006-10-19 17:31:51Z lha $");
 
 #include <roken.h>
 
-/*
+/**
+ * @page page_dh DH - Diffie-Hellman key exchange
+ *
+ * Diffie-Hellman key exchange is a protocol that allows two parties
+ * to establish a shared secret key.
+ *
+ * Include and example how to use DH_new() and friends here.
  *
+ * See the library functions here: @ref hcrypto_dh
+ */
+
+/**
+ * Create a new DH object using DH_new_method(NULL), see DH_new_method().
+ *
+ * @return a newly allocated DH object.
+ *
+ * @ingroup hcrypto_dh
  */
 
 DH *
@@ -53,6 +68,17 @@ DH_new(void)
     return DH_new_method(NULL);
 }
 
+/**
+ * Create a new DH object from the given engine, if the NULL is used,
+ * the default engine is used. Free the DH object with DH_free().
+ *
+ * @param engine The engine to use to allocate the DH object. 
+ *
+ * @return a newly allocated DH object.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 DH *
 DH_new_method(ENGINE *engine)
 {
@@ -88,6 +114,15 @@ DH_new_method(ENGINE *engine)
     return dh;
 }
 
+/**
+ * Free a DH object and release related resources, like ENGINE, that
+ * the object was using.
+ *
+ * @param dh object to be freed.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 void
 DH_free(DH *dh)
 {
@@ -116,18 +151,52 @@ DH_free(DH *dh)
     free(dh);
 }    
 
+/**
+ * Add a reference to the DH object. The object should be free with
+ * DH_free() to drop the reference.
+ *
+ * @param dh the object to increase the reference count too.
+ *
+ * @return the updated reference count, can't safely be used except
+ * for debug printing.
+ * 
+ * @ingroup hcrypto_dh
+ */
+
 int
 DH_up_ref(DH *dh)
 {
     return ++dh->references;
 }
 
+/**
+ * The maximum output size of the DH_compute_key() function.
+ *
+ * @param dh The DH object to get the size from.
+ *
+ * @return the maximum size in bytes of the out data.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 int
 DH_size(const DH *dh)
 {
     return BN_num_bytes(dh->p);
 }
 
+/**
+ * Set the data index idx in the DH object to data.
+ *
+ * @param dh DH object.
+ * @param idx index to set the data for.
+ * @param data data to store for the index idx.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 int
 DH_set_ex_data(DH *dh, int idx, void *data)
 {
@@ -135,12 +204,36 @@ DH_set_ex_data(DH *dh, int idx, void *data)
     return 1;
 }
 
+/**
+ * Get the data for index idx in the DH object.
+ *
+ * @param dh DH object.
+ * @param idx index to get the data for.
+ *
+ * @return the object store in index idx
+ *
+ * @ingroup hcrypto_dh
+ */
+
 void *
 DH_get_ex_data(DH *dh, int idx)
 {
     return dh->ex_data.sk;
 }
 
+/**
+ * Generate DH parameters for the DH object give parameters.
+ *
+ * @param dh The DH object to generate parameters for.
+ * @param prime_len length of the prime
+ * @param generator generator, g
+ * @param cb Callback parameters to show progress, can be NULL.
+ *
+ * @return the maximum size in bytes of the out data.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 int
 DH_generate_parameters_ex(DH *dh, int prime_len, int generator, BN_GENCB *cb)
 {
@@ -149,12 +242,17 @@ DH_generate_parameters_ex(DH *dh, int prime_len, int generator, BN_GENCB *cb)
     return 0;
 }
 
-/*
- * Check that
+/**
+ * Check that the public key is sane.
  *
- *     pub_key > 1    and    pub_key < p - 1
+ * @param dh the local peer DH parameters.
+ * @param pub_key the remote peer public key parameters.
+ * @param codes return that the failures of the pub_key are.
  *
- * to avoid small subgroups attack.
+ * @return 1 on success, 0 on failure and *codes is set the the
+ * combined fail check for the public key
+ *
+ * @ingroup hcrypto_dh
  */
 
 int
@@ -165,6 +263,19 @@ DH_check_pubkey(const DH *dh, const BIGNUM *pub_key, int *codes)
 
     *codes = 0;
 
+    /**
+     * Checks that the function performs are:
+     * - pub_key is not negative 
+     */
+
+    if (BN_is_negative(pub_key))
+       goto out;
+
+    /**
+     * - pub_key > 1    and    pub_key < p - 1,
+     *    to avoid small subgroups attack.
+     */
+
     bn = BN_new();
     if (bn == NULL)
        goto out;
@@ -184,6 +295,28 @@ DH_check_pubkey(const DH *dh, const BIGNUM *pub_key, int *codes)
     if (BN_cmp(sum, dh->p) >= 0)
        *codes |= DH_CHECK_PUBKEY_TOO_LARGE;
 
+    /**
+     * - if g == 2, pub_key have more then one bit set,
+     *   if bits set is 1, log_2(pub_key) is trival
+     */
+
+    if (!BN_set_word(bn, 2))
+       goto out;
+
+    if (BN_cmp(bn, pub_key) == 0) {
+       unsigned i, n = BN_num_bits(pub_key);
+       unsigned bits = 0;
+
+       for (i = 0; i <= n; i++)
+           if (BN_is_bit_set(pub_key, i))
+               bits++;
+
+       if (bits > 1) {
+           *codes |= DH_CHECK_PUBKEY_TOO_SMALL;
+           goto out;
+       }
+    }
+
     ret = 1;
 out:
     if (bn)
@@ -194,24 +327,64 @@ out:
     return ret;
 }
 
+/**
+ * Generate a new DH private-public key pair. The dh parameter must be
+ * allocted first with DH_new(). dh->p and dp->g must be set.
+ *
+ * @param dh dh parameter.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 int
 DH_generate_key(DH *dh)
 {
     return dh->meth->generate_key(dh);
 }
 
+/**
+ * Complute the shared secret key.
+ *
+ * @param shared_key the resulting shared key, need to be at least
+ * DH_size() large.
+ * @param peer_pub_key the peer's public key.
+ * @param dh the dh key pair.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 int
 DH_compute_key(unsigned char *shared_key,
               const BIGNUM *peer_pub_key, DH *dh)
 {
     int codes;
 
+    /**
+     * Checks that the pubkey passed in is valid using
+     * DH_check_pubkey().
+     */
+
     if (!DH_check_pubkey(dh, peer_pub_key, &codes) || codes != 0)
        return -1;
 
     return dh->meth->compute_key(shared_key, peer_pub_key, dh);
 }
 
+/**
+ * Set a new method for the DH keypair.
+ *
+ * @param dh dh parameter.
+ * @param method the new method for the DH parameter.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 int
 DH_set_method(DH *dh, const DH_METHOD *method)
 {
@@ -271,8 +444,16 @@ static const DH_METHOD dh_null_method = {
     dh_null_generate_params
 };
 
-extern const DH_METHOD hc_dh_imath_method;
-static const DH_METHOD *dh_default_method = &hc_dh_imath_method;
+extern const DH_METHOD _hc_dh_imath_method;
+static const DH_METHOD *dh_default_method = &_hc_dh_imath_method;
+
+/**
+ * Return the dummy DH implementation.
+ *
+ * @return pointer to a DH_METHOD.
+ *
+ * @ingroup hcrypto_dh
+ */
 
 const DH_METHOD *
 DH_null_method(void)
@@ -280,12 +461,28 @@ DH_null_method(void)
     return &dh_null_method;
 }
 
+/**
+ * Set the default DH implementation.
+ *
+ * @param meth pointer to a DH_METHOD.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 void
 DH_set_default_method(const DH_METHOD *meth)
 {
     dh_default_method = meth;
 }
 
+/**
+ * Return the default DH implementation.
+ *
+ * @return pointer to a DH_METHOD.
+ *
+ * @ingroup hcrypto_dh
+ */
+
 const DH_METHOD *
 DH_get_default_method(void)
 {
index 19b0ac85e7a0250341b3121254e8a46f70eb2157..788000b05489e2fecc7b82ce03acb914103c3963 100644 (file)
@@ -1,7 +1,42 @@
+/*
+ * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden). 
+ * All rights reserved. 
+ *
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following conditions 
+ * are met: 
+ *
+ * 1. Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright 
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the distribution. 
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors 
+ *    may be used to endorse or promote products derived from this software 
+ *    without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE. 
+ */
+
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
+RCSID("$Id: evp.c 22379 2007-12-29 11:13:26Z lha $");
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -13,6 +48,7 @@
 #include <krb5-types.h>
 
 #include <aes.h>
+#include "camellia.h"
 #include <des.h>
 #include <sha.h>
 #include <rc2.h>
 #include <md4.h>
 #include <md5.h>
 
+/**
+ * @page page_evp EVP - generic crypto interface
+ *
+ * See the library functions here: @ref hcrypto_evp
+ */
+
+
 typedef int (*evp_md_init)(EVP_MD_CTX *);
 typedef int (*evp_md_update)(EVP_MD_CTX *,const void *, size_t);
 typedef int (*evp_md_final)(void *, EVP_MD_CTX *);
@@ -36,8 +79,14 @@ struct hc_evp_md {
     evp_md_cleanup cleanup;
 };
 
-/*
+/**
+ * Return the output size of the message digest function.
+ *
+ * @param md the evp message
  *
+ * @return size output size of the message digest function.
+ *
+ * @ingroup hcrypto_evp
  */
 
 size_t
@@ -46,24 +95,60 @@ EVP_MD_size(const EVP_MD *md)
     return md->hash_size;
 }
 
+/**
+ * Return the blocksize of the message digest function.
+ *
+ * @param md the evp message
+ *
+ * @return size size of the message digest block size
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_MD_block_size(const EVP_MD *md)
 {
     return md->block_size;
 }
 
+/**
+ * Allocate a messsage digest context object. Free with
+ * EVP_MD_CTX_destroy().
+ *
+ * @return a newly allocated message digest context object.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 EVP_MD_CTX *
 EVP_MD_CTX_create(void)
 {
     return calloc(1, sizeof(EVP_MD_CTX));
 }
 
+/**
+ * Initiate a messsage digest context object. Deallocate with
+ * EVP_MD_CTX_cleanup(). Please use EVP_MD_CTX_create() instead.
+ *
+ * @param ctx variable to initiate.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 void
 EVP_MD_CTX_init(EVP_MD_CTX *ctx)
 {
     memset(ctx, 0, sizeof(*ctx));
 }
 
+/**
+ * Free a messsage digest context object.
+ *
+ * @param ctx context to free.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 void
 EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
 {
@@ -71,6 +156,16 @@ EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
     free(ctx);
 }
 
+/**
+ * Free the resources used by the EVP_MD context.
+ *
+ * @param ctx the context to free the resources from.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
 {
@@ -79,9 +174,19 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
     ctx->md = NULL;
     ctx->engine = NULL;
     free(ctx->ptr);
+    memset(ctx, 0, sizeof(*ctx));
     return 1;
 }
 
+/**
+ * Get the EVP_MD use for a specified context.
+ *
+ * @param ctx the EVP_MD context to get the EVP_MD for.
+ *
+ * @return the EVP_MD used for the context.
+ *
+ * @ingroup hcrypto_evp
+ */
 
 const EVP_MD *
 EVP_MD_CTX_md(EVP_MD_CTX *ctx)
@@ -89,18 +194,50 @@ EVP_MD_CTX_md(EVP_MD_CTX *ctx)
     return ctx->md;
 }
 
+/**
+ * Return the output size of the message digest function.
+ *
+ * @param ctx the evp message digest context
+ *
+ * @return size output size of the message digest function.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_MD_CTX_size(EVP_MD_CTX *ctx)
 {
     return EVP_MD_size(ctx->md);
 }
 
+/**
+ * Return the blocksize of the message digest function.
+ *
+ * @param ctx the evp message digest context
+ *
+ * @return size size of the message digest block size
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_MD_CTX_block_size(EVP_MD_CTX *ctx)
 {
     return EVP_MD_block_size(ctx->md);
 }
 
+/**
+ * Init a EVP_MD_CTX for use a specific message digest and engine.
+ *
+ * @param ctx the message digest context to init.
+ * @param md the message digest to use.
+ * @param engine the engine to use, NULL to use the default engine.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *md, ENGINE *engine)
 {
@@ -117,6 +254,18 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *md, ENGINE *engine)
     return 1;
 }
 
+/**
+ * Update the digest with some data.
+ *
+ * @param ctx the context to update
+ * @param data the data to update the context with
+ * @param size length of data
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t size)
 {
@@ -124,6 +273,19 @@ EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t size)
     return 1;
 }
 
+/**
+ * Complete the message digest.
+ *
+ * @param ctx the context to complete.
+ * @param hash the output of the message digest function. At least
+ * EVP_MD_size().
+ * @param size the output size of hash.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_DigestFinal_ex(EVP_MD_CTX *ctx, void *hash, unsigned int *size)
 {
@@ -133,6 +295,23 @@ EVP_DigestFinal_ex(EVP_MD_CTX *ctx, void *hash, unsigned int *size)
     return 1;
 }
 
+/**
+ * Do the whole EVP_MD_CTX_create(), EVP_DigestInit_ex(),
+ * EVP_DigestUpdate(), EVP_DigestFinal_ex(), EVP_MD_CTX_destroy()
+ * dance in one call.
+ *
+ * @param data the data to update the context with
+ * @param dsize length of data
+ * @param hash output data of at least EVP_MD_size() length.
+ * @param hsize output length of hash.
+ * @param md message digest to use
+ * @param engine engine to use, NULL for default engine.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_Digest(const void *data, size_t dsize, void *hash, unsigned int *hsize, 
           const EVP_MD *md, ENGINE *engine)
@@ -144,20 +323,26 @@ EVP_Digest(const void *data, size_t dsize, void *hash, unsigned int *hsize,
     if (ctx == NULL)
        return 0;
     ret = EVP_DigestInit_ex(ctx, md, engine);
-    if (ret != 1)
+    if (ret != 1) {
+       EVP_MD_CTX_destroy(ctx);
        return ret;
+    }
     ret = EVP_DigestUpdate(ctx, data, dsize);
-    if (ret != 1)
+    if (ret != 1) {
+       EVP_MD_CTX_destroy(ctx);
        return ret;
+    }
     ret = EVP_DigestFinal_ex(ctx, hash, hsize);
-    if (ret != 1)
-       return ret;
     EVP_MD_CTX_destroy(ctx);
-    return 1;
+    return ret;
 }
 
-/*
+/**
+ * The message digest SHA256
+ *
+ * @return the message digest type.
  *
+ * @ingroup hcrypto_evp
  */
 
 const EVP_MD *
@@ -185,18 +370,42 @@ static const struct hc_evp_md sha1 = {
     NULL
 };
 
+/**
+ * The message digest SHA1
+ *
+ * @return the message digest type.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_MD *
 EVP_sha1(void)
 {
     return &sha1;
 }
 
+/**
+ * The message digest SHA1
+ *
+ * @return the message digest type.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_MD *
 EVP_sha(void)
 {
     return &sha1;
 }
 
+/**
+ * The message digest MD5
+ *
+ * @return the message digest type.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_MD *
 EVP_md5(void)
 {
@@ -212,6 +421,14 @@ EVP_md5(void)
     return &md5;
 }
 
+/**
+ * The message digest MD4
+ *
+ * @return the message digest type.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_MD *
 EVP_md4(void)
 {
@@ -227,6 +444,14 @@ EVP_md4(void)
     return &md4;
 }
 
+/**
+ * The message digest MD2
+ *
+ * @return the message digest type.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_MD *
 EVP_md2(void)
 {
@@ -255,10 +480,18 @@ null_Update (void *m, const void * data, size_t size)
 {
 }
 static void
-null_Final(void *res, struct md5 *m)
+null_Final(void *res, void *m)
 {
 }
 
+/**
+ * The null message digest
+ *
+ * @return the message digest type.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_MD *
 EVP_md_null(void)
 {
@@ -282,8 +515,14 @@ int        EVP_SignFinal(EVP_MD_CTX *, void *, size_t *, EVP_PKEY *);
 int    EVP_VerifyFinal(EVP_MD_CTX *, const void *, size_t, EVP_PKEY *);
 #endif
 
-/*
+/**
+ * Return the block size of the cipher.
+ *
+ * @param c cipher to get the block size from.
  *
+ * @return the block size of the cipher.
+ *
+ * @ingroup hcrypto_evp
  */
 
 size_t
@@ -292,24 +531,63 @@ EVP_CIPHER_block_size(const EVP_CIPHER *c)
     return c->block_size;
 }
 
+/**
+ * Return the key size of the cipher.
+ *
+ * @param c cipher to get the key size from.
+ *
+ * @return the key size of the cipher.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_CIPHER_key_length(const EVP_CIPHER *c)
 {
     return c->key_len;
 }
 
+/**
+ * Return the IV size of the cipher.
+ *
+ * @param c cipher to get the IV size from.
+ *
+ * @return the IV size of the cipher.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_CIPHER_iv_length(const EVP_CIPHER *c)
 {
     return c->iv_len;
 }
 
+/**
+ * Initiate a EVP_CIPHER_CTX context. Clean up with
+ * EVP_CIPHER_CTX_cleanup().
+ *
+ * @param c the cipher initiate.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 void
 EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *c)
 {
     memset(c, 0, sizeof(*c));
 }
 
+/**
+ * Clean up the EVP_CIPHER_CTX context.
+ *
+ * @param c the cipher to clean up.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
 {
@@ -336,54 +614,149 @@ EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad)
 }
 #endif
 
+/**
+ * Return the EVP_CIPHER for a EVP_CIPHER_CTX context.
+ *
+ * @param ctx the context to get the cipher type from.
+ *
+ * @return the EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *ctx)
 {
     return ctx->cipher;
 }
 
+/**
+ * Return the block size of the cipher context.
+ *
+ * @param ctx cipher context to get the block size from.
+ *
+ * @return the block size of the cipher context.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
 {
     return EVP_CIPHER_block_size(ctx->cipher);
 }
 
+/**
+ * Return the key size of the cipher context.
+ *
+ * @param ctx cipher context to get the key size from.
+ *
+ * @return the key size of the cipher context.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
 {
     return EVP_CIPHER_key_length(ctx->cipher);
 }
 
+/**
+ * Return the IV size of the cipher context.
+ *
+ * @param ctx cipher context to get the IV size from.
+ *
+ * @return the IV size of the cipher context.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 size_t
 EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
 {
     return EVP_CIPHER_iv_length(ctx->cipher);
 }
 
+/**
+ * Get the flags for an EVP_CIPHER_CTX context.
+ *
+ * @param ctx the EVP_CIPHER_CTX to get the flags from
+ *
+ * @return the flags for an EVP_CIPHER_CTX.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 unsigned long
 EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
 {
     return ctx->cipher->flags;
 }
 
+/**
+ * Get the mode for an EVP_CIPHER_CTX context.
+ *
+ * @param ctx the EVP_CIPHER_CTX to get the mode from
+ *
+ * @return the mode for an EVP_CIPHER_CTX.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_CIPHER_CTX_mode(const EVP_CIPHER_CTX *ctx)
 {
     return EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_MODE;
 }
 
+/**
+ * Get the app data for an EVP_CIPHER_CTX context.
+ *
+ * @param ctx the EVP_CIPHER_CTX to get the app data from
+ *
+ * @return the app data for an EVP_CIPHER_CTX.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 void *
 EVP_CIPHER_CTX_get_app_data(EVP_CIPHER_CTX *ctx)
 {
     return ctx->app_data;
 }
 
+/**
+ * Set the app data for an EVP_CIPHER_CTX context.
+ *
+ * @param ctx the EVP_CIPHER_CTX to set the app data for
+ * @param data the app data to set for an EVP_CIPHER_CTX.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 void
 EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data)
 {
     ctx->app_data = data;
 }
 
+/**
+ * Initiate the EVP_CIPHER_CTX context to encrypt or decrypt data.
+ * Clean up with EVP_CIPHER_CTX_cleanup().
+ *
+ * @param ctx context to initiate
+ * @param c cipher to use.
+ * @param engine crypto engine to use, NULL to select default.
+ * @param key the crypto key to use, NULL will use the previous value.
+ * @param iv the IV to use, NULL will use the previous value.
+ * @param encp non zero will encrypt, -1 use the previous value.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *c, ENGINE *engine,
                  const void *key, const void *iv, int encp)
@@ -426,6 +799,17 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *c, ENGINE *engine,
     return 1;
 }
 
+/**
+ * Encypher/decypher data
+ *
+ * @param ctx the cipher context.
+ * @param out out data from the operation.
+ * @param in in data to the operation.
+ * @param size length of data.
+ *
+ * @return 1 on success.
+ */
+
 int
 EVP_Cipher(EVP_CIPHER_CTX *ctx, void *out, const void *in,size_t size)
 {
@@ -461,6 +845,14 @@ enc_null_cleanup(EVP_CIPHER_CTX *ctx)
     return 1;
 }
 
+/**
+ * The NULL cipher type, does no encryption/decryption.
+ *
+ * @return the null EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_enc_null(void)
 {
@@ -524,6 +916,13 @@ rc2_cleanup(EVP_CIPHER_CTX *ctx)
     return 1;
 }
 
+/**
+ * The RC2 cipher type
+ *
+ * @return the RC2 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
 
 const EVP_CIPHER *
 EVP_rc2_cbc(void)
@@ -546,6 +945,14 @@ EVP_rc2_cbc(void)
     return &rc2_cbc;
 }
 
+/**
+ * The RC2-40 cipher type
+ *
+ * @return the RC2-40 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_rc2_40_cbc(void)
 {
@@ -567,6 +974,14 @@ EVP_rc2_40_cbc(void)
     return &rc2_40_cbc;
 }
 
+/**
+ * The RC2-64 cipher type
+ *
+ * @return the RC2-64 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_rc2_64_cbc(void)
 {
@@ -588,8 +1003,12 @@ EVP_rc2_64_cbc(void)
     return &rc2_64_cbc;
 }
 
-/*
+/**
+ * The RC4 cipher type
  *
+ * @return the RC4 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
  */
 
 const EVP_CIPHER *
@@ -600,6 +1019,14 @@ EVP_rc4(void)
     return NULL;
 }
 
+/**
+ * The RC4-40 cipher type
+ *
+ * @return the RC4-40 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_rc4_40(void)
 {
@@ -651,6 +1078,14 @@ des_ede3_cbc_cleanup(EVP_CIPHER_CTX *ctx)
     return 1;
 }
 
+/**
+ * The tripple DES cipher type
+ *
+ * @return the DES-EDE3-CBC EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_des_ede3_cbc(void)
 {
@@ -708,6 +1143,14 @@ aes_cleanup(EVP_CIPHER_CTX *ctx)
     return 1;
 }
 
+/**
+ * The AES-128 cipher type
+ *
+ * @return the AES-128 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_aes_128_cbc(void)
 {
@@ -729,6 +1172,14 @@ EVP_aes_128_cbc(void)
     return &aes_128_cbc;
 }
 
+/**
+ * The AES-192 cipher type
+ *
+ * @return the AES-192 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 const EVP_CIPHER *
 EVP_aes_192_cbc(void)
 {
@@ -750,6 +1201,13 @@ EVP_aes_192_cbc(void)
     return &aes_192_cbc;
 }
 
+/**
+ * The AES-256 cipher type
+ *
+ * @return the AES-256 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
 
 const EVP_CIPHER *
 EVP_aes_256_cbc(void)
@@ -772,6 +1230,123 @@ EVP_aes_256_cbc(void)
     return &aes_256_cbc;
 }
 
+static int
+camellia_init(EVP_CIPHER_CTX *ctx,
+        const unsigned char * key,
+        const unsigned char * iv,
+        int encp)
+{
+    CAMELLIA_KEY *k = ctx->cipher_data;
+    k->bits = ctx->cipher->key_len * 8;
+    CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k);
+    return 1;
+}
+
+static int
+camellia_do_cipher(EVP_CIPHER_CTX *ctx,
+             unsigned char *out,
+             const unsigned char *in,
+             unsigned int size)
+{
+    CAMELLIA_KEY *k = ctx->cipher_data;
+    CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
+    return 1;
+}
+
+static int
+camellia_cleanup(EVP_CIPHER_CTX *ctx)
+{
+    memset(ctx->cipher_data, 0, sizeof(CAMELLIA_KEY));
+    return 1;
+}
+
+/**
+ * The Camellia-128 cipher type
+ *
+ * @return the Camellia-128 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
+const EVP_CIPHER *
+EVP_camellia_128_cbc(void)
+{
+    static const EVP_CIPHER cipher = {
+       0,
+       16,
+       16,
+       16,
+       EVP_CIPH_CBC_MODE,
+       camellia_init,
+       camellia_do_cipher,
+       camellia_cleanup,
+       sizeof(CAMELLIA_KEY),
+       NULL,
+       NULL,
+       NULL,
+       NULL
+    };
+    return &cipher;
+}
+
+/**
+ * The Camellia-198 cipher type
+ *
+ * @return the Camellia-198 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
+const EVP_CIPHER *
+EVP_camellia_192_cbc(void)
+{
+    static const EVP_CIPHER cipher = {
+       0,
+       16,
+       24,
+       16,
+       EVP_CIPH_CBC_MODE,
+       camellia_init,
+       camellia_do_cipher,
+       camellia_cleanup,
+       sizeof(CAMELLIA_KEY),
+       NULL,
+       NULL,
+       NULL,
+       NULL
+    };
+    return &cipher;
+}
+
+/**
+ * The Camellia-256 cipher type
+ *
+ * @return the Camellia-256 EVP_CIPHER pointer.
+ *
+ * @ingroup hcrypto_evp
+ */
+
+const EVP_CIPHER *
+EVP_camellia_256_cbc(void)
+{
+    static const EVP_CIPHER cipher = {
+       0,
+       16,
+       32,
+       16,
+       EVP_CIPH_CBC_MODE,
+       camellia_init,
+       camellia_do_cipher,
+       camellia_cleanup,
+       sizeof(CAMELLIA_KEY),
+       NULL,
+       NULL,
+       NULL,
+       NULL
+    };
+    return &cipher;
+}
+
 /*
  *
  */
@@ -783,9 +1358,21 @@ static const struct cipher_name {
     { "des-ede3-cbc", EVP_des_ede3_cbc },
     { "aes-128-cbc", EVP_aes_128_cbc },
     { "aes-192-cbc", EVP_aes_192_cbc },
-    { "aes-256-cbc", EVP_aes_256_cbc }
+    { "aes-256-cbc", EVP_aes_256_cbc },
+    { "camellia-128-cbc", EVP_camellia_128_cbc },
+    { "camellia-192-cbc", EVP_camellia_192_cbc },
+    { "camellia-256-cbc", EVP_camellia_256_cbc }
 };
 
+/**
+ * Get the cipher type using their name.
+ *
+ * @param name the name of the cipher.
+ *
+ * @return the selected EVP_CIPHER pointer or NULL if not found.
+ *
+ * @ingroup hcrypto_evp
+ */
 
 const EVP_CIPHER *
 EVP_get_cipherbyname(const char *name)
@@ -807,6 +1394,26 @@ EVP_get_cipherbyname(const char *name)
 #define min(a,b) (((a)>(b))?(b):(a))
 #endif
 
+/**
+ * Provides a legancy string to key function, used in PEM files.
+ *
+ * New protocols should use new string to key functions like NIST
+ * SP56-800A or PKCS#5 v2.0 (see PKCS5_PBKDF2_HMAC_SHA1()).
+ *
+ * @param type type of cipher to use
+ * @param md message digest to use
+ * @param salt salt salt string, should be an binary 8 byte buffer.
+ * @param data the password/input key string.
+ * @param datalen length of data parameter.
+ * @param count iteration counter.
+ * @param keydata output keydata, needs to of the size EVP_CIPHER_key_length().
+ * @param ivdata output ivdata, needs to of the size EVP_CIPHER_block_size().
+ *
+ * @return the size of derived key.
+ *
+ * @ingroup hcrypto_evp
+ */
+
 int
 EVP_BytesToKey(const EVP_CIPHER *type,
               const EVP_MD *md, 
@@ -886,8 +1493,10 @@ EVP_BytesToKey(const EVP_CIPHER *type,
     return EVP_CIPHER_key_length(type);
 }
 
-/*
+/**
+ * Add all algorithms to the crypto core.
  *
+ * @ingroup hcrypto_core
  */
 
 void
@@ -896,12 +1505,25 @@ OpenSSL_add_all_algorithms(void)
     return;
 }
 
+/**
+ * Add all algorithms to the crypto core using configuration file.
+ *
+ * @ingroup hcrypto_core
+ */
+
 void
 OpenSSL_add_all_algorithms_conf(void)
 {
     return;
 }
 
+/**
+ * Add all algorithms to the crypto core, but don't use the
+ * configuration file.
+ *
+ * @ingroup hcrypto_core
+ */
+
 void
 OpenSSL_add_all_algorithms_noconf(void)
 {
index a3fbc4c9cad0635f394b9649c15ed9d4d7bc41a2..4910ca01b8df87736e53e3fa079e6b6617e6f3cd 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-/* $Id: evp.h 18312 2006-10-07 17:21:48Z lha $ */
+/* $Id: evp.h 21687 2007-07-24 16:29:05Z lha $ */
 
 #ifndef HEIM_EVP_H
 #define HEIM_EVP_H 1
@@ -83,6 +83,9 @@
 #define EVP_rc2_cbc hc_EVP_rc2_cbc
 #define EVP_rc4 hc_EVP_rc4
 #define EVP_rc4_40 hc_EVP_rc4_40
+#define EVP_camellia_128_cbc hc_EVP_camellia_128_cbc
+#define EVP_camellia_192_cbc hc_EVP_camellia_192_cbc
+#define EVP_camellia_256_cbc hc_EVP_camellia_256_cbc
 #define EVP_sha hc_EVP_sha
 #define EVP_sha1 hc_EVP_sha1
 #define EVP_sha256 hc_EVP_sha256
@@ -180,6 +183,9 @@ const EVP_CIPHER * EVP_rc2_64_cbc(void);
 const EVP_CIPHER * EVP_rc2_cbc(void);
 const EVP_CIPHER * EVP_rc4(void);
 const EVP_CIPHER * EVP_rc4_40(void);
+const EVP_CIPHER * EVP_camellia_128_cbc(void);
+const EVP_CIPHER * EVP_camellia_192_cbc(void);
+const EVP_CIPHER * EVP_camellia_256_cbc(void);
 
 /*
  *
index 6c59758b11c65a2664706f14825b144c5aac5f18..d0433edef6dcc0d7254266428e5fdd8410cc96db 100644 (file)
@@ -1,6 +1,35 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+/*
+ * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden). 
+ * All rights reserved. 
+ *
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following conditions 
+ * are met: 
+ *
+ * 1. Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright 
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the distribution. 
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors 
+ *    may be used to endorse or promote products derived from this software 
+ *    without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE. 
+ */
 
 #include <sys/types.h>
 #include <stdio.h>
index 376425788b0efe50a62248ec31e2922a535e4b8c..4487029f78fdcb1df9d529cd251281a15fdeecb8 100755 (executable)
@@ -2,7 +2,7 @@
   Name:     imath.c
   Purpose:  Arbitrary precision integer arithmetic routines.
   Author:   M. J. Fromberger <http://www.dartmouth.edu/~sting/>
-  Info:     $Id: imath.c 20854 2007-06-03 18:04:10Z lha $
+  Info:     $Id: imath.c 22648 2008-02-25 07:37:57Z lha $
 
   Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
 
@@ -1769,7 +1769,7 @@ mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **e
     return MP_RANGE;
 
   /* Skip leading whitespace */
-  while(isspace((int)*str))
+  while(isspace((unsigned char)*str))
     ++str;
 
   /* Handle leading sign tag (+/-, positive default) */
@@ -3135,7 +3135,7 @@ static int       s_ch2val(char c, int r)
   if(isdigit((unsigned char) c))
     out = c - '0';
   else if(r > 10 && isalpha((unsigned char) c))
-    out = toupper(c) - 'A' + 10;
+      out = toupper((unsigned char)c) - 'A' + 10;
   else
     return -1;
 
index 248fdde620845ee583555c29afee3061edb07684..79dd39eb76609b197a5e50654ccad8f1e7d1eecb 100644 (file)
@@ -35,7 +35,7 @@
 #include <config.h>
 #endif
 
-RCSID("$Id: rand.c 21198 2007-06-20 05:10:41Z lha $");
+RCSID("$Id: rand.c 22199 2007-12-07 13:43:25Z lha $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -189,13 +189,12 @@ RAND_file_name(char *filename, size_t size)
                pathp = 1;
        }
     }
-    if (e == NULL) {
-       struct passwd *pw = getpwuid(getuid()); 
-       if (pw) {
-           e = pw->pw_dir;
-           pathp = 1;
-       }
-    }
+    /* 
+     * Here we really want to call getpwuid(getuid()) but this will
+     * cause recursive lookups if the nss library uses
+     * gssapi/krb5/hcrypto to authenticate to the ldap servers.
+     */
+
     if (e == NULL)
        return NULL;
 
index a7b4371e4d491b457b000c1b595d66a0cbf80766..270857d1759e9c1bbf6f6ddee2725a651cb7739c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
+ * Copyright (c) 2006 - 2008 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden). 
  * All rights reserved. 
  *
@@ -35,7 +35,7 @@
 #include <config.h>
 #endif
 
-RCSID("$Id: rsa.c 20466 2007-04-20 08:29:05Z lha $");
+RCSID("$Id: rsa.c 22422 2008-01-13 09:43:59Z lha $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -46,12 +46,41 @@ RCSID("$Id: rsa.c 20466 2007-04-20 08:29:05Z lha $");
 
 #include <roken.h>
 
+/**
+ * @page page_rsa RSA - public-key cryptography
+ *
+ * RSA is named by its inventors (Ron Rivest, Adi Shamir, and Leonard
+ * Adleman) (published in 1977), patented expired in 21 September 2000.
+ *
+ * See the library functions here: @ref hcrypto_rsa
+ */
+
+/**
+ * Same as RSA_new_method() using NULL as engine.
+ *
+ * @return a newly allocated RSA object. Free with RSA_free().
+ *
+ * @ingroup hcrypto_rsa
+ */
+
 RSA *
 RSA_new(void)
 {
     return RSA_new_method(NULL);
 }
 
+/**
+ * Allocate a new RSA object using the engine, if NULL is specified as
+ * the engine, use the default RSA engine as returned by
+ * ENGINE_get_default_RSA().
+ *
+ * @param engine Specific what ENGINE RSA provider should be used.
+ *
+ * @return a newly allocated RSA object. Free with RSA_free().
+ *
+ * @ingroup hcrypto_rsa
+ */
+
 RSA *
 RSA_new_method(ENGINE *engine)
 {
@@ -87,6 +116,12 @@ RSA_new_method(ENGINE *engine)
     return rsa;
 }
 
+/**
+ * Free an allocation RSA object.
+ *
+ * @param rsa the RSA object to free.
+ * @ingroup hcrypto_rsa
+ */
 
 void
 RSA_free(RSA *rsa)
@@ -117,18 +152,51 @@ RSA_free(RSA *rsa)
     free(rsa);
 }
 
+/**
+ * Add an extra reference to the RSA object. The object should be free
+ * with RSA_free() to drop the reference.
+ *
+ * @param rsa the object to add reference counting too.
+ *
+ * @return the current reference count, can't safely be used except
+ * for debug printing.
+ *
+ * @ingroup hcrypto_rsa
+ */
+
 int
 RSA_up_ref(RSA *rsa)
 {
     return ++rsa->references;
 }
 
+/**
+ * Return the RSA_METHOD used for this RSA object.
+ *
+ * @param rsa the object to get the method from.
+ *
+ * @return the method used for this RSA object.
+ *
+ * @ingroup hcrypto_rsa
+ */
+
 const RSA_METHOD *
 RSA_get_method(const RSA *rsa)
 {
     return rsa->meth;
 }
 
+/**
+ * Set a new method for the RSA keypair.
+ *
+ * @param rsa rsa parameter.
+ * @param method the new method for the RSA parameter.
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_rsa
+ */
+
 int
 RSA_set_method(RSA *rsa, const RSA_METHOD *method)
 {
@@ -144,6 +212,17 @@ RSA_set_method(RSA *rsa, const RSA_METHOD *method)
     return 1;
 }
 
+/**
+ * Set the application data for the RSA object.
+ *
+ * @param rsa the rsa object to set the parameter for
+ * @param arg the data object to store
+ *
+ * @return 1 on success.
+ *
+ * @ingroup hcrypto_rsa
+ */
+
 int
 RSA_set_app_data(RSA *rsa, void *arg)
 {
@@ -151,6 +230,16 @@ RSA_set_app_data(RSA *rsa, void *arg)
     return 1;
 }
 
+/**
+ * Get the application data for the RSA object.
+ *
+ * @param rsa the rsa object to get the parameter for
+ *
+ * @return the data object
+ *
+ * @ingroup hcrypto_rsa
+ */
+
 void *
 RSA_get_app_data(RSA *rsa)
 {
@@ -296,7 +385,11 @@ RSA_null_method(void)
 }
 
 extern const RSA_METHOD hc_rsa_imath_method;
+#ifdef HAVE_GMP
+static const RSA_METHOD *default_rsa_method = &hc_rsa_gmp_method;
+#else
 static const RSA_METHOD *default_rsa_method = &hc_rsa_imath_method;
+#endif
 
 const RSA_METHOD *
 RSA_get_default_method(void)
index 575774dbde8d8ec5b7e8dab50c0eeda1d273b8b8..0f54ca0a4dd0c4ac5105dc71de09269d24043eae 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 /*
- * $Id: rsa.h 19734 2007-01-05 20:26:23Z lha $
+ * $Id: rsa.h 22269 2007-12-11 10:59:22Z lha $
  */
 
 #ifndef _HEIM_RSA_H
@@ -41,6 +41,7 @@
 /* symbol renaming */
 #define RSA_null_method hc_RSA_null_method
 #define RSA_imath_method hc_RSA_imath_method
+#define RSA_gmp_method hc_RSA_gmp_method
 #define RSA_new hc_RSA_new
 #define RSA_new_method hc_RSA_new_method
 #define RSA_free hc_RSA_free
@@ -133,6 +134,7 @@ struct RSA {
 
 const RSA_METHOD *RSA_null_method(void);
 const RSA_METHOD *RSA_imath_method(void);
+const RSA_METHOD *RSA_gmp_method(void);
 
 /*
  *
diff --git a/source/heimdal/lib/hdb/dbinfo.c b/source/heimdal/lib/hdb/dbinfo.c
new file mode 100644 (file)
index 0000000..d43e31b
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2005 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden). 
+ * All rights reserved. 
+ *
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following conditions 
+ * are met: 
+ *
+ * 1. Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright 
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the distribution. 
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors 
+ *    may be used to endorse or promote products derived from this software 
+ *    without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE. 
+ */
+
+#include "hdb_locl.h"
+
+RCSID("$Id: dbinfo.c 22306 2007-12-14 12:22:38Z lha $");
+
+struct hdb_dbinfo {
+    char *label;
+    char *realm;
+    char *dbname;
+    char *mkey_file;
+    char *acl_file;
+    char *log_file;
+    const krb5_config_binding *binding;
+    struct hdb_dbinfo *next;
+};
+
+static int
+get_dbinfo(krb5_context context,
+          const krb5_config_binding *db_binding,
+          const char *label,
+          struct hdb_dbinfo **db)
+{
+    struct hdb_dbinfo *di;
+    const char *p;
+
+    *db = NULL;
+
+    p = krb5_config_get_string(context, db_binding, "dbname", NULL);
+    if(p == NULL)
+       return 0;
+
+    di = calloc(1, sizeof(*di));
+    if (di == NULL) {
+       krb5_set_error_string(context, "malloc: out of memory");
+       return ENOMEM;
+    }
+    di->label = strdup(label);
+    di->dbname = strdup(p);
+
+    p = krb5_config_get_string(context, db_binding, "realm", NULL);
+    if(p)
+       di->realm = strdup(p);
+    p = krb5_config_get_string(context, db_binding, "mkey_file", NULL);
+    if(p)
+       di->mkey_file = strdup(p);
+    p = krb5_config_get_string(context, db_binding, "acl_file", NULL);
+    if(p)
+       di->acl_file = strdup(p);
+    p = krb5_config_get_string(context, db_binding, "log_file", NULL);
+    if(p)
+       di->log_file = strdup(p);
+
+    di->binding = db_binding;
+
+    *db = di;
+    return 0;
+}
+
+
+int
+hdb_get_dbinfo(krb5_context context, struct hdb_dbinfo **dbp)
+{
+    const krb5_config_binding *db_binding;
+    struct hdb_dbinfo *di, **dt, *databases;
+    const char *default_dbname = HDB_DEFAULT_DB;
+    const char *default_mkey = HDB_DB_DIR "/m-key";
+    const char *default_acl = HDB_DB_DIR "/kadmind.acl";
+    const char *p;
+    int ret;
+
+    *dbp = NULL;
+    dt = NULL;
+    databases = NULL;
+
+    db_binding = krb5_config_get(context, NULL, krb5_config_list,
+                                "kdc", 
+                                "database",
+                                NULL);
+    if (db_binding) {
+
+       ret = get_dbinfo(context, db_binding, "default", &di);
+       if (ret == 0 && di) {
+           databases = di;
+           dt = &di->next;
+       }               
+
+       for ( ; db_binding != NULL; db_binding = db_binding->next) {
+
+           if (db_binding->type != krb5_config_list)
+               continue;
+
+           ret = get_dbinfo(context, db_binding->u.list, 
+                            db_binding->name, &di);
+           if (ret)
+               krb5_err(context, 1, ret, "failed getting realm");
+
+           if (di == NULL)
+               continue;
+
+           if (dt)
+               *dt = di;
+           else
+               databases = di;
+           dt = &di->next;
+
+       }
+    }
+
+    if(databases == NULL) {
+       /* if there are none specified, create one and use defaults */
+       di = calloc(1, sizeof(*di));
+       databases = di;
+       di->label = strdup("default");
+    }
+
+    for(di = databases; di; di = di->next) {
+       if(di->dbname == NULL) {
+           di->dbname = strdup(default_dbname);
+           if (di->mkey_file == NULL)
+               di->mkey_file = strdup(default_mkey);
+       }
+       if(di->mkey_file == NULL) {
+           p = strrchr(di->dbname, '.');
+           if(p == NULL || strchr(p, '/') != NULL)
+               /* final pathname component does not contain a . */
+               asprintf(&di->mkey_file, "%s.mkey", di->dbname);
+           else
+               /* the filename is something.else, replace .else with
+                   .mkey */
+               asprintf(&di->mkey_file, "%.*s.mkey", 
+                        (int)(p - di->dbname), di->dbname);
+       }
+       if(di->acl_file == NULL)
+           di->acl_file = strdup(default_acl);
+    }
+    *dbp = databases;
+    return 0;
+}
+
+
+struct hdb_dbinfo *
+hdb_dbinfo_get_next(struct hdb_dbinfo *dbp, struct hdb_dbinfo *dbprevp)
+{
+    if (dbprevp == NULL)
+       return dbp;
+    else
+       return dbprevp->next;
+}
+
+const char *
+hdb_dbinfo_get_label(krb5_context context, struct hdb_dbinfo *dbp)
+{
+    return dbp->label;
+}
+
+const char *
+hdb_dbinfo_get_realm(krb5_context context, struct hdb_dbinfo *dbp)
+{
+    return dbp->realm;
+}
+
+const char *
+hdb_dbinfo_get_dbname(krb5_context context, struct hdb_dbinfo *dbp)
+{
+    return dbp->dbname;
+}
+
+const char *
+hdb_dbinfo_get_mkey_file(krb5_context context, struct hdb_dbinfo *dbp)
+{
+    return dbp->mkey_file;
+}
+
+const char *
+hdb_dbinfo_get_acl_file(krb5_context context, struct hdb_dbinfo *dbp)
+{
+    return dbp->acl_file;
+}
+
+const char *
+hdb_dbinfo_get_log_file(krb5_context context, struct hdb_dbinfo *dbp)
+{
+    return dbp->log_file;
+}
+
+const krb5_config_binding *
+hdb_dbinfo_get_binding(krb5_context context, struct hdb_dbinfo *dbp)
+{
+    return dbp->binding;
+}
+
+void
+hdb_free_dbinfo(krb5_context context, struct hdb_dbinfo **dbp)
+{
+    struct hdb_dbinfo *di, *ndi;
+
+    for(di = *dbp; di != NULL; di = ndi) {
+       ndi = di->next;
+       free (di->realm);
+       free (di->dbname);
+       if (di->mkey_file)
+           free (di->mkey_file);
+       free(di);
+    }
+    *dbp = NULL;
+}
+
+/**
+ * Return the directory where the hdb database resides.
+ *
+ * @param context Kerberos 5 context.
+ *
+ * @return string pointing to directory.
+ */
+
+const char *
+hdb_db_dir(krb5_context context)
+{
+    return HDB_DB_DIR;
+}
+
+/**
+ * Return the default hdb database resides.
+ *
+ * @param context Kerberos 5 context.
+ *
+ * @return string pointing to directory.
+ */
+
+const char *
+hdb_default_db(krb5_context context)
+{
+    return HDB_DEFAULT_DB;
+}
index 6d679fd48f71c7132dfa960b6b97e72f269d83b8..4c3d3eb1ab14ecb47b1498cce96eb075b5c0dd44 100644 (file)
@@ -42,6 +42,9 @@ hdb_db_create (
        HDB **/*db*/,
        const char */*filename*/);
 
+const char *
+hdb_db_dir (krb5_context /*context*/);
+
 const char *
 hdb_dbinfo_get_acl_file (
        krb5_context /*context*/,
@@ -62,6 +65,11 @@ hdb_dbinfo_get_label (
        krb5_context /*context*/,
        struct hdb_dbinfo */*dbp*/);
 
+const char *
+hdb_dbinfo_get_log_file (
+       krb5_context /*context*/,
+       struct hdb_dbinfo */*dbp*/);
+
 const char *
 hdb_dbinfo_get_mkey_file (
        krb5_context /*context*/,
@@ -77,6 +85,9 @@ hdb_dbinfo_get_realm (
        krb5_context /*context*/,
        struct hdb_dbinfo */*dbp*/);
 
+const char *
+hdb_default_db (krb5_context /*context*/);
+
 krb5_error_code
 hdb_enctype2key (
        krb5_context /*context*/,
index 830589388f8a984da3405f899537cc3a8f37bebd..742b92405d45ed96ca329631f74a44a58c9be00f 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE. 
  */
 
-/* $Id: hdb.h 20535 2007-04-23 07:49:16Z lha $ */
+/* $Id: hdb.h 22198 2007-12-07 13:09:25Z lha $ */
 
 #ifndef __HDB_H__
 #define __HDB_H__
@@ -135,10 +135,6 @@ struct hdb_so_method {
     krb5_error_code (*create)(krb5_context, HDB **, const char *filename);
 };
 
-#define HDB_DB_DIR "/var/heimdal"
-#define HDB_DEFAULT_DB HDB_DB_DIR "/heimdal"
-#define HDB_DB_FORMAT_ENTRY "hdb/db-format"
-
 typedef krb5_error_code (*hdb_foreach_func_t)(krb5_context, HDB*,
                                              hdb_entry_ex*, void*);
 extern krb5_kt_ops hdb_kt_ops;
index ad16075b247fe91b4af367d04060e0e20e008911..8f9d6fc4c2b67bda61e14c52cfe013e28b3f41d6 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE. 
  */
 
-/* $Id: hdb_locl.h 12820 2003-09-10 21:54:58Z lha $ */
+/* $Id: hdb_locl.h 22209 2007-12-07 19:03:41Z lha $ */
 
 #ifndef __HDB_LOCL_H__
 #define __HDB_LOCL_H__
@@ -64,6 +64,9 @@
 #include <hdb.h>
 #include <hdb-private.h>
 
+#define HDB_DEFAULT_DB HDB_DB_DIR "/heimdal"
+#define HDB_DB_FORMAT_ENTRY "hdb/db-format"
+
 krb5_error_code
 hdb_ldb_create (
        krb5_context /*context*/,
index 9b870501201dccd40de18d11c8d13d5172ca9e99..60a58677fef99888d8e8c385619cbd438550a20d 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "hdb_locl.h"
 
-RCSID("$Id: keys.c 18819 2006-10-22 09:40:12Z lha $");
+RCSID("$Id: keys.c 22071 2007-11-14 20:04:50Z lha $");
 
 /*
  * free all the memory used by (len, keys)
@@ -105,7 +105,7 @@ parse_key_set(krb5_context context, const char *key,
     salt->saltvalue.length = 0;
 
     for(i = 0; i < num_buf; i++) {
-       if(enctypes == NULL) {
+       if(enctypes == NULL && num_buf > 1) {
            /* this might be a etype specifier */
            /* XXX there should be a string_to_etypes handling
               special cases like `des' and `all' */
@@ -124,7 +124,9 @@ parse_key_set(krb5_context context, const char *key,
                } else
                    return ret;
            }
-       } else if(salt->salttype == 0) {
+           continue;
+       }
+       if(salt->salttype == 0) {
            /* interpret string as a salt specifier, if no etype
               is set, this sets default values */
            /* XXX should perhaps use string_to_salttype, but that
@@ -142,7 +144,10 @@ parse_key_set(krb5_context context, const char *key,
                }
                salt->salttype = KRB5_AFS3_SALT;
            }
-       } else {
+           continue;
+       }
+
+       {
            /* if there is a final string, use it as the string to
               salt with, this is mostly useful with null salt for
               v4 compat, and a cell name for afs compat */
@@ -239,7 +244,7 @@ add_enctype_to_key_set(Key **key_set, size_t *nkeyset,
 /*
  * Generate the `key_set' from the [kadmin]default_keys statement. If
  * `no_salt' is set, salt is not important (and will not be set) since
- * its random keys that is going to be created.
+ * it's random keys that is going to be created.
  */
 
 krb5_error_code
index 02d87b6cf3efbd00560b1bc266e3cf2733504c1a..05cf71c59311c125d7bd09d1ed01f6d3667b69b5 100644 (file)
@@ -36,7 +36,7 @@
 #define O_BINARY 0
 #endif
 
-RCSID("$Id: mkey.c 17445 2006-05-05 10:37:46Z lha $");
+RCSID("$Id: mkey.c 21745 2007-07-31 16:11:25Z lha $");
 
 struct hdb_master_key_data {
     krb5_keytab_entry keytab;
@@ -129,6 +129,11 @@ read_master_keytab(krb5_context context, const char *filename,
     *mkey = NULL;
     while(krb5_kt_next_entry(context, id, &entry, &cursor) == 0) {
        p = calloc(1, sizeof(*p));
+       if(p == NULL) {
+           krb5_kt_end_seq_get(context, id, &cursor);
+           ret = ENOMEM;
+           goto out;
+       }
        p->keytab = entry;
        ret = krb5_crypto_init(context, &p->keytab.keyblock, 0, &p->crypto);
        p->next = *mkey;
index bf8fe1be1a4c91bc7bd16dc94d7df89139ef1049..40260700b3fa2f7f734e7be948dda673bb776362 100644 (file)
 
 #include "hx_locl.h"
 #include <pkinit_asn1.h>
-RCSID("$Id: ca.c 21379 2007-06-28 07:38:17Z lha $");
+RCSID("$Id: ca.c 22456 2008-01-15 20:22:53Z lha $");
+
+/**
+ * @page page_ca Hx509 CA functions
+ *
+ * See the library functions here: @ref hx509_ca
+ */
 
 struct hx509_ca_tbs {
     hx509_name subject;
@@ -55,6 +61,19 @@ struct hx509_ca_tbs {
     CRLDistributionPoints crldp;
 };
 
+/**
+ * Allocate an to-be-signed certificate object that will be converted
+ * into an certificate.
+ *
+ * @param context A hx509 context.
+ * @param tbs returned to-be-signed certicate object, free with
+ * hx509_ca_tbs_free().
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_init(hx509_context context, hx509_ca_tbs *tbs)
 {
@@ -74,6 +93,14 @@ hx509_ca_tbs_init(hx509_context context, hx509_ca_tbs *tbs)
     return 0;
 }
 
+/**
+ * Free an To Be Signed object.
+ *
+ * @param tbs object to free.
+ *
+ * @ingroup hx509_ca
+ */
+
 void
 hx509_ca_tbs_free(hx509_ca_tbs *tbs)
 {
@@ -93,6 +120,19 @@ hx509_ca_tbs_free(hx509_ca_tbs *tbs)
     *tbs = NULL;
 }
 
+/**
+ * Set the absolute time when the certificate is valid from. If not
+ * set the current time will be used.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param t time the certificated will start to be valid
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_notBefore(hx509_context context,
                           hx509_ca_tbs tbs,
@@ -102,6 +142,18 @@ hx509_ca_tbs_set_notBefore(hx509_context context,
     return 0;
 }
 
+/**
+ * Set the absolute time when the certificate is valid to.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param t time when the certificate will expire
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_notAfter(hx509_context context,
                           hx509_ca_tbs tbs,
@@ -111,6 +163,18 @@ hx509_ca_tbs_set_notAfter(hx509_context context,
     return 0;
 }
 
+/**
+ * Set the relative time when the certificiate is going to expire.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param delta seconds to the certificate is going to expire.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_notAfter_lifetime(hx509_context context,
                                   hx509_ca_tbs tbs,
@@ -130,12 +194,35 @@ static const struct units templatebits[] = {
     { NULL, 0 }
 };
 
+/**
+ * Make of template units, use to build flags argument to
+ * hx509_ca_tbs_set_template() with parse_units().
+ *
+ * @return an units structure.
+ *
+ * @ingroup hx509_ca
+ */
+
 const struct units *
 hx509_ca_tbs_template_units(void)
 {
     return templatebits;
 }
 
+/**
+ * Initialize the to-be-signed certificate object from a template certifiate.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param flags bit field selecting what to copy from the template
+ * certifiate.
+ * @param cert template certificate.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_template(hx509_context context,
                          hx509_ca_tbs tbs,
@@ -170,12 +257,10 @@ hx509_ca_tbs_set_template(hx509_context context,
        tbs->notAfter = hx509_cert_get_notAfter(cert);
     if (flags & HX509_CA_TEMPLATE_SPKI) {
        free_SubjectPublicKeyInfo(&tbs->spki);
-       ret = hx509_cert_get_SPKI(cert, &tbs->spki);
+       ret = hx509_cert_get_SPKI(context, cert, &tbs->spki);
        tbs->flags.key = !ret;
-       if (ret) {
-           hx509_set_error_string(context, 0, ret, "Failed to copy SPKI");
+       if (ret)
            return ret;
-       }
     }
     if (flags & HX509_CA_TEMPLATE_KU) {
        KeyUsage ku;
@@ -202,6 +287,20 @@ hx509_ca_tbs_set_template(hx509_context context,
     return 0;
 }
 
+/**
+ * Make the to-be-signed certificate object a CA certificate. If the
+ * pathLenConstraint is negative path length constraint is used.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param pathLenConstraint path length constraint, negative, no
+ * constraint.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_ca(hx509_context context,
                    hx509_ca_tbs tbs,
@@ -212,6 +311,20 @@ hx509_ca_tbs_set_ca(hx509_context context,
     return 0;
 }
 
+/**
+ * Make the to-be-signed certificate object a proxy certificate. If the
+ * pathLenConstraint is negative path length constraint is used.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param pathLenConstraint path length constraint, negative, no
+ * constraint.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_proxy(hx509_context context,
                       hx509_ca_tbs tbs,
@@ -223,6 +336,17 @@ hx509_ca_tbs_set_proxy(hx509_context context,
 }
 
 
+/**
+ * Make the to-be-signed certificate object a windows domain controller certificate.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_domaincontroller(hx509_context context,
                                  hx509_ca_tbs tbs)
@@ -231,6 +355,20 @@ hx509_ca_tbs_set_domaincontroller(hx509_context context,
     return 0;
 }
 
+/**
+ * Set the subject public key info (SPKI) in the to-be-signed certificate
+ * object. SPKI is the public key and key related parameters in the
+ * certificate.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param spki subject public key info to use for the to-be-signed certificate object.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_spki(hx509_context context,
                      hx509_ca_tbs tbs,
@@ -243,6 +381,19 @@ hx509_ca_tbs_set_spki(hx509_context context,
     return ret;
 }
 
+/**
+ * Set the serial number to use for to-be-signed certificate object.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param serialNumber serial number to use for the to-be-signed
+ * certificate object.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_set_serialnumber(hx509_context context,
                              hx509_ca_tbs tbs,
@@ -255,6 +406,19 @@ hx509_ca_tbs_set_serialnumber(hx509_context context,
     return ret;
 }
 
+/**
+ * An an extended key usage to the to-be-signed certificate object.
+ * Duplicates will detected and not added.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param oid extended key usage to add.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_add_eku(hx509_context context,
                     hx509_ca_tbs tbs,
@@ -285,6 +449,20 @@ hx509_ca_tbs_add_eku(hx509_context context,
     return 0;
 }
 
+/**
+ * Add CRL distribution point URI to the to-be-signed certificate
+ * object.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param uri uri to the CRL.
+ * @param issuername name of the issuer.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_add_crl_dp_uri(hx509_context context,
                            hx509_ca_tbs tbs,
@@ -325,6 +503,9 @@ hx509_ca_tbs_add_crl_dp_uri(hx509_context context,
 
     if (issuername) {
 #if 1
+       /**
+        * issuername not supported
+        */
        hx509_set_error_string(context, 0, EINVAL,
                               "CRLDistributionPoints.name.issuername not yet supported");
        return EINVAL;
@@ -372,6 +553,20 @@ out:
     return ret;
 }
 
+/**
+ * Add Subject Alternative Name otherName to the to-be-signed
+ * certificate object.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param oid the oid of the OtherName.
+ * @param os data in the other name.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_add_san_otherName(hx509_context context,
                               hx509_ca_tbs tbs,
@@ -388,6 +583,18 @@ hx509_ca_tbs_add_san_otherName(hx509_context context,
     return add_GeneralNames(&tbs->san, &gn);
 }
 
+/**
+ * Add Kerberos Subject Alternative Name to the to-be-signed
+ * certificate object. The principal string is a UTF8 string.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param principal Kerberos principal to add to the certificate.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
 
 int
 hx509_ca_tbs_add_san_pkinit(hx509_context context,
@@ -511,6 +718,19 @@ out:
     return ret;
 }
 
+/**
+ * Add Microsoft UPN Subject Alternative Name to the to-be-signed
+ * certificate object. The principal string is a UTF8 string.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param principal Microsoft UPN string.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_add_san_ms_upn(hx509_context context,
                            hx509_ca_tbs tbs,
@@ -519,6 +739,19 @@ hx509_ca_tbs_add_san_ms_upn(hx509_context context,
     return add_utf8_san(context, tbs, oid_id_pkinit_ms_san(), principal);
 }
 
+/**
+ * Add a Jabber/XMPP jid Subject Alternative Name to the to-be-signed
+ * certificate object. The jid is an UTF8 string.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param jid string of an a jabber id in UTF8.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_add_san_jid(hx509_context context,
                         hx509_ca_tbs tbs,
@@ -528,6 +761,22 @@ hx509_ca_tbs_add_san_jid(hx509_context context,
 }
 
 
+/**
+ * Add a Subject Alternative Name hostname to to-be-signed certificate
+ * object. A domain match starts with ., an exact match does not.
+ *
+ * Example of a an domain match: .domain.se matches the hostname
+ * host.domain.se.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param dnsname a hostame.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_add_san_hostname(hx509_context context,
                              hx509_ca_tbs tbs,
@@ -542,6 +791,19 @@ hx509_ca_tbs_add_san_hostname(hx509_context context,
     return add_GeneralNames(&tbs->san, &gn);
 }
 
+/**
+ * Add a Subject Alternative Name rfc822 (email address) to
+ * to-be-signed certificate object.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param rfc822Name a string to a email address.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_add_san_rfc822name(hx509_context context,
                                hx509_ca_tbs tbs,
@@ -556,6 +818,17 @@ hx509_ca_tbs_add_san_rfc822name(hx509_context context,
     return add_GeneralNames(&tbs->san, &gn);
 }
 
+/**
+ * Set the subject name of a to-be-signed certificate object.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param subject the name to set a subject.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
 
 int
 hx509_ca_tbs_set_subject(hx509_context context,
@@ -567,6 +840,20 @@ hx509_ca_tbs_set_subject(hx509_context context,
     return hx509_name_copy(context, subject, &tbs->subject);
 }
 
+/**
+ * Expand the the subject name in the to-be-signed certificate object
+ * using hx509_name_expand().
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param env enviroment variable to expand variables in the subject
+ * name, see hx509_env_init().
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_tbs_subject_expand(hx509_context context,
                            hx509_ca_tbs tbs,
@@ -1148,6 +1435,30 @@ out:
 }
 
 
+/**
+ * Sign a to-be-signed certificate object with a issuer certificate. 
+ *
+ * The caller needs to at least have called the following functions on the
+ * to-be-signed certificate object:
+ * - hx509_ca_tbs_init()
+ * - hx509_ca_tbs_set_subject()
+ * - hx509_ca_tbs_set_spki()
+ *
+ * When done the to-be-signed certificate object should be freed with
+ * hx509_ca_tbs_free().
+ *
+ * When creating self-signed certificate use hx509_ca_sign_self() instead.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param signer the CA certificate object to sign with (need private key).
+ * @param certificate return cerificate, free with hx509_cert_free().
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_sign(hx509_context context,
              hx509_ca_tbs tbs,
@@ -1179,6 +1490,19 @@ out:
     return ret;
 }
 
+/**
+ * Work just like hx509_ca_sign() but signs it-self.
+ *
+ * @param context A hx509 context.
+ * @param tbs object to be signed.
+ * @param signer private key to sign with.
+ * @param certificate return cerificate, free with hx509_cert_free().
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_ca
+ */
+
 int
 hx509_ca_sign_self(hx509_context context,
                   hx509_ca_tbs tbs,
index b7f19d152a9f5342685ac899642a2f6a3eb6f8da..09c85bc08413818cc4c9cd3cdf1937b940b326f1 100644 (file)
  */
 
 #include "hx_locl.h"
-RCSID("$Id: cert.c 21380 2007-06-28 07:38:38Z lha $");
+RCSID("$Id: cert.c 22583 2008-02-11 20:46:21Z lha $");
 #include "crypto-headers.h"
 #include <rtbl.h>
 
+/**
+ * @page page_cert The basic certificate
+ *
+ * The basic hx509 cerificate object in hx509 is hx509_cert. The
+ * hx509_cert object is representing one X509/PKIX certificate and
+ * associated attributes; like private key, friendly name, etc.
+ *
+ * A hx509_cert object is usully found via the keyset interfaces (@ref
+ * page_keyset), but its also possible to create a certificate
+ * directly from a parsed object with hx509_cert_init() and
+ * hx509_cert_init_data().
+ *
+ * See the library functions here: @ref hx509_cert
+ */
+
 struct hx509_verify_ctx_data {
     hx509_certs trust_anchors;
     int flags;
@@ -78,8 +93,16 @@ typedef struct hx509_name_constraints {
 #define GeneralSubtrees_SET(g,var) \
        (g)->len = (var)->len, (g)->val = (var)->val;
 
-/*
+/**
+ * Creates a hx509 context that most functions in the library
+ * uses. The context is only allowed to be used by one thread at each
+ * moment. Free the context with hx509_context_free().
  *
+ * @param context Returns a pointer to new hx509 context.
+ *
+ * @return Returns an hx509 error code.
+ *
+ * @ingroup hx509
  */
 
 int
@@ -113,6 +136,19 @@ hx509_context_init(hx509_context *context)
     return 0;
 }
 
+/**
+ * Selects if the hx509_revoke_verify() function is going to require
+ * the existans of a revokation method (OSCP, CRL) or not. Note that
+ * hx509_verify_path(), hx509_cms_verify_signed(), and other function
+ * call hx509_revoke_verify().
+ * 
+ * @param context hx509 context to change the flag for.
+ * @param flag zero, revokation method required, non zero missing
+ * revokation method ok
+ *
+ * @ingroup hx509_verify
+ */
+
 void
 hx509_context_set_missing_revoke(hx509_context context, int flag)
 {
@@ -122,6 +158,14 @@ hx509_context_set_missing_revoke(hx509_context context, int flag)
        context->flags &= ~HX509_CTX_VERIFY_MISSING_OK;
 }
 
+/**
+ * Free the context allocated by hx509_context_init().
+ * 
+ * @param context context to be freed.
+ *
+ * @ingroup hx509
+ */
+
 void
 hx509_context_free(hx509_context *context)
 {
@@ -139,7 +183,6 @@ hx509_context_free(hx509_context *context)
     *context = NULL;
 }
 
-
 /*
  *
  */
@@ -150,33 +193,6 @@ _hx509_get_cert(hx509_cert cert)
     return cert->data;
 }
 
-/*
- *
- */
-
-#if 0
-void
-_hx509_print_cert_subject(hx509_cert cert)
-{
-    char *subject_name;
-    hx509_name name;
-    int ret;
-
-    ret = hx509_cert_get_subject(cert, &name);
-    if (ret)
-       abort();
-       
-    ret = hx509_name_to_string(name, &subject_name);
-    hx509_name_free(&name);
-    if (ret)
-       abort();
-
-    printf("name: %s\n", subject_name);
-
-    free(subject_name);
-}
-#endif
-
 /*
  *
  */
@@ -187,6 +203,19 @@ _hx509_cert_get_version(const Certificate *t)
     return t->tbsCertificate.version ? *t->tbsCertificate.version + 1 : 1;
 }
 
+/**
+ * Allocate and init an hx509 certificate object from the decoded
+ * certificate `c´.
+ *
+ * @param context A hx509 context.
+ * @param c
+ * @param cert
+ *
+ * @return Returns an hx509 error code.
+ *
+ * @ingroup hx509_cert
+ */
+
 int
 hx509_cert_init(hx509_context context, const Certificate *c, hx509_cert *cert)
 {
@@ -218,9 +247,29 @@ hx509_cert_init(hx509_context context, const Certificate *c, hx509_cert *cert)
     return ret;
 }
 
+/**
+ * Just like hx509_cert_init(), but instead of a decode certificate
+ * takes an pointer and length to a memory region that contains a
+ * DER/BER encoded certificate.
+ *
+ * If the memory region doesn't contain just the certificate and
+ * nothing more the function will fail with
+ * HX509_EXTRA_DATA_AFTER_STRUCTURE.
+ *
+ * @param context A hx509 context.
+ * @param ptr pointer to memory region containing encoded certificate.
+ * @param len length of memory region.
+ * @param cert a return pointer to a hx509 certificate object, will
+ * contain NULL on error.
+ *
+ * @return An hx509 error code, see hx509_get_error_string().
+ *
+ * @ingroup hx509_cert
+ */
+
 int
 hx509_cert_init_data(hx509_context context, 
-            const void *ptr,
+                    const void *ptr,
                     size_t len,
                     hx509_cert *cert)
 {
@@ -265,6 +314,15 @@ _hx509_cert_assign_key(hx509_cert cert, hx509_private_key private_key)
     return 0;
 }
 
+/**
+ * Free reference to the hx509 certificate object, if the refcounter
+ * reaches 0, the object if freed. Its allowed to pass in NULL.
+ *
+ * @param cert the cert to free.
+ *
+ * @ingroup hx509_cert
+ */
+
 void
 hx509_cert_free(hx509_cert cert)
 {
@@ -274,7 +332,7 @@ hx509_cert_free(hx509_cert cert)
        return;
 
     if (cert->ref <= 0)
-       _hx509_abort("refcount <= 0");
+       _hx509_abort("cert refcount <= 0 on free");
     if (--cert->ref > 0)
        return;
 
@@ -300,9 +358,21 @@ hx509_cert_free(hx509_cert cert)
     free(cert);
 }
 
+/**
+ * Add a reference to a hx509 certificate object.
+ *
+ * @param cert a pointer to an hx509 certificate object.
+ *
+ * @return the same object as is passed in.
+ *
+ * @ingroup hx509_cert
+ */
+
 hx509_cert
 hx509_cert_ref(hx509_cert cert)
 {
+    if (cert == NULL)
+       return NULL;
     if (cert->ref <= 0)
        _hx509_abort("cert refcount <= 0");
     cert->ref++;
@@ -311,6 +381,18 @@ hx509_cert_ref(hx509_cert cert)
     return cert;
 }
 
+/**
+ * Allocate an verificati