summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-03-20 08:59:49 +0100
committerStef Walter <stefw@gnome.org>2013-03-20 09:31:50 +0100
commit1dc227b4fce16fcc721276925492f4ba4db00b4f (patch)
tree1a0b070061e27e967c07208f2f21891c29969986 /common
parentef8c54a355d3f9814cc53a0aad72d61247b169a0 (diff)
hash: Rename file and functions for hashes
We're going to be adding other hashes. Also build as part of a different common library.
Diffstat (limited to 'common')
-rw-r--r--common/Makefile.am2
-rw-r--r--common/hash.c (renamed from common/checksum.c)22
-rw-r--r--common/hash.h (renamed from common/checksum.h)26
-rw-r--r--common/tests/Makefile.am2
-rw-r--r--common/tests/test-hash.c (renamed from common/tests/test-checksum.c)28
-rw-r--r--common/x509.c4
6 files changed, 42 insertions, 42 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index 3a54089..14432fc 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -25,6 +25,7 @@ libp11_library_la_SOURCES = \
constants.c constants.h \
debug.c debug.h \
dict.c dict.h \
+ hash.c hash.h \
lexer.c lexer.h \
library.c library.h \
pkcs11.h pkcs11x.h \
@@ -45,7 +46,6 @@ libp11_data_la_SOURCES = \
asn1.c asn1.h \
basic.asn basic.asn.h \
base64.c base64.h \
- checksum.c checksum.h \
oid.c oid.h \
openssl.asn openssl.asn.h \
pem.c pem.h \
diff --git a/common/checksum.c b/common/hash.c
index 9532308..59548fa 100644
--- a/common/checksum.c
+++ b/common/hash.c
@@ -32,7 +32,7 @@
#include "config.h"
-#include "checksum.h"
+#include "hash.h"
#include <assert.h>
#include <stdarg.h>
@@ -252,10 +252,10 @@ sha1_final (sha1_t *context,
}
void
-p11_checksum_sha1 (unsigned char *checksum,
- const void *input,
- size_t length,
- ...)
+p11_hash_sha1 (unsigned char *hash,
+ const void *input,
+ size_t length,
+ ...)
{
va_list va;
sha1_t sha1;
@@ -271,7 +271,7 @@ p11_checksum_sha1 (unsigned char *checksum,
}
va_end (va);
- sha1_final (&sha1, checksum);
+ sha1_final (&sha1, hash);
sha1_invalidate (&sha1);
}
@@ -518,10 +518,10 @@ md5_final(md5_t *ctx,
}
void
-p11_checksum_md5 (unsigned char *checksum,
- const void *input,
- size_t length,
- ...)
+p11_hash_md5 (unsigned char *hash,
+ const void *input,
+ size_t length,
+ ...)
{
va_list va;
md5_t md5;
@@ -537,6 +537,6 @@ p11_checksum_md5 (unsigned char *checksum,
}
va_end (va);
- md5_final (&md5, checksum);
+ md5_final (&md5, hash);
md5_invalidate (&md5);
}
diff --git a/common/checksum.h b/common/hash.h
index c688398..f4dfce1 100644
--- a/common/checksum.h
+++ b/common/hash.h
@@ -32,8 +32,8 @@
* Author: Stef Walter <stefw@redhat.com>
*/
-#ifndef P11_CHECKSUM_H_
-#define P11_CHECKSUM_H_
+#ifndef P11_HASH_H_
+#define P11_HASH_H_
#include "compat.h"
@@ -43,18 +43,18 @@
* These particular algorithms would be poor choices for that.
*/
-#define P11_CHECKSUM_SHA1_LENGTH 20
+#define P11_HASH_MD5_LEN 16
-#define P11_CHECKSUM_MD5_LENGTH 16
+void p11_hash_md5 (unsigned char *hash,
+ const void *input,
+ size_t length,
+ ...) GNUC_NULL_TERMINATED;
-void p11_checksum_md5 (unsigned char *checksum,
- const void *input,
- size_t length,
- ...) GNUC_NULL_TERMINATED;
+#define P11_HASH_SHA1_LEN 20
-void p11_checksum_sha1 (unsigned char *checksum,
- const void *input,
- size_t length,
- ...) GNUC_NULL_TERMINATED;
+void p11_hash_sha1 (unsigned char *hash,
+ const void *input,
+ size_t length,
+ ...) GNUC_NULL_TERMINATED;
-#endif /* P11_CHECKSUM_H_ */
+#endif /* P11_HASH_H_ */
diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am
index 85893cb..70f369c 100644
--- a/common/tests/Makefile.am
+++ b/common/tests/Makefile.am
@@ -16,6 +16,7 @@ LDADD = \
CHECK_PROGS = \
test-compat \
+ test-hash \
test-dict \
test-array \
test-constants \
@@ -43,7 +44,6 @@ INCLUDES += \
CHECK_PROGS += \
test-asn1 \
- test-checksum \
test-base64 \
test-pem \
test-oid \
diff --git a/common/tests/test-checksum.c b/common/tests/test-hash.c
index 5604aad..5e32c85 100644
--- a/common/tests/test-checksum.c
+++ b/common/tests/test-hash.c
@@ -39,7 +39,7 @@
#include <stdio.h>
#include <string.h>
-#include "checksum.h"
+#include "hash.h"
const char *sha1_input[] = {
"abc",
@@ -56,7 +56,7 @@ const char *sha1_checksum[] = {
static void
test_sha1 (CuTest *cu)
{
- unsigned char checksum[P11_CHECKSUM_SHA1_LENGTH];
+ unsigned char checksum[P11_HASH_SHA1_LEN];
size_t len;
int i;
@@ -64,12 +64,12 @@ test_sha1 (CuTest *cu)
memset (checksum, 0, sizeof (checksum));
len = strlen (sha1_input[i]);
- p11_checksum_sha1 (checksum, sha1_input[i], len, NULL);
- CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_CHECKSUM_SHA1_LENGTH) == 0);
+ p11_hash_sha1 (checksum, sha1_input[i], len, NULL);
+ CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0);
if (len > 6) {
- p11_checksum_sha1 (checksum, sha1_input[i], 6, sha1_input[i] + 6, len - 6, NULL);
- CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_CHECKSUM_SHA1_LENGTH) == 0);
+ p11_hash_sha1 (checksum, sha1_input[i], 6, sha1_input[i] + 6, len - 6, NULL);
+ CuAssertTrue (cu, memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0);
}
}
}
@@ -77,7 +77,7 @@ test_sha1 (CuTest *cu)
static void
test_sha1_long (CuTest *cu)
{
- unsigned char checksum[P11_CHECKSUM_SHA1_LENGTH];
+ unsigned char checksum[P11_HASH_SHA1_LEN];
char *expected = "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F";
char *input;
@@ -85,8 +85,8 @@ test_sha1_long (CuTest *cu)
CuAssertTrue (cu, input != NULL);
memset (input, 'a', 1000000);
- p11_checksum_sha1 (checksum, input, strlen (input), NULL);
- CuAssertTrue (cu, memcmp (expected, checksum, P11_CHECKSUM_SHA1_LENGTH) == 0);
+ p11_hash_sha1 (checksum, input, strlen (input), NULL);
+ CuAssertTrue (cu, memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0);
}
const char *md5_input[] = {
@@ -110,7 +110,7 @@ const char *md5_checksum[] = {
static void
test_md5 (CuTest *cu)
{
- unsigned char checksum[P11_CHECKSUM_MD5_LENGTH];
+ unsigned char checksum[P11_HASH_MD5_LEN];
size_t len;
int i;
@@ -118,12 +118,12 @@ test_md5 (CuTest *cu)
memset (checksum, 0, sizeof (checksum));
len = strlen (md5_input[i]);
- p11_checksum_md5 (checksum, md5_input[i], len, NULL);
- CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_CHECKSUM_MD5_LENGTH) == 0);
+ p11_hash_md5 (checksum, md5_input[i], len, NULL);
+ CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0);
if (len > 5) {
- p11_checksum_md5 (checksum, md5_input[i], 5, md5_input[i] + 5, len - 5, NULL);
- CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_CHECKSUM_MD5_LENGTH) == 0);
+ p11_hash_md5 (checksum, md5_input[i], 5, md5_input[i] + 5, len - 5, NULL);
+ CuAssertTrue (cu, memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0);
}
}
}
diff --git a/common/x509.c b/common/x509.c
index ae1c810..aa6e171 100644
--- a/common/x509.c
+++ b/common/x509.c
@@ -36,8 +36,8 @@
#include "asn1.h"
#define P11_DEBUG_FLAG P11_DEBUG_TRUST
-#include "checksum.h"
#include "debug.h"
+#include "hash.h"
#include "oid.h"
#include "utf8.h"
#include "x509.h"
@@ -121,7 +121,7 @@ p11_x509_calc_keyid (node_asn *cert,
return_val_if_fail (ret == ASN1_SUCCESS, false);
return_val_if_fail (end >= start, false);
- p11_checksum_sha1 (keyid, (der + start), (end - start) + 1, NULL);
+ p11_hash_sha1 (keyid, (der + start), (end - start) + 1, NULL);
return true;
}