Subject: [PATCH core-updates 2/4] gnu: libtomcrypt: Update to 1.18.2-0.29986d0.

From: Maxim Cournoyer <[email-masked]>
Date: Mon, 16 Jan 2023 00:13:37 -0500

This change makes it possible to cross-compile libtomcrypt.

* gnu/packages/multiprecision.scm (libtomcrypt): Update to 1.18.2-0.29986d0.
[outputs]: Delete field.
[source]: Fetch from git.  Delete snippet and modules field.
[build-system]: Switch to cmake-build-system.
[phases]: Delete all phase.  Add patch-libtomcrypt.pc.in phase.
[native-inputs]: Delete field.
---

 gnu/packages/multiprecision.scm | 106 +++++++++++---------------------
 1 file changed, 35 insertions(+), 71 deletions(-)

diff --git a/gnu/packages/multiprecision.scm b/gnu/packages/multiprecision.scm
index c8b4639ed7..6acf22c6d6 100644
--- a/gnu/packages/multiprecision.scm
+++ b/gnu/packages/multiprecision.scm
@@ -364,80 +364,44 @@ (define-public tomsfastmath
     (license public-domain)))
 
 (define-public libtomcrypt
-  (package
-    (name "libtomcrypt")
-    (version "1.18.2")
-    (outputs '("out" "static"))
-    (source
-      (origin
-        (method url-fetch)
-        (uri (string-append "https://github.com/libtom/libtomcrypt"
-                            "/releases/download/v" version
-                            "/crypt-" version ".tar.xz"))
-        (sha256
-         (base32
-          "113vfrgapyv72lalhd3nkw7jnks8az0gcb5wqn9hj19nhcxlrbcn"))
-        (modules '((guix build utils)))
-        (snippet
-         '(begin
-            ;; Patch CVE-2019-17362
-            ;; https://github.com/libtom/libtomcrypt/commit/25c26a3b7a9ad8192ccc923e15cf62bf0108ef94
-            (substitute* "src/pk/asn1/der/utf8/der_decode_utf8_string.c"
-              (("z > 4") "z == 1 || z > 4"))
-            #t))))
-    (build-system gnu-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (delete 'configure) ; no configure
-         (add-after 'unpack 'prepare-build
-           (lambda _
-             ;; We want the shared library by default so force it to be the
-             ;; default makefile target.
-             (delete-file "makefile")
-             (symlink "makefile.shared" "makefile")
-             ;; We link to libtommath, so we need to add it to the pc file
-             (substitute* "libtomcrypt.pc.in"
-               (("-ltomcrypt") "-ltomcrypt -ltommath"))
-             #t))
-         (add-after 'build 'build-static
-           (lambda* (#:key make-flags #:allow-other-keys)
-             (apply invoke "make" "-f" "makefile.unix" make-flags)))
-         (replace 'check
-           (lambda* (#:key test-target make-flags #:allow-other-keys)
-             (apply invoke "make" "-f" "makefile.unix" test-target make-flags)
-             (invoke "./test")))
-         (add-after 'install 'install-static-library
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out"))
-                   (static (assoc-ref outputs "static")))
-               (mkdir-p (string-append static "/lib"))
-               (mkdir-p (string-append static "/include"))
-               (rename-file (string-append out "/lib/libtomcrypt.a")
-                            (string-append static "/lib/libtomcrypt.a"))
-               (copy-recursively (string-append out "/include")
-                                 (string-append static "/include"))
-               #t))))
-       #:test-target "test"
-       #:make-flags
-       (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
-             "CFLAGS += -DLTM_DESC -DUSE_LTM"
-             (string-append "EXTRALIBS="
-                            (search-input-file %build-inputs
-                                               "/lib/libtommath.so"))
-             (string-append "CC=" ,(cc-for-target)))))
-    (native-inputs
-     (list libtool))
-    (inputs
-     (list libtommath))
-    (home-page "https://www.libtom.net/LibTomCrypt/")
-    (synopsis "Cryptographic toolkit")
-    (description "LibTomCrypt is a fairly comprehensive, modular and portable
+  ;; Use the latest commit, as it contains a new CMake build system capable of
+  ;; cross-compilation.
+  (let ((revision "0")
+        (commit "29986d04f2dca985ee64fbca1c7431ea3e3422f4"))
+    (package
+      (name "libtomcrypt")
+      (version (git-version "1.18.2" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/libtom/libtomcrypt")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "02x0h3lcl2s4zykiqwdccj8cxsbilg0lspxn8r1gmhxc3k9bgk88"))))
+      (build-system cmake-build-system)
+      (arguments
+       (list
+        #:configure-flags #~(list "-DBUILD_TESTING=ON"
+                                  "-DBUILD_SHARED_LIBS=ON")
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'patch-libtomcrypt.pc.in
+              (lambda _
+                ;; We link to libtommath, so we need to add it to the pc file
+                ;; (see: https://github.com/libtom/libtomcrypt/issues/610).
+                (substitute* "libtomcrypt.pc.in"
+                  (("-ltomcrypt") "-ltomcrypt -ltommath")))))))
+      (inputs (list libtommath))
+      (home-page "https://www.libtom.net/LibTomCrypt/")
+      (synopsis "Cryptographic toolkit")
+      (description "LibTomCrypt is a fairly comprehensive, modular and portable
 cryptographic toolkit that provides developers with a vast array of well known
 published block ciphers, one-way hash functions, chaining modes, pseudo-random
 number generators, public key cryptography and a plethora of other routines.")
-    (properties `((lint-hidden-cve . ("CVE-2019-17362"))))
-    (license unlicense)))
+      (properties `((lint-hidden-cve . ("CVE-2019-17362"))))
+      (license unlicense))))
 
 (define-public libtommath
   ;; Use the latest commit, as it contains a new CMake build system capable of
-- 
2.38.1