]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Use existing triplet length definitions
authorMartin Willi <martin@strongswan.org>
Thu, 22 Oct 2009 11:57:37 +0000 (13:57 +0200)
committerMartin Willi <martin@strongswan.org>
Thu, 12 Nov 2009 09:33:59 +0000 (10:33 +0100)
src/charon/plugins/eap_sim/eap_sim_peer.c
src/charon/plugins/eap_sim/eap_sim_server.c

index 1ad669856a25fce1cbc05706551e88915b497c10..c394106a4c20f4555c79efe23ceacd99afa2e531 100644 (file)
 
 /** length of the AT_NONCE_MT/AT_NONCE_S nonce value */
 #define NONCE_LEN 16
-/** length of the AT_MAC value */
-#define MAC_LEN 16
-/** length of the AT_RAND value */
-#define RAND_LEN 16
-/** length of Kc */
-#define KC_LEN 8
-/** length of SRES */
-#define SRES_LEN 4
 
 typedef struct private_eap_sim_peer_t private_eap_sim_peer_t;
 
@@ -240,8 +232,8 @@ static status_t process_challenge(private_eap_sim_peer_t *this,
 
        /* excepting two or three RAND, each 16 bytes. We require two valid
         * and different RANDs */
-       if ((rands.len != 2 * RAND_LEN && rands.len != 3 * RAND_LEN) ||
-               memeq(rands.ptr, rands.ptr + RAND_LEN, RAND_LEN))
+       if ((rands.len != 2 * SIM_RAND_LEN && rands.len != 3 * SIM_RAND_LEN) ||
+               memeq(rands.ptr, rands.ptr + SIM_RAND_LEN, SIM_RAND_LEN))
        {
                DBG1(DBG_IKE, "no valid AT_RAND received");
                *out = create_client_error(this, in->get_identifier(in),
@@ -251,7 +243,7 @@ static status_t process_challenge(private_eap_sim_peer_t *this,
        /* get two or three KCs/SRESes from SIM using RANDs */
        kcs = kc = chunk_alloca(rands.len / 2);
        sreses = sres = chunk_alloca(rands.len / 4);
-       while (rands.len >= RAND_LEN)
+       while (rands.len >= SIM_RAND_LEN)
        {
                if (!get_card_triplet(this, rands.ptr, sres.ptr, kc.ptr))
                {
@@ -261,10 +253,10 @@ static status_t process_challenge(private_eap_sim_peer_t *this,
                        return NEED_MORE;
                }
                DBG3(DBG_IKE, "got triplet for RAND %b\n  Kc %b\n  SRES %b",
-                        rands.ptr, RAND_LEN, sres.ptr, SRES_LEN, kc.ptr, KC_LEN);
-               kc = chunk_skip(kc, KC_LEN);
-               sres = chunk_skip(sres, SRES_LEN);
-               rands = chunk_skip(rands, RAND_LEN);
+                        rands.ptr, SIM_RAND_LEN, sres.ptr, SIM_SRES_LEN, kc.ptr, SIM_KC_LEN);
+               kc = chunk_skip(kc, SIM_KC_LEN);
+               sres = chunk_skip(sres, SIM_SRES_LEN);
+               rands = chunk_skip(rands, SIM_RAND_LEN);
        }
 
        data = chunk_cata("cccc", kcs, this->nonce, this->version_list, version);
index 4ad5558f4556b022e5ce51cb065ea8b1482a5da3..82ed1e0932ced1c2ff8e8c924d7687771f532b33 100644 (file)
 /* number of triplets for one authentication */
 #define TRIPLET_COUNT 3
 
-/** length of the AT_MAC value */
-#define MAC_LEN 16
-/** length of the AT_RAND value */
-#define RAND_LEN 16
-/** length of Kc */
-#define KC_LEN 8
-/** length of SRES */
-#define SRES_LEN 4
-
 typedef struct private_eap_sim_server_t private_eap_sim_server_t;
 
 /**
@@ -144,9 +135,9 @@ static status_t process_start(private_eap_sim_server_t *this,
        }
 
        /* read triplets from provider */
-       rand = rands = chunk_alloca(RAND_LEN * TRIPLET_COUNT);
-       kc = kcs = chunk_alloca(KC_LEN * TRIPLET_COUNT);
-       sres = sreses = chunk_alloca(SRES_LEN * TRIPLET_COUNT);
+       rand = rands = chunk_alloca(SIM_RAND_LEN * TRIPLET_COUNT);
+       kc = kcs = chunk_alloca(SIM_KC_LEN * TRIPLET_COUNT);
+       sres = sreses = chunk_alloca(SIM_SRES_LEN * TRIPLET_COUNT);
        rands.len = kcs.len = sreses.len = 0;
        for (i = 0; i < TRIPLET_COUNT; i++)
        {
@@ -155,12 +146,12 @@ static status_t process_start(private_eap_sim_server_t *this,
                        DBG1(DBG_IKE, "getting EAP-SIM triplet %d failed", i);
                        return FAILED;
                }
-               rands.len += RAND_LEN;
-               sreses.len += SRES_LEN;
-               kcs.len += KC_LEN;
-               rand = chunk_skip(rand, RAND_LEN);
-               sres = chunk_skip(sres, SRES_LEN);
-               kc = chunk_skip(kc, KC_LEN);
+               rands.len += SIM_RAND_LEN;
+               sreses.len += SIM_SRES_LEN;
+               kcs.len += SIM_KC_LEN;
+               rand = chunk_skip(rand, SIM_RAND_LEN);
+               sres = chunk_skip(sres, SIM_SRES_LEN);
+               kc = chunk_skip(kc, SIM_KC_LEN);
        }
        free(this->sreses.ptr);
        this->sreses = chunk_clone(sreses);