Documentation
¶
Index ¶
- Variables
- func ComputeHMAC(hashFunc func() hash.Hash, key, data []byte) []byte
- func EncodeSQN(sqn uint64) []byte
- func PrfPlus(prf PRF, key []byte, seed []byte, totalBytes int) ([]byte, error)
- func RandomBytes(n int) ([]byte, error)
- func VerifyHMAC(hashFunc func() hash.Hash, key, data, expectedMAC []byte) bool
- type DiffieHellman
- type Encrypter
- type FIPS1862PRFSHA1
- type IntegrityAlgorithm
- type Milenage
- func (m *Milenage) F1(rand, sqn, amf []byte) (macA, macS []byte, err error)
- func (m *Milenage) F2F5(rand []byte) (res, ak []byte, err error)
- func (m *Milenage) F3(rand []byte) (ck []byte, err error)
- func (m *Milenage) F4(rand []byte) (ik []byte, err error)
- func (m *Milenage) F5Star(rand []byte) (akStar []byte, err error)
- func (m *Milenage) GenerateAUTN(rand, sqn, amf []byte) (autn []byte, err error)
- func (m *Milenage) GenerateAUTS(rand, sqn []byte) ([]byte, error)
- func (m *Milenage) VerifyAUTN(rand, autn []byte, expectedSQN uint64) (res, ck, ik, auts []byte, err error)
- type PRF
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PRF_HMAC_MD5 = &hmacPRF{newHash: md5.New, keyLen: 16} PRF_HMAC_SHA1 = &hmacPRF{newHash: sha1.New, keyLen: 20} PRF_HMAC_SHA2_256 = &hmacPRF{newHash: sha256.New, keyLen: 32} PRF_HMAC_SHA2_384 = &hmacPRF{newHash: sha512.New384, keyLen: 48} PRF_HMAC_SHA2_512 = &hmacPRF{newHash: sha512.New, keyLen: 64} )
Functions ¶
func ComputeHMAC ¶
ComputeHMAC 通用 HMAC 计算函数
Types ¶
type DiffieHellman ¶
type DiffieHellman struct {
Group uint16
PrivateKey *big.Int
PublicKey *big.Int
P *big.Int
G *big.Int
}
func NewDiffieHellman ¶
func NewDiffieHellman(group uint16) (*DiffieHellman, error)
func (*DiffieHellman) ComputeSharedSecret ¶
func (dh *DiffieHellman) ComputeSharedSecret(peerPubKeyBytes []byte) ([]byte, error)
func (*DiffieHellman) GenerateKey ¶
func (dh *DiffieHellman) GenerateKey() error
func (*DiffieHellman) PublicKeyBytes ¶
func (dh *DiffieHellman) PublicKeyBytes() []byte
type Encrypter ¶
type Encrypter interface {
Encrypt(plaintext []byte, key []byte, iv []byte, aad []byte) ([]byte, error)
Decrypt(ciphertext []byte, key []byte, iv []byte, aad []byte) ([]byte, error)
IVSize() int
BlockSize() int
KeySize() int // 返回密钥长度 (不含盐)
}
加密接口
type FIPS1862PRFSHA1 ¶
type FIPS1862PRFSHA1 struct {
// contains filtered or unexported fields
}
func NewFIPS1862PRFSHA1 ¶
func NewFIPS1862PRFSHA1(key []byte) *FIPS1862PRFSHA1
type IntegrityAlgorithm ¶
type IntegrityAlgorithm interface {
// Compute 计算 MAC
Compute(key, data []byte) []byte
// Verify 验证 MAC
Verify(key, data, expectedMAC []byte) bool
// Output 长度
OutputSize() int
// Key 长度
KeySize() int
}
IntegrityAlgorithm 完整性算法接口
func GetIntegrityAlgorithm ¶
func GetIntegrityAlgorithm(id uint16) (IntegrityAlgorithm, error)
GetIntegrityAlgorithm 根据 ID 获取完整性算法
type Milenage ¶
type Milenage struct {
K [16]byte // 128 位用户密钥
OP [16]byte // 128 位运营商变体算法配置字段
OPc [16]byte // 派生的 OPc = AES_K(OP) ⊕ OP
}
Milenage 实现 3GPP TS 35.206 规范的认证算法 用于 EAP-AKA 认证,支持软件 SIM (不需要物理 SIM 卡)
func NewMilenage ¶
NewMilenage 创建 Milenage 实例 k: 128 位用户密钥 op: 128 位运营商密钥 (OP 或 OPc) useOPc: 如果为 true,则 op 参数是 OPc,否则是 OP
func (*Milenage) F1 ¶
F1 计算网络认证码 MAC-A 和重同步认证码 MAC-S 输入: RAND (16字节), SQN (6字节), AMF (2字节) 输出: MAC-A (8字节), MAC-S (8字节)
func (*Milenage) GenerateAUTN ¶
GenerateAUTN 生成认证令牌 AUTN AUTN = (SQN ⊕ AK) || AMF || MAC-A
func (*Milenage) GenerateAUTS ¶
GenerateAUTS 生成重同步参数 AUTS = (SQN ⊕ AK*) || MAC-S
Click to show internal directories.
Click to hide internal directories.