]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix data types
authorAlan T. DeKok <aland@freeradius.org>
Wed, 16 May 2012 09:19:23 +0000 (11:19 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 11 Jun 2012 10:14:17 +0000 (12:14 +0200)
unsigned char  --> uint8_t
unsigned short --> uint16_t

src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.c
src/modules/rlm_eap/types/rlm_eap_pwd/eap_pwd.h
src/modules/rlm_eap/types/rlm_eap_pwd/rlm_eap_pwd.c

index c1f786312d1e37432fe758138f6f2b955e977b30..030b2224c85427a17b8c65a805195a7b210e937c 100644 (file)
@@ -45,20 +45,20 @@ RCSID("$Id$")
 static void 
 H_Init(HMAC_CTX *ctx)
 {
-    unsigned char allzero[SHA256_DIGEST_LENGTH];
+    uint8_t allzero[SHA256_DIGEST_LENGTH];
 
     memset(allzero, 0, SHA256_DIGEST_LENGTH);
     HMAC_Init(ctx, allzero, SHA256_DIGEST_LENGTH, EVP_sha256());
 }
 
 static void 
-H_Update(HMAC_CTX *ctx, const unsigned char *data, int len)
+H_Update(HMAC_CTX *ctx, const uint8_t *data, int len)
 {
     HMAC_Update(ctx, data, len);
 }
 
 static void 
-H_Final(HMAC_CTX *ctx, unsigned char *digest)
+H_Final(HMAC_CTX *ctx, uint8_t *digest)
 {
     unsigned int mdlen = SHA256_DIGEST_LENGTH;
 
@@ -68,15 +68,15 @@ H_Final(HMAC_CTX *ctx, unsigned char *digest)
 
 /* a counter-based KDF based on NIST SP800-108 */
 static void 
-eap_pwd_kdf(unsigned char *key, int keylen, const char *label, int labellen,
-            unsigned char *result, int resultbitlen)
+eap_pwd_kdf(uint8_t *key, int keylen, const char *label, int labellen,
+            uint8_t *result, int resultbitlen)
 {
     HMAC_CTX hctx;
-    unsigned char digest[SHA256_DIGEST_LENGTH];
-    unsigned short i, ctr, L;
+    uint8_t digest[SHA256_DIGEST_LENGTH];
+    uint16_t i, ctr, L;
     int resultbytelen, len = 0;
     unsigned int mdlen = SHA256_DIGEST_LENGTH;
-    unsigned char mask = 0xff;
+    uint8_t mask = 0xff;
 
     resultbytelen = (resultbitlen + 7)/8;
     ctr = 0;
@@ -87,9 +87,9 @@ eap_pwd_kdf(unsigned char *key, int keylen, const char *label, int labellen,
         if (ctr > 1) {
             HMAC_Update(&hctx, digest, mdlen);
         }
-        HMAC_Update(&hctx, (unsigned char *) &i, sizeof(unsigned short));
-        HMAC_Update(&hctx, (const unsigned char *)label, labellen);
-        HMAC_Update(&hctx, (unsigned char *) &L, sizeof(unsigned short));
+        HMAC_Update(&hctx, (uint8_t *) &i, sizeof(uint16_t));
+        HMAC_Update(&hctx, (const uint8_t *)label, labellen);
+        HMAC_Update(&hctx, (uint8_t *) &L, sizeof(uint16_t));
         HMAC_Final(&hctx, digest, &mdlen);
         if ((len + (int) mdlen) > resultbytelen) {
             memcpy(result + len, digest, resultbytelen - len);
@@ -108,7 +108,7 @@ eap_pwd_kdf(unsigned char *key, int keylen, const char *label, int labellen,
 }
 
 int
-compute_password_element (pwd_session_t *sess, unsigned short grp_num,
+compute_password_element (pwd_session_t *sess, uint16_t grp_num,
                           char *password, int password_len,
                           char *id_server, int id_server_len,
                           char *id_peer, int id_peer_len, 
@@ -116,7 +116,7 @@ compute_password_element (pwd_session_t *sess, unsigned short grp_num,
 {
     BIGNUM *x_candidate = NULL, *rnd = NULL, *cofactor = NULL;
     HMAC_CTX ctx;
-    unsigned char pwe_digest[SHA256_DIGEST_LENGTH], *prfbuf = NULL, ctr;
+    uint8_t pwe_digest[SHA256_DIGEST_LENGTH], *prfbuf = NULL, ctr;
     int nid, is_odd, primebitlen, primebytelen, ret = 0;
 
     switch (grp_num) { /* from IANA registry for IKE D-H groups */
@@ -193,11 +193,11 @@ compute_password_element (pwd_session_t *sess, unsigned short grp_num,
          *                counter)
          */
         H_Init(&ctx);
-        H_Update(&ctx, (unsigned char *)token, sizeof(*token));
-        H_Update(&ctx, (unsigned char *)id_peer, id_peer_len);
-        H_Update(&ctx, (unsigned char *)id_server, id_server_len);
-        H_Update(&ctx, (unsigned char *)password, password_len);
-        H_Update(&ctx, (unsigned char *)&ctr, sizeof(ctr));
+        H_Update(&ctx, (uint8_t *)token, sizeof(*token));
+        H_Update(&ctx, (uint8_t *)id_peer, id_peer_len);
+        H_Update(&ctx, (uint8_t *)id_server, id_server_len);
+        H_Update(&ctx, (uint8_t *)password, password_len);
+        H_Update(&ctx, (uint8_t *)&ctr, sizeof(ctr));
         H_Final(&ctx, pwe_digest);
 
         BN_bin2bn(pwe_digest, SHA256_DIGEST_LENGTH, rnd);
@@ -329,9 +329,9 @@ fail:
 }
 
 int
-process_peer_commit (pwd_session_t *sess, unsigned char *commit, BN_CTX *bnctx)
+process_peer_commit (pwd_session_t *sess, uint8_t *commit, BN_CTX *bnctx)
 {
-    unsigned char *ptr;
+    uint8_t *ptr;
     BIGNUM *x = NULL, *y = NULL, *cofactor = NULL;
     EC_POINT *K = NULL, *point = NULL;
     int res = 1;
@@ -354,7 +354,7 @@ process_peer_commit (pwd_session_t *sess, unsigned char *commit, BN_CTX *bnctx)
     }
 
     /* element, x then y, followed by scalar */
-    ptr = (unsigned char *)commit;
+    ptr = (uint8_t *)commit;
     BN_bin2bn(ptr, BN_num_bytes(sess->prime), x);
     ptr += BN_num_bytes(sess->prime);
     BN_bin2bn(ptr, BN_num_bytes(sess->prime), y);
@@ -428,11 +428,11 @@ process_peer_commit (pwd_session_t *sess, unsigned char *commit, BN_CTX *bnctx)
 }
 
 int
-compute_server_confirm (pwd_session_t *sess, unsigned char *buf, BN_CTX *bnctx)
+compute_server_confirm (pwd_session_t *sess, uint8_t *buf, BN_CTX *bnctx)
 {
     BIGNUM *x = NULL, *y = NULL;
     HMAC_CTX ctx;
-    unsigned char *cruft = NULL;
+    uint8_t *cruft = NULL;
     int offset, req = -1;
 
     /* 
@@ -519,7 +519,7 @@ compute_server_confirm (pwd_session_t *sess, unsigned char *buf, BN_CTX *bnctx)
     /* 
      * finally, ciphersuite 
      */
-    H_Update(&ctx, (unsigned char *)&sess->ciphersuite, sizeof(sess->ciphersuite));
+    H_Update(&ctx, (uint8_t *)&sess->ciphersuite, sizeof(sess->ciphersuite));
 
     H_Final(&ctx, buf);
 
@@ -535,11 +535,11 @@ fin:
 }
 
 int
-compute_peer_confirm (pwd_session_t *sess, unsigned char *buf, BN_CTX *bnctx)
+compute_peer_confirm (pwd_session_t *sess, uint8_t *buf, BN_CTX *bnctx)
 {
     BIGNUM *x = NULL, *y = NULL;
     HMAC_CTX ctx;
-    unsigned char *cruft = NULL;
+    uint8_t *cruft = NULL;
     int offset, req = -1;
 
     /* 
@@ -626,7 +626,7 @@ compute_peer_confirm (pwd_session_t *sess, unsigned char *buf, BN_CTX *bnctx)
     /* 
      * finally, ciphersuite 
      */
-    H_Update(&ctx, (unsigned char *)&sess->ciphersuite, sizeof(sess->ciphersuite));
+    H_Update(&ctx, (uint8_t *)&sess->ciphersuite, sizeof(sess->ciphersuite));
 
     H_Final(&ctx, buf);
 
@@ -642,13 +642,13 @@ fin:
 }
 
 int
-compute_keys (pwd_session_t *sess, unsigned char *peer_confirm, 
-              unsigned char *msk, unsigned char *emsk)
+compute_keys (pwd_session_t *sess, uint8_t *peer_confirm, 
+              uint8_t *msk, uint8_t *emsk)
 {
     HMAC_CTX ctx;
-    unsigned char mk[SHA256_DIGEST_LENGTH], *cruft;
-    unsigned char session_id[SHA256_DIGEST_LENGTH + 1];
-    unsigned char msk_emsk[128];                /* 64 each */
+    uint8_t mk[SHA256_DIGEST_LENGTH], *cruft;
+    uint8_t session_id[SHA256_DIGEST_LENGTH + 1];
+    uint8_t msk_emsk[128];                /* 64 each */
     int offset;
 
     if ((cruft = malloc(BN_num_bytes(sess->prime))) == NULL) {
@@ -661,7 +661,7 @@ compute_keys (pwd_session_t *sess, unsigned char *peer_confirm,
      */
     session_id[0] = PW_EAP_PWD;
     H_Init(&ctx);
-    H_Update(&ctx, (unsigned char *)&sess->ciphersuite, sizeof(sess->ciphersuite));
+    H_Update(&ctx, (uint8_t *)&sess->ciphersuite, sizeof(sess->ciphersuite));
     offset = BN_num_bytes(sess->order) - BN_num_bytes(sess->peer_scalar);
     memset(cruft, 0, BN_num_bytes(sess->prime));
     BN_bn2bin(sess->peer_scalar, cruft + offset);
@@ -670,7 +670,7 @@ compute_keys (pwd_session_t *sess, unsigned char *peer_confirm,
     memset(cruft, 0, BN_num_bytes(sess->prime));
     BN_bn2bin(sess->my_scalar, cruft + offset);
     H_Update(&ctx, cruft, BN_num_bytes(sess->order));
-    H_Final(&ctx, (unsigned char *)&session_id[1]);
+    H_Final(&ctx, (uint8_t *)&session_id[1]);
 
     /* then compute MK = H(k | commit-peer | commit-server) */
     H_Init(&ctx);
index 20391c202d5ea637230ba578095f974acb6fa916..c4fe50fbcf689010126e640f69370d6da9418dd6 100644 (file)
@@ -44,12 +44,12 @@ RCSIDH(eap_pwd_h, "$Id$")
 #include <openssl/hmac.h>
 
 typedef struct _pwd_hdr {
-    unsigned char lm_exchange;
+    uint8_t lm_exchange;
 #define EAP_PWD_EXCH_ID                 1
 #define EAP_PWD_EXCH_COMMIT             2
 #define EAP_PWD_EXCH_CONFIRM            3
-//    unsigned short total_length;      /* there if the L-bit is set */
-    unsigned char data[0];
+//    uint16_t total_length;      /* there if the L-bit is set */
+    uint8_t data[0];
 } __attribute__ ((packed)) pwd_hdr;
 
 #define EAP_PWD_GET_LENGTH_BIT(x)       ((x)->lm_exchange & 0x80)
@@ -60,34 +60,34 @@ typedef struct _pwd_hdr {
 #define EAP_PWD_SET_EXCHANGE(x,y)       ((x)->lm_exchange |= (y))
 
 typedef struct _pwd_id_packet {
-    unsigned short group_num;
-    unsigned char random_function;
+    uint16_t group_num;
+    uint8_t random_function;
 #define EAP_PWD_DEF_RAND_FUN            1
-    unsigned char prf;
+    uint8_t prf;
 #define EAP_PWD_DEF_PRF                 1
-    unsigned char token[4];
-    unsigned char prep;
+    uint8_t token[4];
+    uint8_t prep;
 #define EAP_PWD_PREP_NONE               0
 #define EAP_PWD_PREP_MS                 1
 #define EAP_PWD_PREP_SASL               2
-    unsigned char identity[0];
+    uint8_t identity[0];
 } __attribute__ ((packed)) pwd_id_packet;
 
 typedef struct _pwd_session_t {
-    unsigned short state;
+    uint16_t state;
 #define PWD_STATE_ID_REQ                1
 #define PWD_STATE_COMMIT                2
 #define PWD_STATE_CONFIRM               3
-    unsigned short group_num;
+    uint16_t group_num;
     uint32_t ciphersuite;
     uint32_t token;
     char peer_id[MAX_STRING_LEN];
     int peer_id_len;
     int mtu;
-    unsigned char *in_buf;      /* reassembled fragments */
+    uint8_t *in_buf;      /* reassembled fragments */
     int in_buf_pos;
     int in_buf_len;
-    unsigned char *out_buf;     /* message to fragment */
+    uint8_t *out_buf;     /* message to fragment */
     int out_buf_pos;
     int out_buf_len;
     EC_GROUP *group;
@@ -100,22 +100,22 @@ typedef struct _pwd_session_t {
     BIGNUM *my_scalar;
     EC_POINT *my_element;
     EC_POINT *peer_element;
-    unsigned char my_confirm[SHA256_DIGEST_LENGTH];
+    uint8_t my_confirm[SHA256_DIGEST_LENGTH];
 } pwd_session_t;
 
-int compute_password_element(pwd_session_t *sess, unsigned short grp_num,
+int compute_password_element(pwd_session_t *sess, uint16_t grp_num,
                              char *password, int password_len,
                              char *id_server, int id_server_len,
                              char *id_peer, int id_peer_len, 
                              uint32_t *token);
 int compute_scalar_element(pwd_session_t *sess, BN_CTX *bnctx);
-int process_peer_commit (pwd_session_t *sess, unsigned char *commit, BN_CTX *bnctx);
-int compute_server_confirm(pwd_session_t *sess, unsigned char *buf, BN_CTX *bnctx);
-int compute_peer_confirm(pwd_session_t *sess, unsigned char *buf, BN_CTX *bnctx);
-int compute_keys(pwd_session_t *sess, unsigned char *peer_confirm,
-                 unsigned char *msk, unsigned char *emsk);
+int process_peer_commit (pwd_session_t *sess, uint8_t *commit, BN_CTX *bnctx);
+int compute_server_confirm(pwd_session_t *sess, uint8_t *buf, BN_CTX *bnctx);
+int compute_peer_confirm(pwd_session_t *sess, uint8_t *buf, BN_CTX *bnctx);
+int compute_keys(pwd_session_t *sess, uint8_t *peer_confirm,
+                 uint8_t *msk, uint8_t *emsk);
 #ifdef PRINTBUF
-void print_buf(char *str, unsigned char *buf, int len);
+void print_buf(char *str, uint8_t *buf, int len);
 #endif  /* PRINTBUF */
 
 #endif  /* _EAP_PWD_H */
index 0c79e76a9d8427ed5da00d0b0a59b7f793569c88..33b6d8ac8528c3a40f6e052970cf2bfcbed29d44 100644 (file)
@@ -158,7 +158,7 @@ static int
 send_pwd_request (pwd_session_t *sess, EAP_DS *eap_ds)
 {
     int len;
-    unsigned short totlen;
+    uint16_t totlen;
     pwd_hdr *hdr;
 
     len = (sess->out_buf_len - sess->out_buf_pos) + sizeof(pwd_hdr);
@@ -196,10 +196,10 @@ send_pwd_request (pwd_session_t *sess, EAP_DS *eap_ds)
             EAP_PWD_SET_LENGTH_BIT(hdr);
             totlen = ntohs(sess->out_buf_len);
             memcpy(hdr->data, (char *)&totlen, sizeof(totlen));
-            memcpy(hdr->data + sizeof(unsigned short),
+            memcpy(hdr->data + sizeof(uint16_t),
                    sess->out_buf,
-                   sess->mtu - sizeof(pwd_hdr) - sizeof(unsigned short));
-            sess->out_buf_pos += (sess->mtu - sizeof(pwd_hdr) - sizeof(unsigned short));
+                   sess->mtu - sizeof(pwd_hdr) - sizeof(uint16_t));
+            sess->out_buf_pos += (sess->mtu - sizeof(pwd_hdr) - sizeof(uint16_t));
         } else {
             /*
              * an intermediate fragment
@@ -329,9 +329,9 @@ eap_pwd_authenticate (void *arg, EAP_HANDLER *handler)
     EAP_DS *eap_ds;
     int len, ret = 0;
     eap_pwd_t *inst = (eap_pwd_t *)arg;
-    unsigned short offset;
-    unsigned char exch, *buf, *ptr, msk[MSK_EMSK_LEN], emsk[MSK_EMSK_LEN];
-    unsigned char peer_confirm[SHA256_DIGEST_LENGTH];
+    uint16_t offset;
+    uint8_t exch, *buf, *ptr, msk[MSK_EMSK_LEN], emsk[MSK_EMSK_LEN];
+    uint8_t peer_confirm[SHA256_DIGEST_LENGTH];
     BIGNUM *x = NULL, *y = NULL;
 
     if ((handler == NULL) || 
@@ -374,8 +374,8 @@ eap_pwd_authenticate (void *arg, EAP_HANDLER *handler)
         }
         memset(pwd_session->in_buf, 0, pwd_session->in_buf_len);
         pwd_session->in_buf_pos = 0;
-        buf += sizeof(unsigned short);
-        len -= sizeof(unsigned short);
+        buf += sizeof(uint16_t);
+        len -= sizeof(uint16_t);
     }
 
     /*
@@ -439,11 +439,11 @@ eap_pwd_authenticate (void *arg, EAP_HANDLER *handler)
             /*
              * we've agreed on the ciphersuite, record it...
              */
-            ptr = (unsigned char *)&pwd_session->ciphersuite;
-            memcpy(ptr, (char *)&id->group_num, sizeof(unsigned short));
-            ptr += sizeof(unsigned short);
+            ptr = (uint8_t *)&pwd_session->ciphersuite;
+            memcpy(ptr, (char *)&id->group_num, sizeof(uint16_t));
+            ptr += sizeof(uint16_t);
             *ptr = EAP_PWD_DEF_RAND_FUN;
-            ptr += sizeof(unsigned char);
+            ptr += sizeof(uint8_t);
             *ptr = EAP_PWD_DEF_PRF;
             
             pwd_session->peer_id_len = len - sizeof(pwd_id_packet);