Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
reencrypt
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengjun
reencrypt
Commits
e5da5d27
Commit
e5da5d27
authored
Apr 17, 2020
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add java sdk pre service
parent
8edee9ab
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
50 deletions
+30
-50
crypto_test.go
sdk/crypto/crypto_test.go
+0
-13
pre.go
sdk/pre.go
+12
-11
utils.go
sdk/types/utils.go
+5
-19
rpchandler.go
server/rpchandler.go
+11
-4
server_test.go
server/server_test.go
+1
-2
cli.go
tool/cli.go
+1
-1
No files found.
sdk/crypto/crypto_test.go
View file @
e5da5d27
...
...
@@ -2,8 +2,6 @@ package crypto
import
(
"fmt"
"gitlab.33.cn/pengjun/reencrypt/sdk/types"
"math/big"
"testing"
)
...
...
@@ -25,13 +23,3 @@ func TestAES(t *testing.T) {
fmt
.
Println
(
string
(
cipher
))
}
func
TestUtil
(
t
*
testing
.
T
)
{
var
num
=
big
.
NewInt
(
123
)
fmt
.
Println
(
num
)
numstr
:=
types
.
BigToString
(
num
)
fmt
.
Println
(
numstr
)
res
:=
types
.
StringToBig
(
numstr
)
fmt
.
Println
(
res
)
}
\ No newline at end of file
sdk/pre.go
View file @
e5da5d27
...
...
@@ -2,6 +2,7 @@ package sdk
import
(
"crypto/rand"
"errors"
"fmt"
secp256k1
"github.com/btcsuite/btcd/btcec"
"gitlab.33.cn/pengjun/reencrypt/sdk/crypto"
...
...
@@ -173,7 +174,7 @@ func GenerateKeyFragments(privOwner []byte, pubRecipient []byte, numSplit, thres
return
nil
,
err
}
dAliceHash
.
Write
(
pubRecipientKey
.
X
.
Bytes
())
dAliceHash
.
Write
(
dh_Alice_poit_x
.
Bytes
()
)
dAliceHash
.
Write
(
dh_Alice_poit_x
)
dAlice
:=
dAliceHash
.
Sum
(
nil
)
dAliceBN
:=
hashToModInt
(
dAlice
)
...
...
@@ -184,7 +185,7 @@ func GenerateKeyFragments(privOwner []byte, pubRecipient []byte, numSplit, thres
kFrags
:=
make
([]
*
KFrag
,
numSplit
)
if
numSplit
==
1
{
id
:=
getRandomInt
(
baseN
)
kFrags
[
0
]
=
&
KFrag
{
Random
:
types
.
BigToString
(
id
),
Value
:
types
.
BigToString
(
f0
),
PrecurPub
:
precurPub
}
kFrags
[
0
]
=
&
KFrag
{
Random
:
id
.
String
(),
Value
:
f0
.
String
(
),
PrecurPub
:
precurPub
}
}
else
{
coeffs
:=
makeShamirPolyCoeff
(
threshold
)
coeffs
=
append
(
coeffs
,
f0
)
...
...
@@ -198,11 +199,11 @@ func GenerateKeyFragments(privOwner []byte, pubRecipient []byte, numSplit, thres
return
nil
,
err
}
dShareHash
.
Write
(
pubRecipientKey
.
X
.
Bytes
())
dShareHash
.
Write
(
dh_Alice_poit_x
.
Bytes
()
)
dShareHash
.
Write
(
dh_Alice_poit_x
)
dShareHash
.
Write
(
id
.
Bytes
())
share
:=
hashToModInt
(
dShareHash
.
Sum
(
nil
))
rk
:=
hornerPolyEval
(
coeffs
,
share
)
kFrags
[
i
]
=
&
KFrag
{
Random
:
types
.
BigToString
(
id
),
Value
:
types
.
BigToString
(
rk
),
PrecurPub
:
precurPub
}
kFrags
[
i
]
=
&
KFrag
{
Random
:
id
.
String
(),
Value
:
rk
.
String
(
),
PrecurPub
:
precurPub
}
}
}
...
...
@@ -224,7 +225,7 @@ func AssembleReencryptFragment(privRecipient []byte, reKeyFrags []*ReKeyFrag) ([
return
nil
,
err
}
dBobHash
.
Write
(
privRecipientKey
.
X
.
Bytes
())
dBobHash
.
Write
(
dh_Bob_poit_x
.
Bytes
()
)
dBobHash
.
Write
(
dh_Bob_poit_x
)
dhBob
:=
dBobHash
.
Sum
(
nil
)
dhBobBN
:=
hashToModInt
(
dhBob
)
...
...
@@ -253,13 +254,13 @@ func AssembleReencryptFragment(privRecipient []byte, reKeyFrags []*ReKeyFrag) ([
return
nil
,
err
}
xs
.
Write
(
privRecipientKey
.
X
.
Bytes
())
xs
.
Write
(
dh_Bob_poit_x
.
Bytes
()
)
random
Byte
,
err
:=
types
.
FromHex
(
reKeyFrags
[
x
]
.
Random
)
if
err
!=
nil
{
fmt
.
Errorf
(
"
get randomByte err"
,
err
)
return
nil
,
err
xs
.
Write
(
dh_Bob_poit_x
)
random
,
ret
:=
new
(
big
.
Int
)
.
SetString
(
reKeyFrags
[
x
]
.
Random
,
10
)
if
!
ret
{
fmt
.
Errorf
(
"
AssembleReencryptFragment.get value int"
,
)
return
nil
,
err
ors
.
New
(
"get big int value from keyFragment failed"
)
}
xs
.
Write
(
random
Byte
)
xs
.
Write
(
random
.
Bytes
()
)
ids
[
x
]
=
hashToModInt
(
xs
.
Sum
(
nil
))
}
...
...
sdk/types/utils.go
View file @
e5da5d27
...
...
@@ -4,7 +4,6 @@ import (
"encoding/hex"
secp256k1
"github.com/btcsuite/btcd/btcec"
"github.com/golang/protobuf/proto"
"math/big"
)
//FromHex hex -> []byte
...
...
@@ -28,7 +27,7 @@ func ToHex(b []byte) string {
if
len
(
hex
)
==
0
{
return
""
}
return
"0x"
+
hex
return
hex
}
//Encode 编码
...
...
@@ -46,20 +45,8 @@ func Decode(data []byte, msg proto.Message) error {
}
// ECDH Calculate a shared secret using elliptic curve Diffie-Hellman
func
ECDH
(
priv
*
secp256k1
.
PrivateKey
,
pub
*
secp256k1
.
PublicKey
)
*
big
.
Int
{
x
,
_
:=
secp256k1
.
S256
()
.
ScalarMult
(
pub
.
X
,
pub
.
Y
,
priv
.
D
.
Bytes
())
return
x
func
ECDH
(
priv
*
secp256k1
.
PrivateKey
,
pub
*
secp256k1
.
PublicKey
)
[]
byte
{
ecKey
:=
&
secp256k1
.
PublicKey
{}
ecKey
.
X
,
ecKey
.
Y
=
secp256k1
.
S256
()
.
ScalarMult
(
pub
.
X
,
pub
.
Y
,
priv
.
D
.
Bytes
())
return
ecKey
.
SerializeCompressed
()
}
func
BigToString
(
num
*
big
.
Int
)
string
{
return
ToHex
(
num
.
Bytes
())
}
func
StringToBig
(
num
string
)
*
big
.
Int
{
numbyte
,
err
:=
FromHex
(
num
)
if
err
!=
nil
{
panic
(
err
)
}
return
new
(
big
.
Int
)
.
SetBytes
(
numbyte
)
}
\ No newline at end of file
server/rpchandler.go
View file @
e5da5d27
package
server
import
(
"errors"
secp256k1
"github.com/btcsuite/btcd/btcec"
"github.com/syndtr/goleveldb/leveldb"
"gitlab.33.cn/pengjun/reencrypt/common"
"gitlab.33.cn/pengjun/reencrypt/sdk/crypto"
"gitlab.33.cn/pengjun/reencrypt/sdk/types"
"math/big"
"time"
)
...
...
@@ -55,8 +57,9 @@ func checkDhProof(key string, pub string, dh string) bool {
return
false
}
proof
:=
types
.
ECDH
(
crypto
.
PrivateECDSAFromByte
(
keybyte
[
:
]),
pubkey
)
.
String
()
if
proof
!=
dh
{
private
:=
crypto
.
PrivateECDSAFromByte
(
keybyte
[
:
])
proof
:=
types
.
ECDH
(
private
,
pubkey
)
if
types
.
ToHex
(
proof
)
!=
dh
{
return
false
}
return
true
...
...
@@ -125,7 +128,11 @@ func (service *NodeService) Reencrypt(req *common.ReqReeencryptParam, result *in
return
err
}
rk
:=
types
.
StringToBig
(
keyFragment
.
Value
)
rk
,
ret
:=
new
(
big
.
Int
)
.
SetString
(
keyFragment
.
Value
,
10
)
if
!
ret
{
rlog
.
Error
(
"Reencrypt.get value int"
,)
return
errors
.
New
(
"get big int value from keyFragment failed"
)
}
var
reKeyR
,
reKeyU
secp256k1
.
PublicKey
reKeyR
.
X
,
reKeyR
.
Y
=
secp256k1
.
S256
()
.
ScalarMult
(
pubkeyR
.
X
,
pubkeyR
.
Y
,
rk
.
Bytes
())
reKeyU
.
X
,
reKeyU
.
Y
=
secp256k1
.
S256
()
.
ScalarMult
(
pubkeyU
.
X
,
pubkeyU
.
Y
,
rk
.
Bytes
())
...
...
@@ -137,7 +144,7 @@ func (service *NodeService) Reencrypt(req *common.ReqReeencryptParam, result *in
rep
.
PrecurPub
=
keyFragment
.
PrecurPub
*
result
=
rep
rlog
.
Info
(
"Reencrypt
start
"
,
"pubOwner"
,
req
.
PubOwner
,
"pubRecipient"
,
req
.
PubRecipient
)
rlog
.
Info
(
"Reencrypt
end
"
,
"pubOwner"
,
req
.
PubOwner
,
"pubRecipient"
,
req
.
PubRecipient
)
return
nil
}
server/server_test.go
View file @
e5da5d27
...
...
@@ -48,7 +48,7 @@ func handleReencrypt(t *testing.T, numSplit, threshold int, suffix string) {
Random
:
keyFragment
.
Random
,
Value
:
keyFragment
.
Value
,
Expire
:
1000000
,
DhProof
:
dhproof
.
String
(
),
DhProof
:
types
.
ToHex
(
dhproof
),
PrecurPub
:
keyFragment
.
PrecurPub
,
}
...
...
@@ -91,4 +91,3 @@ func TestReencryptSingle(t *testing.T) {
func
TestReencryptFrag
(
t
*
testing
.
T
)
{
handleReencrypt
(
t
,
3
,
2
,
"frag"
)
}
tool/cli.go
View file @
e5da5d27
...
...
@@ -111,7 +111,7 @@ func ownerEncrypt(cmd *cobra.Command, args []string) {
Random
:
keyFrags
[
0
]
.
Random
,
Value
:
keyFrags
[
0
]
.
Value
,
Expire
:
1000000
,
DhProof
:
dhproof
.
String
(
),
DhProof
:
types
.
ToHex
(
dhproof
),
PrecurPub
:
keyFrags
[
0
]
.
PrecurPub
,
}
jclient
.
Call
(
"CollectFragment"
,
param
,
&
result
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment