]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Formatting in HMAC functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 7 Jan 2019 11:23:32 +0000 (19:23 +0800)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 7 Jan 2019 14:21:11 +0000 (22:21 +0800)
src/lib/util/hmac_md5.c
src/lib/util/hmac_sha1.c
src/lib/util/sha1.c
src/lib/util/sha1.h

index 789f2094024fdbbadf6cdbdcbadb22abed4ce0e0..d8a46eed10e370d49b87cbb2c4b7b3c7f52b1ccf 100644 (file)
@@ -89,7 +89,7 @@ void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *in, size_t in
 void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
                 uint8_t const *key, size_t key_len)
 {
-       FR_MD5_CTX conin;
+       FR_MD5_CTX ctx;
        uint8_t k_ipad[65];    /* inner padding - key XORd with ipad */
        uint8_t k_opad[65];    /* outer padding - key XORd with opad */
        uint8_t tk[16];
@@ -133,20 +133,20 @@ void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *in, size_t in
        /*
         * perform inner MD5
         */
-       fr_md5_init(&conin);               /* init conin for 1st
+       fr_md5_init(&ctx);                 /* init ctx for 1st
                                              * pass */
-       fr_md5_update(&conin, k_ipad, 64);      /* start with inner pad */
-       fr_md5_update(&conin, in, inlen); /* then in of datagram */
-       fr_md5_final(digest, &conin);     /* finish up 1st pass */
+       fr_md5_update(&ctx, k_ipad, 64);      /* start with inner pad */
+       fr_md5_update(&ctx, in, inlen); /* then in of datagram */
+       fr_md5_final(digest, &ctx);       /* finish up 1st pass */
        /*
         * perform outer MD5
         */
-       fr_md5_init(&conin);               /* init conin for 2nd
+       fr_md5_init(&ctx);                 /* init ctx for 2nd
                                              * pass */
-       fr_md5_update(&conin, k_opad, 64);     /* start with outer pad */
-       fr_md5_update(&conin, digest, 16);     /* then results of 1st
+       fr_md5_update(&ctx, k_opad, 64);     /* start with outer pad */
+       fr_md5_update(&ctx, digest, 16);     /* then results of 1st
                                              * hash */
-       fr_md5_final(digest, &conin);     /* finish up 2nd pass */
+       fr_md5_final(digest, &ctx);       /* finish up 2nd pass */
 }
 #endif /* HAVE_OPENSSL_EVP_H */
 
index 7e4d91407db8101c66bde1bdc9e33ca6363683d4..d273756e674857f5a0047481c707d2a8cc622865 100644 (file)
@@ -52,13 +52,13 @@ static void _hmac_sha1_ctx_free_on_exit(void *arg)
 /** Calculate HMAC using OpenSSL's SHA1 implementation
  *
  * @param digest Caller digest to be filled in.
- * @param text Pointer to data stream.
- * @param text_len length of data stream.
+ * @param in Pointer to data stream.
+ * @param inlen length of data stream.
  * @param key Pointer to authentication key.
  * @param key_len Length of authentication key.
 
  */
-void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
+void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
                  uint8_t const *key, size_t key_len)
 {
        HMAC_CTX *ctx;
@@ -72,25 +72,23 @@ void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_
        }
 
        HMAC_Init_ex(ctx, key, key_len, EVP_sha1(), NULL);
-       HMAC_Update(ctx, text, text_len);
+       HMAC_Update(ctx, in, inlen);
        HMAC_Final(ctx, digest, NULL);
        HMAC_CTX_reset(ctx);
 }
-
 #else
-
 /** Calculate HMAC using internal SHA1 implementation
  *
  * @param digest Caller digest to be filled in.
- * @param text Pointer to data stream.
- * @param text_len length of data stream.
+ * @param in Pointer to data stream.
+ * @param inlen length of data stream.
  * @param key Pointer to authentication key.
  * @param key_len Length of authentication key.
  */
