]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
In mtree format, add support sha256/sha256digest,
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 29 Jan 2009 02:38:07 +0000 (21:38 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 29 Jan 2009 02:38:07 +0000 (21:38 -0500)
sha384/sha384digest and sha512/sha512digest keywords.

SVN-Revision: 504

CMakeLists.txt
cmake/config.h.in
configure.ac
libarchive/archive_write_set_format_mtree.c

index 95f356c6a7fcca8d1313669284a9097998d65a57..35894db28786599cc31bf9ce2a3cc1c7bca6dbd7 100644 (file)
@@ -202,9 +202,9 @@ IF(MD_LIBRARY)
   LIST(APPEND ADDITIONAL_LIBS ${MD_LIBRARY})
 ENDIF(MD_LIBRARY)
 #
-# Find SHA1 headers
+# Find SHA headers
 #
-CHECK_HEADERS(sha.h sha1.h)
+CHECK_HEADERS(sha.h sha1.h sha2.h sha256.h)
 
 #
 # Check functions
index b22965a1cf3d46c7b531f5822bc8eebdc890f0b7..48d395a6a6d0f5f49763b45f7783005d683d15a7 100644 (file)
 /* Define to 1 if you have the <sha1.h> header file. */
 #cmakedefine HAVE_SHA1_H 1
 
+/* Define to 1 if you have the <sha256.h> header file. */
+#cmakedefine HAVE_SHA256_H 1
+
+/* Define to 1 if you have the <sha2.h> header file. */
+#cmakedefine HAVE_SHA2_H 1
+
 /* Define to 1 if you have the <sha.h> header file. */
 #cmakedefine HAVE_SHA_H 1
 
index ad1075f67af299453a2f29ea8db5a0665ee2a914..cb602c8b238c3b38d8b27c9b7838e9b06a558a2f 100644 (file)
@@ -197,7 +197,7 @@ fi
 
 AC_CHECK_HEADERS([md5.h md5global.h])
 AC_CHECK_LIB(md,MD5Init)
-AC_CHECK_HEADERS([sha.h sha1.h])
+AC_CHECK_HEADERS([sha.h sha1.h sha2.h sha256.h])
 
 # TODO: Give the user the option of using a pre-existing system
 # libarchive.  This will define HAVE_LIBARCHIVE which will cause
index 8789bd479fb1944f3970f2ec8243756b2eeaca44..79e670bb71169307d234838a2f6683b3eaf8385f 100644 (file)
@@ -45,6 +45,12 @@ __FBSDID("$FreeBSD$");
 #ifdef HAVE_SHA1_H
 #include <sha1.h>
 #endif
+#ifdef HAVE_SHA2_H
+#include <sha2.h>
+#endif
+#ifdef HAVE_SHA256_H
+#include <sha256.h>
+#endif
 
 #include "archive.h"
 #include "archive_entry.h"
@@ -65,6 +71,13 @@ struct mtree_writer {
 #endif
 #if defined(HAVE_SHA_H) || defined(HAVE_SHA1_H)
        SHA_CTX sha1ctx;
+#endif
+#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+       SHA256_CTX sha256ctx;
+#endif
+#ifdef HAVE_SHA2_H
+       SHA384_CTX sha384ctx;
+       SHA512_CTX sha512ctx;
 #endif
        /* Keyword options */
        int keys;
@@ -244,6 +257,28 @@ archive_write_mtree_header(struct archive_write *a,
        } else
                mtree->compute_sum &= ~F_SHA1;
 #endif
+#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+       if ((mtree->keys & F_SHA256) != 0 &&
+           archive_entry_filetype(entry) == AE_IFREG) {
+               mtree->compute_sum |= F_SHA256;
+               SHA256_Init(&mtree->sha256ctx);
+       } else
+               mtree->compute_sum &= ~F_SHA256;
+#endif
+#ifdef HAVE_SHA2_H
+       if ((mtree->keys & F_SHA384) != 0 &&
+           archive_entry_filetype(entry) == AE_IFREG) {
+               mtree->compute_sum |= F_SHA384;
+               SHA384_Init(&mtree->sha384ctx);
+       } else
+               mtree->compute_sum &= ~F_SHA384;
+       if ((mtree->keys & F_SHA512) != 0 &&
+           archive_entry_filetype(entry) == AE_IFREG) {
+               mtree->compute_sum |= F_SHA512;
+               SHA512_Init(&mtree->sha512ctx);
+       } else
+               mtree->compute_sum &= ~F_SHA512;
+#endif
 
        return (ARCHIVE_OK);
 }
@@ -387,6 +422,31 @@ archive_write_mtree_finish_entry(struct archive_write *a)
                archive_strcat(&mtree->buf, " sha1digest=");
                strappend_bin(&mtree->buf, buf, sizeof(buf));
        }
+#endif
+#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+       if (mtree->compute_sum & F_SHA256) {
+               unsigned char buf[32];
+
+               SHA256_Final(buf, &mtree->sha256ctx);
+               archive_strcat(&mtree->buf, " sha256digest=");
+               strappend_bin(&mtree->buf, buf, sizeof(buf));
+       }
+#endif
+#if defined(HAVE_SHA2_H)
+       if (mtree->compute_sum & F_SHA384) {
+               unsigned char buf[48];
+
+               SHA384_Final(buf, &mtree->sha384ctx);
+               archive_strcat(&mtree->buf, " sha384digest=");
+               strappend_bin(&mtree->buf, buf, sizeof(buf));
+       }
+       if (mtree->compute_sum & F_SHA512) {
+               unsigned char buf[64];
+
+               SHA512_Final(buf, &mtree->sha512ctx);
+               archive_strcat(&mtree->buf, " sha512digest=");
+               strappend_bin(&mtree->buf, buf, sizeof(buf));
+       }
 #endif
        archive_strcat(&mtree->buf, "\n");
 
@@ -436,6 +496,16 @@ archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n)
 #if defined(HAVE_SHA_H) || defined(HAVE_SHA1_H)
        if (mtree->compute_sum & F_SHA1)
                SHA1_Update(&mtree->sha1ctx, buff, n);
+#endif
+#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+       if (mtree->compute_sum & F_SHA256)
+               SHA256_Update(&mtree->sha256ctx, buff, n);
+#endif
+#ifdef HAVE_SHA2_H
+       if (mtree->compute_sum & F_SHA384)
+               SHA384_Update(&mtree->sha384ctx, buff, n);
+       if (mtree->compute_sum & F_SHA512)
+               SHA384_Update(&mtree->sha512ctx, buff, n);
 #endif
        return n;
 }
@@ -507,6 +577,19 @@ archive_write_mtree_options(struct archive_write *a, const char *key,
                if (strcmp(key, "sha1") == 0 ||
                    strcmp(key, "sha1digest") == 0)
                        keybit = F_SHA1;
+#endif
+#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+               if (strcmp(key, "sha256") == 0 ||
+                   strcmp(key, "sha256digest") == 0)
+                       keybit = F_SHA256;
+#endif
+#ifdef HAVE_SHA2_H
+               if (strcmp(key, "sha384") == 0 ||
+                   strcmp(key, "sha384digest") == 0)
+                       keybit = F_SHA384;
+               if (strcmp(key, "sha512") == 0 ||
+                   strcmp(key, "sha512digest") == 0)
+                       keybit = F_SHA512;
 #endif
                if (strcmp(key, "size") == 0)
                        keybit = F_SIZE;