Last active
September 22, 2019 19:23
-
-
Save menangen/894915d02113ba43a7bd72bcfcaf3592 to your computer and use it in GitHub Desktop.
Salsa20 Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
//"crypto/rand" | |
"fmt" | |
"golang.org/x/crypto/salsa20" | |
) | |
func main() { | |
nonce := []byte { | |
0xe1,0x71,0x69,0x88,0xf5,0x62,0xad,0xb7,0xb1,0xcb,0x96,0x87,0x3c,0x80,0x7e,0x5a,0x4b,0xfd,0x39, | |
0x35,0x11,0x7b,0xf3,0x9f} | |
key := [32]byte { | |
0xee,0xce,0x81,0x55,0x9b,0x5d,0xa6,0xb0,0xd8,0xb0,0x1f,0x51,0x8d,0xbb,0x11,0x6,0x62,0x3e,0xea, | |
0xd7,0x7c,0x2b,0x34,0x18} | |
/* | |
// Generate a random 24 bytes nonce | |
nonce := make([]byte, 24) | |
if _, err := rand.Read(nonce); err != nil { | |
panic(err) | |
} | |
randomData := make([]byte, 32) | |
if _, err := rand.Read(randomData); err != nil { | |
panic(err) | |
} | |
var key [32]byte | |
copy(key[:], randomData[:]) | |
*/ | |
fmt.Printf("Key len: %d bytes\n", len(key)) | |
fmt.Printf("Key: {") | |
for _, element := range key { | |
fmt.Printf("%#x,", element) | |
} | |
fmt.Printf("}\n") | |
fmt.Printf("Nonce: {") | |
for _, element := range nonce { | |
fmt.Printf("%#x,", element) | |
} | |
fmt.Printf("}\n") | |
text := []byte("Hello, from Go!") | |
ciphertext := make([]byte, len(text)) | |
salsa20.XORKeyStream(ciphertext, text, nonce, &key) | |
fmt.Printf("\n%#x\n", ciphertext) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment