File digest-update.patch of Package ruby2.5

diff -ruN ruby-2.5.9.orig/ext/digest/bubblebabble/bubblebabble.c ruby-2.5.9/ext/digest/bubblebabble/bubblebabble.c
--- ruby-2.5.9.orig/ext/digest/bubblebabble/bubblebabble.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/bubblebabble/bubblebabble.c	2025-02-10 14:05:56.218288960 +0100
@@ -2,12 +2,12 @@
 
   bubblebabble.c - BubbleBabble encoding support
 
-  $Author: nobu $
+  $Author$
   created at: Fri Oct 13 18:31:42 JST 2006
 
   Copyright (C) 2006 Akinori MUSHA
 
-  $Id: bubblebabble.c 55773 2016-07-29 11:57:14Z nobu $
+  $Id$
 
 ************************************************/
 
@@ -37,7 +37,7 @@
     digest_len = RSTRING_LEN(str_digest);
 
     if ((LONG_MAX - 2) / 3 < (digest_len | 1)) {
-	rb_raise(rb_eRuntimeError, "digest string too long");
+        rb_raise(rb_eRuntimeError, "digest string too long");
     }
 
     str = rb_str_new(0, (digest_len | 1) * 3 + 2);
@@ -124,19 +124,19 @@
 void
 Init_bubblebabble(void)
 {
+#undef rb_intern
     VALUE rb_mDigest, rb_mDigest_Instance, rb_cDigest_Class;
 
     rb_require("digest");
 
-    rb_mDigest = rb_path2class("Digest");
-    rb_mDigest_Instance = rb_path2class("Digest::Instance");
-    rb_cDigest_Class = rb_path2class("Digest::Class");
-
 #if 0
     rb_mDigest = rb_define_module("Digest");
     rb_mDigest_Instance = rb_define_module_under(rb_mDigest, "Instance");
     rb_cDigest_Class = rb_define_class_under(rb_mDigest, "Class", rb_cObject);
 #endif
+    rb_mDigest = rb_digest_namespace();
+    rb_mDigest_Instance = rb_const_get(rb_mDigest, rb_intern_const("Instance"));
+    rb_cDigest_Class = rb_const_get(rb_mDigest, rb_intern_const("Class"));
 
     rb_define_module_function(rb_mDigest, "bubblebabble", rb_digest_s_bubblebabble, 1);
     rb_define_singleton_method(rb_cDigest_Class, "bubblebabble", rb_digest_class_s_bubblebabble, -1);
diff -ruN ruby-2.5.9.orig/ext/digest/bubblebabble/extconf.rb ruby-2.5.9/ext/digest/bubblebabble/extconf.rb
--- ruby-2.5.9.orig/ext/digest/bubblebabble/extconf.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/bubblebabble/extconf.rb	2025-02-10 14:05:56.218288960 +0100
@@ -1,6 +1,4 @@
 # frozen_string_literal: false
 require 'mkmf'
 
-$defs << "-DHAVE_CONFIG_H"
-
 create_makefile('digest/bubblebabble')
diff -ruN ruby-2.5.9.orig/ext/digest/defs.h ruby-2.5.9/ext/digest/defs.h
--- ruby-2.5.9.orig/ext/digest/defs.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/defs.h	2025-02-10 14:05:56.218288960 +0100
@@ -1,5 +1,5 @@
 /* -*- C -*-
- * $Id: defs.h 25189 2009-10-02 12:04:37Z akr $
+ * $Id$
  */
 
 #ifndef DEFS_H
diff -ruN ruby-2.5.9.orig/ext/digest/digest.c ruby-2.5.9/ext/digest/digest.c
--- ruby-2.5.9.orig/ext/digest/digest.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/digest.c	2025-02-10 14:05:56.218288960 +0100
@@ -2,14 +2,14 @@
 
   digest.c -
 
-  $Author: svn $
+  $Author$
   created at: Fri May 25 08:57:27 JST 2001
 
   Copyright (C) 1995-2001 Yukihiro Matsumoto
   Copyright (C) 2001-2006 Akinori MUSHA
 
   $RoughId: digest.c,v 1.16 2001/07/13 15:38:27 knu Exp $
-  $Id: digest.c 56456 2016-10-20 07:57:31Z svn $
+  $Id$
 
 ************************************************/
 
@@ -154,7 +154,7 @@
 rb_digest_instance_method_unimpl(VALUE self, const char *method)
 {
     rb_raise(rb_eRuntimeError, "%s does not implement %s()",
-	     rb_obj_classname(self), method);
+             rb_obj_classname(self), method);
 }
 
 /*
@@ -383,8 +383,8 @@
     StringValue(str2);
 
     if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
-	rb_str_cmp(str1, str2) == 0) {
-	return Qtrue;
+        rb_str_cmp(str1, str2) == 0) {
+        return Qtrue;
     }
     return Qfalse;
 }
@@ -406,7 +406,7 @@
 
     /* never blindly assume that #digest() returns a string */
     StringValue(digest);
-    return INT2NUM(RSTRING_LEN(digest));
+    return LONG2NUM(RSTRING_LEN(digest));
 }
 
 /*
@@ -534,9 +534,39 @@
  *
  *
  *  rb_ivar_set(cDigest_SHA1, rb_intern("metadata"),
- *		Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
+ *		rb_digest_make_metadata(&sha1));
  */
 
