HDD Keys generating scripts

Discussion in 'General PS3 Discussion' started by Berion, Sep 14, 2016.

  1. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    Could someone confirm this is proper procedure? I wrote script for Linux bash, based on dev wiki info but for Fat it's not clear enough.
    http://www.psdevwiki.com/ps3/HDD_Encryption
    http://www.psdevwiki.com/ps3/Mounting_HDD_on_PC

    Also I cannot find anywhere kpartx patches, links on wiki are dead. :|

    Code:
    #!/bin/bash
    # for FAT
    erk_data=$(xxd -p -u -c 32 -l 32 "eid_root_key")
    erk_iv=$(xxd -p -u -c 16 -s -16 "eid_root_key")
    openssl aes-192-cbc -e -in "ata_data_seed" -out "ata_data_key" -K $erk_data -iv 0000000000000000 -nopad -nosalt
    openssl aes-192-cbc -e -in "ata_tweak_seed" -out "ata_tweak_key" -K $erk_data -iv 0000000000000000 -nopad -nosalt
    openssl aes-128-cbc -e -in "endec_data_seed" -out "endec_data_key" -K $erk_data -iv 0000000000000000 -nopad -nosalt
    openssl aes-128-cbc -e -in "endec_tweak_seed" -out "endec_tweak_key" -K $erk_data -iv 0000000000000000 -nopad -nosalt
    adk=$(xxd -p -u -c 24 -l 24 ata_data_key)
    atk=$(xxd -p -u -c 24 -l 24 ata_tweak_key)
    edk=$(xxd -p -u -c 16 -l 16 endec_data_key)
    etk=$(xxd -p -u -c 16 -l 16 endec_tweak_key)
    echo "$adk" "$atk" | xxd -r -p > hdd_key.bin
    echo "$edk" "$etk" | xxd -r -p > vflash_key.bin
    

    Code:
    
    #!/bin/bash
    # for SLIM
    erk_data=$(xxd -p -u -c 32 -l 32 "eid_root_key")
    erk_iv=$(xxd -p -u -c 16 -s -16 "eid_root_key")
    openssl aes-128-xts -e -in "ata_data_seed" -out "ata_data_key" -K $erk_data -iv $erk_iv -nopad -nosalt
    openssl aes-128-xts -e -in "ata_tweak_seed" -out "ata_tweak_key" -K $erk_data -iv $erk_iv -nopad -nosalt
    openssl aes-128-xts -e -in "endec_data_seed" -out "endec_data_key" -K $erk_data -iv $erk_iv -nopad -nosalt
    openssl aes-128-xts -e -in "endec_tweak_seed" -out "endec_tweak_key" -K $erk_data -iv $erk_iv -nopad -nosalt
    adk=$(xxd -p -u -c 16 -l 16 ata_data_key)
    atk=$(xxd -p -u -c 16 -l 16 ata_tweak_key)
    edk=$(xxd -p -u -c 16 -l 16 endec_data_key)
    etk=$(xxd -p -u -c 16 -l 16 endec_tweak_key)
    echo "$adk" "$atk" | xxd -r -p > hdd_key.bin
    echo "$edk" "$etk" | xxd -r -p > vflash_key.bin
    
    
     
  2. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    Just go to github.com & search for repositories under the name "multipath-tools".
    Many results, various repo clones, you will find everything you need including kpartx.

    Do the same thing for other repos that are now dead.. Generally there are clones available...
     
    Algol likes this.
  3. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    But isn't this a standard multipath-tools? Isn't a special one for PS3 fs table support? I cannot find any mirrors (and even forgot the name "multipath-tools", btw thanks).
     
  4. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    Look at the github.com repo openSuse/multipath-tools for instance.
    Or the cathay4t/multipath-tools repo which seems updated at least, last commit was 2 weeks ago.
    In the kpartx folder there is a ps3.c file.
    I think the ps3 patch has been upstreamed.
     
    Last edited: Sep 14, 2016
    Berion likes this.
  5. 7,541
    5,613
    872
    kozarovv

    kozarovv Super Moderator

    Joined:
    Nov 8, 2014
    Messages:
    7,541
    Likes Received:
    5,613
    Trophy Points:
    872
    Home Page:
    kpartx

    • kpartx is a tool which reads partition tables and creates device maps.
    • We need kpartx in order to be able to create partitions from device mapper targets.
    • But kpartx doesn't support PS3 partition table currently.
    • We need a patch which adds PS3 partition table support.
    • Official GIT repo: http://git.opensvc.com/multipath-tools/.git
    • PS3 partition table support is upstream now, you don't have to patch it anymore !!!
     
    Berion likes this.
  6. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    Ok. :) But we still need dm-bswap16, right? It doesn't compile for me and I have no idea why? Probably it's something trivial but for programmers, not for a gray citizen like me. ;)

    I'm, using Linux Mint 17.3 and 18 and I have installed build-essential and linux-headers matched to my current kernel but still I getting such error: "No rule to make target".

    Code:
    [email protected] /media/mint/TMP-2/ps3linux-dm-bswap16 $ sudo make
    make -C /lib/modules/4.4.0-21-generic/build M= modules
    make[1]: Entering directory '/usr/src/linux-headers-4.4.0-21-generic'
      HOSTCC  scripts/basic/fixdep
      HOSTCC  scripts/basic/bin2c
      HOSTCC  scripts/kconfig/conf.o
      HOSTCC  scripts/kconfig/zconf.tab.o
      HOSTLD  scripts/kconfig/conf
    scripts/kconfig/conf  --silentoldconfig Kconfig
    make[2]: *** No rule to make target 'arch/x86/entry/syscalls/syscall_32.tbl', needed by 'arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h'.  Stop.
    arch/x86/Makefile:199: recipe for target 'archheaders' failed
    make[1]: *** [archheaders] Error 2
    make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-21-generic'
    Makefile:7: recipe for target 'all' failed
    make: *** [all] Error 2
    When I trying compiling *.c it printed:

    Code:
    [email protected] /media/mint/TMP-2/ps3linux-dm-bswap16 $ sudo gcc -c dm-bswap16.c
    dm-bswap16.c:21:33: fatal error: linux/device-mapper.h: No such file or directory
    compilation terminated.
     
  7. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    Firstly I don't think you should use gcc, stick to the makefile..
    Secondly, some files are missing for the compilation to complete. You need to find out whether there are missing parts of the project or just dependencies to be obtained separately as a requirement.

    Have you tried with this complete archive?
    https://mega.co.nz/#!q51QnIRK!H_PdOPQ_D5gthSJt0lppBi9gtKgWmIozmxUZGNI6A3k

    If that does not solve your issue, we will need to look into the missing header files...

    Check this thread, it may give you useful info.
    http://www.ps3hax.net/showthread.php?t=51169
     
    Last edited: Sep 29, 2016
    nCadeRegal likes this.
  8. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    Inside "gitorious.ps3dev.net.7z|ps3linux.7z|ps3linux-dm-bswap16-master.tar.gz|ps3linux-dm-bswap16/" there are only and the same two files which I have: "dm-bswap16.c" and "Makefile".

    So maybe I don't understand something? It's an application for PS3 Linux, compiling only in this environment (i.e Debian from gitbrew or Red Ribbon) or application for any Linux distro (as logic tell me based on dev wiki title: "mounting on PC")?

    I read all data from this topic at ps3hax but there are lack of two things: no key generation script/app - only misty advices, and only a ready to use vm container with disk image. I want generate keys myself (because there is no app on PS3 side which do this for me) and setup environment on my Linux distro independent on any finished and temporary working version.

    Why even I care that? Because app made by 3141card for Windows is not only for reading content but also very buggy (and author doesn't care of them). So I looking universal solution for rw data on any PS3 HDD (i.e my HDD from Fat PS3 isn't completely encrypted, which is strange).

    And where are they? ;) Here? "/usr/src/linux-headers-4.4.0-21-generic/"
     
  9. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    Am not sure & I don't have the files in front of me to check.
    Have you looked for the mentioned paths/files flagged during compilation error in order to get your bearings?

    The compilation stops with the error generated by the Makefile in arch/x86, line 199, something to do with the syscalls implementation. syscalls_32.h may be using an include file that's missing...?
     
    Last edited: Sep 30, 2016
  10. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    Code:
    /usr/src/linux-headers-4.4.0-22-generic/arch/x86/entry/syscalls
    ├── Makefile -> ../../../../../linux-headers-4.4.0-22/arch/x86/entry/syscalls/Makefile
    ├── syscallhdr.sh -> ../../../../../linux-headers-4.4.0-22/arch/x86/entry/syscalls/syscallhdr.sh
    └── syscalltbl.sh -> ../../../../../linux-headers-4.4.0-22/arch/x86/entry/syscalls/syscalltbl.sh
    
    /usr/src/linux-headers-4.4.0-22-generic/include/generated
    ├── asm-offsets.h
    ├── autoconf.h
    ├── bounds.h
    ├── compile.h
    ├── timeconst.h
    ├── uapi
    │   └── linux
    │       └── version.h
    └── utsrelease.h
    
    /usr/src/linux-headers-4.4.0-22-generic/arch/x86/include/generated/asm/syscalls_32.h
    /usr/src/linux-headers-4.4.0-22/arch/sh/include/asm/syscalls_32.h
    
     
  11. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    The device mapper module is already installed?
    Those required dependencies are in place?
    udev 050+
    libdevmapper 1.2.38+
    urcu

    Also I see the dm-bswap16 project includes these files:

    #include <linux/device-mapper.h>
    #include <linux/module.h>
    #include <linux/version.h>
    #include <linux/init.h>
    #include <linux/bio.h>
    #include <linux/slab.h>
    #include <linux/mempool.h>
    #include <linux/workqueue.h>

    Do you have these headers installed?
     
  12. 7,541
    5,613
    872
    kozarovv

    kozarovv Super Moderator

    Joined:
    Nov 8, 2014
    Messages:
    7,541
    Likes Received:
    5,613
    Trophy Points:
    872
    Home Page:
    apt-get install linux-headers-4.4.0-21-generic
     
    bguerville likes this.
  13. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    He already has it installed.. Otherwise he would not have such a directory with files...

    Edit Sorry my mistake! WELL SPOTTED kozzy!

    Of course I didn't even see it even though it was staring me in the face, you have the wrong version installed for the generic Linux headers so the compilation process is looking for a different folder than the one you currently have! You have 4.4.0-22 but you need 4.4.0-21!

    See if you can get the 4.4.0-21 generic headers with apt like kozzy suggested, it should be there.
    If ever you don't have the option, you may need to use another apt repo or install it manually...

    FYI

    In the dm-bswap16 makefile we find the following stuff. As you can see, it is not a usual makefile because it leads to building the kernel modules by calling the appropriate makefiles.
    Code:
     
    KSRC_DIR=/lib/modules/$(shell uname -r)/build
    
    This line assigns the path to the kernel modules directory on your system to a variable. In order to build the full path, the kernel version is found by calling $(shell uname -r).
    Try it in terminal to see the result.... .
    Code:
     
    all: make -C $(KSRC_DIR) M=$(PWD) modules 
    
    Creates a target called all that has no requirements.
    The recipe to make all is to change the build directory into the directory that is named based on the current kernel release the system is running (which is located in the modules directory under /lib). Then once the new path is set, find a make file in that directory and build the target modules.
    Code:
     
    clean: make -C $(KSRC_DIR) M=$(PWD) clean
    
    The reason the clean target isn't just a rm is because the kernel has a lot of independent parts making rm commands too complicated & too long to write.

    Writing one monolithic makefile would be painful at best & really unmaintainable. That is why each logical part of the build directory has its own makefile that can be called from the coordinating makefile.

    Also as you can see, the makefile must be used with dm-bswap16, you can't use gcc on the C file here because it's not sufficient!
    In this case it's obvious that gcc won't cut it but you should note that it's generally the case with most projects except the most simple ones.
    A makefile often contains extra stuff, paths, flags.... which are necessary for successful compilation & it can also link to other Makefiles.
     
    Last edited: Sep 30, 2016
    Berion and kozarovv like this.
  14. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    On Mint v17.3 I have 4.4.0.22-generic (my resident OS) and on Mint v18 I have 4.4.0.21-generic (LiveDVD OS). On both there are the same compiling errors.

    Thanks for make clarifications. I looked into them before I posting but it was black magic for me (only things which I understand was uname part, and this is why I even installed linux-headers in the first place ;]). Anyway, once again thanks for clarifications.

    About H files from includes: I'll check tomorrow.
     
  15. 7,541
    5,613
    872
    kozarovv

    kozarovv Super Moderator

    Joined:
    Nov 8, 2014
    Messages:
    7,541
    Likes Received:
    5,613
    Trophy Points:
    872
    Home Page:
    @Berion can you upload dm-bswap16.c and makefile? Can be on pastebin like site or as a files. or even in spoiler as plain text.
     
    bitsbubba likes this.
  16. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    Sure:
     

    Attached Files:

    kozarovv likes this.
  17. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    Hold on, I don't get it...
    According to compilation output in your previous post, the kernel found by the compiler on your system is 4.4.0-21 but you say you are running a 4.4.0-22 kernel ?
    Unless you were trying to compile on Live OS?

    I'm any case, forget live OS & focus on the hdd installation only otherwise it gets confusing.
    Let's start again from the start...
    What's the kernel version running on your OS?
    What generic Linux headers version is installed in /usr/src/?
    When you launch the compilation of the day bswap16, the kernel version will be detected automatically, the compilation output will show you the detected version, just look at the directory path used in the output. Is the detected kernel version correct?

    And have you installed the dependencies required for the dm tools?
     
    Last edited: Oct 1, 2016
  18. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    I have tried on two environments: one is my standalone installation of Linux Mint 17.3 with kernel *22. Second is live session of Mint 18 with default kernel *21. On both I have installed linux-headers matched to their kernel versions. Why I using both? For test purposes, I have in the past situations that's not all compiling successfully on my old 17.3 (and I don't want jump to newest because it's lack of some apps like i.e gtk-hash for Nemo). Also I have output in Polish language on 17.3, so as for playground it's easier for me just boot live 18 where all is default and installing stuff is just more few minutes.

    So yes, we can focus on my installed 17.3. Detected kernel version is proper and I also have installed proper (matched) linux-headers to this version. Resulting the same error.
     
  19. 7,843
    6,517
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,843
    Likes Received:
    6,517
    Trophy Points:
    647
    Location:
    Earth
    Can you post the compilation output for this version please?
     
  20. 2,105
    1,994
    272
    Berion

    Berion Developer

    Joined:
    Feb 3, 2015
    Messages:
    2,105
    Likes Received:
    1,994
    Trophy Points:
    272
    Gender:
    Male
    Location:
    rom0:/
    Sure:
    Code:
    [email protected] /media/przemek/TMP-2/ps3linux-dm-bswap16 $ sudo make
    [sudo] password for przemek:
    make -C /lib/modules/4.4.0-22-generic/build M= modules
    make[1]: Wejście do katalogu `/usr/src/linux-headers-4.4.0-22-generic'
    make[2]: *** Brak reguł do zrobienia obiektu `arch/x86/entry/syscalls/syscall_32.tbl', wymaganego przez `arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h'. Stop.
    make[1]: *** [archheaders] Błąd 2
    make[1]: Opuszczenie katalogu `/usr/src/linux-headers-4.4.0-22-generic'
    make: *** [all] Błąd 2
    
    I have checked *.h files and I don't have "version.h" in: "/usr/src/linux-headers-4.4.0-22/include/linux/" (all other remaining yes).
     

    Attached Files:

    Last edited: Oct 1, 2016

Share This Page