package crypto
import (
"crypto/sha1"
"github.com/gotd/td/bin"
)
func sha1a (r []byte , authKey Key , msgKey bin .Int128 , x int ) []byte {
h := sha1 .New ()
_, _ = h .Write (msgKey [:])
_, _ = h .Write (authKey [x : x +32 ])
return h .Sum (r )
}
func sha1b (r []byte , authKey Key , msgKey bin .Int128 , x int ) []byte {
h := sha1 .New ()
_, _ = h .Write (authKey [32 +x : 32 +x +16 ])
_, _ = h .Write (msgKey [:])
_, _ = h .Write (authKey [48 +x : 48 +x +16 ])
return h .Sum (r )
}
func sha1c (r []byte , authKey Key , msgKey bin .Int128 , x int ) []byte {
h := sha1 .New ()
_, _ = h .Write (authKey [64 +x : 64 +x +32 ])
_, _ = h .Write (msgKey [:])
return h .Sum (r )
}
func sha1d (r []byte , authKey Key , msgKey bin .Int128 , x int ) []byte {
h := sha1 .New ()
_, _ = h .Write (msgKey [:])
_, _ = h .Write (authKey [96 +x : 96 +x +32 ])
return h .Sum (r )
}
func OldKeys (authKey Key , msgKey bin .Int128 , mode Side ) (key , iv bin .Int256 ) {
x := getX (mode )
aesKey := func (sha1a , sha1b , sha1c []byte ) (v bin .Int256 ) {
n := copy (v [:], sha1a [:8 ])
n += copy (v [n :], sha1b [8 :8 +12 ])
copy (v [n :], sha1c [4 :4 +12 ])
return v
}
aesIV := func (sha1a , sha1b , sha1c , sha1d []byte ) (v bin .Int256 ) {
n := copy (v [:], sha1a [8 :8 +12 ])
n += copy (v [n :], sha1b [:8 ])
n += copy (v [n :], sha1c [16 :16 +4 ])
copy (v [n :], sha1d [:8 ])
return v
}
r := make ([]byte , sha1 .Size *4 )
a := sha1a (r [0 :0 ], authKey , msgKey , x )
b := sha1b (r [sha1 .Size :sha1 .Size ], authKey , msgKey , x )
c := sha1c (r [2 *sha1 .Size :2 *sha1 .Size ], authKey , msgKey , x )
d := sha1d (r [3 *sha1 .Size :3 *sha1 .Size ], authKey , msgKey , x )
return aesKey (a , b , c ), aesIV (a , b , c , d )
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .