Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9d05b352
提交
9d05b352
authored
12月 11, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
crypto/key: stretcher refactor
上级
ac2be0b6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
26 行删除
+30
-26
key.go
crypto/key.go
+18
-21
handshake.go
crypto/spipe/handshake.go
+12
-5
没有找到文件。
crypto/key.go
浏览文件 @
9d05b352
...
...
@@ -134,9 +134,15 @@ func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error) {
return
pubKey
,
done
,
nil
}
type
StretchedKeys
struct
{
IV
[]
byte
MacKey
[]
byte
CipherKey
[]
byte
}
// Generates a set of keys for each party by stretching the shared key.
// (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey)
func
KeyStretcher
(
c
mp
int
,
cipherType
string
,
hashType
string
,
secret
[]
byte
)
([]
byte
,
[]
byte
,
[]
byte
,
[]
byte
,
[]
byte
,
[]
byte
)
{
func
KeyStretcher
(
c
ipherType
string
,
hashType
string
,
secret
[]
byte
)
(
StretchedKeys
,
StretchedKeys
)
{
var
cipherKeySize
int
var
ivSize
int
switch
cipherType
{
...
...
@@ -198,31 +204,22 @@ func KeyStretcher(cmp int, cipherType string, hashType string, secret []byte) ([
a
=
m
.
Sum
(
nil
)
}
myResult
:=
make
([]
byte
,
ivSize
+
cipherKeySize
+
hmacKeySize
)
theirResult
:=
make
([]
byte
,
ivSize
+
cipherKeySize
+
hmacKeySize
)
half
:=
len
(
result
)
/
2
r1
:=
result
[
:
half
]
r2
:=
result
[
half
:
]
if
cmp
==
1
{
copy
(
myResult
,
result
[
:
half
])
copy
(
theirResult
,
result
[
half
:
])
}
else
if
cmp
==
-
1
{
copy
(
myResult
,
result
[
half
:
])
copy
(
theirResult
,
result
[
:
half
])
}
else
{
// Shouldn't happen, but oh well.
copy
(
myResult
,
result
[
half
:
])
copy
(
theirResult
,
result
[
half
:
])
}
var
k1
StretchedKeys
var
k2
StretchedKeys
myIV
:=
myResult
[
0
:
ivSize
]
myCKey
:=
myResult
[
ivSize
:
ivSize
+
cipherKeySize
]
myMKey
:=
myResult
[
ivSize
+
cipherKeySize
:
]
k1
.
IV
=
r1
[
0
:
ivSize
]
k1
.
CipherKey
=
r1
[
ivSize
:
ivSize
+
cipherKeySize
]
k1
.
MacKey
=
r1
[
ivSize
+
cipherKeySize
:
]
theirIV
:=
theirResult
[
0
:
ivSize
]
theirCKey
:=
theirResult
[
ivSize
:
ivSize
+
cipherKeySize
]
theirMKey
:=
theirResult
[
ivSize
+
cipherKeySize
:
]
k2
.
IV
=
r2
[
0
:
ivSize
]
k2
.
CipherKey
=
r2
[
ivSize
:
ivSize
+
cipherKeySize
]
k2
.
MacKey
=
r2
[
ivSize
+
cipherKeySize
:
]
return
myIV
,
theirIV
,
myCKey
,
theirCKey
,
myMKey
,
theirMKey
return
k1
,
k2
}
// UnmarshalPublicKey converts a protobuf serialized public key into its
...
...
crypto/spipe/handshake.go
浏览文件 @
9d05b352
...
...
@@ -183,12 +183,19 @@ func (s *SecurePipe) handshake() error {
return
err
}
k1
,
k2
:=
ci
.
KeyStretcher
(
cipherType
,
hashType
,
secret
)
cmp
:=
bytes
.
Compare
(
myPubKey
,
proposeResp
.
GetPubkey
())
mIV
,
tIV
,
mCKey
,
tCKey
,
mMKey
,
tMKey
:=
ci
.
KeyStretcher
(
cmp
,
cipherType
,
hashType
,
secret
)
go
s
.
handleSecureIn
(
hashType
,
cipherType
,
tIV
,
tCKey
,
tMKey
)
go
s
.
handleSecureOut
(
hashType
,
cipherType
,
mIV
,
mCKey
,
mMKey
)
switch
cmp
{
case
1
:
case
-
1
:
k1
,
k2
=
k2
,
k1
// swap
case
0
:
// really shouldnt kappen.
copy
(
k2
.
IV
,
k1
.
IV
)
copy
(
k2
.
MacKey
,
k1
.
MacKey
)
copy
(
k2
.
CipherKey
,
k1
.
CipherKey
)
}
go
s
.
handleSecureIn
(
hashType
,
cipherType
,
k2
.
IV
,
k2
.
CipherKey
,
k2
.
MacKey
)
go
s
.
handleSecureOut
(
hashType
,
cipherType
,
k1
.
IV
,
k1
.
CipherKey
,
k1
.
MacKey
)
finished
:=
[]
byte
(
"Finished"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论