+#ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
+static const rb_data_type_t metadata_type = {
+    "digest/metadata",
+    {0},
+};
+
+RUBY_FUNC_EXPORTED VALUE
+rb_digest_wrap_metadata(const rb_digest_metadata_t *meta)
+{
+    return rb_obj_freeze(TypedData_Wrap_Struct(0, &metadata_type, (void *)meta));
+}
+#endif
+
+static rb_digest_metadata_t *
+get_metadata_ptr(VALUE obj)
+{
+    rb_digest_metadata_t *algo;
+
+#ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
+    if (!rb_typeddata_is_kind_of(obj, &metadata_type)) return 0;
+    algo = RTYPEDDATA_DATA(obj);
+#else
+# undef RUBY_UNTYPED_DATA_WARNING
+# define RUBY_UNTYPED_DATA_WARNING 0
+    Data_Get_Struct(obj, rb_digest_metadata_t, algo);
+#endif
+
+    return algo;
+}
+
 static rb_digest_metadata_t *
 get_digest_base_metadata(VALUE klass)
 {
@@ -554,9 +584,15 @@
     if (NIL_P(p))
         rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");
 
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    Data_Get_Struct(obj, rb_digest_metadata_t, algo);
+    algo = get_metadata_ptr(obj);
+    if (!algo) {
+        if (p == klass)
+            rb_raise(rb_eTypeError, "%"PRIsVALUE"::metadata is not initialized properly",
+                     klass);
+        else
+            rb_raise(rb_eTypeError, "%"PRIsVALUE"(%"PRIsVALUE")::metadata is not initialized properly",
+                     klass, p);
+    }
 
     switch (algo->api_version) {
       case 3:
@@ -573,6 +609,12 @@
     return algo;
 }
 
+static rb_digest_metadata_t *
+get_digest_obj_metadata(VALUE obj)
+{
+    return get_digest_base_metadata(rb_obj_class(obj));
+}
+
 static const rb_data_type_t digest_type = {
     "digest",
     {0, RUBY_TYPED_DEFAULT_FREE, 0,},
@@ -584,7 +626,7 @@
 algo_init(const rb_digest_metadata_t *algo, void *pctx)
 {
     if (algo->init_func(pctx) != 1) {
-	rb_raise(rb_eRuntimeError, "Digest initialization failed.");
+        rb_raise(rb_eRuntimeError, "Digest initialization failed.");
     }
 }
 
@@ -596,7 +638,7 @@
     void *pctx;
 
     if (klass == rb_cDigest_Base) {
-	rb_raise(rb_eNotImpError, "Digest::Base is an abstract class");
+        rb_raise(rb_eNotImpError, "Digest::Base is an abstract class");
     }
 
     algo = get_digest_base_metadata(klass);
@@ -619,9 +661,9 @@
 
     rb_check_frozen(copy);
 
-    algo = get_digest_base_metadata(rb_obj_class(copy));
-    if (algo != get_digest_base_metadata(rb_obj_class(obj)))
-	rb_raise(rb_eTypeError, "different algorithms");
+    algo = get_digest_obj_metadata(copy);
+    if (algo != get_digest_obj_metadata(obj))
+        rb_raise(rb_eTypeError, "different algorithms");
 
     TypedData_Get_Struct(obj, void, &digest_type, pctx1);
     TypedData_Get_Struct(copy, void, &digest_type, pctx2);
@@ -641,7 +683,7 @@
     rb_digest_metadata_t *algo;
     void *pctx;
 
-    algo = get_digest_base_metadata(rb_obj_class(self));
+    algo = get_digest_obj_metadata(self);
 
     TypedData_Get_Struct(self, void, &digest_type, pctx);
 
@@ -663,7 +705,7 @@
     rb_digest_metadata_t *algo;
     void *pctx;
 
-    algo = get_digest_base_metadata(rb_obj_class(self));
+    algo = get_digest_obj_metadata(self);
 
     TypedData_Get_Struct(self, void, &digest_type, pctx);
 
@@ -682,7 +724,7 @@
     void *pctx;
     VALUE str;
 
-    algo = get_digest_base_metadata(rb_obj_class(self));
+    algo = get_digest_obj_metadata(self);
 
     TypedData_Get_Struct(self, void, &digest_type, pctx);
 
@@ -705,9 +747,9 @@
 {
     rb_digest_metadata_t *algo;
 
-    algo = get_digest_base_metadata(rb_obj_class(self));
+    algo = get_digest_obj_metadata(self);
 
-    return INT2NUM(algo->digest_len);
+    return SIZET2NUM(algo->digest_len);
 }
 
 /*
@@ -720,26 +762,37 @@
 {
     rb_digest_metadata_t *algo;
 
-    algo = get_digest_base_metadata(rb_obj_class(self));
+    algo = get_digest_obj_metadata(self);
 
-    return INT2NUM(algo->block_len);
+    return SIZET2NUM(algo->block_len);
 }
 
 void
 Init_digest(void)
 {
+#undef rb_intern
     id_reset           = rb_intern("reset");
     id_update          = rb_intern("update");
     id_finish          = rb_intern("finish");
     id_digest          = rb_intern("digest");
     id_hexdigest       = rb_intern("hexdigest");
     id_digest_length   = rb_intern("digest_length");
+    id_metadata        = rb_id_metadata();
+    InitVM(digest);
+}
 
+void
+InitVM_digest(void)
+{
     /*
      * module Digest
      */
     rb_mDigest = rb_define_module("Digest");
 
+#ifdef HAVE_RB_EXT_RACTOR_SAFE
+    rb_ext_ractor_safe(true);
+#endif
+
     /* module functions */
     rb_define_module_function(rb_mDigest, "hexencode", rb_digest_s_hexencode, 1);
 
@@ -781,8 +834,6 @@
     rb_define_singleton_method(rb_cDigest_Class, "digest", rb_digest_class_s_digest, -1);
     rb_define_singleton_method(rb_cDigest_Class, "hexdigest", rb_digest_class_s_hexdigest, -1);
 
-    id_metadata = rb_intern("metadata");
-
     /* class Digest::Base < Digest::Class */
     rb_cDigest_Base = rb_define_class_under(rb_mDigest, "Base", rb_cDigest_Class);
 
diff -ruN ruby-2.5.9.orig/ext/digest/digest_conf.rb ruby-2.5.9/ext/digest/digest_conf.rb
--- ruby-2.5.9.orig/ext/digest/digest_conf.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/digest_conf.rb	2025-02-10 14:05:56.218288960 +0100
@@ -1,60 +1,9 @@
 # frozen_string_literal: false
 
-# Copy from ext/openssl/extconf.rb
-def find_openssl_library
-  if $mswin || $mingw
-    # required for static OpenSSL libraries
-    have_library("gdi32") # OpenSSL <= 1.0.2 (for RAND_screen())
-    have_library("crypt32")
-  end
-
-  return false unless have_header("openssl/ssl.h")
-
-  ret = have_library("crypto", "CRYPTO_malloc") &&
-    have_library("ssl", "SSL_new")
-  return ret if ret
-
-  if $mswin
-    # OpenSSL >= 1.1.0: libcrypto.lib and libssl.lib.
-    if have_library("libcrypto", "CRYPTO_malloc") &&
-        have_library("libssl", "SSL_new")
-      return true
-    end
-
-    # OpenSSL <= 1.0.2: libeay32.lib and ssleay32.lib.
-    if have_library("libeay32", "CRYPTO_malloc") &&
-        have_library("ssleay32", "SSL_new")
-      return true
-    end
-
-    # LibreSSL: libcrypto-##.lib and libssl-##.lib, where ## is the ABI version
-    # number. We have to find the version number out by scanning libpath.
-    libpath = $LIBPATH.dup
-    libpath |= ENV["LIB"].split(File::PATH_SEPARATOR)
-    libpath.map! { |d| d.tr(File::ALT_SEPARATOR, File::SEPARATOR) }
-
-    ret = [
-      ["crypto", "CRYPTO_malloc"],
-      ["ssl", "SSL_new"]
-    ].all? do |base, func|
-      result = false
-      libs = ["lib#{base}-[0-9][0-9]", "lib#{base}-[0-9][0-9][0-9]"]
-      libs = Dir.glob(libs.map{|l| libpath.map{|d| File.join(d, l + ".*")}}.flatten).map{|path| File.basename(path, ".*")}.uniq
-      libs.each do |lib|
-        result = have_library(lib, func)
-        break if result
-      end
-      result
-    end
-    return ret if ret
-  end
-  return false
-end
-
-def digest_conf(name, hdr = name, funcs = nil, types = nil)
+def digest_conf(name)
   unless with_config("bundled-#{name}")
     cc = with_config("common-digest")
-    if cc == true or /\b#{name}\b/ =~ cc
+    if cc != false or /\b#{name}\b/ =~ cc
       if File.exist?("#$srcdir/#{name}cc.h") and
         have_header("CommonCrypto/CommonDigest.h")
         $defs << "-D#{name.upcase}_USE_COMMONDIGEST"
@@ -62,22 +11,6 @@
         return :commondigest
       end
     end
-
-    dir_config("openssl")
-    pkg_config("openssl")
-    require File.expand_path('../../openssl/deprecation', __FILE__)
-    if find_openssl_library
-      funcs ||= name.upcase
-      funcs = Array(funcs)
-      types ||= funcs
-      hdr = "openssl/#{hdr}.h"
-      if funcs.all? {|func| OpenSSL.check_func("#{func}_Transform", hdr)} &&
-         types.all? {|type| have_type("#{type}_CTX", hdr)}
-        $defs << "-D#{name.upcase}_USE_OPENSSL"
-        $headers << "#{name}ossl.h"
-        return :ossl
-      end
-    end
   end
   $objs << "#{name}.#{$OBJEXT}"
   return
diff -ruN ruby-2.5.9.orig/ext/digest/digest.h ruby-2.5.9/ext/digest/digest.h
--- ruby-2.5.9.orig/ext/digest/digest.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/digest.h	2025-02-10 14:05:56.218288960 +0100
@@ -2,14 +2,14 @@
 
   digest.h - header file for ruby digest modules
 
-  $Author: nobu $
+  $Author$
   created at: Fri May 25 08:54:56 JST 2001
 
 
   Copyright (C) 2001-2006 Akinori MUSHA
 
   $RoughId: digest.h,v 1.3 2001/07/13 15:38:27 knu Exp $
-  $Id: digest.h 49564 2015-02-11 02:09:23Z nobu $
+  $Id$
 
 ************************************************/
 
@@ -38,9 +38,10 @@
     const unsigned int stride = 16384; \
  \
     for (; size > stride; size -= stride, ptr += stride) { \
-	name##_Update(ctx, ptr, stride); \
+        name##_Update(ctx, ptr, stride); \
     } \
-    if (size > 0) name##_Update(ctx, ptr, size); \
+    /* Since size <= stride, size should fit into an unsigned int */ \
+    if (size > 0) name##_Update(ctx, ptr, (unsigned int)size); \
 }
 
 #define DEFINE_FINISH_FUNC_FROM_FINAL(name) \
@@ -49,3 +50,57 @@
 { \
     return name##_Final(ptr, ctx); \
 }
+
+static inline VALUE
+rb_digest_namespace(void)
+{
+    rb_require("digest");
+    return rb_path2class("Digest");
+}
+
+static inline ID
+rb_id_metadata(void)
+{
+    return rb_intern_const("metadata");
+}
+
+#if !defined(HAVE_RB_EXT_RESOLVE_SYMBOL)
+#elif !defined(RUBY_UNTYPED_DATA_WARNING)
+# error RUBY_UNTYPED_DATA_WARNING is not defined
+#elif RUBY_UNTYPED_DATA_WARNING
+/* rb_ext_resolve_symbol() has been defined since Ruby 3.3, but digest
+ * bundled with 3.3 didn't use it. */
+# define DIGEST_USE_RB_EXT_RESOLVE_SYMBOL 1
+#endif
+
+static inline VALUE
+rb_digest_make_metadata(const rb_digest_metadata_t *meta)
+{
+#if defined(EXTSTATIC) && EXTSTATIC
+    /* The extension is built as a static library, so safe to refer to
+     * rb_digest_wrap_metadata directly. */
+    extern VALUE rb_digest_wrap_metadata(const rb_digest_metadata_t *meta);
+    return rb_digest_wrap_metadata(meta);
+#else
+    /* The extension is built as a shared library, so we can't refer
+     * to rb_digest_wrap_metadata directly. */
+# ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
+    /* If rb_ext_resolve_symbol() is available, use it to get the address of
+     * rb_digest_wrap_metadata. */
+    typedef VALUE (*wrapper_func_type)(const rb_digest_metadata_t *meta);
+    static wrapper_func_type wrapper;
+    if (!wrapper) {
+        wrapper = (wrapper_func_type)(uintptr_t)
+            rb_ext_resolve_symbol("digest.so", "rb_digest_wrap_metadata");
+        if (!wrapper) rb_raise(rb_eLoadError, "rb_digest_wrap_metadata not found");
+    }
+    return wrapper(meta);
+# else
+    /* If rb_ext_resolve_symbol() is not available, keep using untyped
+     * data. */
+# undef RUBY_UNTYPED_DATA_WARNING
+# define RUBY_UNTYPED_DATA_WARNING 0
+    return rb_obj_freeze(Data_Wrap_Struct(0, 0, 0, (void *)meta));
+# endif
+#endif
+}
diff -ruN ruby-2.5.9.orig/ext/digest/.document ruby-2.5.9/ext/digest/.document
--- ruby-2.5.9.orig/ext/digest/.document	1970-01-01 01:00:00.000000000 +0100
+++ ruby-2.5.9/ext/digest/.document	2025-02-10 14:05:56.218288960 +0100
@@ -0,0 +1,3 @@
+digest.c
+bubblebabble/bubblebabble.c
+*/*init.c
diff -ruN ruby-2.5.9.orig/ext/digest/extconf.rb ruby-2.5.9/ext/digest/extconf.rb
--- ruby-2.5.9.orig/ext/digest/extconf.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/extconf.rb	2025-02-10 14:05:56.218288960 +0100
@@ -1,11 +1,11 @@
 # frozen_string_literal: false
 # $RoughId: extconf.rb,v 1.6 2001/07/13 15:38:27 knu Exp $
-# $Id: extconf.rb 53143 2015-12-16 05:31:54Z naruse $
+# $Id$
 
 require "mkmf"
 
 $INSTALLFILES = {
   "digest.h" => "$(HDRDIR)"
-}
+} if $extmk
 
 create_makefile("digest")
diff -ruN ruby-2.5.9.orig/ext/digest/lib/digest/loader.rb ruby-2.5.9/ext/digest/lib/digest/loader.rb
--- ruby-2.5.9.orig/ext/digest/lib/digest/loader.rb	1970-01-01 01:00:00.000000000 +0100
+++ ruby-2.5.9/ext/digest/lib/digest/loader.rb	2025-02-10 14:05:56.218288960 +0100
@@ -0,0 +1,3 @@
+# frozen_string_literal: true
+
+require 'digest.so'
diff -ruN ruby-2.5.9.orig/ext/digest/lib/digest/sha2/loader.rb ruby-2.5.9/ext/digest/lib/digest/sha2/loader.rb
--- ruby-2.5.9.orig/ext/digest/lib/digest/sha2/loader.rb	1970-01-01 01:00:00.000000000 +0100
+++ ruby-2.5.9/ext/digest/lib/digest/sha2/loader.rb	2025-02-10 14:05:56.219288975 +0100
@@ -0,0 +1,3 @@
+# frozen_string_literal: true
+
+require 'digest/sha2.so'
diff -ruN ruby-2.5.9.orig/ext/digest/md5/extconf.rb ruby-2.5.9/ext/digest/md5/extconf.rb
--- ruby-2.5.9.orig/ext/digest/md5/extconf.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/md5/extconf.rb	2025-02-10 14:05:56.219288975 +0100
@@ -1,13 +1,11 @@
 # -*- coding: us-ascii -*-
 # frozen_string_literal: false
 # $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
-# $Id: extconf.rb 53143 2015-12-16 05:31:54Z naruse $
+# $Id$
 
 require "mkmf"
 require File.expand_path("../../digest_conf", __FILE__)
 
-$defs << "-DHAVE_CONFIG_H"
-
 $objs = [ "md5init.#{$OBJEXT}" ]
 
 digest_conf("md5")
diff -ruN ruby-2.5.9.orig/ext/digest/md5/md5.c ruby-2.5.9/ext/digest/md5/md5.c
--- ruby-2.5.9.orig/ext/digest/md5/md5.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/md5/md5.c	2025-02-10 14:05:56.219288975 +0100
@@ -49,7 +49,7 @@
 
 /*$OrigId: md5c.c,v 1.2 2001/03/26 08:57:14 matz Exp $ */
 /*$RoughId: md5.c,v 1.2 2001/07/13 19:48:41 knu Exp $ */
-/*$Id: md5.c 47744 2014-09-30 05:25:32Z nobu $ */
+/*$Id$ */
 
 #include "md5.h"
 
@@ -225,7 +225,7 @@
     uint32_t xbuf[16];
     const uint32_t *X;
 
-    if (!((data - (const uint8_t *)0) & 3)) {
+    if (!(((uintptr_t)data) & 3)) {
 	/* data are properly aligned */
 	X = (const uint32_t *)data;
     } else {
diff -ruN ruby-2.5.9.orig/ext/digest/md5/md5cc.h ruby-2.5.9/ext/digest/md5/md5cc.h
--- ruby-2.5.9.orig/ext/digest/md5/md5cc.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/md5/md5cc.h	2025-02-10 14:05:56.219288975 +0100
@@ -1,6 +1,21 @@
 #define COMMON_DIGEST_FOR_OPENSSL 1
 #include <CommonCrypto/CommonDigest.h>
 
+#ifdef __GNUC__
+# define RB_DIGEST_DIAGNOSTIC(compiler, op, flag) _Pragma(STRINGIZE(compiler diagnostic op flag))
+# ifdef RBIMPL_WARNING_IGNORED
+#   define RB_DIGEST_WARNING_IGNORED(flag) RBIMPL_WARNING_IGNORED(flag)
+# elif defined(__clang__)
+#   define RB_DIGEST_WARNING_IGNORED(flag) RB_DIGEST_DIAGNOSTIC(clang, ignored, #flag)
+# else /* __GNUC__ */
+#   define RB_DIGEST_WARNING_IGNORED(flag) RB_DIGEST_DIAGNOSTIC(GCC, ignored, #flag)
+# endif
+RB_DIGEST_WARNING_IGNORED(-Wdeprecated-declarations)
+/* Suppress deprecation warnings of MD5 from Xcode 11.1 */
+/* Although we know MD5 is deprecated too, provide just for backward
+ * compatibility, as well as Apple does. */
+#endif
+
 #define MD5_BLOCK_LENGTH	CC_MD5_BLOCK_BYTES
 
 static DEFINE_UPDATE_FUNC_FOR_UINT(MD5)
@@ -10,3 +25,11 @@
 #undef MD5_Finish
 #define MD5_Update rb_digest_MD5_update
 #define MD5_Finish rb_digest_MD5_finish
+
+/*
+ * Pre-10.6 defines are with args, which don't match the argless use in
+ * the function pointer inits.  Thus, we redefine MD5_Init as well.
+ * This is a NOP on 10.6+.
+ */
+#undef MD5_Init
+#define MD5_Init CC_MD5_Init
diff -ruN ruby-2.5.9.orig/ext/digest/md5/md5.h ruby-2.5.9/ext/digest/md5/md5.h
--- ruby-2.5.9.orig/ext/digest/md5/md5.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/md5/md5.h	2025-02-10 14:05:56.219288975 +0100
@@ -41,7 +41,7 @@
 
 /* $OrigId: md5.h,v 1.2 2001/03/26 08:57:14 matz Exp $ */
 /* $RoughId: md5.h,v 1.3 2002/02/24 08:14:31 knu Exp $ */
-/* $Id: md5.h 52694 2015-11-21 04:35:57Z naruse $ */
+/* $Id$ */
 
 #ifndef MD5_INCLUDED
 #  define MD5_INCLUDED
diff -ruN ruby-2.5.9.orig/ext/digest/md5/md5init.c ruby-2.5.9/ext/digest/md5/md5init.c
--- ruby-2.5.9.orig/ext/digest/md5/md5init.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/md5/md5init.c	2025-02-10 14:05:56.219288975 +0100
@@ -1,11 +1,9 @@
 /* $RoughId: md5init.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */
-/* $Id: md5init.c 56459 2016-10-20 13:18:52Z kazu $ */
+/* $Id$ */
 
 #include <ruby/ruby.h>
 #include "../digest.h"
-#if defined(MD5_USE_OPENSSL)
-#include "md5ossl.h"
-#elif defined(MD5_USE_COMMONDIGEST)
+#if defined(MD5_USE_COMMONDIGEST)
 #include "md5cc.h"
 #else
 #include "md5.h"
@@ -51,18 +49,12 @@
 {
     VALUE mDigest, cDigest_Base, cDigest_MD5;
 
-    rb_require("digest");
-
 #if 0
     mDigest = rb_define_module("Digest"); /* let rdoc know */
 #endif
-    mDigest = rb_path2class("Digest");
-    cDigest_Base = rb_path2class("Digest::Base");
+    mDigest = rb_digest_namespace();
+    cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
 
     cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);
-
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    rb_iv_set(cDigest_MD5, "metadata",
-	      Data_Wrap_Struct(0, 0, 0, (void *)&md5));
+    rb_iv_set(cDigest_MD5, "metadata", rb_digest_make_metadata(&md5));
 }
diff -ruN ruby-2.5.9.orig/ext/digest/rmd160/extconf.rb ruby-2.5.9/ext/digest/rmd160/extconf.rb
--- ruby-2.5.9.orig/ext/digest/rmd160/extconf.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/rmd160/extconf.rb	2025-02-10 14:05:56.219288975 +0100
@@ -1,16 +1,18 @@
 # -*- coding: us-ascii -*-
 # frozen_string_literal: false
 # $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
-# $Id: extconf.rb 53143 2015-12-16 05:31:54Z naruse $
+# $Id$
 
 require "mkmf"
 require File.expand_path("../../digest_conf", __FILE__)
 
-$defs << "-DNDEBUG" << "-DHAVE_CONFIG_H"
+if try_static_assert("RUBY_API_VERSION_MAJOR < 3", "ruby/version.h")
+  $defs << "-DNDEBUG"
+end
 
 $objs = [ "rmd160init.#{$OBJEXT}" ]
 
-digest_conf("rmd160", "ripemd", "RIPEMD160")
+digest_conf("rmd160")
 
 have_header("sys/cdefs.h")
 
diff -ruN ruby-2.5.9.orig/ext/digest/rmd160/rmd160.c ruby-2.5.9/ext/digest/rmd160/rmd160.c
--- ruby-2.5.9.orig/ext/digest/rmd160/rmd160.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/rmd160/rmd160.c	2025-02-10 14:05:56.219288975 +0100
@@ -1,6 +1,6 @@
 /*	$NetBSD: rmd160.c,v 1.1.1.1 2001/03/06 11:21:05 agc Exp $	*/
 /*	$RoughId: rmd160.c,v 1.2 2001/07/13 19:49:10 knu Exp $	*/
-/*	$Id: rmd160.c 46827 2014-07-15 14:59:20Z nobu $	*/
+/*	$Id$	*/
 
 /********************************************************************\
  *
diff -ruN ruby-2.5.9.orig/ext/digest/rmd160/rmd160.h ruby-2.5.9/ext/digest/rmd160/rmd160.h
--- ruby-2.5.9.orig/ext/digest/rmd160/rmd160.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/rmd160/rmd160.h	2025-02-10 14:05:56.219288975 +0100
@@ -1,6 +1,6 @@
 /*	$NetBSD: rmd160.h,v 1.2 2000/07/07 10:47:06 ad Exp $	*/
 /*	$RoughId: rmd160.h,v 1.3 2002/02/24 08:14:31 knu Exp $	*/
-/*	$Id: rmd160.h 52694 2015-11-21 04:35:57Z naruse $	*/
+/*	$Id$	*/
 
 /********************************************************************\
  *
diff -ruN ruby-2.5.9.orig/ext/digest/rmd160/rmd160init.c ruby-2.5.9/ext/digest/rmd160/rmd160init.c
--- ruby-2.5.9.orig/ext/digest/rmd160/rmd160init.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/rmd160/rmd160init.c	2025-02-10 14:05:56.219288975 +0100
@@ -1,13 +1,9 @@
 /* $RoughId: rmd160init.c,v 1.3 2001/07/13 20:00:43 knu Exp $ */
-/* $Id: rmd160init.c 56456 2016-10-20 07:57:31Z svn $ */
+/* $Id$ */
 
 #include <ruby/ruby.h>
 #include "../digest.h"
-#if defined(RMD160_USE_OPENSSL)
-#include "rmd160ossl.h"
-#else
 #include "rmd160.h"
-#endif
 
 static const rb_digest_metadata_t rmd160 = {
     RUBY_DIGEST_API_VERSION,
@@ -49,18 +45,12 @@
 {
     VALUE mDigest, cDigest_Base, cDigest_RMD160;
 
-    rb_require("digest");
-
 #if 0
     mDigest = rb_define_module("Digest"); /* let rdoc know */
 #endif
-    mDigest = rb_path2class("Digest");
-    cDigest_Base = rb_path2class("Digest::Base");
+    mDigest = rb_digest_namespace();
+    cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
 
     cDigest_RMD160 = rb_define_class_under(mDigest, "RMD160", cDigest_Base);
-
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    rb_iv_set(cDigest_RMD160, "metadata",
-	      Data_Wrap_Struct(0, 0, 0, (void *)&rmd160));
+    rb_iv_set(cDigest_RMD160, "metadata", rb_digest_make_metadata(&rmd160));
 }
diff -ruN ruby-2.5.9.orig/ext/digest/sha1/extconf.rb ruby-2.5.9/ext/digest/sha1/extconf.rb
--- ruby-2.5.9.orig/ext/digest/sha1/extconf.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha1/extconf.rb	2025-02-10 14:05:56.219288975 +0100
@@ -1,16 +1,14 @@
 # -*- coding: us-ascii -*-
 # frozen_string_literal: false
 # $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
-# $Id: extconf.rb 53143 2015-12-16 05:31:54Z naruse $
+# $Id$
 
 require "mkmf"
 require File.expand_path("../../digest_conf", __FILE__)
 
-$defs << "-DHAVE_CONFIG_H"
-
 $objs = [ "sha1init.#{$OBJEXT}" ]
 
-digest_conf("sha1", "sha", nil, %w[SHA])
+digest_conf("sha1")
 
 have_header("sys/cdefs.h")
 
diff -ruN ruby-2.5.9.orig/ext/digest/sha1/sha1.c ruby-2.5.9/ext/digest/sha1/sha1.c
--- ruby-2.5.9.orig/ext/digest/sha1/sha1.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha1/sha1.c	2025-02-10 14:05:56.219288975 +0100
@@ -1,7 +1,7 @@
 /*	$NetBSD: sha1.c,v 1.2 2001/03/22 09:51:48 agc Exp $	*/
 /*	$OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $	*/
 /*	$RoughId: sha1.c,v 1.2 2001/07/13 19:49:10 knu Exp $	*/
-/*	$Id: sha1.c 46827 2014-07-15 14:59:20Z nobu $	*/
+/*	$Id$	*/
 
 /*
  * SHA-1 in C
diff -ruN ruby-2.5.9.orig/ext/digest/sha1/sha1cc.h ruby-2.5.9/ext/digest/sha1/sha1cc.h
--- ruby-2.5.9.orig/ext/digest/sha1/sha1cc.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha1/sha1cc.h	2025-02-10 14:05:56.219288975 +0100
@@ -12,3 +12,11 @@
 #undef SHA1_Finish
 #define SHA1_Update rb_digest_SHA1_update
 #define SHA1_Finish rb_digest_SHA1_finish
+
+/*
+ * Pre-10.6 defines are with args, which don't match the argless use in
+ * the function pointer inits.  Thus, we redefine SHA1_Init as well.
+ * This is a NOP on 10.6+.
+ */
+#undef SHA1_Init
+#define SHA1_Init CC_SHA1_Init
diff -ruN ruby-2.5.9.orig/ext/digest/sha1/sha1.h ruby-2.5.9/ext/digest/sha1/sha1.h
--- ruby-2.5.9.orig/ext/digest/sha1/sha1.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha1/sha1.h	2025-02-10 14:05:56.219288975 +0100
@@ -1,6 +1,6 @@
 /*	$NetBSD: sha1.h,v 1.2 1998/05/29 22:55:44 thorpej Exp $	*/
 /*	$RoughId: sha1.h,v 1.3 2002/02/24 08:14:32 knu Exp $	*/
-/*	$Id: sha1.h 52694 2015-11-21 04:35:57Z naruse $	*/
+/*	$Id$	*/
 
 /*
  * SHA-1 in C
diff -ruN ruby-2.5.9.orig/ext/digest/sha1/sha1init.c ruby-2.5.9/ext/digest/sha1/sha1init.c
--- ruby-2.5.9.orig/ext/digest/sha1/sha1init.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha1/sha1init.c	2025-02-10 14:05:56.219288975 +0100
@@ -1,11 +1,9 @@
 /* $RoughId: sha1init.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */
-/* $Id: sha1init.c 56456 2016-10-20 07:57:31Z svn $ */
+/* $Id$ */
 
 #include <ruby/ruby.h>
 #include "../digest.h"
-#if defined(SHA1_USE_OPENSSL)
-#include "sha1ossl.h"
-#elif defined(SHA1_USE_COMMONDIGEST)
+#if defined(SHA1_USE_COMMONDIGEST)
 #include "sha1cc.h"
 #else
 #include "sha1.h"
@@ -53,18 +51,12 @@
 {
     VALUE mDigest, cDigest_Base, cDigest_SHA1;
 
-    rb_require("digest");
-
 #if 0
     mDigest = rb_define_module("Digest"); /* let rdoc know */
 #endif
-    mDigest = rb_path2class("Digest");
-    cDigest_Base = rb_path2class("Digest::Base");
+    mDigest = rb_digest_namespace();
+    cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
 
     cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
-
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    rb_iv_set(cDigest_SHA1, "metadata",
-	      Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
+    rb_iv_set(cDigest_SHA1, "metadata", rb_digest_make_metadata(&sha1));
 }
diff -ruN ruby-2.5.9.orig/ext/digest/sha2/extconf.rb ruby-2.5.9/ext/digest/sha2/extconf.rb
--- ruby-2.5.9.orig/ext/digest/sha2/extconf.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha2/extconf.rb	2025-02-10 14:05:56.219288975 +0100
@@ -1,16 +1,14 @@
 # -*- coding: us-ascii -*-
 # frozen_string_literal: false
 # $RoughId: extconf.rb,v 1.4 2001/08/14 19:54:51 knu Exp $
-# $Id: extconf.rb 53143 2015-12-16 05:31:54Z naruse $
+# $Id$
 
 require "mkmf"
 require File.expand_path("../../digest_conf", __FILE__)
 
-$defs << "-DHAVE_CONFIG_H"
-
 $objs = [ "sha2init.#{$OBJEXT}" ]
 
-unless digest_conf("sha2", "sha", %w[SHA256 SHA512])
+unless digest_conf("sha2")
   have_type("u_int8_t")
 end
 
diff -ruN ruby-2.5.9.orig/ext/digest/sha2/sha2.c ruby-2.5.9/ext/digest/sha2/sha2.c
--- ruby-2.5.9.orig/ext/digest/sha2/sha2.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha2/sha2.c	2025-02-10 14:05:56.219288975 +0100
@@ -31,7 +31,7 @@
  *
  * $OrigId: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
  * $RoughId: sha2.c,v 1.3 2002/02/26 22:03:36 knu Exp $
- * $Id: sha2.c 52694 2015-11-21 04:35:57Z naruse $
+ * $Id$
  */
 
 #include "../defs.h"
@@ -94,7 +94,7 @@
 
 /*
  * Define the followingsha2_* types to types of the correct length on
- * the native archtecture.   Most BSD systems and Linux define u_intXX_t
+ * the native architecture.  Most BSD systems and Linux define u_intXX_t
  * types.  Machines with very recent ANSI C headers, can use the
  * uintXX_t definintions from inttypes.h by defining SHA2_USE_INTTYPES_H
  * during compile or in the sha.h header file.
@@ -128,7 +128,7 @@
 #define SHA512_SHORT_BLOCK_LENGTH	(SHA512_BLOCK_LENGTH - 16)
 
 
-#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(__GNUC__) || defined(_HPUX_SOURCE) || defined(__IBMC__)
+#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(__GNUC__) || defined(__IBMC__)
 #define ULL(number)	number##ULL
 #else
 #define ULL(number)	(uint64_t)(number)
@@ -575,7 +575,7 @@
 	usedspace = freespace = 0;
 }
 
-int SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
+int SHA256_Final(sha2_byte digest[SHA256_DIGEST_LENGTH], SHA256_CTX* context) {
 	sha2_word32	*d = (sha2_word32*)digest;
 	unsigned int	usedspace;
 
@@ -640,7 +640,7 @@
 	return 1;
 }
 
-char *SHA256_End(SHA256_CTX* context, char buffer[]) {
+char *SHA256_End(SHA256_CTX* context, char buffer[SHA256_DIGEST_STRING_LENGTH]) {
 	sha2_byte	digest[SHA256_DIGEST_LENGTH], *d = digest;
 	int		i;
 
@@ -943,7 +943,7 @@
 	SHA512_Transform(context, (sha2_word64*)context->buffer);
 }
 
-int SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
+int SHA512_Final(sha2_byte digest[SHA512_DIGEST_LENGTH], SHA512_CTX* context) {
 	sha2_word64	*d = (sha2_word64*)digest;
 
 	/* Sanity check: */
@@ -973,7 +973,7 @@
 	return 1;
 }
 
-char *SHA512_End(SHA512_CTX* context, char buffer[]) {
+char *SHA512_End(SHA512_CTX* context, char buffer[SHA512_DIGEST_STRING_LENGTH]) {
 	sha2_byte	digest[SHA512_DIGEST_LENGTH], *d = digest;
 	int		i;
 
@@ -1019,7 +1019,7 @@
 	SHA512_Update((SHA512_CTX*)context, data, len);
 }
 
-int SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
+int SHA384_Final(sha2_byte digest[SHA384_DIGEST_LENGTH], SHA384_CTX* context) {
 	sha2_word64	*d = (sha2_word64*)digest;
 
 	/* Sanity check: */
@@ -1049,7 +1049,7 @@
 	return 1;
 }
 
-char *SHA384_End(SHA384_CTX* context, char buffer[]) {
+char *SHA384_End(SHA384_CTX* context, char buffer[SHA384_DIGEST_STRING_LENGTH]) {
 	sha2_byte	digest[SHA384_DIGEST_LENGTH], *d = digest;
 	int		i;
 
diff -ruN ruby-2.5.9.orig/ext/digest/sha2/sha2cc.h ruby-2.5.9/ext/digest/sha2/sha2cc.h
--- ruby-2.5.9.orig/ext/digest/sha2/sha2cc.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha2/sha2cc.h	2025-02-10 14:05:56.219288975 +0100
@@ -1,6 +1,33 @@
 #define COMMON_DIGEST_FOR_OPENSSL 1
 #include <CommonCrypto/CommonDigest.h>
 
+/*
+ * Prior to 10.5, OpenSSL-compatible definitions are missing for
+ * SHA2 macros, though the CC_ versions are present.
+ * Add the missing definitions we actually use here if needed.
+ * Note that the definitions are the argless 10.6+-style.
+ * The weird CTX mismatch is copied from the 10.6 header.
+ */
+#ifndef SHA256_DIGEST_LENGTH
+#define SHA256_DIGEST_LENGTH	CC_SHA256_DIGEST_LENGTH
+#define SHA256_CTX		CC_SHA256_CTX
+#define SHA256_Update		CC_SHA256_Update
+#define SHA256_Final		CC_SHA256_Final
+#endif /* !defined SHA256_DIGEST_LENGTH */
+
+#ifndef SHA384_DIGEST_LENGTH
+#define SHA384_DIGEST_LENGTH	CC_SHA384_DIGEST_LENGTH
+#define SHA512_CTX		CC_SHA512_CTX
+#define SHA384_Update		CC_SHA384_Update
+#define SHA384_Final		CC_SHA384_Final
+#endif /* !defined SHA384_DIGEST_LENGTH */
+
+#ifndef SHA512_DIGEST_LENGTH
+#define SHA512_DIGEST_LENGTH	CC_SHA512_DIGEST_LENGTH
+#define SHA512_Update		CC_SHA512_Update
+#define SHA512_Final		CC_SHA512_Final
+#endif /* !defined SHA512_DIGEST_LENGTH */
+
 #define SHA256_BLOCK_LENGTH	CC_SHA256_BLOCK_BYTES
 #define SHA384_BLOCK_LENGTH	CC_SHA384_BLOCK_BYTES
 #define SHA512_BLOCK_LENGTH	CC_SHA512_BLOCK_BYTES
@@ -29,3 +56,15 @@
 #undef SHA512_Finish
 #define SHA512_Update rb_digest_SHA512_update
 #define SHA512_Finish rb_digest_SHA512_finish
+
+/*
+ * Pre-10.6 defines are with args, which don't match the argless use in
+ * the function pointer inits.  Thus, we redefine SHA*_Init as well.
+ * This is a NOP on 10.6+.
+ */
+#undef SHA256_Init
+#define SHA256_Init CC_SHA256_Init
+#undef SHA384_Init
+#define SHA384_Init CC_SHA384_Init
+#undef SHA512_Init
+#define SHA512_Init CC_SHA512_Init
diff -ruN ruby-2.5.9.orig/ext/digest/sha2/sha2.h ruby-2.5.9/ext/digest/sha2/sha2.h
--- ruby-2.5.9.orig/ext/digest/sha2/sha2.h	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha2/sha2.h	2025-02-10 14:05:56.219288975 +0100
@@ -31,7 +31,7 @@
  *
  * $OrigId: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
  * $RoughId: sha2.h,v 1.3 2002/02/24 08:14:32 knu Exp $
- * $Id: sha2.h 46827 2014-07-15 14:59:20Z nobu $
+ * $Id$
  */
 
 #ifndef __SHA2_H__
diff -ruN ruby-2.5.9.orig/ext/digest/sha2/sha2init.c ruby-2.5.9/ext/digest/sha2/sha2init.c
--- ruby-2.5.9.orig/ext/digest/sha2/sha2init.c	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/ext/digest/sha2/sha2init.c	2025-02-10 14:05:56.219288975 +0100
@@ -1,11 +1,9 @@
 /* $RoughId: sha2init.c,v 1.3 2001/07/13 20:00:43 knu Exp $ */
-/* $Id: sha2init.c 52694 2015-11-21 04:35:57Z naruse $ */
+/* $Id$ */
 
 #include <ruby/ruby.h>
 #include "../digest.h"
-#if defined(SHA2_USE_OPENSSL)
-#include "sha2ossl.h"
-#elif defined(SHA2_USE_COMMONDIGEST)
+#if defined(SHA2_USE_COMMONDIGEST)
 #include "sha2cc.h"
 #else
 #include "sha2.h"
@@ -27,35 +25,50 @@
 FOREACH_BITLEN(DEFINE_ALGO_METADATA)
 
 /*
+ * Document-class: Digest::SHA256 < Digest::Base
+ *
  * Classes for calculating message digests using the SHA-256/384/512
  * Secure Hash Algorithm(s) by NIST (the US' National Institute of
  * Standards and Technology), described in FIPS PUB 180-2.
+ *
+ * See SHA2.
+ */
+/*
+ * Document-class: Digest::SHA384 < Digest::Base
+ *
+ * Classes for calculating message digests using the SHA-256/384/512
+ * Secure Hash Algorithm(s) by NIST (the US' National Institute of
+ * Standards and Technology), described in FIPS PUB 180-2.
+ *
+ * See SHA2.
+ */
+/*
+ * Document-class: Digest::SHA512 < Digest::Base
+ *
+ * Classes for calculating message digests using the SHA-256/384/512
+ * Secure Hash Algorithm(s) by NIST (the US' National Institute of
+ * Standards and Technology), described in FIPS PUB 180-2.
+ *
+ * See SHA2.
  */
 void
 Init_sha2(void)
 {
-    VALUE mDigest, cDigest_Base;
-    ID id_metadata;
-
-#define DECLARE_ALGO_CLASS(bitlen) \
-    VALUE cDigest_SHA##bitlen;
+    VALUE mDigest, cDigest_Base, cDigest_SHA2;
+    ID id_metadata = rb_id_metadata();
 
-    FOREACH_BITLEN(DECLARE_ALGO_CLASS)
-
-    rb_require("digest");
-
-    id_metadata = rb_intern_const("metadata");
+#if 0
+    mDigest = rb_define_module("Digest"); /* let rdoc know */
+#endif
+    mDigest = rb_digest_namespace();
+    cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
 
-    mDigest = rb_path2class("Digest");
-    cDigest_Base = rb_path2class("Digest::Base");
+    cDigest_SHA2 = rb_define_class_under(mDigest, "SHA256", cDigest_Base);
+    rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha256));
 
-#define DEFINE_ALGO_CLASS(bitlen) \
-    cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
-\
-    rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
-		Data_Wrap_Struct(0, 0, 0, (void *)&sha##bitlen));
+    cDigest_SHA2 = rb_define_class_under(mDigest, "SHA384", cDigest_Base);
+    rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha384));
 
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    FOREACH_BITLEN(DEFINE_ALGO_CLASS)
+    cDigest_SHA2 = rb_define_class_under(mDigest, "SHA512", cDigest_Base);
+    rb_ivar_set(cDigest_SHA2, id_metadata, rb_digest_make_metadata(&sha512));
 }
diff -ruN ruby-2.5.9.orig/lib/digest/sha2.rb ruby-2.5.9/lib/digest/sha2.rb
--- ruby-2.5.9.orig/lib/digest/sha2.rb	1970-01-01 01:00:00.000000000 +0100
+++ ruby-2.5.9/lib/digest/sha2.rb	2025-02-10 14:06:21.314061673 +0100
@@ -0,0 +1,142 @@
+# frozen_string_literal: false
+#--
+# sha2.rb - defines Digest::SHA2 class which wraps up the SHA256,
+#           SHA384, and SHA512 classes.
+#++
+# Copyright (c) 2006 Akinori MUSHA <knu@iDaemons.org>
+#
+# All rights reserved.  You can redistribute and/or modify it under the same
+# terms as Ruby.
+#
+#   $Id$
+
+require 'digest'
+require 'digest/sha2/loader'
+
+module Digest
+  #
+  # A meta digest provider class for SHA256, SHA384 and SHA512.
+  #
+  # FIPS 180-2 describes SHA2 family of digest algorithms. It defines
+  # three algorithms:
+  # * one which works on chunks of 512 bits and returns a 256-bit
+  #   digest (SHA256),
+  # * one which works on chunks of 1024 bits and returns a 384-bit
+  #   digest (SHA384),
+  # * and one which works on chunks of 1024 bits and returns a 512-bit
+  #   digest (SHA512).
+  #
+  # ==Examples
+  #  require 'digest'
+  #
+  #  # Compute a complete digest
+  #  Digest::SHA2.hexdigest 'abc'          # => "ba7816bf8..."
+  #  Digest::SHA2.new(256).hexdigest 'abc' # => "ba7816bf8..."
+  #  Digest::SHA256.hexdigest 'abc'        # => "ba7816bf8..."
+  #
+  #  Digest::SHA2.new(384).hexdigest 'abc' # => "cb00753f4..."
+  #  Digest::SHA384.hexdigest 'abc'        # => "cb00753f4..."
+  #
+  #  Digest::SHA2.new(512).hexdigest 'abc' # => "ddaf35a19..."
+  #  Digest::SHA512.hexdigest 'abc'        # => "ddaf35a19..."
+  #
+  #  # Compute digest by chunks
+  #  sha2 = Digest::SHA2.new               # =>#<Digest::SHA2:256>
+  #  sha2.update "ab"
+  #  sha2 << "c"                           # alias for #update
+  #  sha2.hexdigest                        # => "ba7816bf8..."
+  #
+  #  # Use the same object to compute another digest
+  #  sha2.reset
+  #  sha2 << "message"
+  #  sha2.hexdigest                        # => "ab530a13e..."
+  #
+  class SHA2 < Digest::Class
+    # call-seq:
+    #   Digest::SHA2.new(bitlen = 256) -> digest_obj
+    #
+    # Create a new SHA2 hash object with a given bit length.
+    #
+    # Valid bit lengths are 256, 384 and 512.
+    def initialize(bitlen = 256)
+      case bitlen
+      when 256
+        @sha2 = Digest::SHA256.new
+      when 384
+        @sha2 = Digest::SHA384.new
+      when 512
+        @sha2 = Digest::SHA512.new
+      else
+        raise ArgumentError, "unsupported bit length: %s" % bitlen.inspect
+      end
+      @bitlen = bitlen
+    end
+
+    # call-seq:
+    #   digest_obj.reset -> digest_obj
+    #
+    # Reset the digest to the initial state and return self.
+    def reset
+      @sha2.reset
+      self
+    end
+
+    # call-seq:
+    #   digest_obj.update(string) -> digest_obj
+    #   digest_obj << string -> digest_obj
+    #
+    # Update the digest using a given _string_ and return self.
+    def update(str)
+      @sha2.update(str)
+      self
+    end
+    alias << update
+
+    def finish # :nodoc:
+      @sha2.digest!
+    end
+    private :finish
+
+
+    # call-seq:
+    #   digest_obj.block_length -> Integer
+    #
+    # Return the block length of the digest in bytes.
+    #
+    #   Digest::SHA256.new.block_length * 8
+    #   # => 512
+    #   Digest::SHA384.new.block_length * 8
+    #   # => 1024
+    #   Digest::SHA512.new.block_length * 8
+    #   # => 1024
+    def block_length
+      @sha2.block_length
+    end
+
+    # call-seq:
+    #   digest_obj.digest_length -> Integer
+    #
+    # Return the length of the hash value (the digest) in bytes.
+    #
+    #   Digest::SHA256.new.digest_length * 8
+    #   # => 256
+    #   Digest::SHA384.new.digest_length * 8
+    #   # => 384
+    #   Digest::SHA512.new.digest_length * 8
+    #   # => 512
+    #
+    # For example, digests produced by Digest::SHA256 will always be 32 bytes
+    # (256 bits) in size.
+    def digest_length
+      @sha2.digest_length
+    end
+
+    def initialize_copy(other) # :nodoc:
+      @sha2 = other.instance_eval { @sha2.clone }
+    end
+
+    def inspect # :nodoc:
+      "#<%s:%d %s>" % [self.class.name, @bitlen, hexdigest]
+    end
+  end
+end
diff -ruN ruby-2.5.9.orig/lib/digest/version.rb ruby-2.5.9/lib/digest/version.rb
--- ruby-2.5.9.orig/lib/digest/version.rb	1970-01-01 01:00:00.000000000 +0100
+++ ruby-2.5.9/lib/digest/version.rb	2025-02-10 14:06:21.314061673 +0100
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+module Digest
+  VERSION = "3.2.0"
+end
diff -ruN ruby-2.5.9.orig/lib/digest.rb ruby-2.5.9/lib/digest.rb
--- ruby-2.5.9.orig/lib/digest.rb	1970-01-01 01:00:00.000000000 +0100
+++ ruby-2.5.9/lib/digest.rb	2025-02-10 14:06:21.314061673 +0100
@@ -0,0 +1,123 @@
+# frozen_string_literal: false
+
+if defined?(Digest) &&
+    /\A(?:2\.|3\.0\.[0-2]\z)/.match?(RUBY_VERSION) &&
+    caller_locations.any? { |l|
+      %r{/(rubygems/gem_runner|bundler/cli)\.rb}.match?(l.path)
+    }
+  # Before Ruby 3.0.3/3.1.0, the gem and bundle commands used to load
+  # the digest library before loading additionally installed gems, so
+  # you will get constant redefinition warnings and unexpected
+  # implementation overwriting if we proceed here.  Avoid that.
+  return
+end
+
+require 'digest/version'
+require 'digest/loader'
+
+module Digest
+  # A mutex for Digest().
+  REQUIRE_MUTEX = Thread::Mutex.new
+
+  def self.const_missing(name) # :nodoc:
+    case name
+    when :SHA256, :SHA384, :SHA512
+      lib = 'digest/sha2'
+    else
+      lib = File.join('digest', name.to_s.downcase)
+    end
+
+    begin
+      require lib
+    rescue LoadError
+      raise LoadError, "library not found for class Digest::#{name} -- #{lib}", caller(1)
+    end
+    unless Digest.const_defined?(name)
+      raise NameError, "uninitialized constant Digest::#{name}", caller(1)
+    end
+    Digest.const_get(name)
+  end
+
+  class ::Digest::Class
+    # Creates a digest object and reads a given file, _name_.
+    # Optional arguments are passed to the constructor of the digest
+    # class.
+    #
+    #   p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
+    #   # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
+    def self.file(name, *args)
+      new(*args).file(name)
+    end
+
+    # Returns the base64 encoded hash value of a given _string_.  The
+    # return value is properly padded with '=' and contains no line
+    # feeds.
+    def self.base64digest(str, *args)
+      [digest(str, *args)].pack('m0')
+    end
+  end
+
+  module Instance
+    # Updates the digest with the contents of a given file _name_ and
+    # returns self.
+    def file(name)
+      File.open(name, "rb") {|f|
+        buf = ""
+        while f.read(16384, buf)
+          update buf
+        end
+      }
+      self
+    end
+
+    # If none is given, returns the resulting hash value of the digest
+    # in a base64 encoded form, keeping the digest's state.
+    #
+    # If a +string+ is given, returns the hash value for the given
+    # +string+ in a base64 encoded form, resetting the digest to the
+    # initial state before and after the process.
+    #
+    # In either case, the return value is properly padded with '=' and
+    # contains no line feeds.
+    def base64digest(str = nil)
+      [str ? digest(str) : digest].pack('m0')
+    end
+
+    # Returns the resulting hash value and resets the digest to the
+    # initial state.
+    def base64digest!
+      [digest!].pack('m0')
+    end
+  end
+end
+
+# call-seq:
+#   Digest(name) -> digest_subclass
+#
+# Returns a Digest subclass by +name+ in a thread-safe manner even
+# when on-demand loading is involved.
+#
+#   require 'digest'
+#
+#   Digest("MD5")
+#   # => Digest::MD5
+#
+#   Digest(:SHA256)
+#   # => Digest::SHA256
+#
+#   Digest(:Foo)
+#   # => LoadError: library not found for class Digest::Foo -- digest/foo
+def Digest(name)
+  const = name.to_sym
+  Digest::REQUIRE_MUTEX.synchronize {
+    # Ignore autoload's because it is void when we have #const_missing
+    Digest.const_missing(const)
+  }
+rescue LoadError
+  # Constants do not necessarily rely on digest/*.
+  if Digest.const_defined?(const)
+    Digest.const_get(const)
+  else
+    raise
+  end
+end
diff -ruN ruby-2.5.9.orig/test/digest/test_digest_extend.rb ruby-2.5.9/test/digest/test_digest_extend.rb
--- ruby-2.5.9.orig/test/digest/test_digest_extend.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/test/digest/test_digest_extend.rb	2025-02-10 14:09:13.947265037 +0100
@@ -1,11 +1,16 @@
 # frozen_string_literal: false
 require 'test/unit'
 require 'digest'
-require_relative '../lib/with_different_ofs.rb'
+require_relative '../lib/with_different_ofs'
 
 class TestDigestExtend < Test::Unit::TestCase
   extend DifferentOFS
 
+  TEST_DIGEST = %w[SHA1024 SHA512 SHA384 SHA256 SHA1].find do |n|
+    break Digest.const_get(n)
+  rescue LoadError
+  end
+
   class MyDigest < Digest::Class
     def initialize(*arg)
       super
@@ -54,7 +59,7 @@
   end
 
   def test_class_reset
-    a = Digest::SHA1.new
+    a = TEST_DIGEST.new
     base = a.to_s
     assert_equal(base, a.reset.to_s)
     b = a.new
@@ -62,7 +67,7 @@
     b.update('1')
     assert_not_equal(base, b.to_s)
     assert_equal(base, b.reset.to_s)
-  end
+  end if TEST_DIGEST
 
   def test_digest
     assert_equal("\3", MyDigest.digest("foo"))
@@ -83,7 +88,7 @@
   end
 
   def test_new
-    a = Digest::SHA1.new
+    a = TEST_DIGEST.new
     b = a.new
     obj = a.to_s
     assert_equal(obj, a.to_s)
@@ -91,7 +96,7 @@
     a.update('1')
     assert_not_equal(obj, a.to_s)
     assert_equal(obj, b.to_s)
-  end
+  end if TEST_DIGEST
 
   def test_digest_hexdigest
     [:digest, :hexdigest].each do |m|
diff -ruN ruby-2.5.9.orig/test/digest/test_digest.rb ruby-2.5.9/test/digest/test_digest.rb
--- ruby-2.5.9.orig/test/digest/test_digest.rb	2021-04-05 13:46:35.000000000 +0200
+++ ruby-2.5.9/test/digest/test_digest.rb	2025-02-10 14:09:13.947265037 +0100
@@ -1,6 +1,6 @@
 # frozen_string_literal: false
 # $RoughId: test.rb,v 1.4 2001/07/13 15:38:27 knu Exp $
-# $Id: test_digest.rb 61186 2017-12-12 18:44:21Z eregon $
+# $Id$
 
 require 'test/unit'
 require 'tempfile'
@@ -247,10 +247,10 @@
     end
 
     def test_race
-      assert_separately(['-rdigest', "-I#{File.dirname(__FILE__)}"], <<-'end;')
+      assert_separately(['-rdigest', "-I#{File.dirname(__FILE__)}"], <<-"end;")
         assert_nothing_raised {
           t = Thread.start {
-            sleep 0.1
+            sleep #{ EnvUtil.apply_timeout_scale(0.1) }
             Digest(:Foo).new
           }
           Digest(:Foo).new
@@ -260,10 +260,10 @@
     end
 
     def test_race_mixed
-      assert_separately(['-rdigest', "-I#{File.dirname(__FILE__)}"], <<-'end;')
+      assert_separately(['-rdigest', "-I#{File.dirname(__FILE__)}"], <<-"end;")
         assert_nothing_raised {
           t = Thread.start {
-            sleep 0.1
+            sleep #{ EnvUtil.apply_timeout_scale(0.1) }
             Thread.current.report_on_exception = false
             Digest::Foo.new
           }
diff -ruN ruby-2.5.9.orig/test/digest/test_ractor.rb ruby-2.5.9/test/digest/test_ractor.rb
--- ruby-2.5.9.orig/test/digest/test_ractor.rb	1970-01-01 01:00:00.000000000 +0100
+++ ruby-2.5.9/test/digest/test_ractor.rb	2025-02-10 14:09:13.947265037 +0100
@@ -0,0 +1,97 @@
+# frozen_string_literal: true
+require 'test/unit'
+
+require 'digest'
+%w[digest/md5 digest/rmd160 digest/sha1 digest/sha2 digest/bubblebabble].each do |lib|
+  begin
+    require lib
+  rescue LoadError
+  end
+end
+
+module TestDigestRactor
+  Data1 = "abc"
+  Data2 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+
+  def test_s_hexdigest
+    assert_in_out_err([], <<-"end;", ["true", "true"], [])
+      $VERBOSE = nil
+      require "digest"
+      require "#{self.class::LIB}"
+      DATA = #{self.class::DATA.inspect}
+      rs = DATA.map do |str, hexdigest|
+        r = Ractor.new str do |x|
+          #{self.class::ALGO}.hexdigest(x)
+        end
+        [r, hexdigest]
+      end
+      rs.each do |r, hexdigest|
+        puts r.take == hexdigest
+      end
+    end;
+  end
+
+  class TestMD5Ractor < Test::Unit::TestCase
+    include TestDigestRactor
+    LIB = "digest/md5"
+    ALGO = Digest::MD5
+    DATA = {
+      Data1 => "900150983cd24fb0d6963f7d28e17f72",
+      Data2 => "8215ef0796a20bcaaae116d3876c664a",
+    }
+  end if defined?(Digest::MD5)
+
+  class TestSHA1Ractor < Test::Unit::TestCase
+    include TestDigestRactor
+    LIB = "digest/sha1"
+    ALGO = Digest::SHA1
+    DATA = {
+      Data1 => "a9993e364706816aba3e25717850c26c9cd0d89d",
+      Data2 => "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
+    }
+  end if defined?(Digest::SHA1)
+
+  class TestSHA256Ractor < Test::Unit::TestCase
+    include TestDigestRactor
+    LIB = "digest/sha2"
+    ALGO = Digest::SHA256
+    DATA = {
+      Data1 => "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
+      Data2 => "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
+    }
+  end if defined?(Digest::SHA256)
+
+  class TestSHA384Ractor < Test::Unit::TestCase
+    include TestDigestRactor
+    LIB = "digest/sha2"
+    ALGO = Digest::SHA384
+    DATA = {
+      Data1 => "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed"\
+               "8086072ba1e7cc2358baeca134c825a7",
+      Data2 => "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6"\
+               "b0455a8520bc4e6f5fe95b1fe3c8452b",
+    }
+  end if defined?(Digest::SHA384)
+
+  class TestSHA512Ractor < Test::Unit::TestCase
+    include TestDigestRactor
+    LIB = "digest/sha2"
+    ALGO = Digest::SHA512
+    DATA = {
+      Data1 => "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"\
+               "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
+      Data2 => "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c335"\
+               "96fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445",
+    }
+  end if defined?(Digest::SHA512)
+
+  class TestRMD160Ractor < Test::Unit::TestCase
+    include TestDigestRactor
+    LIB = "digest/rmd160"
+    ALGO = Digest::RMD160
+    DATA = {
+      Data1 => "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
+      Data2 => "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
+    }
+  end if defined?(Digest::RMD160)
+end if defined?(Ractor)
openSUSE Build Service is sponsored by