diff --git a/crypto/key.go b/crypto/key.go index c2c0a69..220fd28 100644 --- a/crypto/key.go +++ b/crypto/key.go @@ -78,8 +78,8 @@ func newSymmetricKey(ek *packet.EncryptedKey) *SymmetricKey { } } +// DecryptAttKey and return a symmetric key // Use: bridge -// Decrypt and return a symmetric key func DecryptAttKey(kr *KeyRing, keyPacket string) (key *SymmetricKey, err error) { r := base64.NewDecoder(base64.StdEncoding, strings.NewReader(keyPacket)) packets := packet.NewReader(r) diff --git a/crypto/session.go b/crypto/session.go index 624467a..736f235 100644 --- a/crypto/session.go +++ b/crypto/session.go @@ -11,8 +11,8 @@ import ( "golang.org/x/crypto/openpgp/packet" ) -// Use: ios/android only //RandomToken ... +// Use: ios/android only func (pm *PmCrypto) RandomToken() ([]byte, error) { config := &packet.Config{DefaultCipher: packet.CipherAES256} keySize := config.DefaultCipher.KeySize() @@ -23,8 +23,8 @@ func (pm *PmCrypto) RandomToken() ([]byte, error) { return symKey, nil } -// Use: ios/android only // RandomTokenWith ... +// Use: ios/android only func (pm *PmCrypto) RandomTokenWith(size int) ([]byte, error) { config := &packet.Config{DefaultCipher: packet.CipherAES256} symKey := make([]byte, size) @@ -34,8 +34,8 @@ func (pm *PmCrypto) RandomTokenWith(size int) ([]byte, error) { return symKey, nil } +// GetSessionFromKeyPacket get session key no encoding in and out // Use: ios/android only -//GetSessionFromKeyPacketBinkeys get session key no encoding in and out func (pm *PmCrypto) GetSessionFromKeyPacket(keyPackage []byte, privateKey *KeyRing, passphrase string) (*SymmetricKey, error) { keyReader := bytes.NewReader(keyPackage) @@ -68,14 +68,14 @@ func (pm *PmCrypto) GetSessionFromKeyPacket(keyPackage []byte, privateKey *KeyRi } if decryptErr != nil { - return nil, err + return nil, decryptErr } return getSessionSplit(ek) } -// Use: ios/android only //KeyPacketWithPublicKey ... +// Use: ios/android only func (pm *PmCrypto) KeyPacketWithPublicKey(sessionSplit *SymmetricKey, publicKey string) ([]byte, error) { pubkeyRaw, err := armor.Unarmor(publicKey) if err != nil { @@ -84,8 +84,8 @@ func (pm *PmCrypto) KeyPacketWithPublicKey(sessionSplit *SymmetricKey, publicKey return pm.KeyPacketWithPublicKeyBin(sessionSplit, pubkeyRaw) } -// Use: ios/android only // KeyPacketWithPublicKeyBin ... +// Use: ios/android only func (pm *PmCrypto) KeyPacketWithPublicKeyBin(sessionSplit *SymmetricKey, publicKey []byte) ([]byte, error) { publicKeyReader := bytes.NewReader(publicKey) pubKeyEntries, err := openpgp.ReadKeyRing(publicKeyReader) @@ -169,8 +169,8 @@ func (pm *PmCrypto) GetSessionFromSymmetricPacket(keyPackage []byte, password st return nil, errors.New("password incorrect") } -// Use: ios/android only // SymmetricKeyPacketWithPassword ... +// Use: ios/android only func (pm *PmCrypto) SymmetricKeyPacketWithPassword(sessionSplit *SymmetricKey, password string) ([]byte, error) { outbuf := &bytes.Buffer{} diff --git a/crypto/subtle.go b/crypto/subtle.go index 700f790..35f181d 100644 --- a/crypto/subtle.go +++ b/crypto/subtle.go @@ -7,8 +7,8 @@ import ( "golang.org/x/crypto/scrypt" ) -// Use: ios/android only // EncryptWithoutIntegrity encrypts data with AES-CTR. Note: this encryption mode is not secure when stored/sent on an untrusted medium. +// Use: ios/android only func EncryptWithoutIntegrity(key, input, iv []byte) (output []byte, err error) { var block cipher.Block if block, err = aes.NewCipher(key); err != nil { @@ -20,15 +20,15 @@ func EncryptWithoutIntegrity(key, input, iv []byte) (output []byte, err error) { return } -// Use: ios/android only // DecryptWithoutIntegrity decrypts data encrypted with AES-CTR. +// Use: ios/android only func DecryptWithoutIntegrity(key, input, iv []byte) ([]byte, error) { // AES-CTR decryption is identical to encryption. return EncryptWithoutIntegrity(key, input, iv) } -// Use: ios/android only // DeriveKey derives a key from a password using scrypt. N should be set to the highest power of 2 you can derive within 100 milliseconds. +// Use: ios/android only func DeriveKey(password string, salt []byte, N int) ([]byte, error) { return scrypt.Key([]byte(password), salt, N, 8, 1, 32) }