1
0
Fork 0
mirror of https://github.com/HACKERALERT/Picocrypt.git synced 2024-12-29 19:02:43 +00:00

Updated to v1.9

Picocrypt 1.9 will be released soon.
This commit is contained in:
Evan Su 2021-03-16 15:07:25 -04:00 committed by GitHub
parent 25bf719c04
commit 3b223850b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -112,8 +112,10 @@ def inputSelected():
# Exception will be caught by except below # Exception will be caught by except below
raise Exception("No file selected.") raise Exception("No file selected.")
inputFile = tmp inputFile = tmp
# Decide if encrypting or decrypting # Decide if encrypting or decrypting (".pcf" is the legacy Picocrypt extension,
if ".pcf" in inputFile.split("/")[-1]: # ".pcv" is the newer Picocrypt extension. Both are cross-compatible, but
# I just think ".pcv" is better because it stands for "Picocrypt Volume")
if ".pcf" in inputFile.split("/")[-1] or ".pcv" in inputFile.split("/")[-1]:
suffix = " (will decrypt)" suffix = " (will decrypt)"
fin = open(inputFile,"rb+") fin = open(inputFile,"rb+")
# Read file metadata # Read file metadata
@ -217,9 +219,9 @@ def start():
chunkSize = 2**20 chunkSize = 2**20
# Decide if encrypting or decrypting # Decide if encrypting or decrypting
if ".pcf" not in inputFile: if ".pcf" not in inputFile and ".pcv" not in inputFile:
mode = "encrypt" mode = "encrypt"
outputFile = inputFile+".pcf" outputFile = inputFile+".pcv"
reedsolo = rs.get()==1 reedsolo = rs.get()==1
else: else:
mode = "decrypt" mode = "decrypt"
@ -229,7 +231,6 @@ def start():
test.close() test.close()
if decider=="+": if decider=="+":
reedsolo = True reedsolo = True
print("reed solo")
# Decrypted output is just input file without the extension # Decrypted output is just input file without the extension
outputFile = inputFile[:-4] outputFile = inputFile[:-4]
@ -288,12 +289,15 @@ def start():
fout.write(str(len(ad)).encode("utf-8")) # Length of metadata fout.write(str(len(ad)).encode("utf-8")) # Length of metadata
fout.write(b"|") # Separator fout.write(b"|") # Separator
fout.write(ad) # Metadata (associated data) fout.write(ad) # Metadata (associated data)
# Write zeros as placeholder, come back to write over it later # Write zeros as placeholder, come back to write over it later
fout.write(b"0"*64) # SHA3-512 of encryption key # Note that 8 additional bytes are added if Reed-Solomon is enabled
fout.write(b"0"*64) # CRC of file fout.write(b"0"*(64+(8 if reedsolo else 0))) # SHA3-512 of encryption key
fout.write(b"0"*16) # Poly1305 tag fout.write(b"0"*(64+(8 if reedsolo else 0))) # CRC of file
fout.write(salt) # Argon2 salt fout.write(b"0"*(16+(8 if reedsolo else 0))) # Poly1305 tag
fout.write(nonce) # ChaCha20 nonce # If Reed-Solomon is enabled, encode the salt and nonce, otherwise write them raw
fout.write(bytes(rsc.encode(salt)) if reedsolo else salt) # Argon2 salt
fout.write(bytes(rsc.encode(nonce)) if reedsolo else nonce) # ChaCha20 nonce
# If decrypting, read values from file # If decrypting, read values from file
else: else:
# Read past metadata into actual data # Read past metadata into actual data
@ -306,11 +310,19 @@ def start():
break break
fin.read(int(adlen.decode("utf-8"))) fin.read(int(adlen.decode("utf-8")))
# Read the salt, nonce, etc. # Read the salt, nonce, etc.
cs = fin.read(64) # Read 8 extra bytes if Reed-Solomon is enabled
crccs = fin.read(64) cs = fin.read(72 if reedsolo else 64)
digest = fin.read(16) crccs = fin.read(72 if reedsolo else 64)
salt = fin.read(16) digest = fin.read(24 if reedsolo else 16)
nonce = fin.read(24) salt = fin.read(24 if reedsolo else 16)
nonce = fin.read(32 if reedsolo else 24)
# If Reed-Solomon is enabled, decode each value
if reedsolo:
cs = bytes(rsc.decode(cs)[0])
crccs = bytes(rsc.decode(crccs)[0])
digest = bytes(rsc.decode(digest)[0])
salt = bytes(rsc.decode(salt)[0])
nonce = bytes(rsc.decode(nonce)[0])
# Show notice about key derivation # Show notice about key derivation
statusString.set(derivingNotice) statusString.set(derivingNotice)
@ -391,6 +403,12 @@ def start():
rsOffset = 1 if reedsolo else 0 rsOffset = 1 if reedsolo else 0
fout.seek(len(str(len(ad)))+1+len(ad)+rsOffset) fout.seek(len(str(len(ad)))+1+len(ad)+rsOffset)
# Write hash of key, CRC, and Poly1305 MAC tag # Write hash of key, CRC, and Poly1305 MAC tag
# Reed-Solomon-encode if selected by user
if reedsolo:
fout.write(bytes(rsc.encode(check)))
fout.write(bytes(rsc.encode(crc.digest())))
fout.write(bytes(rsc.encode(digest)))
else:
fout.write(check) fout.write(check)
fout.write(crc.digest()) fout.write(crc.digest())
fout.write(digest) fout.write(digest)
@ -530,9 +548,9 @@ def start():
# Show appropriate notice if file corrupted or modified # Show appropriate notice if file corrupted or modified
if not kept: if not kept:
if mode=="encrypt": if mode=="encrypt":
output = inputFile.split("/")[-1]+".pcf" output = inputFile.split("/")[-1]+".pcv"
else: else:
output = inputFile.split("/")[-1].replace(".pcf","") output = inputFile.split("/")[-1].replace(".pcf","").replace(".pcv","")
statusString.set(f"Completed. (Output: {output})") statusString.set(f"Completed. (Output: {output})")
# Show Reed-Solomon stats if it fixed corrupted bytes # Show Reed-Solomon stats if it fixed corrupted bytes
if mode=="decrypt" and reedsolo and reedsoloFixedCount: if mode=="decrypt" and reedsolo and reedsoloFixedCount:
@ -589,8 +607,7 @@ def wrapper():
# Try start() and handle errors # Try start() and handle errors
try: try:
start() start()
except Exception as e: except Exception:
print(e)
progress["value"] = 100 progress["value"] = 100
selectFileInput["state"] = "normal" selectFileInput["state"] = "normal"
passwordInput["state"] = "normal" passwordInput["state"] = "normal"