I've come up with a way to transform a stream of bytes such that if any single bit is modified, it cannot be transformed back into its original state. Here's how it works:
- Get hash of entire file (call it hash A)
- XOR file using repeat concatenations of hash A
- Get hash of XOR'd file (call it hash B)
- XOR hash A using hash B (call it key)
- Put key at beginning of file
- Hash file excluding key (we get hash B)
- XOR key using hash B (we get hash A)
- XOR file excluding key with hash A
- File is good if its hash matches hash A
I've made a working implementation of this here, using
sha1 as the hash function.
Edit: found out they're called All-or-nothing transforms.
My use case
I'm planning a peer-to-peer social networking system where users are authenticated using a conventional username/password combo. One method I can think of is to generate a private/public keypair, encode the private key with an AONT, split it up into pieces, and give an ID to each piece using some hash or PRNG output seeded by the username and password.
The pieces will then be distributed to random peers. Since each peer gets an incomplete part of the encoded file, it should not be readable. The peers would not know where the other pieces are, so the only way to reconstruct the file should be by getting all the pieces by generating the same IDs using the same username/password combo and requesting it from the network.
Somewhat like IPFS, where files are identified by its hash, each piece of the encoded file will only be accessible by its ID, which can only be acquired by seeding the PRNG with the correct username/password combo.
- Is my encoding method right? Did I miss anything that would cause the encoded file to be (partially) decoded when the complete file isn't accessible?
- Is there anything I could modify to improve it?
- Is my use case approach to storing private info correct?
Thanks in advance!