| 1 |
package crypto |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto/aes" |
| 5 |
"crypto/hmac" |
| 6 |
"crypto/sha1" |
| 7 |
"hash" |
| 8 |
|
| 9 |
"gopkg.in/jcmturner/gokrb5.v5/crypto/common" |
| 10 |
"gopkg.in/jcmturner/gokrb5.v5/crypto/rfc3961" |
| 11 |
"gopkg.in/jcmturner/gokrb5.v5/crypto/rfc3962" |
| 12 |
"gopkg.in/jcmturner/gokrb5.v5/iana/chksumtype" |
| 13 |
"gopkg.in/jcmturner/gokrb5.v5/iana/etypeID" |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
type Aes256CtsHmacSha96 struct { |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
func (e Aes256CtsHmacSha96) GetETypeID() int32 { |
| 24 |
return etypeID.AES256_CTS_HMAC_SHA1_96 |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
func (e Aes256CtsHmacSha96) GetHashID() int32 { |
| 29 |
return chksumtype.HMAC_SHA1_96_AES256 |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
func (e Aes256CtsHmacSha96) GetKeyByteSize() int { |
| 34 |
return 256 / 8 |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
func (e Aes256CtsHmacSha96) GetKeySeedBitLength() int { |
| 39 |
return e.GetKeyByteSize() * 8 |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
func (e Aes256CtsHmacSha96) GetHashFunc() func() hash.Hash { |
| 44 |
return sha1.New |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
func (e Aes256CtsHmacSha96) GetMessageBlockByteSize() int { |
| 49 |
return 1 |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
func (e Aes256CtsHmacSha96) GetDefaultStringToKeyParams() string { |
| 54 |
return "00001000" |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
func (e Aes256CtsHmacSha96) GetConfounderByteSize() int { |
| 59 |
return aes.BlockSize |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
func (e Aes256CtsHmacSha96) GetHMACBitLength() int { |
| 64 |
return 96 |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
func (e Aes256CtsHmacSha96) GetCypherBlockBitLength() int { |
| 69 |
return aes.BlockSize * 8 |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
func (e Aes256CtsHmacSha96) StringToKey(secret string, salt string, s2kparams string) ([]byte, error) { |
| 74 |
return rfc3962.StringToKey(secret, salt, s2kparams, e) |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
func (e Aes256CtsHmacSha96) RandomToKey(b []byte) []byte { |
| 79 |
return rfc3961.RandomToKey(b) |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
func (e Aes256CtsHmacSha96) EncryptData(key, data []byte) ([]byte, []byte, error) { |
| 84 |
return rfc3962.EncryptData(key, data, e) |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
func (e Aes256CtsHmacSha96) EncryptMessage(key, message []byte, usage uint32) ([]byte, []byte, error) { |
| 89 |
return rfc3962.EncryptMessage(key, message, usage, e) |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
func (e Aes256CtsHmacSha96) DecryptData(key, data []byte) ([]byte, error) { |
| 94 |
return rfc3962.DecryptData(key, data, e) |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
func (e Aes256CtsHmacSha96) DecryptMessage(key, ciphertext []byte, usage uint32) ([]byte, error) { |
| 99 |
return rfc3962.DecryptMessage(key, ciphertext, usage, e) |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
func (e Aes256CtsHmacSha96) DeriveKey(protocolKey, usage []byte) ([]byte, error) { |
| 104 |
return rfc3961.DeriveKey(protocolKey, usage, e) |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
func (e Aes256CtsHmacSha96) DeriveRandom(protocolKey, usage []byte) ([]byte, error) { |
| 109 |
return rfc3961.DeriveRandom(protocolKey, usage, e) |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
func (e Aes256CtsHmacSha96) VerifyIntegrity(protocolKey, ct, pt []byte, usage uint32) bool { |
| 114 |
return rfc3961.VerifyIntegrity(protocolKey, ct, pt, usage, e) |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
func (e Aes256CtsHmacSha96) GetChecksumHash(protocolKey, data []byte, usage uint32) ([]byte, error) { |
| 119 |
return common.GetHash(data, protocolKey, common.GetUsageKc(usage), e) |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
func (e Aes256CtsHmacSha96) VerifyChecksum(protocolKey, data, chksum []byte, usage uint32) bool { |
| 124 |
c, err := e.GetChecksumHash(protocolKey, data, usage) |
| 125 |
if err != nil { |
| 126 |
return false |
| 127 |
} |
| 128 |
return hmac.Equal(chksum, c) |
| 129 |
} |