Subject: [PATCH v7 3/3] gnu: Add blacksmith.

From: Raghav Gururajan <[email-masked]>
Date: Thu, 9 Dec 2021 08:45:47 -0500

* gnu/packages/cybersecurity.scm (blacksmith): New variable.
---
 gnu/packages/cybersecurity.scm | 75 ++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/gnu/packages/cybersecurity.scm b/gnu/packages/cybersecurity.scm
index e4614e908e..2ebdf6a8f8 100644
--- a/gnu/packages/cybersecurity.scm
+++ b/gnu/packages/cybersecurity.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2020 Jakub Kądziołka <[email-masked]>
 ;;; Copyright © 2020, 2021 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2021 c4droid <[email-masked]>
+;;; Copyright © 2021 Raghav Gururajan <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -20,10 +21,14 @@
 
 (define-module (gnu packages cybersecurity)
   #:use-module (guix download)
+  #:use-module (guix git-download)
   #:use-module (guix packages)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
   #:use-module (guix build-system python)
+  #:use-module (gnu packages cpp)
   #:use-module (gnu packages engineering)
+  #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
   #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages python-crypto)
@@ -32,6 +37,76 @@ (define-module (gnu packages cybersecurity)
   #:use-module (gnu packages bioinformatics)      ;python-intervaltree
   #:use-module (gnu packages emulators))
 
+(define-public blacksmith
+  (package
+    (name "blacksmith")
+    (version "0.0.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri
+        (git-reference
+         (url "https://github.com/comsec-group/blacksmith")
+         (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "0kyp71wndf527dgza5iks5m5vj543mvxp5w7cjd8x0pilmd1xrls"))
+       (modules '((guix build utils)))
+       (snippet
+        `(begin
+           (delete-file-recursively "external")
+           (substitute* "CMakeLists.txt"
+             (("add_subdirectory\\(external\\)") "")
+             (("[ \t]*FetchContent_MakeAvailable\\(asmjit\\)")
+              (string-append "find_package(asmjit)\n"
+                             "find_package(nlohmann_json)")))
+           #t))))
+    (build-system cmake-build-system)
+    (arguments
+     `(#:tests? #f                      ;no test-suite
+       #:imported-modules
+       ((guix build copy-build-system)
+        ,@%cmake-build-system-modules)
+       #:modules
+       (((guix build copy-build-system)
+         #:prefix copy:)
+        (guix build cmake-build-system)
+        (guix build utils))
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'fix-build
+           (lambda _
+             (substitute* "CMakeLists.txt"
+               ;; Use default C++ standard instead.
+               (("cxx_std_17") "")
+               ;; This project tries to link argagg library,
+               ;; which doesn't exist, as argagg project
+               ;; is a single header file.
+               (("argagg") ""))))
+         (replace 'install
+           (lambda args
+             (apply (assoc-ref copy:%standard-phases 'install)
+                    #:install-plan
+                    '(("." "bin"
+                       #:include ("blacksmith"))
+                      ("." "lib"
+                       #:include-regexp ("\\.a$")))
+                    args))))))
+    (native-inputs
+     `(("pkg-config" ,pkg-config)))
+    (inputs
+     `(("argagg" ,argagg)
+       ("asmjit" ,asmjit)
+       ("json-modern-cxx" ,json-modern-cxx)))
+    (home-page "https://comsec.ethz.ch/research/dram/blacksmith")
+    (synopsis "Rowhammer fuzzer with non-uniform and frequency-based patterns")
+    (description "Blacksmith is an implementation of Rowhammer fuzzer that
+crafts novel non-uniform Rowhammer access patterns based on the concepts of
+frequency, phase, and amplitude.  It is able to bypass recent
+@acronym{TRR, Target Row Refresh}in-DRAM mitigations effectively and as such can
+trigger bit flips.")
+    (license license:expat)))
+
 (define-public ropgadget
   (package
     (name "ropgadget")
-- 
2.34.0