]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/md5.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / md5.c
index 8989a93c597b2fb133c4e009b4f00fca5609a4b0..a62d937a3e02f9a1511b42814448849e404e85eb 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-3-Clause
 /*
  * Copyright (C) 2004 6WIND
  *                          <Vincent.Jardin@6WIND.com>
@@ -9,30 +10,6 @@
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  * 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 project 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 PROJECT 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 PROJECT 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 <zebra.h>
@@ -375,13 +352,8 @@ static void md5_calc(const uint8_t *b64, md5_ctxt *ctxt)
 }
 
 /* From RFC 2104 */
-void hmac_md5(text, text_len, key, key_len,
-             digest) unsigned char *text; /* pointer to data stream */
-int text_len;                             /* length of data stream */
-unsigned char *key;                       /* pointer to authentication key */
-int key_len;                              /* length of authentication key */
-uint8_t *digest;                          /* caller digest to be filled in */
-
+void hmac_md5(unsigned char *text, int text_len, unsigned char *key,
+             int key_len, uint8_t *digest)
 {
        MD5_CTX context;
        unsigned char k_ipad[65]; /* inner padding -
@@ -417,8 +389,8 @@ uint8_t *digest;                       /* caller digest to be filled in */
         */
 
        /* start out by storing key in pads */
-       bzero(k_ipad, sizeof k_ipad);
-       bzero(k_opad, sizeof k_opad);
+       bzero(k_ipad, sizeof(k_ipad));
+       bzero(k_opad, sizeof(k_opad));
        bcopy(key, k_ipad, key_len);
        bcopy(key, k_opad, key_len);
 
@@ -434,7 +406,7 @@ uint8_t *digest;                       /* caller digest to be filled in */
                                                * pass */
        MD5Update(&context, k_ipad, 64);       /* start with inner pad */
        MD5Update(&context, text, text_len);   /* then text of datagram */
-       MD5Final((uint8_t *)digest, &context); /* finish up 1st pass */
+       MD5Final(digest, &context); /* finish up 1st pass */
        /*
         * perform outer MD5
         */
@@ -443,5 +415,6 @@ uint8_t *digest;                       /* caller digest to be filled in */
        MD5Update(&context, k_opad, 64);       /* start with outer pad */
        MD5Update(&context, digest, 16);       /* then results of 1st
                                                * hash */
-       MD5Final((uint8_t *)digest, &context); /* finish up 2nd pass */
+       MD5Final(digest, &context); /* finish up 2nd pass */
+       explicit_bzero(&context, sizeof(context));
 }