]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/sha.c
tests/examples: Mark some variables only used within their files as static.
[ffmpeg] / libavutil / sha.c
index 38221a71642de2369c545053b2381e4cb400e900..5af742dc48f6cd20a46b8e98aa8d047753682037 100644 (file)
@@ -4,24 +4,24 @@
  * based on public domain SHA-1 code by Steve Reid <steve@edmweb.com>
  * and on BSD-licensed SHA-2 code by Aaron D. Gifford
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "common.h"
+#include <string.h>
 #include "avutil.h"
 #include "bswap.h"
 #include "sha.h"
@@ -42,7 +42,7 @@ const int av_sha_size = sizeof(AVSHA);
 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
 
 /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
-#define blk0(i) (block[i] = be2me_32(((const uint32_t*)buffer)[i]))
+#define blk0(i) (block[i] = AV_RB32(buffer + 4 * (i)))
 #define blk(i)  (block[i] = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1))
 
 #define R0(v,w,x,y,z,i) z += ((w&(x^y))^y)     + blk0(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30);
@@ -67,7 +67,7 @@ static void sha1_transform(uint32_t state[5], const uint8_t buffer[64])
     for (i = 0; i < 80; i++) {
         int t;
         if (i < 16)
-            t = be2me_32(((uint32_t*)buffer)[i]);
+            t = AV_RB32(buffer + 4 * i);
         else
             t = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1);
         block[i] = t;
@@ -313,39 +313,16 @@ void av_sha_update(AVSHA* ctx, const uint8_t* data, unsigned int len)
 void av_sha_final(AVSHA* ctx, uint8_t *digest)
 {
     int i;
-    uint64_t finalcount = be2me_64(ctx->count << 3);
+    uint64_t finalcount = av_be2ne64(ctx->count << 3);
 
     av_sha_update(ctx, "\200", 1);
     while ((ctx->count & 63) != 56)
         av_sha_update(ctx, "", 1);
     av_sha_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform() */
     for (i = 0; i < ctx->digest_len; i++)
-        AV_WN32(digest + i*4, be2me_32(ctx->state[i]));
+        AV_WB32(digest + i*4, ctx->state[i]);
 }
 
-#if LIBAVUTIL_VERSION_MAJOR < 51
-struct AVSHA1 {
-    AVSHA sha;
-};
-
-const int av_sha1_size = sizeof(struct AVSHA1);
-
-void av_sha1_init(struct AVSHA1* context)
-{
-    av_sha_init(&context->sha, 160);
-}
-
-void av_sha1_update(struct AVSHA1* context, const uint8_t* data, unsigned int len)
-{
-    av_sha_update(&context->sha, data, len);
-}
-
-void av_sha1_final(struct AVSHA1* context, uint8_t digest[20])
-{
-    av_sha_final(&context->sha, digest);
-}
-#endif
-
 #ifdef TEST
 #include <stdio.h>
 #undef printf