crypto: Rename internal functions
This commit is contained in:
parent
7a7cc5b39f
commit
7b6bd98c9e
3 changed files with 7 additions and 7 deletions
|
@ -71,7 +71,7 @@ var poly1305KeyMask = [16]byte{
|
||||||
}
|
}
|
||||||
|
|
||||||
// key is a [32]byte, in the form k||r
|
// key is a [32]byte, in the form k||r
|
||||||
func poly1305_sign(msg []byte, nonce []byte, key *SigningKey) []byte {
|
func poly1305Sign(msg []byte, nonce []byte, key *SigningKey) []byte {
|
||||||
// prepare key for low-level poly1305.Sum(): r||n
|
// prepare key for low-level poly1305.Sum(): r||n
|
||||||
var k [32]byte
|
var k [32]byte
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ func macKeyFromSlice(mk *SigningKey, data []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// key: k||r
|
// key: k||r
|
||||||
func poly1305_verify(msg []byte, nonce []byte, key *SigningKey, mac []byte) bool {
|
func poly1305Verify(msg []byte, nonce []byte, key *SigningKey, mac []byte) bool {
|
||||||
// prepare key for low-level poly1305.Sum(): r||n
|
// prepare key for low-level poly1305.Sum(): r||n
|
||||||
var k [32]byte
|
var k [32]byte
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ func Encrypt(ks *Key, ciphertext, plaintext []byte) ([]byte, error) {
|
||||||
copy(ciphertext, iv[:])
|
copy(ciphertext, iv[:])
|
||||||
ciphertext = ciphertext[:ivSize+len(plaintext)]
|
ciphertext = ciphertext[:ivSize+len(plaintext)]
|
||||||
|
|
||||||
mac := poly1305_sign(ciphertext[ivSize:], ciphertext[:ivSize], &ks.Sign)
|
mac := poly1305Sign(ciphertext[ivSize:], ciphertext[:ivSize], &ks.Sign)
|
||||||
ciphertext = append(ciphertext, mac...)
|
ciphertext = append(ciphertext, mac...)
|
||||||
|
|
||||||
return ciphertext, nil
|
return ciphertext, nil
|
||||||
|
@ -252,7 +252,7 @@ func Decrypt(ks *Key, plaintext, ciphertext []byte) ([]byte, error) {
|
||||||
ciphertext, mac := ciphertext[:l], ciphertext[l:]
|
ciphertext, mac := ciphertext[:l], ciphertext[l:]
|
||||||
|
|
||||||
// verify mac
|
// verify mac
|
||||||
if !poly1305_verify(ciphertext[ivSize:], ciphertext[:ivSize], &ks.Sign, mac) {
|
if !poly1305Verify(ciphertext[ivSize:], ciphertext[:ivSize], &ks.Sign, mac) {
|
||||||
return nil, ErrUnauthenticated
|
return nil, ErrUnauthenticated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,13 +48,13 @@ func TestPoly1305(t *testing.T) {
|
||||||
key := &SigningKey{}
|
key := &SigningKey{}
|
||||||
copy(key.K[:], test.k)
|
copy(key.K[:], test.k)
|
||||||
copy(key.R[:], test.r)
|
copy(key.R[:], test.r)
|
||||||
mac := poly1305_sign(test.msg, test.nonce, key)
|
mac := poly1305Sign(test.msg, test.nonce, key)
|
||||||
|
|
||||||
if !bytes.Equal(mac, test.mac) {
|
if !bytes.Equal(mac, test.mac) {
|
||||||
t.Fatalf("wrong mac calculated, want: %02x, got: %02x", test.mac, mac)
|
t.Fatalf("wrong mac calculated, want: %02x, got: %02x", test.mac, mac)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !poly1305_verify(test.msg, test.nonce, key, test.mac) {
|
if !poly1305Verify(test.msg, test.nonce, key, test.mac) {
|
||||||
t.Fatalf("mac does not verify: mac: %02x", test.mac)
|
t.Fatalf("mac does not verify: mac: %02x", test.mac)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type encryptWriter struct {
|
||||||
|
|
||||||
func (e *encryptWriter) Close() error {
|
func (e *encryptWriter) Close() error {
|
||||||
// write mac
|
// write mac
|
||||||
mac := poly1305_sign(e.data.Bytes()[ivSize:], e.data.Bytes()[:ivSize], &e.key.Sign)
|
mac := poly1305Sign(e.data.Bytes()[ivSize:], e.data.Bytes()[:ivSize], &e.key.Sign)
|
||||||
_, err := e.origWr.Write(mac)
|
_, err := e.origWr.Write(mac)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue