package crypto
import (
"crypto/des"
"crypto/hmac"
"crypto/sha1"
"errors"
"hash"
"github.com/jcmturner/gokrb5/v8/crypto/common"
"github.com/jcmturner/gokrb5/v8/crypto/rfc3961"
"github.com/jcmturner/gokrb5/v8/iana/chksumtype"
"github.com/jcmturner/gokrb5/v8/iana/etypeID"
)
type Des3CbcSha1Kd struct {
}
func (e Des3CbcSha1Kd ) GetETypeID () int32 {
return etypeID .DES3_CBC_SHA1_KD
}
func (e Des3CbcSha1Kd ) GetHashID () int32 {
return chksumtype .HMAC_SHA1_DES3_KD
}
func (e Des3CbcSha1Kd ) GetKeyByteSize () int {
return 24
}
func (e Des3CbcSha1Kd ) GetKeySeedBitLength () int {
return 21 * 8
}
func (e Des3CbcSha1Kd ) GetHashFunc () func () hash .Hash {
return sha1 .New
}
func (e Des3CbcSha1Kd ) GetMessageBlockByteSize () int {
return des .BlockSize
}
func (e Des3CbcSha1Kd ) GetDefaultStringToKeyParams () string {
var s string
return s
}
func (e Des3CbcSha1Kd ) GetConfounderByteSize () int {
return des .BlockSize
}
func (e Des3CbcSha1Kd ) GetHMACBitLength () int {
return e .GetHashFunc ()().Size () * 8
}
func (e Des3CbcSha1Kd ) GetCypherBlockBitLength () int {
return des .BlockSize * 8
}
func (e Des3CbcSha1Kd ) StringToKey (secret string , salt string , s2kparams string ) ([]byte , error ) {
if s2kparams != "" {
return []byte {}, errors .New ("s2kparams must be an empty string" )
}
return rfc3961 .DES3StringToKey (secret , salt , e )
}
func (e Des3CbcSha1Kd ) RandomToKey (b []byte ) []byte {
return rfc3961 .DES3RandomToKey (b )
}
func (e Des3CbcSha1Kd ) DeriveRandom (protocolKey , usage []byte ) ([]byte , error ) {
r , err := rfc3961 .DeriveRandom (protocolKey , usage , e )
return r , err
}
func (e Des3CbcSha1Kd ) DeriveKey (protocolKey , usage []byte ) ([]byte , error ) {
r , err := e .DeriveRandom (protocolKey , usage )
if err != nil {
return nil , err
}
return e .RandomToKey (r ), nil
}
func (e Des3CbcSha1Kd ) EncryptData (key , data []byte ) ([]byte , []byte , error ) {
return rfc3961 .DES3EncryptData (key , data , e )
}
func (e Des3CbcSha1Kd ) EncryptMessage (key , message []byte , usage uint32 ) ([]byte , []byte , error ) {
return rfc3961 .DES3EncryptMessage (key , message , usage , e )
}
func (e Des3CbcSha1Kd ) DecryptData (key , data []byte ) ([]byte , error ) {
return rfc3961 .DES3DecryptData (key , data , e )
}
func (e Des3CbcSha1Kd ) DecryptMessage (key , ciphertext []byte , usage uint32 ) ([]byte , error ) {
return rfc3961 .DES3DecryptMessage (key , ciphertext , usage , e )
}
func (e Des3CbcSha1Kd ) VerifyIntegrity (protocolKey , ct , pt []byte , usage uint32 ) bool {
return rfc3961 .VerifyIntegrity (protocolKey , ct , pt , usage , e )
}
func (e Des3CbcSha1Kd ) GetChecksumHash (protocolKey , data []byte , usage uint32 ) ([]byte , error ) {
return common .GetHash (data , protocolKey , common .GetUsageKc (usage ), e )
}
func (e Des3CbcSha1Kd ) VerifyChecksum (protocolKey , data , chksum []byte , usage uint32 ) bool {
c , err := e .GetChecksumHash (protocolKey , data , usage )
if err != nil {
return false
}
return hmac .Equal (chksum , c )
}
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 .