Skip to content

Commit

Permalink
refactor: use CFB logic from go-crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
lubux committed Aug 28, 2023
1 parent f202cff commit f1e673a
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions helper/decrypt_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,7 @@ func QuickCheckDecryptReader(sessionKey *crypto.SessionKey, prefixReader crypto.
if err != nil {
return false, errors.New("gopenpgp: failed to initialize the cipher")
}

blockBuffer := make([]byte, blockSize)
// Decrypt 2 bytes of the second block
blockCipher.Encrypt(blockBuffer, encryptedData[:blockSize])
for ind := range blockBuffer[:2] {
encryptedData[blockSize+ind] ^= blockBuffer[ind]
}
for ind := range blockBuffer {
blockBuffer[ind] = 0
}
// Decrypt the first block
blockCipher.Encrypt(blockBuffer, blockBuffer)
for ind := range blockBuffer {
encryptedData[ind] ^= blockBuffer[ind]
}

_ = packet.NewOCFBDecrypter(blockCipher, encryptedData, packet.OCFBNoResync)
return encryptedData[blockSize-2] == encryptedData[blockSize] &&
encryptedData[blockSize-1] == encryptedData[blockSize+1], nil
}
Expand Down

0 comments on commit f1e673a

Please sign in to comment.