mirror of
https://github.com/HACKERALERT/Picocrypt.git
synced 2024-09-20 09:46:43 +00:00
More robust and reliable
Reduce metadataLength from 10 to 5, add BLAKE2b for fast mode, use regex to check if the input file is a valid Picocrypt volume when decrypting
This commit is contained in:
parent
0e294620b3
commit
dae39ef264
|
@ -23,8 +23,10 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
"sync"
|
"sync"
|
||||||
|
"hash"
|
||||||
"image"
|
"image"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"strconv"
|
"strconv"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -630,12 +632,31 @@ func onDrop(names []string){
|
||||||
// Open input file in read-only mode
|
// Open input file in read-only mode
|
||||||
fin,_ := os.Open(names[0])
|
fin,_ := os.Open(names[0])
|
||||||
|
|
||||||
|
// Use regex to test if input is a valid Picocrypt volume
|
||||||
|
tmp := make([]byte,30)
|
||||||
|
fin.Read(tmp)
|
||||||
|
if string(tmp[:5])=="v1.13"{
|
||||||
|
resetUI()
|
||||||
|
_status = "Please use Picocrypt v1.13 to decrypt this file."
|
||||||
|
_status_color = color.RGBA{0xff,0x00,0x00,255}
|
||||||
|
fin.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if valid,_:=regexp.Match(`^v\d\.\d{2}.{10}0?\d+`,tmp);!valid{
|
||||||
|
resetUI()
|
||||||
|
_status = "This doesn't seem to be a Picocrypt file."
|
||||||
|
_status_color = color.RGBA{0xff,0x00,0x00,255}
|
||||||
|
fin.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fin.Seek(0,0)
|
||||||
|
|
||||||
// Read metadata and insert into box
|
// Read metadata and insert into box
|
||||||
var err error
|
var err error
|
||||||
fin.Read(make([]byte,15))
|
fin.Read(make([]byte,15))
|
||||||
tmp := make([]byte,30)
|
tmp = make([]byte,15)
|
||||||
fin.Read(tmp)
|
fin.Read(tmp)
|
||||||
tmp,err = rsDecode(rs10,tmp)
|
tmp,err = rsDecode(rs5,tmp)
|
||||||
|
|
||||||
if err==nil{
|
if err==nil{
|
||||||
metadataLength,_ := strconv.Atoi(string(tmp))
|
metadataLength,_ := strconv.Atoi(string(tmp))
|
||||||
|
@ -644,7 +665,7 @@ func onDrop(names []string){
|
||||||
metadata = ""
|
metadata = ""
|
||||||
|
|
||||||
for i:=0;i<metadataLength*3;i+=3{
|
for i:=0;i<metadataLength*3;i+=3{
|
||||||
fmt.Println(tmp[i:i+3])
|
//fmt.Println(tmp[i:i+3])
|
||||||
t,err := rsDecode(rs1,tmp[i:i+3])
|
t,err := rsDecode(rs1,tmp[i:i+3])
|
||||||
if err!=nil{
|
if err!=nil{
|
||||||
metadata = "Metadata is corrupted."
|
metadata = "Metadata is corrupted."
|
||||||
|
@ -658,11 +679,9 @@ func onDrop(names []string){
|
||||||
|
|
||||||
flags := make([]byte,15)
|
flags := make([]byte,15)
|
||||||
fin.Read(flags)
|
fin.Read(flags)
|
||||||
flags,_ = rsDecode(rs5,flags)
|
flags,err = rsDecode(rs5,flags)
|
||||||
|
if err!=nil{
|
||||||
// If not a Picocrypt file, Reed-Solomon will fail
|
_status = "File is corrupt and cannot be decrypted."
|
||||||
if len(flags)==0{
|
|
||||||
_status = "This doesn't seem to be a Picocrypt file."
|
|
||||||
_status_color = color.RGBA{0xff,0x00,0x00,255}
|
_status_color = color.RGBA{0xff,0x00,0x00,255}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -891,9 +910,11 @@ func work(){
|
||||||
fout.Write(rsEncode(rs5,[]byte(version)))
|
fout.Write(rsEncode(rs5,[]byte(version)))
|
||||||
|
|
||||||
// Encode the length of the metadata with Reed-Solomon
|
// Encode the length of the metadata with Reed-Solomon
|
||||||
metadataLength := []byte(fmt.Sprintf("%010d",len(metadata)))
|
metadataLength := []byte(fmt.Sprintf("%05d",len(metadata)))
|
||||||
//fmt.Println("metadataLength:",metadataLength)
|
//fmt.Println("metadataLength:",metadataLength)
|
||||||
metadataLength = rsEncode(rs10,metadataLength)
|
metadataLength = rsEncode(rs5,metadataLength)
|
||||||
|
|
||||||
|
fmt.Println(metadataLength)
|
||||||
|
|
||||||
// Write the length of the metadata to file
|
// Write the length of the metadata to file
|
||||||
fout.Write(metadataLength)
|
fout.Write(metadataLength)
|
||||||
|
@ -954,17 +975,11 @@ func work(){
|
||||||
giu.Update()
|
giu.Update()
|
||||||
version := make([]byte,15)
|
version := make([]byte,15)
|
||||||
fin.Read(version)
|
fin.Read(version)
|
||||||
version,err1 = rsDecode(rs5,version)
|
_,err1 = rsDecode(rs5,version)
|
||||||
if string(version)=="v1.13"{
|
|
||||||
_status = "Please use Picocrypt v1.13 to decrypt this file."
|
|
||||||
_status_color = color.RGBA{0xff,0x00,0x00,255}
|
|
||||||
fin.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp := make([]byte,30)
|
tmp := make([]byte,15)
|
||||||
fin.Read(tmp)
|
fin.Read(tmp)
|
||||||
tmp,err2 = rsDecode(rs10,tmp)
|
tmp,err2 = rsDecode(rs5,tmp)
|
||||||
metadataLength,_ := strconv.Atoi(string(tmp))
|
metadataLength,_ := strconv.Atoi(string(tmp))
|
||||||
|
|
||||||
fin.Read(make([]byte,metadataLength*3))
|
fin.Read(make([]byte,metadataLength*3))
|
||||||
|
@ -1001,7 +1016,14 @@ func work(){
|
||||||
|
|
||||||
// Is there a better way?
|
// Is there a better way?
|
||||||
if err1!=nil||err2!=nil||err3!=nil||err4!=nil||err5!=nil||err6!=nil||err7!=nil||err8!=nil||err9!=nil{
|
if err1!=nil||err2!=nil||err3!=nil||err4!=nil||err5!=nil||err6!=nil||err7!=nil||err8!=nil||err9!=nil{
|
||||||
fmt.Println("Header error")
|
if keep{
|
||||||
|
kept = true
|
||||||
|
}else{
|
||||||
|
_status = "The header is corrupt and the file cannot be decrypted."
|
||||||
|
_status_color = color.RGBA{0xff,0x00,0x00,255}
|
||||||
|
fin.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1123,13 +1145,20 @@ func work(){
|
||||||
done := 0
|
done := 0
|
||||||
counter := 0
|
counter := 0
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
cipher,_ := chacha20.NewUnauthenticatedCipher(key,nonce)
|
cipher,_ := chacha20.NewUnauthenticatedCipher(key,nonce)
|
||||||
|
|
||||||
|
// Use HKDF-SHA3 to generate a subkey
|
||||||
|
var mac hash.Hash
|
||||||
subkey := make([]byte,32)
|
subkey := make([]byte,32)
|
||||||
hkdf := hkdf.New(sha3.New256,key,hkdfSalt,nil)
|
hkdf := hkdf.New(sha3.New256,key,hkdfSalt,nil)
|
||||||
hkdf.Read(subkey)
|
hkdf.Read(subkey)
|
||||||
mac := hmac.New(sha3.New512,subkey)
|
if fast{
|
||||||
|
// Keyed BLAKE2b
|
||||||
|
mac,_ = blake2b.New512(subkey)
|
||||||
|
}else{
|
||||||
|
// HMAC-SHA3
|
||||||
|
mac = hmac.New(sha3.New512,subkey)
|
||||||
|
}
|
||||||
for{
|
for{
|
||||||
if !working{
|
if !working{
|
||||||
_status = "Operation cancelled by user."
|
_status = "Operation cancelled by user."
|
||||||
|
@ -1185,7 +1214,7 @@ func work(){
|
||||||
}
|
}
|
||||||
|
|
||||||
if mode=="encrypt"{
|
if mode=="encrypt"{
|
||||||
fout.Seek(int64(276+len(metadata)*3),0)
|
fout.Seek(int64(261+len(metadata)*3),0)
|
||||||
fout.Write(rsEncode(rs64,keyHash))
|
fout.Write(rsEncode(rs64,keyHash))
|
||||||
fout.Write(rsEncode(rs32,khash_hash))
|
fout.Write(rsEncode(rs32,khash_hash))
|
||||||
fout.Write(rsEncode(rs64,mac.Sum(nil)))
|
fout.Write(rsEncode(rs64,mac.Sum(nil)))
|
||||||
|
@ -1201,6 +1230,7 @@ func work(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println(mac.Sum(nil),fileMac)
|
||||||
|
|
||||||
fin.Close()
|
fin.Close()
|
||||||
fout.Close()
|
fout.Close()
|
||||||
|
|
Loading…
Reference in a new issue