[vlc-devel] [PATCH v3 08/14] rand: use new md5 API
Marvin Scholz
epirat07 at gmail.com
Wed Apr 8 16:10:18 CEST 2020
---
src/posix/rand.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/src/posix/rand.c b/src/posix/rand.c
index b2b724f771..1c258055b7 100644
--- a/src/posix/rand.c
+++ b/src/posix/rand.c
@@ -35,7 +35,7 @@
#include <pthread.h>
#include <vlc_fs.h>
-#include <vlc_md5.h>
+#include <vlc_hash.h>
/*
* Pseudo-random number generator using a HMAC-MD5 in counter mode.
@@ -83,33 +83,35 @@ void vlc_rand_bytes (void *buf, size_t len)
while (len > 0)
{
uint64_t val;
- struct md5_s mdi, mdo;
+ vlc_hash_md5_t mdi, mdo;
+ uint8_t mdi_buf[VLC_HASH_MD5_DIGEST_SIZE];
+ uint8_t mdo_buf[VLC_HASH_MD5_DIGEST_SIZE];
- InitMD5 (&mdi);
- InitMD5 (&mdo);
+ vlc_hash_md5_Init (&mdi);
+ vlc_hash_md5_Init (&mdo);
pthread_mutex_lock (&lock);
if (counter == 0)
vlc_rand_init ();
val = counter++;
- AddMD5 (&mdi, ikey, sizeof (ikey));
- AddMD5 (&mdo, okey, sizeof (okey));
+ vlc_hash_md5_Update (&mdi, ikey, sizeof (ikey));
+ vlc_hash_md5_Update (&mdo, okey, sizeof (okey));
pthread_mutex_unlock (&lock);
- AddMD5 (&mdi, &stamp, sizeof (stamp));
- AddMD5 (&mdi, &val, sizeof (val));
- EndMD5 (&mdi);
- AddMD5 (&mdo, mdi.buf, 16);
- EndMD5 (&mdo);
+ vlc_hash_md5_Update (&mdi, &stamp, sizeof (stamp));
+ vlc_hash_md5_Update (&mdi, &val, sizeof (val));
+ vlc_hash_md5_Finish (&mdi, mdi_buf, sizeof(mdi_buf));
+ vlc_hash_md5_Update (&mdo, mdi_buf, sizeof(mdi_buf));
+ vlc_hash_md5_Finish (&mdo, mdo_buf, sizeof(mdo_buf));
- if (len < 16)
+ if (len < sizeof(mdo_buf))
{
- memcpy (buf, mdo.buf, len);
+ memcpy (buf, mdo_buf, len);
break;
}
- memcpy (buf, mdo.buf, 16);
+ memcpy (buf, mdo_buf, sizeof(mdo_buf));
len -= 16;
buf = ((uint8_t *)buf) + 16;
}
--
2.24.1 (Apple Git-126)
More information about the vlc-devel
mailing list