Skip to content

Commit

Permalink
v1.5.2-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroalbanese authored Aug 31, 2024
1 parent 5209097 commit 5a8e7c4
Showing 1 changed file with 80 additions and 79 deletions.
159 changes: 80 additions & 79 deletions cmd/edgetk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func main() {
flag.Parse()

if *version {
fmt.Println("EDGE Toolkit v1.5.1 14 Aug 2024")
fmt.Println("EDGE Toolkit v1.5.2a 30 Aug 2024")
}

if len(os.Args) < 2 {
Expand All @@ -305,7 +305,7 @@ Public Key Subcommands:
decrypt x509 verify help
Public Key Algorithms:
ecdsa/ecgdsa elgamal nums/nums-te sm2[ph]
ecdsa/eckcdsa elgamal nums/nums-te sm2[ph]
ed25519[ph] ec-elgamal rsa (default) sphincs
ed448[ph] kyber sm9encrypt x25519
gost2012 dilithium sm9sign[ph] x448
Expand Down Expand Up @@ -1539,83 +1539,6 @@ Subcommands:
}
}

if *crypt != "" && (*cph == "curupira" && strings.ToUpper(*mode) == "LETTERSOUP") {
var keyHex string
keyHex = *key
var key []byte
var err error
if keyHex == "" {
_, err = io.ReadFull(rand.Reader, key)
if err != nil {
log.Fatal(err)
}
fmt.Fprintln(os.Stderr, "Key=", hex.EncodeToString(key))
} else {
key, err = hex.DecodeString(keyHex)
if err != nil {
log.Fatal(err)
}
if len(key) != 12 && len(key) != 18 && len(key) != 24 {
log.Fatal("Invalid key size. Key must be either 96, 144, or 192 bits for Curupira.")
}
}

buf := bytes.NewBuffer(nil)
var data io.Reader
data = inputfile
io.Copy(buf, data)
msg := buf.Bytes()

aad := []byte(*info)

cipher, err := curupira1.NewCipher(key)
if err != nil {
log.Fatal("Error creating Curupira cipher instance:", err)
}

aead := curupira1.NewLetterSoup(cipher)

if *crypt == "enc" {
nonce := make([]byte, 12)
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
log.Fatal(err)
}
aead.SetIV(nonce)

ciphertext := make([]byte, len(msg))
aead.Encrypt(ciphertext, msg)
aead.Update(aad)
tag := aead.GetTag(nil, 96)

output := append(nonce, tag...)
output = append(output, ciphertext...)
os.Stdout.Write(output)

os.Exit(0)
}

if *crypt == "dec" {
nonce, tag, msg := msg[:12], msg[12:24], msg[24:]

aead.SetIV(nonce)

decrypted := make([]byte, len(msg))
aead.Decrypt(decrypted, msg)

ciphertext := make([]byte, len(decrypted))
aead.Encrypt(ciphertext, decrypted)
aead.Update(aad)
tagEnc := aead.GetTag(nil, 96)

if bytes.Equal(tag, tagEnc) {
os.Stdout.Write(decrypted)
os.Exit(0)
} else {
log.Fatal("Error: authentication verification failed!")
}
}
}

if *crypt != "" && (*cph == "rc4") {
var keyHex string
keyHex = *key
Expand Down Expand Up @@ -2707,6 +2630,84 @@ Subcommands:
os.Exit(0)
}

if *crypt != "" && (*cph == "curupira" && strings.ToUpper(*mode) == "LETTERSOUP") {
var keyHex string
keyHex = *key
var key []byte
var err error
if keyHex == "" {
key = make([]byte, *length/8)
_, err = io.ReadFull(rand.Reader, key)
if err != nil {
log.Fatal(err)
}
fmt.Fprintln(os.Stderr, "Key=", hex.EncodeToString(key))
} else {
key, err = hex.DecodeString(keyHex)
if err != nil {
log.Fatal(err)
}
if len(key) != 12 && len(key) != 18 && len(key) != 24 {
log.Fatal("Invalid key size. Key must be either 96, 144, or 192 bits for Curupira.")
}
}

buf := bytes.NewBuffer(nil)
var data io.Reader
data = inputfile
io.Copy(buf, data)
msg := buf.Bytes()

aad := []byte(*info)

cipher, err := curupira1.NewCipher(key)
if err != nil {
log.Fatal("Error creating Curupira cipher instance:", err)
}

aead := curupira1.NewLetterSoup(cipher)

if *crypt == "enc" {
nonce := make([]byte, 12)
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
log.Fatal(err)
}
aead.SetIV(nonce)

ciphertext := make([]byte, len(msg))
aead.Encrypt(ciphertext, msg)
aead.Update(aad)
tag := aead.GetTag(nil, 96)

output := append(nonce, tag...)
output = append(output, ciphertext...)
os.Stdout.Write(output)

os.Exit(0)
}

if *crypt == "dec" {
nonce, tag, msg := msg[:12], msg[12:24], msg[24:]

aead.SetIV(nonce)

decrypted := make([]byte, len(msg))
aead.Decrypt(decrypted, msg)

ciphertext := make([]byte, len(decrypted))
aead.Encrypt(ciphertext, decrypted)
aead.Update(aad)
tagEnc := aead.GetTag(nil, 96)

if bytes.Equal(tag, tagEnc) {
os.Stdout.Write(decrypted)
os.Exit(0)
} else {
log.Fatal("Error: authentication verification failed!")
}
}
}

if *crypt != "" && (*cph == "curupira") && (strings.ToUpper(*mode) == "EAX") {
var keyHex string
keyHex = *key
Expand Down

0 comments on commit 5a8e7c4

Please sign in to comment.