summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorEmil Velikov <[email protected]>2017-01-24 21:21:09 +0000
committerEmil Velikov <[email protected]>2017-03-15 11:18:43 +0000
commita9a4028fd7136ee2ee7bf0efa8179e7a6312f008 (patch)
tree453980dcab1abb0de018129f4b6a5fd6de8f8218 /src/util
parentc96127e873584e6ea3808d5cdb661d2135de1ff2 (diff)
util/sha1: rework _mesa_sha1_{init,final}
Rather than having an extra memory allocation [that we currently do not and act accordingly] just make the API take an pointer to a stack allocated instance. This and follow-up steps will effectively make the _mesa_sha1_foo simple define/inlines around their SHA1 counterparts. Signed-off-by: Emil Velikov <[email protected]> Reviewed-by: Grazvydas Ignotas <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mesa-sha1.c34
-rw-r--r--src/util/mesa-sha1.h13
2 files changed, 13 insertions, 34 deletions
diff --git a/src/util/mesa-sha1.c b/src/util/mesa-sha1.c
index e8f1bad22f0..eb882e8bd00 100644
--- a/src/util/mesa-sha1.c
+++ b/src/util/mesa-sha1.c
@@ -27,45 +27,21 @@
#include "sha1/sha1.h"
#include "mesa-sha1.h"
-struct mesa_sha1 *
-_mesa_sha1_init(void)
-{
- SHA1_CTX *ctx = malloc(sizeof(*ctx));
-
- if (!ctx)
- return NULL;
-
- SHA1Init(ctx);
- return (struct mesa_sha1 *) ctx;
-}
-
int
_mesa_sha1_update(struct mesa_sha1 *ctx, const void *data, int size)
{
- SHA1_CTX *sha1_ctx = (SHA1_CTX *) ctx;
-
- SHA1Update(sha1_ctx, data, size);
- return 1;
-}
-
-int
-_mesa_sha1_final(struct mesa_sha1 *ctx, unsigned char result[20])
-{
- SHA1_CTX *sha1_ctx = (SHA1_CTX *) ctx;
-
- SHA1Final(result, sha1_ctx);
- free(sha1_ctx);
+ SHA1Update(ctx, data, size);
return 1;
}
void
_mesa_sha1_compute(const void *data, size_t size, unsigned char result[20])
{
- struct mesa_sha1 *ctx;
+ struct mesa_sha1 ctx;
- ctx = _mesa_sha1_init();
- _mesa_sha1_update(ctx, data, size);
- _mesa_sha1_final(ctx, result);
+ _mesa_sha1_init(&ctx);
+ _mesa_sha1_update(&ctx, data, size);
+ _mesa_sha1_final(&ctx, result);
}
char *
diff --git a/src/util/mesa-sha1.h b/src/util/mesa-sha1.h
index 0be5485f313..f927d5772db 100644
--- a/src/util/mesa-sha1.h
+++ b/src/util/mesa-sha1.h
@@ -24,21 +24,24 @@
#define SHA1_H
#include <stdlib.h>
+#include "sha1/sha1.h"
#ifdef __cplusplus
extern "C" {
#endif
-struct mesa_sha1;
+#define mesa_sha1 _SHA1_CTX
-struct mesa_sha1 *
-_mesa_sha1_init(void);
+#define _mesa_sha1_init SHA1Init
int
_mesa_sha1_update(struct mesa_sha1 *ctx, const void *data, int size);
-int
-_mesa_sha1_final(struct mesa_sha1 *ctx, unsigned char result[20]);
+static inline void
+_mesa_sha1_final(struct mesa_sha1 *ctx, unsigned char result[20])
+{
+ SHA1Final(result, ctx);
+}
char *
_mesa_sha1_format(char *buf, const unsigned char *sha1);