|
|
05f9c5 |
From 1dbd23dc2566b3fe9113bf09fd9e190dfd4651b6 Mon Sep 17 00:00:00 2001
|
|
|
ffbc92 |
From: Petr Lautrbach <plautrba@redhat.com>
|
|
|
db4930 |
Date: Fri, 30 Jul 2021 14:14:37 +0200
|
|
|
ffbc92 |
Subject: [PATCH] Use SHA-2 instead of SHA-1
|
|
|
1175f7 |
Content-type: text/plain
|
|
|
ffbc92 |
|
|
|
ffbc92 |
The use of SHA-1 in RHEL9 is deprecated
|
|
|
ffbc92 |
---
|
|
|
ffbc92 |
libselinux/include/selinux/label.h | 6 +-
|
|
|
ffbc92 |
libselinux/include/selinux/restorecon.h | 4 +-
|
|
|
ffbc92 |
libselinux/man/man3/selabel_digest.3 | 4 +-
|
|
|
ffbc92 |
libselinux/man/man3/selabel_open.3 | 2 +-
|
|
|
1175f7 |
libselinux/man/man3/selinux_restorecon.3 | 18 +-
|
|
|
ffbc92 |
.../man/man3/selinux_restorecon_xattr.3 | 2 +-
|
|
|
ffbc92 |
libselinux/src/Makefile | 2 +-
|
|
|
ffbc92 |
libselinux/src/label_file.c | 40 +--
|
|
|
ffbc92 |
libselinux/src/label_internal.h | 10 +-
|
|
|
1175f7 |
libselinux/src/label_support.c | 10 +-
|
|
|
ffbc92 |
libselinux/src/selinux_restorecon.c | 24 +-
|
|
|
ffbc92 |
libselinux/src/sha1.c | 220 -------------
|
|
|
ffbc92 |
libselinux/src/sha1.h | 85 -----
|
|
|
ffbc92 |
libselinux/src/sha256.c | 294 ++++++++++++++++++
|
|
|
ffbc92 |
libselinux/src/sha256.h | 89 ++++++
|
|
|
ffbc92 |
libselinux/utils/selabel_digest.c | 26 +-
|
|
|
ffbc92 |
.../selabel_get_digests_all_partial_matches.c | 28 +-
|
|
|
1175f7 |
17 files changed, 471 insertions(+), 393 deletions(-)
|
|
|
ffbc92 |
delete mode 100644 libselinux/src/sha1.c
|
|
|
ffbc92 |
delete mode 100644 libselinux/src/sha1.h
|
|
|
ffbc92 |
create mode 100644 libselinux/src/sha256.c
|
|
|
ffbc92 |
create mode 100644 libselinux/src/sha256.h
|
|
|
ffbc92 |
|
|
|
ffbc92 |
diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h
|
|
|
ffbc92 |
index e8983606d93b..a35d84d63b0a 100644
|
|
|
ffbc92 |
--- a/libselinux/include/selinux/label.h
|
|
|
ffbc92 |
+++ b/libselinux/include/selinux/label.h
|
|
|
ffbc92 |
@@ -120,13 +120,13 @@ extern int selabel_lookup_best_match_raw(struct selabel_handle *rec, char **con,
|
|
|
ffbc92 |
const char *key, const char **aliases, int type);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
/**
|
|
|
ffbc92 |
- * selabel_digest - Retrieve the SHA1 digest and the list of specfiles used to
|
|
|
ffbc92 |
+ * selabel_digest - Retrieve the SHA256 digest and the list of specfiles used to
|
|
|
ffbc92 |
* generate the digest. The SELABEL_OPT_DIGEST option must
|
|
|
ffbc92 |
* be set in selabel_open() to initiate the digest generation.
|
|
|
ffbc92 |
* @handle: specifies backend instance to query
|
|
|
ffbc92 |
- * @digest: returns a pointer to the SHA1 digest.
|
|
|
ffbc92 |
+ * @digest: returns a pointer to the SHA256 digest.
|
|
|
ffbc92 |
* @digest_len: returns length of digest in bytes.
|
|
|
ffbc92 |
- * @specfiles: a list of specfiles used in the SHA1 digest generation.
|
|
|
ffbc92 |
+ * @specfiles: a list of specfiles used in the SHA256 digest generation.
|
|
|
ffbc92 |
* The list is NULL terminated and will hold @num_specfiles entries.
|
|
|
ffbc92 |
* @num_specfiles: number of specfiles in the list.
|
|
|
ffbc92 |
*
|
|
|
ffbc92 |
diff --git a/libselinux/include/selinux/restorecon.h b/libselinux/include/selinux/restorecon.h
|
|
|
1175f7 |
index b10fe684eff9..8df4744505b3 100644
|
|
|
ffbc92 |
--- a/libselinux/include/selinux/restorecon.h
|
|
|
ffbc92 |
+++ b/libselinux/include/selinux/restorecon.h
|
|
|
1175f7 |
@@ -41,8 +41,8 @@ extern int selinux_restorecon_parallel(const char *pathname,
|
|
|
ffbc92 |
* restorecon_flags options
|
|
|
ffbc92 |
*/
|
|
|
ffbc92 |
/*
|
|
|
ffbc92 |
- * Force the checking of labels even if the stored SHA1 digest
|
|
|
ffbc92 |
- * matches the specfiles SHA1 digest (requires CAP_SYS_ADMIN).
|
|
|
ffbc92 |
+ * Force the checking of labels even if the stored SHA256 digest
|
|
|
ffbc92 |
+ * matches the specfiles SHA256 digest (requires CAP_SYS_ADMIN).
|
|
|
ffbc92 |
*/
|
|
|
ffbc92 |
#define SELINUX_RESTORECON_IGNORE_DIGEST 0x00001
|
|
|
ffbc92 |
/*
|
|
|
ffbc92 |
diff --git a/libselinux/man/man3/selabel_digest.3 b/libselinux/man/man3/selabel_digest.3
|
|
|
ffbc92 |
index 56a008f00df0..5f7c42533d0e 100644
|
|
|
ffbc92 |
--- a/libselinux/man/man3/selabel_digest.3
|
|
|
ffbc92 |
+++ b/libselinux/man/man3/selabel_digest.3
|
|
|
ffbc92 |
@@ -20,11 +20,11 @@ selabel_digest \- Return digest of specfiles and list of files used
|
|
|
ffbc92 |
.BR selabel_digest ()
|
|
|
ffbc92 |
performs an operation on the handle
|
|
|
ffbc92 |
.IR hnd ,
|
|
|
ffbc92 |
-returning the results of the SHA1 digest pointed to by
|
|
|
ffbc92 |
+returning the results of the SHA256 digest pointed to by
|
|
|
ffbc92 |
.IR digest ,
|
|
|
ffbc92 |
whose length will be
|
|
|
ffbc92 |
.IR digest_len .
|
|
|
ffbc92 |
-The list of specfiles used in the SHA1 digest calculation is returned in
|
|
|
ffbc92 |
+The list of specfiles used in the SHA256 digest calculation is returned in
|
|
|
ffbc92 |
.I specfiles
|
|
|
ffbc92 |
with the number of entries in
|
|
|
ffbc92 |
.IR num_specfiles .
|
|
|
ffbc92 |
diff --git a/libselinux/man/man3/selabel_open.3 b/libselinux/man/man3/selabel_open.3
|
|
|
1175f7 |
index 0e03e1be111e..14ab888d2e03 100644
|
|
|
ffbc92 |
--- a/libselinux/man/man3/selabel_open.3
|
|
|
ffbc92 |
+++ b/libselinux/man/man3/selabel_open.3
|
|
|
ffbc92 |
@@ -69,7 +69,7 @@ is used; a custom validation function can be provided via
|
|
|
ffbc92 |
Note that an invalid context may not be treated as an error unless it is actually encountered during a lookup operation.
|
|
|
ffbc92 |
.TP
|
|
|
ffbc92 |
.B SELABEL_OPT_DIGEST
|
|
|
ffbc92 |
-A non-null value for this option enables the generation of an SHA1 digest of
|
|
|
ffbc92 |
+A non-null value for this option enables the generation of an SHA256 digest of
|
|
|
ffbc92 |
the spec files loaded as described in
|
|
|
ffbc92 |
.BR selabel_digest (3)
|
|
|
ffbc92 |
.
|
|
|
ffbc92 |
diff --git a/libselinux/man/man3/selinux_restorecon.3 b/libselinux/man/man3/selinux_restorecon.3
|
|
|
1175f7 |
index 218aaf6d2ae5..5f6d4b386429 100644
|
|
|
ffbc92 |
--- a/libselinux/man/man3/selinux_restorecon.3
|
|
|
ffbc92 |
+++ b/libselinux/man/man3/selinux_restorecon.3
|
|
|
1175f7 |
@@ -36,7 +36,7 @@ If this is a directory and the
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_RECURSE
|
|
|
ffbc92 |
has been set (for descending through directories), then
|
|
|
ffbc92 |
.BR selinux_restorecon ()
|
|
|
ffbc92 |
-will write an SHA1 digest of specfile entries calculated by
|
|
|
ffbc92 |
+will write an SHA256 digest of specfile entries calculated by
|
|
|
ffbc92 |
.BR selabel_get_digests_all_partial_matches (3)
|
|
|
ffbc92 |
to an extended attribute of
|
|
|
ffbc92 |
.IR security.sehash
|
|
|
1175f7 |
@@ -55,7 +55,7 @@ will take place.
|
|
|
ffbc92 |
.br
|
|
|
ffbc92 |
The
|
|
|
ffbc92 |
.IR restorecon_flags
|
|
|
ffbc92 |
-that can be used to manage the usage of the SHA1 digest are:
|
|
|
ffbc92 |
+that can be used to manage the usage of the SHA256 digest are:
|
|
|
ffbc92 |
.RS
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_SKIP_DIGEST
|
|
|
ffbc92 |
.br
|
|
|
1175f7 |
@@ -73,8 +73,8 @@ Do not check or update any extended attribute
|
|
|
ffbc92 |
entries.
|
|
|
ffbc92 |
.sp
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_IGNORE_DIGEST
|
|
|
ffbc92 |
-force the checking of labels even if the stored SHA1 digest matches the
|
|
|
ffbc92 |
-specfile entries SHA1 digest. The specfile entries digest will be written to the
|
|
|
ffbc92 |
+force the checking of labels even if the stored SHA256 digest matches the
|
|
|
ffbc92 |
+specfile entries SHA256 digest. The specfile entries digest will be written to the
|
|
|
ffbc92 |
.IR security.sehash
|
|
|
ffbc92 |
extended attribute once relabeling has been completed successfully provided the
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_NOCHANGE
|
|
|
1175f7 |
@@ -95,7 +95,7 @@ default specfile context.
|
|
|
ffbc92 |
.sp
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_RECURSE
|
|
|
ffbc92 |
change file and directory labels recursively (descend directories)
|
|
|
ffbc92 |
-and if successful write an SHA1 digest of the specfile entries to an
|
|
|
ffbc92 |
+and if successful write an SHA256 digest of the specfile entries to an
|
|
|
ffbc92 |
extended attribute as described in the
|
|
|
ffbc92 |
.B NOTES
|
|
|
ffbc92 |
section.
|
|
|
1175f7 |
@@ -179,12 +179,12 @@ for fetching the ignored (skipped) error count after
|
|
|
1175f7 |
or
|
|
|
1175f7 |
.BR selinux_restorecon_parallel (3)
|
|
|
1175f7 |
completes with success. In case any errors were skipped during the file tree
|
|
|
1175f7 |
-walk, the specfile entries SHA1 digest will not have been written to the
|
|
|
1175f7 |
+walk, the specfile entries SHA256 digest will not have been written to the
|
|
|
1175f7 |
.IR security.sehash
|
|
|
1175f7 |
extended attribute.
|
|
|
ffbc92 |
.RE
|
|
|
ffbc92 |
.sp
|
|
|
ffbc92 |
-The behavior regarding the checking and updating of the SHA1 digest described
|
|
|
ffbc92 |
+The behavior regarding the checking and updating of the SHA256 digest described
|
|
|
ffbc92 |
above is the default behavior. It is possible to change this by first calling
|
|
|
ffbc92 |
.BR selabel_open (3)
|
|
|
ffbc92 |
and not enabling the
|
|
|
1175f7 |
@@ -247,7 +247,7 @@ To improve performance when relabeling file systems recursively (e.g. the
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_RECURSE
|
|
|
ffbc92 |
flag is set)
|
|
|
ffbc92 |
.BR selinux_restorecon ()
|
|
|
ffbc92 |
-will write a calculated SHA1 digest of the specfile entries returned by
|
|
|
ffbc92 |
+will write a calculated SHA256 digest of the specfile entries returned by
|
|
|
ffbc92 |
.BR selabel_get_digests_all_partial_matches (3)
|
|
|
ffbc92 |
to an extended attribute named
|
|
|
ffbc92 |
.IR security.sehash
|
|
|
1175f7 |
@@ -269,7 +269,7 @@ Should any of the specfile entries have changed, then when
|
|
|
ffbc92 |
.BR selinux_restorecon ()
|
|
|
ffbc92 |
is run again with the
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_RECURSE
|
|
|
ffbc92 |
-flag set, new SHA1 digests will be calculated and all files automatically
|
|
|
ffbc92 |
+flag set, new SHA256 digests will be calculated and all files automatically
|
|
|
ffbc92 |
relabeled depending on the settings of the
|
|
|
ffbc92 |
.B SELINUX_RESTORECON_SET_SPECFILE_CTX
|
|
|
ffbc92 |
flag (provided
|
|
|
ffbc92 |
diff --git a/libselinux/man/man3/selinux_restorecon_xattr.3 b/libselinux/man/man3/selinux_restorecon_xattr.3
|
|
|
ffbc92 |
index c56326814b94..098c840fc59b 100644
|
|
|
ffbc92 |
--- a/libselinux/man/man3/selinux_restorecon_xattr.3
|
|
|
ffbc92 |
+++ b/libselinux/man/man3/selinux_restorecon_xattr.3
|
|
|
ffbc92 |
@@ -119,7 +119,7 @@ By default
|
|
|
ffbc92 |
.BR selinux_restorecon_xattr (3)
|
|
|
ffbc92 |
will use the default set of specfiles described in
|
|
|
ffbc92 |
.BR files_contexts (5)
|
|
|
ffbc92 |
-to calculate the SHA1 digests to be used for comparison.
|
|
|
ffbc92 |
+to calculate the SHA256 digests to be used for comparison.
|
|
|
ffbc92 |
To change this default behavior
|
|
|
ffbc92 |
.BR selabel_open (3)
|
|
|
ffbc92 |
must be called specifying the required
|
|
|
ffbc92 |
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
|
|
|
05f9c5 |
index 70ba063ada5d..0c803d8d4aae 100644
|
|
|
ffbc92 |
--- a/libselinux/src/Makefile
|
|
|
ffbc92 |
+++ b/libselinux/src/Makefile
|
|
|
05f9c5 |
@@ -125,7 +125,7 @@ DISABLE_FLAGS+= -DNO_MEDIA_BACKEND -DNO_DB_BACKEND -DNO_X_BACKEND \
|
|
|
ffbc92 |
-DBUILD_HOST
|
|
|
ffbc92 |
SRCS= callbacks.c freecon.c label.c label_file.c \
|
|
|
ffbc92 |
label_backends_android.c regex.c label_support.c \
|
|
|
ffbc92 |
- matchpathcon.c setrans_client.c sha1.c booleans.c
|
|
|
ffbc92 |
+ matchpathcon.c setrans_client.c sha256.c booleans.c
|
|
|
ffbc92 |
else
|
|
|
ffbc92 |
LABEL_BACKEND_ANDROID=y
|
|
|
ffbc92 |
endif
|
|
|
ffbc92 |
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
|
|
|
1175f7 |
index 74ae9b9feb70..33d395e414f0 100644
|
|
|
ffbc92 |
--- a/libselinux/src/label_file.c
|
|
|
ffbc92 |
+++ b/libselinux/src/label_file.c
|
|
|
1175f7 |
@@ -1010,7 +1010,7 @@ static struct spec *lookup_common(struct selabel_handle *rec,
|
|
|
ffbc92 |
|
|
|
ffbc92 |
/*
|
|
|
ffbc92 |
* Returns true if the digest of all partial matched contexts is the same as
|
|
|
ffbc92 |
- * the one saved by setxattr, otherwise returns false. The length of the SHA1
|
|
|
ffbc92 |
+ * the one saved by setxattr, otherwise returns false. The length of the SHA256
|
|
|
ffbc92 |
* digest will always be returned. The caller must free any returned digests.
|
|
|
ffbc92 |
*/
|
|
|
ffbc92 |
static bool get_digests_all_partial_matches(struct selabel_handle *rec,
|
|
|
1175f7 |
@@ -1019,39 +1019,39 @@ static bool get_digests_all_partial_matches(struct selabel_handle *rec,
|
|
|
ffbc92 |
uint8_t **xattr_digest,
|
|
|
ffbc92 |
size_t *digest_len)
|
|
|
ffbc92 |
{
|
|
|
ffbc92 |
- uint8_t read_digest[SHA1_HASH_SIZE];
|
|
|
ffbc92 |
+ uint8_t read_digest[SHA256_HASH_SIZE];
|
|
|
ffbc92 |
ssize_t read_size = getxattr(pathname, RESTORECON_PARTIAL_MATCH_DIGEST,
|
|
|
ffbc92 |
- read_digest, SHA1_HASH_SIZE
|
|
|
ffbc92 |
+ read_digest, SHA256_HASH_SIZE
|
|
|
ffbc92 |
#ifdef __APPLE__
|
|
|
ffbc92 |
, 0, 0
|
|
|
ffbc92 |
#endif /* __APPLE __ */
|
|
|
ffbc92 |
);
|
|
|
ffbc92 |
- uint8_t hash_digest[SHA1_HASH_SIZE];
|
|
|
ffbc92 |
+ uint8_t hash_digest[SHA256_HASH_SIZE];
|
|
|
ffbc92 |
bool status = selabel_hash_all_partial_matches(rec, pathname,
|
|
|
ffbc92 |
hash_digest);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
*xattr_digest = NULL;
|
|
|
ffbc92 |
*calculated_digest = NULL;
|
|
|
ffbc92 |
- *digest_len = SHA1_HASH_SIZE;
|
|
|
ffbc92 |
+ *digest_len = SHA256_HASH_SIZE;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- if (read_size == SHA1_HASH_SIZE) {
|
|
|
ffbc92 |
- *xattr_digest = calloc(1, SHA1_HASH_SIZE + 1);
|
|
|
ffbc92 |
+ if (read_size == SHA256_HASH_SIZE) {
|
|
|
ffbc92 |
+ *xattr_digest = calloc(1, SHA256_HASH_SIZE + 1);
|
|
|
ffbc92 |
if (!*xattr_digest)
|
|
|
ffbc92 |
goto oom;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- memcpy(*xattr_digest, read_digest, SHA1_HASH_SIZE);
|
|
|
ffbc92 |
+ memcpy(*xattr_digest, read_digest, SHA256_HASH_SIZE);
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
if (status) {
|
|
|
ffbc92 |
- *calculated_digest = calloc(1, SHA1_HASH_SIZE + 1);
|
|
|
ffbc92 |
+ *calculated_digest = calloc(1, SHA256_HASH_SIZE + 1);
|
|
|
ffbc92 |
if (!*calculated_digest)
|
|
|
ffbc92 |
goto oom;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- memcpy(*calculated_digest, hash_digest, SHA1_HASH_SIZE);
|
|
|
ffbc92 |
+ memcpy(*calculated_digest, hash_digest, SHA256_HASH_SIZE);
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- if (status && read_size == SHA1_HASH_SIZE &&
|
|
|
ffbc92 |
- memcmp(read_digest, hash_digest, SHA1_HASH_SIZE) == 0)
|
|
|
ffbc92 |
+ if (status && read_size == SHA256_HASH_SIZE &&
|
|
|
ffbc92 |
+ memcmp(read_digest, hash_digest, SHA256_HASH_SIZE) == 0)
|
|
|
ffbc92 |
return true;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
return false;
|
|
|
1175f7 |
@@ -1071,22 +1071,22 @@ static bool hash_all_partial_matches(struct selabel_handle *rec, const char *key
|
|
|
ffbc92 |
return false;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- Sha1Context context;
|
|
|
ffbc92 |
- Sha1Initialise(&context);
|
|
|
ffbc92 |
+ Sha256Context context;
|
|
|
ffbc92 |
+ Sha256Initialise(&context);
|
|
|
ffbc92 |
size_t i;
|
|
|
ffbc92 |
for (i = 0; i < total_matches; i++) {
|
|
|
ffbc92 |
char* regex_str = matches[i]->regex_str;
|
|
|
ffbc92 |
mode_t mode = matches[i]->mode;
|
|
|
ffbc92 |
char* ctx_raw = matches[i]->lr.ctx_raw;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- Sha1Update(&context, regex_str, strlen(regex_str) + 1);
|
|
|
ffbc92 |
- Sha1Update(&context, &mode, sizeof(mode_t));
|
|
|
ffbc92 |
- Sha1Update(&context, ctx_raw, strlen(ctx_raw) + 1);
|
|
|
ffbc92 |
+ Sha256Update(&context, regex_str, strlen(regex_str) + 1);
|
|
|
ffbc92 |
+ Sha256Update(&context, &mode, sizeof(mode_t));
|
|
|
ffbc92 |
+ Sha256Update(&context, ctx_raw, strlen(ctx_raw) + 1);
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- SHA1_HASH sha1_hash;
|
|
|
ffbc92 |
- Sha1Finalise(&context, &sha1_hash);
|
|
|
ffbc92 |
- memcpy(digest, sha1_hash.bytes, SHA1_HASH_SIZE);
|
|
|
ffbc92 |
+ SHA256_HASH sha256_hash;
|
|
|
ffbc92 |
+ Sha256Finalise(&context, &sha256_hash);
|
|
|
ffbc92 |
+ memcpy(digest, sha256_hash.bytes, SHA256_HASH_SIZE);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
free(matches);
|
|
|
ffbc92 |
return true;
|
|
|
ffbc92 |
diff --git a/libselinux/src/label_internal.h b/libselinux/src/label_internal.h
|
|
|
ffbc92 |
index 782c6aa8cc0c..304e8d96490a 100644
|
|
|
ffbc92 |
--- a/libselinux/src/label_internal.h
|
|
|
ffbc92 |
+++ b/libselinux/src/label_internal.h
|
|
|
ffbc92 |
@@ -13,7 +13,7 @@
|
|
|
ffbc92 |
#include <stdio.h>
|
|
|
ffbc92 |
#include <selinux/selinux.h>
|
|
|
ffbc92 |
#include <selinux/label.h>
|
|
|
ffbc92 |
-#include "sha1.h"
|
|
|
ffbc92 |
+#include "sha256.h"
|
|
|
ffbc92 |
|
|
|
ffbc92 |
#if defined(ANDROID) || defined(__APPLE__)
|
|
|
ffbc92 |
// Android and Mac do not have fgets_unlocked()
|
|
|
ffbc92 |
@@ -47,15 +47,15 @@ int selabel_service_init(struct selabel_handle *rec,
|
|
|
ffbc92 |
*/
|
|
|
ffbc92 |
|
|
|
ffbc92 |
/*
|
|
|
ffbc92 |
- * Calculate an SHA1 hash of all the files used to build the specs.
|
|
|
ffbc92 |
+ * Calculate an SHA256 hash of all the files used to build the specs.
|
|
|
ffbc92 |
* The hash value is held in rec->digest if SELABEL_OPT_DIGEST set. To
|
|
|
ffbc92 |
* calculate the hash the hashbuf will hold a concatenation of all the files
|
|
|
ffbc92 |
* used. This is released once the value has been calculated.
|
|
|
ffbc92 |
*/
|
|
|
ffbc92 |
-#define DIGEST_SPECFILE_SIZE SHA1_HASH_SIZE
|
|
|
ffbc92 |
+#define DIGEST_SPECFILE_SIZE SHA256_HASH_SIZE
|
|
|
ffbc92 |
#define DIGEST_FILES_MAX 8
|
|
|
ffbc92 |
struct selabel_digest {
|
|
|
ffbc92 |
- unsigned char *digest; /* SHA1 digest of specfiles */
|
|
|
ffbc92 |
+ unsigned char *digest; /* SHA256 digest of specfiles */
|
|
|
ffbc92 |
unsigned char *hashbuf; /* buffer to hold specfiles */
|
|
|
ffbc92 |
size_t hashbuf_size; /* buffer size */
|
|
|
ffbc92 |
size_t specfile_cnt; /* how many specfiles processed */
|
|
|
ffbc92 |
@@ -110,7 +110,7 @@ struct selabel_handle {
|
|
|
ffbc92 |
*/
|
|
|
ffbc92 |
char *spec_file;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- /* ptr to SHA1 hash information if SELABEL_OPT_DIGEST set */
|
|
|
ffbc92 |
+ /* ptr to SHA256 hash information if SELABEL_OPT_DIGEST set */
|
|
|
ffbc92 |
struct selabel_digest *digest;
|
|
|
ffbc92 |
};
|
|
|
ffbc92 |
|
|
|
ffbc92 |
diff --git a/libselinux/src/label_support.c b/libselinux/src/label_support.c
|
|
|
1175f7 |
index 54fd49a5b7b9..4003eb8dc7af 100644
|
|
|
ffbc92 |
--- a/libselinux/src/label_support.c
|
|
|
ffbc92 |
+++ b/libselinux/src/label_support.c
|
|
|
1175f7 |
@@ -115,7 +115,7 @@ int read_spec_entries(char *line_buf, const char **errbuf, int num_args, ...)
|
|
|
ffbc92 |
/* Once all the specfiles are in the hash_buf, generate the hash. */
|
|
|
ffbc92 |
void digest_gen_hash(struct selabel_digest *digest)
|
|
|
ffbc92 |
{
|
|
|
ffbc92 |
- Sha1Context context;
|
|
|
ffbc92 |
+ Sha256Context context;
|
|
|
1175f7 |
size_t remaining_size;
|
|
|
1175f7 |
const unsigned char *ptr;
|
|
|
ffbc92 |
|
|
|
1175f7 |
@@ -123,19 +123,19 @@ void digest_gen_hash(struct selabel_digest *digest)
|
|
|
ffbc92 |
if (!digest)
|
|
|
ffbc92 |
return;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- Sha1Initialise(&context);
|
|
|
ffbc92 |
+ Sha256Initialise(&context);
|
|
|
1175f7 |
|
|
|
1175f7 |
/* Process in blocks of UINT32_MAX bytes */
|
|
|
1175f7 |
remaining_size = digest->hashbuf_size;
|
|
|
1175f7 |
ptr = digest->hashbuf;
|
|
|
1175f7 |
while (remaining_size > UINT32_MAX) {
|
|
|
1175f7 |
- Sha1Update(&context, ptr, UINT32_MAX);
|
|
|
1175f7 |
+ Sha256Update(&context, ptr, UINT32_MAX);
|
|
|
1175f7 |
remaining_size -= UINT32_MAX;
|
|
|
1175f7 |
ptr += UINT32_MAX;
|
|
|
1175f7 |
}
|
|
|
1175f7 |
- Sha1Update(&context, ptr, remaining_size);
|
|
|
1175f7 |
+ Sha256Update(&context, ptr, remaining_size);
|
|
|
1175f7 |
|
|
|
1175f7 |
- Sha1Finalise(&context, (SHA1_HASH *)digest->digest);
|
|
|
ffbc92 |
+ Sha256Finalise(&context, (SHA256_HASH *)digest->digest);
|
|
|
ffbc92 |
free(digest->hashbuf);
|
|
|
ffbc92 |
digest->hashbuf = NULL;
|
|
|
ffbc92 |
return;
|
|
|
ffbc92 |
diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
|
|
|
05f9c5 |
index 6b5f6921b82b..24604776974e 100644
|
|
|
ffbc92 |
--- a/libselinux/src/selinux_restorecon.c
|
|
|
ffbc92 |
+++ b/libselinux/src/selinux_restorecon.c
|
|
|
ffbc92 |
@@ -37,7 +37,7 @@
|
|
|
ffbc92 |
#include "callbacks.h"
|
|
|
ffbc92 |
#include "selinux_internal.h"
|
|
|
ffbc92 |
#include "label_file.h"
|
|
|
ffbc92 |
-#include "sha1.h"
|
|
|
ffbc92 |
+#include "sha256.h"
|
|
|
ffbc92 |
|
|
|
ffbc92 |
#define STAR_COUNT 1024
|
|
|
ffbc92 |
|
|
|
1175f7 |
@@ -305,7 +305,7 @@ static uint64_t exclude_non_seclabel_mounts(void)
|
|
|
ffbc92 |
static int add_xattr_entry(const char *directory, bool delete_nonmatch,
|
|
|
ffbc92 |
bool delete_all)
|
|
|
ffbc92 |
{
|
|
|
ffbc92 |
- char *sha1_buf = NULL;
|
|
|
ffbc92 |
+ char *sha256_buf = NULL;
|
|
|
ffbc92 |
size_t i, digest_len = 0;
|
|
|
1175f7 |
int rc;
|
|
|
1175f7 |
enum digest_result digest_result;
|
|
|
1175f7 |
@@ -329,15 +329,15 @@ static int add_xattr_entry(const char *directory, bool delete_nonmatch,
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
/* Convert entry to a hex encoded string. */
|
|
|
ffbc92 |
- sha1_buf = malloc(digest_len * 2 + 1);
|
|
|
ffbc92 |
- if (!sha1_buf) {
|
|
|
ffbc92 |
+ sha256_buf = malloc(digest_len * 2 + 1);
|
|
|
ffbc92 |
+ if (!sha256_buf) {
|
|
|
ffbc92 |
free(xattr_digest);
|
|
|
ffbc92 |
free(calculated_digest);
|
|
|
ffbc92 |
goto oom;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
for (i = 0; i < digest_len; i++)
|
|
|
ffbc92 |
- sprintf((&sha1_buf[i * 2]), "%02x", xattr_digest[i]);
|
|
|
ffbc92 |
+ sprintf((&sha256_buf[i * 2]), "%02x", xattr_digest[i]);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
digest_result = match ? MATCH : NOMATCH;
|
|
|
ffbc92 |
|
|
|
1175f7 |
@@ -357,7 +357,7 @@ static int add_xattr_entry(const char *directory, bool delete_nonmatch,
|
|
|
ffbc92 |
/* Now add entries to link list. */
|
|
|
ffbc92 |
new_entry = malloc(sizeof(struct dir_xattr));
|
|
|
ffbc92 |
if (!new_entry) {
|
|
|
ffbc92 |
- free(sha1_buf);
|
|
|
ffbc92 |
+ free(sha256_buf);
|
|
|
ffbc92 |
goto oom;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
new_entry->next = NULL;
|
|
|
1175f7 |
@@ -365,15 +365,15 @@ static int add_xattr_entry(const char *directory, bool delete_nonmatch,
|
|
|
ffbc92 |
new_entry->directory = strdup(directory);
|
|
|
ffbc92 |
if (!new_entry->directory) {
|
|
|
ffbc92 |
free(new_entry);
|
|
|
ffbc92 |
- free(sha1_buf);
|
|
|
ffbc92 |
+ free(sha256_buf);
|
|
|
ffbc92 |
goto oom;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- new_entry->digest = strdup(sha1_buf);
|
|
|
ffbc92 |
+ new_entry->digest = strdup(sha256_buf);
|
|
|
ffbc92 |
if (!new_entry->digest) {
|
|
|
ffbc92 |
free(new_entry->directory);
|
|
|
ffbc92 |
free(new_entry);
|
|
|
ffbc92 |
- free(sha1_buf);
|
|
|
ffbc92 |
+ free(sha256_buf);
|
|
|
ffbc92 |
goto oom;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
1175f7 |
@@ -387,7 +387,7 @@ static int add_xattr_entry(const char *directory, bool delete_nonmatch,
|
|
|
ffbc92 |
dir_xattr_last = new_entry;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- free(sha1_buf);
|
|
|
ffbc92 |
+ free(sha256_buf);
|
|
|
ffbc92 |
return 0;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
oom:
|
|
|
05f9c5 |
@@ -775,7 +775,7 @@ err:
|
|
|
ffbc92 |
|
|
|
ffbc92 |
struct dir_hash_node {
|
|
|
ffbc92 |
char *path;
|
|
|
ffbc92 |
- uint8_t digest[SHA1_HASH_SIZE];
|
|
|
ffbc92 |
+ uint8_t digest[SHA256_HASH_SIZE];
|
|
|
ffbc92 |
struct dir_hash_node *next;
|
|
|
ffbc92 |
};
|
|
|
ffbc92 |
/*
|
|
|
05f9c5 |
@@ -1281,7 +1281,7 @@ static int selinux_restorecon_common(const char *pathname_orig,
|
|
|
ffbc92 |
if (setxattr(current->path,
|
|
|
ffbc92 |
RESTORECON_PARTIAL_MATCH_DIGEST,
|
|
|
ffbc92 |
current->digest,
|
|
|
ffbc92 |
- SHA1_HASH_SIZE, 0) < 0) {
|
|
|
ffbc92 |
+ SHA256_HASH_SIZE, 0) < 0) {
|
|
|
ffbc92 |
selinux_log(SELINUX_ERROR,
|
|
|
db4930 |
"setxattr failed: %s: %m\n",
|
|
|
db4930 |
current->path);
|
|
|
ffbc92 |
diff --git a/libselinux/src/sha1.c b/libselinux/src/sha1.c
|
|
|
ffbc92 |
deleted file mode 100644
|
|
|
05f9c5 |
index 9d51e04ac331..000000000000
|
|
|
ffbc92 |
--- a/libselinux/src/sha1.c
|
|
|
ffbc92 |
+++ /dev/null
|
|
|
ffbc92 |
@@ -1,220 +0,0 @@
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// LibSha1
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Implementation of SHA1 hash function.
|
|
|
ffbc92 |
-// Original author: Steve Reid <sreid@sea-to-sky.net>
|
|
|
ffbc92 |
-// Contributions by: James H. Brown <jbrown@burgoyne.com>, Saul Kravitz <Saul.Kravitz@celera.com>,
|
|
|
ffbc92 |
-// and Ralph Giles <giles@ghostscript.com>
|
|
|
ffbc92 |
-// Modified by WaterJuice retaining Public Domain license.
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
|
ffbc92 |
-// Modified to:
|
|
|
ffbc92 |
-// - stop symbols being exported for libselinux shared library - October 2015
|
|
|
ffbc92 |
-// Richard Haines <richard_c_haines@btinternet.com>
|
|
|
05f9c5 |
-// - Not cast the workspace from a byte array to a CHAR64LONG16 due to alignment issues.
|
|
|
ffbc92 |
-// Fixes:
|
|
|
ffbc92 |
-// sha1.c:73:33: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'CHAR64LONG16 *' increases required alignment from 1 to 4 [-Werror,-Wcast-align]
|
|
|
ffbc92 |
-// CHAR64LONG16* block = (CHAR64LONG16*) workspace;
|
|
|
ffbc92 |
-// William Roberts <william.c.roberts@intel.com>
|
|
|
ffbc92 |
-// - Silence clang's -Wextra-semi-stmt warning - July 2021, Nicolas Iooss <nicolas.iooss@m4x.org>
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// IMPORTS
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-#include "sha1.h"
|
|
|
ffbc92 |
-#include <memory.h>
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// TYPES
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-typedef union
|
|
|
ffbc92 |
-{
|
|
|
ffbc92 |
- uint8_t c [64];
|
|
|
ffbc92 |
- uint32_t l [16];
|
|
|
ffbc92 |
-} CHAR64LONG16;
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// INTERNAL FUNCTIONS
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-// blk0() and blk() perform the initial expand.
|
|
|
ffbc92 |
-#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|
|
|
ffbc92 |
- |(rol(block->l[i],8)&0x00FF00FF))
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
|
|
ffbc92 |
- ^block->l[(i+2)&15]^block->l[i&15],1))
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-// (R0+R1), R2, R3, R4 are the different operations used in SHA1
|
|
|
ffbc92 |
-#define R0(v,w,x,y,z,i) do { z += ((w&(x^y))^y) + blk0(i)+ 0x5A827999 + rol(v,5); w=rol(w,30); } while (0)
|
|
|
ffbc92 |
-#define R1(v,w,x,y,z,i) do { z += ((w&(x^y))^y) + blk(i) + 0x5A827999 + rol(v,5); w=rol(w,30); } while (0)
|
|
|
ffbc92 |
-#define R2(v,w,x,y,z,i) do { z += (w^x^y) + blk(i) + 0x6ED9EBA1 + rol(v,5); w=rol(w,30); } while (0)
|
|
|
ffbc92 |
-#define R3(v,w,x,y,z,i) do { z += (((w|x)&y)|(w&x)) + blk(i) + 0x8F1BBCDC + rol(v,5); w=rol(w,30); } while (0)
|
|
|
ffbc92 |
-#define R4(v,w,x,y,z,i) do { z += (w^x^y) + blk(i) + 0xCA62C1D6 + rol(v,5); w=rol(w,30); } while (0)
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// TransformFunction
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Hash a single 512-bit block. This is the core of the algorithm
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-static
|
|
|
ffbc92 |
-void
|
|
|
ffbc92 |
- TransformFunction
|
|
|
ffbc92 |
- (
|
|
|
ffbc92 |
- uint32_t state[5],
|
|
|
ffbc92 |
- const uint8_t buffer[64]
|
|
|
ffbc92 |
- )
|
|
|
ffbc92 |
-{
|
|
|
ffbc92 |
- uint32_t a;
|
|
|
ffbc92 |
- uint32_t b;
|
|
|
ffbc92 |
- uint32_t c;
|
|
|
ffbc92 |
- uint32_t d;
|
|
|
ffbc92 |
- uint32_t e;
|
|
|
ffbc92 |
- CHAR64LONG16 workspace;
|
|
|
ffbc92 |
- CHAR64LONG16* block = &workspace;
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- memcpy(block, buffer, 64);
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- // Copy context->state[] to working vars
|
|
|
ffbc92 |
- a = state[0];
|
|
|
ffbc92 |
- b = state[1];
|
|
|
ffbc92 |
- c = state[2];
|
|
|
ffbc92 |
- d = state[3];
|
|
|
ffbc92 |
- e = state[4];
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- // 4 rounds of 20 operations each. Loop unrolled.
|
|
|
ffbc92 |
- R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
|
|
|
ffbc92 |
- R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
|
|
|
ffbc92 |
- R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
|
|
|
ffbc92 |
- R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
|
|
|
ffbc92 |
- R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
|
|
ffbc92 |
- R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
|
|
|
ffbc92 |
- R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
|
|
|
ffbc92 |
- R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
|
|
|
ffbc92 |
- R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
|
|
|
ffbc92 |
- R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
|
|
|
ffbc92 |
- R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
|
|
|
ffbc92 |
- R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
|
|
|
ffbc92 |
- R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
|
|
|
ffbc92 |
- R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
|
|
|
ffbc92 |
- R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
|
|
|
ffbc92 |
- R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
|
|
|
ffbc92 |
- R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
|
|
|
ffbc92 |
- R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
|
|
|
ffbc92 |
- R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
|
|
|
ffbc92 |
- R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- // Add the working vars back into context.state[]
|
|
|
ffbc92 |
- state[0] += a;
|
|
|
ffbc92 |
- state[1] += b;
|
|
|
ffbc92 |
- state[2] += c;
|
|
|
ffbc92 |
- state[3] += d;
|
|
|
ffbc92 |
- state[4] += e;
|
|
|
ffbc92 |
-}
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// PUBLIC FUNCTIONS
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// Sha1Initialise
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Initialises an SHA1 Context. Use this to initialise/reset a context.
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-void
|
|
|
ffbc92 |
- Sha1Initialise
|
|
|
ffbc92 |
- (
|
|
|
ffbc92 |
- Sha1Context* Context
|
|
|
ffbc92 |
- )
|
|
|
ffbc92 |
-{
|
|
|
ffbc92 |
- // SHA1 initialization constants
|
|
|
ffbc92 |
- Context->State[0] = 0x67452301;
|
|
|
ffbc92 |
- Context->State[1] = 0xEFCDAB89;
|
|
|
ffbc92 |
- Context->State[2] = 0x98BADCFE;
|
|
|
ffbc92 |
- Context->State[3] = 0x10325476;
|
|
|
ffbc92 |
- Context->State[4] = 0xC3D2E1F0;
|
|
|
ffbc92 |
- Context->Count[0] = 0;
|
|
|
ffbc92 |
- Context->Count[1] = 0;
|
|
|
ffbc92 |
-}
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// Sha1Update
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Adds data to the SHA1 context. This will process the data and update the internal state of the context. Keep on
|
|
|
ffbc92 |
-// calling this function until all the data has been added. Then call Sha1Finalise to calculate the hash.
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-void
|
|
|
ffbc92 |
- Sha1Update
|
|
|
ffbc92 |
- (
|
|
|
ffbc92 |
- Sha1Context* Context,
|
|
|
ffbc92 |
- const void* Buffer,
|
|
|
ffbc92 |
- uint32_t BufferSize
|
|
|
ffbc92 |
- )
|
|
|
ffbc92 |
-{
|
|
|
ffbc92 |
- uint32_t i;
|
|
|
ffbc92 |
- uint32_t j;
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- j = (Context->Count[0] >> 3) & 63;
|
|
|
ffbc92 |
- if ((Context->Count[0] += BufferSize << 3) < (BufferSize << 3))
|
|
|
ffbc92 |
- {
|
|
|
ffbc92 |
- Context->Count[1]++;
|
|
|
ffbc92 |
- }
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- Context->Count[1] += (BufferSize >> 29);
|
|
|
ffbc92 |
- if ((j + BufferSize) > 63)
|
|
|
ffbc92 |
- {
|
|
|
ffbc92 |
- i = 64 - j;
|
|
|
ffbc92 |
- memcpy(&Context->Buffer[j], Buffer, i);
|
|
|
ffbc92 |
- TransformFunction(Context->State, Context->Buffer);
|
|
|
ffbc92 |
- for (; i + 63 < BufferSize; i += 64)
|
|
|
ffbc92 |
- {
|
|
|
ffbc92 |
- TransformFunction(Context->State, (const uint8_t*)Buffer + i);
|
|
|
ffbc92 |
- }
|
|
|
ffbc92 |
- j = 0;
|
|
|
ffbc92 |
- }
|
|
|
ffbc92 |
- else
|
|
|
ffbc92 |
- {
|
|
|
ffbc92 |
- i = 0;
|
|
|
ffbc92 |
- }
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- memcpy(&Context->Buffer[j], &((const uint8_t*)Buffer)[i], BufferSize - i);
|
|
|
ffbc92 |
-}
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// Sha1Finalise
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Performs the final calculation of the hash and returns the digest (20 byte buffer containing 160bit hash). After
|
|
|
ffbc92 |
-// calling this, Sha1Initialised must be used to reuse the context.
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-void
|
|
|
ffbc92 |
- Sha1Finalise
|
|
|
ffbc92 |
- (
|
|
|
ffbc92 |
- Sha1Context* Context,
|
|
|
ffbc92 |
- SHA1_HASH* Digest
|
|
|
ffbc92 |
- )
|
|
|
ffbc92 |
-{
|
|
|
ffbc92 |
- uint32_t i;
|
|
|
ffbc92 |
- uint8_t finalcount[8];
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- for (i = 0; i < 8; i++)
|
|
|
ffbc92 |
- {
|
|
|
ffbc92 |
- finalcount[i] = (unsigned char)((Context->Count[(i >= 4 ? 0 : 1)]
|
|
|
ffbc92 |
- >> ((3-(i & 3)) * 8) ) & 255); // Endian independent
|
|
|
ffbc92 |
- }
|
|
|
ffbc92 |
- Sha1Update(Context, (const uint8_t*)"\x80", 1);
|
|
|
ffbc92 |
- while ((Context->Count[0] & 504) != 448)
|
|
|
ffbc92 |
- {
|
|
|
ffbc92 |
- Sha1Update(Context, (const uint8_t*)"\0", 1);
|
|
|
ffbc92 |
- }
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
- Sha1Update(Context, finalcount, 8); // Should cause a Sha1TransformFunction()
|
|
|
ffbc92 |
- for (i = 0; i < SHA1_HASH_SIZE; i++)
|
|
|
ffbc92 |
- {
|
|
|
ffbc92 |
- Digest->bytes[i] = (uint8_t)((Context->State[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
|
|
ffbc92 |
- }
|
|
|
ffbc92 |
-}
|
|
|
ffbc92 |
diff --git a/libselinux/src/sha1.h b/libselinux/src/sha1.h
|
|
|
ffbc92 |
deleted file mode 100644
|
|
|
ffbc92 |
index f83a6e7ed7ba..000000000000
|
|
|
ffbc92 |
--- a/libselinux/src/sha1.h
|
|
|
ffbc92 |
+++ /dev/null
|
|
|
ffbc92 |
@@ -1,85 +0,0 @@
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// LibSha1
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Implementation of SHA1 hash function.
|
|
|
ffbc92 |
-// Original author: Steve Reid <sreid@sea-to-sky.net>
|
|
|
ffbc92 |
-// Contributions by: James H. Brown <jbrown@burgoyne.com>, Saul Kravitz <Saul.Kravitz@celera.com>,
|
|
|
ffbc92 |
-// and Ralph Giles <giles@ghostscript.com>
|
|
|
ffbc92 |
-// Modified by WaterJuice retaining Public Domain license.
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-#ifndef _sha1_h_
|
|
|
ffbc92 |
-#define _sha1_h_
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// IMPORTS
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-#include <stdint.h>
|
|
|
ffbc92 |
-#include <stdio.h>
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// TYPES
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-// Sha1Context - This must be initialised using Sha1Initialised. Do not modify the contents of this structure directly.
|
|
|
ffbc92 |
-typedef struct
|
|
|
ffbc92 |
-{
|
|
|
ffbc92 |
- uint32_t State[5];
|
|
|
ffbc92 |
- uint32_t Count[2];
|
|
|
ffbc92 |
- uint8_t Buffer[64];
|
|
|
ffbc92 |
-} Sha1Context;
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-#define SHA1_HASH_SIZE ( 160 / 8 )
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-typedef struct
|
|
|
ffbc92 |
-{
|
|
|
ffbc92 |
- uint8_t bytes [SHA1_HASH_SIZE];
|
|
|
ffbc92 |
-} SHA1_HASH;
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// PUBLIC FUNCTIONS
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// Sha1Initialise
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Initialises an SHA1 Context. Use this to initialise/reset a context.
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-void
|
|
|
ffbc92 |
- Sha1Initialise
|
|
|
ffbc92 |
- (
|
|
|
ffbc92 |
- Sha1Context* Context
|
|
|
ffbc92 |
- );
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// Sha1Update
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Adds data to the SHA1 context. This will process the data and update the internal state of the context. Keep on
|
|
|
ffbc92 |
-// calling this function until all the data has been added. Then call Sha1Finalise to calculate the hash.
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-void
|
|
|
ffbc92 |
- Sha1Update
|
|
|
ffbc92 |
- (
|
|
|
ffbc92 |
- Sha1Context* Context,
|
|
|
ffbc92 |
- const void* Buffer,
|
|
|
ffbc92 |
- uint32_t BufferSize
|
|
|
ffbc92 |
- );
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-// Sha1Finalise
|
|
|
ffbc92 |
-//
|
|
|
ffbc92 |
-// Performs the final calculation of the hash and returns the digest (20 byte buffer containing 160bit hash). After
|
|
|
ffbc92 |
-// calling this, Sha1Initialised must be used to reuse the context.
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-void
|
|
|
ffbc92 |
- Sha1Finalise
|
|
|
ffbc92 |
- (
|
|
|
ffbc92 |
- Sha1Context* Context,
|
|
|
ffbc92 |
- SHA1_HASH* Digest
|
|
|
ffbc92 |
- );
|
|
|
ffbc92 |
-
|
|
|
ffbc92 |
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
-#endif //_sha1_h_
|
|
|
ffbc92 |
diff --git a/libselinux/src/sha256.c b/libselinux/src/sha256.c
|
|
|
ffbc92 |
new file mode 100644
|
|
|
ffbc92 |
index 000000000000..fe2aeef07f53
|
|
|
ffbc92 |
--- /dev/null
|
|
|
ffbc92 |
+++ b/libselinux/src/sha256.c
|
|
|
ffbc92 |
@@ -0,0 +1,294 @@
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// WjCryptLib_Sha256
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Implementation of SHA256 hash function.
|
|
|
ffbc92 |
+// Original author: Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
|
|
ffbc92 |
+// Modified by WaterJuice retaining Public Domain license.
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// IMPORTS
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#include "sha256.h"
|
|
|
ffbc92 |
+#include <memory.h>
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// MACROS
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define ror(value, bits) (((value) >> (bits)) | ((value) << (32 - (bits))))
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define MIN(x, y) ( ((x)<(y))?(x):(y) )
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define STORE32H(x, y) \
|
|
|
ffbc92 |
+ { (y)[0] = (uint8_t)(((x)>>24)&255); (y)[1] = (uint8_t)(((x)>>16)&255); \
|
|
|
ffbc92 |
+ (y)[2] = (uint8_t)(((x)>>8)&255); (y)[3] = (uint8_t)((x)&255); }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define LOAD32H(x, y) \
|
|
|
ffbc92 |
+ { x = ((uint32_t)((y)[0] & 255)<<24) | \
|
|
|
ffbc92 |
+ ((uint32_t)((y)[1] & 255)<<16) | \
|
|
|
ffbc92 |
+ ((uint32_t)((y)[2] & 255)<<8) | \
|
|
|
ffbc92 |
+ ((uint32_t)((y)[3] & 255)); }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define STORE64H(x, y) \
|
|
|
ffbc92 |
+ { (y)[0] = (uint8_t)(((x)>>56)&255); (y)[1] = (uint8_t)(((x)>>48)&255); \
|
|
|
ffbc92 |
+ (y)[2] = (uint8_t)(((x)>>40)&255); (y)[3] = (uint8_t)(((x)>>32)&255); \
|
|
|
ffbc92 |
+ (y)[4] = (uint8_t)(((x)>>24)&255); (y)[5] = (uint8_t)(((x)>>16)&255); \
|
|
|
ffbc92 |
+ (y)[6] = (uint8_t)(((x)>>8)&255); (y)[7] = (uint8_t)((x)&255); }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// CONSTANTS
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+// The K array
|
|
|
ffbc92 |
+static const uint32_t K[64] = {
|
|
|
ffbc92 |
+ 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
|
|
|
ffbc92 |
+ 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
|
|
|
ffbc92 |
+ 0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
|
|
|
ffbc92 |
+ 0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
|
|
|
ffbc92 |
+ 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
|
|
|
ffbc92 |
+ 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
|
|
|
ffbc92 |
+ 0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
|
|
|
ffbc92 |
+ 0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
|
|
|
ffbc92 |
+ 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
|
|
|
ffbc92 |
+ 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
|
|
|
ffbc92 |
+ 0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
|
|
|
ffbc92 |
+ 0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
|
|
|
ffbc92 |
+ 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
|
|
|
ffbc92 |
+};
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define BLOCK_SIZE 64
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// INTERNAL FUNCTIONS
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+// Various logical functions
|
|
|
ffbc92 |
+#define Ch( x, y, z ) (z ^ (x & (y ^ z)))
|
|
|
ffbc92 |
+#define Maj( x, y, z ) (((x | y) & z) | (x & y))
|
|
|
ffbc92 |
+#define S( x, n ) ror((x),(n))
|
|
|
ffbc92 |
+#define R( x, n ) (((x)&0xFFFFFFFFUL)>>(n))
|
|
|
ffbc92 |
+#define Sigma0( x ) (S(x, 2) ^ S(x, 13) ^ S(x, 22))
|
|
|
ffbc92 |
+#define Sigma1( x ) (S(x, 6) ^ S(x, 11) ^ S(x, 25))
|
|
|
ffbc92 |
+#define Gamma0( x ) (S(x, 7) ^ S(x, 18) ^ R(x, 3))
|
|
|
ffbc92 |
+#define Gamma1( x ) (S(x, 17) ^ S(x, 19) ^ R(x, 10))
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define Sha256Round( a, b, c, d, e, f, g, h, i ) \
|
|
|
ffbc92 |
+ t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
|
|
|
ffbc92 |
+ t1 = Sigma0(a) + Maj(a, b, c); \
|
|
|
ffbc92 |
+ d += t0; \
|
|
|
ffbc92 |
+ h = t0 + t1;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// TransformFunction
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Compress 512-bits
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+static
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ TransformFunction
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ Sha256Context* Context,
|
|
|
ffbc92 |
+ uint8_t const* Buffer
|
|
|
ffbc92 |
+ )
|
|
|
ffbc92 |
+{
|
|
|
ffbc92 |
+ uint32_t S[8];
|
|
|
ffbc92 |
+ uint32_t W[64];
|
|
|
ffbc92 |
+ uint32_t t0;
|
|
|
ffbc92 |
+ uint32_t t1;
|
|
|
ffbc92 |
+ uint32_t t;
|
|
|
ffbc92 |
+ int i;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Copy state into S
|
|
|
ffbc92 |
+ for( i=0; i<8; i++ )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ S[i] = Context->state[i];
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Copy the state into 512-bits into W[0..15]
|
|
|
ffbc92 |
+ for( i=0; i<16; i++ )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ LOAD32H( W[i], Buffer + (4*i) );
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Fill W[16..63]
|
|
|
ffbc92 |
+ for( i=16; i<64; i++ )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ W[i] = Gamma1( W[i-2]) + W[i-7] + Gamma0( W[i-15] ) + W[i-16];
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Compress
|
|
|
ffbc92 |
+ for( i=0; i<64; i++ )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ Sha256Round( S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i );
|
|
|
ffbc92 |
+ t = S[7];
|
|
|
ffbc92 |
+ S[7] = S[6];
|
|
|
ffbc92 |
+ S[6] = S[5];
|
|
|
ffbc92 |
+ S[5] = S[4];
|
|
|
ffbc92 |
+ S[4] = S[3];
|
|
|
ffbc92 |
+ S[3] = S[2];
|
|
|
ffbc92 |
+ S[2] = S[1];
|
|
|
ffbc92 |
+ S[1] = S[0];
|
|
|
ffbc92 |
+ S[0] = t;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Feedback
|
|
|
ffbc92 |
+ for( i=0; i<8; i++ )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ Context->state[i] = Context->state[i] + S[i];
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+}
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// PUBLIC FUNCTIONS
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Initialise
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Initialises a SHA256 Context. Use this to initialise/reset a context.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Initialise
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ Sha256Context* Context // [out]
|
|
|
ffbc92 |
+ )
|
|
|
ffbc92 |
+{
|
|
|
ffbc92 |
+ Context->curlen = 0;
|
|
|
ffbc92 |
+ Context->length = 0;
|
|
|
ffbc92 |
+ Context->state[0] = 0x6A09E667UL;
|
|
|
ffbc92 |
+ Context->state[1] = 0xBB67AE85UL;
|
|
|
ffbc92 |
+ Context->state[2] = 0x3C6EF372UL;
|
|
|
ffbc92 |
+ Context->state[3] = 0xA54FF53AUL;
|
|
|
ffbc92 |
+ Context->state[4] = 0x510E527FUL;
|
|
|
ffbc92 |
+ Context->state[5] = 0x9B05688CUL;
|
|
|
ffbc92 |
+ Context->state[6] = 0x1F83D9ABUL;
|
|
|
ffbc92 |
+ Context->state[7] = 0x5BE0CD19UL;
|
|
|
ffbc92 |
+}
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Update
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Adds data to the SHA256 context. This will process the data and update the internal state of the context. Keep on
|
|
|
ffbc92 |
+// calling this function until all the data has been added. Then call Sha256Finalise to calculate the hash.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Update
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ Sha256Context* Context, // [in out]
|
|
|
ffbc92 |
+ void const* Buffer, // [in]
|
|
|
ffbc92 |
+ uint32_t BufferSize // [in]
|
|
|
ffbc92 |
+ )
|
|
|
ffbc92 |
+{
|
|
|
ffbc92 |
+ uint32_t n;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ if( Context->curlen > sizeof(Context->buf) )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ return;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ while( BufferSize > 0 )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ if( Context->curlen == 0 && BufferSize >= BLOCK_SIZE )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ TransformFunction( Context, (uint8_t*)Buffer );
|
|
|
ffbc92 |
+ Context->length += BLOCK_SIZE * 8;
|
|
|
ffbc92 |
+ Buffer = (uint8_t*)Buffer + BLOCK_SIZE;
|
|
|
ffbc92 |
+ BufferSize -= BLOCK_SIZE;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+ else
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ n = MIN( BufferSize, (BLOCK_SIZE - Context->curlen) );
|
|
|
ffbc92 |
+ memcpy( Context->buf + Context->curlen, Buffer, (size_t)n );
|
|
|
ffbc92 |
+ Context->curlen += n;
|
|
|
ffbc92 |
+ Buffer = (uint8_t*)Buffer + n;
|
|
|
ffbc92 |
+ BufferSize -= n;
|
|
|
ffbc92 |
+ if( Context->curlen == BLOCK_SIZE )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ TransformFunction( Context, Context->buf );
|
|
|
ffbc92 |
+ Context->length += 8*BLOCK_SIZE;
|
|
|
ffbc92 |
+ Context->curlen = 0;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+}
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Finalise
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Performs the final calculation of the hash and returns the digest (32 byte buffer containing 256bit hash). After
|
|
|
ffbc92 |
+// calling this, Sha256Initialised must be used to reuse the context.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Finalise
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ Sha256Context* Context, // [in out]
|
|
|
ffbc92 |
+ SHA256_HASH* Digest // [out]
|
|
|
ffbc92 |
+ )
|
|
|
ffbc92 |
+{
|
|
|
ffbc92 |
+ int i;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ if( Context->curlen >= sizeof(Context->buf) )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ return;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Increase the length of the message
|
|
|
ffbc92 |
+ Context->length += Context->curlen * 8;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Append the '1' bit
|
|
|
ffbc92 |
+ Context->buf[Context->curlen++] = (uint8_t)0x80;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // if the length is currently above 56 bytes we append zeros
|
|
|
ffbc92 |
+ // then compress. Then we can fall back to padding zeros and length
|
|
|
ffbc92 |
+ // encoding like normal.
|
|
|
ffbc92 |
+ if( Context->curlen > 56 )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ while( Context->curlen < 64 )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ Context->buf[Context->curlen++] = (uint8_t)0;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+ TransformFunction(Context, Context->buf);
|
|
|
ffbc92 |
+ Context->curlen = 0;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Pad up to 56 bytes of zeroes
|
|
|
ffbc92 |
+ while( Context->curlen < 56 )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ Context->buf[Context->curlen++] = (uint8_t)0;
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Store length
|
|
|
ffbc92 |
+ STORE64H( Context->length, Context->buf+56 );
|
|
|
ffbc92 |
+ TransformFunction( Context, Context->buf );
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ // Copy output
|
|
|
ffbc92 |
+ for( i=0; i<8; i++ )
|
|
|
ffbc92 |
+ {
|
|
|
ffbc92 |
+ STORE32H( Context->state[i], Digest->bytes+(4*i) );
|
|
|
ffbc92 |
+ }
|
|
|
ffbc92 |
+}
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Calculate
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Combines Sha256Initialise, Sha256Update, and Sha256Finalise into one function. Calculates the SHA256 hash of the
|
|
|
ffbc92 |
+// buffer.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Calculate
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ void const* Buffer, // [in]
|
|
|
ffbc92 |
+ uint32_t BufferSize, // [in]
|
|
|
ffbc92 |
+ SHA256_HASH* Digest // [in]
|
|
|
ffbc92 |
+ )
|
|
|
ffbc92 |
+{
|
|
|
ffbc92 |
+ Sha256Context context;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+ Sha256Initialise( &context );
|
|
|
ffbc92 |
+ Sha256Update( &context, Buffer, BufferSize );
|
|
|
ffbc92 |
+ Sha256Finalise( &context, Digest );
|
|
|
ffbc92 |
+}
|
|
|
ffbc92 |
diff --git a/libselinux/src/sha256.h b/libselinux/src/sha256.h
|
|
|
ffbc92 |
new file mode 100644
|
|
|
ffbc92 |
index 000000000000..406ed869cd82
|
|
|
ffbc92 |
--- /dev/null
|
|
|
ffbc92 |
+++ b/libselinux/src/sha256.h
|
|
|
ffbc92 |
@@ -0,0 +1,89 @@
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// WjCryptLib_Sha256
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Implementation of SHA256 hash function.
|
|
|
ffbc92 |
+// Original author: Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
|
|
ffbc92 |
+// Modified by WaterJuice retaining Public Domain license.
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#pragma once
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// IMPORTS
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#include <stdint.h>
|
|
|
ffbc92 |
+#include <stdio.h>
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+typedef struct
|
|
|
ffbc92 |
+{
|
|
|
ffbc92 |
+ uint64_t length;
|
|
|
ffbc92 |
+ uint32_t state[8];
|
|
|
ffbc92 |
+ uint32_t curlen;
|
|
|
ffbc92 |
+ uint8_t buf[64];
|
|
|
ffbc92 |
+} Sha256Context;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+#define SHA256_HASH_SIZE ( 256 / 8 )
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+typedef struct
|
|
|
ffbc92 |
+{
|
|
|
ffbc92 |
+ uint8_t bytes [SHA256_HASH_SIZE];
|
|
|
ffbc92 |
+} SHA256_HASH;
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// PUBLIC FUNCTIONS
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Initialise
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Initialises a SHA256 Context. Use this to initialise/reset a context.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Initialise
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ Sha256Context* Context // [out]
|
|
|
ffbc92 |
+ );
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Update
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Adds data to the SHA256 context. This will process the data and update the internal state of the context. Keep on
|
|
|
ffbc92 |
+// calling this function until all the data has been added. Then call Sha256Finalise to calculate the hash.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Update
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ Sha256Context* Context, // [in out]
|
|
|
ffbc92 |
+ void const* Buffer, // [in]
|
|
|
ffbc92 |
+ uint32_t BufferSize // [in]
|
|
|
ffbc92 |
+ );
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Finalise
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Performs the final calculation of the hash and returns the digest (32 byte buffer containing 256bit hash). After
|
|
|
ffbc92 |
+// calling this, Sha256Initialised must be used to reuse the context.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Finalise
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ Sha256Context* Context, // [in out]
|
|
|
ffbc92 |
+ SHA256_HASH* Digest // [out]
|
|
|
ffbc92 |
+ );
|
|
|
ffbc92 |
+
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+// Sha256Calculate
|
|
|
ffbc92 |
+//
|
|
|
ffbc92 |
+// Combines Sha256Initialise, Sha256Update, and Sha256Finalise into one function. Calculates the SHA256 hash of the
|
|
|
ffbc92 |
+// buffer.
|
|
|
ffbc92 |
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
ffbc92 |
+void
|
|
|
ffbc92 |
+ Sha256Calculate
|
|
|
ffbc92 |
+ (
|
|
|
ffbc92 |
+ void const* Buffer, // [in]
|
|
|
ffbc92 |
+ uint32_t BufferSize, // [in]
|
|
|
ffbc92 |
+ SHA256_HASH* Digest // [in]
|
|
|
ffbc92 |
+ );
|
|
|
ffbc92 |
diff --git a/libselinux/utils/selabel_digest.c b/libselinux/utils/selabel_digest.c
|
|
|
1175f7 |
index 6a8313a2c88d..a69331f1c6b5 100644
|
|
|
ffbc92 |
--- a/libselinux/utils/selabel_digest.c
|
|
|
ffbc92 |
+++ b/libselinux/utils/selabel_digest.c
|
|
|
ffbc92 |
@@ -15,8 +15,8 @@ static __attribute__ ((__noreturn__)) void usage(const char *progname)
|
|
|
ffbc92 |
"Where:\n\t"
|
|
|
ffbc92 |
"-b The backend - \"file\", \"media\", \"x\", \"db\" or "
|
|
|
ffbc92 |
"\"prop\"\n\t"
|
|
|
ffbc92 |
- "-v Run \"cat <specfile_list> | openssl dgst -sha1 -hex\"\n\t"
|
|
|
ffbc92 |
- " on the list of specfiles to compare the SHA1 digests.\n\t"
|
|
|
ffbc92 |
+ "-v Run \"cat <specfile_list> | openssl dgst -sha256 -hex\"\n\t"
|
|
|
ffbc92 |
+ " on the list of specfiles to compare the SHA256 digests.\n\t"
|
|
|
ffbc92 |
"-B Use base specfiles only (valid for \"-b file\" only).\n\t"
|
|
|
ffbc92 |
"-i Do not request a digest.\n\t"
|
|
|
ffbc92 |
"-f Optional file containing the specs (defaults to\n\t"
|
|
|
ffbc92 |
@@ -62,12 +62,12 @@ int main(int argc, char **argv)
|
|
|
ffbc92 |
int backend = 0, rc, opt, validate = 0;
|
|
|
ffbc92 |
char *baseonly = NULL, *file = NULL, *digest = (char *)1;
|
|
|
ffbc92 |
char **specfiles = NULL;
|
|
|
ffbc92 |
- unsigned char *sha1_digest = NULL;
|
|
|
ffbc92 |
+ unsigned char *sha256_digest = NULL;
|
|
|
ffbc92 |
size_t i, num_specfiles;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
char cmd_buf[4096];
|
|
|
ffbc92 |
char *cmd_ptr;
|
|
|
ffbc92 |
- char *sha1_buf;
|
|
|
ffbc92 |
+ char *sha256_buf;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
struct selabel_handle *hnd;
|
|
|
ffbc92 |
struct selinux_opt selabel_option[] = {
|
|
|
ffbc92 |
@@ -137,7 +137,7 @@ int main(int argc, char **argv)
|
|
|
ffbc92 |
return -1;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- rc = selabel_digest(hnd, &sha1_digest, &digest_len, &specfiles,
|
|
|
ffbc92 |
+ rc = selabel_digest(hnd, &sha256_digest, &digest_len, &specfiles,
|
|
|
ffbc92 |
&num_specfiles);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
if (rc) {
|
|
|
ffbc92 |
@@ -152,19 +152,19 @@ int main(int argc, char **argv)
|
|
|
ffbc92 |
goto err;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- sha1_buf = malloc(digest_len * 2 + 1);
|
|
|
ffbc92 |
- if (!sha1_buf) {
|
|
|
ffbc92 |
+ sha256_buf = malloc(digest_len * 2 + 1);
|
|
|
ffbc92 |
+ if (!sha256_buf) {
|
|
|
ffbc92 |
fprintf(stderr, "Could not malloc buffer ERROR: %s\n",
|
|
|
ffbc92 |
strerror(errno));
|
|
|
ffbc92 |
rc = -1;
|
|
|
ffbc92 |
goto err;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- printf("SHA1 digest: ");
|
|
|
ffbc92 |
+ printf("SHA256 digest: ");
|
|
|
ffbc92 |
for (i = 0; i < digest_len; i++)
|
|
|
ffbc92 |
- sprintf(&(sha1_buf[i * 2]), "%02x", sha1_digest[i]);
|
|
|
ffbc92 |
+ sprintf(&(sha256_buf[i * 2]), "%02x", sha256_digest[i]);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- printf("%s\n", sha1_buf);
|
|
|
ffbc92 |
+ printf("%s\n", sha256_buf);
|
|
|
ffbc92 |
printf("calculated using the following specfile(s):\n");
|
|
|
ffbc92 |
|
|
|
ffbc92 |
if (specfiles) {
|
|
|
ffbc92 |
@@ -177,13 +177,13 @@ int main(int argc, char **argv)
|
|
|
ffbc92 |
cmd_ptr += strlen(specfiles[i]) + 1;
|
|
|
ffbc92 |
printf("%s\n", specfiles[i]);
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
- sprintf(cmd_ptr, "| /usr/bin/openssl dgst -sha1 -hex");
|
|
|
ffbc92 |
+ sprintf(cmd_ptr, "| /usr/bin/openssl dgst -sha256 -hex");
|
|
|
ffbc92 |
|
|
|
ffbc92 |
if (validate)
|
|
|
ffbc92 |
- rc = run_check_digest(cmd_buf, sha1_buf);
|
|
|
ffbc92 |
+ rc = run_check_digest(cmd_buf, sha256_buf);
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- free(sha1_buf);
|
|
|
ffbc92 |
+ free(sha256_buf);
|
|
|
ffbc92 |
err:
|
|
|
ffbc92 |
selabel_close(hnd);
|
|
|
ffbc92 |
return rc;
|
|
|
ffbc92 |
diff --git a/libselinux/utils/selabel_get_digests_all_partial_matches.c b/libselinux/utils/selabel_get_digests_all_partial_matches.c
|
|
|
1175f7 |
index c4e0f836b260..80723f714264 100644
|
|
|
ffbc92 |
--- a/libselinux/utils/selabel_get_digests_all_partial_matches.c
|
|
|
ffbc92 |
+++ b/libselinux/utils/selabel_get_digests_all_partial_matches.c
|
|
|
ffbc92 |
@@ -18,8 +18,8 @@ static __attribute__ ((__noreturn__)) void usage(const char *progname)
|
|
|
ffbc92 |
"-v Validate file_contxts entries against loaded policy.\n\t"
|
|
|
ffbc92 |
"-r Recursively descend directories.\n\t"
|
|
|
ffbc92 |
"-f Optional file_contexts file (defaults to current policy).\n\t"
|
|
|
ffbc92 |
- "path Path to check current SHA1 digest against file_contexts entries.\n\n"
|
|
|
ffbc92 |
- "This will check the directory selinux.sehash SHA1 digest for "
|
|
|
ffbc92 |
+ "path Path to check current SHA256 digest against file_contexts entries.\n\n"
|
|
|
ffbc92 |
+ "This will check the directory selinux.sehash SHA256 digest for "
|
|
|
ffbc92 |
"<path> against\na newly generated digest based on the "
|
|
|
ffbc92 |
"file_context entries for that node\n(using the regx, mode "
|
|
|
ffbc92 |
"and path entries).\n", progname);
|
|
|
ffbc92 |
@@ -37,7 +37,7 @@ int main(int argc, char **argv)
|
|
|
ffbc92 |
char *paths[2] = { NULL, NULL };
|
|
|
ffbc92 |
uint8_t *xattr_digest = NULL;
|
|
|
ffbc92 |
uint8_t *calculated_digest = NULL;
|
|
|
ffbc92 |
- char *sha1_buf = NULL;
|
|
|
ffbc92 |
+ char *sha256_buf = NULL;
|
|
|
ffbc92 |
|
|
|
ffbc92 |
struct selabel_handle *hnd;
|
|
|
ffbc92 |
struct selinux_opt selabel_option[] = {
|
|
|
1175f7 |
@@ -106,27 +106,27 @@ int main(int argc, char **argv)
|
|
|
ffbc92 |
&xattr_digest,
|
|
|
ffbc92 |
&digest_len);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
- sha1_buf = calloc(1, digest_len * 2 + 1);
|
|
|
ffbc92 |
- if (!sha1_buf) {
|
|
|
ffbc92 |
+ sha256_buf = calloc(1, digest_len * 2 + 1);
|
|
|
ffbc92 |
+ if (!sha256_buf) {
|
|
|
ffbc92 |
fprintf(stderr, "Could not calloc buffer ERROR: %s\n",
|
|
|
ffbc92 |
strerror(errno));
|
|
|
ffbc92 |
return -1;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
|
|
|
ffbc92 |
if (status) { /* They match */
|
|
|
ffbc92 |
- printf("xattr and file_contexts SHA1 digests match for: %s\n",
|
|
|
ffbc92 |
+ printf("xattr and file_contexts SHA256 digests match for: %s\n",
|
|
|
ffbc92 |
ftsent->fts_path);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
if (calculated_digest) {
|
|
|
ffbc92 |
for (i = 0; i < digest_len; i++)
|
|
|
ffbc92 |
- sprintf((&sha1_buf[i * 2]),
|
|
|
ffbc92 |
+ sprintf((&sha256_buf[i * 2]),
|
|
|
ffbc92 |
"%02x",
|
|
|
ffbc92 |
calculated_digest[i]);
|
|
|
ffbc92 |
- printf("SHA1 digest: %s\n", sha1_buf);
|
|
|
ffbc92 |
+ printf("SHA256 digest: %s\n", sha256_buf);
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
} else {
|
|
|
ffbc92 |
if (!calculated_digest) {
|
|
|
ffbc92 |
- printf("No SHA1 digest available for: %s\n",
|
|
|
ffbc92 |
+ printf("No SHA256 digest available for: %s\n",
|
|
|
ffbc92 |
ftsent->fts_path);
|
|
|
ffbc92 |
printf("as file_context entry is \"<<none>>\"\n");
|
|
|
ffbc92 |
goto cleanup;
|
|
|
1175f7 |
@@ -136,25 +136,25 @@ int main(int argc, char **argv)
|
|
|
ffbc92 |
ftsent->fts_path);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
for (i = 0; i < digest_len; i++)
|
|
|
ffbc92 |
- sprintf((&sha1_buf[i * 2]), "%02x",
|
|
|
ffbc92 |
+ sprintf((&sha256_buf[i * 2]), "%02x",
|
|
|
ffbc92 |
calculated_digest[i]);
|
|
|
ffbc92 |
- printf("generated SHA1 digest: %s\n", sha1_buf);
|
|
|
ffbc92 |
+ printf("generated SHA256 digest: %s\n", sha256_buf);
|
|
|
ffbc92 |
|
|
|
ffbc92 |
if (!xattr_digest) {
|
|
|
ffbc92 |
printf("however there is no selinux.sehash xattr entry.\n");
|
|
|
ffbc92 |
} else {
|
|
|
ffbc92 |
printf("however it does NOT match the current entry of:\n");
|
|
|
ffbc92 |
for (i = 0; i < digest_len; i++)
|
|
|
ffbc92 |
- sprintf((&sha1_buf[i * 2]),
|
|
|
ffbc92 |
+ sprintf((&sha256_buf[i * 2]),
|
|
|
ffbc92 |
"%02x",
|
|
|
ffbc92 |
xattr_digest[i]);
|
|
|
ffbc92 |
- printf("%s\n", sha1_buf);
|
|
|
ffbc92 |
+ printf("%s\n", sha256_buf);
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
cleanup:
|
|
|
ffbc92 |
free(xattr_digest);
|
|
|
ffbc92 |
free(calculated_digest);
|
|
|
ffbc92 |
- free(sha1_buf);
|
|
|
ffbc92 |
+ free(sha256_buf);
|
|
|
ffbc92 |
break;
|
|
|
ffbc92 |
}
|
|
|
ffbc92 |
default:
|
|
|
ffbc92 |
--
|
|
|
05f9c5 |
2.39.0
|
|
|
ffbc92 |
|