aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-04 04:18:43 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-04 04:18:43 +0100
commit49e4914724526daa8ba52600891961c7dedf559b (patch)
treee273d3f644648d9d04cd11138c844d5a4b9f4a9d /src
parentm (diff)
downloadlibkeccak-49e4914724526daa8ba52600891961c7dedf559b.tar.gz
libkeccak-49e4914724526daa8ba52600891961c7dedf559b.tar.bz2
libkeccak-49e4914724526daa8ba52600891961c7dedf559b.tar.xz
add digest.h and hex.h
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libkeccak.h2
-rw-r--r--src/libkeccak/digest.h85
-rw-r--r--src/libkeccak/hex.h60
-rw-r--r--src/libkeccak/state.h4
4 files changed, 150 insertions, 1 deletions
diff --git a/src/libkeccak.h b/src/libkeccak.h
index 1dab356..af6bfac 100644
--- a/src/libkeccak.h
+++ b/src/libkeccak.h
@@ -22,6 +22,8 @@
#include "libkeccak/spec.h"
#include "libkeccak/state.h"
+#include "libkeccak/digest.h"
+#include "libkeccak/hex.h"
#undef
diff --git a/src/libkeccak/digest.h b/src/libkeccak/digest.h
new file mode 100644
index 0000000..4853631
--- /dev/null
+++ b/src/libkeccak/digest.h
@@ -0,0 +1,85 @@
+/**
+ * libkeccak – Keccak-family hashing library
+ *
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef LIBKECCAK_DIGEST_H
+#define LIBKECCAK_DIGEST_H 1
+
+
+#include "state.h"
+
+
+/**
+ * Absorb the more of the message to the Keccak sponge
+ *
+ * @param state The hashing state
+ * @param msg The partial message
+ * @param msglen The length of the partial message
+ */
+__attribute__((nonnull(1)))
+void libkeccak_update(libkeccak_state_t* restrict state, const char* restrict msg, size_t msglen);
+
+
+/**
+ * Absorb the last part of the message and squeeze the Keccak sponge
+ *
+ * @param state The hashing state
+ * @param msg The rest of the message, may be `NULL`
+ * @param msglen The length of the partial message
+ * @param bits The number of bits at the end of the message not covered by `msglen`
+ * @param suffix The suffix concatenate to the message
+ * @param hashsum Output paramter for the hashsum, may be `NULL`
+ * @return Zero on success, -1 on error
+ */
+__attribute__((nonnull(1)))
+int libkeccak_digest(libkeccak_state_t* restrict state, const char* restrict msg, size_t msglen,
+ size_t bits, const char* restrict suffix, char* restrict hashsum);
+
+
+/**
+ * Force some rounds of Keccak-f
+ *
+ * @param state The hashing state
+ * @param times The number of rounds
+ */
+__attribute__((nonnull, nothrow))
+void libkeccak_simple_squeeze(libkeccak_state_t* restrict state, long times);
+
+
+/**
+ * Squeeze as much as is needed to get a digest a number of times
+ *
+ * @param state The hashing state
+ * @param times The number of digests
+ */
+__attribute__((nonnull, nothrow))
+void libkeccak_fast_squeeze(libkeccak_state_t* restrict state, long times);
+
+
+/**
+ * Squeeze out another digest
+ *
+ * @param state The hashing state
+ * @param hashsum Output paramter for the hashsum
+ * @return Zero on success, -1 on error
+ */
+__attribute__((nonnull, nothrow))
+int libkeccak_squeeze(libkeccak_state_t* restrict state, char* restrict hashsum);
+
+
+#undef
+
diff --git a/src/libkeccak/hex.h b/src/libkeccak/hex.h
new file mode 100644
index 0000000..5d9470c
--- /dev/null
+++ b/src/libkeccak/hex.h
@@ -0,0 +1,60 @@
+/**
+ * libkeccak – Keccak-family hashing library
+ *
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef LIBKECCAK_HEX_H
+#define LIBKECCAK_HEX_H 1
+
+
+#include <stddef.h>
+
+
+/**
+ * Convert a binary hashsum to lower case hexadecimal representation
+ *
+ * @param output Output array, should have an allocation size of at least `2 * n + 1`
+ * @param hashsum The hashsum to convert
+ * @param n The size of `hashsum`
+ */
+__attribute__((leaf, nonnull, nothrow))
+void libkeccak_behex_lower(char* restrict output, const char* restrict hashsum, size_t n);
+
+
+/**
+ * Convert a binary hashsum to upper case hexadecimal representation
+ *
+ * @param output Output array, should have an allocation size of at least `2 * n + 1`
+ * @param hashsum The hashsum to convert
+ * @param n The size of `hashsum`
+ */
+__attribute__((leaf, nonnull, nothrow))
+void libkeccak_behex_upper(char* restrict output, const char* restrict hashsum, size_t n);
+
+
+/**
+ * Convert a hexadecimal hashsum (both lower case, upper
+ * case and mixed is supported) to binary representation
+ *
+ * @param output Output array, should have an allocation size of at least `strlen(hashsum) / 2`
+ * @param hashsum The hashsum to convert
+ */
+__attribute__((leaf, nonnull, nothrow))
+void libkeccak_unhex(char* restrict output, const char* restrict hashsum);
+
+
+#undef
+
diff --git a/src/libkeccak/state.h b/src/libkeccak/state.h
index 5abbb5a..00d8af7 100644
--- a/src/libkeccak/state.h
+++ b/src/libkeccak/state.h
@@ -30,7 +30,9 @@
/**
- * This datastructure describes the state of a hashing process
+ * Satastructure that describes the state of a hashing process
+ *
+ * The `char`-size of the output hashsum is calculated by `(.n + 7) >> 3`
*/
typedef struct libkeccak_state
{