Skip to content

Commit

Permalink
Fix pointer to AEAD context
Browse files Browse the repository at this point in the history
The crypto_aead functions with precomputation take a pointer to a
`crypto_aead_aes256gcm_state` object as argument, not a char array.

The compiler is changed to clang because the code with the correct pointer does
not compile with GCC, see golang/go#7270.
  • Loading branch information
silkeh committed Jul 16, 2017
1 parent 548dff0 commit c72d571
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
exec go build ./...
export CC=clang
exec go build ./...
8 changes: 4 additions & 4 deletions cryptoaead/crypto_aead_aes256gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func CryptoAEADAES256GCMEncryptAfterNM(m, ad, npub, ctx []byte) ([]byte, int) {
(C.ulonglong)(len(ad)),
(*C.uchar)(nil),
(*C.uchar)(&npub[0]),
(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))
(*C.crypto_aead_aes256gcm_state)(unsafe.Pointer(&ctx[0]))))

return c, exit
}
Expand All @@ -171,7 +171,7 @@ func CryptoAEADAES256GCMDecryptAfterNM(c, ad, npub, ctx []byte) ([]byte, int) {
(*C.uchar)(support.BytePointer(ad)),
(C.ulonglong)(len(ad)),
(*C.uchar)(&npub[0]),
(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))
(*C.crypto_aead_aes256gcm_state)(unsafe.Pointer(&ctx[0]))))

return m, exit
}
Expand All @@ -194,7 +194,7 @@ func CryptoAEADAES256GCMEncryptDetachedAfterNM(m, ad, npub, ctx []byte) ([]byte,
(C.ulonglong)(len(ad)),
(*C.uchar)(nil),
(*C.uchar)(&npub[0]),
(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))
(*C.crypto_aead_aes256gcm_state)(unsafe.Pointer(&ctx[0]))))

return c, mac, exit
}
Expand All @@ -215,7 +215,7 @@ func CryptoAEADAES256GCMDecryptDetachedAfterNM(c, mac, ad, npub, ctx []byte) ([]
(*C.uchar)(support.BytePointer(ad)),
(C.ulonglong)(len(ad)),
(*C.uchar)(&npub[0]),
(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))
(*C.crypto_aead_aes256gcm_state)(unsafe.Pointer(&ctx[0]))))

return m, exit
}
Expand Down

0 comments on commit c72d571

Please sign in to comment.