func TestCrypto(t *testing.T) { passwd := "hello world" initKey := sha256.Sum256([]byte(passwd)) nonce := sha512.Sum512_224([]byte(passwd)) cs, err := chacha20.NewXChaCha(initKey[:], nonce[:chacha20.XNonceSize]) ds, err := chacha20.NewXChaCha(initKey[:], nonce[:chacha20.XNonceSize]) if err != nil { t.Errorf("Bad init") } dst := make([]byte, len(passwd)) cs.XORKeyStream(dst, []byte(passwd)) den := make([]byte, 4) ds.XORKeyStream(den, dst[:4]) if !bytes.Equal([]byte("hell"), den) { t.Errorf("Bad Decoder") } }
func shasum(data *[]byte, algorithm string) (interface{}, error) { var sum interface{} switch strings.ToLower(algorithm) { case "md5": sum = md5.Sum(*data) case "1": sum = sha1.Sum(*data) case "224": sum = sha256.Sum224(*data) case "256": sum = sha256.Sum256(*data) case "384": sum = sha512.Sum384(*data) case "512": sum = sha512.Sum512(*data) case "512224": sum = sha512.Sum512_224(*data) case "512256": sum = sha512.Sum512_256(*data) default: return nil, errors.New("unsupported algorithm") } return sum, nil }