[hipl-commit] [trunk] Rev 4324: Remove disabled code from hipd/keymat.c.

  • From: Diego Biurrun <diego@xxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Fri, 16 Apr 2010 21:42:01 +0300

Committer: Diego Biurrun <diego@xxxxxxxxxx>
Date: 16/04/2010 at 21:42:01
Revision: 4324
Revision-id: diego@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  Remove disabled code from hipd/keymat.c.

Modified:
  M  hipd/keymat.c

=== modified file 'hipd/keymat.c'
--- hipd/keymat.c       2010-04-15 20:47:19 +0000
+++ hipd/keymat.c       2010-04-16 18:41:45 +0000
@@ -146,7 +146,6 @@
 
     bufsize = kij_len + 2 * sizeof(struct in6_addr) +
               2 * sizeof(uint64_t) + 1;
-    //bufsize = kij_len+2*sizeof(struct in6_addr)+ 1;
 
     // XX FIXME: is this correct
     hip_build_digest(HIP_DIGEST_SHA1, shabuffer, bufsize, dstbuf);
@@ -242,152 +241,6 @@
     return err;
 }
 
-#if 0
-/**
- * Calculates new keying material.
- *
- * This function gets next @c key_len bytes of KEYMAT to @c key starting from
- * requested offset @c keymat_index. On entry of this function @c calc_index
- * tells the one byte index value which is related to @c calc_index_keymat (for
- * example, if @c calc_index_keymat is K3, then @c calc_index is 3).
- *
- * On successful return, @c keymat_index and @c calc_index contain the values
- * used in the last round of calculating Kn of KEYMAT, @c calc_index_keymat
- * contains the last Kn, and @c Kn_is_at contains the byte offset value of
- * @c calc_index_keymat.
- *
- * @param key               buffer where the created KEYMAT is stored.
- * @param key_len           length of @c key in bytes.
- * @param kij               shared key.
- * @param kij_len           length of @c kij in bytes.
- * @param keymat_index      keymat index.
- * @param calc_index        the one byte index value.
- * @param calc_index_keymat Kn.
- * @param Kn_is_at          the byte offset where @c calc_index_keymat starts.
- * @return                  0 on success, < 0 otherwise.
- */
-static int hip_keymat_get_new(void *key, size_t key_len, char *kij, size_t 
kij_len,
-                              uint16_t *keymat_index, uint8_t *calc_index,
-                              unsigned char *calc_index_keymat, uint16_t 
*Kn_is_at)
-{
-    /* must have the hadb lock when calling this function */
-    int err      = 0;
-    int copied   = 0;
-    uint8_t *tmp_data = NULL;
-    size_t tmp_data_len;
-
-    _HIP_DEBUG("key_len=%d, requested keymat_index=%u calc_index=%u 
Kn_is_at=%u\n",
-               key_len, *keymat_index, *calc_index, *Kn_is_at);
-    _HIP_HEXDUMP("calc_index_keymat", calc_index_keymat, HIP_AH_SHA_LEN);
-
-    if (key_len == 0 || kij_len == 0) {
-        HIP_ERROR("key_len = 0 or kij_len = 0\n");
-        err = -EINVAL;
-        goto out_err;
-    }
-
-    _HIP_DEBUG("one byte index at req'd index in the end should be %u\n",
-               (*keymat_index / HIP_AH_SHA_LEN + 1) % 256);
-
-    if (*keymat_index < *Kn_is_at) {
-        HIP_ERROR("requested keymat index %u is lower than lowest keymat index 
of Kn (%u)\n",
-                  *keymat_index, *Kn_is_at);
-        err = -EINVAL;
-        goto out_err;
-    }
-    /** @todo Check here if we have to test *keymat_index <
-     *  entry->current_keymat_index ? */
-
-    /* before calculating any hashes test if we already have
-     * needed amount of ready keymat
-     *
-     * must first check that the requested keymat_index is within the ready 
keymat
-     */
-    if (*keymat_index - *Kn_is_at < HIP_AH_SHA_LEN) {
-        int tmp = HIP_AH_SHA_LEN - (*keymat_index - *Kn_is_at);
-        _HIP_DEBUG("test: can copy %d bytes from the end of sha K\n", tmp);
-        if (tmp > HIP_AH_SHA_LEN) {
-            HIP_ERROR("bug: tmp > 20\n");
-            err = -EINVAL;
-            goto out_err;
-        }
-
-        if (tmp > 0) {
-            memcpy(key, calc_index_keymat + HIP_AH_SHA_LEN - tmp, tmp);
-            copied += tmp;
-        }
-    }
-
-    _HIP_DEBUG("copied=%d\n", copied);
-    _HIP_HEXDUMP("KEY (0)", key, copied);
-
-    if (copied == key_len) {
-        _HIP_DEBUG("copied all, return\n");
-        goto out;
-    }
-
-    _HIP_DEBUG("need %d bytes more data\n", key_len - copied);
-
-    tmp_data_len = kij_len + HIP_AH_SHA_LEN + 1;
-    tmp_data     = malloc(tmp_data_len);
-    if (!tmp_data) {
-        HIP_ERROR("malloc failed\n");
-        err = -ENOMEM;
-        goto out_err;
-    }
-
-    memcpy(tmp_data);     /* fixed part of every Kn round */
-
-    while (copied < key_len) {
-        (*calc_index)++;
-        _HIP_DEBUG("calc_index=%u\n", *calc_index);
-        /* create Kn = SHA-1( Kij | Kn-1 | calc_index) */
-
-        /* Kij | Kn-1 */
-        memcpy(tmp_data + kij_len, calc_index_keymat, HIP_AH_SHA_LEN);
-        /* Kij | Kn-1 | calc_index */
-        memcpy(tmp_data + kij_len + HIP_AH_SHA_LEN, calc_index, 
HIP_KEYMAT_INDEX_NBR_SIZE);
-        /* SHA-1( Kij | Kn-1 | calc_index) */
-        err = hip_build_digest(HIP_DIGEST_SHA1, tmp_data, tmp_data_len, 
calc_index_keymat);
-        if (err) {
-            HIP_ERROR("build_digest failed (K%u)\n", *calc_index);
-            goto out_err;
-        }
-        *Kn_is_at += HIP_AH_SHA_LEN;
-        if (*Kn_is_at + HIP_AH_SHA_LEN < *keymat_index) {
-            HIP_DEBUG("skip until we are at right offset\n");
-            continue;
-        }
-
-        _HIP_DEBUG("copied=%u, key_len=%u calc_index=%u dst to 0x%p\n", 
copied, key_len, *calc_index, key + copied);
-        if (copied + HIP_AH_SHA_LEN <= key_len) {
-            _HIP_DEBUG("copy whole sha block\n");
-            memcpy(key + copied, calc_index_keymat, HIP_AH_SHA_LEN);
-            copied += HIP_AH_SHA_LEN;
-        } else {
-            int t = HIP_AH_SHA_LEN - key_len % HIP_AH_SHA_LEN;
-            t       = key_len - copied;
-            _HIP_DEBUG("copy partial %d bytes\n", t);
-            memcpy(key + copied, calc_index_keymat, t);
-            copied += t;
-        }
-    }
-
-    _HIP_DEBUG("end: copied=%u\n", copied);
-
-out:
-    _HIP_HEXDUMP("CALCULATED KEY", key, key_len);
-    _HIP_DEBUG("at end: *keymat_index=%u *calc_index=%u\n",
-               *keymat_index, *calc_index);
-out_err:
-    if (tmp_data) {
-        free(tmp_data);
-    }
-    return err;
-}
-
-#endif
-
 /** hip_update_entry_keymat - update HADB's KEYMAT related information
  * @param entry HADB entry to be update
  * @param new_keymat_index new Keymat Index value

Other related posts:

  • » [hipl-commit] [trunk] Rev 4324: Remove disabled code from hipd/keymat.c. - Diego Biurrun