crypto

package
v0.185.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Database = make(map[int]User)

Database simulates a simple in-memory user database

Functions

func CalcMd5File

func CalcMd5File(filename string) (string, error)

TODO(@benqi): remove to baselib

func GenerateAccessHash

func GenerateAccessHash(user User, visitorID int) int64

GenerateAccessHash generates a unique access hash for a user accessed by a specific visitor and returns it as int64

func GenerateBaseHash

func GenerateBaseHash(userID int, timestamp int64, salt int) int64

GenerateBaseHash generates a base hash for a user and returns it as int64

func GenerateNonce

func GenerateNonce(size int) []byte

func GenerateStringNonce

func GenerateStringNonce(size int) string

func NewAesCBCDecrypt

func NewAesCBCDecrypt(aesKey, aesIV []byte) (cipher.BlockMode, error)

func NewAesCBCEncrypt

func NewAesCBCEncrypt(aesKey, aesIV []byte) (cipher.BlockMode, error)

func RandomBytes

func RandomBytes(size int) []byte

func RandomString

func RandomString(size int) string

func Sha1Digest

func Sha1Digest(data []byte) []byte

func Sha256Digest

func Sha256Digest(data []byte) []byte

func VerifyAccessHash

func VerifyAccessHash(userID int, visitorID int, providedAccessHash int64) bool

VerifyAccessHash verifies if the provided access hash matches the expected hash for a visitor

Types

type AES256IGECryptor

type AES256IGECryptor struct {
	// contains filtered or unexported fields
}

func NewAES256IGECryptor

func NewAES256IGECryptor(aesKey, aesIV []byte) *AES256IGECryptor

func (*AES256IGECryptor) Decrypt

func (c *AES256IGECryptor) Decrypt(data []byte) ([]byte, error)

func (*AES256IGECryptor) Encrypt

func (c *AES256IGECryptor) Encrypt(data []byte) ([]byte, error)

Encrypt data长度必须是aes.BlockSize(16)的倍数,如果不是请调用者补齐

type AesCTR128Encrypt

type AesCTR128Encrypt struct {
	// contains filtered or unexported fields
}

func NewAesCTR128Encrypt

func NewAesCTR128Encrypt(key []byte, iv []byte) (*AesCTR128Encrypt, error)

key长度必须为16、24或32

func (*AesCTR128Encrypt) Encrypt

func (e *AesCTR128Encrypt) Encrypt(plaintext []byte) []byte

type AesCTR128KeySizeError

type AesCTR128KeySizeError int

func (AesCTR128KeySizeError) Error

func (k AesCTR128KeySizeError) Error() string

type AuthKey

type AuthKey struct {
	// contains filtered or unexported fields
}

func CreateAuthKey

func CreateAuthKey() *AuthKey

CreateAuthKey

## android client, pushAuthKey algo:

  • authKey if (SharedConfig.pushAuthKey == null) { SharedConfig.pushAuthKey = new byte[256]; Utilities.random.nextBytes(SharedConfig.pushAuthKey); SharedConfig.saveConfig(); }
  • calcAuthKeyId SharedConfig.pushAuthKeyId = new byte[8]; byte[] authKeyHash = Utilities.computeSHA1(SharedConfig.pushAuthKey); System.arraycopy(authKeyHash, authKeyHash.length - 8, SharedConfig.pushAuthKeyId, 0, 8);

for bots...

func NewAuthKey

func NewAuthKey(keyId int64, keyData []byte) *AuthKey

func NewClientAuthKey

func NewClientAuthKey(keyId int64, keyData []byte) *AuthKey

func (*AuthKey) AesIgeDecrypt

func (k *AuthKey) AesIgeDecrypt(msgKey, rawData []byte) ([]byte, error)

func (*AuthKey) AesIgeDecryptV1

func (k *AuthKey) AesIgeDecryptV1(msgKey, rawData []byte) ([]byte, error)

func (*AuthKey) AesIgeEncrypt

func (k *AuthKey) AesIgeEncrypt(rawData []byte) ([]byte, []byte, error)

func (*AuthKey) AesIgeEncryptV1

func (k *AuthKey) AesIgeEncryptV1(rawData []byte) ([]byte, []byte, error)

AesIgeEncryptV1

| salt <br> int64 | `session_id` <br> int64 | `message_id` <br> int64 | `seq_no` <br> int32 |`message_data_length` <br> int32 | `message_data` <br> bytes | padding12..1024 <br> bytes| |:-:|:-:|:-:|:-:|:-:|:-:|:-:|

func (*AuthKey) AuthKey

func (k *AuthKey) AuthKey() []byte

func (*AuthKey) AuthKeyId

func (k *AuthKey) AuthKeyId() int64

func (*AuthKey) Equals

func (k *AuthKey) Equals(o *AuthKey) bool

type PasswordKdfAlgoModPow

type PasswordKdfAlgoModPow struct {
	Salt1 []byte
	Salt2 []byte
	G     int32
	P     []byte
}

type RSACryptor

type RSACryptor struct {
	// contains filtered or unexported fields
}

func NewRSACryptor

func NewRSACryptor(keyFile string) (*RSACryptor, error)

func NewRSACryptorByKeyData

func NewRSACryptorByKeyData(pkcs1PemPrivateKey []byte) (*RSACryptor, error)

func (*RSACryptor) Decrypt

func (m *RSACryptor) Decrypt(b []byte) []byte

func (*RSACryptor) Encrypt

func (m *RSACryptor) Encrypt(b []byte) []byte

type SRPUtil

type SRPUtil struct {
	*PasswordKdfAlgoModPow
	// contains filtered or unexported fields
}

func MakeSRPUtil

func MakeSRPUtil(algo *PasswordKdfAlgoModPow) *SRPUtil

func (*SRPUtil) CalcClientM

func (m *SRPUtil) CalcClientM(newSalt1, xBytes, srpB []byte) ([]byte, []byte)

func (*SRPUtil) CalcClientM2

func (m *SRPUtil) CalcClientM2(newSalt1, aBytes, ABytes, xBytes, srpB []byte) []byte

func (*SRPUtil) CalcM

func (m *SRPUtil) CalcM(newSalt1, vBytes, srpA, srpb, srpB []byte) []byte

func (*SRPUtil) CalcSRPB

func (m *SRPUtil) CalcSRPB(vBytes []byte) ([]byte, []byte)

func (*SRPUtil) CalcSRPB2

func (m *SRPUtil) CalcSRPB2(bNonce, vBytes []byte) []byte

func (*SRPUtil) CheckNewSalt1

func (m *SRPUtil) CheckNewSalt1(newSalt1 []byte) bool

func (*SRPUtil) GetV

func (m *SRPUtil) GetV(newSalt1, passwordBytes []byte) *big.Int

func (*SRPUtil) GetVBytes

func (m *SRPUtil) GetVBytes(newSalt1, passwordBytes []byte) []byte

func (*SRPUtil) GetX

func (m *SRPUtil) GetX(newSalt1, passwordBytes []byte) []byte

type User

type User struct {
	ID        int
	BaseHash  int64
	Timestamp int64
	Salt      int
}

User represents a Telegram user with an ID, base hash, timestamp, and salt

func CreateUser

func CreateUser(userID int) User

CreateUser creates a new user and stores it in the database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL