Hello all,
The recent work I've been doing with checksum in Subversion has inspired me to
dig more into it. Using OpenSSL was a great proof of concept and it showed a
huge performance improvement. However, I think there are some disadvantages to
using it. It's just too heavy for our needs. Many things are inconsistent and
the current implementation relies on deprecated APIs (which is fixable but it
will result in worse performance).
This is how I decided to try out and collect those optimised digest algorithms
into a separate and standalone project. As at this point this library works
great and it's in a decently stable state. The source code is published on
GitHub: [1].
I would like to propose the idea of using it as a checksum backend in
Subversion. I have attached a patch that adds support for it.
What do you think?
[1] https://github.com/rinrab/xdigest
--
Timofei Zhakov
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 1931402)
+++ CMakeLists.txt (working copy)
@@ -111,8 +111,8 @@ cmake_dependent_option(SVN_BUILD_SHARED_RA "Build
option(SVN_DEBUG "Enables specific features for developer builds" OFF)
cmake_dependent_option(SVN_USE_WIN32_CRASHHANDLER "Enables WIN32 crash
handler." ON "WIN32" OFF)
option(SVN_USE_DSO "Defined if svn should try to load DSOs" OFF)
-set(SVN_CHECKSUM_BACKEND "apr" CACHE STRING "Checksum backend to use (possible
values are 'apr', 'openssl', or 'bcrypt')" )
-set_property(CACHE SVN_CHECKSUM_BACKEND PROPERTY STRINGS "apr" "openssl"
"bcrypt")
+set(SVN_CHECKSUM_BACKEND "apr" CACHE STRING "Checksum backend to use (possible
values are 'apr', 'openssl', 'bcrypt', 'xdigest')" )
+set_property(CACHE SVN_CHECKSUM_BACKEND PROPERTY STRINGS "apr" "openssl"
"bcrypt" "xdigest")
set(SVN_SOVERSION "0" CACHE STRING "Subversion library ABI version")
mark_as_advanced(SVN_SOVERSION)
@@ -410,6 +410,19 @@ elseif (SVN_CHECKSUM_BACKEND STREQUAL "bcrypt")
"Defined if svn should use BCrypt to compute checksums."
"SVN_CHECKSUM_BACKEND_BCRYPT" "1"
)
+elseif (SVN_CHECKSUM_BACKEND STREQUAL "xdigest")
+ if (SVN_USE_PKG_CONFIG AND TODO)
+ pkg_check_modules(xdigest REQUIRED IMPORTED_TARGET xdigest)
+ add_library(external-checksum-libs ALIAS PkgConfig::xdigest)
+ else()
+ find_package(XDIGEST REQUIRED)
+ add_library(external-checksum-libs ALIAS XDIGEST::XDIGEST)
+ endif()
+
+ add_private_config_definition(
+ "Defined if svn should use xdigest to compute checksums."
+ "SVN_CHECKSUM_BACKEND_XDIGEST" "1"
+ )
else()
message(SEND_ERROR
"Invalid value of SVN_CHECKSUM_BACKEND: '${SVN_CHECKSUM_BACKEND}'. "
Index: build/cmake/FindXDIGEST.cmake
===================================================================
--- build/cmake/FindXDIGEST.cmake (nonexistent)
+++ build/cmake/FindXDIGEST.cmake (working copy)
@@ -0,0 +1,47 @@
+find_path(XDIGEST_INCLUDE_DIR
+ NAMES "xdigest.h"
+ PATH_SUFFIXES
+ "include/xdigest"
+)
+
+find_library(XDIGEST_LIBRARY
+ NAMES "xdigest"
+ PATH_SUFFIXES "lib"
+)
+
+if(XDIGEST_INCLUDE_DIR AND EXISTS "${XDIGEST_INCLUDE_DIR}/xdigest.h")
+ file(
+ STRINGS "${XDIGEST_INCLUDE_DIR}/xdigest.h" VERSION_STRINGS
+ REGEX "#define
(XDIG_VERSION_MAJOR|XDIG_VERSION_MINOR|XDIG_VERSION_PATCH)"
+ )
+
+ string(REGEX REPLACE ".*XDIG_VERSION_MAJOR +([0-9]+).*" "\\1"
XDIG_VERSION_MAJOR ${VERSION_STRINGS})
+ string(REGEX REPLACE ".*XDIG_VERSION_MINOR +([0-9]+).*" "\\1"
XDIG_VERSION_MINOR ${VERSION_STRINGS})
+ string(REGEX REPLACE ".*XDIG_VERSION_PATCH +([0-9]+).*" "\\1"
XDIG_VERSION_PATCH ${VERSION_STRINGS})
+
+ set(XDIGEST_VERSION
"${XDIG_VERSION_MAJOR}.${XDIG_VERSION_MINOR}.${XDIG_VERSION_PATCH}")
+endif()
+
+mark_as_advanced(
+ XDIGEST_INCLUDE_DIR
+ XDIGEST_LIBRARY
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ XDIGEST
+ REQUIRED_VARS
+ XDIGEST_LIBRARY
+ XDIGEST_INCLUDE_DIR
+ VERSION_VAR
+ XDIGEST_VERSION
+)
+
+if(XDIGEST_FOUND)
+ add_library(XDIGEST::XDIGEST IMPORTED STATIC)
+
+ set_target_properties(XDIGEST::XDIGEST PROPERTIES
+ IMPORTED_LOCATION ${XDIGEST_LIBRARY}
+ INTERFACE_INCLUDE_DIRECTORIES ${XDIGEST_INCLUDE_DIR}
+ )
+endif()
Index: subversion/libsvn_subr/checksum_xdigest.c
===================================================================
--- subversion/libsvn_subr/checksum_xdigest.c (nonexistent)
+++ subversion/libsvn_subr/checksum_xdigest.c (working copy)
@@ -0,0 +1,127 @@
+/*
+ * checksum_xdigest.c: xdigest backed checksums
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ */
+
+#include "svn_private_config.h"
+#ifdef SVN_CHECKSUM_BACKEND_XDIGEST
+
+#define APR_WANT_BYTEFUNC
+
+#include <apr_md5.h>
+#include <apr_sha1.h>
+
+#include "svn_error.h"
+#include "checksum.h"
+
+#include <xdigest.h>
+#include <xdigest_md5.h>
+#include <xdigest_sha1.h>
+
+/*** MD5 checksum ***/
+svn_error_t *
+svn_checksum__md5(unsigned char *digest,
+ const void *data,
+ apr_size_t len)
+{
+ xdig_md5(digest, data, len);
+ return SVN_NO_ERROR;
+}
+
+svn_checksum__md5_ctx_t *
+svn_checksum__md5_ctx_create(apr_pool_t *pool)
+{
+ xdig_md5_ctx_t *result = apr_palloc(pool, xdig_md5_ctx_size());
+ xdig_md5_ctx_init(result);
+ return (svn_checksum__md5_ctx_t *)result;
+}
+
+svn_error_t *
+svn_checksum__md5_ctx_reset(svn_checksum__md5_ctx_t *ctx)
+{
+ memset(ctx, 0, xdig_md5_ctx_size());
+ xdig_md5_ctx_init((xdig_md5_ctx_t *)ctx);
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_checksum__md5_ctx_update(svn_checksum__md5_ctx_t *ctx,
+ const void *data,
+ apr_size_t len)
+{
+ xdig_md5_ctx_update((xdig_md5_ctx_t *)ctx, data, len);
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_checksum__md5_ctx_final(unsigned char *digest,
+ svn_checksum__md5_ctx_t *ctx)
+{
+ xdig_md5_ctx_final((xdig_md5_ctx_t *)ctx, digest);
+ return SVN_NO_ERROR;
+}
+
+
+/*** SHA1 checksum ***/
+svn_error_t *
+svn_checksum__sha1(unsigned char *digest,
+ const void *data,
+ apr_size_t len)
+{
+ xdig_sha1(digest, data, len);
+ return SVN_NO_ERROR;
+}
+
+svn_checksum__sha1_ctx_t *
+svn_checksum__sha1_ctx_create(apr_pool_t *pool)
+{
+ xdig_sha1_ctx_t *result = apr_palloc(pool, xdig_sha1_ctx_size());
+ xdig_sha1_ctx_init(result);
+ return (svn_checksum__sha1_ctx_t *)result;
+}
+
+svn_error_t *
+svn_checksum__sha1_ctx_reset(svn_checksum__sha1_ctx_t *ctx)
+{
+ memset(ctx, 0, xdig_sha1_ctx_size());
+ xdig_sha1_ctx_init((xdig_sha1_ctx_t *)ctx);
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_checksum__sha1_ctx_update(svn_checksum__sha1_ctx_t *ctx,
+ const void *data,
+ apr_size_t len)
+{
+ xdig_sha1_ctx_update((xdig_sha1_ctx_t *)ctx , data, len);
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_checksum__sha1_ctx_final(unsigned char *digest,
+ svn_checksum__sha1_ctx_t *ctx)
+{
+ xdig_sha1_ctx_final((xdig_sha1_ctx_t *)ctx, digest);
+ return SVN_NO_ERROR;
+}
+
+#endif /* SVN_CHECKSUM_BACKEND_XDIGEST */
+
Property changes on: subversion/libsvn_subr/checksum_xdigest.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property