Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Aug 9, 2024
1 parent ab79ab2 commit 0009f56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rabin/rabin.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func (priv *PrivateKey) Public() crypto.PublicKey {

// crypto.Decrypter
func (priv *PrivateKey) Decrypt(_ io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error) {
if len(ciphertext) <= 32 {
if len(ciphertext) <= 36 {
return nil, errors.New("cryptobin/rabin: ciphertext data too short.")
}

length := getu32(ciphertext[:4])
length := int(getu32(ciphertext[:4]))

h := ciphertext[len(ciphertext) - 32:]
ct := ciphertext[4:len(ciphertext) - 32]
Expand Down
6 changes: 3 additions & 3 deletions rabin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ func decrypt(p *big.Int, q *big.Int, C *big.Int, N *big.Int) (
return ypPmqPlusyqQmp, NegativeypPmqPlusyqQmp, ypPmqMinusyqQmp, NegativeypPmqMinusyqQmp
}

func hashEqual(p *big.Int, h []byte, length uint32) (bool, []byte) {
if p.BitLen() > int(length) * 8 {
func hashEqual(p *big.Int, h []byte, length int) (bool, []byte) {
if p.BitLen() > length * 8 {
return false, nil
}

data := p.FillBytes(make([]byte, int(length)))
data := p.FillBytes(make([]byte, length))

hash := sha256.Sum256(data)
if bytes.Equal(hash[:], h) {
Expand Down

0 comments on commit 0009f56

Please sign in to comment.