-void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
+void fr_hmac_sha1(uint8_t digest[static SHA1_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
                  uint8_t const *key, size_t key_len)
 {
-       fr_sha1_ctx context;
+       fr_sha1_ctx ctx;
        uint8_t k_ipad[65];    /* inner padding - key XORd with ipad */
        uint8_t k_opad[65];    /* outer padding - key XORd with opad */
        uint8_t tk[20];
@@ -124,10 +122,10 @@ void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_
 
                        printf("%02x", key[i]);
                }
-               printf("\nDATA: (%d)    ",text_len);
+               printf("\nDATA: (%d)    ",inlen);
 
                j=0; k=0;
-               for (i = 0; i < text_len; i++) {
+               for (i = 0; i < inlen; i++) {
                  if(k==20) {
                    printf("\n      ");
                    k=0;
@@ -140,7 +138,7 @@ void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_
                  k++;
                  j++;
 
-                 printf("%02x", text[i]);
+                 printf("%02x", in[i]);
                }
                printf("\n");
        }
@@ -150,13 +148,13 @@ void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_
        /*
         * the HMAC_SHA1 transform looks like:
         *
-        * SHA1(K XOR opad, SHA1(K XOR ipad, text))
+        * SHA1(K XOR opad, SHA1(K XOR ipad, in))
         *
         * where K is an n byte key
         * ipad is the byte 0x36 repeated 64 times
 
         * opad is the byte 0x5c repeated 64 times
-        * and text is the data being protected
+        * and in is the data being protected
         */
 
        /* start out by storing key in pads */
@@ -173,17 +171,17 @@ void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_
        /*
         * perform inner SHA1
         */
-       fr_sha1_init(&context);                         /* init context for 1st pass */
-       fr_sha1_update(&context, k_ipad, 64);           /* start with inner pad */
-       fr_sha1_update(&context, text, text_len);       /* then text of datagram */
-       fr_sha1_final(digest, &context);                /* finish up 1st pass */
+       fr_sha1_init(&ctx);                             /* init ctx for 1st pass */
+       fr_sha1_update(&ctx, k_ipad, 64);               /* start with inner pad */
+       fr_sha1_update(&ctx, in, inlen);        /* then in of datagram */
+       fr_sha1_final(digest, &ctx);            /* finish up 1st pass */
        /*
         * perform outer SHA1
         */
-       fr_sha1_init(&context);                         /* init context for 2nd pass */
-       fr_sha1_update(&context, k_opad, 64);           /* start with outer pad */
-       fr_sha1_update(&context, digest, 20);           /* then results of 1st hash */
-       fr_sha1_final(digest, &context);                /* finish up 2nd pass */
+       fr_sha1_init(&ctx);                             /* init ctx for 2nd pass */
+       fr_sha1_update(&ctx, k_opad, 64);               /* start with outer pad */
+       fr_sha1_update(&ctx, digest, 20);               /* then results of 1st hash */
+       fr_sha1_final(digest, &ctx);            /* finish up 2nd pass */
 
 #ifdef HMAC_SHA1_DATA_PROBLEMS
        if (sha1_data_problems) {
index f9d0601dfe4b80386d1bedc0fabd2c5819b318e0..a5f24fa8e9e888f383a9d1037d10ccd39648923a 100644 (file)
@@ -103,7 +103,7 @@ void fr_sha1_init(fr_sha1_ctx* context)
 }
 
 /* Run your data through this. */
-void fr_sha1_update(fr_sha1_ctx *context,uint8_t const *data, size_t len)
+void fr_sha1_update(fr_sha1_ctx *context, uint8_t const *data, size_t len)
 {
        unsigned int i, j;
 
@@ -129,7 +129,7 @@ void fr_sha1_update(fr_sha1_ctx *context,uint8_t const *data, size_t len)
 
 /* Add padding and return the message digest. */
 
-void fr_sha1_final(uint8_t digest[static 20], fr_sha1_ctx *context)
+void fr_sha1_final(uint8_t digest[static SHA1_DIGEST_LENGTH], fr_sha1_ctx *context)
 {
        uint32_t i, j;
        uint8_t finalcount[8];
@@ -162,7 +162,7 @@ void fr_sha1_final(uint8_t digest[static 20], fr_sha1_ctx *context)
 #  endif
 }
 
-void fr_sha1_final_no_len(uint8_t digest[static 20], fr_sha1_ctx *context)
+void fr_sha1_final_no_len(uint8_t digest[static SHA1_DIGEST_LENGTH], fr_sha1_ctx *context)
 {
        uint32_t i, j;
 
index ce6cbe0a54453453336de7caadf320ce49197248..fb8645135b426eaea7d35dd74f3d736ea9f48d5e 100644 (file)
@@ -38,13 +38,13 @@ typedef struct {
 void fr_sha1_transform(uint32_t state[static 5], uint8_t const buffer[static 64]);
 void fr_sha1_init(fr_sha1_ctx *context);
 void fr_sha1_update(fr_sha1_ctx *context, uint8_t const *data, size_t len);
-void fr_sha1_final(uint8_t digest[static 20], fr_sha1_ctx *context);
+void fr_sha1_final(uint8_t digest[static SHA1_DIGEST_LENGTH], fr_sha1_ctx *context);
 
 /*
  * this version implements a raw SHA1 transform, no length is appended,
  * nor any 128s out to the block size.
  */
-void fr_sha1_final_no_len(uint8_t digest[static 20], fr_sha1_ctx* context);
+void fr_sha1_final_no_len(uint8_t digest[static SHA1_DIGEST_LENGTH], fr_sha1_ctx* context);
 
 #else  /* WITH_OPENSSL_SHA1 */
 USES_APPLE_DEPRECATED_API
@@ -57,7 +57,7 @@ USES_APPLE_DEPRECATED_API
 
 /* hmacsha1.c */
 
-void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
+void fr_hmac_sha1(uint8_t digest[static SHA1_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
                  uint8_t const *key, size_t key_len);
 
 #ifdef __cplusplus