aboutsummaryrefslogtreecommitdiffstats
path: root/unhex.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-10 17:10:20 +0100
committerMattias Andrée <maandree@kth.se>2019-02-10 17:11:30 +0100
commit32a5ae4e65844615cb3e32aaefcdb7abe4af54c9 (patch)
tree0ecfa02766944f2568b184d8d5a8ba0edc71425f /unhex.c
parentUse lowest bits rather than highest bits in complete byte, document this, and add tests (diff)
downloadlibsha2-32a5ae4e65844615cb3e32aaefcdb7abe4af54c9.tar.gz
libsha2-32a5ae4e65844615cb3e32aaefcdb7abe4af54c9.tar.bz2
libsha2-32a5ae4e65844615cb3e32aaefcdb7abe4af54c9.tar.xz
Add HMAC and use void * instead of char * for binary data
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--unhex.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/unhex.c b/unhex.c
index a84ac19..1cada1f 100644
--- a/unhex.c
+++ b/unhex.c
@@ -11,17 +11,18 @@
* @param hashsum The hashsum to convert
*/
void
-libsha2_unhex(char *restrict output, const char *restrict hashsum)
+libsha2_unhex(void *restrict output_, const char *restrict hashsum)
{
+ unsigned char *restrict output = output_;
size_t n = strlen(hashsum) / 2;
- char a, b;
+ unsigned char a, b;
while (n--) {
- a = hashsum[2 * n + 0];
- b = hashsum[2 * n + 1];
+ a = ((const unsigned char *)hashsum)[2 * n + 0];
+ b = ((const unsigned char *)hashsum)[2 * n + 1];
- a = (char)((a & 15) + (a > '9' ? 9 : 0));
- b = (char)((b & 15) + (b > '9' ? 9 : 0));
+ a = (unsigned char)((a & 15) + (a > '9' ? 9 : 0));
+ b = (unsigned char)((b & 15) + (b > '9' ? 9 : 0));
- output[n] = (char)((a << 4) | b);
+ output[n] = (unsigned char)((a << 4) | b);
}
}