2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-04 10:00:48 +00:00

crypto: Rename internal functions

This commit is contained in:
Alexander Neumann 2015-04-19 14:56:23 +02:00
parent 7a7cc5b39f
commit 7b6bd98c9e
3 changed files with 7 additions and 7 deletions

View File

@ -71,7 +71,7 @@ var poly1305KeyMask = [16]byte{
}
// 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
var k [32]byte
@ -113,7 +113,7 @@ func macKeyFromSlice(mk *SigningKey, data []byte) {
}
// 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
var k [32]byte
@ -228,7 +228,7 @@ func Encrypt(ks *Key, ciphertext, plaintext []byte) ([]byte, error) {
copy(ciphertext, iv[:])
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...)
return ciphertext, nil
@ -252,7 +252,7 @@ func Decrypt(ks *Key, plaintext, ciphertext []byte) ([]byte, error) {
ciphertext, mac := ciphertext[:l], ciphertext[l:]
// verify mac
if !poly1305_verify(ciphertext[ivSize:], ciphertext[:ivSize], &ks.Sign, mac) {
if !poly1305Verify(ciphertext[ivSize:], ciphertext[:ivSize], &ks.Sign, mac) {
return nil, ErrUnauthenticated
}

View File

@ -48,13 +48,13 @@ func TestPoly1305(t *testing.T) {
key := &SigningKey{}
copy(key.K[:], test.k)
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) {
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)
}
}

View File

@ -22,7 +22,7 @@ type encryptWriter struct {
func (e *encryptWriter) Close() error {
// 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)
if err != nil {
return err