about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorMasum Reza <50095635+JohnRTitor@users.noreply.github.com>2024-06-30 00:59:50 +0530
committerGitHub <noreply@github.com>2024-06-30 00:59:50 +0530
commit40366025414b4ba81921a410ea9089968b64c06b (patch)
tree0e9a9f6230a49b9a28508cd8a960ade9fbe98862 /pkgs
parente45e106e99f6c6fcf9c6cf7d2ea3611bb0837f0f (diff)
parenteac595161a60da7d695d46469e2e849d82da57d6 (diff)
Merge pull request #280482 from CyberShadow/pull-20240112-093826
john: add OpenCL support
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/tools/security/john/default.nix101
-rw-r--r--pkgs/tools/security/john/opencl.patch18
2 files changed, 102 insertions, 17 deletions
diff --git a/pkgs/tools/security/john/default.nix b/pkgs/tools/security/john/default.nix
index b06e0f3ec64ff..aeefcaa0bbefd 100644
--- a/pkgs/tools/security/john/default.nix
+++ b/pkgs/tools/security/john/default.nix
@@ -1,5 +1,25 @@
-{ lib, stdenv, fetchFromGitHub, openssl, nss, nspr, libkrb5, gmp, zlib, libpcap, re2
-, gcc, python3Packages, perl, perlPackages, makeWrapper, }:
+{
+  lib,
+  stdenv,
+  fetchFromGitHub,
+  openssl,
+  nss,
+  nspr,
+  libkrb5,
+  gmp,
+  zlib,
+  libpcap,
+  re2,
+  gcc,
+  python3Packages,
+  perl,
+  perlPackages,
+  withOpenCL ? true,
+  opencl-headers,
+  ocl-icd,
+  substituteAll,
+  makeWrapper,
+}:
 
 stdenv.mkDerivation rec {
   pname = "john";
@@ -12,6 +32,13 @@ stdenv.mkDerivation rec {
     hash = "sha256-zvoN+8Sx6qpVg2JeRLOIH1ehfl3tFTv7r5wQZ44Qsbc=";
   };
 
+  patches = lib.optionals withOpenCL [
+    (substituteAll {
+      src = ./opencl.patch;
+      ocl_icd = ocl-icd;
+    })
+  ];
+
   postPatch = ''
     sed -ri -e '
       s!^(#define\s+CFG_[A-Z]+_NAME\s+).*/!\1"'"$out"'/etc/john/!
@@ -23,25 +50,61 @@ stdenv.mkDerivation rec {
     }' run/*.conf
   '';
 
-  preConfigure = ''
-    cd src
-    # Makefile.in depends on AS and LD being set to CC, which is set by default in configure.ac.
-    # This ensures we override the environment variables set in cc-wrapper/setup-hook.sh
-    export AS=$CC
-    export LD=$CC
-  '';
+  preConfigure =
+    ''
+      cd src
+      # Makefile.in depends on AS and LD being set to CC, which is set by default in configure.ac.
+      # This ensures we override the environment variables set in cc-wrapper/setup-hook.sh
+      export AS=$CC
+      export LD=$CC
+    ''
+    + lib.optionalString withOpenCL ''
+      python ./opencl_generate_dynamic_loader.py  # Update opencl_dynamic_loader.c
+    '';
   configureFlags = [
     "--disable-native-tests"
     "--with-systemwide"
   ];
 
-  buildInputs = [ openssl nss nspr libkrb5 gmp zlib libpcap re2 ];
-  nativeBuildInputs = [ gcc python3Packages.wrapPython perl makeWrapper ];
-  propagatedBuildInputs = (with python3Packages; [ dpkt scapy lxml ]) ++ # For pcap2john.py
-                          (with perlPackages; [ DigestMD4 DigestSHA1 GetoptLong # For pass_gen.pl
-                                                CompressRawLzma # For 7z2john.pl
-                                                perlldap ]); # For sha-dump.pl
-                          # TODO: Get dependencies for radius2john.pl and lion2john-alt.pl
+  buildInputs =
+    [
+      openssl
+      nss
+      nspr
+      libkrb5
+      gmp
+      zlib
+      libpcap
+      re2
+    ]
+    ++ lib.optionals withOpenCL [
+      opencl-headers
+      ocl-icd
+    ];
+  nativeBuildInputs = [
+    gcc
+    python3Packages.wrapPython
+    perl
+    makeWrapper
+  ];
+  propagatedBuildInputs =
+    # For pcap2john.py
+    (with python3Packages; [
+      dpkt
+      scapy
+      lxml
+    ])
+    ++ (with perlPackages; [
+      # For pass_gen.pl
+      DigestMD4
+      DigestSHA1
+      GetoptLong
+      # For 7z2john.pl
+      CompressRawLzma
+      # For sha-dump.pl
+      perlldap
+    ]);
+  # TODO: Get dependencies for radius2john.pl and lion2john-alt.pl
 
   # gcc -DAC_BUILT -Wall vncpcap2john.o memdbg.o -g    -lpcap -fopenmp -o ../run/vncpcap2john
   # gcc: error: memdbg.o: No such file or directory
@@ -70,7 +133,11 @@ stdenv.mkDerivation rec {
     description = "John the Ripper password cracker";
     license = licenses.gpl2Plus;
     homepage = "https://github.com/openwall/john/";
-    maintainers = with maintainers; [ offline matthewbauer cherrykitten ];
+    maintainers = with maintainers; [
+      offline
+      matthewbauer
+      cherrykitten
+    ];
     platforms = platforms.unix;
   };
 }
diff --git a/pkgs/tools/security/john/opencl.patch b/pkgs/tools/security/john/opencl.patch
new file mode 100644
index 0000000000000..575bfa82638ba
--- /dev/null
+++ b/pkgs/tools/security/john/opencl.patch
@@ -0,0 +1,18 @@
+diff --git a/src/opencl_generate_dynamic_loader.py b/src/opencl_generate_dynamic_loader.py
+index 790705330..2acedbc56 100755
+--- a/src/opencl_generate_dynamic_loader.py
++++ b/src/opencl_generate_dynamic_loader.py
+@@ -134,12 +134,7 @@ static void load_opencl_dll(void)
+ 
+ 	/* Names to try to load */
+ 	const char * const opencl_names[] = {
+-		"libOpenCL.so",		/* Linux/others, hack via "development" sub-package's symlink */
+-		"OpenCL",		/* _WIN */
+-		"/System/Library/Frameworks/OpenCL.framework/OpenCL", /* __APPLE__ */
+-		"opencl.dll",		/* __CYGWIN__ */
+-		"cygOpenCL-1.dll",	/* __CYGWIN__ */
+-		"libOpenCL.so.1"	/* Linux/others, no "development" sub-package installed */
++		"@ocl_icd@/lib/libOpenCL.so"	/* NixOS */
+ 	};
+ 
+ 	for (i = 0; i < sizeof(opencl_names)/sizeof(opencl_names[0]); i++) {