Skip to content

Commit

Permalink
implement Decrypter interface
Browse files Browse the repository at this point in the history
  • Loading branch information
purifiedwater committed Sep 17, 2020
1 parent 058e61d commit 4a2cb80
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 更新日志

### master 更新(Sep 11, 2020):
### master 更新(Sep 17, 2020)
- 私钥新增Decrypt函数,实现crypto.Decrypter接口

### master 更新(Sep 11, 2020)
- 新增导入导出接口

| 接口名 | 接口功能 |
Expand Down Expand Up @@ -28,13 +31,13 @@
- 新增CHANGLOG文件


### master 更新(Aug 13, 2020):
### master 更新(Aug 13, 2020)
- 优化国密tls库,支持tls双国密证书通信。

### master 更新(Aug 7, 2020)
- 将中国网安的两个底层密码库合并到一起。

### master 更新(Jul 17, 2020):
### master 更新(Jul 17, 2020)
- 上传中国网安国密密码库。


Expand Down
5 changes: 5 additions & 0 deletions sm2/sm2enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package sm2

import (
"bytes"
"crypto"
"encoding/binary"
"errors"
"io"
Expand All @@ -18,6 +19,10 @@ import (
var EncryptionErr = errors.New("sm2: encryption error")
var DecryptionErr = errors.New("sm2: decryption error")

func (key *PrivateKey) Decrypt(rand io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error) {
return Decrypt(msg, key)
}

func keyDerivation(Z []byte, klen int) []byte {
var ct = 1
if klen%8 != 0 {
Expand Down
1 change: 1 addition & 0 deletions tls/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ func (c *Conn) Handshake() error {
// If an error occurred during the hadshake try to flush the
// alert that might be left in the buffer.
c.flush()
fmt.Println("handshake error :", c.handshakeErr)
}

if c.handshakeErr == nil && !c.handshakeComplete() {
Expand Down
2 changes: 1 addition & 1 deletion tls/gm_handshake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build sigle_cert
// +build single_cert

package tls

Expand Down
2 changes: 1 addition & 1 deletion tls/gm_handshake_client_double.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !sigle_cert
// +build !single_cert

package tls

Expand Down
2 changes: 1 addition & 1 deletion tls/gm_handshake_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build sigle_cert
// +build single_cert

package tls

Expand Down
2 changes: 1 addition & 1 deletion tls/gm_handshake_server_double.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !sigle_cert
// +build !single_cert

package tls

Expand Down

0 comments on commit 4a2cb80

Please sign in to comment.