summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--tools/extract-jks.c14
-rw-r--r--tools/extract-openssl.c10
-rw-r--r--trust/builder.c16
-rw-r--r--trust/parser.c4
-rw-r--r--trust/tests/test-builder.c6
-rw-r--r--trust/tests/test-module.c10
12 files changed, 72 insertions, 72 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;
}
diff --git a/tools/extract-jks.c b/tools/extract-jks.c
index d75735c..d72b1dc 100644
--- a/tools/extract-jks.c
+++ b/tools/extract-jks.c
@@ -36,10 +36,10 @@
#include "attrs.h"
#include "buffer.h"
-#include "checksum.h"
#include "compat.h"
#include "debug.h"
#include "extract.h"
+#include "hash.h"
#include "library.h"
#include "save.h"
@@ -299,13 +299,13 @@ prepare_jks_buffer (P11KitIter *iter,
* as the password for this keyed digest.
*/
length = buffer->len;
- digest = p11_buffer_append (buffer, P11_CHECKSUM_SHA1_LENGTH);
+ digest = p11_buffer_append (buffer, P11_HASH_SHA1_LEN);
return_val_if_fail (digest != NULL, false);
- p11_checksum_sha1 (digest,
- "\000c\000h\000a\000n\000g\000e\000i\000t", 16, /* default password */
- "Mighty Aphrodite", 16, /* go figure */
- buffer->data, length,
- NULL);
+ p11_hash_sha1 (digest,
+ "\000c\000h\000a\000n\000g\000e\000i\000t", 16, /* default password */
+ "Mighty Aphrodite", 16, /* go figure */
+ buffer->data, length,
+ NULL);
return_val_if_fail (p11_buffer_ok (buffer), false);
return true;
diff --git a/tools/extract-openssl.c b/tools/extract-openssl.c
index bc7427a..8e02421 100644
--- a/tools/extract-openssl.c
+++ b/tools/extract-openssl.c
@@ -37,11 +37,11 @@
#include "asn1.h"
#include "attrs.h"
#include "buffer.h"
-#include "checksum.h"
#include "compat.h"
#include "debug.h"
#include "dict.h"
#include "extract.h"
+#include "hash.h"
#include "library.h"
#include "oid.h"
#include "pem.h"
@@ -520,7 +520,7 @@ p11_openssl_canon_name_der (p11_dict *asn1_defs,
static char *
symlink_for_subject_hash (p11_extract_info *ex)
{
- unsigned char md[P11_CHECKSUM_SHA1_LENGTH];
+ unsigned char md[P11_HASH_SHA1_LEN];
p11_buffer der;
CK_ATTRIBUTE *subject;
unsigned long hash;
@@ -535,7 +535,7 @@ symlink_for_subject_hash (p11_extract_info *ex)
return_val_if_fail (der.data != NULL, NULL);
if (p11_openssl_canon_name_der (ex->asn1_defs, &der)) {
- p11_checksum_sha1 (md, der.data, der.len, NULL);
+ p11_hash_sha1 (md, der.data, der.len, NULL);
hash = (
((unsigned long)md[0] ) | ((unsigned long)md[1] << 8L) |
@@ -553,7 +553,7 @@ symlink_for_subject_hash (p11_extract_info *ex)
static char *
symlink_for_subject_old_hash (p11_extract_info *ex)
{
- unsigned char md[P11_CHECKSUM_MD5_LENGTH];
+ unsigned char md[P11_HASH_MD5_LEN];
CK_ATTRIBUTE *subject;
unsigned long hash;
char *linkname;
@@ -562,7 +562,7 @@ symlink_for_subject_old_hash (p11_extract_info *ex)
if (!subject)
return NULL;
- p11_checksum_md5 (md, subject->pValue, subject->ulValueLen, NULL);
+ p11_hash_md5 (md, subject->pValue, subject->ulValueLen, NULL);
hash = (
((unsigned long)md[0] ) | ((unsigned long)md[1] << 8L) |
diff --git a/trust/builder.c b/trust/builder.c
index 85abe5b..f4ababa 100644
--- a/trust/builder.c
+++ b/trust/builder.c
@@ -40,9 +40,9 @@
#include "asn1.h"
#include "attrs.h"
#include "builder.h"
-#include "checksum.h"
#include "constants.h"
#include "debug.h"
+#include "hash.h"
#include "index.h"
#include "library.h"
#include "oid.h"
@@ -222,8 +222,8 @@ calc_check_value (const unsigned char *data,
size_t length,
CK_BYTE *check_value)
{
- unsigned char checksum[P11_CHECKSUM_SHA1_LENGTH];
- p11_checksum_sha1 (checksum, data, length, NULL);
+ unsigned char checksum[P11_HASH_SHA1_LEN];
+ p11_hash_sha1 (checksum, data, length, NULL);
memcpy (check_value, checksum, 3);
}
@@ -412,7 +412,7 @@ certificate_value_attrs (CK_ATTRIBUTE *attrs,
const unsigned char *der,
size_t der_len)
{
- unsigned char checksum[P11_CHECKSUM_SHA1_LENGTH];
+ unsigned char checksum[P11_HASH_SHA1_LEN];
CK_BBOOL falsev = CK_FALSE;
CK_ULONG zero = 0UL;
CK_BYTE checkv[3];
@@ -1057,8 +1057,8 @@ replace_nss_trust_object (p11_builder *builder,
CK_RV rv;
CK_OBJECT_CLASS klassv = CKO_NSS_TRUST;
- CK_BYTE sha1v[P11_CHECKSUM_SHA1_LENGTH];
- CK_BYTE md5v[P11_CHECKSUM_MD5_LENGTH];
+ CK_BYTE sha1v[P11_HASH_SHA1_LEN];
+ CK_BYTE md5v[P11_HASH_MD5_LEN];
CK_BBOOL generatedv = CK_FALSE;
CK_BBOOL falsev = CK_FALSE;
@@ -1094,8 +1094,8 @@ replace_nss_trust_object (p11_builder *builder,
md5_hash.type = CKA_INVALID;
sha1_hash.type = CKA_INVALID;
} else {
- p11_checksum_md5 (md5v, value, length, NULL);
- p11_checksum_sha1 (sha1v, value, length, NULL);
+ p11_hash_md5 (md5v, value, length, NULL);
+ p11_hash_sha1 (sha1v, value, length, NULL);
}
if (!issuer)
issuer = &invalid;
diff --git a/trust/parser.c b/trust/parser.c
index 42d74fc..91fd5e8 100644
--- a/trust/parser.c
+++ b/trust/parser.c
@@ -37,10 +37,10 @@
#include "array.h"
#include "asn1.h"
#include "attrs.h"
-#include "checksum.h"
#define P11_DEBUG_FLAG P11_DEBUG_TRUST
#include "debug.h"
#include "dict.h"
+#include "hash.h"
#include "library.h"
#include "module.h"
#include "oid.h"
@@ -71,7 +71,7 @@ struct _p11_parser {
int flags;
};
-#define ID_LENGTH P11_CHECKSUM_SHA1_LENGTH
+#define ID_LENGTH P11_HASH_SHA1_LEN
typedef int (* parser_func) (p11_parser *parser,
const unsigned char *data,
diff --git a/trust/tests/test-builder.c b/trust/tests/test-builder.c
index 536d7dc..bbc731a 100644
--- a/trust/tests/test-builder.c
+++ b/trust/tests/test-builder.c
@@ -41,7 +41,7 @@
#include "attrs.h"
#include "builder.h"
-#include "checksum.h"
+#include "hash.h"
#include "debug.h"
#include "index.h"
#include "library.h"
@@ -187,7 +187,7 @@ test_build_certificate (CuTest *cu)
static void
test_build_certificate_empty (CuTest *cu)
{
- unsigned char checksum[P11_CHECKSUM_SHA1_LENGTH];
+ unsigned char checksum[P11_HASH_SHA1_LEN];
CK_ULONG domain = 0;
CK_ULONG category = 0;
@@ -225,7 +225,7 @@ test_build_certificate_empty (CuTest *cu)
setup (cu);
- p11_checksum_sha1 (checksum, test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL);
+ p11_hash_sha1 (checksum, test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL);
attrs = NULL;
merge = p11_attrs_dup (input);
diff --git a/trust/tests/test-module.c b/trust/tests/test-module.c
index 57df78e..1d97f9b 100644
--- a/trust/tests/test-module.c
+++ b/trust/tests/test-module.c
@@ -42,8 +42,8 @@
#define CRYPTOKI_EXPORTS
#include "attrs.h"
-#include "checksum.h"
#include "debug.h"
+#include "hash.h"
#include "library.h"
#include "pkcs11x.h"
#include "test-data.h"
@@ -385,8 +385,8 @@ check_trust_object_hashes (CuTest *cu,
CK_OBJECT_HANDLE trust,
CK_ATTRIBUTE *cert)
{
- unsigned char sha1[P11_CHECKSUM_SHA1_LENGTH];
- unsigned char md5[P11_CHECKSUM_MD5_LENGTH];
+ unsigned char sha1[P11_HASH_SHA1_LEN];
+ unsigned char md5[P11_HASH_MD5_LEN];
unsigned char check[128];
CK_ATTRIBUTE *value;
CK_RV rv;
@@ -403,10 +403,10 @@ check_trust_object_hashes (CuTest *cu,
value = p11_attrs_find_valid (cert, CKA_VALUE);
CuAssertPtrNotNull (cu, value);
- p11_checksum_md5 (check, value->pValue, value->ulValueLen, NULL);
+ p11_hash_md5 (check, value->pValue, value->ulValueLen, NULL);
CuAssertTrue (cu, memcmp (md5, check, sizeof (md5)) == 0);
- p11_checksum_sha1 (check, value->pValue, value->ulValueLen, NULL);
+ p11_hash_sha1 (check, value->pValue, value->ulValueLen, NULL);
CuAssertTrue (cu, memcmp (sha1, check, sizeof (sha1)) == 0);
}