Verified Commit 9fc55975 authored by Nadim Kobeissi's avatar Nadim Kobeissi 💎

Don't export everything

parent 7087f432
Pipeline #639 failed with stages
in 44 seconds
......@@ -48,8 +48,34 @@ func goConstants(c []Constant) string {
return goString
}
func goPrimitiveName(p Primitive) string {
goName := strings.ToLower(p.Name)
switch goName {
case "split", "hkdf":
return fmt.Sprintf("%s%d", p.Name, len(p.Arguments))
case "pw_hash":
return "pwHash"
case "aead_enc":
return "aeadEnc"
case "aead_dec":
return "aeadDec"
case "pke_enc":
return "pkeEnc"
case "pke_dec":
return "pkeDec"
case "shamir_split":
return "shamirSplit"
case "shamir_join":
return "shamirJoin"
default:
return goName
}
}
func goPrimitive(p Primitive) string {
goString := fmt.Sprintf("%s(", p.Name)
goString := fmt.Sprintf("%s(",
goPrimitiveName(p),
)
check := ""
if p.Check {
check = "?"
......@@ -127,7 +153,7 @@ func goExpression(expression Expression) (string, error) {
case "generates":
for _, c := range expression.Constants {
output = fmt.Sprintf(
"%s := GENERATES()\n\tif err != nil {\n\t\treturn err\n\t}",
"%s := generates()\n\tif err != nil {\n\t\treturn err\n\t}",
c.Name,
)
}
......
......@@ -41,16 +41,16 @@ var libgo = strings.Join([]string{
" * ELLIPTIC CURVE CRYPTOGRAPHY *",
" * ---------------------------------------------------------------- */",
"",
"func x25519DhFromEd25519PublicKey(private_key []byte, public_key []byte) ([]byte, error) {",
"\treturn curve25519.X25519(private_key, public_key)",
"func x25519DhFromEd25519PublicKey(privateKey []byte, publicKey []byte) ([]byte, error) {",
"\treturn curve25519.X25519(privateKey, publicKey)",
"}",
"",
"func ed25519Gen() ([]byte, []byte, error) {",
"\tpublic_key, private_key, err := ed25519.GenerateKey(rand.Reader)",
"\tpublicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)",
"\tif err != nil {",
"\t\treturn public_key, private_key, err",
"\t\treturn publicKey, privateKey, err",
"\t}",
"\treturn private_key, public_key, nil",
"\treturn privateKey, publicKey, nil",
"}",
"",
"func ed25519PublicKeyToCurve25519(pk ed25519.PublicKey) []byte {",
......@@ -224,7 +224,7 @@ var libgo = strings.Join([]string{
"\treturn k1, k2, k3, k4, k5, err",
"}",
"",
"func pw_hash(a ...[]byte) ([]byte, error) {",
"func pwHash(a ...[]byte) ([]byte, error) {",
"\th := hash(a...)",
"\tsalt := make([]byte, 16)",
"\t_, err := rand.Read(salt)",
......@@ -269,7 +269,7 @@ var libgo = strings.Join([]string{
"\treturn plaintext, nil",
"}",
"",
"func aead_enc(k []byte, plaintext []byte, ad []byte) ([]byte, error) {",
"func aeadEnc(k []byte, plaintext []byte, ad []byte) ([]byte, error) {",
"\tnonce := make([]byte, chacha20poly1305.NonceSizeX)",
"\t_, err := rand.Read(nonce)",
"\tif err != nil {",
......@@ -280,7 +280,7 @@ var libgo = strings.Join([]string{
"\treturn append(nonce, ciphertext...), nil",
"}",
"",
"func aead_dec(k []byte, ciphertext []byte, ad []byte) ([]byte, error) {",
"func aeadDec(k []byte, ciphertext []byte, ad []byte) ([]byte, error) {",
"\tenc, err := chacha20poly1305.NewX(k)",
"\tif err != nil {",
"\t\treturn []byte{}, err",
......@@ -296,7 +296,7 @@ var libgo = strings.Join([]string{
"\treturn plaintext, err",
"}",
"",
"func pke_enc(pk []byte, plaintext []byte) ([]byte, error) {",
"func pkeEnc(pk []byte, plaintext []byte) ([]byte, error) {",
"\tesk, epk, err := ed25519Gen()",
"\tif err != nil {",
"\t\treturn []byte{}, err",
......@@ -309,7 +309,7 @@ var libgo = strings.Join([]string{
"\treturn append(epk, ciphertext...), err",
"}",
"",
"func pke_dec(k []byte, ciphertext []byte) ([]byte, error) {",
"func pkeDec(k []byte, ciphertext []byte) ([]byte, error) {",
"\tif len(ciphertext) <= 32 {",
"\t\treturn []byte{}, fmt.Errorf(\"invalid ciphertext\")",
"\t}",
......@@ -334,7 +334,9 @@ var libgo = strings.Join([]string{
"\treturn []byte{}",
"}",
"",
"func ringsignverif(pka []byte, pkb []byte, pkc []byte, message []byte, signature []byte) bool {",
"func ringsignverif(",
"\tpka []byte, pkb []byte, pkc []byte, message []byte, signature []byte,",
") bool {",
"\treturn false",
"}",
"",
......@@ -346,11 +348,11 @@ var libgo = strings.Join([]string{
"\treturn []byte{}",
"}",
"",
"func shamir_split(x []byte) []byte {",
"func shamirSplit(x []byte) []byte {",
"\treturn []byte{}",
"}",
"",
"func shamir_join(a []byte, b []byte, c []byte) []byte {",
"func shamirJoin(a []byte, b []byte, c []byte) []byte {",
"\treturn []byte{}",
"}",
"",
......
......@@ -325,7 +325,9 @@ func ringsign(ka []byte, kb []byte, kc []byte, message []byte) []byte {
return []byte{}
}
func ringsignverif(pka []byte, pkb []byte, pkc []byte, message []byte, signature []byte) bool {
func ringsignverif(
pka []byte, pkb []byte, pkc []byte, message []byte, signature []byte,
) bool {
return false
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment