{"action":"created","issue":{"url":"https://api.github.com/repos/andlabs/reallymine/issues/33","repository_url":"https://api.github.com/repos/andlabs/reallymine","labels_url":"https://api.github.com/repos/andlabs/reallymine/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/andlabs/reallymine/issues/33/comments","events_url":"https://api.github.com/repos/andlabs/reallymine/issues/33/events","html_url":"https://github.com/andlabs/reallymine/issues/33","id":216125715,"number":33,"title":"Create sparse output files","user":{"login":"SteveAyre","id":1141663,"avatar_url":"https://avatars3.githubusercontent.com/u/1141663?v=3","gravatar_id":"","url":"https://api.github.com/users/SteveAyre","html_url":"https://github.com/SteveAyre","followers_url":"https://api.github.com/users/SteveAyre/followers","following_url":"https://api.github.com/users/SteveAyre/following{/other_user}","gists_url":"https://api.github.com/users/SteveAyre/gists{/gist_id}","starred_url":"https://api.github.com/users/SteveAyre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SteveAyre/subscriptions","organizations_url":"https://api.github.com/users/SteveAyre/orgs","repos_url":"https://api.github.com/users/SteveAyre/repos","events_url":"https://api.github.com/users/SteveAyre/events{/privacy}","received_events_url":"https://api.github.com/users/SteveAyre/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-03-22T16:22:21Z","updated_at":"2017-03-29T22:15:49Z","closed_at":null,"body":"Would it be possible to create the output file as a sparse file with the disk size as its apparent size (perhaps as a command line option)?\r\n\r\nI'm not familiar with Go so can't say how to create such a file, but with `dd` it would be as follows:\r\n\r\n> $ dd if=/dev/zero of=file.img bs=1 count=0 seek=512M\r\n> 0+0 records in\r\n> 0+0 records out\r\n> 0 bytes (0 B) copied, 0.00149225 s, 0.0 kB/s\r\n> $ du -h file.img\r\n> 0       file.img\r\n> $ du -h --apparent-size file.img\r\n> 512M    file.img\r\n\r\nThis would not immediately allocate the space on disk so wouldn't affect the time to decrypt the drive, but would make it appear as if it is the correct size.\r\n\r\nThis would be useful to try mounting the drive read-only for inspection while the decryption is still running. Without being a sparse file you'll see an dmesg error like `EXT4-fs (loop0): bad geometry: block count 244018688 exceeds size of device (30502080 blocks)` but with the correct apparent size the drive can be mounted successfully with the correct options (for example `mount -o loop,ro,noload,offset=$OFFSET,errors=continue $IMAGE $MOUNTPOINT`). How much is recoverable at that stage would depend on the decryption progress, but potentially allows recovering particular files much quicker. It also allows you to verify the resulting file is a mountable image early on."},"comment":{"url":"https://api.github.com/repos/andlabs/reallymine/issues/comments/290243202","html_url":"https://github.com/andlabs/reallymine/issues/33#issuecomment-290243202","issue_url":"https://api.github.com/repos/andlabs/reallymine/issues/33","id":290243202,"user":{"login":"themaddoctor","id":6364418,"avatar_url":"https://avatars3.githubusercontent.com/u/6364418?v=3","gravatar_id":"","url":"https://api.github.com/users/themaddoctor","html_url":"https://github.com/themaddoctor","followers_url":"https://api.github.com/users/themaddoctor/followers","following_url":"https://api.github.com/users/themaddoctor/following{/other_user}","gists_url":"https://api.github.com/users/themaddoctor/gists{/gist_id}","starred_url":"https://api.github.com/users/themaddoctor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/themaddoctor/subscriptions","organizations_url":"https://api.github.com/users/themaddoctor/orgs","repos_url":"https://api.github.com/users/themaddoctor/repos","events_url":"https://api.github.com/users/themaddoctor/events{/privacy}","received_events_url":"https://api.github.com/users/themaddoctor/received_events","type":"User","site_admin":false},"created_at":"2017-03-29T22:15:49Z","updated_at":"2017-03-29T22:15:49Z","body":"Here is the C code for it. To build, you need the build requirement for your kernel.\r\nOn Ubuntu, you get them with this:\r\nsudo apt-get build-dep linux-image-$(uname -r)\r\nCreate a makefile:\r\necho “obj-m := permute.o” > Makefile\r\nBuild:\r\nmake -C /lib/modules/`uname -r`/build M=$PWD\r\nInsert:\r\nsudo insmod ./permute.ko\r\n\r\n/*\r\n * Cryptographic API.\r\n * very simple cipher to permute each block of 16 bytes\r\n * Thomas Kaeding <thomas.a.kaeding@gmail.com>, 20170313\r\n */\r\n\r\n#include <linux/module.h>\r\n#include <linux/init.h>\r\n#include <linux/types.h>\r\n#include <linux/errno.h>\r\n#include <linux/crypto.h>\r\n#include <asm/byteorder.h>\r\n\r\nstatic u8 encvec[16], decvec[16];\r\n\r\nint permute_setkey(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len)\r\n{\r\n        int i;\r\n        for (i=0;i<key_len;i++) {\r\n                encvec[2*i]   = in_key[i] >> 4;\r\n                encvec[2*i+1] = in_key[i] & 0x0f;\r\n        }\r\n        for (i=0;i<16;i++)\r\n                decvec[encvec[i]] = (u8)i;\r\n        return 0;\r\n}\r\n\r\nstatic void permute_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)\r\n{\r\n        int i;\r\n        u8 temp[16];\r\n        for (i=0;i<16;i++)\r\n                temp[i] = in[i];\r\n        for (i=0;i<16;i++)\r\n                out[i] = temp[encvec[i]];\r\n        return;\r\n}\r\n\r\nstatic void permute_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)\r\n{\r\n        int i;\r\n        u8 temp[16];\r\n        for (i=0;i<16;i++)\r\n                temp[i] = in[i];\r\n        for (i=0;i<16;i++)\r\n                out[i] = temp[decvec[i]];\r\n        return;\r\n}\r\n\r\nstatic struct crypto_alg permute_alg = {\r\n        .cra_name               =       \"permute\",\r\n        .cra_driver_name        =       \"permute\",\r\n        .cra_priority           =       100,\r\n        .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,\r\n        .cra_blocksize          =       16,\r\n        .cra_ctxsize            =       0,\r\n        .cra_alignmask          =       3,\r\n        .cra_module             =       THIS_MODULE,\r\n        .cra_u                  =       {\r\n                .cipher = {\r\n                        .cia_min_keysize        =       8,\r\n                        .cia_max_keysize        =       8,\r\n                        .cia_setkey             =       permute_setkey,\r\n                        .cia_encrypt            =       permute_encrypt,\r\n                        .cia_decrypt            =       permute_decrypt\r\n                }\r\n        }\r\n};\r\n\r\nstatic int __init permute_init(void)\r\n{\r\n        return crypto_register_alg(&permute_alg);\r\n}\r\n\r\nstatic void __exit permute_fini(void)\r\n{\r\n        crypto_unregister_alg(&permute_alg);\r\n}\r\n\r\nmodule_init(permute_init);\r\nmodule_exit(permute_fini);\r\n\r\nMODULE_DESCRIPTION(\"permutes the bytes of each 16-byte block\");\r\nMODULE_LICENSE(\"GPL\");\r\nMODULE_ALIAS(\"permute\");\r\n"}}
{"actor":{"display_login":"themaddoctor"}}