summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2015-10-12 22:57:19 +0000
committerbrian m. carlson <sandals@crustytoothpaste.net>2015-10-12 22:57:19 +0000
commit1525a1a644149f1eb633b7d9760a1afcebcbfb15 (patch)
tree707a2a844d65abec6bb6ed36923ad18a1731a60e
parentf645df29b1a5b6c70f52a922eddb2646cc6f6988 (diff)
hash: add technique for enumerating parameter sets.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
-rw-r--r--impl/hash/hash-plugin.hh8
-rw-r--r--impl/hash/hash.hh13
-rw-r--r--include/drew/hash.h16
3 files changed, 37 insertions, 0 deletions
diff --git a/impl/hash/hash-plugin.hh b/impl/hash/hash-plugin.hh
index 77975c0..4b5fa53 100644
--- a/impl/hash/hash-plugin.hh
+++ b/impl/hash/hash-plugin.hh
@@ -114,6 +114,14 @@ static int prefix ## info2(const drew_hash_t *ctx, int op, drew_param_t *out, \
return hname::buffer_size; \
case DREW_HASH_INTSIZE: \
return sizeof(hname); \
+ case DREW_HASH_PARAM: \
+ for (p = out; p; p = p->next) \
+ if (!strcmp(p->name, "parameters")) { \
+ drew_hash_parameters_t *q = \
+ (drew_hash_parameters_t *)p->param.array.ptr; \
+ return hname::GetParameters(q->offset, q->digest_size, \
+ q->block_size, q->buffer_size); \
+ } \
case DREW_HASH_ENDIAN: \
return hname::endian_t::GetEndianness(); \
default: \
diff --git a/impl/hash/hash.hh b/impl/hash/hash.hh
index 687349d..0a5f2b2 100644
--- a/impl/hash/hash.hh
+++ b/impl/hash/hash.hh
@@ -27,6 +27,7 @@
#include <algorithm>
#include <internal.h>
+#include <drew/plugin.h>
#include "util.hh"
@@ -137,6 +138,18 @@ class Hash
{
return BufSize;
}
+ static int GetParameters(int seq, size_t &sz, size_t &blocksz,
+ size_t &bufsz)
+ {
+ if (seq == -1)
+ return 1;
+ if (seq != 0)
+ return -DREW_ERR_NONEXISTENT;
+ sz = Size;
+ blocksz = BlkSize;
+ bufsz = BufSize;
+ return 0;
+ }
static inline void Transform(T *, const uint8_t *data);
protected:
virtual void Transform(const uint8_t *data) = 0;
diff --git a/include/drew/hash.h b/include/drew/hash.h
index a73e33e..8afa025 100644
--- a/include/drew/hash.h
+++ b/include/drew/hash.h
@@ -64,6 +64,14 @@
#define DREW_HASH_SIZE_CTX 10
#define DREW_HASH_BLKSIZE_CTX 11
#define DREW_HASH_BUFSIZE_CTX 12
+/* Returns the next set of parameters in sequence, from smallest to largest, as
+ * a drew_hash_parameters_t.
+ */
+#define DREW_HASH_PARAM 13
+/* Returns the set of parameters for the current context as a
+ * drew_hash_parameters_t.
+ */
+#define DREW_HASH_PARAM_CTX 13
/* This bit indicates that the ctx member of drew_hash_t is externally
* allocated and sufficiently large.
@@ -77,6 +85,14 @@
#define DREW_HASH_ALIGNMENT 16
typedef struct {
+ int offset;
+ size_t digest_size;
+ size_t block_size;
+ size_t buffer_size;
+ size_t pad[5];
+} drew_hash_parameters_t;
+
+typedef struct {
int (*info)(int op, void *p);
void (*init)(void **, drew_loader_t *, const drew_param_t *);
void (*update)(void *, const uint8_t *, size_t);